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