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