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