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