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