Mercurial > mplayer.hg
annotate gui/wm/ws.c @ 35673:2b7f93ef711d
Make functions static that only have file scope.
author | ib |
---|---|
date | Thu, 17 Jan 2013 16:51:50 +0000 |
parents | 144d3a71db7d |
children | 5c2f331d306a |
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 |
35667 | 90 int wsDepthOnScreen; |
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 |
35673 | 168 static int wsGetDepthOnScreen(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); | |
177 wsDepthOnScreen = mXImage->bits_per_pixel; | |
178 wsRedMask = mXImage->red_mask; | |
179 wsGreenMask = mXImage->green_mask; | |
180 wsBlueMask = mXImage->blue_mask; | |
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 | |
202 wsDepthOnScreen = ibpp; | |
203 wsRedMask = mXImage->red_mask; | |
204 wsGreenMask = mXImage->green_mask; | |
205 wsBlueMask = mXImage->blue_mask; | |
206 XDestroyImage(mXImage); | |
207 } | |
208 | |
209 return wsDepthOnScreen; | |
210 } | |
211 | |
35673 | 212 static int wsGetOutMask(void) |
35672 | 213 { |
214 if ((wsDepthOnScreen == 32) && (wsRedMask == 0xff0000) && (wsGreenMask == 0x00ff00) && (wsBlueMask == 0x0000ff)) | |
215 return wsRGB32; | |
216 | |
217 if ((wsDepthOnScreen == 32) && (wsRedMask == 0x0000ff) && (wsGreenMask == 0x00ff00) && (wsBlueMask == 0xff0000)) | |
218 return wsBGR32; | |
219 | |
220 if ((wsDepthOnScreen == 24) && (wsRedMask == 0xff0000) && (wsGreenMask == 0x00ff00) && (wsBlueMask == 0x0000ff)) | |
221 return wsRGB24; | |
222 | |
223 if ((wsDepthOnScreen == 24) && (wsRedMask == 0x0000ff) && (wsGreenMask == 0x00ff00) && (wsBlueMask == 0xff0000)) | |
224 return wsBGR24; | |
225 | |
226 if ((wsDepthOnScreen == 16) && (wsRedMask == 0xf800) && (wsGreenMask == 0x7e0) && (wsBlueMask == 0x1f)) | |
227 return wsRGB16; | |
228 | |
229 if ((wsDepthOnScreen == 16) && (wsRedMask == 0x1f) && (wsGreenMask == 0x7e0) && (wsBlueMask == 0xf800)) | |
230 return wsBGR16; | |
231 | |
232 if ((wsDepthOnScreen == 15) && (wsRedMask == 0x7c00) && (wsGreenMask == 0x3e0) && (wsBlueMask == 0x1f)) | |
233 return wsRGB15; | |
234 | |
235 if ((wsDepthOnScreen == 15) && (wsRedMask == 0x1f) && (wsGreenMask == 0x3e0) && (wsBlueMask == 0x7c00)) | |
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 |
312 wsGetDepthOnScreen(); | |
33549 | 313 |
33985 | 314 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] Screen depth: %d\n", wsDepthOnScreen); |
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 wsSetTitle(wsWindow *win, char *name) |
1019 { | |
1020 XStoreName(wsDisplay, win->WindowID, name); | |
1021 } | |
1022 | |
1023 void wsWindowDecoration(wsWindow *win, Bool decor) | |
1024 { | |
1025 MotifWmHints wsMotifWmHints; | |
1026 | |
1027 wsMotifHints = XInternAtom(wsDisplay, "_MOTIF_WM_HINTS", 0); | |
1028 | |
1029 if (wsMotifHints == None) | |
1030 return; | |
1031 | |
1032 memset(&wsMotifWmHints, 0, sizeof(MotifWmHints)); | |
1033 wsMotifWmHints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; | |
1034 | |
1035 if (decor) { | |
1036 wsMotifWmHints.functions = MWM_FUNC_MOVE | MWM_FUNC_CLOSE | MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE | MWM_FUNC_RESIZE; | |
1037 wsMotifWmHints.decorations = MWM_DECOR_ALL; | |
1038 } | |
1039 | |
1040 XChangeProperty(wsDisplay, win->WindowID, wsMotifHints, wsMotifHints, 32, | |
1041 PropModeReplace, (unsigned char *)&wsMotifWmHints, 5); | |
1042 } | |
1043 | |
1044 void wsSetShape(wsWindow *win, char *data) | |
1045 { | |
1046 #ifdef CONFIG_XSHAPE | |
1047 if (!wsUseXShape) | |
1048 return; | |
1049 | |
1050 if (data) { | |
1051 win->Mask = XCreateBitmapFromData(wsDisplay, win->WindowID, data, win->Width, win->Height); | |
1052 XShapeCombineMask(wsDisplay, win->WindowID, ShapeBounding, 0, 0, win->Mask, ShapeSet); | |
1053 XFreePixmap(wsDisplay, win->Mask); | |
1054 } else | |
1055 XShapeCombineMask(wsDisplay, win->WindowID, ShapeBounding, 0, 0, None, ShapeSet); | |
1056 #endif | |
1057 } | |
1058 | |
34081 | 1059 /** |
35672 | 1060 * @brief Set differently sized icons to a window. |
1061 * | |
1062 * This function sets the X icon hint as well as | |
1063 * the properties KWM_WIN_ICON and _NET_WM_ICON. | |
1064 * | |
1065 * @param display display | |
1066 * @param Win window | |
1067 * @param icon pointer to the icons | |
34081 | 1068 */ |
35672 | 1069 void wsSetIcon(Display *display, Window Win, guiIcon_t *icon) |
34081 | 1070 { |
35672 | 1071 XWMHints *wm; |
1072 Atom iconatom; | |
1073 long data[2]; | |
1074 | |
1075 if (icon->normal) { | |
1076 wm = XGetWMHints(display, Win); | |
1077 | |
1078 if (!wm) | |
1079 wm = XAllocWMHints(); | |
1080 | |
1081 wm->icon_pixmap = icon->normal; | |
1082 wm->icon_mask = icon->normal_mask; | |
1083 wm->flags |= IconPixmapHint | IconMaskHint; | |
1084 | |
1085 XSetWMHints(display, Win, wm); | |
1086 XFree(wm); | |
1087 } | |
1088 | |
1089 if (icon->small || icon->normal) { | |
1090 iconatom = XInternAtom(display, "KWM_WIN_ICON", False); | |
1091 data[0] = (icon->small ? icon->small : icon->normal); | |
1092 data[1] = (icon->small ? icon->small_mask : icon->normal_mask); | |
1093 | |
1094 XChangeProperty(display, Win, iconatom, iconatom, 32, PropModeReplace, (unsigned char *)data, 2); | |
1095 } | |
1096 | |
1097 if (icon->collection) { | |
1098 iconatom = XInternAtom(display, "_NET_WM_ICON", False); | |
1099 XChangeProperty(display, Win, iconatom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)icon->collection, icon->collection_size); | |
34081 | 1100 } |
1101 } | |
1102 | |
23077 | 1103 // ---------------------------------------------------------------------------------------------- |
35672 | 1104 // Set window background to 'color'. |
23077 | 1105 // ---------------------------------------------------------------------------------------------- |
35672 | 1106 void wsSetBackgroundRGB(wsWindow *win, int r, int g, int b) |
23077 | 1107 { |
35672 | 1108 int color = 0; |
35541 | 1109 |
35672 | 1110 switch (wsOutMask) { |
1111 case wsRGB32: | |
1112 case wsRGB24: | |
1113 color = (r << 16) + (g << 8) + b; | |
23077 | 1114 break; |
1115 | |
35672 | 1116 case wsBGR32: |
1117 case wsBGR24: | |
1118 color = (b << 16) + (g << 8) + r; | |
1119 break; | |
33539 | 1120 |
35672 | 1121 case wsRGB16: |
1122 PACK_RGB16(b, g, r, color); | |
23077 | 1123 break; |
1124 | |
35672 | 1125 case wsBGR16: |
1126 PACK_RGB16(r, g, b, color); | |
23077 | 1127 break; |
1128 | |
35672 | 1129 case wsRGB15: |
1130 PACK_RGB15(b, g, r, color); | |
23077 | 1131 break; |
1132 | |
35672 | 1133 case wsBGR15: |
1134 PACK_RGB15(r, g, b, color); | |
33539 | 1135 break; |
1136 } | |
1137 | |
35672 | 1138 XSetWindowBackground(wsDisplay, win->WindowID, color); |
33539 | 1139 } |
23077 | 1140 |
34009
5c33025ccfd8
Replace comment for wsFullScreen() by doxygen comment.
ib
parents:
34008
diff
changeset
|
1141 /** |
35672 | 1142 * @brief Clear the entire area in a window. |
34009
5c33025ccfd8
Replace comment for wsFullScreen() by doxygen comment.
ib
parents:
34008
diff
changeset
|
1143 * |
5c33025ccfd8
Replace comment for wsFullScreen() by doxygen comment.
ib
parents:
34008
diff
changeset
|
1144 * @param win pointer to a ws window structure |
5c33025ccfd8
Replace comment for wsFullScreen() by doxygen comment.
ib
parents:
34008
diff
changeset
|
1145 */ |
35672 | 1146 void wsClearWindow(wsWindow *win) |
23077 | 1147 { |
35672 | 1148 XClearWindow(wsDisplay, win->WindowID); |
23077 | 1149 } |
1150 | |
1151 // ---------------------------------------------------------------------------------------------- | |
1152 // Move window to x, y. | |
1153 // ---------------------------------------------------------------------------------------------- | |
35656 | 1154 void wsMoveWindow(wsWindow *win, Bool abs, int x, int y) |
23077 | 1155 { |
33993 | 1156 if (abs) { |
1157 win->X = x; | |
1158 win->Y = y; | |
33995 | 1159 } else |
1160 wsWindowPosition(win, x, y, win->Width, win->Height); | |
23077 | 1161 |
35651 | 1162 wsSizeHint(win); |
33539 | 1163 XMoveWindow(wsDisplay, win->WindowID, win->X, win->Y); |
23077 | 1164 } |
1165 | |
33998
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1166 /** |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1167 * @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
|
1168 * 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
|
1169 * |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1170 * @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
|
1171 * @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
|
1172 * @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
|
1173 * @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
|
1174 */ |
35656 | 1175 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
|
1176 { |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1177 Bool fitting = True; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1178 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1179 wsMoveWindow(win, abs, x, y); |
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->X + win->Width + 1 > wsMaxX) { |
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->X = wsMaxX - win->Width; |
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->X < 0) |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1186 win->X = 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 (win->Y + win->Height + 1 > wsMaxY) { |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1190 fitting = False; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1191 win->Y = wsMaxY - win->Height; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1192 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1193 if (win->Y < 0) |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1194 win->Y = 0; |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1195 } |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1196 |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1197 if (!fitting) |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1198 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
|
1199 } |
ca20e4098c1d
Preserve x and y position of a double-size window if possible.
ib
parents:
33996
diff
changeset
|
1200 |
23077 | 1201 // ---------------------------------------------------------------------------------------------- |
1202 // Resize window to sx, sy. | |
1203 // ---------------------------------------------------------------------------------------------- | |
35656 | 1204 void wsResizeWindow(wsWindow *win, int sx, int sy) |
23077 | 1205 { |
33539 | 1206 win->Width = sx; |
1207 win->Height = sy; | |
23077 | 1208 |
33539 | 1209 if (vo_wm_type == 0) |
1210 XUnmapWindow(wsDisplay, win->WindowID); | |
23077 | 1211 |
35648 | 1212 wsSizeHint(win); |
33539 | 1213 XResizeWindow(wsDisplay, win->WindowID, sx, sy); |
1214 | |
34124 | 1215 if (vo_wm_type == 0) |
1216 XMapWindow(wsDisplay, win->WindowID); | |
23077 | 1217 } |
1218 | |
35355 | 1219 /** |
35672 | 1220 * @brief Switch window fullscreen state. |
1221 * | |
1222 * Switch normal window to fullscreen and fullscreen window to normal. | |
1223 * | |
1224 * @param win pointer to a ws window structure | |
1225 */ | |
1226 void wsFullScreen(wsWindow *win) | |
1227 { | |
1228 if (win->isFullScreen) { | |
1229 if (vo_fs_type & vo_wm_FULLSCREEN) | |
1230 /* window manager supports EWMH */ | |
1231 vo_x11_ewmh_fullscreen(win->WindowID, _NET_WM_STATE_REMOVE); | |
1232 else { | |
1233 win->X = win->OldX; | |
1234 win->Y = win->OldY; | |
1235 win->Width = win->OldWidth; | |
1236 win->Height = win->OldHeight; | |
1237 } | |
1238 | |
1239 win->isFullScreen = False; | |
1240 } else { | |
1241 if (vo_fs_type & vo_wm_FULLSCREEN) | |
1242 /* window manager supports EWMH */ | |
1243 vo_x11_ewmh_fullscreen(win->WindowID, _NET_WM_STATE_ADD); | |
1244 else { | |
1245 win->OldX = win->X; | |
1246 win->OldY = win->Y; | |
1247 win->OldWidth = win->Width; | |
1248 win->OldHeight = win->Height; | |
1249 } | |
1250 | |
1251 win->isFullScreen = True; | |
1252 | |
1253 wsUpdateXineramaInfo(win); | |
1254 } | |
1255 | |
1256 /* unknown window manager and obsolete option -fsmode used */ | |
1257 if (vo_wm_type == 0 && !(vo_fsmode & 16)) { | |
1258 XUnmapWindow(wsDisplay, win->WindowID); // required for MWM | |
1259 XWithdrawWindow(wsDisplay, win->WindowID, wsScreen); | |
1260 } | |
1261 | |
1262 /* restore window if window manager doesn't support EWMH */ | |
1263 if (!(vo_fs_type & vo_wm_FULLSCREEN)) { | |
1264 wsSizeHint(win); | |
1265 wsWindowDecoration(win, win->Decorations && !win->isFullScreen); | |
1266 wsSetLayer(wsDisplay, win->WindowID, win->isFullScreen); | |
1267 XMoveResizeWindow(wsDisplay, win->WindowID, win->X, win->Y, win->Width, win->Height); | |
1268 } | |
1269 | |
1270 /* some window managers lose ontop after fullscreen */ | |
1271 if (!win->isFullScreen & vo_ontop) | |
1272 wsSetLayer(wsDisplay, win->WindowID, vo_ontop); | |
1273 | |
1274 wsRaiseWindowTop(wsDisplay, win->WindowID); | |
1275 XFlush(wsDisplay); | |
1276 } | |
1277 | |
1278 /** | |
35355 | 1279 * @brief Iconify a window. |
1280 * | |
1281 * @param win pointer to a ws window structure | |
1282 */ | |
35656 | 1283 void wsIconify(wsWindow *win) |
33539 | 1284 { |
35355 | 1285 XIconifyWindow(wsDisplay, win->WindowID, 0); |
33539 | 1286 } |
23077 | 1287 |
35656 | 1288 void wsVisibleWindow(wsWindow *win, int show) |
23077 | 1289 { |
33539 | 1290 switch (show) { |
1291 case wsShowWindow: | |
35541 | 1292 |
33539 | 1293 XMapRaised(wsDisplay, win->WindowID); |
35652 | 1294 wsMapWait(win); |
35541 | 1295 |
33952 | 1296 if (vo_fs_type & vo_wm_FULLSCREEN) |
1297 win->isFullScreen = False; | |
35541 | 1298 |
33539 | 1299 break; |
1300 | |
1301 case wsHideWindow: | |
35541 | 1302 |
33539 | 1303 XUnmapWindow(wsDisplay, win->WindowID); |
1304 break; | |
1305 } | |
1306 | |
1307 XFlush(wsDisplay); | |
23077 | 1308 } |
1309 | |
35672 | 1310 /** |
1311 * @brief Map a window and raise it to the top. | |
1312 * | |
1313 * @param display display | |
1314 * @param Win window | |
1315 */ | |
1316 void wsRaiseWindowTop(Display *display, Window Win) | |
23077 | 1317 { |
35672 | 1318 XMapRaised(display, Win); // NOTE TO MYSELF: is that really enough? |
1319 XRaiseWindow(display, Win); // NOTE TO MYSELF: is that really enough? | |
23077 | 1320 } |
1321 | |
35672 | 1322 // ---------------------------------------------------------------------------------------------- |
1323 // Move window to selected layer | |
1324 // ---------------------------------------------------------------------------------------------- | |
1325 | |
1326 /** | |
1327 * @brief Set the layer for a window. | |
1328 * | |
1329 * @param display display | |
1330 * @param Win window | |
1331 * @param fullscreen whether to set fullscreen or normal layer | |
1332 */ | |
1333 void wsSetLayer(Display *display, Window Win, Bool fullscreen) | |
1334 { | |
1335 vo_x11_setlayer(display, Win, fullscreen); | |
1336 } | |
1337 | |
1338 // ---------------------------------------------------------------------------------------------- | |
1339 // Redraw screen. | |
1340 // ---------------------------------------------------------------------------------------------- | |
1341 void wsPostRedisplay(wsWindow *win) | |
1342 { | |
1343 if (win->ReDraw) { | |
1344 win->State = wsWindowExpose; | |
1345 win->ReDraw(); | |
1346 XFlush(wsDisplay); | |
1347 } | |
1348 } | |
1349 | |
1350 // ---------------------------------------------------------------------------------------------- | |
1351 // Put 'Image' to window. | |
1352 // ---------------------------------------------------------------------------------------------- | |
35656 | 1353 void wsCreateImage(wsWindow *win, int Width, int Height) |
23077 | 1354 { |
34465 | 1355 #ifdef HAVE_SHM |
33539 | 1356 if (wsUseXShm) { |
1357 win->xImage = XShmCreateImage(wsDisplay, win->VisualInfo.visual, | |
1358 win->VisualInfo.depth, ZPixmap, NULL, &win->Shminfo, Width, Height); | |
1359 | |
1360 if (win->xImage == NULL) { | |
1361 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ShmError); | |
33768 | 1362 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1363 } |
1364 | |
1365 win->Shminfo.shmid = shmget(IPC_PRIVATE, win->xImage->bytes_per_line * win->xImage->height, IPC_CREAT | 0777); | |
1366 | |
1367 if (win->Shminfo.shmid < 0) { | |
1368 XDestroyImage(win->xImage); | |
1369 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ShmError); | |
33768 | 1370 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1371 } |
1372 | |
1373 win->Shminfo.shmaddr = (char *)shmat(win->Shminfo.shmid, 0, 0); | |
1374 | |
1375 if (win->Shminfo.shmaddr == ((char *)-1)) { | |
1376 XDestroyImage(win->xImage); | |
23077 | 1377 |
33539 | 1378 if (win->Shminfo.shmaddr != ((char *)-1)) |
1379 shmdt(win->Shminfo.shmaddr); | |
1380 | |
1381 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ShmError); | |
33768 | 1382 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1383 } |
1384 | |
1385 win->xImage->data = win->Shminfo.shmaddr; | |
35493 | 1386 win->Shminfo.readOnly = False; |
33539 | 1387 XShmAttach(wsDisplay, &win->Shminfo); |
1388 XSync(wsDisplay, False); | |
1389 shmctl(win->Shminfo.shmid, IPC_RMID, 0); | |
34465 | 1390 } else |
1391 #endif | |
1392 { | |
33539 | 1393 win->xImage = XCreateImage(wsDisplay, win->VisualInfo.visual, win->VisualInfo.depth, |
1394 ZPixmap, 0, 0, Width, Height, | |
1395 (wsDepthOnScreen == 3) ? 32 : wsDepthOnScreen, | |
1396 0); | |
1397 | |
1398 if ((win->xImage->data = malloc(win->xImage->bytes_per_line * win->xImage->height)) == NULL) { | |
1399 mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_NotEnoughMemoryDrawBuffer); | |
33768 | 1400 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
33539 | 1401 } |
23077 | 1402 } |
33539 | 1403 |
1404 win->ImageData = (unsigned char *)win->xImage->data; | |
1405 win->ImageDataw = (unsigned short int *)win->xImage->data; | |
1406 win->ImageDatadw = (unsigned int *)win->xImage->data; | |
23077 | 1407 } |
1408 | |
35672 | 1409 void wsDestroyImage(wsWindow *win) |
1410 { | |
1411 if (win->xImage) { | |
1412 XDestroyImage(win->xImage); | |
1413 | |
1414 #ifdef HAVE_SHM | |
1415 if (wsUseXShm) { | |
1416 XShmDetach(wsDisplay, &win->Shminfo); | |
1417 shmdt(win->Shminfo.shmaddr); | |
1418 } | |
1419 #endif | |
1420 } | |
1421 | |
1422 win->xImage = NULL; | |
1423 } | |
1424 | |
1425 void wsConvert(wsWindow *win, unsigned char *Image) | |
1426 { | |
1427 static struct SwsContext *sws_ctx; | |
1428 const uint8_t *src[4] = { Image, NULL, NULL, NULL }; | |
1429 int src_stride[4] = { 4 * win->xImage->width, 0, 0, 0 }; | |
1430 uint8_t *dst[4] = { win->ImageData, NULL, NULL, NULL }; | |
1431 int dst_stride[4]; | |
1432 int i; | |
1433 | |
1434 sws_ctx = sws_getCachedContext(sws_ctx, win->xImage->width, win->xImage->height, PIX_FMT_RGB32, | |
1435 win->xImage->width, win->xImage->height, out_pix_fmt, | |
1436 SWS_POINT, NULL, NULL, NULL); | |
1437 av_image_fill_linesizes(dst_stride, out_pix_fmt, win->xImage->width); | |
1438 sws_scale(sws_ctx, src, src_stride, 0, win->xImage->height, dst, dst_stride); | |
1439 | |
1440 if (!wsNonNativeOrder) | |
1441 return; | |
1442 | |
1443 switch (win->xImage->bits_per_pixel) { | |
1444 case 32: | |
1445 { | |
1446 uint32_t *d = (uint32_t *)win->ImageData; | |
1447 | |
1448 for (i = 0; i < win->xImage->width * win->xImage->height; i++) | |
1449 d[i] = bswap_32(d[i]); | |
1450 | |
1451 break; | |
1452 } | |
1453 | |
1454 case 16: | |
1455 case 15: | |
1456 { | |
1457 uint16_t *d = (uint16_t *)win->ImageData; | |
1458 | |
1459 for (i = 0; i < win->xImage->width * win->xImage->height; i++) | |
1460 d[i] = bswap_16(d[i]); | |
1461 | |
1462 break; | |
1463 } | |
1464 } | |
1465 } | |
1466 | |
1467 void wsPutImage(wsWindow *win) | |
1468 { | |
1469 #ifdef HAVE_SHM | |
1470 if (wsUseXShm) { | |
1471 XShmPutImage(wsDisplay, win->WindowID, win->wGC, win->xImage, | |
1472 0, 0, | |
1473 (win->Width - win->xImage->width) / 2, (win->Height - win->xImage->height) / 2, | |
1474 win->xImage->width, win->xImage->height, 0); | |
1475 } else | |
1476 #endif | |
1477 { | |
1478 XPutImage(wsDisplay, win->WindowID, win->wGC, win->xImage, | |
1479 0, 0, | |
1480 (win->Width - win->xImage->width) / 2, (win->Height - win->xImage->height) / 2, | |
1481 win->xImage->width, win->xImage->height); | |
1482 } | |
1483 } | |
1484 | |
35656 | 1485 void wsResizeImage(wsWindow *win, int Width, int Height) |
33539 | 1486 { |
1487 wsDestroyImage(win); | |
1488 wsCreateImage(win, Width, Height); | |
1489 } | |
23077 | 1490 |
35672 | 1491 // ---------------------------------------------------------------------------------------------- |
1492 // Show / hide mouse cursor. | |
1493 // ---------------------------------------------------------------------------------------------- | |
1494 void wsVisibleMouse(wsWindow *win, int m) | |
23077 | 1495 { |
35672 | 1496 switch (m) { |
1497 case wsShowMouseCursor: | |
33539 | 1498 |
35672 | 1499 if (win->wsCursor != None) { |
1500 XFreeCursor(wsDisplay, win->wsCursor); | |
1501 win->wsCursor = None; | |
1502 } | |
33539 | 1503 |
35672 | 1504 XDefineCursor(wsDisplay, win->WindowID, 0); |
1505 break; | |
33539 | 1506 |
35672 | 1507 case wsHideMouseCursor: |
33539 | 1508 |
35672 | 1509 win->wsCursor = XCreatePixmapCursor(wsDisplay, win->wsCursorPixmap, win->wsCursorPixmap, &win->wsColor, &win->wsColor, 0, 0); |
1510 XDefineCursor(wsDisplay, win->WindowID, win->wsCursor); | |
1511 break; | |
1512 } | |
33539 | 1513 |
35672 | 1514 XFlush(wsDisplay); |
23077 | 1515 } |
1516 | |
35639 | 1517 /** |
35672 | 1518 * @brief Handle automatic hiding of the cursor. |
35639 | 1519 */ |
35672 | 1520 void wsAutohideCursor(void) |
23077 | 1521 { |
35672 | 1522 if (mouse_win && (GetTimerMS() - mouse_time >= MOUSEHIDE_DELAY)) { |
1523 wsVisibleMouse(mouse_win, wsHideMouseCursor); | |
1524 mouse_win = NULL; | |
33542 | 1525 } |
23077 | 1526 } |