Mercurial > mplayer.hg
annotate gui/wm/ws.c @ 36194:829983f984ad
Handle events while waiting for window being mapped.
Reported by Jens Stimpfle, debian jstimpfle de.
author | ib |
---|---|
date | Sun, 26 May 2013 15:54:34 +0000 |
parents | 9beb155c77a0 |
children | 9a319cd3ee66 |
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) { |
36194 | 758 do { |
35652 | 759 XNextEvent(wsDisplay, &xev); |
36194 | 760 wsEvent(&xev); |
761 } while (xev.type != MapNotify || xev.xmap.event != win->WindowID); | |
35653 | 762 |
763 win->Mapped = wsMapped; | |
764 } | |
35652 | 765 } |
766 | |
23077 | 767 // ---------------------------------------------------------------------------------------------- |
768 // Create window. | |
769 // X,Y : window position | |
770 // wX,wY : size of window | |
771 // bW : border width | |
772 // cV : visible mouse cursor on window | |
773 // D : visible frame, title, etc. | |
774 // sR : screen ratio | |
775 // ---------------------------------------------------------------------------------------------- | |
776 | |
33539 | 777 XClassHint wsClassHint; |
778 XTextProperty wsTextProperty; | |
779 Window LeaderWindow; | |
23077 | 780 |
35655 | 781 // ---------------------------------------------------------------------------------------------- |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
782 // wsWindowCreate: create a new window on the screen. |
35655 | 783 // x,y : window position |
784 // w,h : window size | |
785 // c : mouse cursor visible | |
786 // p : properties - "decoration", visible titlebar, etc ... | |
787 // ---------------------------------------------------------------------------------------------- | |
35687 | 788 void wsWindowCreate(wsWindow *win, int x, int y, int w, int h, int p, int c, char *label) |
23077 | 789 { |
36193 | 790 int i, depth; |
33539 | 791 |
36193 | 792 for (i = 0; i < wsWLCount; i++) |
793 if (wsWindowList[i] == NULL) | |
794 break; | |
36192 | 795 |
36193 | 796 if (i == wsWLCount) { |
797 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_TooManyOpenWindows); | |
798 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); | |
799 } | |
36192 | 800 |
36193 | 801 wsWindowList[i] = win; |
36192 | 802 |
35655 | 803 win->Property = p; |
23077 | 804 |
35697 | 805 win->Decoration = ((p & wsShowFrame) != 0); |
33539 | 806 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
807 wsWindowUpdatePosition(win, x, y, w, h); |
33539 | 808 |
35655 | 809 win->Width = w; |
810 win->Height = h; | |
33539 | 811 win->OldX = win->X; |
812 win->OldY = win->Y; | |
813 win->OldWidth = win->Width; | |
814 win->OldHeight = win->Height; | |
23077 | 815 |
34684 | 816 /* Hide Mouse Cursor */ |
33539 | 817 win->wsCursor = None; |
35655 | 818 win->wsMouseEventType = c; |
33539 | 819 win->wsCursorData[0] = 0; |
820 win->wsCursorPixmap = XCreateBitmapFromData(wsDisplay, wsRootWin, win->wsCursorData, 1, 1); | |
23077 | 821 |
35655 | 822 if (!(c & wsShowMouseCursor)) |
33539 | 823 win->wsCursor = XCreatePixmapCursor(wsDisplay, win->wsCursorPixmap, win->wsCursorPixmap, &win->wsColor, &win->wsColor, 0, 0); |
824 | |
825 depth = vo_find_depth_from_visuals(wsDisplay, wsScreen, NULL); | |
826 | |
827 if (depth < 15) { | |
828 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ColorDepthTooLow); | |
33768 | 829 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 830 } |
831 | |
832 XMatchVisualInfo(wsDisplay, wsScreen, depth, TrueColor, &win->VisualInfo); | |
23077 | 833 |
34684 | 834 /* --- */ |
33539 | 835 win->AtomLeaderClient = XInternAtom(wsDisplay, "WM_CLIENT_LEADER", False); |
836 win->AtomDeleteWindow = XInternAtom(wsDisplay, "WM_DELETE_WINDOW", False); | |
837 win->AtomTakeFocus = XInternAtom(wsDisplay, "WM_TAKE_FOCUS", False); | |
838 win->AtomRolle = XInternAtom(wsDisplay, "WM_WINDOW_ROLE", False); | |
839 win->AtomWMSizeHint = XInternAtom(wsDisplay, "WM_SIZE_HINT", False); | |
840 win->AtomWMNormalHint = XInternAtom(wsDisplay, "WM_NORMAL_HINT", False); | |
841 win->AtomProtocols = XInternAtom(wsDisplay, "WM_PROTOCOLS", False); | |
842 win->AtomsProtocols[0] = win->AtomDeleteWindow; | |
843 win->AtomsProtocols[1] = win->AtomTakeFocus; | |
844 win->AtomsProtocols[2] = win->AtomRolle; | |
34684 | 845 /* --- */ |
23077 | 846 |
35737 | 847 win->WindowAttrib.border_pixel = WhitePixel(wsDisplay, wsScreen); |
848 win->WindowAttrib.colormap = XCreateColormap(wsDisplay, wsRootWin, win->VisualInfo.visual, AllocNone); | |
849 win->WindowAttrib.event_mask = StructureNotifyMask | FocusChangeMask | | |
850 ExposureMask | PropertyChangeMask | | |
851 EnterWindowMask | LeaveWindowMask | | |
852 VisibilityChangeMask | | |
853 KeyPressMask | KeyReleaseMask; | |
23077 | 854 |
35655 | 855 if ((c & wsHandleMouseButton)) |
33539 | 856 win->WindowAttrib.event_mask |= ButtonPressMask | ButtonReleaseMask; |
857 | |
35655 | 858 if ((c & wsHandleMouseMove)) |
33539 | 859 win->WindowAttrib.event_mask |= PointerMotionMask; |
860 | |
861 win->WindowAttrib.cursor = win->wsCursor; | |
862 win->WindowAttrib.override_redirect = False; | |
863 | |
35655 | 864 if (p & wsOverredirect) |
33539 | 865 win->WindowAttrib.override_redirect = True; |
23077 | 866 |
35736
f1a696672425
Remove setting pointless window attribute CWBackPixel.
ib
parents:
35734
diff
changeset
|
867 win->WindowMask = CWBorderPixel | |
33539 | 868 CWColormap | CWEventMask | CWCursor | |
869 CWOverrideRedirect; | |
23077 | 870 |
33539 | 871 win->WindowID = XCreateWindow(wsDisplay, |
872 (win->Parent != 0 ? win->Parent : wsRootWin), | |
35683
75155d8a9c7e
Remove parameter for border_width from wsWindowCreate().
ib
parents:
35682
diff
changeset
|
873 win->X, win->Y, win->Width, win->Height, 0, |
33539 | 874 win->VisualInfo.depth, |
875 InputOutput, | |
876 win->VisualInfo.visual, | |
877 win->WindowMask, &win->WindowAttrib); | |
23077 | 878 |
36055 | 879 wsClassHint.res_name = "GUI"; |
33539 | 880 |
36053 | 881 wsClassHint.res_class = MPlayer; |
33539 | 882 XSetClassHint(wsDisplay, win->WindowID, &wsClassHint); |
883 | |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
884 wsWindowSizeHint(win); |
23077 | 885 |
33539 | 886 win->WMHints.flags = InputHint | StateHint; |
887 win->WMHints.input = True; | |
888 win->WMHints.initial_state = NormalState; | |
889 XSetWMHints(wsDisplay, win->WindowID, &win->WMHints); | |
23077 | 890 |
35697 | 891 wsWindowDecoration(win); |
33539 | 892 XStoreName(wsDisplay, win->WindowID, label); |
893 XmbSetWMProperties(wsDisplay, win->WindowID, label, label, NULL, 0, NULL, NULL, NULL); | |
23077 | 894 |
33539 | 895 XSetWMProtocols(wsDisplay, win->WindowID, win->AtomsProtocols, 3); |
896 XChangeProperty(wsDisplay, win->WindowID, | |
897 win->AtomLeaderClient, | |
898 XA_WINDOW, 32, PropModeReplace, | |
899 (unsigned char *)&LeaderWindow, 1); | |
23077 | 900 |
33539 | 901 wsTextProperty.value = label; |
902 wsTextProperty.encoding = XA_STRING; | |
903 wsTextProperty.format = 8; | |
904 wsTextProperty.nitems = strlen(label); | |
905 XSetWMIconName(wsDisplay, win->WindowID, &wsTextProperty); | |
906 | |
907 win->wGC = XCreateGC(wsDisplay, win->WindowID, | |
35679 | 908 0, |
909 NULL); | |
23077 | 910 |
35498
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
911 win->Visible = wsNo; |
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
912 win->Focused = wsNo; |
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
913 win->Mapped = wsNo; |
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
914 win->Rolled = wsNo; |
23077 | 915 |
35655 | 916 if (p & wsShowWindow) { |
33539 | 917 XMapWindow(wsDisplay, win->WindowID); |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
918 wsWindowMapWait(win); |
35652 | 919 } |
23077 | 920 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
921 wsImageCreate(win, win->Width, win->Height); |
34684 | 922 /* End of creating -------------------------------------------------------------------------- */ |
23077 | 923 |
33539 | 924 XFlush(wsDisplay); |
925 XSync(wsDisplay, False); | |
23077 | 926 |
35760 | 927 win->DrawHandler = NULL; |
33539 | 928 win->MouseHandler = NULL; |
929 win->KeyHandler = NULL; | |
33985 | 930 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] window is created. ( %s ).\n", label); |
23077 | 931 } |
932 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
933 void wsWindowDestroy(wsWindow *win) |
23077 | 934 { |
33539 | 935 int l; |
936 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
937 l = wsWindowListSearch(win->WindowID); |
35354 | 938 |
939 if (l != -1) | |
940 wsWindowList[l] = NULL; | |
33539 | 941 |
35760 | 942 win->DrawHandler = NULL; |
35752 | 943 win->MouseHandler = NULL; |
944 win->KeyHandler = NULL; | |
35759 | 945 win->DNDHandler = NULL; |
35752 | 946 |
33539 | 947 if (win->wsCursor != None) { |
948 XFreeCursor(wsDisplay, win->wsCursor); | |
949 win->wsCursor = None; | |
950 } | |
951 | |
952 XFreeGC(wsDisplay, win->wGC); | |
953 XUnmapWindow(wsDisplay, win->WindowID); | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
954 wsImageDestroy(win); |
33539 | 955 XDestroyWindow(wsDisplay, win->WindowID); |
23077 | 956 #if 0 |
35753 | 957 win->Visible = wsNo; |
958 win->Focused = wsNo; | |
959 win->Mapped = wsNo; | |
960 win->Rolled = wsNo; | |
23077 | 961 #endif |
962 } | |
963 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
964 void wsWindowShape(wsWindow *win, char *data) |
35672 | 965 { |
966 #ifdef CONFIG_XSHAPE | |
967 if (!wsUseXShape) | |
968 return; | |
969 | |
970 if (data) { | |
971 win->Mask = XCreateBitmapFromData(wsDisplay, win->WindowID, data, win->Width, win->Height); | |
972 XShapeCombineMask(wsDisplay, win->WindowID, ShapeBounding, 0, 0, win->Mask, ShapeSet); | |
973 XFreePixmap(wsDisplay, win->Mask); | |
974 } else | |
975 XShapeCombineMask(wsDisplay, win->WindowID, ShapeBounding, 0, 0, None, ShapeSet); | |
976 #endif | |
977 } | |
978 | |
34081 | 979 /** |
35672 | 980 * @brief Set differently sized icons to a window. |
981 * | |
982 * This function sets the X icon hint as well as | |
983 * the properties KWM_WIN_ICON and _NET_WM_ICON. | |
984 * | |
985 * @param display display | |
986 * @param Win window | |
987 * @param icon pointer to the icons | |
34081 | 988 */ |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
989 void wsWindowIcon(Display *display, Window Win, guiIcon_t *icon) |
34081 | 990 { |
35672 | 991 XWMHints *wm; |
992 Atom iconatom; | |
993 long data[2]; | |
994 | |
995 if (icon->normal) { | |
996 wm = XGetWMHints(display, Win); | |
997 | |
998 if (!wm) | |
999 wm = XAllocWMHints(); | |
1000 | |
1001 wm->icon_pixmap = icon->normal; | |
1002 wm->icon_mask = icon->normal_mask; | |
1003 wm->flags |= IconPixmapHint | IconMaskHint; | |
1004 | |
1005 XSetWMHints(display, Win, wm); | |
1006 XFree(wm); | |
1007 } | |
1008 | |
1009 if (icon->small || icon->normal) { | |
1010 iconatom = XInternAtom(display, "KWM_WIN_ICON", False); | |
1011 data[0] = (icon->small ? icon->small : icon->normal); | |
1012 data[1] = (icon->small ? icon->small_mask : icon->normal_mask); | |
1013 | |
1014 XChangeProperty(display, Win, iconatom, iconatom, 32, PropModeReplace, (unsigned char *)data, 2); | |
1015 } | |
1016 | |
1017 if (icon->collection) { | |
1018 iconatom = XInternAtom(display, "_NET_WM_ICON", False); | |
1019 XChangeProperty(display, Win, iconatom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)icon->collection, icon->collection_size); | |
34081 | 1020 } |
1021 } | |
1022 | |
35730 | 1023 /** |
1024 * @brief Pack color components @a r, @a g and @a b into 15 bits. | |
1025 * | |
1026 * @param r red (0 - 255) | |
1027 * @param g green (0 - 255) | |
1028 * @param b blue (0 - 255) | |
1029 * | |
1030 * @return pixel suitable for a RGB 15 bits color format | |
1031 */ | |
1032 static int pack_rgb15(int r, int g, int b) | |
1033 { | |
1034 int pixel; | |
1035 | |
35734 | 1036 pixel = r >> 3; |
35730 | 1037 pixel <<= 5; |
35734 | 1038 pixel |= g >> 3; |
35730 | 1039 pixel <<= 5; |
35734 | 1040 pixel |= b >> 3; |
35730 | 1041 |
1042 return pixel; | |
1043 } | |
1044 | |
1045 /** | |
1046 * @brief Pack color components @a r, @a g and @a b into 16 bits. | |
1047 * | |
1048 * @param r red (0 - 255) | |
1049 * @param g green (0 - 255) | |
1050 * @param b blue (0 - 255) | |
1051 * | |
1052 * @return pixel suitable for a RGB 16 bits color format | |
1053 */ | |
1054 static int pack_rgb16(int r, int g, int b) | |
1055 { | |
1056 int pixel; | |
1057 | |
35734 | 1058 pixel = r >> 3; |
35730 | 1059 pixel <<= 6; |
35734 | 1060 pixel |= g >> 2; |
35730 | 1061 pixel <<= 5; |
35734 | 1062 pixel |= b >> 3; |
35730 | 1063 |
1064 return pixel; | |
1065 } | |
1066 | |
35755
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1067 /** |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1068 * @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
|
1069 * |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1070 * @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
|
1071 * @param r red (0 - 255, or -1) |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1072 * @param g green (0 - 255, or -1) |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1073 * @param b blue (0 - 255, or -1) |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1074 * |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1075 * @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
|
1076 */ |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1077 void wsWindowBackground(wsWindow *win, int r, int g, int b) |
23077 | 1078 { |
35672 | 1079 int color = 0; |
35541 | 1080 |
35733 | 1081 switch (out_pix_fmt) { |
1082 case PIX_FMT_RGB32: | |
1083 case PIX_FMT_RGB24: | |
35672 | 1084 color = (r << 16) + (g << 8) + b; |
23077 | 1085 break; |
1086 | |
35733 | 1087 case PIX_FMT_BGR32: |
1088 case PIX_FMT_BGR24: | |
35672 | 1089 color = (b << 16) + (g << 8) + r; |
1090 break; | |
33539 | 1091 |
35733 | 1092 case PIX_FMT_RGB565: |
35730 | 1093 color = pack_rgb16(r, g, b); |
23077 | 1094 break; |
1095 | |
35733 | 1096 case PIX_FMT_BGR565: |
35730 | 1097 color = pack_rgb16(b, g, r); |
35728 | 1098 break; |
1099 | |
35733 | 1100 case PIX_FMT_RGB555: |
35730 | 1101 color = pack_rgb15(r, g, b); |
23077 | 1102 break; |
1103 | |
35733 | 1104 case PIX_FMT_BGR555: |
35730 | 1105 color = pack_rgb15(b, g, r); |
33539 | 1106 break; |
35733 | 1107 |
1108 default: | |
1109 ; | |
33539 | 1110 } |
1111 | |
35755
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1112 if (r == -1 && g == -1 && b == -1) |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1113 XSetWindowBackgroundPixmap(wsDisplay, win->WindowID, None); |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1114 else { |
35756 | 1115 XSetWindowBackground(wsDisplay, win->WindowID, color); |
1116 XClearWindow(wsDisplay, win->WindowID); | |
35755
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1117 } |
23077 | 1118 } |
1119 | |
1120 // ---------------------------------------------------------------------------------------------- | |
1121 // Move window to x, y. | |
1122 // ---------------------------------------------------------------------------------------------- | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1123 void wsWindowMove(wsWindow *win, Bool abs, int x, int y) |
23077 | 1124 { |
33993 | 1125 if (abs) { |
1126 win->X = x; | |
1127 win->Y = y; | |
33995 | 1128 } else |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1129 wsWindowUpdatePosition(win, x, y, win->Width, win->Height); |
23077 | 1130 |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
1131 wsWindowSizeHint(win); |
33539 | 1132 XMoveWindow(wsDisplay, win->WindowID, win->X, win->Y); |
23077 | 1133 } |
1134 | |
33998
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1135 /** |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1136 * @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
|
1137 * 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
|
1138 * |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1139 * @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
|
1140 * @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
|
1141 * @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
|
1142 * @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
|
1143 */ |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1144 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
|
1145 { |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1146 Bool fitting = True; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1147 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1148 wsWindowMove(win, abs, x, y); |
33998
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1149 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1150 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
|
1151 fitting = False; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1152 win->X = wsMaxX - win->Width; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1153 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1154 if (win->X < 0) |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1155 win->X = 0; |
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 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1158 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
|
1159 fitting = False; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1160 win->Y = wsMaxY - win->Height; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1161 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1162 if (win->Y < 0) |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1163 win->Y = 0; |
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 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1166 if (!fitting) |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1167 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
|
1168 } |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1169 |
23077 | 1170 // ---------------------------------------------------------------------------------------------- |
1171 // Resize window to sx, sy. | |
1172 // ---------------------------------------------------------------------------------------------- | |
35682 | 1173 void wsWindowResize(wsWindow *win, int w, int h) |
23077 | 1174 { |
35682 | 1175 win->Width = w; |
1176 win->Height = h; | |
23077 | 1177 |
33539 | 1178 if (vo_wm_type == 0) |
1179 XUnmapWindow(wsDisplay, win->WindowID); | |
23077 | 1180 |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
1181 wsWindowSizeHint(win); |
35682 | 1182 XResizeWindow(wsDisplay, win->WindowID, w, h); |
33539 | 1183 |
34124 | 1184 if (vo_wm_type == 0) |
1185 XMapWindow(wsDisplay, win->WindowID); | |
23077 | 1186 } |
1187 | |
35355 | 1188 /** |
35672 | 1189 * @brief Switch window fullscreen state. |
1190 * | |
1191 * Switch normal window to fullscreen and fullscreen window to normal. | |
1192 * | |
1193 * @param win pointer to a ws window structure | |
1194 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1195 void wsWindowFullscreen(wsWindow *win) |
35672 | 1196 { |
1197 if (win->isFullScreen) { | |
1198 if (vo_fs_type & vo_wm_FULLSCREEN) | |
1199 /* window manager supports EWMH */ | |
1200 vo_x11_ewmh_fullscreen(win->WindowID, _NET_WM_STATE_REMOVE); | |
1201 else { | |
1202 win->X = win->OldX; | |
1203 win->Y = win->OldY; | |
1204 win->Width = win->OldWidth; | |
1205 win->Height = win->OldHeight; | |
1206 } | |
1207 | |
1208 win->isFullScreen = False; | |
1209 } else { | |
1210 if (vo_fs_type & vo_wm_FULLSCREEN) | |
1211 /* window manager supports EWMH */ | |
1212 vo_x11_ewmh_fullscreen(win->WindowID, _NET_WM_STATE_ADD); | |
1213 else { | |
1214 win->OldX = win->X; | |
1215 win->OldY = win->Y; | |
1216 win->OldWidth = win->Width; | |
1217 win->OldHeight = win->Height; | |
1218 } | |
1219 | |
1220 win->isFullScreen = True; | |
1221 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1222 wsWindowUpdateXinerama(win); |
35672 | 1223 } |
1224 | |
1225 /* unknown window manager and obsolete option -fsmode used */ | |
1226 if (vo_wm_type == 0 && !(vo_fsmode & 16)) { | |
1227 XUnmapWindow(wsDisplay, win->WindowID); // required for MWM | |
1228 XWithdrawWindow(wsDisplay, win->WindowID, wsScreen); | |
1229 } | |
1230 | |
1231 /* restore window if window manager doesn't support EWMH */ | |
1232 if (!(vo_fs_type & vo_wm_FULLSCREEN)) { | |
35697 | 1233 if (!win->isFullScreen) |
1234 wsWindowDecoration(win); | |
1235 | |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
1236 wsWindowSizeHint(win); |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1237 wsWindowLayer(wsDisplay, win->WindowID, win->isFullScreen); |
35672 | 1238 XMoveResizeWindow(wsDisplay, win->WindowID, win->X, win->Y, win->Width, win->Height); |
1239 } | |
1240 | |
1241 /* some window managers lose ontop after fullscreen */ | |
1242 if (!win->isFullScreen & vo_ontop) | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1243 wsWindowLayer(wsDisplay, win->WindowID, vo_ontop); |
35672 | 1244 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1245 wsWindowRaiseTop(wsDisplay, win->WindowID); |
35672 | 1246 XFlush(wsDisplay); |
1247 } | |
1248 | |
1249 /** | |
35355 | 1250 * @brief Iconify a window. |
1251 * | |
1252 * @param win pointer to a ws window structure | |
1253 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1254 void wsWindowIconify(wsWindow *win) |
33539 | 1255 { |
35355 | 1256 XIconifyWindow(wsDisplay, win->WindowID, 0); |
33539 | 1257 } |
23077 | 1258 |
35682 | 1259 void wsWindowVisibility(wsWindow *win, int vis) |
23077 | 1260 { |
35682 | 1261 switch (vis) { |
33539 | 1262 case wsShowWindow: |
35541 | 1263 |
33539 | 1264 XMapRaised(wsDisplay, win->WindowID); |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
1265 wsWindowMapWait(win); |
35541 | 1266 |
33952 | 1267 if (vo_fs_type & vo_wm_FULLSCREEN) |
1268 win->isFullScreen = False; | |
35541 | 1269 |
33539 | 1270 break; |
1271 | |
1272 case wsHideWindow: | |
35541 | 1273 |
33539 | 1274 XUnmapWindow(wsDisplay, win->WindowID); |
1275 break; | |
1276 } | |
1277 | |
1278 XFlush(wsDisplay); | |
23077 | 1279 } |
1280 | |
35672 | 1281 /** |
1282 * @brief Map a window and raise it to the top. | |
1283 * | |
1284 * @param display display | |
1285 * @param Win window | |
1286 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1287 void wsWindowRaiseTop(Display *display, Window Win) |
23077 | 1288 { |
35672 | 1289 XMapRaised(display, Win); // NOTE TO MYSELF: is that really enough? |
1290 XRaiseWindow(display, Win); // NOTE TO MYSELF: is that really enough? | |
23077 | 1291 } |
1292 | |
35672 | 1293 // ---------------------------------------------------------------------------------------------- |
1294 // Move window to selected layer | |
1295 // ---------------------------------------------------------------------------------------------- | |
1296 | |
1297 /** | |
1298 * @brief Set the layer for a window. | |
1299 * | |
1300 * @param display display | |
1301 * @param Win window | |
1302 * @param fullscreen whether to set fullscreen or normal layer | |
1303 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1304 void wsWindowLayer(Display *display, Window Win, Bool fullscreen) |
35672 | 1305 { |
1306 vo_x11_setlayer(display, Win, fullscreen); | |
1307 } | |
1308 | |
1309 // ---------------------------------------------------------------------------------------------- | |
1310 // Redraw screen. | |
1311 // ---------------------------------------------------------------------------------------------- | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1312 void wsWindowRedraw(wsWindow *win) |
35672 | 1313 { |
35760 | 1314 if (win->DrawHandler) { |
35672 | 1315 win->State = wsWindowExpose; |
35760 | 1316 win->DrawHandler(); |
35672 | 1317 XFlush(wsDisplay); |
1318 } | |
1319 } | |
1320 | |
1321 // ---------------------------------------------------------------------------------------------- | |
1322 // Put 'Image' to window. | |
1323 // ---------------------------------------------------------------------------------------------- | |
35682 | 1324 void wsImageCreate(wsWindow *win, int w, int h) |
23077 | 1325 { |
34465 | 1326 #ifdef HAVE_SHM |
33539 | 1327 if (wsUseXShm) { |
1328 win->xImage = XShmCreateImage(wsDisplay, win->VisualInfo.visual, | |
35682 | 1329 win->VisualInfo.depth, ZPixmap, NULL, &win->Shminfo, w, h); |
33539 | 1330 |
1331 if (win->xImage == NULL) { | |
1332 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ShmError); | |
33768 | 1333 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1334 } |
1335 | |
1336 win->Shminfo.shmid = shmget(IPC_PRIVATE, win->xImage->bytes_per_line * win->xImage->height, IPC_CREAT | 0777); | |
1337 | |
1338 if (win->Shminfo.shmid < 0) { | |
1339 XDestroyImage(win->xImage); | |
1340 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ShmError); | |
33768 | 1341 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1342 } |
1343 | |
1344 win->Shminfo.shmaddr = (char *)shmat(win->Shminfo.shmid, 0, 0); | |
1345 | |
1346 if (win->Shminfo.shmaddr == ((char *)-1)) { | |
1347 XDestroyImage(win->xImage); | |
23077 | 1348 |
33539 | 1349 if (win->Shminfo.shmaddr != ((char *)-1)) |
1350 shmdt(win->Shminfo.shmaddr); | |
1351 | |
1352 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ShmError); | |
33768 | 1353 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1354 } |
1355 | |
1356 win->xImage->data = win->Shminfo.shmaddr; | |
35493 | 1357 win->Shminfo.readOnly = False; |
33539 | 1358 XShmAttach(wsDisplay, &win->Shminfo); |
1359 XSync(wsDisplay, False); | |
1360 shmctl(win->Shminfo.shmid, IPC_RMID, 0); | |
34465 | 1361 } else |
1362 #endif | |
1363 { | |
33539 | 1364 win->xImage = XCreateImage(wsDisplay, win->VisualInfo.visual, win->VisualInfo.depth, |
35682 | 1365 ZPixmap, 0, 0, w, h, |
35676 | 1366 (wsScreenDepth == 3) ? 32 : wsScreenDepth, |
33539 | 1367 0); |
1368 | |
1369 if ((win->xImage->data = malloc(win->xImage->bytes_per_line * win->xImage->height)) == NULL) { | |
1370 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_NotEnoughMemoryDrawBuffer); | |
33768 | 1371 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1372 } |
23077 | 1373 } |
33539 | 1374 |
1375 win->ImageData = (unsigned char *)win->xImage->data; | |
1376 win->ImageDataw = (unsigned short int *)win->xImage->data; | |
1377 win->ImageDatadw = (unsigned int *)win->xImage->data; | |
23077 | 1378 } |
1379 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1380 void wsImageDestroy(wsWindow *win) |
35672 | 1381 { |
1382 if (win->xImage) { | |
1383 XDestroyImage(win->xImage); | |
1384 | |
1385 #ifdef HAVE_SHM | |
1386 if (wsUseXShm) { | |
1387 XShmDetach(wsDisplay, &win->Shminfo); | |
1388 shmdt(win->Shminfo.shmaddr); | |
1389 } | |
1390 #endif | |
1391 } | |
1392 | |
1393 win->xImage = NULL; | |
1394 } | |
1395 | |
35744 | 1396 void wsImageRender(wsWindow *win, unsigned char *img) |
35672 | 1397 { |
1398 static struct SwsContext *sws_ctx; | |
35682 | 1399 const uint8_t *src[4] = { img, NULL, NULL, NULL }; |
35672 | 1400 int src_stride[4] = { 4 * win->xImage->width, 0, 0, 0 }; |
1401 uint8_t *dst[4] = { win->ImageData, NULL, NULL, NULL }; | |
1402 int dst_stride[4]; | |
1403 int i; | |
1404 | |
1405 sws_ctx = sws_getCachedContext(sws_ctx, win->xImage->width, win->xImage->height, PIX_FMT_RGB32, | |
1406 win->xImage->width, win->xImage->height, out_pix_fmt, | |
1407 SWS_POINT, NULL, NULL, NULL); | |
1408 av_image_fill_linesizes(dst_stride, out_pix_fmt, win->xImage->width); | |
1409 sws_scale(sws_ctx, src, src_stride, 0, win->xImage->height, dst, dst_stride); | |
1410 | |
1411 if (!wsNonNativeOrder) | |
1412 return; | |
1413 | |
1414 switch (win->xImage->bits_per_pixel) { | |
1415 case 32: | |
1416 { | |
1417 uint32_t *d = (uint32_t *)win->ImageData; | |
1418 | |
1419 for (i = 0; i < win->xImage->width * win->xImage->height; i++) | |
1420 d[i] = bswap_32(d[i]); | |
1421 | |
1422 break; | |
1423 } | |
1424 | |
1425 case 16: | |
1426 case 15: | |
1427 { | |
1428 uint16_t *d = (uint16_t *)win->ImageData; | |
1429 | |
1430 for (i = 0; i < win->xImage->width * win->xImage->height; i++) | |
1431 d[i] = bswap_16(d[i]); | |
1432 | |
1433 break; | |
1434 } | |
1435 } | |
1436 } | |
1437 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1438 void wsImageDraw(wsWindow *win) |
35672 | 1439 { |
1440 #ifdef HAVE_SHM | |
1441 if (wsUseXShm) { | |
1442 XShmPutImage(wsDisplay, win->WindowID, win->wGC, win->xImage, | |
1443 0, 0, | |
1444 (win->Width - win->xImage->width) / 2, (win->Height - win->xImage->height) / 2, | |
1445 win->xImage->width, win->xImage->height, 0); | |
1446 } else | |
1447 #endif | |
1448 { | |
1449 XPutImage(wsDisplay, win->WindowID, win->wGC, win->xImage, | |
1450 0, 0, | |
1451 (win->Width - win->xImage->width) / 2, (win->Height - win->xImage->height) / 2, | |
1452 win->xImage->width, win->xImage->height); | |
1453 } | |
1454 } | |
1455 | |
35682 | 1456 void wsImageResize(wsWindow *win, int w, int h) |
33539 | 1457 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1458 wsImageDestroy(win); |
35682 | 1459 wsImageCreate(win, w, h); |
33539 | 1460 } |
23077 | 1461 |
35672 | 1462 // ---------------------------------------------------------------------------------------------- |
1463 // Show / hide mouse cursor. | |
1464 // ---------------------------------------------------------------------------------------------- | |
35682 | 1465 void wsMouseVisibility(wsWindow *win, int vis) |
23077 | 1466 { |
35682 | 1467 switch (vis) { |
35672 | 1468 case wsShowMouseCursor: |
33539 | 1469 |
35672 | 1470 if (win->wsCursor != None) { |
1471 XFreeCursor(wsDisplay, win->wsCursor); | |
1472 win->wsCursor = None; | |
1473 } | |
33539 | 1474 |
35672 | 1475 XDefineCursor(wsDisplay, win->WindowID, 0); |
1476 break; | |
33539 | 1477 |
35672 | 1478 case wsHideMouseCursor: |
33539 | 1479 |
35672 | 1480 win->wsCursor = XCreatePixmapCursor(wsDisplay, win->wsCursorPixmap, win->wsCursorPixmap, &win->wsColor, &win->wsColor, 0, 0); |
1481 XDefineCursor(wsDisplay, win->WindowID, win->wsCursor); | |
1482 break; | |
1483 } | |
33539 | 1484 |
35672 | 1485 XFlush(wsDisplay); |
23077 | 1486 } |
1487 | |
35639 | 1488 /** |
35672 | 1489 * @brief Handle automatic hiding of the cursor. |
35639 | 1490 */ |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1491 void wsMouseAutohide(void) |
23077 | 1492 { |
35672 | 1493 if (mouse_win && (GetTimerMS() - mouse_time >= MOUSEHIDE_DELAY)) { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1494 wsMouseVisibility(mouse_win, wsHideMouseCursor); |
35672 | 1495 mouse_win = NULL; |
33542 | 1496 } |
23077 | 1497 } |