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