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