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