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