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