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