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