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