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