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