Mercurial > mplayer.hg
annotate gui/wm/ws.c @ 35736:f1a696672425
Remove setting pointless window attribute CWBackPixel.
This will be set by XSetWindowBackground() later anyway
(and - most likely - to a different color than black).
author | ib |
---|---|
date | Wed, 23 Jan 2013 14:08:58 +0000 |
parents | 4ac697e15661 |
children | 1bdc6cea0722 |
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 { |
35680 | 297 //XCloseDisplay(wsDisplay); |
35672 | 298 } |
299 | |
300 /** | |
301 * @brief Inform about an X error that has occurred. | |
302 * | |
303 * @param display display | |
304 * @param event pointer to an X error event structure | |
305 * | |
306 * @return 0 | |
307 */ | |
308 static int wsErrorHandler(Display *display, XErrorEvent *event) | |
309 { | |
310 char type[128]; | |
311 | |
312 XGetErrorText(display, event->error_code, type, sizeof(type)); | |
313 | |
314 mp_msg(MSGT_GPLAYER, MSGL_ERR, "[ws] " MSGTR_WS_XError); | |
315 mp_msg(MSGT_GPLAYER, MSGL_ERR, "[ws] Error code: %d - %s\n", event->error_code, type); | |
316 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] Request code: %d (minor code: %d)\n", event->request_code, event->minor_code); | |
317 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] MPlayer module: %s\n", current_module ? current_module : "(none)"); | |
318 | |
319 return 0; | |
320 } | |
321 | |
322 /** | |
323 * @brief Set the X error handler. | |
324 */ | |
325 void wsSetErrorHandler(void) | |
326 { | |
327 XSetErrorHandler(wsErrorHandler); | |
328 } | |
329 | |
330 // ---------------------------------------------------------------------------------------------- | |
331 // Handle events. | |
332 // ---------------------------------------------------------------------------------------------- | |
333 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
334 static int wsWindowListSearch(Window win) |
35672 | 335 { |
336 int i; | |
337 | |
338 for (i = 0; i < wsWLCount; i++) | |
339 if (wsWindowList[i] && wsWindowList[i]->WindowID == win) | |
340 return i; | |
341 | |
342 return -1; | |
343 } | |
344 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
345 void wsEvent(XEvent *event) |
35672 | 346 { |
347 unsigned long i = 0; | |
348 int l; | |
349 int x, y; | |
350 Window child_window = 0; | |
351 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
352 l = wsWindowListSearch(event->xany.window); |
35672 | 353 |
354 if (l == -1) | |
355 return; | |
356 | |
357 wsWindowList[l]->State = wsNone; | |
358 | |
359 switch (event->type) { | |
360 case ClientMessage: | |
361 | |
362 if (event->xclient.message_type == wsWindowList[l]->AtomProtocols) { | |
363 if ((Atom)event->xclient.data.l[0] == wsWindowList[l]->AtomDeleteWindow) { | |
364 i = wsWindowClosed; | |
365 goto expose; | |
366 } | |
367 | |
368 if ((Atom)event->xclient.data.l[0] == wsWindowList[l]->AtomTakeFocus) { | |
369 i = wsWindowFocusIn; | |
370 wsWindowList[l]->Focused = wsFocused; | |
371 goto expose; | |
372 } | |
373 | |
374 if ((Atom)event->xclient.data.l[0] == wsWindowList[l]->AtomRolle) { | |
375 mp_msg(MSGT_GPLAYER, MSGL_V, "[ws] role set.\n"); | |
376 } | |
377 } else { | |
378 /* try to process DND events */ | |
379 wsXDNDProcessClientMessage(&event->xclient); | |
380 } | |
381 | |
382 break; | |
383 | |
384 case MapNotify: | |
385 | |
386 i = wsWindowMapped; | |
387 wsWindowList[l]->Mapped = wsMapped; | |
388 goto expose; | |
389 | |
390 case UnmapNotify: | |
391 | |
392 i = wsWindowUnmapped; | |
393 wsWindowList[l]->Mapped = wsNo; | |
394 goto expose; | |
395 | |
396 case FocusIn: | |
397 | |
398 if (wsWindowList[l]->Focused == wsFocused) | |
399 break; | |
400 | |
401 i = wsWindowFocusIn; | |
402 wsWindowList[l]->Focused = wsFocused; | |
403 goto expose; | |
404 | |
405 case FocusOut: | |
406 | |
407 if (wsWindowList[l]->Focused == wsNo) | |
408 break; | |
409 | |
410 i = wsWindowFocusOut; | |
411 wsWindowList[l]->Focused = wsNo; | |
412 goto expose; | |
413 | |
414 case VisibilityNotify: | |
415 | |
416 switch (event->xvisibility.state) { | |
417 case VisibilityUnobscured: | |
418 i = wsWindowVisible; | |
419 wsWindowList[l]->Visible = wsVisible; | |
420 goto expose; | |
421 | |
422 case VisibilityFullyObscured: | |
423 i = wsWindowNotVisible; | |
424 wsWindowList[l]->Visible = wsNotVisible; | |
425 goto expose; | |
426 | |
427 case VisibilityPartiallyObscured: | |
428 i = wsWindowPartialVisible; | |
429 wsWindowList[l]->Visible = wsPVisible; | |
430 goto expose; | |
431 } | |
432 | |
433 expose: | |
434 wsWindowList[l]->State = i; | |
435 | |
436 if (wsWindowList[l]->ReDraw) | |
437 wsWindowList[l]->ReDraw(); | |
438 | |
439 break; | |
440 | |
441 case Expose: | |
442 | |
443 wsWindowList[l]->State = wsWindowExpose; | |
444 | |
445 if ((wsWindowList[l]->ReDraw) && (!event->xexpose.count)) | |
446 wsWindowList[l]->ReDraw(); | |
447 | |
448 break; | |
449 | |
450 case ConfigureNotify: | |
451 | |
452 XTranslateCoordinates(wsDisplay, wsWindowList[l]->WindowID, wsRootWin, 0, 0, &x, &y, &child_window); | |
453 | |
454 if ((wsWindowList[l]->X != x) || (wsWindowList[l]->Y != y) || (wsWindowList[l]->Width != event->xconfigure.width) || (wsWindowList[l]->Height != event->xconfigure.height)) { | |
455 wsWindowList[l]->X = x; | |
456 wsWindowList[l]->Y = y; | |
457 wsWindowList[l]->Width = event->xconfigure.width; | |
458 wsWindowList[l]->Height = event->xconfigure.height; | |
459 } | |
460 | |
461 wsWindowList[l]->Rolled = wsNo; | |
462 | |
463 if (event->xconfigure.y < 0) { | |
464 i = wsWindowRolled; | |
465 wsWindowList[l]->Rolled = wsRolled; | |
466 goto expose; | |
467 } | |
468 | |
469 break; | |
470 | |
471 case KeyPress: | |
472 | |
473 i = wsKeyPressed; | |
474 goto keypressed; | |
475 | |
476 case KeyRelease: | |
477 | |
478 i = wsKeyReleased; | |
479 keypressed: | |
480 wsWindowList[l]->Alt = False; | |
481 wsWindowList[l]->Shift = False; | |
482 wsWindowList[l]->NumLock = False; | |
483 wsWindowList[l]->Control = False; | |
484 wsWindowList[l]->CapsLock = False; | |
485 | |
486 if (event->xkey.state & Mod1Mask) | |
487 wsWindowList[l]->Alt = True; | |
488 | |
489 if (event->xkey.state & Mod2Mask) | |
490 wsWindowList[l]->NumLock = True; | |
491 | |
492 if (event->xkey.state & ControlMask) | |
493 wsWindowList[l]->Control = True; | |
494 | |
495 if (event->xkey.state & ShiftMask) | |
496 wsWindowList[l]->Shift = True; | |
497 | |
498 if (event->xkey.state & LockMask) | |
499 wsWindowList[l]->CapsLock = True; | |
500 | |
501 #if 0 | |
502 { | |
503 KeySym keySym; | |
504 keySym = XKeycodeToKeysym(wsDisplay, event->xkey.keycode, 0); | |
505 | |
506 if (keySym != NoSymbol) { | |
507 keySym = ((keySym & 0xff00) != 0 ? ((keySym & 0x00ff) + 256) : (keySym)); | |
508 | |
509 if (wsWindowList[l]->KeyHandler) | |
510 wsWindowList[l]->KeyHandler(event->xkey.state, i, keySym); | |
511 } | |
512 } | |
513 #else | |
514 { | |
515 int key; | |
516 char buf[100]; | |
517 KeySym keySym; | |
518 static XComposeStatus stat; | |
519 | |
520 XLookupString(&event->xkey, buf, sizeof(buf), &keySym, &stat); | |
521 key = ((keySym & 0xff00) != 0 ? ((keySym & 0x00ff) + 256) : (keySym)); | |
522 | |
523 if (wsWindowList[l]->KeyHandler) | |
524 wsWindowList[l]->KeyHandler(event->xkey.keycode, i, key); | |
525 } | |
526 #endif | |
527 break; | |
528 | |
529 case MotionNotify: | |
530 | |
531 i = wsMoveMouse; | |
532 { | |
533 /* pump all motion events from the display queue: | |
534 * this way it works faster when moving the window */ | |
535 static XEvent e; | |
536 | |
537 if (event->xmotion.state) { | |
538 while (XCheckTypedWindowEvent(wsDisplay, event->xany.window, MotionNotify, &e)) { | |
539 /* FIXME: need to make sure we didn't release/press the button in between...*/ | |
540 /* FIXME: do we need some timeout here to make sure we don't spend too much time | |
541 * removing events from the queue? */ | |
542 event = &e; | |
543 } | |
544 } | |
545 } | |
546 | |
547 if (wsWindowList[l]->wsCursor != None) { | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
548 wsMouseVisibility(wsWindowList[l], wsShowMouseCursor); |
35672 | 549 mouse_win = wsWindowList[l]; |
550 mouse_time = GetTimerMS(); | |
551 } | |
552 | |
553 goto buttonreleased; | |
554 | |
555 case ButtonRelease: | |
556 | |
557 i = event->xbutton.button + 128; | |
558 | |
559 if (wsWindowList[l]->wsCursor != None) { | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
560 wsMouseVisibility(wsWindowList[l], wsShowMouseCursor); |
35672 | 561 mouse_win = wsWindowList[l]; |
562 mouse_time = GetTimerMS(); | |
563 } | |
564 | |
565 goto buttonreleased; | |
566 | |
567 case ButtonPress: | |
568 | |
569 i = event->xbutton.button; | |
570 | |
571 if (wsWindowList[l]->wsCursor != None) { | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
572 wsMouseVisibility(wsWindowList[l], wsShowMouseCursor); |
35672 | 573 mouse_win = wsWindowList[l]; |
574 mouse_time = GetTimerMS(); | |
575 } | |
576 | |
577 goto buttonreleased; | |
578 | |
579 case EnterNotify: | |
580 | |
581 i = wsEnterWindow; | |
582 goto buttonreleased; | |
583 | |
584 case LeaveNotify: | |
585 | |
586 i = wsLeaveWindow; | |
587 buttonreleased: | |
588 | |
589 if (wsWindowList[l]->MouseHandler) | |
590 wsWindowList[l]->MouseHandler(i, event->xbutton.x, event->xbutton.y, event->xmotion.x_root, event->xmotion.y_root); | |
591 | |
592 break; | |
593 | |
594 case SelectionNotify: | |
595 | |
596 /* Handle DandD */ | |
597 wsXDNDProcessSelection(wsWindowList[l], event); | |
598 break; | |
599 } | |
600 | |
601 XFlush(wsDisplay); | |
602 XSync(wsDisplay, False); | |
603 } | |
604 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
605 void wsEvents(void) |
35672 | 606 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
607 XEvent xev; |
35672 | 608 /* handle pending events */ |
609 while (XPending(wsDisplay)) { | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
610 XNextEvent(wsDisplay, &xev); |
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
611 // printf("### X event: %d [%d]\n",xev.type,delay); |
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
612 wsEvent(&xev); |
35672 | 613 } |
614 } | |
615 | |
33995 | 616 /** |
617 * @brief Calculate and store the x and y position for a window. | |
618 * | |
619 * @param win pointer to a ws window structure | |
620 * @param x x position of the window (real/absolute or mock) | |
621 * @param y y position of the window (real/absolute or mock) | |
622 * @param width width of the area to place the window in | |
623 * @param height height of the area to place the window in | |
624 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
625 static void wsWindowUpdatePosition(wsWindow *win, int x, int y, int width, int height) |
33995 | 626 { |
627 switch (x) { | |
628 case -1: | |
629 win->X = wsOrgX + (wsMaxX - width) / 2; | |
630 break; | |
631 | |
632 case -2: | |
633 win->X = wsOrgX + wsMaxX - width; | |
634 break; | |
635 | |
636 default: | |
637 win->X = x; | |
638 break; | |
639 } | |
640 | |
641 switch (y) { | |
642 case -1: | |
643 win->Y = wsOrgY + (wsMaxY - height) / 2; | |
644 break; | |
645 | |
646 case -2: | |
647 win->Y = wsOrgY + wsMaxY - height; | |
648 break; | |
649 | |
650 default: | |
651 win->Y = y; | |
652 break; | |
653 } | |
654 } | |
655 | |
35645 | 656 /** |
657 * @brief Replace the size hints for the WM_NORMAL_HINTS property of a window. | |
658 * | |
659 * @param win pointer to a ws window structure | |
660 */ | |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
661 static void wsWindowSizeHint(wsWindow *win) |
35645 | 662 { |
35660 | 663 XSizeHints size; |
664 | |
665 size.flags = 0; | |
35645 | 666 |
35648 | 667 /* obsolete, solely for compatibility reasons */ |
35660 | 668 size.flags |= PPosition; |
669 size.x = win->X; | |
670 size.y = win->Y; | |
35645 | 671 |
35648 | 672 /* obsolete, solely for compatibility reasons */ |
35660 | 673 size.flags |= PSize; |
674 size.width = win->Width; | |
675 size.height = win->Height; | |
35645 | 676 |
35648 | 677 /* a minimum of 4 is said to avoid off-by-one errors and be required by mga_vid */ |
35660 | 678 size.flags |= PMinSize; |
679 size.min_width = 4; | |
680 size.min_height = 4; | |
35648 | 681 |
682 if (win->Property & wsMinSize) { | |
35660 | 683 size.min_width = win->Width; |
684 size.min_height = win->Height; | |
35645 | 685 } |
686 | |
35648 | 687 if (win->Property & wsMaxSize) { |
35660 | 688 size.flags |= PMaxSize; |
689 size.max_width = win->Width; | |
690 size.max_height = win->Height; | |
35645 | 691 } |
692 | |
35657 | 693 if (vo_keepaspect && (win->Property & wsAspect)) { |
35660 | 694 size.flags |= PAspect; |
695 size.min_aspect.x = win->Width; | |
696 size.min_aspect.y = win->Height; | |
697 size.max_aspect.x = win->Width; | |
698 size.max_aspect.y = win->Height; | |
35645 | 699 } |
700 | |
35660 | 701 size.flags |= PBaseSize; |
702 size.base_width = 0; | |
703 size.base_height = 0; | |
35645 | 704 |
35660 | 705 size.flags |= PWinGravity; |
706 size.win_gravity = StaticGravity; | |
35645 | 707 |
35660 | 708 XSetWMNormalHints(wsDisplay, win->WindowID, &size); |
35645 | 709 } |
710 | |
35699 | 711 static void wsWindowDecoration(wsWindow *win) |
35698 | 712 { |
713 Atom wsMotifHints; | |
714 struct { | |
715 unsigned long flags; | |
716 unsigned long functions; | |
717 unsigned long decorations; | |
718 long input_mode; | |
719 unsigned long status; | |
720 } wsMotifWmHints; | |
721 | |
722 wsMotifHints = XInternAtom(wsDisplay, "_MOTIF_WM_HINTS", 0); | |
723 | |
724 if (wsMotifHints == None) | |
725 return; | |
726 | |
727 memset(&wsMotifWmHints, 0, sizeof(wsMotifWmHints)); | |
728 wsMotifWmHints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; | |
729 | |
730 if (win->Decoration) { | |
731 wsMotifWmHints.functions = MWM_FUNC_MOVE | MWM_FUNC_CLOSE | MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE; | |
732 | |
733 if (!(win->Property & wsMinSize) || !(win->Property & wsMaxSize)) | |
734 wsMotifWmHints.functions |= MWM_FUNC_RESIZE; | |
735 | |
736 wsMotifWmHints.decorations = MWM_DECOR_ALL; | |
737 } | |
738 | |
739 XChangeProperty(wsDisplay, win->WindowID, wsMotifHints, wsMotifHints, 32, | |
740 PropModeReplace, (unsigned char *)&wsMotifWmHints, 5); | |
741 } | |
742 | |
35652 | 743 /** |
744 * @brief Wait until a window is mapped if its property requires it. | |
745 * | |
746 * @param win pointer to a ws window structure | |
747 */ | |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
748 static void wsWindowMapWait(wsWindow *win) |
35652 | 749 { |
750 XEvent xev; | |
751 | |
35653 | 752 if (win->Property & wsWaitMap) { |
35652 | 753 do |
754 XNextEvent(wsDisplay, &xev); | |
755 while (xev.type != MapNotify || xev.xmap.event != win->WindowID); | |
35653 | 756 |
757 win->Mapped = wsMapped; | |
758 } | |
35652 | 759 } |
760 | |
23077 | 761 // ---------------------------------------------------------------------------------------------- |
762 // Create window. | |
763 // X,Y : window position | |
764 // wX,wY : size of window | |
765 // bW : border width | |
766 // cV : visible mouse cursor on window | |
767 // D : visible frame, title, etc. | |
768 // sR : screen ratio | |
769 // ---------------------------------------------------------------------------------------------- | |
770 | |
33539 | 771 XClassHint wsClassHint; |
772 XTextProperty wsTextProperty; | |
773 Window LeaderWindow; | |
23077 | 774 |
35655 | 775 // ---------------------------------------------------------------------------------------------- |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
776 // wsWindowCreate: create a new window on the screen. |
35655 | 777 // x,y : window position |
778 // w,h : window size | |
779 // c : mouse cursor visible | |
780 // p : properties - "decoration", visible titlebar, etc ... | |
781 // ---------------------------------------------------------------------------------------------- | |
35687 | 782 void wsWindowCreate(wsWindow *win, int x, int y, int w, int h, int p, int c, char *label) |
23077 | 783 { |
33539 | 784 int depth; |
785 | |
35655 | 786 win->Property = p; |
23077 | 787 |
35697 | 788 win->Decoration = ((p & wsShowFrame) != 0); |
33539 | 789 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
790 wsWindowUpdatePosition(win, x, y, w, h); |
33539 | 791 |
35655 | 792 win->Width = w; |
793 win->Height = h; | |
33539 | 794 win->OldX = win->X; |
795 win->OldY = win->Y; | |
796 win->OldWidth = win->Width; | |
797 win->OldHeight = win->Height; | |
23077 | 798 |
34684 | 799 /* Hide Mouse Cursor */ |
33539 | 800 win->wsCursor = None; |
35655 | 801 win->wsMouseEventType = c; |
33539 | 802 win->wsCursorData[0] = 0; |
803 win->wsCursorPixmap = XCreateBitmapFromData(wsDisplay, wsRootWin, win->wsCursorData, 1, 1); | |
23077 | 804 |
35655 | 805 if (!(c & wsShowMouseCursor)) |
33539 | 806 win->wsCursor = XCreatePixmapCursor(wsDisplay, win->wsCursorPixmap, win->wsCursorPixmap, &win->wsColor, &win->wsColor, 0, 0); |
807 | |
808 depth = vo_find_depth_from_visuals(wsDisplay, wsScreen, NULL); | |
809 | |
810 if (depth < 15) { | |
811 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ColorDepthTooLow); | |
33768 | 812 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 813 } |
814 | |
815 XMatchVisualInfo(wsDisplay, wsScreen, depth, TrueColor, &win->VisualInfo); | |
23077 | 816 |
34684 | 817 /* --- */ |
33539 | 818 win->AtomLeaderClient = XInternAtom(wsDisplay, "WM_CLIENT_LEADER", False); |
819 win->AtomDeleteWindow = XInternAtom(wsDisplay, "WM_DELETE_WINDOW", False); | |
820 win->AtomTakeFocus = XInternAtom(wsDisplay, "WM_TAKE_FOCUS", False); | |
821 win->AtomRolle = XInternAtom(wsDisplay, "WM_WINDOW_ROLE", False); | |
822 win->AtomWMSizeHint = XInternAtom(wsDisplay, "WM_SIZE_HINT", False); | |
823 win->AtomWMNormalHint = XInternAtom(wsDisplay, "WM_NORMAL_HINT", False); | |
824 win->AtomProtocols = XInternAtom(wsDisplay, "WM_PROTOCOLS", False); | |
825 win->AtomsProtocols[0] = win->AtomDeleteWindow; | |
826 win->AtomsProtocols[1] = win->AtomTakeFocus; | |
827 win->AtomsProtocols[2] = win->AtomRolle; | |
34684 | 828 /* --- */ |
23077 | 829 |
33539 | 830 win->WindowAttrib.border_pixel = WhitePixel(wsDisplay, wsScreen); |
831 win->WindowAttrib.colormap = XCreateColormap(wsDisplay, wsRootWin, win->VisualInfo.visual, AllocNone); | |
832 win->WindowAttrib.event_mask = StructureNotifyMask | FocusChangeMask | | |
833 ExposureMask | PropertyChangeMask | | |
834 EnterWindowMask | LeaveWindowMask | | |
835 VisibilityChangeMask | | |
836 KeyPressMask | KeyReleaseMask; | |
23077 | 837 |
35655 | 838 if ((c & wsHandleMouseButton)) |
33539 | 839 win->WindowAttrib.event_mask |= ButtonPressMask | ButtonReleaseMask; |
840 | |
35655 | 841 if ((c & wsHandleMouseMove)) |
33539 | 842 win->WindowAttrib.event_mask |= PointerMotionMask; |
843 | |
844 win->WindowAttrib.cursor = win->wsCursor; | |
845 win->WindowAttrib.override_redirect = False; | |
846 | |
35655 | 847 if (p & wsOverredirect) |
33539 | 848 win->WindowAttrib.override_redirect = True; |
23077 | 849 |
35736
f1a696672425
Remove setting pointless window attribute CWBackPixel.
ib
parents:
35734
diff
changeset
|
850 win->WindowMask = CWBorderPixel | |
33539 | 851 CWColormap | CWEventMask | CWCursor | |
852 CWOverrideRedirect; | |
23077 | 853 |
33539 | 854 win->WindowID = XCreateWindow(wsDisplay, |
855 (win->Parent != 0 ? win->Parent : wsRootWin), | |
35683
75155d8a9c7e
Remove parameter for border_width from wsWindowCreate().
ib
parents:
35682
diff
changeset
|
856 win->X, win->Y, win->Width, win->Height, 0, |
33539 | 857 win->VisualInfo.depth, |
858 InputOutput, | |
859 win->VisualInfo.visual, | |
860 win->WindowMask, &win->WindowAttrib); | |
23077 | 861 |
33539 | 862 wsClassHint.res_name = "MPlayer"; |
863 | |
864 wsClassHint.res_class = "MPlayer"; | |
865 XSetClassHint(wsDisplay, win->WindowID, &wsClassHint); | |
866 | |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
867 wsWindowSizeHint(win); |
23077 | 868 |
33539 | 869 win->WMHints.flags = InputHint | StateHint; |
870 win->WMHints.input = True; | |
871 win->WMHints.initial_state = NormalState; | |
872 XSetWMHints(wsDisplay, win->WindowID, &win->WMHints); | |
23077 | 873 |
35697 | 874 wsWindowDecoration(win); |
33539 | 875 XStoreName(wsDisplay, win->WindowID, label); |
876 XmbSetWMProperties(wsDisplay, win->WindowID, label, label, NULL, 0, NULL, NULL, NULL); | |
23077 | 877 |
33539 | 878 XSetWMProtocols(wsDisplay, win->WindowID, win->AtomsProtocols, 3); |
879 XChangeProperty(wsDisplay, win->WindowID, | |
880 win->AtomLeaderClient, | |
881 XA_WINDOW, 32, PropModeReplace, | |
882 (unsigned char *)&LeaderWindow, 1); | |
23077 | 883 |
33539 | 884 wsTextProperty.value = label; |
885 wsTextProperty.encoding = XA_STRING; | |
886 wsTextProperty.format = 8; | |
887 wsTextProperty.nitems = strlen(label); | |
888 XSetWMIconName(wsDisplay, win->WindowID, &wsTextProperty); | |
889 | |
890 win->wGC = XCreateGC(wsDisplay, win->WindowID, | |
35679 | 891 0, |
892 NULL); | |
23077 | 893 |
35498
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
894 win->Visible = wsNo; |
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
895 win->Focused = wsNo; |
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
896 win->Mapped = wsNo; |
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
897 win->Rolled = wsNo; |
23077 | 898 |
35655 | 899 if (p & wsShowWindow) { |
33539 | 900 XMapWindow(wsDisplay, win->WindowID); |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
901 wsWindowMapWait(win); |
35652 | 902 } |
23077 | 903 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
904 wsImageCreate(win, win->Width, win->Height); |
34684 | 905 /* End of creating -------------------------------------------------------------------------- */ |
23077 | 906 |
33539 | 907 { |
908 int i; | |
909 | |
910 for (i = 0; i < wsWLCount; i++) | |
911 if (wsWindowList[i] == NULL) | |
912 break; | |
913 | |
914 if (i == wsWLCount) { | |
915 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_TooManyOpenWindows); | |
33768 | 916 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 917 } |
23077 | 918 |
33539 | 919 wsWindowList[i] = win; |
920 } | |
921 | |
922 XFlush(wsDisplay); | |
923 XSync(wsDisplay, False); | |
23077 | 924 |
33539 | 925 win->ReDraw = NULL; |
926 win->MouseHandler = NULL; | |
927 win->KeyHandler = NULL; | |
33985 | 928 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] window is created. ( %s ).\n", label); |
23077 | 929 } |
930 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
931 void wsWindowDestroy(wsWindow *win) |
23077 | 932 { |
33539 | 933 int l; |
934 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
935 l = wsWindowListSearch(win->WindowID); |
35354 | 936 |
937 if (l != -1) | |
938 wsWindowList[l] = NULL; | |
33539 | 939 |
940 if (win->wsCursor != None) { | |
941 XFreeCursor(wsDisplay, win->wsCursor); | |
942 win->wsCursor = None; | |
943 } | |
944 | |
945 XFreeGC(wsDisplay, win->wGC); | |
946 XUnmapWindow(wsDisplay, win->WindowID); | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
947 wsImageDestroy(win); |
33539 | 948 XDestroyWindow(wsDisplay, win->WindowID); |
23077 | 949 #if 0 |
33539 | 950 win->ReDraw = NULL; |
951 win->MouseHandler = NULL; | |
952 win->KeyHandler = NULL; | |
35498
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
953 win->Visible = wsNo; |
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
954 win->Focused = wsNo; |
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
955 win->Mapped = wsNo; |
c505a4aa9582
Rename wsNone wsNo and use it instead of a numeric constant.
ib
parents:
35497
diff
changeset
|
956 win->Rolled = wsNo; |
23077 | 957 #endif |
958 } | |
959 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
960 void wsWindowShape(wsWindow *win, char *data) |
35672 | 961 { |
962 #ifdef CONFIG_XSHAPE | |
963 if (!wsUseXShape) | |
964 return; | |
965 | |
966 if (data) { | |
967 win->Mask = XCreateBitmapFromData(wsDisplay, win->WindowID, data, win->Width, win->Height); | |
968 XShapeCombineMask(wsDisplay, win->WindowID, ShapeBounding, 0, 0, win->Mask, ShapeSet); | |
969 XFreePixmap(wsDisplay, win->Mask); | |
970 } else | |
971 XShapeCombineMask(wsDisplay, win->WindowID, ShapeBounding, 0, 0, None, ShapeSet); | |
972 #endif | |
973 } | |
974 | |
34081 | 975 /** |
35672 | 976 * @brief Set differently sized icons to a window. |
977 * | |
978 * This function sets the X icon hint as well as | |
979 * the properties KWM_WIN_ICON and _NET_WM_ICON. | |
980 * | |
981 * @param display display | |
982 * @param Win window | |
983 * @param icon pointer to the icons | |
34081 | 984 */ |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
985 void wsWindowIcon(Display *display, Window Win, guiIcon_t *icon) |
34081 | 986 { |
35672 | 987 XWMHints *wm; |
988 Atom iconatom; | |
989 long data[2]; | |
990 | |
991 if (icon->normal) { | |
992 wm = XGetWMHints(display, Win); | |
993 | |
994 if (!wm) | |
995 wm = XAllocWMHints(); | |
996 | |
997 wm->icon_pixmap = icon->normal; | |
998 wm->icon_mask = icon->normal_mask; | |
999 wm->flags |= IconPixmapHint | IconMaskHint; | |
1000 | |
1001 XSetWMHints(display, Win, wm); | |
1002 XFree(wm); | |
1003 } | |
1004 | |
1005 if (icon->small || icon->normal) { | |
1006 iconatom = XInternAtom(display, "KWM_WIN_ICON", False); | |
1007 data[0] = (icon->small ? icon->small : icon->normal); | |
1008 data[1] = (icon->small ? icon->small_mask : icon->normal_mask); | |
1009 | |
1010 XChangeProperty(display, Win, iconatom, iconatom, 32, PropModeReplace, (unsigned char *)data, 2); | |
1011 } | |
1012 | |
1013 if (icon->collection) { | |
1014 iconatom = XInternAtom(display, "_NET_WM_ICON", False); | |
1015 XChangeProperty(display, Win, iconatom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)icon->collection, icon->collection_size); | |
34081 | 1016 } |
1017 } | |
1018 | |
23077 | 1019 // ---------------------------------------------------------------------------------------------- |
35672 | 1020 // Set window background to 'color'. |
23077 | 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 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1066 void wsWindowBackground(wsWindow *win, int r, int g, int b) |
23077 | 1067 { |
35672 | 1068 int color = 0; |
35541 | 1069 |
35733 | 1070 switch (out_pix_fmt) { |
1071 case PIX_FMT_RGB32: | |
1072 case PIX_FMT_RGB24: | |
35672 | 1073 color = (r << 16) + (g << 8) + b; |
23077 | 1074 break; |
1075 | |
35733 | 1076 case PIX_FMT_BGR32: |
1077 case PIX_FMT_BGR24: | |
35672 | 1078 color = (b << 16) + (g << 8) + r; |
1079 break; | |
33539 | 1080 |
35733 | 1081 case PIX_FMT_RGB565: |
35730 | 1082 color = pack_rgb16(r, g, b); |
23077 | 1083 break; |
1084 | |
35733 | 1085 case PIX_FMT_BGR565: |
35730 | 1086 color = pack_rgb16(b, g, r); |
35728 | 1087 break; |
1088 | |
35733 | 1089 case PIX_FMT_RGB555: |
35730 | 1090 color = pack_rgb15(r, g, b); |
23077 | 1091 break; |
1092 | |
35733 | 1093 case PIX_FMT_BGR555: |
35730 | 1094 color = pack_rgb15(b, g, r); |
33539 | 1095 break; |
35733 | 1096 |
1097 default: | |
1098 ; | |
33539 | 1099 } |
1100 | |
35672 | 1101 XSetWindowBackground(wsDisplay, win->WindowID, color); |
33539 | 1102 } |
23077 | 1103 |
34009
5c33025ccfd8
Replace comment for wsFullScreen() by doxygen comment.
ib
parents:
34008
diff
changeset
|
1104 /** |
35672 | 1105 * @brief Clear the entire area in a window. |
34009
5c33025ccfd8
Replace comment for wsFullScreen() by doxygen comment.
ib
parents:
34008
diff
changeset
|
1106 * |
5c33025ccfd8
Replace comment for wsFullScreen() by doxygen comment.
ib
parents:
34008
diff
changeset
|
1107 * @param win pointer to a ws window structure |
5c33025ccfd8
Replace comment for wsFullScreen() by doxygen comment.
ib
parents:
34008
diff
changeset
|
1108 */ |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1109 void wsWindowClear(wsWindow *win) |
23077 | 1110 { |
35672 | 1111 XClearWindow(wsDisplay, win->WindowID); |
23077 | 1112 } |
1113 | |
1114 // ---------------------------------------------------------------------------------------------- | |
1115 // Move window to x, y. | |
1116 // ---------------------------------------------------------------------------------------------- | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1117 void wsWindowMove(wsWindow *win, Bool abs, int x, int y) |
23077 | 1118 { |
33993 | 1119 if (abs) { |
1120 win->X = x; | |
1121 win->Y = y; | |
33995 | 1122 } else |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1123 wsWindowUpdatePosition(win, x, y, win->Width, win->Height); |
23077 | 1124 |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
1125 wsWindowSizeHint(win); |
33539 | 1126 XMoveWindow(wsDisplay, win->WindowID, win->X, win->Y); |
23077 | 1127 } |
1128 | |
33998
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1129 /** |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1130 * @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
|
1131 * 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
|
1132 * |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1133 * @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
|
1134 * @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
|
1135 * @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
|
1136 * @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
|
1137 */ |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1138 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
|
1139 { |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1140 Bool fitting = True; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1141 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1142 wsWindowMove(win, abs, x, y); |
33998
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1143 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1144 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
|
1145 fitting = False; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1146 win->X = wsMaxX - win->Width; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1147 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1148 if (win->X < 0) |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1149 win->X = 0; |
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 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1152 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
|
1153 fitting = False; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1154 win->Y = wsMaxY - win->Height; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1155 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1156 if (win->Y < 0) |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1157 win->Y = 0; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1158 } |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1159 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1160 if (!fitting) |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1161 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
|
1162 } |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1163 |
23077 | 1164 // ---------------------------------------------------------------------------------------------- |
1165 // Resize window to sx, sy. | |
1166 // ---------------------------------------------------------------------------------------------- | |
35682 | 1167 void wsWindowResize(wsWindow *win, int w, int h) |
23077 | 1168 { |
35682 | 1169 win->Width = w; |
1170 win->Height = h; | |
23077 | 1171 |
33539 | 1172 if (vo_wm_type == 0) |
1173 XUnmapWindow(wsDisplay, win->WindowID); | |
23077 | 1174 |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
1175 wsWindowSizeHint(win); |
35682 | 1176 XResizeWindow(wsDisplay, win->WindowID, w, h); |
33539 | 1177 |
34124 | 1178 if (vo_wm_type == 0) |
1179 XMapWindow(wsDisplay, win->WindowID); | |
23077 | 1180 } |
1181 | |
35355 | 1182 /** |
35672 | 1183 * @brief Switch window fullscreen state. |
1184 * | |
1185 * Switch normal window to fullscreen and fullscreen window to normal. | |
1186 * | |
1187 * @param win pointer to a ws window structure | |
1188 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1189 void wsWindowFullscreen(wsWindow *win) |
35672 | 1190 { |
1191 if (win->isFullScreen) { | |
1192 if (vo_fs_type & vo_wm_FULLSCREEN) | |
1193 /* window manager supports EWMH */ | |
1194 vo_x11_ewmh_fullscreen(win->WindowID, _NET_WM_STATE_REMOVE); | |
1195 else { | |
1196 win->X = win->OldX; | |
1197 win->Y = win->OldY; | |
1198 win->Width = win->OldWidth; | |
1199 win->Height = win->OldHeight; | |
1200 } | |
1201 | |
1202 win->isFullScreen = False; | |
1203 } else { | |
1204 if (vo_fs_type & vo_wm_FULLSCREEN) | |
1205 /* window manager supports EWMH */ | |
1206 vo_x11_ewmh_fullscreen(win->WindowID, _NET_WM_STATE_ADD); | |
1207 else { | |
1208 win->OldX = win->X; | |
1209 win->OldY = win->Y; | |
1210 win->OldWidth = win->Width; | |
1211 win->OldHeight = win->Height; | |
1212 } | |
1213 | |
1214 win->isFullScreen = True; | |
1215 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1216 wsWindowUpdateXinerama(win); |
35672 | 1217 } |
1218 | |
1219 /* unknown window manager and obsolete option -fsmode used */ | |
1220 if (vo_wm_type == 0 && !(vo_fsmode & 16)) { | |
1221 XUnmapWindow(wsDisplay, win->WindowID); // required for MWM | |
1222 XWithdrawWindow(wsDisplay, win->WindowID, wsScreen); | |
1223 } | |
1224 | |
1225 /* restore window if window manager doesn't support EWMH */ | |
1226 if (!(vo_fs_type & vo_wm_FULLSCREEN)) { | |
35697 | 1227 if (!win->isFullScreen) |
1228 wsWindowDecoration(win); | |
1229 | |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
1230 wsWindowSizeHint(win); |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1231 wsWindowLayer(wsDisplay, win->WindowID, win->isFullScreen); |
35672 | 1232 XMoveResizeWindow(wsDisplay, win->WindowID, win->X, win->Y, win->Width, win->Height); |
1233 } | |
1234 | |
1235 /* some window managers lose ontop after fullscreen */ | |
1236 if (!win->isFullScreen & vo_ontop) | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1237 wsWindowLayer(wsDisplay, win->WindowID, vo_ontop); |
35672 | 1238 |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1239 wsWindowRaiseTop(wsDisplay, win->WindowID); |
35672 | 1240 XFlush(wsDisplay); |
1241 } | |
1242 | |
1243 /** | |
35355 | 1244 * @brief Iconify a window. |
1245 * | |
1246 * @param win pointer to a ws window structure | |
1247 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1248 void wsWindowIconify(wsWindow *win) |
33539 | 1249 { |
35355 | 1250 XIconifyWindow(wsDisplay, win->WindowID, 0); |
33539 | 1251 } |
23077 | 1252 |
35682 | 1253 void wsWindowVisibility(wsWindow *win, int vis) |
23077 | 1254 { |
35682 | 1255 switch (vis) { |
33539 | 1256 case wsShowWindow: |
35541 | 1257 |
33539 | 1258 XMapRaised(wsDisplay, win->WindowID); |
35700
7820bad7c1f8
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35699
diff
changeset
|
1259 wsWindowMapWait(win); |
35541 | 1260 |
33952 | 1261 if (vo_fs_type & vo_wm_FULLSCREEN) |
1262 win->isFullScreen = False; | |
35541 | 1263 |
33539 | 1264 break; |
1265 | |
1266 case wsHideWindow: | |
35541 | 1267 |
33539 | 1268 XUnmapWindow(wsDisplay, win->WindowID); |
1269 break; | |
1270 } | |
1271 | |
1272 XFlush(wsDisplay); | |
23077 | 1273 } |
1274 | |
35672 | 1275 /** |
1276 * @brief Map a window and raise it to the top. | |
1277 * | |
1278 * @param display display | |
1279 * @param Win window | |
1280 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1281 void wsWindowRaiseTop(Display *display, Window Win) |
23077 | 1282 { |
35672 | 1283 XMapRaised(display, Win); // NOTE TO MYSELF: is that really enough? |
1284 XRaiseWindow(display, Win); // NOTE TO MYSELF: is that really enough? | |
23077 | 1285 } |
1286 | |
35672 | 1287 // ---------------------------------------------------------------------------------------------- |
1288 // Move window to selected layer | |
1289 // ---------------------------------------------------------------------------------------------- | |
1290 | |
1291 /** | |
1292 * @brief Set the layer for a window. | |
1293 * | |
1294 * @param display display | |
1295 * @param Win window | |
1296 * @param fullscreen whether to set fullscreen or normal layer | |
1297 */ | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1298 void wsWindowLayer(Display *display, Window Win, Bool fullscreen) |
35672 | 1299 { |
1300 vo_x11_setlayer(display, Win, fullscreen); | |
1301 } | |
1302 | |
1303 // ---------------------------------------------------------------------------------------------- | |
1304 // Redraw screen. | |
1305 // ---------------------------------------------------------------------------------------------- | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1306 void wsWindowRedraw(wsWindow *win) |
35672 | 1307 { |
1308 if (win->ReDraw) { | |
1309 win->State = wsWindowExpose; | |
1310 win->ReDraw(); | |
1311 XFlush(wsDisplay); | |
1312 } | |
1313 } | |
1314 | |
1315 // ---------------------------------------------------------------------------------------------- | |
1316 // Put 'Image' to window. | |
1317 // ---------------------------------------------------------------------------------------------- | |
35682 | 1318 void wsImageCreate(wsWindow *win, int w, int h) |
23077 | 1319 { |
34465 | 1320 #ifdef HAVE_SHM |
33539 | 1321 if (wsUseXShm) { |
1322 win->xImage = XShmCreateImage(wsDisplay, win->VisualInfo.visual, | |
35682 | 1323 win->VisualInfo.depth, ZPixmap, NULL, &win->Shminfo, w, h); |
33539 | 1324 |
1325 if (win->xImage == NULL) { | |
1326 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ShmError); | |
33768 | 1327 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1328 } |
1329 | |
1330 win->Shminfo.shmid = shmget(IPC_PRIVATE, win->xImage->bytes_per_line * win->xImage->height, IPC_CREAT | 0777); | |
1331 | |
1332 if (win->Shminfo.shmid < 0) { | |
1333 XDestroyImage(win->xImage); | |
1334 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ShmError); | |
33768 | 1335 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1336 } |
1337 | |
1338 win->Shminfo.shmaddr = (char *)shmat(win->Shminfo.shmid, 0, 0); | |
1339 | |
1340 if (win->Shminfo.shmaddr == ((char *)-1)) { | |
1341 XDestroyImage(win->xImage); | |
23077 | 1342 |
33539 | 1343 if (win->Shminfo.shmaddr != ((char *)-1)) |
1344 shmdt(win->Shminfo.shmaddr); | |
1345 | |
1346 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ShmError); | |
33768 | 1347 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1348 } |
1349 | |
1350 win->xImage->data = win->Shminfo.shmaddr; | |
35493 | 1351 win->Shminfo.readOnly = False; |
33539 | 1352 XShmAttach(wsDisplay, &win->Shminfo); |
1353 XSync(wsDisplay, False); | |
1354 shmctl(win->Shminfo.shmid, IPC_RMID, 0); | |
34465 | 1355 } else |
1356 #endif | |
1357 { | |
33539 | 1358 win->xImage = XCreateImage(wsDisplay, win->VisualInfo.visual, win->VisualInfo.depth, |
35682 | 1359 ZPixmap, 0, 0, w, h, |
35676 | 1360 (wsScreenDepth == 3) ? 32 : wsScreenDepth, |
33539 | 1361 0); |
1362 | |
1363 if ((win->xImage->data = malloc(win->xImage->bytes_per_line * win->xImage->height)) == NULL) { | |
1364 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_NotEnoughMemoryDrawBuffer); | |
33768 | 1365 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1366 } |
23077 | 1367 } |
33539 | 1368 |
1369 win->ImageData = (unsigned char *)win->xImage->data; | |
1370 win->ImageDataw = (unsigned short int *)win->xImage->data; | |
1371 win->ImageDatadw = (unsigned int *)win->xImage->data; | |
23077 | 1372 } |
1373 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1374 void wsImageDestroy(wsWindow *win) |
35672 | 1375 { |
1376 if (win->xImage) { | |
1377 XDestroyImage(win->xImage); | |
1378 | |
1379 #ifdef HAVE_SHM | |
1380 if (wsUseXShm) { | |
1381 XShmDetach(wsDisplay, &win->Shminfo); | |
1382 shmdt(win->Shminfo.shmaddr); | |
1383 } | |
1384 #endif | |
1385 } | |
1386 | |
1387 win->xImage = NULL; | |
1388 } | |
1389 | |
35682 | 1390 void wsImageConvert(wsWindow *win, unsigned char *img) |
35672 | 1391 { |
1392 static struct SwsContext *sws_ctx; | |
35682 | 1393 const uint8_t *src[4] = { img, NULL, NULL, NULL }; |
35672 | 1394 int src_stride[4] = { 4 * win->xImage->width, 0, 0, 0 }; |
1395 uint8_t *dst[4] = { win->ImageData, NULL, NULL, NULL }; | |
1396 int dst_stride[4]; | |
1397 int i; | |
1398 | |
1399 sws_ctx = sws_getCachedContext(sws_ctx, win->xImage->width, win->xImage->height, PIX_FMT_RGB32, | |
1400 win->xImage->width, win->xImage->height, out_pix_fmt, | |
1401 SWS_POINT, NULL, NULL, NULL); | |
1402 av_image_fill_linesizes(dst_stride, out_pix_fmt, win->xImage->width); | |
1403 sws_scale(sws_ctx, src, src_stride, 0, win->xImage->height, dst, dst_stride); | |
1404 | |
1405 if (!wsNonNativeOrder) | |
1406 return; | |
1407 | |
1408 switch (win->xImage->bits_per_pixel) { | |
1409 case 32: | |
1410 { | |
1411 uint32_t *d = (uint32_t *)win->ImageData; | |
1412 | |
1413 for (i = 0; i < win->xImage->width * win->xImage->height; i++) | |
1414 d[i] = bswap_32(d[i]); | |
1415 | |
1416 break; | |
1417 } | |
1418 | |
1419 case 16: | |
1420 case 15: | |
1421 { | |
1422 uint16_t *d = (uint16_t *)win->ImageData; | |
1423 | |
1424 for (i = 0; i < win->xImage->width * win->xImage->height; i++) | |
1425 d[i] = bswap_16(d[i]); | |
1426 | |
1427 break; | |
1428 } | |
1429 } | |
1430 } | |
1431 | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1432 void wsImageDraw(wsWindow *win) |
35672 | 1433 { |
1434 #ifdef HAVE_SHM | |
1435 if (wsUseXShm) { | |
1436 XShmPutImage(wsDisplay, win->WindowID, win->wGC, win->xImage, | |
1437 0, 0, | |
1438 (win->Width - win->xImage->width) / 2, (win->Height - win->xImage->height) / 2, | |
1439 win->xImage->width, win->xImage->height, 0); | |
1440 } else | |
1441 #endif | |
1442 { | |
1443 XPutImage(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); | |
1447 } | |
1448 } | |
1449 | |
35682 | 1450 void wsImageResize(wsWindow *win, int w, int h) |
33539 | 1451 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1452 wsImageDestroy(win); |
35682 | 1453 wsImageCreate(win, w, h); |
33539 | 1454 } |
23077 | 1455 |
35672 | 1456 // ---------------------------------------------------------------------------------------------- |
1457 // Show / hide mouse cursor. | |
1458 // ---------------------------------------------------------------------------------------------- | |
35682 | 1459 void wsMouseVisibility(wsWindow *win, int vis) |
23077 | 1460 { |
35682 | 1461 switch (vis) { |
35672 | 1462 case wsShowMouseCursor: |
33539 | 1463 |
35672 | 1464 if (win->wsCursor != None) { |
1465 XFreeCursor(wsDisplay, win->wsCursor); | |
1466 win->wsCursor = None; | |
1467 } | |
33539 | 1468 |
35672 | 1469 XDefineCursor(wsDisplay, win->WindowID, 0); |
1470 break; | |
33539 | 1471 |
35672 | 1472 case wsHideMouseCursor: |
33539 | 1473 |
35672 | 1474 win->wsCursor = XCreatePixmapCursor(wsDisplay, win->wsCursorPixmap, win->wsCursorPixmap, &win->wsColor, &win->wsColor, 0, 0); |
1475 XDefineCursor(wsDisplay, win->WindowID, win->wsCursor); | |
1476 break; | |
1477 } | |
33539 | 1478 |
35672 | 1479 XFlush(wsDisplay); |
23077 | 1480 } |
1481 | |
35639 | 1482 /** |
35672 | 1483 * @brief Handle automatic hiding of the cursor. |
35639 | 1484 */ |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1485 void wsMouseAutohide(void) |
23077 | 1486 { |
35672 | 1487 if (mouse_win && (GetTimerMS() - mouse_time >= MOUSEHIDE_DELAY)) { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35680
diff
changeset
|
1488 wsMouseVisibility(mouse_win, wsHideMouseCursor); |
35672 | 1489 mouse_win = NULL; |
33542 | 1490 } |
23077 | 1491 } |