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