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