Mercurial > mplayer.hg
annotate gui/wm/ws.c @ 36053:7affacef2f88
Define "MPlayer" string.
author | ib |
---|---|
date | Thu, 04 Apr 2013 11:47:39 +0000 |
parents | c667e34fb941 |
children | 4489eafbe0a9 |
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 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
608 void wsEvents(void) |
35672 | 609 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
610 XEvent xev; |
35672 | 611 /* handle pending events */ |
612 while (XPending(wsDisplay)) { | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
613 XNextEvent(wsDisplay, &xev); |
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
614 // printf("### X event: %d [%d]\n",xev.type,delay); |
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
615 wsEvent(&xev); |
35672 | 616 } |
617 } | |
618 | |
33995 | 619 /** |
620 * @brief Calculate and store the x and y position for a window. | |
621 * | |
622 * @param win pointer to a ws window structure | |
623 * @param x x position of the window (real/absolute or mock) | |
624 * @param y y position of the window (real/absolute or mock) | |
625 * @param width width of the area to place the window in | |
626 * @param height height of the area to place the window in | |
627 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
628 static void wsWindowUpdatePosition(wsWindow *win, int x, int y, int width, int height) |
33995 | 629 { |
630 switch (x) { | |
631 case -1: | |
632 win->X = wsOrgX + (wsMaxX - width) / 2; | |
633 break; | |
634 | |
635 case -2: | |
636 win->X = wsOrgX + wsMaxX - width; | |
637 break; | |
638 | |
639 default: | |
640 win->X = x; | |
641 break; | |
642 } | |
643 | |
644 switch (y) { | |
645 case -1: | |
646 win->Y = wsOrgY + (wsMaxY - height) / 2; | |
647 break; | |
648 | |
649 case -2: | |
650 win->Y = wsOrgY + wsMaxY - height; | |
651 break; | |
652 | |
653 default: | |
654 win->Y = y; | |
655 break; | |
656 } | |
657 } | |
658 | |
35645 | 659 /** |
660 * @brief Replace the size hints for the WM_NORMAL_HINTS property of a window. | |
661 * | |
662 * @param win pointer to a ws window structure | |
663 */ | |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
664 static void wsWindowSizeHint(wsWindow *win) |
35645 | 665 { |
35660 | 666 XSizeHints size; |
667 | |
668 size.flags = 0; | |
35645 | 669 |
35648 | 670 /* obsolete, solely for compatibility reasons */ |
35660 | 671 size.flags |= PPosition; |
672 size.x = win->X; | |
673 size.y = win->Y; | |
35645 | 674 |
35648 | 675 /* obsolete, solely for compatibility reasons */ |
35660 | 676 size.flags |= PSize; |
677 size.width = win->Width; | |
678 size.height = win->Height; | |
35645 | 679 |
35648 | 680 /* a minimum of 4 is said to avoid off-by-one errors and be required by mga_vid */ |
35660 | 681 size.flags |= PMinSize; |
682 size.min_width = 4; | |
683 size.min_height = 4; | |
35648 | 684 |
685 if (win->Property & wsMinSize) { | |
35660 | 686 size.min_width = win->Width; |
687 size.min_height = win->Height; | |
35645 | 688 } |
689 | |
35648 | 690 if (win->Property & wsMaxSize) { |
35660 | 691 size.flags |= PMaxSize; |
692 size.max_width = win->Width; | |
693 size.max_height = win->Height; | |
35645 | 694 } |
695 | |
35657 | 696 if (vo_keepaspect && (win->Property & wsAspect)) { |
35660 | 697 size.flags |= PAspect; |
698 size.min_aspect.x = win->Width; | |
699 size.min_aspect.y = win->Height; | |
700 size.max_aspect.x = win->Width; | |
701 size.max_aspect.y = win->Height; | |
35645 | 702 } |
703 | |
35660 | 704 size.flags |= PBaseSize; |
705 size.base_width = 0; | |
706 size.base_height = 0; | |
35645 | 707 |
35660 | 708 size.flags |= PWinGravity; |
709 size.win_gravity = StaticGravity; | |
35645 | 710 |
35660 | 711 XSetWMNormalHints(wsDisplay, win->WindowID, &size); |
35645 | 712 } |
713 | |
35699 | 714 static void wsWindowDecoration(wsWindow *win) |
35698 | 715 { |
716 Atom wsMotifHints; | |
717 struct { | |
718 unsigned long flags; | |
719 unsigned long functions; | |
720 unsigned long decorations; | |
721 long input_mode; | |
722 unsigned long status; | |
723 } wsMotifWmHints; | |
724 | |
725 wsMotifHints = XInternAtom(wsDisplay, "_MOTIF_WM_HINTS", 0); | |
726 | |
727 if (wsMotifHints == None) | |
728 return; | |
729 | |
730 memset(&wsMotifWmHints, 0, sizeof(wsMotifWmHints)); | |
731 wsMotifWmHints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; | |
732 | |
733 if (win->Decoration) { | |
734 wsMotifWmHints.functions = MWM_FUNC_MOVE | MWM_FUNC_CLOSE | MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE; | |
735 | |
736 if (!(win->Property & wsMinSize) || !(win->Property & wsMaxSize)) | |
737 wsMotifWmHints.functions |= MWM_FUNC_RESIZE; | |
738 | |
739 wsMotifWmHints.decorations = MWM_DECOR_ALL; | |
740 } | |
741 | |
742 XChangeProperty(wsDisplay, win->WindowID, wsMotifHints, wsMotifHints, 32, | |
743 PropModeReplace, (unsigned char *)&wsMotifWmHints, 5); | |
744 } | |
745 | |
35652 | 746 /** |
747 * @brief Wait until a window is mapped if its property requires it. | |
748 * | |
749 * @param win pointer to a ws window structure | |
750 */ | |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
751 static void wsWindowMapWait(wsWindow *win) |
35652 | 752 { |
753 XEvent xev; | |
754 | |
35653 | 755 if (win->Property & wsWaitMap) { |
35652 | 756 do |
757 XNextEvent(wsDisplay, &xev); | |
758 while (xev.type != MapNotify || xev.xmap.event != win->WindowID); | |
35653 | 759 |
760 win->Mapped = wsMapped; | |
761 } | |
35652 | 762 } |
763 | |
23077 | 764 // ---------------------------------------------------------------------------------------------- |
765 // Create window. | |
766 // X,Y : window position | |
767 // wX,wY : size of window | |
768 // bW : border width | |
769 // cV : visible mouse cursor on window | |
770 // D : visible frame, title, etc. | |
771 // sR : screen ratio | |
772 // ---------------------------------------------------------------------------------------------- | |
773 | |
33539 | 774 XClassHint wsClassHint; |
775 XTextProperty wsTextProperty; | |
776 Window LeaderWindow; | |
23077 | 777 |
35655 | 778 // ---------------------------------------------------------------------------------------------- |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
779 // wsWindowCreate: create a new window on the screen. |
35655 | 780 // x,y : window position |
781 // w,h : window size | |
782 // c : mouse cursor visible | |
783 // p : properties - "decoration", visible titlebar, etc ... | |
784 // ---------------------------------------------------------------------------------------------- | |
35687 | 785 void wsWindowCreate(wsWindow *win, int x, int y, int w, int h, int p, int c, char *label) |
23077 | 786 { |
33539 | 787 int depth; |
788 | |
35655 | 789 win->Property = p; |
23077 | 790 |
35697 | 791 win->Decoration = ((p & wsShowFrame) != 0); |
33539 | 792 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
793 wsWindowUpdatePosition(win, x, y, w, h); |
33539 | 794 |
35655 | 795 win->Width = w; |
796 win->Height = h; | |
33539 | 797 win->OldX = win->X; |
798 win->OldY = win->Y; | |
799 win->OldWidth = win->Width; | |
800 win->OldHeight = win->Height; | |
23077 | 801 |
34684 | 802 /* Hide Mouse Cursor */ |
33539 | 803 win->wsCursor = None; |
35655 | 804 win->wsMouseEventType = c; |
33539 | 805 win->wsCursorData[0] = 0; |
806 win->wsCursorPixmap = XCreateBitmapFromData(wsDisplay, wsRootWin, win->wsCursorData, 1, 1); | |
23077 | 807 |
35655 | 808 if (!(c & wsShowMouseCursor)) |
33539 | 809 win->wsCursor = XCreatePixmapCursor(wsDisplay, win->wsCursorPixmap, win->wsCursorPixmap, &win->wsColor, &win->wsColor, 0, 0); |
810 | |
811 depth = vo_find_depth_from_visuals(wsDisplay, wsScreen, NULL); | |
812 | |
813 if (depth < 15) { | |
814 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ColorDepthTooLow); | |
33768 | 815 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 816 } |
817 | |
818 XMatchVisualInfo(wsDisplay, wsScreen, depth, TrueColor, &win->VisualInfo); | |
23077 | 819 |
34684 | 820 /* --- */ |
33539 | 821 win->AtomLeaderClient = XInternAtom(wsDisplay, "WM_CLIENT_LEADER", False); |
822 win->AtomDeleteWindow = XInternAtom(wsDisplay, "WM_DELETE_WINDOW", False); | |
823 win->AtomTakeFocus = XInternAtom(wsDisplay, "WM_TAKE_FOCUS", False); | |
824 win->AtomRolle = XInternAtom(wsDisplay, "WM_WINDOW_ROLE", False); | |
825 win->AtomWMSizeHint = XInternAtom(wsDisplay, "WM_SIZE_HINT", False); | |
826 win->AtomWMNormalHint = XInternAtom(wsDisplay, "WM_NORMAL_HINT", False); | |
827 win->AtomProtocols = XInternAtom(wsDisplay, "WM_PROTOCOLS", False); | |
828 win->AtomsProtocols[0] = win->AtomDeleteWindow; | |
829 win->AtomsProtocols[1] = win->AtomTakeFocus; | |
830 win->AtomsProtocols[2] = win->AtomRolle; | |
34684 | 831 /* --- */ |
23077 | 832 |
35737 | 833 win->WindowAttrib.border_pixel = WhitePixel(wsDisplay, wsScreen); |
834 win->WindowAttrib.colormap = XCreateColormap(wsDisplay, wsRootWin, win->VisualInfo.visual, AllocNone); | |
835 win->WindowAttrib.event_mask = StructureNotifyMask | FocusChangeMask | | |
836 ExposureMask | PropertyChangeMask | | |
837 EnterWindowMask | LeaveWindowMask | | |
838 VisibilityChangeMask | | |
839 KeyPressMask | KeyReleaseMask; | |
23077 | 840 |
35655 | 841 if ((c & wsHandleMouseButton)) |
33539 | 842 win->WindowAttrib.event_mask |= ButtonPressMask | ButtonReleaseMask; |
843 | |
35655 | 844 if ((c & wsHandleMouseMove)) |
33539 | 845 win->WindowAttrib.event_mask |= PointerMotionMask; |
846 | |
847 win->WindowAttrib.cursor = win->wsCursor; | |
848 win->WindowAttrib.override_redirect = False; | |
849 | |
35655 | 850 if (p & wsOverredirect) |
33539 | 851 win->WindowAttrib.override_redirect = True; |
23077 | 852 |
35736
f1a696672425
Remove setting pointless window attribute CWBackPixel.
ib
parents:
35734
diff
changeset
|
853 win->WindowMask = CWBorderPixel | |
33539 | 854 CWColormap | CWEventMask | CWCursor | |
855 CWOverrideRedirect; | |
23077 | 856 |
33539 | 857 win->WindowID = XCreateWindow(wsDisplay, |
858 (win->Parent != 0 ? win->Parent : wsRootWin), | |
35683
75155d8a9c7e
Remove parameter for border_width from wsWindowCreate().
ib
parents:
35682
diff
changeset
|
859 win->X, win->Y, win->Width, win->Height, 0, |
33539 | 860 win->VisualInfo.depth, |
861 InputOutput, | |
862 win->VisualInfo.visual, | |
863 win->WindowMask, &win->WindowAttrib); | |
23077 | 864 |
36053 | 865 wsClassHint.res_name = MPlayer; |
33539 | 866 |
36053 | 867 wsClassHint.res_class = MPlayer; |
33539 | 868 XSetClassHint(wsDisplay, win->WindowID, &wsClassHint); |
869 | |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
870 wsWindowSizeHint(win); |
23077 | 871 |
33539 | 872 win->WMHints.flags = InputHint | StateHint; |
873 win->WMHints.input = True; | |
874 win->WMHints.initial_state = NormalState; | |
875 XSetWMHints(wsDisplay, win->WindowID, &win->WMHints); | |
23077 | 876 |
35697 | 877 wsWindowDecoration(win); |
33539 | 878 XStoreName(wsDisplay, win->WindowID, label); |
879 XmbSetWMProperties(wsDisplay, win->WindowID, label, label, NULL, 0, NULL, NULL, NULL); | |
23077 | 880 |
33539 | 881 XSetWMProtocols(wsDisplay, win->WindowID, win->AtomsProtocols, 3); |
882 XChangeProperty(wsDisplay, win->WindowID, | |
883 win->AtomLeaderClient, | |
884 XA_WINDOW, 32, PropModeReplace, | |
885 (unsigned char *)&LeaderWindow, 1); | |
23077 | 886 |
33539 | 887 wsTextProperty.value = label; |
888 wsTextProperty.encoding = XA_STRING; | |
889 wsTextProperty.format = 8; | |
890 wsTextProperty.nitems = strlen(label); | |
891 XSetWMIconName(wsDisplay, win->WindowID, &wsTextProperty); | |
892 | |
893 win->wGC = XCreateGC(wsDisplay, win->WindowID, | |
35679 | 894 0, |
895 NULL); | |
23077 | 896 |
35498
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
897 win->Visible = wsNo; |
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
898 win->Focused = wsNo; |
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
899 win->Mapped = wsNo; |
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
900 win->Rolled = wsNo; |
23077 | 901 |
35655 | 902 if (p & wsShowWindow) { |
33539 | 903 XMapWindow(wsDisplay, win->WindowID); |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
904 wsWindowMapWait(win); |
35652 | 905 } |
23077 | 906 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
907 wsImageCreate(win, win->Width, win->Height); |
34684 | 908 /* End of creating -------------------------------------------------------------------------- */ |
23077 | 909 |
33539 | 910 { |
911 int i; | |
912 | |
913 for (i = 0; i < wsWLCount; i++) | |
914 if (wsWindowList[i] == NULL) | |
915 break; | |
916 | |
917 if (i == wsWLCount) { | |
918 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_TooManyOpenWindows); | |
33768 | 919 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 920 } |
23077 | 921 |
33539 | 922 wsWindowList[i] = win; |
923 } | |
924 | |
925 XFlush(wsDisplay); | |
926 XSync(wsDisplay, False); | |
23077 | 927 |
35760 | 928 win->DrawHandler = NULL; |
33539 | 929 win->MouseHandler = NULL; |
930 win->KeyHandler = NULL; | |
33985 | 931 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] window is created. ( %s ).\n", label); |
23077 | 932 } |
933 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
934 void wsWindowDestroy(wsWindow *win) |
23077 | 935 { |
33539 | 936 int l; |
937 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
938 l = wsWindowListSearch(win->WindowID); |
35354 | 939 |
940 if (l != -1) | |
941 wsWindowList[l] = NULL; | |
33539 | 942 |
35760 | 943 win->DrawHandler = NULL; |
35752 | 944 win->MouseHandler = NULL; |
945 win->KeyHandler = NULL; | |
35759 | 946 win->DNDHandler = NULL; |
35752 | 947 |
33539 | 948 if (win->wsCursor != None) { |
949 XFreeCursor(wsDisplay, win->wsCursor); | |
950 win->wsCursor = None; | |
951 } | |
952 | |
953 XFreeGC(wsDisplay, win->wGC); | |
954 XUnmapWindow(wsDisplay, win->WindowID); | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
955 wsImageDestroy(win); |
33539 | 956 XDestroyWindow(wsDisplay, win->WindowID); |
23077 | 957 #if 0 |
35753 | 958 win->Visible = wsNo; |
959 win->Focused = wsNo; | |
960 win->Mapped = wsNo; | |
961 win->Rolled = wsNo; | |
23077 | 962 #endif |
963 } | |
964 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
965 void wsWindowShape(wsWindow *win, char *data) |
35672 | 966 { |
967 #ifdef CONFIG_XSHAPE | |
968 if (!wsUseXShape) | |
969 return; | |
970 | |
971 if (data) { | |
972 win->Mask = XCreateBitmapFromData(wsDisplay, win->WindowID, data, win->Width, win->Height); | |
973 XShapeCombineMask(wsDisplay, win->WindowID, ShapeBounding, 0, 0, win->Mask, ShapeSet); | |
974 XFreePixmap(wsDisplay, win->Mask); | |
975 } else | |
976 XShapeCombineMask(wsDisplay, win->WindowID, ShapeBounding, 0, 0, None, ShapeSet); | |
977 #endif | |
978 } | |
979 | |
34081 | 980 /** |
35672 | 981 * @brief Set differently sized icons to a window. |
982 * | |
983 * This function sets the X icon hint as well as | |
984 * the properties KWM_WIN_ICON and _NET_WM_ICON. | |
985 * | |
986 * @param display display | |
987 * @param Win window | |
988 * @param icon pointer to the icons | |
34081 | 989 */ |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
990 void wsWindowIcon(Display *display, Window Win, guiIcon_t *icon) |
34081 | 991 { |
35672 | 992 XWMHints *wm; |
993 Atom iconatom; | |
994 long data[2]; | |
995 | |
996 if (icon->normal) { | |
997 wm = XGetWMHints(display, Win); | |
998 | |
999 if (!wm) | |
1000 wm = XAllocWMHints(); | |
1001 | |
1002 wm->icon_pixmap = icon->normal; | |
1003 wm->icon_mask = icon->normal_mask; | |
1004 wm->flags |= IconPixmapHint | IconMaskHint; | |
1005 | |
1006 XSetWMHints(display, Win, wm); | |
1007 XFree(wm); | |
1008 } | |
1009 | |
1010 if (icon->small || icon->normal) { | |
1011 iconatom = XInternAtom(display, "KWM_WIN_ICON", False); | |
1012 data[0] = (icon->small ? icon->small : icon->normal); | |
1013 data[1] = (icon->small ? icon->small_mask : icon->normal_mask); | |
1014 | |
1015 XChangeProperty(display, Win, iconatom, iconatom, 32, PropModeReplace, (unsigned char *)data, 2); | |
1016 } | |
1017 | |
1018 if (icon->collection) { | |
1019 iconatom = XInternAtom(display, "_NET_WM_ICON", False); | |
1020 XChangeProperty(display, Win, iconatom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)icon->collection, icon->collection_size); | |
34081 | 1021 } |
1022 } | |
1023 | |
35730 | 1024 /** |
1025 * @brief Pack color components @a r, @a g and @a b into 15 bits. | |
1026 * | |
1027 * @param r red (0 - 255) | |
1028 * @param g green (0 - 255) | |
1029 * @param b blue (0 - 255) | |
1030 * | |
1031 * @return pixel suitable for a RGB 15 bits color format | |
1032 */ | |
1033 static int pack_rgb15(int r, int g, int b) | |
1034 { | |
1035 int pixel; | |
1036 | |
35734 | 1037 pixel = r >> 3; |
35730 | 1038 pixel <<= 5; |
35734 | 1039 pixel |= g >> 3; |
35730 | 1040 pixel <<= 5; |
35734 | 1041 pixel |= b >> 3; |
35730 | 1042 |
1043 return pixel; | |
1044 } | |
1045 | |
1046 /** | |
1047 * @brief Pack color components @a r, @a g and @a b into 16 bits. | |
1048 * | |
1049 * @param r red (0 - 255) | |
1050 * @param g green (0 - 255) | |
1051 * @param b blue (0 - 255) | |
1052 * | |
1053 * @return pixel suitable for a RGB 16 bits color format | |
1054 */ | |
1055 static int pack_rgb16(int r, int g, int b) | |
1056 { | |
1057 int pixel; | |
1058 | |
35734 | 1059 pixel = r >> 3; |
35730 | 1060 pixel <<= 6; |
35734 | 1061 pixel |= g >> 2; |
35730 | 1062 pixel <<= 5; |
35734 | 1063 pixel |= b >> 3; |
35730 | 1064 |
1065 return pixel; | |
1066 } | |
1067 | |
35755
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1068 /** |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1069 * @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
|
1070 * |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1071 * @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
|
1072 * @param r red (0 - 255, or -1) |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1073 * @param g green (0 - 255, or -1) |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1074 * @param b blue (0 - 255, or -1) |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1075 * |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1076 * @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
|
1077 */ |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1078 void wsWindowBackground(wsWindow *win, int r, int g, int b) |
23077 | 1079 { |
35672 | 1080 int color = 0; |
35541 | 1081 |
35733 | 1082 switch (out_pix_fmt) { |
1083 case PIX_FMT_RGB32: | |
1084 case PIX_FMT_RGB24: | |
35672 | 1085 color = (r << 16) + (g << 8) + b; |
23077 | 1086 break; |
1087 | |
35733 | 1088 case PIX_FMT_BGR32: |
1089 case PIX_FMT_BGR24: | |
35672 | 1090 color = (b << 16) + (g << 8) + r; |
1091 break; | |
33539 | 1092 |
35733 | 1093 case PIX_FMT_RGB565: |
35730 | 1094 color = pack_rgb16(r, g, b); |
23077 | 1095 break; |
1096 | |
35733 | 1097 case PIX_FMT_BGR565: |
35730 | 1098 color = pack_rgb16(b, g, r); |
35728 | 1099 break; |
1100 | |
35733 | 1101 case PIX_FMT_RGB555: |
35730 | 1102 color = pack_rgb15(r, g, b); |
23077 | 1103 break; |
1104 | |
35733 | 1105 case PIX_FMT_BGR555: |
35730 | 1106 color = pack_rgb15(b, g, r); |
33539 | 1107 break; |
35733 | 1108 |
1109 default: | |
1110 ; | |
33539 | 1111 } |
1112 | |
35755
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1113 if (r == -1 && g == -1 && b == -1) |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1114 XSetWindowBackgroundPixmap(wsDisplay, win->WindowID, None); |
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1115 else { |
35756 | 1116 XSetWindowBackground(wsDisplay, win->WindowID, color); |
1117 XClearWindow(wsDisplay, win->WindowID); | |
35755
589cf8a5f165
Realize a smooth and flicker-free video when resizing during playback.
ib
parents:
35754
diff
changeset
|
1118 } |
23077 | 1119 } |
1120 | |
1121 // ---------------------------------------------------------------------------------------------- | |
1122 // Move window to x, y. | |
1123 // ---------------------------------------------------------------------------------------------- | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1124 void wsWindowMove(wsWindow *win, Bool abs, int x, int y) |
23077 | 1125 { |
33993 | 1126 if (abs) { |
1127 win->X = x; | |
1128 win->Y = y; | |
33995 | 1129 } else |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1130 wsWindowUpdatePosition(win, x, y, win->Width, win->Height); |
23077 | 1131 |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
1132 wsWindowSizeHint(win); |
33539 | 1133 XMoveWindow(wsDisplay, win->WindowID, win->X, win->Y); |
23077 | 1134 } |
1135 | |
33998
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1136 /** |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1137 * @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
|
1138 * 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
|
1139 * |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1140 * @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
|
1141 * @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
|
1142 * @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
|
1143 * @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
|
1144 */ |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1145 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
|
1146 { |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1147 Bool fitting = True; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1148 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1149 wsWindowMove(win, abs, x, y); |
33998
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1150 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1151 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
|
1152 fitting = False; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1153 win->X = wsMaxX - win->Width; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1154 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1155 if (win->X < 0) |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1156 win->X = 0; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1157 } |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1158 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1159 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
|
1160 fitting = False; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1161 win->Y = wsMaxY - win->Height; |
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->Y < 0) |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1164 win->Y = 0; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1165 } |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1166 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1167 if (!fitting) |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1168 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
|
1169 } |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1170 |
23077 | 1171 // ---------------------------------------------------------------------------------------------- |
1172 // Resize window to sx, sy. | |
1173 // ---------------------------------------------------------------------------------------------- | |
35682 | 1174 void wsWindowResize(wsWindow *win, int w, int h) |
23077 | 1175 { |
35682 | 1176 win->Width = w; |
1177 win->Height = h; | |
23077 | 1178 |
33539 | 1179 if (vo_wm_type == 0) |
1180 XUnmapWindow(wsDisplay, win->WindowID); | |
23077 | 1181 |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
1182 wsWindowSizeHint(win); |
35682 | 1183 XResizeWindow(wsDisplay, win->WindowID, w, h); |
33539 | 1184 |
34124 | 1185 if (vo_wm_type == 0) |
1186 XMapWindow(wsDisplay, win->WindowID); | |
23077 | 1187 } |
1188 | |
35355 | 1189 /** |
35672 | 1190 * @brief Switch window fullscreen state. |
1191 * | |
1192 * Switch normal window to fullscreen and fullscreen window to normal. | |
1193 * | |
1194 * @param win pointer to a ws window structure | |
1195 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1196 void wsWindowFullscreen(wsWindow *win) |
35672 | 1197 { |
1198 if (win->isFullScreen) { | |
1199 if (vo_fs_type & vo_wm_FULLSCREEN) | |
1200 /* window manager supports EWMH */ | |
1201 vo_x11_ewmh_fullscreen(win->WindowID, _NET_WM_STATE_REMOVE); | |
1202 else { | |
1203 win->X = win->OldX; | |
1204 win->Y = win->OldY; | |
1205 win->Width = win->OldWidth; | |
1206 win->Height = win->OldHeight; | |
1207 } | |
1208 | |
1209 win->isFullScreen = False; | |
1210 } else { | |
1211 if (vo_fs_type & vo_wm_FULLSCREEN) | |
1212 /* window manager supports EWMH */ | |
1213 vo_x11_ewmh_fullscreen(win->WindowID, _NET_WM_STATE_ADD); | |
1214 else { | |
1215 win->OldX = win->X; | |
1216 win->OldY = win->Y; | |
1217 win->OldWidth = win->Width; | |
1218 win->OldHeight = win->Height; | |
1219 } | |
1220 | |
1221 win->isFullScreen = True; | |
1222 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1223 wsWindowUpdateXinerama(win); |
35672 | 1224 } |
1225 | |
1226 /* unknown window manager and obsolete option -fsmode used */ | |
1227 if (vo_wm_type == 0 && !(vo_fsmode & 16)) { | |
1228 XUnmapWindow(wsDisplay, win->WindowID); // required for MWM | |
1229 XWithdrawWindow(wsDisplay, win->WindowID, wsScreen); | |
1230 } | |
1231 | |
1232 /* restore window if window manager doesn't support EWMH */ | |
1233 if (!(vo_fs_type & vo_wm_FULLSCREEN)) { | |
35697 | 1234 if (!win->isFullScreen) |
1235 wsWindowDecoration(win); | |
1236 | |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
1237 wsWindowSizeHint(win); |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1238 wsWindowLayer(wsDisplay, win->WindowID, win->isFullScreen); |
35672 | 1239 XMoveResizeWindow(wsDisplay, win->WindowID, win->X, win->Y, win->Width, win->Height); |
1240 } | |
1241 | |
1242 /* some window managers lose ontop after fullscreen */ | |
1243 if (!win->isFullScreen & vo_ontop) | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1244 wsWindowLayer(wsDisplay, win->WindowID, vo_ontop); |
35672 | 1245 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1246 wsWindowRaiseTop(wsDisplay, win->WindowID); |
35672 | 1247 XFlush(wsDisplay); |
1248 } | |
1249 | |
1250 /** | |
35355 | 1251 * @brief Iconify a window. |
1252 * | |
1253 * @param win pointer to a ws window structure | |
1254 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1255 void wsWindowIconify(wsWindow *win) |
33539 | 1256 { |
35355 | 1257 XIconifyWindow(wsDisplay, win->WindowID, 0); |
33539 | 1258 } |
23077 | 1259 |
35682 | 1260 void wsWindowVisibility(wsWindow *win, int vis) |
23077 | 1261 { |
35682 | 1262 switch (vis) { |
33539 | 1263 case wsShowWindow: |
35541 | 1264 |
33539 | 1265 XMapRaised(wsDisplay, win->WindowID); |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
1266 wsWindowMapWait(win); |
35541 | 1267 |
33952 | 1268 if (vo_fs_type & vo_wm_FULLSCREEN) |
1269 win->isFullScreen = False; | |
35541 | 1270 |
33539 | 1271 break; |
1272 | |
1273 case wsHideWindow: | |
35541 | 1274 |
33539 | 1275 XUnmapWindow(wsDisplay, win->WindowID); |
1276 break; | |
1277 } | |
1278 | |
1279 XFlush(wsDisplay); | |
23077 | 1280 } |
1281 | |
35672 | 1282 /** |
1283 * @brief Map a window and raise it to the top. | |
1284 * | |
1285 * @param display display | |
1286 * @param Win window | |
1287 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1288 void wsWindowRaiseTop(Display *display, Window Win) |
23077 | 1289 { |
35672 | 1290 XMapRaised(display, Win); // NOTE TO MYSELF: is that really enough? |
1291 XRaiseWindow(display, Win); // NOTE TO MYSELF: is that really enough? | |
23077 | 1292 } |
1293 | |
35672 | 1294 // ---------------------------------------------------------------------------------------------- |
1295 // Move window to selected layer | |
1296 // ---------------------------------------------------------------------------------------------- | |
1297 | |
1298 /** | |
1299 * @brief Set the layer for a window. | |
1300 * | |
1301 * @param display display | |
1302 * @param Win window | |
1303 * @param fullscreen whether to set fullscreen or normal layer | |
1304 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1305 void wsWindowLayer(Display *display, Window Win, Bool fullscreen) |
35672 | 1306 { |
1307 vo_x11_setlayer(display, Win, fullscreen); | |
1308 } | |
1309 | |
1310 // ---------------------------------------------------------------------------------------------- | |
1311 // Redraw screen. | |
1312 // ---------------------------------------------------------------------------------------------- | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1313 void wsWindowRedraw(wsWindow *win) |
35672 | 1314 { |
35760 | 1315 if (win->DrawHandler) { |
35672 | 1316 win->State = wsWindowExpose; |
35760 | 1317 win->DrawHandler(); |
35672 | 1318 XFlush(wsDisplay); |
1319 } | |
1320 } | |
1321 | |
1322 // ---------------------------------------------------------------------------------------------- | |
1323 // Put 'Image' to window. | |
1324 // ---------------------------------------------------------------------------------------------- | |
35682 | 1325 void wsImageCreate(wsWindow *win, int w, int h) |
23077 | 1326 { |
34465 | 1327 #ifdef HAVE_SHM |
33539 | 1328 if (wsUseXShm) { |
1329 win->xImage = XShmCreateImage(wsDisplay, win->VisualInfo.visual, | |
35682 | 1330 win->VisualInfo.depth, ZPixmap, NULL, &win->Shminfo, w, h); |
33539 | 1331 |
1332 if (win->xImage == NULL) { | |
1333 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ShmError); | |
33768 | 1334 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1335 } |
1336 | |
1337 win->Shminfo.shmid = shmget(IPC_PRIVATE, win->xImage->bytes_per_line * win->xImage->height, IPC_CREAT | 0777); | |
1338 | |
1339 if (win->Shminfo.shmid < 0) { | |
1340 XDestroyImage(win->xImage); | |
1341 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ShmError); | |
33768 | 1342 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1343 } |
1344 | |
1345 win->Shminfo.shmaddr = (char *)shmat(win->Shminfo.shmid, 0, 0); | |
1346 | |
1347 if (win->Shminfo.shmaddr == ((char *)-1)) { | |
1348 XDestroyImage(win->xImage); | |
23077 | 1349 |
33539 | 1350 if (win->Shminfo.shmaddr != ((char *)-1)) |
1351 shmdt(win->Shminfo.shmaddr); | |
1352 | |
1353 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ShmError); | |
33768 | 1354 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1355 } |
1356 | |
1357 win->xImage->data = win->Shminfo.shmaddr; | |
35493 | 1358 win->Shminfo.readOnly = False; |
33539 | 1359 XShmAttach(wsDisplay, &win->Shminfo); |
1360 XSync(wsDisplay, False); | |
1361 shmctl(win->Shminfo.shmid, IPC_RMID, 0); | |
34465 | 1362 } else |
1363 #endif | |
1364 { | |
33539 | 1365 win->xImage = XCreateImage(wsDisplay, win->VisualInfo.visual, win->VisualInfo.depth, |
35682 | 1366 ZPixmap, 0, 0, w, h, |
35676 | 1367 (wsScreenDepth == 3) ? 32 : wsScreenDepth, |
33539 | 1368 0); |
1369 | |
1370 if ((win->xImage->data = malloc(win->xImage->bytes_per_line * win->xImage->height)) == NULL) { | |
1371 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_NotEnoughMemoryDrawBuffer); | |
33768 | 1372 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1373 } |
23077 | 1374 } |
33539 | 1375 |
1376 win->ImageData = (unsigned char *)win->xImage->data; | |
1377 win->ImageDataw = (unsigned short int *)win->xImage->data; | |
1378 win->ImageDatadw = (unsigned int *)win->xImage->data; | |
23077 | 1379 } |
1380 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1381 void wsImageDestroy(wsWindow *win) |
35672 | 1382 { |
1383 if (win->xImage) { | |
1384 XDestroyImage(win->xImage); | |
1385 | |
1386 #ifdef HAVE_SHM | |
1387 if (wsUseXShm) { | |
1388 XShmDetach(wsDisplay, &win->Shminfo); | |
1389 shmdt(win->Shminfo.shmaddr); | |
1390 } | |
1391 #endif | |
1392 } | |
1393 | |
1394 win->xImage = NULL; | |
1395 } | |
1396 | |
35744 | 1397 void wsImageRender(wsWindow *win, unsigned char *img) |
35672 | 1398 { |
1399 static struct SwsContext *sws_ctx; | |
35682 | 1400 const uint8_t *src[4] = { img, NULL, NULL, NULL }; |
35672 | 1401 int src_stride[4] = { 4 * win->xImage->width, 0, 0, 0 }; |
1402 uint8_t *dst[4] = { win->ImageData, NULL, NULL, NULL }; | |
1403 int dst_stride[4]; | |
1404 int i; | |
1405 | |
1406 sws_ctx = sws_getCachedContext(sws_ctx, win->xImage->width, win->xImage->height, PIX_FMT_RGB32, | |
1407 win->xImage->width, win->xImage->height, out_pix_fmt, | |
1408 SWS_POINT, NULL, NULL, NULL); | |
1409 av_image_fill_linesizes(dst_stride, out_pix_fmt, win->xImage->width); | |
1410 sws_scale(sws_ctx, src, src_stride, 0, win->xImage->height, dst, dst_stride); | |
1411 | |
1412 if (!wsNonNativeOrder) | |
1413 return; | |
1414 | |
1415 switch (win->xImage->bits_per_pixel) { | |
1416 case 32: | |
1417 { | |
1418 uint32_t *d = (uint32_t *)win->ImageData; | |
1419 | |
1420 for (i = 0; i < win->xImage->width * win->xImage->height; i++) | |
1421 d[i] = bswap_32(d[i]); | |
1422 | |
1423 break; | |
1424 } | |
1425 | |
1426 case 16: | |
1427 case 15: | |
1428 { | |
1429 uint16_t *d = (uint16_t *)win->ImageData; | |
1430 | |
1431 for (i = 0; i < win->xImage->width * win->xImage->height; i++) | |
1432 d[i] = bswap_16(d[i]); | |
1433 | |
1434 break; | |
1435 } | |
1436 } | |
1437 } | |
1438 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1439 void wsImageDraw(wsWindow *win) |
35672 | 1440 { |
1441 #ifdef HAVE_SHM | |
1442 if (wsUseXShm) { | |
1443 XShmPutImage(wsDisplay, win->WindowID, win->wGC, win->xImage, | |
1444 0, 0, | |
1445 (win->Width - win->xImage->width) / 2, (win->Height - win->xImage->height) / 2, | |
1446 win->xImage->width, win->xImage->height, 0); | |
1447 } else | |
1448 #endif | |
1449 { | |
1450 XPutImage(wsDisplay, win->WindowID, win->wGC, win->xImage, | |
1451 0, 0, | |
1452 (win->Width - win->xImage->width) / 2, (win->Height - win->xImage->height) / 2, | |
1453 win->xImage->width, win->xImage->height); | |
1454 } | |
1455 } | |
1456 | |
35682 | 1457 void wsImageResize(wsWindow *win, int w, int h) |
33539 | 1458 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1459 wsImageDestroy(win); |
35682 | 1460 wsImageCreate(win, w, h); |
33539 | 1461 } |
23077 | 1462 |
35672 | 1463 // ---------------------------------------------------------------------------------------------- |
1464 // Show / hide mouse cursor. | |
1465 // ---------------------------------------------------------------------------------------------- | |
35682 | 1466 void wsMouseVisibility(wsWindow *win, int vis) |
23077 | 1467 { |
35682 | 1468 switch (vis) { |
35672 | 1469 case wsShowMouseCursor: |
33539 | 1470 |
35672 | 1471 if (win->wsCursor != None) { |
1472 XFreeCursor(wsDisplay, win->wsCursor); | |
1473 win->wsCursor = None; | |
1474 } | |
33539 | 1475 |
35672 | 1476 XDefineCursor(wsDisplay, win->WindowID, 0); |
1477 break; | |
33539 | 1478 |
35672 | 1479 case wsHideMouseCursor: |
33539 | 1480 |
35672 | 1481 win->wsCursor = XCreatePixmapCursor(wsDisplay, win->wsCursorPixmap, win->wsCursorPixmap, &win->wsColor, &win->wsColor, 0, 0); |
1482 XDefineCursor(wsDisplay, win->WindowID, win->wsCursor); | |
1483 break; | |
1484 } | |
33539 | 1485 |
35672 | 1486 XFlush(wsDisplay); |
23077 | 1487 } |
1488 | |
35639 | 1489 /** |
35672 | 1490 * @brief Handle automatic hiding of the cursor. |
35639 | 1491 */ |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1492 void wsMouseAutohide(void) |
23077 | 1493 { |
35672 | 1494 if (mouse_win && (GetTimerMS() - mouse_time >= MOUSEHIDE_DELAY)) { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1495 wsMouseVisibility(mouse_win, wsHideMouseCursor); |
35672 | 1496 mouse_win = NULL; |
33542 | 1497 } |
23077 | 1498 } |