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