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