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