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