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