Mercurial > mplayer.hg
annotate gui/wm/ws.c @ 36072:506cefd8a5f0
Make comment a doxygen comment.
Additionally, remove commented code.
author | ib |
---|---|
date | Fri, 05 Apr 2013 12:43:11 +0000 |
parents | 4489eafbe0a9 |
children | 2e0729818242 |
rev | line source |
---|---|
26458 | 1 /* |
2 * This file is part of MPlayer. | |
3 * | |
4 * MPlayer is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; either version 2 of the License, or | |
7 * (at your option) any later version. | |
8 * | |
9 * MPlayer is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License along | |
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
35666
01ac3cd2f101
Cosmetic: Relocate and revise comments on code origin.
ib
parents:
35665
diff
changeset
|
17 * |
01ac3cd2f101
Cosmetic: Relocate and revise comments on code origin.
ib
parents:
35665
diff
changeset
|
18 * based on: AutoSpace Window System for Linux/Win32, |
01ac3cd2f101
Cosmetic: Relocate and revise comments on code origin.
ib
parents:
35665
diff
changeset
|
19 * written by pontscho/fresh!mindworkz |
26458 | 20 */ |
23077 | 21 |
35702 | 22 #include <stdint.h> |
23077 | 23 #include <stdlib.h> |
24 #include <string.h> | |
35702 | 25 #include <sys/ipc.h> |
26 #include <X11/Xatom.h> | |
23077 | 27 |
35702 | 28 #include "ws.h" |
29 #include "wsxdnd.h" | |
30 #include "gui/interface.h" | |
36053 | 31 #include "gui/app/gui.h" |
23077 | 32 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
23795
diff
changeset
|
33 #include "config.h" |
35702 | 34 #include "help_mp.h" |
36032 | 35 #include "mp_core.h" |
36 #include "mp_msg.h" | |
37 #include "mpbswap.h" | |
38 #include "mplayer.h" | |
35702 | 39 #include "libavutil/imgutils.h" |
40 #include "libavutil/pixfmt.h" | |
41 #include "libswscale/swscale.h" | |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
23795
diff
changeset
|
42 #include "libvo/video_out.h" |
35702 | 43 #include "libvo/x11_common.h" |
34033 | 44 #include "osdep/timer.h" |
23077 | 45 |
35702 | 46 #ifdef HAVE_SHM |
47 #include <sys/shm.h> | |
48 #endif | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
49 #ifdef CONFIG_XSHAPE |
23077 | 50 #include <X11/extensions/shape.h> |
51 #endif | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
52 #ifdef CONFIG_XF86VM |
23077 | 53 #include <X11/extensions/xf86vmode.h> |
54 #endif | |
55 | |
34034
8c75091726d8
Replace numeric constant for cursor autohide time by symbolic constant.
ib
parents:
34033
diff
changeset
|
56 #define MOUSEHIDE_DELAY 1000 // in milliseconds |
8c75091726d8
Replace numeric constant for cursor autohide time by symbolic constant.
ib
parents:
34033
diff
changeset
|
57 |
35656 | 58 static wsWindow *mouse_win; |
34081 | 59 static unsigned int mouse_time; |
60 | |
35667 | 61 int wsMaxX; // Screen width. |
62 int wsMaxY; // Screen height. | |
63 int wsOrgX; // Screen origin x. | |
64 int wsOrgY; // Screen origin y. | |
23077 | 65 |
33539 | 66 Display *wsDisplay; |
35667 | 67 static int wsScreen; |
68 static Window wsRootWin; | |
23077 | 69 |
35678 | 70 static int wsScreenDepth; |
35667 | 71 static int wsRedMask; |
72 static int wsGreenMask; | |
73 static int wsBlueMask; | |
74 static int wsNonNativeOrder; | |
23077 | 75 |
33539 | 76 #define wsWLCount 5 |
35667 | 77 static wsWindow *wsWindowList[wsWLCount]; |
33539 | 78 |
35667 | 79 static int wsUseXShm = True; |
80 static int wsUseXShape = True; | |
23077 | 81 |
35707
4ba6b8d3197e
Replace PixelFormat and PIX_FMT_FOO by their AV_-prefixed counterparts.
diego
parents:
35702
diff
changeset
|
82 static enum AVPixelFormat out_pix_fmt = PIX_FMT_NONE; |
23077 | 83 |
34684 | 84 /* --- */ |
23077 | 85 |
86 #define MWM_HINTS_FUNCTIONS (1L << 0) | |
87 #define MWM_HINTS_DECORATIONS (1L << 1) | |
88 | |
89 #define MWM_FUNC_RESIZE (1L << 1) | |
90 #define MWM_FUNC_MOVE (1L << 2) | |
91 #define MWM_FUNC_MINIMIZE (1L << 3) | |
92 #define MWM_FUNC_MAXIMIZE (1L << 4) | |
93 #define MWM_FUNC_CLOSE (1L << 5) | |
94 | |
95 #define MWM_DECOR_ALL (1L << 0) | |
96 | |
33994
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
97 /** |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
98 * @brief Update screen width, screen height and screen origin x and y |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
99 * from xinerama information. |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
100 * |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
101 * Set wsOrgX, wsOrgY, wsMaxX and wsMaxY as well as |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
102 * win->X, win->Y, win->Width and win->Height. |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
103 * |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
104 * @param win pointer to a ws window structure or NULL |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
105 */ |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
106 static void wsWindowUpdateXinerama(wsWindow *win) |
33994
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
107 { |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
108 if (win) { |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
109 vo_dx = win->X; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
110 vo_dy = win->Y; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
111 vo_dwidth = win->Width; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
112 vo_dheight = win->Height; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
113 } |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
114 |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
115 vo_screenwidth = wsMaxX; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
116 vo_screenheight = wsMaxY; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
117 |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
118 update_xinerama_info(); |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
119 |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
120 wsMaxX = vo_screenwidth; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
121 wsMaxY = vo_screenheight; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
122 wsOrgX = xinerama_x; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
123 wsOrgY = xinerama_y; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
124 |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
125 if (win) { |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
126 win->X = wsOrgX; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
127 win->Y = wsOrgY; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
128 win->Width = wsMaxX; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
129 win->Height = wsMaxY; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
130 } |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
131 } |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
132 |
35676 | 133 static int wsGetScreenDepth(void) |
35636 | 134 { |
35672 | 135 int depth; |
136 XImage *mXImage; | |
137 Visual *visual; | |
138 | |
139 if ((depth = vo_find_depth_from_visuals(wsDisplay, wsScreen, &visual)) > 0) { | |
140 mXImage = XCreateImage(wsDisplay, visual, depth, ZPixmap, 0, NULL, | |
141 1, 1, 32, 0); | |
35676 | 142 wsScreenDepth = mXImage->bits_per_pixel; |
35677 | 143 wsRedMask = mXImage->red_mask; |
144 wsGreenMask = mXImage->green_mask; | |
145 wsBlueMask = mXImage->blue_mask; | |
35672 | 146 #if HAVE_BIGENDIAN |
147 wsNonNativeOrder = mXImage->byte_order == LSBFirst; | |
148 #else | |
149 wsNonNativeOrder = mXImage->byte_order == MSBFirst; | |
150 #endif | |
151 XDestroyImage(mXImage); | |
152 } else { | |
153 int bpp, ibpp; | |
154 XWindowAttributes attribs; | |
155 | |
156 mXImage = XGetImage(wsDisplay, wsRootWin, 0, 0, 1, 1, AllPlanes, ZPixmap); | |
157 bpp = mXImage->bits_per_pixel; | |
158 | |
159 XGetWindowAttributes(wsDisplay, wsRootWin, &attribs); | |
160 ibpp = attribs.depth; | |
161 mXImage = XGetImage(wsDisplay, wsRootWin, 0, 0, 1, 1, AllPlanes, ZPixmap); | |
162 bpp = mXImage->bits_per_pixel; | |
163 | |
164 if ((ibpp + 7) / 8 != (bpp + 7) / 8) | |
165 ibpp = bpp; | |
166 | |
35676 | 167 wsScreenDepth = ibpp; |
35677 | 168 wsRedMask = mXImage->red_mask; |
169 wsGreenMask = mXImage->green_mask; | |
170 wsBlueMask = mXImage->blue_mask; | |
35672 | 171 XDestroyImage(mXImage); |
172 } | |
173 | |
35676 | 174 return wsScreenDepth; |
35672 | 175 } |
176 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
177 void wsInit(Display *display) |
23077 | 178 { |
33539 | 179 int eventbase; |
180 int errorbase; | |
23077 | 181 |
35622
59456592c6d1
Add a message indicating start of initialization of X.
ib
parents:
35541
diff
changeset
|
182 mp_msg(MSGT_GPLAYER, MSGL_V, "X init.\n"); |
59456592c6d1
Add a message indicating start of initialization of X.
ib
parents:
35541
diff
changeset
|
183 |
35631 | 184 wsDisplay = display; |
23077 | 185 |
35636 | 186 wsSetErrorHandler(); |
31323
c674bb16fa6d
Install error handler as early as possible to avoid crashing.
reimar
parents:
31314
diff
changeset
|
187 |
23077 | 188 /* enable DND atoms */ |
33539 | 189 wsXDNDInitialize(); |
190 | |
191 { /* on remote display XShm will be disabled - LGB */ | |
192 char *dispname = DisplayString(wsDisplay); | |
193 int localdisp = 1; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
194 |
33539 | 195 if (dispname && *dispname != ':') { |
196 localdisp = 0; | |
35493 | 197 wsUseXShm = False; |
33539 | 198 } |
199 | |
33985 | 200 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] display name: %s => %s display.\n", dispname, localdisp ? "local" : "REMOTE"); |
23077 | 201 |
33539 | 202 if (!localdisp) |
33549 | 203 mp_msg(MSGT_GPLAYER, MSGL_INFO, MSGTR_WS_RemoteDisplay); |
33539 | 204 } |
205 | |
34465 | 206 #ifdef HAVE_SHM |
34461 | 207 if (!XShmQueryExtension(wsDisplay)) |
34465 | 208 #endif |
35493 | 209 wsUseXShm = False; |
33539 | 210 |
34460
c4731df07bfe
Always inform / warn about missing shared memory / shape extension
ib
parents:
34459
diff
changeset
|
211 if (!wsUseXShm) |
c4731df07bfe
Always inform / warn about missing shared memory / shape extension
ib
parents:
34459
diff
changeset
|
212 mp_msg(MSGT_GPLAYER, MSGL_INFO, MSGTR_WS_NoXshm); |
c4731df07bfe
Always inform / warn about missing shared memory / shape extension
ib
parents:
34459
diff
changeset
|
213 |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
214 #ifdef CONFIG_XSHAPE |
34461 | 215 if (!XShapeQueryExtension(wsDisplay, &eventbase, &errorbase)) |
34462 | 216 #endif |
35493 | 217 wsUseXShape = False; |
23077 | 218 |
34460
c4731df07bfe
Always inform / warn about missing shared memory / shape extension
ib
parents:
34459
diff
changeset
|
219 if (!wsUseXShape) |
c4731df07bfe
Always inform / warn about missing shared memory / shape extension
ib
parents:
34459
diff
changeset
|
220 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_WS_NoXshape); |
c4731df07bfe
Always inform / warn about missing shared memory / shape extension
ib
parents:
34459
diff
changeset
|
221 |
33539 | 222 XSynchronize(wsDisplay, True); |
23077 | 223 |
33539 | 224 wsScreen = DefaultScreen(wsDisplay); |
225 wsRootWin = RootWindow(wsDisplay, wsScreen); | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
226 #ifdef CONFIG_XF86VM |
23077 | 227 { |
33539 | 228 int clock; |
229 XF86VidModeModeLine modeline; | |
23077 | 230 |
33539 | 231 XF86VidModeGetModeLine(wsDisplay, wsScreen, &clock, &modeline); |
232 wsMaxX = modeline.hdisplay; | |
233 wsMaxY = modeline.vdisplay; | |
23077 | 234 } |
235 #endif | |
33539 | 236 { |
237 wsOrgX = wsOrgY = 0; | |
23077 | 238 |
33539 | 239 if (!wsMaxX) |
240 wsMaxX = DisplayWidth(wsDisplay, wsScreen); | |
241 | |
242 if (!wsMaxY) | |
243 wsMaxY = DisplayHeight(wsDisplay, wsScreen); | |
23077 | 244 } |
33994
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
245 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
246 wsWindowUpdateXinerama(NULL); |
33539 | 247 |
35676 | 248 wsGetScreenDepth(); |
33549 | 249 |
35676 | 250 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] Screen depth: %d\n", wsScreenDepth); |
33985 | 251 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] size: %dx%d\n", wsMaxX, wsMaxY); |
33549 | 252 |
33539 | 253 #ifdef CONFIG_XINERAMA |
33985 | 254 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] origin: +%d+%d\n", wsOrgX, wsOrgY); |
33539 | 255 #endif |
33549 | 256 |
33985 | 257 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] red mask: 0x%x\n", wsRedMask); |
258 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] green mask: 0x%x\n", wsGreenMask); | |
259 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] blue mask: 0x%x\n", wsBlueMask); | |
33539 | 260 |
34465 | 261 #ifdef HAVE_SHM |
33550 | 262 if (wsUseXShm) { |
263 int minor, major, shp; | |
33549 | 264 |
33550 | 265 XShmQueryVersion(wsDisplay, &major, &minor, &shp); |
33985 | 266 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] XShm version is %d.%d\n", major, minor); |
33550 | 267 } |
34465 | 268 #endif |
33539 | 269 |
270 #ifdef CONFIG_XSHAPE | |
33550 | 271 if (wsUseXShape) { |
272 int minor, major; | |
33549 | 273 |
33550 | 274 XShapeQueryVersion(wsDisplay, &major, &minor); |
33985 | 275 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] XShape version is %d.%d\n", major, minor); |
33550 | 276 } |
23077 | 277 #endif |
33549 | 278 |
35733 | 279 if (wsScreenDepth == 32 && wsRedMask == 0xff0000 && wsGreenMask == 0x00ff00 && wsBlueMask == 0x0000ff) |
33539 | 280 out_pix_fmt = PIX_FMT_RGB32; |
35733 | 281 else if (wsScreenDepth == 32 && wsRedMask == 0x0000ff && wsGreenMask == 0x00ff00 && wsBlueMask == 0xff0000) |
33539 | 282 out_pix_fmt = PIX_FMT_BGR32; |
35733 | 283 else if (wsScreenDepth == 24 && wsRedMask == 0xff0000 && wsGreenMask == 0x00ff00 && wsBlueMask == 0x0000ff) |
33539 | 284 out_pix_fmt = PIX_FMT_RGB24; |
35733 | 285 else if (wsScreenDepth == 24 && wsRedMask == 0x0000ff && wsGreenMask == 0x00ff00 && wsBlueMask == 0xff0000) |
33539 | 286 out_pix_fmt = PIX_FMT_BGR24; |
35733 | 287 else if (wsScreenDepth == 16 && wsRedMask == 0xf800 && wsGreenMask == 0x7e0 && wsBlueMask == 0x1f) |
33539 | 288 out_pix_fmt = PIX_FMT_RGB565; |
35733 | 289 else if (wsScreenDepth == 16 && wsRedMask == 0x1f && wsGreenMask == 0x7e0 && wsBlueMask == 0xf800) |
33539 | 290 out_pix_fmt = PIX_FMT_BGR565; |
35733 | 291 else if (wsScreenDepth == 15 && wsRedMask == 0x7c00 && wsGreenMask == 0x3e0 && wsBlueMask == 0x1f) |
33539 | 292 out_pix_fmt = PIX_FMT_RGB555; |
35733 | 293 else if (wsScreenDepth == 15 && wsRedMask == 0x1f && wsGreenMask == 0x3e0 && wsBlueMask == 0x7c00) |
33539 | 294 out_pix_fmt = PIX_FMT_BGR555; |
23077 | 295 } |
296 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
297 void wsDone(void) |
35672 | 298 { |
35746 | 299 // NOTE TO MYSELF: uninit wsInit stuff? |
35680 | 300 //XCloseDisplay(wsDisplay); |
35672 | 301 } |
302 | |
303 /** | |
304 * @brief Inform about an X error that has occurred. | |
305 * | |
306 * @param display display | |
307 * @param event pointer to an X error event structure | |
308 * | |
309 * @return 0 | |
310 */ | |
311 static int wsErrorHandler(Display *display, XErrorEvent *event) | |
312 { | |
313 char type[128]; | |
314 | |
315 XGetErrorText(display, event->error_code, type, sizeof(type)); | |
316 | |
317 mp_msg(MSGT_GPLAYER, MSGL_ERR, "[ws] " MSGTR_WS_XError); | |
318 mp_msg(MSGT_GPLAYER, MSGL_ERR, "[ws] Error code: %d - %s\n", event->error_code, type); | |
319 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] Request code: %d (minor code: %d)\n", event->request_code, event->minor_code); | |
320 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] MPlayer module: %s\n", current_module ? current_module : "(none)"); | |
321 | |
322 return 0; | |
323 } | |
324 | |
325 /** | |
326 * @brief Set the X error handler. | |
327 */ | |
328 void wsSetErrorHandler(void) | |
329 { | |
330 XSetErrorHandler(wsErrorHandler); | |
331 } | |
332 | |
333 // ---------------------------------------------------------------------------------------------- | |
334 // Handle events. | |
335 // ---------------------------------------------------------------------------------------------- | |
336 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
337 static int wsWindowListSearch(Window win) |
35672 | 338 { |
339 int i; | |
340 | |
341 for (i = 0; i < wsWLCount; i++) | |
342 if (wsWindowList[i] && wsWindowList[i]->WindowID == win) | |
343 return i; | |
344 | |
345 return -1; | |
346 } | |
347 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
348 void wsEvent(XEvent *event) |
35672 | 349 { |
350 unsigned long i = 0; | |
351 int l; | |
352 int x, y; | |
353 Window child_window = 0; | |
354 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
355 l = wsWindowListSearch(event->xany.window); |
35672 | 356 |
357 if (l == -1) | |
358 return; | |
359 | |
360 wsWindowList[l]->State = wsNone; | |
361 | |
362 switch (event->type) { | |
363 case ClientMessage: | |
364 | |
365 if (event->xclient.message_type == wsWindowList[l]->AtomProtocols) { | |
366 if ((Atom)event->xclient.data.l[0] == wsWindowList[l]->AtomDeleteWindow) { | |
367 i = wsWindowClosed; | |
368 goto expose; | |
369 } | |
370 | |
371 if ((Atom)event->xclient.data.l[0] == wsWindowList[l]->AtomTakeFocus) { | |
372 i = wsWindowFocusIn; | |
373 wsWindowList[l]->Focused = wsFocused; | |
374 goto expose; | |
375 } | |
376 | |
377 if ((Atom)event->xclient.data.l[0] == wsWindowList[l]->AtomRolle) { | |
378 mp_msg(MSGT_GPLAYER, MSGL_V, "[ws] role set.\n"); | |
379 } | |
380 } else { | |
381 /* try to process DND events */ | |
382 wsXDNDProcessClientMessage(&event->xclient); | |
383 } | |
384 | |
385 break; | |
386 | |
387 case MapNotify: | |
388 | |
389 i = wsWindowMapped; | |
390 wsWindowList[l]->Mapped = wsMapped; | |
391 goto expose; | |
392 | |
393 case UnmapNotify: | |
394 | |
395 i = wsWindowUnmapped; | |
396 wsWindowList[l]->Mapped = wsNo; | |
397 goto expose; | |
398 | |
399 case FocusIn: | |
400 | |
401 if (wsWindowList[l]->Focused == wsFocused) | |
402 break; | |
403 | |
404 i = wsWindowFocusIn; | |
405 wsWindowList[l]->Focused = wsFocused; | |
406 goto expose; | |
407 | |
408 case FocusOut: | |
409 | |
410 if (wsWindowList[l]->Focused == wsNo) | |
411 break; | |
412 | |
413 i = wsWindowFocusOut; | |
414 wsWindowList[l]->Focused = wsNo; | |
415 goto expose; | |
416 | |
417 case VisibilityNotify: | |
418 | |
419 switch (event->xvisibility.state) { | |
420 case VisibilityUnobscured: | |
421 i = wsWindowVisible; | |
422 wsWindowList[l]->Visible = wsVisible; | |
423 goto expose; | |
424 | |
425 case VisibilityFullyObscured: | |
426 i = wsWindowNotVisible; | |
427 wsWindowList[l]->Visible = wsNotVisible; | |
428 goto expose; | |
429 | |
430 case VisibilityPartiallyObscured: | |
431 i = wsWindowPartialVisible; | |
432 wsWindowList[l]->Visible = wsPVisible; | |
433 goto expose; | |
434 } | |
435 | |
436 expose: | |
437 wsWindowList[l]->State = i; | |
438 | |
35760 | 439 if (wsWindowList[l]->DrawHandler) |
440 wsWindowList[l]->DrawHandler(); | |
35672 | 441 |
442 break; | |
443 | |
444 case Expose: | |
445 | |
446 wsWindowList[l]->State = wsWindowExpose; | |
447 | |
35760 | 448 if ((wsWindowList[l]->DrawHandler) && (!event->xexpose.count)) |
449 wsWindowList[l]->DrawHandler(); | |
35672 | 450 |
451 break; | |
452 | |
453 case ConfigureNotify: | |
454 | |
455 XTranslateCoordinates(wsDisplay, wsWindowList[l]->WindowID, wsRootWin, 0, 0, &x, &y, &child_window); | |
456 | |
457 if ((wsWindowList[l]->X != x) || (wsWindowList[l]->Y != y) || (wsWindowList[l]->Width != event->xconfigure.width) || (wsWindowList[l]->Height != event->xconfigure.height)) { | |
458 wsWindowList[l]->X = x; | |
459 wsWindowList[l]->Y = y; | |
460 wsWindowList[l]->Width = event->xconfigure.width; | |
461 wsWindowList[l]->Height = event->xconfigure.height; | |
462 } | |
463 | |
464 wsWindowList[l]->Rolled = wsNo; | |
465 | |
466 if (event->xconfigure.y < 0) { | |
467 i = wsWindowRolled; | |
468 wsWindowList[l]->Rolled = wsRolled; | |
469 goto expose; | |
470 } | |
471 | |
472 break; | |
473 | |
474 case KeyPress: | |
475 | |
476 i = wsKeyPressed; | |
477 goto keypressed; | |
478 | |
479 case KeyRelease: | |
480 | |
481 i = wsKeyReleased; | |
482 keypressed: | |
483 wsWindowList[l]->Alt = False; | |
484 wsWindowList[l]->Shift = False; | |
485 wsWindowList[l]->NumLock = False; | |
486 wsWindowList[l]->Control = False; | |
487 wsWindowList[l]->CapsLock = False; | |
488 | |
489 if (event->xkey.state & Mod1Mask) | |
490 wsWindowList[l]->Alt = True; | |
491 | |
492 if (event->xkey.state & Mod2Mask) | |
493 wsWindowList[l]->NumLock = True; | |
494 | |
495 if (event->xkey.state & ControlMask) | |
496 wsWindowList[l]->Control = True; | |
497 | |
498 if (event->xkey.state & ShiftMask) | |
499 wsWindowList[l]->Shift = True; | |
500 | |
501 if (event->xkey.state & LockMask) | |
502 wsWindowList[l]->CapsLock = True; | |
503 | |
504 #if 0 | |
505 { | |
506 KeySym keySym; | |
507 keySym = XKeycodeToKeysym(wsDisplay, event->xkey.keycode, 0); | |
508 | |
509 if (keySym != NoSymbol) { | |
510 keySym = ((keySym & 0xff00) != 0 ? ((keySym & 0x00ff) + 256) : (keySym)); | |
511 | |
512 if (wsWindowList[l]->KeyHandler) | |
513 wsWindowList[l]->KeyHandler(event->xkey.state, i, keySym); | |
514 } | |
515 } | |
516 #else | |
517 { | |
518 int key; | |
519 char buf[100]; | |
520 KeySym keySym; | |
521 static XComposeStatus stat; | |
522 | |
523 XLookupString(&event->xkey, buf, sizeof(buf), &keySym, &stat); | |
524 key = ((keySym & 0xff00) != 0 ? ((keySym & 0x00ff) + 256) : (keySym)); | |
525 | |
526 if (wsWindowList[l]->KeyHandler) | |
527 wsWindowList[l]->KeyHandler(event->xkey.keycode, i, key); | |
528 } | |
529 #endif | |
530 break; | |
531 | |
532 case MotionNotify: | |
533 | |
534 i = wsMoveMouse; | |
535 { | |
536 /* pump all motion events from the display queue: | |
537 * this way it works faster when moving the window */ | |
538 static XEvent e; | |
539 | |
540 if (event->xmotion.state) { | |
541 while (XCheckTypedWindowEvent(wsDisplay, event->xany.window, MotionNotify, &e)) { | |
542 /* FIXME: need to make sure we didn't release/press the button in between...*/ | |
543 /* FIXME: do we need some timeout here to make sure we don't spend too much time | |
544 * removing events from the queue? */ | |
545 event = &e; | |
546 } | |
547 } | |
548 } | |
549 | |
550 if (wsWindowList[l]->wsCursor != None) { | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
551 wsMouseVisibility(wsWindowList[l], wsShowMouseCursor); |
35672 | 552 mouse_win = wsWindowList[l]; |
553 mouse_time = GetTimerMS(); | |
554 } | |
555 | |
556 goto buttonreleased; | |
557 | |
558 case ButtonRelease: | |
559 | |
560 i = event->xbutton.button + 128; | |
561 | |
562 if (wsWindowList[l]->wsCursor != None) { | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
563 wsMouseVisibility(wsWindowList[l], wsShowMouseCursor); |
35672 | 564 mouse_win = wsWindowList[l]; |
565 mouse_time = GetTimerMS(); | |
566 } | |
567 | |
568 goto buttonreleased; | |
569 | |
570 case ButtonPress: | |
571 | |
572 i = event->xbutton.button; | |
573 | |
574 if (wsWindowList[l]->wsCursor != None) { | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
575 wsMouseVisibility(wsWindowList[l], wsShowMouseCursor); |
35672 | 576 mouse_win = wsWindowList[l]; |
577 mouse_time = GetTimerMS(); | |
578 } | |
579 | |
580 goto buttonreleased; | |
581 | |
582 case EnterNotify: | |
583 | |
584 i = wsEnterWindow; | |
585 goto buttonreleased; | |
586 | |
587 case LeaveNotify: | |
588 | |
589 i = wsLeaveWindow; | |
590 buttonreleased: | |
591 | |
592 if (wsWindowList[l]->MouseHandler) | |
593 wsWindowList[l]->MouseHandler(i, event->xbutton.x, event->xbutton.y, event->xmotion.x_root, event->xmotion.y_root); | |
594 | |
595 break; | |
596 | |
597 case SelectionNotify: | |
598 | |
35759 | 599 /* Handle drag & drop */ |
35672 | 600 wsXDNDProcessSelection(wsWindowList[l], event); |
601 break; | |
602 } | |
603 | |
604 XFlush(wsDisplay); | |
605 XSync(wsDisplay, False); | |
606 } | |
607 | |
36072 | 608 /** |
609 * @brief Process all pending events. | |
610 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
611 void wsEvents(void) |
35672 | 612 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
613 XEvent xev; |
36072 | 614 |
35672 | 615 while (XPending(wsDisplay)) { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
616 XNextEvent(wsDisplay, &xev); |
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
617 wsEvent(&xev); |
35672 | 618 } |
619 } | |
620 | |
33995 | 621 /** |
622 * @brief Calculate and store the x and y position for a window. | |
623 * | |
624 * @param win pointer to a ws window structure | |
625 * @param x x position of the window (real/absolute or mock) | |
626 * @param y y position of the window (real/absolute or mock) | |
627 * @param width width of the area to place the window in | |
628 * @param height height of the area to place the window in | |
629 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
630 static void wsWindowUpdatePosition(wsWindow *win, int x, int y, int width, int height) |
33995 | 631 { |
632 switch (x) { | |
633 case -1: | |
634 win->X = wsOrgX + (wsMaxX - width) / 2; | |
635 break; | |
636 | |
637 case -2: | |
638 win->X = wsOrgX + wsMaxX - width; | |
639 break; | |
640 | |
641 default: | |
642 win->X = x; | |
643 break; | |
644 } | |
645 | |
646 switch (y) { | |
647 case -1: | |
648 win->Y = wsOrgY + (wsMaxY - height) / 2; | |
649 break; | |
650 | |
651 case -2: | |
652 win->Y = wsOrgY + wsMaxY - height; | |
653 break; | |
654 | |
655 default: | |
656 win->Y = y; | |
657 break; | |
658 } | |
659 } | |
660 | |
35645 | 661 /** |
662 * @brief Replace the size hints for the WM_NORMAL_HINTS property of a window. | |
663 * | |
664 * @param win pointer to a ws window structure | |
665 */ | |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
666 static void wsWindowSizeHint(wsWindow *win) |
35645 | 667 { |
35660 | 668 XSizeHints size; |
669 | |
670 size.flags = 0; | |
35645 | 671 |
35648 | 672 /* obsolete, solely for compatibility reasons */ |
35660 | 673 size.flags |= PPosition; |
674 size.x = win->X; | |
675 size.y = win->Y; | |
35645 | 676 |
35648 | 677 /* obsolete, solely for compatibility reasons */ |
35660 | 678 size.flags |= PSize; |
679 size.width = win->Width; | |
680 size.height = win->Height; | |
35645 | 681 |
35648 | 682 /* a minimum of 4 is said to avoid off-by-one errors and be required by mga_vid */ |
35660 | 683 size.flags |= PMinSize; |
684 size.min_width = 4; | |
685 size.min_height = 4; | |
35648 | 686 |
687 if (win->Property & wsMinSize) { | |
35660 | 688 size.min_width = win->Width; |
689 size.min_height = win->Height; | |
35645 | 690 } |
691 | |
35648 | 692 if (win->Property & wsMaxSize) { |
35660 | 693 size.flags |= PMaxSize; |
694 size.max_width = win->Width; | |
695 size.max_height = win->Height; | |
35645 | 696 } |
697 | |
35657 | 698 if (vo_keepaspect && (win->Property & wsAspect)) { |
35660 | 699 size.flags |= PAspect; |
700 size.min_aspect.x = win->Width; | |
701 size.min_aspect.y = win->Height; | |
702 size.max_aspect.x = win->Width; | |
703 size.max_aspect.y = win->Height; | |
35645 | 704 } |
705 | |
35660 | 706 size.flags |= PBaseSize; |
707 size.base_width = 0; | |
708 size.base_height = 0; | |
35645 | 709 |
35660 | 710 size.flags |= PWinGravity; |
711 size.win_gravity = StaticGravity; | |
35645 | 712 |
35660 | 713 XSetWMNormalHints(wsDisplay, win->WindowID, &size); |
35645 | 714 } |
715 | |
35699 | 716 static void wsWindowDecoration(wsWindow *win) |
35698 | 717 { |
718 Atom wsMotifHints; | |
719 struct { | |
720 unsigned long flags; | |
721 unsigned long functions; | |
722 unsigned long decorations; | |
723 long input_mode; | |
724 unsigned long status; | |
725 } wsMotifWmHints; | |
726 | |
727 wsMotifHints = XInternAtom(wsDisplay, "_MOTIF_WM_HINTS", 0); | |
728 | |
729 if (wsMotifHints == None) | |
730 return; | |
731 | |
732 memset(&wsMotifWmHints, 0, sizeof(wsMotifWmHints)); | |
733 wsMotifWmHints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; | |
734 | |
735 if (win->Decoration) { | |
736 wsMotifWmHints.functions = MWM_FUNC_MOVE | MWM_FUNC_CLOSE | MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE; | |
737 | |
738 if (!(win->Property & wsMinSize) || !(win->Property & wsMaxSize)) | |
739 wsMotifWmHints.functions |= MWM_FUNC_RESIZE; | |
740 | |
741 wsMotifWmHints.decorations = MWM_DECOR_ALL; | |
742 } | |
743 | |
744 XChangeProperty(wsDisplay, win->WindowID, wsMotifHints, wsMotifHints, 32, | |
745 PropModeReplace, (unsigned char *)&wsMotifWmHints, 5); | |
746 } | |
747 | |
35652 | 748 /** |
749 * @brief Wait until a window is mapped if its property requires it. | |
750 * | |
751 * @param win pointer to a ws window structure | |
752 */ | |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
753 static void wsWindowMapWait(wsWindow *win) |
35652 | 754 { |
755 XEvent xev; | |
756 | |
35653 | 757 if (win->Property & wsWaitMap) { |
35652 | 758 do |
759 XNextEvent(wsDisplay, &xev); | |
760 while (xev.type != MapNotify || xev.xmap.event != win->WindowID); | |
35653 | 761 |
762 win->Mapped = wsMapped; | |
763 } | |
35652 | 764 } |
765 | |
23077 | 766 // ---------------------------------------------------------------------------------------------- |
767 // Create window. | |
768 // X,Y : window position | |
769 // wX,wY : size of window | |
770 // bW : border width | |
771 // cV : visible mouse cursor on window | |
772 // D : visible frame, title, etc. | |
773 // sR : screen ratio | |
774 // ---------------------------------------------------------------------------------------------- | |
775 | |
33539 | 776 XClassHint wsClassHint; |
777 XTextProperty wsTextProperty; | |
778 Window LeaderWindow; | |
23077 | 779 |
35655 | 780 // ---------------------------------------------------------------------------------------------- |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
781 // wsWindowCreate: create a new window on the screen. |
35655 | 782 // x,y : window position |
783 // w,h : window size | |
784 // c : mouse cursor visible | |
785 // p : properties - "decoration", visible titlebar, etc ... | |
786 // ---------------------------------------------------------------------------------------------- | |
35687 | 787 void wsWindowCreate(wsWindow *win, int x, int y, int w, int h, int p, int c, char *label) |
23077 | 788 { |
33539 | 789 int depth; |
790 | |
35655 | 791 win->Property = p; |
23077 | 792 |
35697 | 793 win->Decoration = ((p & wsShowFrame) != 0); |
33539 | 794 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
795 wsWindowUpdatePosition(win, x, y, w, h); |
33539 | 796 |
35655 | 797 win->Width = w; |
798 win->Height = h; | |
33539 | 799 win->OldX = win->X; |
800 win->OldY = win->Y; | |
801 win->OldWidth = win->Width; | |
802 win->OldHeight = win->Height; | |
23077 | 803 |
34684 | 804 /* Hide Mouse Cursor */ |
33539 | 805 win->wsCursor = None; |
35655 | 806 win->wsMouseEventType = c; |
33539 | 807 win->wsCursorData[0] = 0; |
808 win->wsCursorPixmap = XCreateBitmapFromData(wsDisplay, wsRootWin, win->wsCursorData, 1, 1); | |
23077 | 809 |
35655 | 810 if (!(c & wsShowMouseCursor)) |
33539 | 811 win->wsCursor = XCreatePixmapCursor(wsDisplay, win->wsCursorPixmap, win->wsCursorPixmap, &win->wsColor, &win->wsColor, 0, 0); |
812 | |
813 depth = vo_find_depth_from_visuals(wsDisplay, wsScreen, NULL); | |
814 | |
815 if (depth < 15) { | |
816 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ColorDepthTooLow); | |
33768 | 817 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 818 } |
819 | |
820 XMatchVisualInfo(wsDisplay, wsScreen, depth, TrueColor, &win->VisualInfo); | |
23077 | 821 |
34684 | 822 /* --- */ |
33539 | 823 win->AtomLeaderClient = XInternAtom(wsDisplay, "WM_CLIENT_LEADER", False); |
824 win->AtomDeleteWindow = XInternAtom(wsDisplay, "WM_DELETE_WINDOW", False); | |
825 win->AtomTakeFocus = XInternAtom(wsDisplay, "WM_TAKE_FOCUS", False); | |
826 win->AtomRolle = XInternAtom(wsDisplay, "WM_WINDOW_ROLE", False); | |
827 win->AtomWMSizeHint = XInternAtom(wsDisplay, "WM_SIZE_HINT", False); | |
828 win->AtomWMNormalHint = XInternAtom(wsDisplay, "WM_NORMAL_HINT", False); | |
829 win->AtomProtocols = XInternAtom(wsDisplay, "WM_PROTOCOLS", False); | |
830 win->AtomsProtocols[0] = win->AtomDeleteWindow; | |
831 win->AtomsProtocols[1] = win->AtomTakeFocus; | |
832 win->AtomsProtocols[2] = win->AtomRolle; | |
34684 | 833 /* --- */ |
23077 | 834 |
35737 | 835 win->WindowAttrib.border_pixel = WhitePixel(wsDisplay, wsScreen); |
836 win->WindowAttrib.colormap = XCreateColormap(wsDisplay, wsRootWin, win->VisualInfo.visual, AllocNone); | |
837 win->WindowAttrib.event_mask = StructureNotifyMask | FocusChangeMask | | |
838 ExposureMask | PropertyChangeMask | | |
839 EnterWindowMask | LeaveWindowMask | | |
840 VisibilityChangeMask | | |
841 KeyPressMask | KeyReleaseMask; | |
23077 | 842 |
35655 | 843 if ((c & wsHandleMouseButton)) |
33539 | 844 win->WindowAttrib.event_mask |= ButtonPressMask | ButtonReleaseMask; |
845 | |
35655 | 846 if ((c & wsHandleMouseMove)) |
33539 | 847 win->WindowAttrib.event_mask |= PointerMotionMask; |
848 | |
849 win->WindowAttrib.cursor = win->wsCursor; | |
850 win->WindowAttrib.override_redirect = False; | |
851 | |
35655 | 852 if (p & wsOverredirect) |
33539 | 853 win->WindowAttrib.override_redirect = True; |
23077 | 854 |
35736
f1a696672425
Remove setting pointless window attribute CWBackPixel.
ib
parents:
35734
diff
changeset
|
855 win->WindowMask = CWBorderPixel | |
33539 | 856 CWColormap | CWEventMask | CWCursor | |
857 CWOverrideRedirect; | |
23077 | 858 |
33539 | 859 win->WindowID = XCreateWindow(wsDisplay, |
860 (win->Parent != 0 ? win->Parent : wsRootWin), | |
35683
75155d8a9c7e
Remove parameter for border_width from wsWindowCreate().
ib
parents:
35682
diff
changeset
|
861 win->X, win->Y, win->Width, win->Height, 0, |
33539 | 862 win->VisualInfo.depth, |
863 InputOutput, | |
864 win->VisualInfo.visual, | |
865 win->WindowMask, &win->WindowAttrib); | |
23077 | 866 |
36055 | 867 wsClassHint.res_name = "GUI"; |
33539 | 868 |
36053 | 869 wsClassHint.res_class = MPlayer; |
33539 | 870 XSetClassHint(wsDisplay, win->WindowID, &wsClassHint); |
871 | |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
872 wsWindowSizeHint(win); |
23077 | 873 |
33539 | 874 win->WMHints.flags = InputHint | StateHint; |
875 win->WMHints.input = True; | |
876 win->WMHints.initial_state = NormalState; | |
877 XSetWMHints(wsDisplay, win->WindowID, &win->WMHints); | |
23077 | 878 |
35697 | 879 wsWindowDecoration(win); |
33539 | 880 XStoreName(wsDisplay, win->WindowID, label); |
881 XmbSetWMProperties(wsDisplay, win->WindowID, label, label, NULL, 0, NULL, NULL, NULL); | |
23077 | 882 |
33539 | 883 XSetWMProtocols(wsDisplay, win->WindowID, win->AtomsProtocols, 3); |
884 XChangeProperty(wsDisplay, win->WindowID, | |
885 win->AtomLeaderClient, | |
886 XA_WINDOW, 32, PropModeReplace, | |
887 (unsigned char *)&LeaderWindow, 1); | |
23077 | 888 |
33539 | 889 wsTextProperty.value = label; |
890 wsTextProperty.encoding = XA_STRING; | |
891 wsTextProperty.format = 8; | |
892 wsTextProperty.nitems = strlen(label); | |
893 XSetWMIconName(wsDisplay, win->WindowID, &wsTextProperty); | |
894 | |
895 win->wGC = XCreateGC(wsDisplay, win->WindowID, | |
35679 | 896 0, |
897 NULL); | |
23077 | 898 |
35498
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
899 win->Visible = wsNo; |
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
900 win->Focused = wsNo; |
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
901 win->Mapped = wsNo; |
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
902 win->Rolled = wsNo; |
23077 | 903 |
35655 | 904 if (p & wsShowWindow) { |
33539 | 905 XMapWindow(wsDisplay, win->WindowID); |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
906 wsWindowMapWait(win); |
35652 | 907 } |
23077 | 908 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
909 wsImageCreate(win, win->Width, win->Height); |
34684 | 910 /* End of creating -------------------------------------------------------------------------- */ |
23077 | 911 |
33539 | 912 { |
913 int i; | |
914 | |
915 for (i = 0; i < wsWLCount; i++) | |
916 if (wsWindowList[i] == NULL) | |
917 break; | |
918 | |
919 if (i == wsWLCount) { | |
920 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_TooManyOpenWindows); | |
33768 | 921 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 922 } |
23077 | 923 |
33539 | 924 wsWindowList[i] = win; |
925 } | |
926 | |
927 XFlush(wsDisplay); | |
928 XSync(wsDisplay, False); | |
23077 | 929 |
35760 | 930 win->DrawHandler = NULL; |
33539 | 931 win->MouseHandler = NULL; |
932 win->KeyHandler = NULL; | |
33985 | 933 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] window is created. ( %s ).\n", label); |
23077 | 934 } |
935 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
936 void wsWindowDestroy(wsWindow *win) |
23077 | 937 { |
33539 | 938 int l; |
939 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
940 l = wsWindowListSearch(win->WindowID); |
35354 | 941 |
942 if (l != -1) | |
943 wsWindowList[l] = NULL; | |
33539 | 944 |
35760 | 945 win->DrawHandler = NULL; |
35752 | 946 win->MouseHandler = NULL; |
947 win->KeyHandler = NULL; | |
35759 | 948 win->DNDHandler = NULL; |
35752 | 949 |
33539 | 950 if (win->wsCursor != None) { |
951 XFreeCursor(wsDisplay, win->wsCursor); | |
952 win->wsCursor = None; | |
953 } | |
954 | |
955 XFreeGC(wsDisplay, win->wGC); | |
956 XUnmapWindow(wsDisplay, win->WindowID); | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
957 wsImageDestroy(win); |
33539 | 958 XDestroyWindow(wsDisplay, win->WindowID); |
23077 | 959 #if 0 |
35753 | 960 win->Visible = wsNo; |
961 win->Focused = wsNo; | |
962 win->Mapped = wsNo; | |
963 win->Rolled = wsNo; | |
23077 | 964 #endif |
965 } | |
966 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
967 void wsWindowShape(wsWindow *win, char *data) |
35672 | 968 { |
969 #ifdef CONFIG_XSHAPE | |
970 if (!wsUseXShape) | |
971 return; | |
972 | |
973 if (data) { | |
974 win->Mask = XCreateBitmapFromData(wsDisplay, win->WindowID, data, win->Width, win->Height); | |
975 XShapeCombineMask(wsDisplay, win->WindowID, ShapeBounding, 0, 0, win->Mask, ShapeSet); | |
976 XFreePixmap(wsDisplay, win->Mask); | |
977 } else | |
978 XShapeCombineMask(wsDisplay, win->WindowID, ShapeBounding, 0, 0, None, ShapeSet); | |
979 #endif | |
980 } | |
981 | |
34081 | 982 /** |
35672 | 983 * @brief Set differently sized icons to a window. |
984 * | |
985 * This function sets the X icon hint as well as | |
986 * the properties KWM_WIN_ICON and _NET_WM_ICON. | |
987 * | |
988 * @param display display | |
989 * @param Win window | |
990 * @param icon pointer to the icons | |
34081 | 991 */ |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
992 void wsWindowIcon(Display *display, Window Win, guiIcon_t *icon) |
34081 | 993 { |
35672 | 994 XWMHints *wm; |
995 Atom iconatom; | |
996 long data[2]; | |
997 | |
998 if (icon->normal) { | |
999 wm = XGetWMHints(display, Win); | |
1000 | |
1001 if (!wm) | |
1002 wm = XAllocWMHints(); | |
1003 | |
1004 wm->icon_pixmap = icon->normal; | |
1005 wm->icon_mask = icon->normal_mask; | |
1006 wm->flags |= IconPixmapHint | IconMaskHint; | |
1007 | |
1008 XSetWMHints(display, Win, wm); | |
1009 XFree(wm); | |
1010 } | |
1011 | |
1012 if (icon->small || icon->normal) { | |
1013 iconatom = XInternAtom(display, "KWM_WIN_ICON", False); | |
1014 data[0] = (icon->small ? icon->small : icon->normal); | |
1015 data[1] = (icon->small ? icon->small_mask : icon->normal_mask); | |
1016 | |
1017 XChangeProperty(display, Win, iconatom, iconatom, 32, PropModeReplace, (unsigned char *)data, 2); | |
1018 } | |
1019 | |
1020 if (icon->collection) { | |
1021 iconatom = XInternAtom(display, "_NET_WM_ICON", False); | |
1022 XChangeProperty(display, Win, iconatom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)icon->collection, icon->collection_size); | |
34081 | 1023 } |
1024 } | |
1025 | |
35730 | 1026 /** |
1027 * @brief Pack color components @a r, @a g and @a b into 15 bits. | |
1028 * | |
1029 * @param r red (0 - 255) | |
1030 * @param g green (0 - 255) | |
1031 * @param b blue (0 - 255) | |
1032 * | |
1033 * @return pixel suitable for a RGB 15 bits color format | |
1034 */ | |
1035 static int pack_rgb15(int r, int g, int b) | |
1036 { | |
1037 int pixel; | |
1038 | |
35734 | 1039 pixel = r >> 3; |
35730 | 1040 pixel <<= 5; |
35734 | 1041 pixel |= g >> 3; |
35730 | 1042 pixel <<= 5; |
35734 | 1043 pixel |= b >> 3; |
35730 | 1044 |
1045 return pixel; | |
1046 } | |
1047 | |
1048 /** | |
1049 * @brief Pack color components @a r, @a g and @a b into 16 bits. | |
1050 * | |
1051 * @param r red (0 - 255) | |
1052 * @param g green (0 - 255) | |
1053 * @param b blue (0 - 255) | |
1054 * | |
1055 * @return pixel suitable for a RGB 16 bits color format | |
1056 */ | |
1057 static int pack_rgb16(int r, int g, int b) | |
1058 { | |
1059 int pixel; | |
1060 | |
35734 | 1061 pixel = r >> 3; |
35730 | 1062 pixel <<= 6; |
35734 | 1063 pixel |= g >> 2; |
35730 | 1064 pixel <<= 5; |
35734 | 1065 pixel |= b >> 3; |
35730 | 1066 |
1067 return pixel; | |
1068 } | |
1069 | |
35755
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1070 /** |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1071 * @brief Set and fill, or unset a window background. |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1072 * |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1073 * @param win pointer to a ws window structure |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1074 * @param r red (0 - 255, or -1) |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1075 * @param g green (0 - 255, or -1) |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1076 * @param b blue (0 - 255, or -1) |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1077 * |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1078 * @note Passing -1 for @a r, @a g and @a b unsets the background. |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1079 */ |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1080 void wsWindowBackground(wsWindow *win, int r, int g, int b) |
23077 | 1081 { |
35672 | 1082 int color = 0; |
35541 | 1083 |
35733 | 1084 switch (out_pix_fmt) { |
1085 case PIX_FMT_RGB32: | |
1086 case PIX_FMT_RGB24: | |
35672 | 1087 color = (r << 16) + (g << 8) + b; |
23077 | 1088 break; |
1089 | |
35733 | 1090 case PIX_FMT_BGR32: |
1091 case PIX_FMT_BGR24: | |
35672 | 1092 color = (b << 16) + (g << 8) + r; |
1093 break; | |
33539 | 1094 |
35733 | 1095 case PIX_FMT_RGB565: |
35730 | 1096 color = pack_rgb16(r, g, b); |
23077 | 1097 break; |
1098 | |
35733 | 1099 case PIX_FMT_BGR565: |
35730 | 1100 color = pack_rgb16(b, g, r); |
35728 | 1101 break; |
1102 | |
35733 | 1103 case PIX_FMT_RGB555: |
35730 | 1104 color = pack_rgb15(r, g, b); |
23077 | 1105 break; |
1106 | |
35733 | 1107 case PIX_FMT_BGR555: |
35730 | 1108 color = pack_rgb15(b, g, r); |
33539 | 1109 break; |
35733 | 1110 |
1111 default: | |
1112 ; | |
33539 | 1113 } |
1114 | |
35755
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1115 if (r == -1 && g == -1 && b == -1) |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1116 XSetWindowBackgroundPixmap(wsDisplay, win->WindowID, None); |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1117 else { |
35756 | 1118 XSetWindowBackground(wsDisplay, win->WindowID, color); |
1119 XClearWindow(wsDisplay, win->WindowID); | |
35755
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1120 } |
23077 | 1121 } |
1122 | |
1123 // ---------------------------------------------------------------------------------------------- | |
1124 // Move window to x, y. | |
1125 // ---------------------------------------------------------------------------------------------- | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1126 void wsWindowMove(wsWindow *win, Bool abs, int x, int y) |
23077 | 1127 { |
33993 | 1128 if (abs) { |
1129 win->X = x; | |
1130 win->Y = y; | |
33995 | 1131 } else |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1132 wsWindowUpdatePosition(win, x, y, win->Width, win->Height); |
23077 | 1133 |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
1134 wsWindowSizeHint(win); |
33539 | 1135 XMoveWindow(wsDisplay, win->WindowID, win->X, win->Y); |
23077 | 1136 } |
1137 | |
33998
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1138 /** |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1139 * @brief Move the window to the x and y position, but if it no longer fits |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1140 * into the screen, reposition it towards the upper left. |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1141 * |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1142 * @param win pointer to a ws window structure |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1143 * @param abs flag whether the position is real/absolute (True) or mock (False) |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1144 * @param x x position of the window (real/absolute or mock) |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1145 * @param y y position of the window (real/absolute or mock) |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1146 */ |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1147 void wsWindowMoveWithin(wsWindow *win, Bool abs, int x, int y) |
33998
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1148 { |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1149 Bool fitting = True; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1150 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1151 wsWindowMove(win, abs, x, y); |
33998
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1152 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1153 if (win->X + win->Width + 1 > wsMaxX) { |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1154 fitting = False; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1155 win->X = wsMaxX - win->Width; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1156 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1157 if (win->X < 0) |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1158 win->X = 0; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1159 } |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1160 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1161 if (win->Y + win->Height + 1 > wsMaxY) { |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1162 fitting = False; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1163 win->Y = wsMaxY - win->Height; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1164 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1165 if (win->Y < 0) |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1166 win->Y = 0; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1167 } |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1168 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1169 if (!fitting) |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1170 wsWindowMove(win, True, win->X, win->Y); |
33998
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1171 } |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1172 |
23077 | 1173 // ---------------------------------------------------------------------------------------------- |
1174 // Resize window to sx, sy. | |
1175 // ---------------------------------------------------------------------------------------------- | |
35682 | 1176 void wsWindowResize(wsWindow *win, int w, int h) |
23077 | 1177 { |
35682 | 1178 win->Width = w; |
1179 win->Height = h; | |
23077 | 1180 |
33539 | 1181 if (vo_wm_type == 0) |
1182 XUnmapWindow(wsDisplay, win->WindowID); | |
23077 | 1183 |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
1184 wsWindowSizeHint(win); |
35682 | 1185 XResizeWindow(wsDisplay, win->WindowID, w, h); |
33539 | 1186 |
34124 | 1187 if (vo_wm_type == 0) |
1188 XMapWindow(wsDisplay, win->WindowID); | |
23077 | 1189 } |
1190 | |
35355 | 1191 /** |
35672 | 1192 * @brief Switch window fullscreen state. |
1193 * | |
1194 * Switch normal window to fullscreen and fullscreen window to normal. | |
1195 * | |
1196 * @param win pointer to a ws window structure | |
1197 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1198 void wsWindowFullscreen(wsWindow *win) |
35672 | 1199 { |
1200 if (win->isFullScreen) { | |
1201 if (vo_fs_type & vo_wm_FULLSCREEN) | |
1202 /* window manager supports EWMH */ | |
1203 vo_x11_ewmh_fullscreen(win->WindowID, _NET_WM_STATE_REMOVE); | |
1204 else { | |
1205 win->X = win->OldX; | |
1206 win->Y = win->OldY; | |
1207 win->Width = win->OldWidth; | |
1208 win->Height = win->OldHeight; | |
1209 } | |
1210 | |
1211 win->isFullScreen = False; | |
1212 } else { | |
1213 if (vo_fs_type & vo_wm_FULLSCREEN) | |
1214 /* window manager supports EWMH */ | |
1215 vo_x11_ewmh_fullscreen(win->WindowID, _NET_WM_STATE_ADD); | |
1216 else { | |
1217 win->OldX = win->X; | |
1218 win->OldY = win->Y; | |
1219 win->OldWidth = win->Width; | |
1220 win->OldHeight = win->Height; | |
1221 } | |
1222 | |
1223 win->isFullScreen = True; | |
1224 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1225 wsWindowUpdateXinerama(win); |
35672 | 1226 } |
1227 | |
1228 /* unknown window manager and obsolete option -fsmode used */ | |
1229 if (vo_wm_type == 0 && !(vo_fsmode & 16)) { | |
1230 XUnmapWindow(wsDisplay, win->WindowID); // required for MWM | |
1231 XWithdrawWindow(wsDisplay, win->WindowID, wsScreen); | |
1232 } | |
1233 | |
1234 /* restore window if window manager doesn't support EWMH */ | |
1235 if (!(vo_fs_type & vo_wm_FULLSCREEN)) { | |
35697 | 1236 if (!win->isFullScreen) |
1237 wsWindowDecoration(win); | |
1238 | |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
1239 wsWindowSizeHint(win); |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1240 wsWindowLayer(wsDisplay, win->WindowID, win->isFullScreen); |
35672 | 1241 XMoveResizeWindow(wsDisplay, win->WindowID, win->X, win->Y, win->Width, win->Height); |
1242 } | |
1243 | |
1244 /* some window managers lose ontop after fullscreen */ | |
1245 if (!win->isFullScreen & vo_ontop) | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1246 wsWindowLayer(wsDisplay, win->WindowID, vo_ontop); |
35672 | 1247 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1248 wsWindowRaiseTop(wsDisplay, win->WindowID); |
35672 | 1249 XFlush(wsDisplay); |
1250 } | |
1251 | |
1252 /** | |
35355 | 1253 * @brief Iconify a window. |
1254 * | |
1255 * @param win pointer to a ws window structure | |
1256 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1257 void wsWindowIconify(wsWindow *win) |
33539 | 1258 { |
35355 | 1259 XIconifyWindow(wsDisplay, win->WindowID, 0); |
33539 | 1260 } |
23077 | 1261 |
35682 | 1262 void wsWindowVisibility(wsWindow *win, int vis) |
23077 | 1263 { |
35682 | 1264 switch (vis) { |
33539 | 1265 case wsShowWindow: |
35541 | 1266 |
33539 | 1267 XMapRaised(wsDisplay, win->WindowID); |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
1268 wsWindowMapWait(win); |
35541 | 1269 |
33952 | 1270 if (vo_fs_type & vo_wm_FULLSCREEN) |
1271 win->isFullScreen = False; | |
35541 | 1272 |
33539 | 1273 break; |
1274 | |
1275 case wsHideWindow: | |
35541 | 1276 |
33539 | 1277 XUnmapWindow(wsDisplay, win->WindowID); |
1278 break; | |
1279 } | |
1280 | |
1281 XFlush(wsDisplay); | |
23077 | 1282 } |
1283 | |
35672 | 1284 /** |
1285 * @brief Map a window and raise it to the top. | |
1286 * | |
1287 * @param display display | |
1288 * @param Win window | |
1289 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1290 void wsWindowRaiseTop(Display *display, Window Win) |
23077 | 1291 { |
35672 | 1292 XMapRaised(display, Win); // NOTE TO MYSELF: is that really enough? |
1293 XRaiseWindow(display, Win); // NOTE TO MYSELF: is that really enough? | |
23077 | 1294 } |
1295 | |
35672 | 1296 // ---------------------------------------------------------------------------------------------- |
1297 // Move window to selected layer | |
1298 // ---------------------------------------------------------------------------------------------- | |
1299 | |
1300 /** | |
1301 * @brief Set the layer for a window. | |
1302 * | |
1303 * @param display display | |
1304 * @param Win window | |
1305 * @param fullscreen whether to set fullscreen or normal layer | |
1306 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1307 void wsWindowLayer(Display *display, Window Win, Bool fullscreen) |
35672 | 1308 { |
1309 vo_x11_setlayer(display, Win, fullscreen); | |
1310 } | |
1311 | |
1312 // ---------------------------------------------------------------------------------------------- | |
1313 // Redraw screen. | |
1314 // ---------------------------------------------------------------------------------------------- | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1315 void wsWindowRedraw(wsWindow *win) |
35672 | 1316 { |
35760 | 1317 if (win->DrawHandler) { |
35672 | 1318 win->State = wsWindowExpose; |
35760 | 1319 win->DrawHandler(); |
35672 | 1320 XFlush(wsDisplay); |
1321 } | |
1322 } | |
1323 | |
1324 // ---------------------------------------------------------------------------------------------- | |
1325 // Put 'Image' to window. | |
1326 // ---------------------------------------------------------------------------------------------- | |
35682 | 1327 void wsImageCreate(wsWindow *win, int w, int h) |
23077 | 1328 { |
34465 | 1329 #ifdef HAVE_SHM |
33539 | 1330 if (wsUseXShm) { |
1331 win->xImage = XShmCreateImage(wsDisplay, win->VisualInfo.visual, | |
35682 | 1332 win->VisualInfo.depth, ZPixmap, NULL, &win->Shminfo, w, h); |
33539 | 1333 |
1334 if (win->xImage == NULL) { | |
1335 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ShmError); | |
33768 | 1336 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1337 } |
1338 | |
1339 win->Shminfo.shmid = shmget(IPC_PRIVATE, win->xImage->bytes_per_line * win->xImage->height, IPC_CREAT | 0777); | |
1340 | |
1341 if (win->Shminfo.shmid < 0) { | |
1342 XDestroyImage(win->xImage); | |
1343 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ShmError); | |
33768 | 1344 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1345 } |
1346 | |
1347 win->Shminfo.shmaddr = (char *)shmat(win->Shminfo.shmid, 0, 0); | |
1348 | |
1349 if (win->Shminfo.shmaddr == ((char *)-1)) { | |
1350 XDestroyImage(win->xImage); | |
23077 | 1351 |
33539 | 1352 if (win->Shminfo.shmaddr != ((char *)-1)) |
1353 shmdt(win->Shminfo.shmaddr); | |
1354 | |
1355 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ShmError); | |
33768 | 1356 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1357 } |
1358 | |
1359 win->xImage->data = win->Shminfo.shmaddr; | |
35493 | 1360 win->Shminfo.readOnly = False; |
33539 | 1361 XShmAttach(wsDisplay, &win->Shminfo); |
1362 XSync(wsDisplay, False); | |
1363 shmctl(win->Shminfo.shmid, IPC_RMID, 0); | |
34465 | 1364 } else |
1365 #endif | |
1366 { | |
33539 | 1367 win->xImage = XCreateImage(wsDisplay, win->VisualInfo.visual, win->VisualInfo.depth, |
35682 | 1368 ZPixmap, 0, 0, w, h, |
35676 | 1369 (wsScreenDepth == 3) ? 32 : wsScreenDepth, |
33539 | 1370 0); |
1371 | |
1372 if ((win->xImage->data = malloc(win->xImage->bytes_per_line * win->xImage->height)) == NULL) { | |
1373 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_NotEnoughMemoryDrawBuffer); | |
33768 | 1374 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1375 } |
23077 | 1376 } |
33539 | 1377 |
1378 win->ImageData = (unsigned char *)win->xImage->data; | |
1379 win->ImageDataw = (unsigned short int *)win->xImage->data; | |
1380 win->ImageDatadw = (unsigned int *)win->xImage->data; | |
23077 | 1381 } |
1382 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1383 void wsImageDestroy(wsWindow *win) |
35672 | 1384 { |
1385 if (win->xImage) { | |
1386 XDestroyImage(win->xImage); | |
1387 | |
1388 #ifdef HAVE_SHM | |
1389 if (wsUseXShm) { | |
1390 XShmDetach(wsDisplay, &win->Shminfo); | |
1391 shmdt(win->Shminfo.shmaddr); | |
1392 } | |
1393 #endif | |
1394 } | |
1395 | |
1396 win->xImage = NULL; | |
1397 } | |
1398 | |
35744 | 1399 void wsImageRender(wsWindow *win, unsigned char *img) |
35672 | 1400 { |
1401 static struct SwsContext *sws_ctx; | |
35682 | 1402 const uint8_t *src[4] = { img, NULL, NULL, NULL }; |
35672 | 1403 int src_stride[4] = { 4 * win->xImage->width, 0, 0, 0 }; |
1404 uint8_t *dst[4] = { win->ImageData, NULL, NULL, NULL }; | |
1405 int dst_stride[4]; | |
1406 int i; | |
1407 | |
1408 sws_ctx = sws_getCachedContext(sws_ctx, win->xImage->width, win->xImage->height, PIX_FMT_RGB32, | |
1409 win->xImage->width, win->xImage->height, out_pix_fmt, | |
1410 SWS_POINT, NULL, NULL, NULL); | |
1411 av_image_fill_linesizes(dst_stride, out_pix_fmt, win->xImage->width); | |
1412 sws_scale(sws_ctx, src, src_stride, 0, win->xImage->height, dst, dst_stride); | |
1413 | |
1414 if (!wsNonNativeOrder) | |
1415 return; | |
1416 | |
1417 switch (win->xImage->bits_per_pixel) { | |
1418 case 32: | |
1419 { | |
1420 uint32_t *d = (uint32_t *)win->ImageData; | |
1421 | |
1422 for (i = 0; i < win->xImage->width * win->xImage->height; i++) | |
1423 d[i] = bswap_32(d[i]); | |
1424 | |
1425 break; | |
1426 } | |
1427 | |
1428 case 16: | |
1429 case 15: | |
1430 { | |
1431 uint16_t *d = (uint16_t *)win->ImageData; | |
1432 | |
1433 for (i = 0; i < win->xImage->width * win->xImage->height; i++) | |
1434 d[i] = bswap_16(d[i]); | |
1435 | |
1436 break; | |
1437 } | |
1438 } | |
1439 } | |
1440 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1441 void wsImageDraw(wsWindow *win) |
35672 | 1442 { |
1443 #ifdef HAVE_SHM | |
1444 if (wsUseXShm) { | |
1445 XShmPutImage(wsDisplay, win->WindowID, win->wGC, win->xImage, | |
1446 0, 0, | |
1447 (win->Width - win->xImage->width) / 2, (win->Height - win->xImage->height) / 2, | |
1448 win->xImage->width, win->xImage->height, 0); | |
1449 } else | |
1450 #endif | |
1451 { | |
1452 XPutImage(wsDisplay, win->WindowID, win->wGC, win->xImage, | |
1453 0, 0, | |
1454 (win->Width - win->xImage->width) / 2, (win->Height - win->xImage->height) / 2, | |
1455 win->xImage->width, win->xImage->height); | |
1456 } | |
1457 } | |
1458 | |
35682 | 1459 void wsImageResize(wsWindow *win, int w, int h) |
33539 | 1460 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1461 wsImageDestroy(win); |
35682 | 1462 wsImageCreate(win, w, h); |
33539 | 1463 } |
23077 | 1464 |
35672 | 1465 // ---------------------------------------------------------------------------------------------- |
1466 // Show / hide mouse cursor. | |
1467 // ---------------------------------------------------------------------------------------------- | |
35682 | 1468 void wsMouseVisibility(wsWindow *win, int vis) |
23077 | 1469 { |
35682 | 1470 switch (vis) { |
35672 | 1471 case wsShowMouseCursor: |
33539 | 1472 |
35672 | 1473 if (win->wsCursor != None) { |
1474 XFreeCursor(wsDisplay, win->wsCursor); | |
1475 win->wsCursor = None; | |
1476 } | |
33539 | 1477 |
35672 | 1478 XDefineCursor(wsDisplay, win->WindowID, 0); |
1479 break; | |
33539 | 1480 |
35672 | 1481 case wsHideMouseCursor: |
33539 | 1482 |
35672 | 1483 win->wsCursor = XCreatePixmapCursor(wsDisplay, win->wsCursorPixmap, win->wsCursorPixmap, &win->wsColor, &win->wsColor, 0, 0); |
1484 XDefineCursor(wsDisplay, win->WindowID, win->wsCursor); | |
1485 break; | |
1486 } | |
33539 | 1487 |
35672 | 1488 XFlush(wsDisplay); |
23077 | 1489 } |
1490 | |
35639 | 1491 /** |
35672 | 1492 * @brief Handle automatic hiding of the cursor. |
35639 | 1493 */ |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1494 void wsMouseAutohide(void) |
23077 | 1495 { |
35672 | 1496 if (mouse_win && (GetTimerMS() - mouse_time >= MOUSEHIDE_DELAY)) { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1497 wsMouseVisibility(mouse_win, wsHideMouseCursor); |
35672 | 1498 mouse_win = NULL; |
33542 | 1499 } |
23077 | 1500 } |