Mercurial > mplayer.hg
annotate gui/wm/ws.c @ 35728:168aae142525
Redefine PACK_RGB16 and PACK_RGB15.
First and third parameter were mixed up
which resulted in confusing calls.
author | ib |
---|---|
date | Tue, 22 Jan 2013 15:37:17 +0000 |
parents | 4ba6b8d3197e |
children | 330325df88ed |
rev | line source |
---|---|
26458 | 1 /* |
2 * This file is part of MPlayer. | |
3 * | |
4 * MPlayer is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; either version 2 of the License, or | |
7 * (at your option) any later version. | |
8 * | |
9 * MPlayer is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License along | |
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
35666
01ac3cd2f101
Cosmetic: Relocate and revise comments on code origin.
ib
parents:
35665
diff
changeset
|
17 * |
01ac3cd2f101
Cosmetic: Relocate and revise comments on code origin.
ib
parents:
35665
diff
changeset
|
18 * based on: AutoSpace Window System for Linux/Win32, |
01ac3cd2f101
Cosmetic: Relocate and revise comments on code origin.
ib
parents:
35665
diff
changeset
|
19 * written by pontscho/fresh!mindworkz |
26458 | 20 */ |
23077 | 21 |
35702 | 22 #include <stdint.h> |
23077 | 23 #include <stdlib.h> |
24 #include <string.h> | |
35702 | 25 #include <sys/ipc.h> |
26 #include <X11/Xatom.h> | |
23077 | 27 |
35702 | 28 #include "ws.h" |
29 #include "wsxdnd.h" | |
30 #include "gui/interface.h" | |
23077 | 31 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
23795
diff
changeset
|
32 #include "config.h" |
35702 | 33 #include "help_mp.h" |
34 #include "libavutil/imgutils.h" | |
35 #include "libavutil/pixfmt.h" | |
36 #include "libswscale/swscale.h" | |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
23795
diff
changeset
|
37 #include "libvo/video_out.h" |
35702 | 38 #include "libvo/x11_common.h" |
39 #include "mpbswap.h" | |
33264 | 40 #include "mp_core.h" |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
23795
diff
changeset
|
41 #include "mp_msg.h" |
34033 | 42 #include "osdep/timer.h" |
23077 | 43 |
35702 | 44 #ifdef HAVE_SHM |
45 #include <sys/shm.h> | |
46 #endif | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
47 #ifdef CONFIG_XSHAPE |
23077 | 48 #include <X11/extensions/shape.h> |
49 #endif | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
50 #ifdef CONFIG_XF86VM |
23077 | 51 #include <X11/extensions/xf86vmode.h> |
52 #endif | |
53 | |
34034
8c75091726d8
Replace numeric constant for cursor autohide time by symbolic constant.
ib
parents:
34033
diff
changeset
|
54 #define MOUSEHIDE_DELAY 1000 // in milliseconds |
8c75091726d8
Replace numeric constant for cursor autohide time by symbolic constant.
ib
parents:
34033
diff
changeset
|
55 |
35656 | 56 static wsWindow *mouse_win; |
34081 | 57 static unsigned int mouse_time; |
58 | |
35667 | 59 int wsMaxX; // Screen width. |
60 int wsMaxY; // Screen height. | |
61 int wsOrgX; // Screen origin x. | |
62 int wsOrgY; // Screen origin y. | |
23077 | 63 |
33539 | 64 Display *wsDisplay; |
35667 | 65 static int wsScreen; |
66 static Window wsRootWin; | |
23077 | 67 |
35678 | 68 static int wsScreenDepth; |
35667 | 69 static int wsRedMask; |
70 static int wsGreenMask; | |
71 static int wsBlueMask; | |
72 static int wsOutMask; | |
73 static int wsNonNativeOrder; | |
23077 | 74 |
33539 | 75 #define wsWLCount 5 |
35667 | 76 static wsWindow *wsWindowList[wsWLCount]; |
33539 | 77 |
35667 | 78 static int wsUseXShm = True; |
79 static int wsUseXShape = True; | |
23077 | 80 |
34684 | 81 /* --- */ |
23077 | 82 |
35728 | 83 #define PACK_RGB16(r, g, b, pixel) \ |
84 pixel = (r >> 3); \ | |
33539 | 85 pixel <<= 6; \ |
86 pixel |= (g >> 2); \ | |
87 pixel <<= 5; \ | |
35728 | 88 pixel |= (b >> 3) |
23077 | 89 |
35728 | 90 #define PACK_RGB15(r, g, b, pixel) \ |
91 pixel = (r >> 3); \ | |
33539 | 92 pixel <<= 5; \ |
93 pixel |= (g >> 3); \ | |
94 pixel <<= 5; \ | |
35728 | 95 pixel |= (b >> 3) |
23077 | 96 |
35707
4ba6b8d3197e
Replace PixelFormat and PIX_FMT_FOO by their AV_-prefixed counterparts.
diego
parents:
35702
diff
changeset
|
97 static enum AVPixelFormat out_pix_fmt = PIX_FMT_NONE; |
23077 | 98 |
34684 | 99 /* --- */ |
23077 | 100 |
101 #define MWM_HINTS_FUNCTIONS (1L << 0) | |
102 #define MWM_HINTS_DECORATIONS (1L << 1) | |
103 | |
104 #define MWM_FUNC_RESIZE (1L << 1) | |
105 #define MWM_FUNC_MOVE (1L << 2) | |
106 #define MWM_FUNC_MINIMIZE (1L << 3) | |
107 #define MWM_FUNC_MAXIMIZE (1L << 4) | |
108 #define MWM_FUNC_CLOSE (1L << 5) | |
109 | |
110 #define MWM_DECOR_ALL (1L << 0) | |
111 | |
33994
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
112 /** |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
113 * @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
|
114 * from xinerama information. |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
115 * |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
116 * Set wsOrgX, wsOrgY, wsMaxX and wsMaxY as well as |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
117 * win->X, win->Y, win->Width and win->Height. |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
118 * |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
119 * @param win pointer to a ws window structure or NULL |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
120 */ |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
121 static void wsWindowUpdateXinerama(wsWindow *win) |
33994
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
122 { |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
123 if (win) { |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
124 vo_dx = win->X; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
125 vo_dy = win->Y; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
126 vo_dwidth = win->Width; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
127 vo_dheight = win->Height; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
128 } |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
129 |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
130 vo_screenwidth = wsMaxX; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
131 vo_screenheight = wsMaxY; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
132 |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
133 update_xinerama_info(); |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
134 |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
135 wsMaxX = vo_screenwidth; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
136 wsMaxY = vo_screenheight; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
137 wsOrgX = xinerama_x; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
138 wsOrgY = xinerama_y; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
139 |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
140 if (win) { |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
141 win->X = wsOrgX; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
142 win->Y = wsOrgY; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
143 win->Width = wsMaxX; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
144 win->Height = wsMaxY; |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
145 } |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
146 } |
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
147 |
35676 | 148 static int wsGetScreenDepth(void) |
35636 | 149 { |
35672 | 150 int depth; |
151 XImage *mXImage; | |
152 Visual *visual; | |
153 | |
154 if ((depth = vo_find_depth_from_visuals(wsDisplay, wsScreen, &visual)) > 0) { | |
155 mXImage = XCreateImage(wsDisplay, visual, depth, ZPixmap, 0, NULL, | |
156 1, 1, 32, 0); | |
35676 | 157 wsScreenDepth = mXImage->bits_per_pixel; |
35677 | 158 wsRedMask = mXImage->red_mask; |
159 wsGreenMask = mXImage->green_mask; | |
160 wsBlueMask = mXImage->blue_mask; | |
35672 | 161 #if HAVE_BIGENDIAN |
162 wsNonNativeOrder = mXImage->byte_order == LSBFirst; | |
163 #else | |
164 wsNonNativeOrder = mXImage->byte_order == MSBFirst; | |
165 #endif | |
166 XDestroyImage(mXImage); | |
167 } else { | |
168 int bpp, ibpp; | |
169 XWindowAttributes attribs; | |
170 | |
171 mXImage = XGetImage(wsDisplay, wsRootWin, 0, 0, 1, 1, AllPlanes, ZPixmap); | |
172 bpp = mXImage->bits_per_pixel; | |
173 | |
174 XGetWindowAttributes(wsDisplay, wsRootWin, &attribs); | |
175 ibpp = attribs.depth; | |
176 mXImage = XGetImage(wsDisplay, wsRootWin, 0, 0, 1, 1, AllPlanes, ZPixmap); | |
177 bpp = mXImage->bits_per_pixel; | |
178 | |
179 if ((ibpp + 7) / 8 != (bpp + 7) / 8) | |
180 ibpp = bpp; | |
181 | |
35676 | 182 wsScreenDepth = ibpp; |
35677 | 183 wsRedMask = mXImage->red_mask; |
184 wsGreenMask = mXImage->green_mask; | |
185 wsBlueMask = mXImage->blue_mask; | |
35672 | 186 XDestroyImage(mXImage); |
187 } | |
188 | |
35676 | 189 return wsScreenDepth; |
35672 | 190 } |
191 | |
35673 | 192 static int wsGetOutMask(void) |
35672 | 193 { |
35676 | 194 if ((wsScreenDepth == 32) && (wsRedMask == 0xff0000) && (wsGreenMask == 0x00ff00) && (wsBlueMask == 0x0000ff)) |
35672 | 195 return wsRGB32; |
196 | |
35676 | 197 if ((wsScreenDepth == 32) && (wsRedMask == 0x0000ff) && (wsGreenMask == 0x00ff00) && (wsBlueMask == 0xff0000)) |
35672 | 198 return wsBGR32; |
199 | |
35676 | 200 if ((wsScreenDepth == 24) && (wsRedMask == 0xff0000) && (wsGreenMask == 0x00ff00) && (wsBlueMask == 0x0000ff)) |
35672 | 201 return wsRGB24; |
202 | |
35676 | 203 if ((wsScreenDepth == 24) && (wsRedMask == 0x0000ff) && (wsGreenMask == 0x00ff00) && (wsBlueMask == 0xff0000)) |
35672 | 204 return wsBGR24; |
205 | |
35676 | 206 if ((wsScreenDepth == 16) && (wsRedMask == 0xf800) && (wsGreenMask == 0x7e0) && (wsBlueMask == 0x1f)) |
35672 | 207 return wsRGB16; |
208 | |
35676 | 209 if ((wsScreenDepth == 16) && (wsRedMask == 0x1f) && (wsGreenMask == 0x7e0) && (wsBlueMask == 0xf800)) |
35672 | 210 return wsBGR16; |
211 | |
35676 | 212 if ((wsScreenDepth == 15) && (wsRedMask == 0x7c00) && (wsGreenMask == 0x3e0) && (wsBlueMask == 0x1f)) |
35672 | 213 return wsRGB15; |
214 | |
35676 | 215 if ((wsScreenDepth == 15) && (wsRedMask == 0x1f) && (wsGreenMask == 0x3e0) && (wsBlueMask == 0x7c00)) |
35672 | 216 return wsBGR15; |
217 | |
218 return 0; | |
35636 | 219 } |
220 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
221 void wsInit(Display *display) |
23077 | 222 { |
33539 | 223 int eventbase; |
224 int errorbase; | |
23077 | 225 |
35622
59456592c6d1
Add a message indicating start of initialization of X.
ib
parents:
35541
diff
changeset
|
226 mp_msg(MSGT_GPLAYER, MSGL_V, "X init.\n"); |
59456592c6d1
Add a message indicating start of initialization of X.
ib
parents:
35541
diff
changeset
|
227 |
35631 | 228 wsDisplay = display; |
23077 | 229 |
35636 | 230 wsSetErrorHandler(); |
31323
c674bb16fa6d
Install error handler as early as possible to avoid crashing.
reimar
parents:
31314
diff
changeset
|
231 |
23077 | 232 /* enable DND atoms */ |
33539 | 233 wsXDNDInitialize(); |
234 | |
235 { /* on remote display XShm will be disabled - LGB */ | |
236 char *dispname = DisplayString(wsDisplay); | |
237 int localdisp = 1; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27377
diff
changeset
|
238 |
33539 | 239 if (dispname && *dispname != ':') { |
240 localdisp = 0; | |
35493 | 241 wsUseXShm = False; |
33539 | 242 } |
243 | |
33985 | 244 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] display name: %s => %s display.\n", dispname, localdisp ? "local" : "REMOTE"); |
23077 | 245 |
33539 | 246 if (!localdisp) |
33549 | 247 mp_msg(MSGT_GPLAYER, MSGL_INFO, MSGTR_WS_RemoteDisplay); |
33539 | 248 } |
249 | |
34465 | 250 #ifdef HAVE_SHM |
34461 | 251 if (!XShmQueryExtension(wsDisplay)) |
34465 | 252 #endif |
35493 | 253 wsUseXShm = False; |
33539 | 254 |
34460
c4731df07bfe
Always inform / warn about missing shared memory / shape extension
ib
parents:
34459
diff
changeset
|
255 if (!wsUseXShm) |
c4731df07bfe
Always inform / warn about missing shared memory / shape extension
ib
parents:
34459
diff
changeset
|
256 mp_msg(MSGT_GPLAYER, MSGL_INFO, MSGTR_WS_NoXshm); |
c4731df07bfe
Always inform / warn about missing shared memory / shape extension
ib
parents:
34459
diff
changeset
|
257 |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
258 #ifdef CONFIG_XSHAPE |
34461 | 259 if (!XShapeQueryExtension(wsDisplay, &eventbase, &errorbase)) |
34462 | 260 #endif |
35493 | 261 wsUseXShape = False; |
23077 | 262 |
34460
c4731df07bfe
Always inform / warn about missing shared memory / shape extension
ib
parents:
34459
diff
changeset
|
263 if (!wsUseXShape) |
c4731df07bfe
Always inform / warn about missing shared memory / shape extension
ib
parents:
34459
diff
changeset
|
264 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_WS_NoXshape); |
c4731df07bfe
Always inform / warn about missing shared memory / shape extension
ib
parents:
34459
diff
changeset
|
265 |
33539 | 266 XSynchronize(wsDisplay, True); |
23077 | 267 |
33539 | 268 wsScreen = DefaultScreen(wsDisplay); |
269 wsRootWin = RootWindow(wsDisplay, wsScreen); | |
27377
d58d06eafe83
Change a bunch of X11-specific preprocessor directives.
diego
parents:
26458
diff
changeset
|
270 #ifdef CONFIG_XF86VM |
23077 | 271 { |
33539 | 272 int clock; |
273 XF86VidModeModeLine modeline; | |
23077 | 274 |
33539 | 275 XF86VidModeGetModeLine(wsDisplay, wsScreen, &clock, &modeline); |
276 wsMaxX = modeline.hdisplay; | |
277 wsMaxY = modeline.vdisplay; | |
23077 | 278 } |
279 #endif | |
33539 | 280 { |
281 wsOrgX = wsOrgY = 0; | |
23077 | 282 |
33539 | 283 if (!wsMaxX) |
284 wsMaxX = DisplayWidth(wsDisplay, wsScreen); | |
285 | |
286 if (!wsMaxY) | |
287 wsMaxY = DisplayHeight(wsDisplay, wsScreen); | |
23077 | 288 } |
33994
8e5680eccf54
Move common code to new function wsUpdateXineramaInfo().
ib
parents:
33993
diff
changeset
|
289 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
290 wsWindowUpdateXinerama(NULL); |
33539 | 291 |
35676 | 292 wsGetScreenDepth(); |
33549 | 293 |
35676 | 294 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] Screen depth: %d\n", wsScreenDepth); |
33985 | 295 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] size: %dx%d\n", wsMaxX, wsMaxY); |
33549 | 296 |
33539 | 297 #ifdef CONFIG_XINERAMA |
33985 | 298 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] origin: +%d+%d\n", wsOrgX, wsOrgY); |
33539 | 299 #endif |
33549 | 300 |
33985 | 301 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] red mask: 0x%x\n", wsRedMask); |
302 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] green mask: 0x%x\n", wsGreenMask); | |
303 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] blue mask: 0x%x\n", wsBlueMask); | |
33539 | 304 |
34465 | 305 #ifdef HAVE_SHM |
33550 | 306 if (wsUseXShm) { |
307 int minor, major, shp; | |
33549 | 308 |
33550 | 309 XShmQueryVersion(wsDisplay, &major, &minor, &shp); |
33985 | 310 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] XShm version is %d.%d\n", major, minor); |
33550 | 311 } |
34465 | 312 #endif |
33539 | 313 |
314 #ifdef CONFIG_XSHAPE | |
33550 | 315 if (wsUseXShape) { |
316 int minor, major; | |
33549 | 317 |
33550 | 318 XShapeQueryVersion(wsDisplay, &major, &minor); |
33985 | 319 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] XShape version is %d.%d\n", major, minor); |
33550 | 320 } |
23077 | 321 #endif |
33549 | 322 |
33539 | 323 wsOutMask = wsGetOutMask(); |
324 | |
325 switch (wsOutMask) { | |
326 case wsRGB32: | |
327 out_pix_fmt = PIX_FMT_RGB32; | |
328 break; | |
329 | |
330 case wsBGR32: | |
331 out_pix_fmt = PIX_FMT_BGR32; | |
332 break; | |
333 | |
334 case wsRGB24: | |
335 out_pix_fmt = PIX_FMT_RGB24; | |
336 break; | |
337 | |
338 case wsBGR24: | |
339 out_pix_fmt = PIX_FMT_BGR24; | |
340 break; | |
341 | |
342 case wsRGB16: | |
343 out_pix_fmt = PIX_FMT_RGB565; | |
344 break; | |
345 | |
346 case wsBGR16: | |
347 out_pix_fmt = PIX_FMT_BGR565; | |
348 break; | |
349 | |
350 case wsRGB15: | |
351 out_pix_fmt = PIX_FMT_RGB555; | |
352 break; | |
353 | |
354 case wsBGR15: | |
355 out_pix_fmt = PIX_FMT_BGR555; | |
356 break; | |
357 } | |
23077 | 358 } |
359 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
360 void wsDone(void) |
35672 | 361 { |
35680 | 362 //XCloseDisplay(wsDisplay); |
35672 | 363 } |
364 | |
365 /** | |
366 * @brief Inform about an X error that has occurred. | |
367 * | |
368 * @param display display | |
369 * @param event pointer to an X error event structure | |
370 * | |
371 * @return 0 | |
372 */ | |
373 static int wsErrorHandler(Display *display, XErrorEvent *event) | |
374 { | |
375 char type[128]; | |
376 | |
377 XGetErrorText(display, event->error_code, type, sizeof(type)); | |
378 | |
379 mp_msg(MSGT_GPLAYER, MSGL_ERR, "[ws] " MSGTR_WS_XError); | |
380 mp_msg(MSGT_GPLAYER, MSGL_ERR, "[ws] Error code: %d - %s\n", event->error_code, type); | |
381 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] Request code: %d (minor code: %d)\n", event->request_code, event->minor_code); | |
382 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] MPlayer module: %s\n", current_module ? current_module : "(none)"); | |
383 | |
384 return 0; | |
385 } | |
386 | |
387 /** | |
388 * @brief Set the X error handler. | |
389 */ | |
390 void wsSetErrorHandler(void) | |
391 { | |
392 XSetErrorHandler(wsErrorHandler); | |
393 } | |
394 | |
395 // ---------------------------------------------------------------------------------------------- | |
396 // Handle events. | |
397 // ---------------------------------------------------------------------------------------------- | |
398 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
399 static int wsWindowListSearch(Window win) |
35672 | 400 { |
401 int i; | |
402 | |
403 for (i = 0; i < wsWLCount; i++) | |
404 if (wsWindowList[i] && wsWindowList[i]->WindowID == win) | |
405 return i; | |
406 | |
407 return -1; | |
408 } | |
409 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
410 void wsEvent(XEvent *event) |
35672 | 411 { |
412 unsigned long i = 0; | |
413 int l; | |
414 int x, y; | |
415 Window child_window = 0; | |
416 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
417 l = wsWindowListSearch(event->xany.window); |
35672 | 418 |
419 if (l == -1) | |
420 return; | |
421 | |
422 wsWindowList[l]->State = wsNone; | |
423 | |
424 switch (event->type) { | |
425 case ClientMessage: | |
426 | |
427 if (event->xclient.message_type == wsWindowList[l]->AtomProtocols) { | |
428 if ((Atom)event->xclient.data.l[0] == wsWindowList[l]->AtomDeleteWindow) { | |
429 i = wsWindowClosed; | |
430 goto expose; | |
431 } | |
432 | |
433 if ((Atom)event->xclient.data.l[0] == wsWindowList[l]->AtomTakeFocus) { | |
434 i = wsWindowFocusIn; | |
435 wsWindowList[l]->Focused = wsFocused; | |
436 goto expose; | |
437 } | |
438 | |
439 if ((Atom)event->xclient.data.l[0] == wsWindowList[l]->AtomRolle) { | |
440 mp_msg(MSGT_GPLAYER, MSGL_V, "[ws] role set.\n"); | |
441 } | |
442 } else { | |
443 /* try to process DND events */ | |
444 wsXDNDProcessClientMessage(&event->xclient); | |
445 } | |
446 | |
447 break; | |
448 | |
449 case MapNotify: | |
450 | |
451 i = wsWindowMapped; | |
452 wsWindowList[l]->Mapped = wsMapped; | |
453 goto expose; | |
454 | |
455 case UnmapNotify: | |
456 | |
457 i = wsWindowUnmapped; | |
458 wsWindowList[l]->Mapped = wsNo; | |
459 goto expose; | |
460 | |
461 case FocusIn: | |
462 | |
463 if (wsWindowList[l]->Focused == wsFocused) | |
464 break; | |
465 | |
466 i = wsWindowFocusIn; | |
467 wsWindowList[l]->Focused = wsFocused; | |
468 goto expose; | |
469 | |
470 case FocusOut: | |
471 | |
472 if (wsWindowList[l]->Focused == wsNo) | |
473 break; | |
474 | |
475 i = wsWindowFocusOut; | |
476 wsWindowList[l]->Focused = wsNo; | |
477 goto expose; | |
478 | |
479 case VisibilityNotify: | |
480 | |
481 switch (event->xvisibility.state) { | |
482 case VisibilityUnobscured: | |
483 i = wsWindowVisible; | |
484 wsWindowList[l]->Visible = wsVisible; | |
485 goto expose; | |
486 | |
487 case VisibilityFullyObscured: | |
488 i = wsWindowNotVisible; | |
489 wsWindowList[l]->Visible = wsNotVisible; | |
490 goto expose; | |
491 | |
492 case VisibilityPartiallyObscured: | |
493 i = wsWindowPartialVisible; | |
494 wsWindowList[l]->Visible = wsPVisible; | |
495 goto expose; | |
496 } | |
497 | |
498 expose: | |
499 wsWindowList[l]->State = i; | |
500 | |
501 if (wsWindowList[l]->ReDraw) | |
502 wsWindowList[l]->ReDraw(); | |
503 | |
504 break; | |
505 | |
506 case Expose: | |
507 | |
508 wsWindowList[l]->State = wsWindowExpose; | |
509 | |
510 if ((wsWindowList[l]->ReDraw) && (!event->xexpose.count)) | |
511 wsWindowList[l]->ReDraw(); | |
512 | |
513 break; | |
514 | |
515 case ConfigureNotify: | |
516 | |
517 XTranslateCoordinates(wsDisplay, wsWindowList[l]->WindowID, wsRootWin, 0, 0, &x, &y, &child_window); | |
518 | |
519 if ((wsWindowList[l]->X != x) || (wsWindowList[l]->Y != y) || (wsWindowList[l]->Width != event->xconfigure.width) || (wsWindowList[l]->Height != event->xconfigure.height)) { | |
520 wsWindowList[l]->X = x; | |
521 wsWindowList[l]->Y = y; | |
522 wsWindowList[l]->Width = event->xconfigure.width; | |
523 wsWindowList[l]->Height = event->xconfigure.height; | |
524 } | |
525 | |
526 wsWindowList[l]->Rolled = wsNo; | |
527 | |
528 if (event->xconfigure.y < 0) { | |
529 i = wsWindowRolled; | |
530 wsWindowList[l]->Rolled = wsRolled; | |
531 goto expose; | |
532 } | |
533 | |
534 break; | |
535 | |
536 case KeyPress: | |
537 | |
538 i = wsKeyPressed; | |
539 goto keypressed; | |
540 | |
541 case KeyRelease: | |
542 | |
543 i = wsKeyReleased; | |
544 keypressed: | |
545 wsWindowList[l]->Alt = False; | |
546 wsWindowList[l]->Shift = False; | |
547 wsWindowList[l]->NumLock = False; | |
548 wsWindowList[l]->Control = False; | |
549 wsWindowList[l]->CapsLock = False; | |
550 | |
551 if (event->xkey.state & Mod1Mask) | |
552 wsWindowList[l]->Alt = True; | |
553 | |
554 if (event->xkey.state & Mod2Mask) | |
555 wsWindowList[l]->NumLock = True; | |
556 | |
557 if (event->xkey.state & ControlMask) | |
558 wsWindowList[l]->Control = True; | |
559 | |
560 if (event->xkey.state & ShiftMask) | |
561 wsWindowList[l]->Shift = True; | |
562 | |
563 if (event->xkey.state & LockMask) | |
564 wsWindowList[l]->CapsLock = True; | |
565 | |
566 #if 0 | |
567 { | |
568 KeySym keySym; | |
569 keySym = XKeycodeToKeysym(wsDisplay, event->xkey.keycode, 0); | |
570 | |
571 if (keySym != NoSymbol) { | |
572 keySym = ((keySym & 0xff00) != 0 ? ((keySym & 0x00ff) + 256) : (keySym)); | |
573 | |
574 if (wsWindowList[l]->KeyHandler) | |
575 wsWindowList[l]->KeyHandler(event->xkey.state, i, keySym); | |
576 } | |
577 } | |
578 #else | |
579 { | |
580 int key; | |
581 char buf[100]; | |
582 KeySym keySym; | |
583 static XComposeStatus stat; | |
584 | |
585 XLookupString(&event->xkey, buf, sizeof(buf), &keySym, &stat); | |
586 key = ((keySym & 0xff00) != 0 ? ((keySym & 0x00ff) + 256) : (keySym)); | |
587 | |
588 if (wsWindowList[l]->KeyHandler) | |
589 wsWindowList[l]->KeyHandler(event->xkey.keycode, i, key); | |
590 } | |
591 #endif | |
592 break; | |
593 | |
594 case MotionNotify: | |
595 | |
596 i = wsMoveMouse; | |
597 { | |
598 /* pump all motion events from the display queue: | |
599 * this way it works faster when moving the window */ | |
600 static XEvent e; | |
601 | |
602 if (event->xmotion.state) { | |
603 while (XCheckTypedWindowEvent(wsDisplay, event->xany.window, MotionNotify, &e)) { | |
604 /* FIXME: need to make sure we didn't release/press the button in between...*/ | |
605 /* FIXME: do we need some timeout here to make sure we don't spend too much time | |
606 * removing events from the queue? */ | |
607 event = &e; | |
608 } | |
609 } | |
610 } | |
611 | |
612 if (wsWindowList[l]->wsCursor != None) { | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
613 wsMouseVisibility(wsWindowList[l], wsShowMouseCursor); |
35672 | 614 mouse_win = wsWindowList[l]; |
615 mouse_time = GetTimerMS(); | |
616 } | |
617 | |
618 goto buttonreleased; | |
619 | |
620 case ButtonRelease: | |
621 | |
622 i = event->xbutton.button + 128; | |
623 | |
624 if (wsWindowList[l]->wsCursor != None) { | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
625 wsMouseVisibility(wsWindowList[l], wsShowMouseCursor); |
35672 | 626 mouse_win = wsWindowList[l]; |
627 mouse_time = GetTimerMS(); | |
628 } | |
629 | |
630 goto buttonreleased; | |
631 | |
632 case ButtonPress: | |
633 | |
634 i = event->xbutton.button; | |
635 | |
636 if (wsWindowList[l]->wsCursor != None) { | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
637 wsMouseVisibility(wsWindowList[l], wsShowMouseCursor); |
35672 | 638 mouse_win = wsWindowList[l]; |
639 mouse_time = GetTimerMS(); | |
640 } | |
641 | |
642 goto buttonreleased; | |
643 | |
644 case EnterNotify: | |
645 | |
646 i = wsEnterWindow; | |
647 goto buttonreleased; | |
648 | |
649 case LeaveNotify: | |
650 | |
651 i = wsLeaveWindow; | |
652 buttonreleased: | |
653 | |
654 if (wsWindowList[l]->MouseHandler) | |
655 wsWindowList[l]->MouseHandler(i, event->xbutton.x, event->xbutton.y, event->xmotion.x_root, event->xmotion.y_root); | |
656 | |
657 break; | |
658 | |
659 case SelectionNotify: | |
660 | |
661 /* Handle DandD */ | |
662 wsXDNDProcessSelection(wsWindowList[l], event); | |
663 break; | |
664 } | |
665 | |
666 XFlush(wsDisplay); | |
667 XSync(wsDisplay, False); | |
668 } | |
669 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
670 void wsEvents(void) |
35672 | 671 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
672 XEvent xev; |
35672 | 673 /* handle pending events */ |
674 while (XPending(wsDisplay)) { | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
675 XNextEvent(wsDisplay, &xev); |
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
676 // printf("### X event: %d [%d]\n",xev.type,delay); |
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
677 wsEvent(&xev); |
35672 | 678 } |
679 } | |
680 | |
33995 | 681 /** |
682 * @brief Calculate and store the x and y position for a window. | |
683 * | |
684 * @param win pointer to a ws window structure | |
685 * @param x x position of the window (real/absolute or mock) | |
686 * @param y y position of the window (real/absolute or mock) | |
687 * @param width width of the area to place the window in | |
688 * @param height height of the area to place the window in | |
689 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
690 static void wsWindowUpdatePosition(wsWindow *win, int x, int y, int width, int height) |
33995 | 691 { |
692 switch (x) { | |
693 case -1: | |
694 win->X = wsOrgX + (wsMaxX - width) / 2; | |
695 break; | |
696 | |
697 case -2: | |
698 win->X = wsOrgX + wsMaxX - width; | |
699 break; | |
700 | |
701 default: | |
702 win->X = x; | |
703 break; | |
704 } | |
705 | |
706 switch (y) { | |
707 case -1: | |
708 win->Y = wsOrgY + (wsMaxY - height) / 2; | |
709 break; | |
710 | |
711 case -2: | |
712 win->Y = wsOrgY + wsMaxY - height; | |
713 break; | |
714 | |
715 default: | |
716 win->Y = y; | |
717 break; | |
718 } | |
719 } | |
720 | |
35645 | 721 /** |
722 * @brief Replace the size hints for the WM_NORMAL_HINTS property of a window. | |
723 * | |
724 * @param win pointer to a ws window structure | |
725 */ | |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
726 static void wsWindowSizeHint(wsWindow *win) |
35645 | 727 { |
35660 | 728 XSizeHints size; |
729 | |
730 size.flags = 0; | |
35645 | 731 |
35648 | 732 /* obsolete, solely for compatibility reasons */ |
35660 | 733 size.flags |= PPosition; |
734 size.x = win->X; | |
735 size.y = win->Y; | |
35645 | 736 |
35648 | 737 /* obsolete, solely for compatibility reasons */ |
35660 | 738 size.flags |= PSize; |
739 size.width = win->Width; | |
740 size.height = win->Height; | |
35645 | 741 |
35648 | 742 /* a minimum of 4 is said to avoid off-by-one errors and be required by mga_vid */ |
35660 | 743 size.flags |= PMinSize; |
744 size.min_width = 4; | |
745 size.min_height = 4; | |
35648 | 746 |
747 if (win->Property & wsMinSize) { | |
35660 | 748 size.min_width = win->Width; |
749 size.min_height = win->Height; | |
35645 | 750 } |
751 | |
35648 | 752 if (win->Property & wsMaxSize) { |
35660 | 753 size.flags |= PMaxSize; |
754 size.max_width = win->Width; | |
755 size.max_height = win->Height; | |
35645 | 756 } |
757 | |
35657 | 758 if (vo_keepaspect && (win->Property & wsAspect)) { |
35660 | 759 size.flags |= PAspect; |
760 size.min_aspect.x = win->Width; | |
761 size.min_aspect.y = win->Height; | |
762 size.max_aspect.x = win->Width; | |
763 size.max_aspect.y = win->Height; | |
35645 | 764 } |
765 | |
35660 | 766 size.flags |= PBaseSize; |
767 size.base_width = 0; | |
768 size.base_height = 0; | |
35645 | 769 |
35660 | 770 size.flags |= PWinGravity; |
771 size.win_gravity = StaticGravity; | |
35645 | 772 |
35660 | 773 XSetWMNormalHints(wsDisplay, win->WindowID, &size); |
35645 | 774 } |
775 | |
35699 | 776 static void wsWindowDecoration(wsWindow *win) |
35698 | 777 { |
778 Atom wsMotifHints; | |
779 struct { | |
780 unsigned long flags; | |
781 unsigned long functions; | |
782 unsigned long decorations; | |
783 long input_mode; | |
784 unsigned long status; | |
785 } wsMotifWmHints; | |
786 | |
787 wsMotifHints = XInternAtom(wsDisplay, "_MOTIF_WM_HINTS", 0); | |
788 | |
789 if (wsMotifHints == None) | |
790 return; | |
791 | |
792 memset(&wsMotifWmHints, 0, sizeof(wsMotifWmHints)); | |
793 wsMotifWmHints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; | |
794 | |
795 if (win->Decoration) { | |
796 wsMotifWmHints.functions = MWM_FUNC_MOVE | MWM_FUNC_CLOSE | MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE; | |
797 | |
798 if (!(win->Property & wsMinSize) || !(win->Property & wsMaxSize)) | |
799 wsMotifWmHints.functions |= MWM_FUNC_RESIZE; | |
800 | |
801 wsMotifWmHints.decorations = MWM_DECOR_ALL; | |
802 } | |
803 | |
804 XChangeProperty(wsDisplay, win->WindowID, wsMotifHints, wsMotifHints, 32, | |
805 PropModeReplace, (unsigned char *)&wsMotifWmHints, 5); | |
806 } | |
807 | |
35652 | 808 /** |
809 * @brief Wait until a window is mapped if its property requires it. | |
810 * | |
811 * @param win pointer to a ws window structure | |
812 */ | |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
813 static void wsWindowMapWait(wsWindow *win) |
35652 | 814 { |
815 XEvent xev; | |
816 | |
35653 | 817 if (win->Property & wsWaitMap) { |
35652 | 818 do |
819 XNextEvent(wsDisplay, &xev); | |
820 while (xev.type != MapNotify || xev.xmap.event != win->WindowID); | |
35653 | 821 |
822 win->Mapped = wsMapped; | |
823 } | |
35652 | 824 } |
825 | |
23077 | 826 // ---------------------------------------------------------------------------------------------- |
827 // Create window. | |
828 // X,Y : window position | |
829 // wX,wY : size of window | |
830 // bW : border width | |
831 // cV : visible mouse cursor on window | |
832 // D : visible frame, title, etc. | |
833 // sR : screen ratio | |
834 // ---------------------------------------------------------------------------------------------- | |
835 | |
33539 | 836 XClassHint wsClassHint; |
837 XTextProperty wsTextProperty; | |
838 Window LeaderWindow; | |
23077 | 839 |
35655 | 840 // ---------------------------------------------------------------------------------------------- |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
841 // wsWindowCreate: create a new window on the screen. |
35655 | 842 // x,y : window position |
843 // w,h : window size | |
844 // c : mouse cursor visible | |
845 // p : properties - "decoration", visible titlebar, etc ... | |
846 // ---------------------------------------------------------------------------------------------- | |
35687 | 847 void wsWindowCreate(wsWindow *win, int x, int y, int w, int h, int p, int c, char *label) |
23077 | 848 { |
33539 | 849 int depth; |
850 | |
35655 | 851 win->Property = p; |
23077 | 852 |
35697 | 853 win->Decoration = ((p & wsShowFrame) != 0); |
33539 | 854 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
855 wsWindowUpdatePosition(win, x, y, w, h); |
33539 | 856 |
35655 | 857 win->Width = w; |
858 win->Height = h; | |
33539 | 859 win->OldX = win->X; |
860 win->OldY = win->Y; | |
861 win->OldWidth = win->Width; | |
862 win->OldHeight = win->Height; | |
23077 | 863 |
34684 | 864 /* Hide Mouse Cursor */ |
33539 | 865 win->wsCursor = None; |
35655 | 866 win->wsMouseEventType = c; |
33539 | 867 win->wsCursorData[0] = 0; |
868 win->wsCursorPixmap = XCreateBitmapFromData(wsDisplay, wsRootWin, win->wsCursorData, 1, 1); | |
23077 | 869 |
35655 | 870 if (!(c & wsShowMouseCursor)) |
33539 | 871 win->wsCursor = XCreatePixmapCursor(wsDisplay, win->wsCursorPixmap, win->wsCursorPixmap, &win->wsColor, &win->wsColor, 0, 0); |
872 | |
873 depth = vo_find_depth_from_visuals(wsDisplay, wsScreen, NULL); | |
874 | |
875 if (depth < 15) { | |
876 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ColorDepthTooLow); | |
33768 | 877 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 878 } |
879 | |
880 XMatchVisualInfo(wsDisplay, wsScreen, depth, TrueColor, &win->VisualInfo); | |
23077 | 881 |
34684 | 882 /* --- */ |
33539 | 883 win->AtomLeaderClient = XInternAtom(wsDisplay, "WM_CLIENT_LEADER", False); |
884 win->AtomDeleteWindow = XInternAtom(wsDisplay, "WM_DELETE_WINDOW", False); | |
885 win->AtomTakeFocus = XInternAtom(wsDisplay, "WM_TAKE_FOCUS", False); | |
886 win->AtomRolle = XInternAtom(wsDisplay, "WM_WINDOW_ROLE", False); | |
887 win->AtomWMSizeHint = XInternAtom(wsDisplay, "WM_SIZE_HINT", False); | |
888 win->AtomWMNormalHint = XInternAtom(wsDisplay, "WM_NORMAL_HINT", False); | |
889 win->AtomProtocols = XInternAtom(wsDisplay, "WM_PROTOCOLS", False); | |
890 win->AtomsProtocols[0] = win->AtomDeleteWindow; | |
891 win->AtomsProtocols[1] = win->AtomTakeFocus; | |
892 win->AtomsProtocols[2] = win->AtomRolle; | |
34684 | 893 /* --- */ |
23077 | 894 |
33539 | 895 win->WindowAttrib.background_pixel = BlackPixel(wsDisplay, wsScreen); |
896 win->WindowAttrib.border_pixel = WhitePixel(wsDisplay, wsScreen); | |
897 win->WindowAttrib.colormap = XCreateColormap(wsDisplay, wsRootWin, win->VisualInfo.visual, AllocNone); | |
898 win->WindowAttrib.event_mask = StructureNotifyMask | FocusChangeMask | | |
899 ExposureMask | PropertyChangeMask | | |
900 EnterWindowMask | LeaveWindowMask | | |
901 VisibilityChangeMask | | |
902 KeyPressMask | KeyReleaseMask; | |
23077 | 903 |
35655 | 904 if ((c & wsHandleMouseButton)) |
33539 | 905 win->WindowAttrib.event_mask |= ButtonPressMask | ButtonReleaseMask; |
906 | |
35655 | 907 if ((c & wsHandleMouseMove)) |
33539 | 908 win->WindowAttrib.event_mask |= PointerMotionMask; |
909 | |
910 win->WindowAttrib.cursor = win->wsCursor; | |
911 win->WindowAttrib.override_redirect = False; | |
912 | |
35655 | 913 if (p & wsOverredirect) |
33539 | 914 win->WindowAttrib.override_redirect = True; |
23077 | 915 |
33539 | 916 win->WindowMask = CWBackPixel | CWBorderPixel | |
917 CWColormap | CWEventMask | CWCursor | | |
918 CWOverrideRedirect; | |
23077 | 919 |
33539 | 920 win->WindowID = XCreateWindow(wsDisplay, |
921 (win->Parent != 0 ? win->Parent : wsRootWin), | |
35683
75155d8a9c7e
Remove parameter for border_width from wsWindowCreate().
ib
parents:
35682
diff
changeset
|
922 win->X, win->Y, win->Width, win->Height, 0, |
33539 | 923 win->VisualInfo.depth, |
924 InputOutput, | |
925 win->VisualInfo.visual, | |
926 win->WindowMask, &win->WindowAttrib); | |
23077 | 927 |
33539 | 928 wsClassHint.res_name = "MPlayer"; |
929 | |
930 wsClassHint.res_class = "MPlayer"; | |
931 XSetClassHint(wsDisplay, win->WindowID, &wsClassHint); | |
932 | |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
933 wsWindowSizeHint(win); |
23077 | 934 |
33539 | 935 win->WMHints.flags = InputHint | StateHint; |
936 win->WMHints.input = True; | |
937 win->WMHints.initial_state = NormalState; | |
938 XSetWMHints(wsDisplay, win->WindowID, &win->WMHints); | |
23077 | 939 |
35697 | 940 wsWindowDecoration(win); |
33539 | 941 XStoreName(wsDisplay, win->WindowID, label); |
942 XmbSetWMProperties(wsDisplay, win->WindowID, label, label, NULL, 0, NULL, NULL, NULL); | |
23077 | 943 |
33539 | 944 XSetWMProtocols(wsDisplay, win->WindowID, win->AtomsProtocols, 3); |
945 XChangeProperty(wsDisplay, win->WindowID, | |
946 win->AtomLeaderClient, | |
947 XA_WINDOW, 32, PropModeReplace, | |
948 (unsigned char *)&LeaderWindow, 1); | |
23077 | 949 |
33539 | 950 wsTextProperty.value = label; |
951 wsTextProperty.encoding = XA_STRING; | |
952 wsTextProperty.format = 8; | |
953 wsTextProperty.nitems = strlen(label); | |
954 XSetWMIconName(wsDisplay, win->WindowID, &wsTextProperty); | |
955 | |
956 win->wGC = XCreateGC(wsDisplay, win->WindowID, | |
35679 | 957 0, |
958 NULL); | |
23077 | 959 |
35498
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
960 win->Visible = wsNo; |
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
961 win->Focused = wsNo; |
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
962 win->Mapped = wsNo; |
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
963 win->Rolled = wsNo; |
23077 | 964 |
35655 | 965 if (p & wsShowWindow) { |
33539 | 966 XMapWindow(wsDisplay, win->WindowID); |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
967 wsWindowMapWait(win); |
35652 | 968 } |
23077 | 969 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
970 wsImageCreate(win, win->Width, win->Height); |
34684 | 971 /* End of creating -------------------------------------------------------------------------- */ |
23077 | 972 |
33539 | 973 { |
974 int i; | |
975 | |
976 for (i = 0; i < wsWLCount; i++) | |
977 if (wsWindowList[i] == NULL) | |
978 break; | |
979 | |
980 if (i == wsWLCount) { | |
981 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_TooManyOpenWindows); | |
33768 | 982 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 983 } |
23077 | 984 |
33539 | 985 wsWindowList[i] = win; |
986 } | |
987 | |
988 XFlush(wsDisplay); | |
989 XSync(wsDisplay, False); | |
23077 | 990 |
33539 | 991 win->ReDraw = NULL; |
992 win->MouseHandler = NULL; | |
993 win->KeyHandler = NULL; | |
33985 | 994 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] window is created. ( %s ).\n", label); |
23077 | 995 } |
996 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
997 void wsWindowDestroy(wsWindow *win) |
23077 | 998 { |
33539 | 999 int l; |
1000 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1001 l = wsWindowListSearch(win->WindowID); |
35354 | 1002 |
1003 if (l != -1) | |
1004 wsWindowList[l] = NULL; | |
33539 | 1005 |
1006 if (win->wsCursor != None) { | |
1007 XFreeCursor(wsDisplay, win->wsCursor); | |
1008 win->wsCursor = None; | |
1009 } | |
1010 | |
1011 XFreeGC(wsDisplay, win->wGC); | |
1012 XUnmapWindow(wsDisplay, win->WindowID); | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1013 wsImageDestroy(win); |
33539 | 1014 XDestroyWindow(wsDisplay, win->WindowID); |
23077 | 1015 #if 0 |
33539 | 1016 win->ReDraw = NULL; |
1017 win->MouseHandler = NULL; | |
1018 win->KeyHandler = NULL; | |
35498
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
1019 win->Visible = wsNo; |
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
1020 win->Focused = wsNo; |
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
1021 win->Mapped = wsNo; |
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
1022 win->Rolled = wsNo; |
23077 | 1023 #endif |
1024 } | |
1025 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1026 void wsWindowShape(wsWindow *win, char *data) |
35672 | 1027 { |
1028 #ifdef CONFIG_XSHAPE | |
1029 if (!wsUseXShape) | |
1030 return; | |
1031 | |
1032 if (data) { | |
1033 win->Mask = XCreateBitmapFromData(wsDisplay, win->WindowID, data, win->Width, win->Height); | |
1034 XShapeCombineMask(wsDisplay, win->WindowID, ShapeBounding, 0, 0, win->Mask, ShapeSet); | |
1035 XFreePixmap(wsDisplay, win->Mask); | |
1036 } else | |
1037 XShapeCombineMask(wsDisplay, win->WindowID, ShapeBounding, 0, 0, None, ShapeSet); | |
1038 #endif | |
1039 } | |
1040 | |
34081 | 1041 /** |
35672 | 1042 * @brief Set differently sized icons to a window. |
1043 * | |
1044 * This function sets the X icon hint as well as | |
1045 * the properties KWM_WIN_ICON and _NET_WM_ICON. | |
1046 * | |
1047 * @param display display | |
1048 * @param Win window | |
1049 * @param icon pointer to the icons | |
34081 | 1050 */ |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1051 void wsWindowIcon(Display *display, Window Win, guiIcon_t *icon) |
34081 | 1052 { |
35672 | 1053 XWMHints *wm; |
1054 Atom iconatom; | |
1055 long data[2]; | |
1056 | |
1057 if (icon->normal) { | |
1058 wm = XGetWMHints(display, Win); | |
1059 | |
1060 if (!wm) | |
1061 wm = XAllocWMHints(); | |
1062 | |
1063 wm->icon_pixmap = icon->normal; | |
1064 wm->icon_mask = icon->normal_mask; | |
1065 wm->flags |= IconPixmapHint | IconMaskHint; | |
1066 | |
1067 XSetWMHints(display, Win, wm); | |
1068 XFree(wm); | |
1069 } | |
1070 | |
1071 if (icon->small || icon->normal) { | |
1072 iconatom = XInternAtom(display, "KWM_WIN_ICON", False); | |
1073 data[0] = (icon->small ? icon->small : icon->normal); | |
1074 data[1] = (icon->small ? icon->small_mask : icon->normal_mask); | |
1075 | |
1076 XChangeProperty(display, Win, iconatom, iconatom, 32, PropModeReplace, (unsigned char *)data, 2); | |
1077 } | |
1078 | |
1079 if (icon->collection) { | |
1080 iconatom = XInternAtom(display, "_NET_WM_ICON", False); | |
1081 XChangeProperty(display, Win, iconatom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)icon->collection, icon->collection_size); | |
34081 | 1082 } |
1083 } | |
1084 | |
23077 | 1085 // ---------------------------------------------------------------------------------------------- |
35672 | 1086 // Set window background to 'color'. |
23077 | 1087 // ---------------------------------------------------------------------------------------------- |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1088 void wsWindowBackground(wsWindow *win, int r, int g, int b) |
23077 | 1089 { |
35672 | 1090 int color = 0; |
35541 | 1091 |
35672 | 1092 switch (wsOutMask) { |
1093 case wsRGB32: | |
1094 case wsRGB24: | |
1095 color = (r << 16) + (g << 8) + b; | |
23077 | 1096 break; |
1097 | |
35672 | 1098 case wsBGR32: |
1099 case wsBGR24: | |
1100 color = (b << 16) + (g << 8) + r; | |
1101 break; | |
33539 | 1102 |
35672 | 1103 case wsRGB16: |
1104 PACK_RGB16(r, g, b, color); | |
23077 | 1105 break; |
1106 | |
35728 | 1107 case wsBGR16: |
1108 PACK_RGB16(b, g, r, color); | |
1109 break; | |
1110 | |
35672 | 1111 case wsRGB15: |
35728 | 1112 PACK_RGB15(r, g, b, color); |
23077 | 1113 break; |
1114 | |
35672 | 1115 case wsBGR15: |
35728 | 1116 PACK_RGB15(b, g, r, color); |
33539 | 1117 break; |
1118 } | |
1119 | |
35672 | 1120 XSetWindowBackground(wsDisplay, win->WindowID, color); |
33539 | 1121 } |
23077 | 1122 |
34009
5c33025ccfd8
Replace comment for wsFullScreen() by doxygen comment.
ib
parents:
34008
diff
changeset
|
1123 /** |
35672 | 1124 * @brief Clear the entire area in a window. |
34009
5c33025ccfd8
Replace comment for wsFullScreen() by doxygen comment.
ib
parents:
34008
diff
changeset
|
1125 * |
5c33025ccfd8
Replace comment for wsFullScreen() by doxygen comment.
ib
parents:
34008
diff
changeset
|
1126 * @param win pointer to a ws window structure |
5c33025ccfd8
Replace comment for wsFullScreen() by doxygen comment.
ib
parents:
34008
diff
changeset
|
1127 */ |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1128 void wsWindowClear(wsWindow *win) |
23077 | 1129 { |
35672 | 1130 XClearWindow(wsDisplay, win->WindowID); |
23077 | 1131 } |
1132 | |
1133 // ---------------------------------------------------------------------------------------------- | |
1134 // Move window to x, y. | |
1135 // ---------------------------------------------------------------------------------------------- | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1136 void wsWindowMove(wsWindow *win, Bool abs, int x, int y) |
23077 | 1137 { |
33993 | 1138 if (abs) { |
1139 win->X = x; | |
1140 win->Y = y; | |
33995 | 1141 } else |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1142 wsWindowUpdatePosition(win, x, y, win->Width, win->Height); |
23077 | 1143 |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
1144 wsWindowSizeHint(win); |
33539 | 1145 XMoveWindow(wsDisplay, win->WindowID, win->X, win->Y); |
23077 | 1146 } |
1147 | |
33998
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 * @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
|
1150 * 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
|
1151 * |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1152 * @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
|
1153 * @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
|
1154 * @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
|
1155 * @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
|
1156 */ |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1157 void wsWindowMoveWithin(wsWindow *win, Bool abs, int x, int y) |
33998
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1158 { |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1159 Bool fitting = True; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1160 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1161 wsWindowMove(win, abs, x, y); |
33998
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1162 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1163 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
|
1164 fitting = False; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1165 win->X = wsMaxX - win->Width; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1166 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1167 if (win->X < 0) |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1168 win->X = 0; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1169 } |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1170 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1171 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
|
1172 fitting = False; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1173 win->Y = wsMaxY - win->Height; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1174 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1175 if (win->Y < 0) |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1176 win->Y = 0; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1177 } |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1178 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1179 if (!fitting) |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1180 wsWindowMove(win, True, win->X, win->Y); |
33998
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1181 } |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1182 |
23077 | 1183 // ---------------------------------------------------------------------------------------------- |
1184 // Resize window to sx, sy. | |
1185 // ---------------------------------------------------------------------------------------------- | |
35682 | 1186 void wsWindowResize(wsWindow *win, int w, int h) |
23077 | 1187 { |
35682 | 1188 win->Width = w; |
1189 win->Height = h; | |
23077 | 1190 |
33539 | 1191 if (vo_wm_type == 0) |
1192 XUnmapWindow(wsDisplay, win->WindowID); | |
23077 | 1193 |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
1194 wsWindowSizeHint(win); |
35682 | 1195 XResizeWindow(wsDisplay, win->WindowID, w, h); |
33539 | 1196 |
34124 | 1197 if (vo_wm_type == 0) |
1198 XMapWindow(wsDisplay, win->WindowID); | |
23077 | 1199 } |
1200 | |
35355 | 1201 /** |
35672 | 1202 * @brief Switch window fullscreen state. |
1203 * | |
1204 * Switch normal window to fullscreen and fullscreen window to normal. | |
1205 * | |
1206 * @param win pointer to a ws window structure | |
1207 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1208 void wsWindowFullscreen(wsWindow *win) |
35672 | 1209 { |
1210 if (win->isFullScreen) { | |
1211 if (vo_fs_type & vo_wm_FULLSCREEN) | |
1212 /* window manager supports EWMH */ | |
1213 vo_x11_ewmh_fullscreen(win->WindowID, _NET_WM_STATE_REMOVE); | |
1214 else { | |
1215 win->X = win->OldX; | |
1216 win->Y = win->OldY; | |
1217 win->Width = win->OldWidth; | |
1218 win->Height = win->OldHeight; | |
1219 } | |
1220 | |
1221 win->isFullScreen = False; | |
1222 } else { | |
1223 if (vo_fs_type & vo_wm_FULLSCREEN) | |
1224 /* window manager supports EWMH */ | |
1225 vo_x11_ewmh_fullscreen(win->WindowID, _NET_WM_STATE_ADD); | |
1226 else { | |
1227 win->OldX = win->X; | |
1228 win->OldY = win->Y; | |
1229 win->OldWidth = win->Width; | |
1230 win->OldHeight = win->Height; | |
1231 } | |
1232 | |
1233 win->isFullScreen = True; | |
1234 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1235 wsWindowUpdateXinerama(win); |
35672 | 1236 } |
1237 | |
1238 /* unknown window manager and obsolete option -fsmode used */ | |
1239 if (vo_wm_type == 0 && !(vo_fsmode & 16)) { | |
1240 XUnmapWindow(wsDisplay, win->WindowID); // required for MWM | |
1241 XWithdrawWindow(wsDisplay, win->WindowID, wsScreen); | |
1242 } | |
1243 | |
1244 /* restore window if window manager doesn't support EWMH */ | |
1245 if (!(vo_fs_type & vo_wm_FULLSCREEN)) { | |
35697 | 1246 if (!win->isFullScreen) |
1247 wsWindowDecoration(win); | |
1248 | |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
1249 wsWindowSizeHint(win); |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1250 wsWindowLayer(wsDisplay, win->WindowID, win->isFullScreen); |
35672 | 1251 XMoveResizeWindow(wsDisplay, win->WindowID, win->X, win->Y, win->Width, win->Height); |
1252 } | |
1253 | |
1254 /* some window managers lose ontop after fullscreen */ | |
1255 if (!win->isFullScreen & vo_ontop) | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1256 wsWindowLayer(wsDisplay, win->WindowID, vo_ontop); |
35672 | 1257 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1258 wsWindowRaiseTop(wsDisplay, win->WindowID); |
35672 | 1259 XFlush(wsDisplay); |
1260 } | |
1261 | |
1262 /** | |
35355 | 1263 * @brief Iconify a window. |
1264 * | |
1265 * @param win pointer to a ws window structure | |
1266 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1267 void wsWindowIconify(wsWindow *win) |
33539 | 1268 { |
35355 | 1269 XIconifyWindow(wsDisplay, win->WindowID, 0); |
33539 | 1270 } |
23077 | 1271 |
35682 | 1272 void wsWindowVisibility(wsWindow *win, int vis) |
23077 | 1273 { |
35682 | 1274 switch (vis) { |
33539 | 1275 case wsShowWindow: |
35541 | 1276 |
33539 | 1277 XMapRaised(wsDisplay, win->WindowID); |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
1278 wsWindowMapWait(win); |
35541 | 1279 |
33952 | 1280 if (vo_fs_type & vo_wm_FULLSCREEN) |
1281 win->isFullScreen = False; | |
35541 | 1282 |
33539 | 1283 break; |
1284 | |
1285 case wsHideWindow: | |
35541 | 1286 |
33539 | 1287 XUnmapWindow(wsDisplay, win->WindowID); |
1288 break; | |
1289 } | |
1290 | |
1291 XFlush(wsDisplay); | |
23077 | 1292 } |
1293 | |
35672 | 1294 /** |
1295 * @brief Map a window and raise it to the top. | |
1296 * | |
1297 * @param display display | |
1298 * @param Win window | |
1299 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1300 void wsWindowRaiseTop(Display *display, Window Win) |
23077 | 1301 { |
35672 | 1302 XMapRaised(display, Win); // NOTE TO MYSELF: is that really enough? |
1303 XRaiseWindow(display, Win); // NOTE TO MYSELF: is that really enough? | |
23077 | 1304 } |
1305 | |
35672 | 1306 // ---------------------------------------------------------------------------------------------- |
1307 // Move window to selected layer | |
1308 // ---------------------------------------------------------------------------------------------- | |
1309 | |
1310 /** | |
1311 * @brief Set the layer for a window. | |
1312 * | |
1313 * @param display display | |
1314 * @param Win window | |
1315 * @param fullscreen whether to set fullscreen or normal layer | |
1316 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1317 void wsWindowLayer(Display *display, Window Win, Bool fullscreen) |
35672 | 1318 { |
1319 vo_x11_setlayer(display, Win, fullscreen); | |
1320 } | |
1321 | |
1322 // ---------------------------------------------------------------------------------------------- | |
1323 // Redraw screen. | |
1324 // ---------------------------------------------------------------------------------------------- | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1325 void wsWindowRedraw(wsWindow *win) |
35672 | 1326 { |
1327 if (win->ReDraw) { | |
1328 win->State = wsWindowExpose; | |
1329 win->ReDraw(); | |
1330 XFlush(wsDisplay); | |
1331 } | |
1332 } | |
1333 | |
1334 // ---------------------------------------------------------------------------------------------- | |
1335 // Put 'Image' to window. | |
1336 // ---------------------------------------------------------------------------------------------- | |
35682 | 1337 void wsImageCreate(wsWindow *win, int w, int h) |
23077 | 1338 { |
34465 | 1339 #ifdef HAVE_SHM |
33539 | 1340 if (wsUseXShm) { |
1341 win->xImage = XShmCreateImage(wsDisplay, win->VisualInfo.visual, | |
35682 | 1342 win->VisualInfo.depth, ZPixmap, NULL, &win->Shminfo, w, h); |
33539 | 1343 |
1344 if (win->xImage == NULL) { | |
1345 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ShmError); | |
33768 | 1346 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1347 } |
1348 | |
1349 win->Shminfo.shmid = shmget(IPC_PRIVATE, win->xImage->bytes_per_line * win->xImage->height, IPC_CREAT | 0777); | |
1350 | |
1351 if (win->Shminfo.shmid < 0) { | |
1352 XDestroyImage(win->xImage); | |
1353 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ShmError); | |
33768 | 1354 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1355 } |
1356 | |
1357 win->Shminfo.shmaddr = (char *)shmat(win->Shminfo.shmid, 0, 0); | |
1358 | |
1359 if (win->Shminfo.shmaddr == ((char *)-1)) { | |
1360 XDestroyImage(win->xImage); | |
23077 | 1361 |
33539 | 1362 if (win->Shminfo.shmaddr != ((char *)-1)) |
1363 shmdt(win->Shminfo.shmaddr); | |
1364 | |
1365 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ShmError); | |
33768 | 1366 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1367 } |
1368 | |
1369 win->xImage->data = win->Shminfo.shmaddr; | |
35493 | 1370 win->Shminfo.readOnly = False; |
33539 | 1371 XShmAttach(wsDisplay, &win->Shminfo); |
1372 XSync(wsDisplay, False); | |
1373 shmctl(win->Shminfo.shmid, IPC_RMID, 0); | |
34465 | 1374 } else |
1375 #endif | |
1376 { | |
33539 | 1377 win->xImage = XCreateImage(wsDisplay, win->VisualInfo.visual, win->VisualInfo.depth, |
35682 | 1378 ZPixmap, 0, 0, w, h, |
35676 | 1379 (wsScreenDepth == 3) ? 32 : wsScreenDepth, |
33539 | 1380 0); |
1381 | |
1382 if ((win->xImage->data = malloc(win->xImage->bytes_per_line * win->xImage->height)) == NULL) { | |
1383 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_NotEnoughMemoryDrawBuffer); | |
33768 | 1384 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1385 } |
23077 | 1386 } |
33539 | 1387 |
1388 win->ImageData = (unsigned char *)win->xImage->data; | |
1389 win->ImageDataw = (unsigned short int *)win->xImage->data; | |
1390 win->ImageDatadw = (unsigned int *)win->xImage->data; | |
23077 | 1391 } |
1392 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1393 void wsImageDestroy(wsWindow *win) |
35672 | 1394 { |
1395 if (win->xImage) { | |
1396 XDestroyImage(win->xImage); | |
1397 | |
1398 #ifdef HAVE_SHM | |
1399 if (wsUseXShm) { | |
1400 XShmDetach(wsDisplay, &win->Shminfo); | |
1401 shmdt(win->Shminfo.shmaddr); | |
1402 } | |
1403 #endif | |
1404 } | |
1405 | |
1406 win->xImage = NULL; | |
1407 } | |
1408 | |
35682 | 1409 void wsImageConvert(wsWindow *win, unsigned char *img) |
35672 | 1410 { |
1411 static struct SwsContext *sws_ctx; | |
35682 | 1412 const uint8_t *src[4] = { img, NULL, NULL, NULL }; |
35672 | 1413 int src_stride[4] = { 4 * win->xImage->width, 0, 0, 0 }; |
1414 uint8_t *dst[4] = { win->ImageData, NULL, NULL, NULL }; | |
1415 int dst_stride[4]; | |
1416 int i; | |
1417 | |
1418 sws_ctx = sws_getCachedContext(sws_ctx, win->xImage->width, win->xImage->height, PIX_FMT_RGB32, | |
1419 win->xImage->width, win->xImage->height, out_pix_fmt, | |
1420 SWS_POINT, NULL, NULL, NULL); | |
1421 av_image_fill_linesizes(dst_stride, out_pix_fmt, win->xImage->width); | |
1422 sws_scale(sws_ctx, src, src_stride, 0, win->xImage->height, dst, dst_stride); | |
1423 | |
1424 if (!wsNonNativeOrder) | |
1425 return; | |
1426 | |
1427 switch (win->xImage->bits_per_pixel) { | |
1428 case 32: | |
1429 { | |
1430 uint32_t *d = (uint32_t *)win->ImageData; | |
1431 | |
1432 for (i = 0; i < win->xImage->width * win->xImage->height; i++) | |
1433 d[i] = bswap_32(d[i]); | |
1434 | |
1435 break; | |
1436 } | |
1437 | |
1438 case 16: | |
1439 case 15: | |
1440 { | |
1441 uint16_t *d = (uint16_t *)win->ImageData; | |
1442 | |
1443 for (i = 0; i < win->xImage->width * win->xImage->height; i++) | |
1444 d[i] = bswap_16(d[i]); | |
1445 | |
1446 break; | |
1447 } | |
1448 } | |
1449 } | |
1450 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1451 void wsImageDraw(wsWindow *win) |
35672 | 1452 { |
1453 #ifdef HAVE_SHM | |
1454 if (wsUseXShm) { | |
1455 XShmPutImage(wsDisplay, win->WindowID, win->wGC, win->xImage, | |
1456 0, 0, | |
1457 (win->Width - win->xImage->width) / 2, (win->Height - win->xImage->height) / 2, | |
1458 win->xImage->width, win->xImage->height, 0); | |
1459 } else | |
1460 #endif | |
1461 { | |
1462 XPutImage(wsDisplay, win->WindowID, win->wGC, win->xImage, | |
1463 0, 0, | |
1464 (win->Width - win->xImage->width) / 2, (win->Height - win->xImage->height) / 2, | |
1465 win->xImage->width, win->xImage->height); | |
1466 } | |
1467 } | |
1468 | |
35682 | 1469 void wsImageResize(wsWindow *win, int w, int h) |
33539 | 1470 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1471 wsImageDestroy(win); |
35682 | 1472 wsImageCreate(win, w, h); |
33539 | 1473 } |
23077 | 1474 |
35672 | 1475 // ---------------------------------------------------------------------------------------------- |
1476 // Show / hide mouse cursor. | |
1477 // ---------------------------------------------------------------------------------------------- | |
35682 | 1478 void wsMouseVisibility(wsWindow *win, int vis) |
23077 | 1479 { |
35682 | 1480 switch (vis) { |
35672 | 1481 case wsShowMouseCursor: |
33539 | 1482 |
35672 | 1483 if (win->wsCursor != None) { |
1484 XFreeCursor(wsDisplay, win->wsCursor); | |
1485 win->wsCursor = None; | |
1486 } | |
33539 | 1487 |
35672 | 1488 XDefineCursor(wsDisplay, win->WindowID, 0); |
1489 break; | |
33539 | 1490 |
35672 | 1491 case wsHideMouseCursor: |
33539 | 1492 |
35672 | 1493 win->wsCursor = XCreatePixmapCursor(wsDisplay, win->wsCursorPixmap, win->wsCursorPixmap, &win->wsColor, &win->wsColor, 0, 0); |
1494 XDefineCursor(wsDisplay, win->WindowID, win->wsCursor); | |
1495 break; | |
1496 } | |
33539 | 1497 |
35672 | 1498 XFlush(wsDisplay); |
23077 | 1499 } |
1500 | |
35639 | 1501 /** |
35672 | 1502 * @brief Handle automatic hiding of the cursor. |
35639 | 1503 */ |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1504 void wsMouseAutohide(void) |
23077 | 1505 { |
35672 | 1506 if (mouse_win && (GetTimerMS() - mouse_time >= MOUSEHIDE_DELAY)) { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1507 wsMouseVisibility(mouse_win, wsHideMouseCursor); |
35672 | 1508 mouse_win = NULL; |
33542 | 1509 } |
23077 | 1510 } |