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