2 * This file is part of MPlayer.
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.
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.
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.
29 #include "libavutil/common.h"
30 #include "x11_common.h"
39 #include "video_out.h"
43 #include "osdep/timer.h"
47 #include <X11/Xutil.h>
48 #include <X11/Xatom.h>
51 #include <X11/extensions/scrnsaver.h>
55 #include <X11/extensions/dpms.h>
58 #ifdef CONFIG_XINERAMA
59 #include <X11/extensions/Xinerama.h>
63 #include <X11/extensions/xf86vmode.h>
67 #include <X11/XF86keysym.h>
71 #include <X11/extensions/Xv.h>
72 #include <X11/extensions/Xvlib.h>
74 #include "subopt-helper.h"
77 #include "input/input.h"
78 #include "input/mouse.h"
80 #define WIN_LAYER_ONBOTTOM 2
81 #define WIN_LAYER_NORMAL 4
82 #define WIN_LAYER_ONTOP 6
83 #define WIN_LAYER_ABOVE_DOCK 10
85 extern int enable_mouse_movements
;
86 int fs_layer
= WIN_LAYER_ABOVE_DOCK
;
88 int stop_xscreensaver
= 0;
90 static int dpms_disabled
= 0;
92 char *mDisplayName
= NULL
;
94 char **vo_fstype_list
;
96 /* 1 means that the WM is metacity (broken as hell) */
97 int metacity_hack
= 0;
100 XF86VidModeModeInfo
**vidmodes
= NULL
;
101 XF86VidModeModeLine modeline
;
104 static int vo_x11_get_fs_type(int supported
);
105 static void saver_off(Display
*);
106 static void saver_on(Display
*);
109 * Sends the EWMH fullscreen state event.
111 * action: could be one of _NET_WM_STATE_REMOVE -- remove state
112 * _NET_WM_STATE_ADD -- add state
113 * _NET_WM_STATE_TOGGLE -- toggle
115 void vo_x11_ewmh_fullscreen(struct vo_x11_state
*x11
, int action
)
117 assert(action
== _NET_WM_STATE_REMOVE
||
118 action
== _NET_WM_STATE_ADD
|| action
== _NET_WM_STATE_TOGGLE
);
120 if (x11
->fs_type
& vo_wm_FULLSCREEN
)
124 /* init X event structure for _NET_WM_FULLSCREEN client message */
125 xev
.xclient
.type
= ClientMessage
;
126 xev
.xclient
.serial
= 0;
127 xev
.xclient
.send_event
= True
;
128 xev
.xclient
.message_type
= x11
->XA_NET_WM_STATE
;
129 xev
.xclient
.window
= x11
->window
;
130 xev
.xclient
.format
= 32;
131 xev
.xclient
.data
.l
[0] = action
;
132 xev
.xclient
.data
.l
[1] = x11
->XA_NET_WM_STATE_FULLSCREEN
;
133 xev
.xclient
.data
.l
[2] = 0;
134 xev
.xclient
.data
.l
[3] = 0;
135 xev
.xclient
.data
.l
[4] = 0;
137 /* finally send that damn thing */
138 if (!XSendEvent(x11
->display
, DefaultRootWindow(x11
->display
), False
,
139 SubstructureRedirectMask
| SubstructureNotifyMask
,
142 mp_tmsg(MSGT_VO
, MSGL_ERR
, "\nX11: Couldn't send EWMH fullscreen event!\n");
147 static void vo_hidecursor(Display
* disp
, Window win
)
153 const char bm_no_data
[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
156 return; // do not hide if playing on the root window
158 colormap
= DefaultColormap(disp
, DefaultScreen(disp
));
159 if ( !XAllocNamedColor(disp
, colormap
, "black", &black
, &dummy
) )
161 return; // color alloc failed, give up
163 bm_no
= XCreateBitmapFromData(disp
, win
, bm_no_data
, 8, 8);
164 no_ptr
= XCreatePixmapCursor(disp
, bm_no
, bm_no
, &black
, &black
, 0, 0);
165 XDefineCursor(disp
, win
, no_ptr
);
166 XFreeCursor(disp
, no_ptr
);
168 XFreePixmap(disp
, bm_no
);
169 XFreeColors(disp
,colormap
,&black
.pixel
,1,0);
172 static void vo_showcursor(Display
* disp
, Window win
)
176 XDefineCursor(disp
, win
, 0);
179 static int x11_errorhandler(Display
* display
, XErrorEvent
* event
)
184 XGetErrorText(display
, event
->error_code
, (char *) &msg
, MSGLEN
);
186 mp_msg(MSGT_VO
, MSGL_ERR
, "X11 error: %s\n", msg
);
188 mp_msg(MSGT_VO
, MSGL_V
,
189 "Type: %x, display: %p, resourceid: %lx, serial: %lx\n",
190 event
->type
, event
->display
, event
->resourceid
, event
->serial
);
191 mp_msg(MSGT_VO
, MSGL_V
,
192 "Error code: %x, request code: %x, minor code: %x\n",
193 event
->error_code
, event
->request_code
, event
->minor_code
);
196 //exit_player("X11 error");
201 void fstype_help(void)
203 mp_tmsg(MSGT_VO
, MSGL_INFO
, "Available fullscreen layer change modes:\n");
204 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FULL_SCREEN_TYPES\n");
206 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "none",
207 "don't set fullscreen window layer");
208 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "layer",
209 "use _WIN_LAYER hint with default layer");
210 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "layer=<0..15>",
211 "use _WIN_LAYER hint with a given layer number");
212 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "netwm",
213 "force NETWM style");
214 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "above",
215 "use _NETWM_STATE_ABOVE hint if available");
216 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "below",
217 "use _NETWM_STATE_BELOW hint if available");
218 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "fullscreen",
219 "use _NETWM_STATE_FULLSCREEN hint if availale");
220 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "stays_on_top",
221 "use _NETWM_STATE_STAYS_ON_TOP hint if available");
222 mp_msg(MSGT_VO
, MSGL_INFO
,
223 "You can also negate the settings with simply putting '-' in the beginning");
224 mp_msg(MSGT_VO
, MSGL_INFO
, "\n");
227 static void fstype_dump(int fstype
)
231 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Current fstype setting honours");
232 if (fstype
& vo_wm_LAYER
)
233 mp_msg(MSGT_VO
, MSGL_V
, " LAYER");
234 if (fstype
& vo_wm_FULLSCREEN
)
235 mp_msg(MSGT_VO
, MSGL_V
, " FULLSCREEN");
236 if (fstype
& vo_wm_STAYS_ON_TOP
)
237 mp_msg(MSGT_VO
, MSGL_V
, " STAYS_ON_TOP");
238 if (fstype
& vo_wm_ABOVE
)
239 mp_msg(MSGT_VO
, MSGL_V
, " ABOVE");
240 if (fstype
& vo_wm_BELOW
)
241 mp_msg(MSGT_VO
, MSGL_V
, " BELOW");
242 mp_msg(MSGT_VO
, MSGL_V
, " X atoms\n");
244 mp_msg(MSGT_VO
, MSGL_V
,
245 "[x11] Current fstype setting doesn't honour any X atoms\n");
248 static int net_wm_support_state_test(struct vo_x11_state
*x11
, Atom atom
)
250 #define NET_WM_STATE_TEST(x) { if (atom == x11->XA_NET_WM_STATE_##x) { mp_msg( MSGT_VO,MSGL_V, "[x11] Detected wm supports " #x " state.\n" ); return vo_wm_##x; } }
252 NET_WM_STATE_TEST(FULLSCREEN
);
253 NET_WM_STATE_TEST(ABOVE
);
254 NET_WM_STATE_TEST(STAYS_ON_TOP
);
255 NET_WM_STATE_TEST(BELOW
);
259 static int x11_get_property(struct vo_x11_state
*x11
, Atom type
, Atom
** args
,
260 unsigned long *nitems
)
263 unsigned long bytesafter
;
266 XGetWindowProperty(x11
->display
, x11
->rootwin
, type
, 0, 16384, False
,
267 AnyPropertyType
, &type
, &format
, nitems
,
268 &bytesafter
, (unsigned char **) args
)
272 static int vo_wm_detect(struct vo
*vo
)
274 struct vo_x11_state
*x11
= vo
->x11
;
277 unsigned long nitems
;
283 // -- supports layers
284 if (x11_get_property(x11
, x11
->XA_WIN_PROTOCOLS
, &args
, &nitems
))
286 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Detected wm supports layers.\n");
287 for (i
= 0; i
< nitems
; i
++)
289 if (args
[i
] == x11
->XA_WIN_LAYER
)
294 /* metacity is the only window manager I know which reports
295 * supporting only the _WIN_LAYER hint in _WIN_PROTOCOLS.
296 * (what's more support for it is broken) */
300 if (wm
&& (metacity_hack
== 1))
302 // metacity claims to support layers, but it is not the truth :-)
304 mp_msg(MSGT_VO
, MSGL_V
,
305 "[x11] Using workaround for Metacity bugs.\n");
309 if (x11_get_property(x11
, x11
->XA_NET_SUPPORTED
, &args
, &nitems
))
311 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Detected wm supports NetWM.\n");
312 for (i
= 0; i
< nitems
; i
++)
313 wm
|= net_wm_support_state_test(vo
->x11
, args
[i
]);
318 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Unknown wm type...\n");
322 #define XA_INIT(x) x11->XA##x = XInternAtom(x11->display, #x, False)
323 static void init_atoms(struct vo_x11_state
*x11
)
325 XA_INIT(_NET_SUPPORTED
);
326 XA_INIT(_NET_WM_STATE
);
327 XA_INIT(_NET_WM_STATE_FULLSCREEN
);
328 XA_INIT(_NET_WM_STATE_ABOVE
);
329 XA_INIT(_NET_WM_STATE_STAYS_ON_TOP
);
330 XA_INIT(_NET_WM_STATE_BELOW
);
331 XA_INIT(_NET_WM_PID
);
332 XA_INIT(_WIN_PROTOCOLS
);
335 XA_INIT(WM_PROTOCOLS
);
336 XA_INIT(WM_DELETE_WINDOW
);
339 void update_xinerama_info(struct vo
*vo
) {
340 struct MPOpts
*opts
= vo
->opts
;
341 int screen
= xinerama_screen
;
342 xinerama_x
= xinerama_y
= 0;
343 #ifdef CONFIG_XINERAMA
344 if (screen
>= -1 && XineramaIsActive(vo
->x11
->display
))
346 XineramaScreenInfo
*screens
;
349 screens
= XineramaQueryScreens(vo
->x11
->display
, &num_screens
);
350 if (screen
>= num_screens
)
351 screen
= num_screens
- 1;
353 int x
= vo
->dx
+ vo
->dwidth
/ 2;
354 int y
= vo
->dy
+ vo
->dheight
/ 2;
355 for (screen
= num_screens
- 1; screen
> 0; screen
--) {
356 int left
= screens
[screen
].x_org
;
357 int right
= left
+ screens
[screen
].width
;
358 int top
= screens
[screen
].y_org
;
359 int bottom
= top
+ screens
[screen
].height
;
360 if (left
<= x
&& x
<= right
&& top
<= y
&& y
<= bottom
)
366 opts
->vo_screenwidth
= screens
[screen
].width
;
367 opts
->vo_screenheight
= screens
[screen
].height
;
368 xinerama_x
= screens
[screen
].x_org
;
369 xinerama_y
= screens
[screen
].y_org
;
374 aspect_save_screenres(vo
, opts
->vo_screenwidth
, opts
->vo_screenheight
);
377 int vo_init(struct vo
*vo
)
379 struct MPOpts
*opts
= vo
->opts
;
380 struct vo_x11_state
*x11
= vo
->x11
;
385 // char * DisplayName = ":0.0";
386 // Display * mDisplay;
387 XImage
*mXImage
= NULL
;
390 XWindowAttributes attribs
;
394 WinID
= 0; // use root window
396 if (x11
->depthonscreen
)
398 saver_off(x11
->display
);
399 return 1; // already called
402 XSetErrorHandler(x11_errorhandler
);
406 if (!(mDisplayName
= getenv("DISPLAY")))
407 mDisplayName
= strdup(":0.0");
409 dispName
= XDisplayName(mDisplayName
);
412 mp_msg(MSGT_VO
, MSGL_V
, "X11 opening display: %s\n", dispName
);
414 x11
->display
= XOpenDisplay(dispName
);
417 mp_msg(MSGT_VO
, MSGL_ERR
,
418 "vo: couldn't open the X11 display (%s)!\n", dispName
);
421 x11
->screen
= DefaultScreen(x11
->display
); // screen ID
422 x11
->rootwin
= RootWindow(x11
->display
, x11
->screen
); // root window ID
430 XF86VidModeGetModeLine(x11
->display
, x11
->screen
, &clock
, &modeline
);
431 if (!opts
->vo_screenwidth
)
432 opts
->vo_screenwidth
= modeline
.hdisplay
;
433 if (!opts
->vo_screenheight
)
434 opts
->vo_screenheight
= modeline
.vdisplay
;
438 if (!opts
->vo_screenwidth
)
439 opts
->vo_screenwidth
= DisplayWidth(x11
->display
, x11
->screen
);
440 if (!opts
->vo_screenheight
)
441 opts
->vo_screenheight
= DisplayHeight(x11
->display
, x11
->screen
);
443 // get color depth (from root window, or the best visual):
444 XGetWindowAttributes(x11
->display
, x11
->rootwin
, &attribs
);
445 depth
= attribs
.depth
;
447 if (depth
!= 15 && depth
!= 16 && depth
!= 24 && depth
!= 32)
451 depth
= vo_find_depth_from_visuals(x11
->display
, x11
->screen
, &visual
);
453 mXImage
= XCreateImage(x11
->display
, visual
, depth
, ZPixmap
,
454 0, NULL
, 1, 1, 8, 1);
457 XGetImage(x11
->display
, x11
->rootwin
, 0, 0, 1, 1, AllPlanes
, ZPixmap
);
459 x11
->depthonscreen
= depth
; // display depth on screen
461 // get bits/pixel from XImage structure:
468 * for the depth==24 case, the XImage structures might use
469 * 24 or 32 bits of data per pixel. The x11->depthonscreen
470 * field stores the amount of data per pixel in the
473 * Maybe we should rename vo_depthonscreen to (or add) vo_bpp?
475 bpp
= mXImage
->bits_per_pixel
;
476 if ((x11
->depthonscreen
+ 7) / 8 != (bpp
+ 7) / 8)
477 x11
->depthonscreen
= bpp
; // by A'rpi
479 mXImage
->red_mask
| mXImage
->green_mask
| mXImage
->blue_mask
;
480 mp_msg(MSGT_VO
, MSGL_V
,
481 "vo: X11 color mask: %X (R:%lX G:%lX B:%lX)\n", mask
,
482 mXImage
->red_mask
, mXImage
->green_mask
, mXImage
->blue_mask
);
483 XDestroyImage(mXImage
);
485 if (((x11
->depthonscreen
+ 7) / 8) == 2)
488 x11
->depthonscreen
= 15;
489 else if (mask
== 0xFFFF)
490 x11
->depthonscreen
= 16;
492 // XCloseDisplay( mDisplay );
493 /* slightly improved local display detection AST */
494 if (strncmp(dispName
, "unix:", 5) == 0)
496 else if (strncmp(dispName
, "localhost:", 10) == 0)
498 if (*dispName
== ':' && atoi(dispName
+ 1) < 10)
499 x11
->display_is_local
= 1;
501 x11
->display_is_local
= 0;
502 mp_msg(MSGT_VO
, MSGL_V
,
503 "vo: X11 running at %dx%d with depth %d and %d bpp (\"%s\" => %s display)\n",
504 opts
->vo_screenwidth
, opts
->vo_screenheight
, depth
, x11
->depthonscreen
,
505 dispName
, x11
->display_is_local
? "local" : "remote");
507 x11
->wm_type
= vo_wm_detect(vo
);
509 x11
->fs_type
= vo_x11_get_fs_type(x11
->wm_type
);
511 fstype_dump(x11
->fs_type
);
513 saver_off(x11
->display
);
517 void vo_uninit(struct vo_x11_state
*x11
)
521 mp_msg(MSGT_VO
, MSGL_V
,
522 "vo: x11 uninit called but X11 not initialized..\n");
524 mp_msg(MSGT_VO
, MSGL_V
, "vo: uninit ...\n");
525 XSetErrorHandler(NULL
);
526 XCloseDisplay(x11
->display
);
527 x11
->depthonscreen
= 0;
533 #include "osdep/keycodes.h"
536 #ifdef XF86XK_AudioPause
537 static const struct keymap keysym_map
[] = {
538 {XF86XK_MenuKB
, KEY_MENU
},
539 {XF86XK_AudioPlay
, KEY_PLAY
}, {XF86XK_AudioPause
, KEY_PAUSE
}, {XF86XK_AudioStop
, KEY_STOP
},
540 {XF86XK_AudioPrev
, KEY_PREV
}, {XF86XK_AudioNext
, KEY_NEXT
},
541 {XF86XK_AudioMute
, KEY_MUTE
}, {XF86XK_AudioLowerVolume
, KEY_VOLUME_DOWN
}, {XF86XK_AudioRaiseVolume
, KEY_VOLUME_UP
},
545 static void vo_x11_putkey_ext(struct vo
*vo
, int keysym
)
547 struct mp_fifo
*f
= vo
->key_fifo
;
548 int mpkey
= lookup_keymap_table(keysym_map
, keysym
);
550 mplayer_put_key(f
, mpkey
);
554 static const struct keymap keymap
[] = {
556 {wsEscape
, KEY_ESC
}, {wsBackSpace
, KEY_BS
}, {wsTab
, KEY_TAB
}, {wsEnter
, KEY_ENTER
},
559 {wsLeft
, KEY_LEFT
}, {wsRight
, KEY_RIGHT
}, {wsUp
, KEY_UP
}, {wsDown
, KEY_DOWN
},
562 {wsInsert
, KEY_INSERT
}, {wsDelete
, KEY_DELETE
}, {wsHome
, KEY_HOME
}, {wsEnd
, KEY_END
},
563 {wsPageUp
, KEY_PAGE_UP
}, {wsPageDown
, KEY_PAGE_DOWN
},
566 {wsF1
, KEY_F
+1}, {wsF2
, KEY_F
+2}, {wsF3
, KEY_F
+3}, {wsF4
, KEY_F
+4},
567 {wsF5
, KEY_F
+5}, {wsF6
, KEY_F
+6}, {wsF7
, KEY_F
+7}, {wsF8
, KEY_F
+8},
568 {wsF9
, KEY_F
+9}, {wsF10
, KEY_F
+10}, {wsF11
, KEY_F
+11}, {wsF12
, KEY_F
+12},
570 // numpad independent of numlock
571 {wsGrayMinus
, '-'}, {wsGrayPlus
, '+'}, {wsGrayMul
, '*'}, {wsGrayDiv
, '/'},
572 {wsGrayEnter
, KEY_KPENTER
},
574 // numpad with numlock
575 {wsGray0
, KEY_KP0
}, {wsGray1
, KEY_KP1
}, {wsGray2
, KEY_KP2
},
576 {wsGray3
, KEY_KP3
}, {wsGray4
, KEY_KP4
}, {wsGray5
, KEY_KP5
},
577 {wsGray6
, KEY_KP6
}, {wsGray7
, KEY_KP7
}, {wsGray8
, KEY_KP8
},
578 {wsGray9
, KEY_KP9
}, {wsGrayDecimal
, KEY_KPDEC
},
580 // numpad without numlock
581 {wsGrayInsert
, KEY_KPINS
}, {wsGrayEnd
, KEY_KP1
}, {wsGrayDown
, KEY_KP2
},
582 {wsGrayPgDn
, KEY_KP3
}, {wsGrayLeft
, KEY_KP4
}, {wsGray5Dup
, KEY_KP5
},
583 {wsGrayRight
, KEY_KP6
}, {wsGrayHome
, KEY_KP7
}, {wsGrayUp
, KEY_KP8
},
584 {wsGrayPgUp
, KEY_KP9
}, {wsGrayDelete
, KEY_KPDEL
},
589 void vo_x11_putkey(struct vo
*vo
, int key
)
591 static const char *passthrough_keys
= " -+*/<>`~!@#$%^&()_{}:;\"\',.?\\|=[]";
593 if ((key
>= 'a' && key
<= 'z') ||
594 (key
>= 'A' && key
<= 'Z') ||
595 (key
>= '0' && key
<= '9') ||
596 (key
> 0 && key
< 256 && strchr(passthrough_keys
, key
)))
600 mpkey
= lookup_keymap_table(keymap
, key
);
603 mplayer_put_key(vo
->key_fifo
, mpkey
);
607 // ----- Motif header: -------
609 #define MWM_HINTS_FUNCTIONS (1L << 0)
610 #define MWM_HINTS_DECORATIONS (1L << 1)
611 #define MWM_HINTS_INPUT_MODE (1L << 2)
612 #define MWM_HINTS_STATUS (1L << 3)
614 #define MWM_FUNC_ALL (1L << 0)
615 #define MWM_FUNC_RESIZE (1L << 1)
616 #define MWM_FUNC_MOVE (1L << 2)
617 #define MWM_FUNC_MINIMIZE (1L << 3)
618 #define MWM_FUNC_MAXIMIZE (1L << 4)
619 #define MWM_FUNC_CLOSE (1L << 5)
621 #define MWM_DECOR_ALL (1L << 0)
622 #define MWM_DECOR_BORDER (1L << 1)
623 #define MWM_DECOR_RESIZEH (1L << 2)
624 #define MWM_DECOR_TITLE (1L << 3)
625 #define MWM_DECOR_MENU (1L << 4)
626 #define MWM_DECOR_MINIMIZE (1L << 5)
627 #define MWM_DECOR_MAXIMIZE (1L << 6)
629 #define MWM_INPUT_MODELESS 0
630 #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
631 #define MWM_INPUT_SYSTEM_MODAL 2
632 #define MWM_INPUT_FULL_APPLICATION_MODAL 3
633 #define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL
635 #define MWM_TEAROFF_WINDOW (1L<<0)
646 static MotifWmHints vo_MotifWmHints
;
647 static Atom vo_MotifHints
= None
;
649 void vo_x11_decoration(struct vo
*vo
, int d
)
651 struct vo_x11_state
*x11
= vo
->x11
;
654 unsigned long mn
, mb
;
661 XSetTransientForHint(x11
->display
, x11
->window
,
662 RootWindow(x11
->display
, x11
->screen
));
665 vo_MotifHints
= XInternAtom(x11
->display
, "_MOTIF_WM_HINTS", 0);
666 if (vo_MotifHints
!= None
)
670 MotifWmHints
*mhints
= NULL
;
672 XGetWindowProperty(x11
->display
, x11
->window
,
673 vo_MotifHints
, 0, 20, False
,
674 vo_MotifHints
, &mtype
, &mformat
, &mn
,
675 &mb
, (unsigned char **) &mhints
);
678 if (mhints
->flags
& MWM_HINTS_DECORATIONS
)
679 x11
->olddecor
= mhints
->decorations
;
680 if (mhints
->flags
& MWM_HINTS_FUNCTIONS
)
681 x11
->oldfuncs
= mhints
->functions
;
686 memset(&vo_MotifWmHints
, 0, sizeof(MotifWmHints
));
687 vo_MotifWmHints
.flags
=
688 MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
691 vo_MotifWmHints
.functions
= x11
->oldfuncs
;
695 vo_MotifWmHints
.decorations
=
696 d
| ((vo_fsmode
& 2) ? 0 : MWM_DECOR_MENU
);
698 vo_MotifWmHints
.decorations
=
699 d
| ((vo_fsmode
& 2) ? MWM_DECOR_MENU
: 0);
701 XChangeProperty(x11
->display
, x11
->window
, vo_MotifHints
,
704 (unsigned char *) &vo_MotifWmHints
,
705 (vo_fsmode
& 4) ? 4 : 5);
709 void vo_x11_classhint(struct vo
*vo
, Window window
, const char *name
)
711 struct vo_x11_state
*x11
= vo
->x11
;
713 pid_t pid
= getpid();
715 wmClass
.res_name
= vo_winname
? vo_winname
: name
;
716 wmClass
.res_class
= "MPlayer";
717 XSetClassHint(x11
->display
, window
, &wmClass
);
718 XChangeProperty(x11
->display
, window
, x11
->XA_NET_WM_PID
, XA_CARDINAL
,
719 32, PropModeReplace
, (unsigned char *) &pid
, 1);
722 void vo_x11_uninit(struct vo
*vo
)
724 struct vo_x11_state
*x11
= vo
->x11
;
725 saver_on(x11
->display
);
726 if (x11
->window
!= None
)
727 vo_showcursor(x11
->display
, x11
->window
);
731 XFreeGC(vo
->x11
->display
, x11
->f_gc
);
737 XSetBackground(vo
->x11
->display
, x11
->vo_gc
, 0);
738 XFreeGC(vo
->x11
->display
, x11
->vo_gc
);
741 if (x11
->window
!= None
)
743 XClearWindow(x11
->display
, x11
->window
);
748 XUnmapWindow(x11
->display
, x11
->window
);
749 XDestroyWindow(x11
->display
, x11
->window
);
752 XNextEvent(x11
->display
, &xev
);
754 while (xev
.type
!= DestroyNotify
755 || xev
.xdestroywindow
.event
!= x11
->window
);
760 x11
->vo_old_width
= x11
->vo_old_height
= 0;
764 int vo_x11_check_events(struct vo
*vo
)
766 struct vo_x11_state
*x11
= vo
->x11
;
767 Display
*display
= vo
->x11
->display
;
773 // unsigned long vo_KeyTable[512];
775 if ((x11
->vo_mouse_autohide
) && x11
->mouse_waiting_hide
&&
776 (GetTimerMS() - x11
->mouse_timer
>= 1000)) {
777 vo_hidecursor(display
, x11
->window
);
778 x11
->mouse_waiting_hide
= 0;
781 while (XPending(display
))
783 XNextEvent(display
, &Event
);
784 // printf("\rEvent.type=%X \n",Event.type);
788 ret
|= VO_EVENT_EXPOSE
;
790 case ConfigureNotify
:
791 if (x11
->window
== None
)
794 int old_w
= vo
->dwidth
, old_h
= vo
->dheight
;
795 vo_x11_update_geometry(vo
);
796 if (vo
->dwidth
!= old_w
|| vo
->dheight
!= old_h
)
797 ret
|= VO_EVENT_RESIZE
;
804 XLookupString(&Event
.xkey
, buf
, sizeof(buf
), &keySym
,
805 &x11
->compose_status
);
806 #ifdef XF86XK_AudioPause
807 vo_x11_putkey_ext(vo
, keySym
);
810 ((keySym
& 0xff00) !=
811 0 ? ((keySym
& 0x00ff) + 256) : (keySym
));
812 vo_x11_putkey(vo
, key
);
813 ret
|= VO_EVENT_KEYPRESS
;
817 if(enable_mouse_movements
)
820 sprintf(cmd_str
,"set_mouse_pos %i %i",Event
.xmotion
.x
, Event
.xmotion
.y
);
821 mp_input_queue_cmd(vo
->input_ctx
,
822 mp_input_parse_cmd(cmd_str
));
825 if (x11
->vo_mouse_autohide
)
827 vo_showcursor(display
, x11
->window
);
828 x11
->mouse_waiting_hide
= 1;
829 x11
->mouse_timer
= GetTimerMS();
833 if (x11
->vo_mouse_autohide
)
835 vo_showcursor(display
, x11
->window
);
836 x11
->mouse_waiting_hide
= 1;
837 x11
->mouse_timer
= GetTimerMS();
839 mplayer_put_key(vo
->key_fifo
,
840 (MOUSE_BTN0
+ Event
.xbutton
.button
- 1)
844 if (x11
->vo_mouse_autohide
)
846 vo_showcursor(display
, x11
->window
);
847 x11
->mouse_waiting_hide
= 1;
848 x11
->mouse_timer
= GetTimerMS();
850 mplayer_put_key(vo
->key_fifo
,
851 MOUSE_BTN0
+ Event
.xbutton
.button
- 1);
856 XGetAtomName(display
, Event
.xproperty
.atom
);
861 // fprintf(stderr,"[ws] PropertyNotify ( 0x%x ) %s ( 0x%x )\n",vo_window,name,Event.xproperty.atom );
867 x11
->vo_hint
.win_gravity
= x11
->old_gravity
;
868 XSetWMNormalHints(display
, x11
->window
, &x11
->vo_hint
);
872 if (Event
.xclient
.message_type
== x11
->XAWM_PROTOCOLS
&&
873 Event
.xclient
.data
.l
[0] == x11
->XAWM_DELETE_WINDOW
)
874 mplayer_put_key(vo
->key_fifo
, KEY_CLOSE_WIN
);
882 * \brief sets the size and position of the non-fullscreen window.
884 static void vo_x11_nofs_sizepos(struct vo
*vo
, int x
, int y
,
885 int width
, int height
)
887 struct vo_x11_state
*x11
= vo
->x11
;
888 vo_x11_sizehint(vo
, x
, y
, width
, height
, 0);
892 x11
->vo_old_width
= width
;
893 x11
->vo_old_height
= height
;
898 vo
->dheight
= height
;
899 if (vo
->opts
->force_window_position
)
900 XMoveResizeWindow(vo
->x11
->display
, vo
->x11
->window
, x
, y
, width
,
903 XResizeWindow(vo
->x11
->display
, vo
->x11
->window
, width
, height
);
907 void vo_x11_sizehint(struct vo
*vo
, int x
, int y
, int width
, int height
, int max
)
909 struct vo_x11_state
*x11
= vo
->x11
;
910 x11
->vo_hint
.flags
= 0;
913 x11
->vo_hint
.flags
|= PAspect
;
914 x11
->vo_hint
.min_aspect
.x
= width
;
915 x11
->vo_hint
.min_aspect
.y
= height
;
916 x11
->vo_hint
.max_aspect
.x
= width
;
917 x11
->vo_hint
.max_aspect
.y
= height
;
920 x11
->vo_hint
.flags
|= PPosition
| PSize
;
923 x11
->vo_hint
.width
= width
;
924 x11
->vo_hint
.height
= height
;
927 x11
->vo_hint
.flags
|= PMaxSize
;
928 x11
->vo_hint
.max_width
= width
;
929 x11
->vo_hint
.max_height
= height
;
932 x11
->vo_hint
.max_width
= 0;
933 x11
->vo_hint
.max_height
= 0;
936 // Set minimum height/width to 4 to avoid off-by-one errors
937 // and because mga_vid requires a minimal size of 4 pixels.
938 x11
->vo_hint
.flags
|= PMinSize
;
939 x11
->vo_hint
.min_width
= x11
->vo_hint
.min_height
= 4;
941 // Set the base size. A window manager might display the window
942 // size to the user relative to this.
943 // Setting these to width/height might be nice, but e.g. fluxbox can't handle it.
944 x11
->vo_hint
.flags
|= PBaseSize
;
945 x11
->vo_hint
.base_width
= 0 /*width*/;
946 x11
->vo_hint
.base_height
= 0 /*height*/;
948 x11
->vo_hint
.flags
|= PWinGravity
;
949 x11
->vo_hint
.win_gravity
= StaticGravity
;
950 XSetWMNormalHints(x11
->display
, x11
->window
, &x11
->vo_hint
);
953 static int vo_x11_get_gnome_layer(struct vo_x11_state
*x11
, Window win
)
957 unsigned long nitems
;
958 unsigned long bytesafter
;
959 unsigned short *args
= NULL
;
961 if (XGetWindowProperty(x11
->display
, win
, x11
->XA_WIN_LAYER
, 0, 16384,
962 False
, AnyPropertyType
, &type
, &format
, &nitems
,
964 (unsigned char **) &args
) == Success
965 && nitems
> 0 && args
)
967 mp_msg(MSGT_VO
, MSGL_V
, "[x11] original window layer is %d.\n",
971 return WIN_LAYER_NORMAL
;
975 static Window
vo_x11_create_smooth_window(struct vo_x11_state
*x11
, Window mRoot
,
976 Visual
* vis
, int x
, int y
,
977 unsigned int width
, unsigned int height
,
978 int depth
, Colormap col_map
)
980 unsigned long xswamask
= CWBorderPixel
;
981 XSetWindowAttributes xswa
;
984 if (col_map
!= CopyFromParent
)
986 xswa
.colormap
= col_map
;
987 xswamask
|= CWColormap
;
989 xswa
.background_pixel
= 0;
990 xswa
.border_pixel
= 0;
991 xswa
.backing_store
= NotUseful
;
992 xswa
.bit_gravity
= StaticGravity
;
995 XCreateWindow(x11
->display
, x11
->rootwin
, x
, y
, width
, height
, 0, depth
,
996 CopyFromParent
, vis
, xswamask
, &xswa
);
997 XSetWMProtocols(x11
->display
, ret_win
, &x11
->XAWM_DELETE_WINDOW
, 1);
999 x11
->f_gc
= XCreateGC(x11
->display
, ret_win
, 0, 0);
1000 XSetForeground(x11
->display
, x11
->f_gc
, 0);
1006 * \brief create and setup a window suitable for display
1007 * \param vis Visual to use for creating the window
1008 * \param x x position of window
1009 * \param y y position of window
1010 * \param width width of window
1011 * \param height height of window
1012 * \param flags flags for window creation.
1013 * Only VOFLAG_FULLSCREEN is supported so far.
1014 * \param col_map Colourmap for window or CopyFromParent if a specific colormap isn't needed
1015 * \param classname name to use for the classhint
1016 * \param title title for the window
1018 * This also does the grunt-work like setting Window Manager hints etc.
1019 * If vo_window is already set it just moves and resizes it.
1021 void vo_x11_create_vo_window(struct vo
*vo
, XVisualInfo
*vis
, int x
, int y
,
1022 unsigned int width
, unsigned int height
, int flags
,
1024 const char *classname
, const char *title
)
1026 struct MPOpts
*opts
= vo
->opts
;
1027 struct vo_x11_state
*x11
= vo
->x11
;
1028 Display
*mDisplay
= vo
->x11
->display
;
1031 vo_fs
= flags
& VOFLAG_FULLSCREEN
;
1032 x11
->window
= WinID
? (Window
)WinID
: x11
->rootwin
;
1033 if (col_map
!= CopyFromParent
) {
1034 unsigned long xswamask
= CWColormap
;
1035 XSetWindowAttributes xswa
;
1036 xswa
.colormap
= col_map
;
1037 XChangeWindowAttributes(mDisplay
, x11
->window
, xswamask
, &xswa
);
1038 XInstallColormap(mDisplay
, col_map
);
1040 if (WinID
) vo_x11_update_geometry(vo
);
1041 vo_x11_selectinput_witherr(mDisplay
, x11
->window
,
1042 StructureNotifyMask
| KeyPressMask
| PointerMotionMask
|
1043 ButtonPressMask
| ButtonReleaseMask
| ExposureMask
);
1046 if (x11
->window
== None
) {
1049 vo
->dheight
= height
;
1050 x11
->window
= vo_x11_create_smooth_window(x11
, x11
->rootwin
, vis
->visual
,
1051 x
, y
, width
, height
, vis
->depth
, col_map
);
1052 x11
->window_state
= VOFLAG_HIDDEN
;
1054 if (flags
& VOFLAG_HIDDEN
)
1056 if (x11
->window_state
& VOFLAG_HIDDEN
) {
1059 x11
->window_state
&= ~VOFLAG_HIDDEN
;
1060 vo_x11_classhint(vo
, x11
->window
, classname
);
1061 XStoreName(mDisplay
, x11
->window
, title
);
1062 vo_hidecursor(mDisplay
, x11
->window
);
1063 XSelectInput(mDisplay
, x11
->window
, StructureNotifyMask
);
1064 hint
.x
= x
; hint
.y
= y
;
1065 hint
.width
= width
; hint
.height
= height
;
1066 hint
.flags
= PPosition
| PSize
;
1067 XSetStandardProperties(mDisplay
, x11
->window
, title
, title
, None
, NULL
, 0, &hint
);
1068 if (!vo_border
) vo_x11_decoration(vo
, 0);
1070 XMapWindow(mDisplay
, x11
->window
);
1071 vo_x11_clearwindow(vo
, x11
->window
);
1074 XNextEvent(mDisplay
, &xev
);
1075 } while (xev
.type
!= MapNotify
|| xev
.xmap
.event
!= x11
->window
);
1076 XSelectInput(mDisplay
, x11
->window
, NoEventMask
);
1077 XSync(mDisplay
, False
);
1078 vo_x11_selectinput_witherr(mDisplay
, x11
->window
,
1079 StructureNotifyMask
| KeyPressMask
| PointerMotionMask
|
1080 ButtonPressMask
| ButtonReleaseMask
| ExposureMask
);
1082 if (opts
->vo_ontop
) vo_x11_setlayer(vo
, x11
->window
, opts
->vo_ontop
);
1083 vo_x11_nofs_sizepos(vo
, vo
->dx
, vo
->dy
, width
, height
);
1084 if (!!vo_fs
!= !!(flags
& VOFLAG_FULLSCREEN
))
1085 vo_x11_fullscreen(vo
);
1087 // if we are already in fullscreen do not switch back and forth, just
1088 // set the size values right.
1089 vo
->dwidth
= vo
->opts
->vo_screenwidth
;
1090 vo
->dheight
= vo
->opts
->vo_screenheight
;
1093 if (x11
->vo_gc
!= None
)
1094 XFreeGC(mDisplay
, x11
->vo_gc
);
1095 x11
->vo_gc
= XCreateGC(mDisplay
, x11
->window
, GCForeground
, &xgcv
);
1096 XSync(mDisplay
, False
);
1097 x11
->vo_mouse_autohide
= 1;
1100 void vo_x11_clearwindow_part(struct vo
*vo
, Window vo_window
,
1101 int img_width
, int img_height
, int use_fs
)
1103 struct vo_x11_state
*x11
= vo
->x11
;
1104 struct MPOpts
*opts
= vo
->opts
;
1105 Display
*mDisplay
= vo
->x11
->display
;
1106 int u_dheight
, u_dwidth
, left_ov
, left_ov2
;
1111 u_dheight
= use_fs
? opts
->vo_screenheight
: vo
->dheight
;
1112 u_dwidth
= use_fs
? opts
->vo_screenwidth
: vo
->dwidth
;
1113 if ((u_dheight
<= img_height
) && (u_dwidth
<= img_width
))
1116 left_ov
= (u_dheight
- img_height
) / 2;
1117 left_ov2
= (u_dwidth
- img_width
) / 2;
1119 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, 0, 0, u_dwidth
, left_ov
);
1120 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, 0, u_dheight
- left_ov
- 1,
1121 u_dwidth
, left_ov
+ 1);
1123 if (u_dwidth
> img_width
)
1125 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, 0, left_ov
, left_ov2
,
1127 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, u_dwidth
- left_ov2
- 1,
1128 left_ov
, left_ov2
+ 1, img_height
);
1134 void vo_x11_clearwindow(struct vo
*vo
, Window vo_window
)
1136 struct vo_x11_state
*x11
= vo
->x11
;
1137 struct MPOpts
*opts
= vo
->opts
;
1140 XFillRectangle(x11
->display
, vo_window
, x11
->f_gc
, 0, 0,
1141 opts
->vo_screenwidth
, opts
->vo_screenheight
);
1143 XFlush(x11
->display
);
1147 void vo_x11_setlayer(struct vo
*vo
, Window vo_window
, int layer
)
1149 struct vo_x11_state
*x11
= vo
->x11
;
1153 if (x11
->fs_type
& vo_wm_LAYER
)
1155 XClientMessageEvent xev
;
1157 if (!x11
->orig_layer
)
1158 x11
->orig_layer
= vo_x11_get_gnome_layer(x11
, vo_window
);
1160 memset(&xev
, 0, sizeof(xev
));
1161 xev
.type
= ClientMessage
;
1162 xev
.display
= x11
->display
;
1163 xev
.window
= vo_window
;
1164 xev
.message_type
= x11
->XA_WIN_LAYER
;
1166 xev
.data
.l
[0] = layer
? fs_layer
: x11
->orig_layer
; // if not fullscreen, stay on default layer
1167 xev
.data
.l
[1] = CurrentTime
;
1168 mp_msg(MSGT_VO
, MSGL_V
,
1169 "[x11] Layered style stay on top (layer %ld).\n",
1171 XSendEvent(x11
->display
, x11
->rootwin
, False
, SubstructureNotifyMask
,
1173 } else if (x11
->fs_type
& vo_wm_NETWM
)
1175 XClientMessageEvent xev
;
1178 memset(&xev
, 0, sizeof(xev
));
1179 xev
.type
= ClientMessage
;
1180 xev
.message_type
= x11
->XA_NET_WM_STATE
;
1181 xev
.display
= x11
->display
;
1182 xev
.window
= vo_window
;
1184 xev
.data
.l
[0] = layer
;
1186 if (x11
->fs_type
& vo_wm_STAYS_ON_TOP
)
1187 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_STAYS_ON_TOP
;
1188 else if (x11
->fs_type
& vo_wm_ABOVE
)
1189 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_ABOVE
;
1190 else if (x11
->fs_type
& vo_wm_FULLSCREEN
)
1191 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_FULLSCREEN
;
1192 else if (x11
->fs_type
& vo_wm_BELOW
)
1193 // This is not fallback. We can safely assume that the situation
1194 // where only NETWM_STATE_BELOW is supported doesn't exist.
1195 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_BELOW
;
1197 XSendEvent(x11
->display
, x11
->rootwin
, False
, SubstructureRedirectMask
,
1199 state
= XGetAtomName(x11
->display
, xev
.data
.l
[1]);
1200 mp_msg(MSGT_VO
, MSGL_V
,
1201 "[x11] NET style stay on top (layer %d). Using state %s.\n",
1207 static int vo_x11_get_fs_type(int supported
)
1210 int type
= supported
;
1214 for (i
= 0; vo_fstype_list
[i
]; i
++)
1217 char *arg
= vo_fstype_list
[i
];
1219 if (vo_fstype_list
[i
][0] == '-')
1222 arg
= vo_fstype_list
[i
] + 1;
1225 if (!strncmp(arg
, "layer", 5))
1227 if (!neg
&& (arg
[5] == '='))
1229 char *endptr
= NULL
;
1230 int layer
= strtol(vo_fstype_list
[i
] + 6, &endptr
, 10);
1232 if (endptr
&& *endptr
== '\0' && layer
>= 0
1237 type
&= ~vo_wm_LAYER
;
1239 type
|= vo_wm_LAYER
;
1240 } else if (!strcmp(arg
, "above"))
1243 type
&= ~vo_wm_ABOVE
;
1245 type
|= vo_wm_ABOVE
;
1246 } else if (!strcmp(arg
, "fullscreen"))
1249 type
&= ~vo_wm_FULLSCREEN
;
1251 type
|= vo_wm_FULLSCREEN
;
1252 } else if (!strcmp(arg
, "stays_on_top"))
1255 type
&= ~vo_wm_STAYS_ON_TOP
;
1257 type
|= vo_wm_STAYS_ON_TOP
;
1258 } else if (!strcmp(arg
, "below"))
1261 type
&= ~vo_wm_BELOW
;
1263 type
|= vo_wm_BELOW
;
1264 } else if (!strcmp(arg
, "netwm"))
1267 type
&= ~vo_wm_NETWM
;
1269 type
|= vo_wm_NETWM
;
1270 } else if (!strcmp(arg
, "none"))
1271 type
= 0; // clear; keep parsing
1279 * \brief update vo->dx, vo->dy, vo->dwidth and vo->dheight with current values of vo->x11->window
1280 * \return returns current color depth of vo->x11->window
1282 int vo_x11_update_geometry(struct vo
*vo
)
1284 struct vo_x11_state
*x11
= vo
->x11
;
1285 unsigned depth
, w
, h
;
1288 XGetGeometry(x11
->display
, x11
->window
, &dummy_win
, &dummy_int
, &dummy_int
,
1289 &w
, &h
, &dummy_int
, &depth
);
1290 if (w
<= INT_MAX
&& h
<= INT_MAX
) {
1294 XTranslateCoordinates(x11
->display
, x11
->window
, x11
->rootwin
, 0, 0,
1295 &vo
->dx
, &vo
->dy
, &dummy_win
);
1297 XStoreName(x11
->display
, x11
->window
, vo_wintitle
);
1299 return depth
<= INT_MAX
? depth
: 0;
1302 void vo_x11_fullscreen(struct vo
*vo
)
1304 struct MPOpts
*opts
= vo
->opts
;
1305 struct vo_x11_state
*x11
= vo
->x11
;
1309 w
= x11
->vo_old_width
;
1310 h
= x11
->vo_old_height
;
1321 vo_x11_ewmh_fullscreen(x11
, _NET_WM_STATE_REMOVE
); // removes fullscreen state if wm supports EWMH
1326 vo_x11_ewmh_fullscreen(x11
, _NET_WM_STATE_ADD
); // sends fullscreen state to be added if wm supports EWMH
1329 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1331 x11
->vo_old_x
= vo
->dx
;
1332 x11
->vo_old_y
= vo
->dy
;
1333 x11
->vo_old_width
= vo
->dwidth
;
1334 x11
->vo_old_height
= vo
->dheight
;
1336 update_xinerama_info(vo
);
1339 w
= opts
->vo_screenwidth
;
1340 h
= opts
->vo_screenheight
;
1345 XGetWMNormalHints(x11
->display
, x11
->window
, &x11
->vo_hint
, &dummy
);
1346 if (!(x11
->vo_hint
.flags
& PWinGravity
))
1347 x11
->old_gravity
= NorthWestGravity
;
1349 x11
->old_gravity
= x11
->vo_hint
.win_gravity
;
1351 if (x11
->wm_type
== 0 && !(vo_fsmode
& 16))
1353 XUnmapWindow(x11
->display
, x11
->window
); // required for MWM
1354 XWithdrawWindow(x11
->display
, x11
->window
, x11
->screen
);
1358 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1360 vo_x11_decoration(vo
, vo_border
&& !vo_fs
);
1361 vo_x11_sizehint(vo
, x
, y
, w
, h
, 0);
1362 vo_x11_setlayer(vo
, x11
->window
, vo_fs
);
1365 XMoveResizeWindow(x11
->display
, x11
->window
, x
, y
, w
, h
);
1367 /* some WMs lose ontop after fullscreen */
1368 if ((!(vo_fs
)) & opts
->vo_ontop
)
1369 vo_x11_setlayer(vo
, x11
->window
, opts
->vo_ontop
);
1371 XMapRaised(x11
->display
, x11
->window
);
1372 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // some WMs change window pos on map
1373 XMoveResizeWindow(x11
->display
, x11
->window
, x
, y
, w
, h
);
1374 XRaiseWindow(x11
->display
, x11
->window
);
1375 XFlush(x11
->display
);
1378 void vo_x11_ontop(struct vo
*vo
)
1380 struct MPOpts
*opts
= vo
->opts
;
1381 opts
->vo_ontop
= !opts
->vo_ontop
;
1383 vo_x11_setlayer(vo
, vo
->x11
->window
, opts
->vo_ontop
);
1386 void vo_x11_border(struct vo
*vo
)
1388 vo_border
= !vo_border
;
1389 vo_x11_decoration(vo
, vo_border
&& !vo_fs
);
1393 * XScreensaver stuff
1396 static int screensaver_off
;
1397 static unsigned int time_last
;
1399 void xscreensaver_heartbeat(struct vo_x11_state
*x11
)
1401 unsigned int time
= GetTimerMS();
1403 if (x11
->display
&& screensaver_off
&& (time
- time_last
) > 30000)
1407 XResetScreenSaver(x11
->display
);
1411 static int xss_suspend(Display
*mDisplay
, Bool suspend
)
1416 int event
, error
, major
, minor
;
1417 if (XScreenSaverQueryExtension(mDisplay
, &event
, &error
) != True
||
1418 XScreenSaverQueryVersion(mDisplay
, &major
, &minor
) != True
)
1420 if (major
< 1 || (major
== 1 && minor
< 1))
1422 XScreenSaverSuspend(mDisplay
, suspend
);
1428 * End of XScreensaver stuff
1431 static void saver_on(Display
* mDisplay
)
1434 if (!screensaver_off
)
1436 screensaver_off
= 0;
1437 if (xss_suspend(mDisplay
, False
))
1443 if (DPMSQueryExtension(mDisplay
, ¬hing
, ¬hing
))
1445 if (!DPMSEnable(mDisplay
))
1446 { // restoring power saving settings
1447 mp_msg(MSGT_VO
, MSGL_WARN
, "DPMS not available?\n");
1450 // DPMS does not seem to be enabled unless we call DPMSInfo
1454 DPMSForceLevel(mDisplay
, DPMSModeOn
);
1455 DPMSInfo(mDisplay
, &state
, &onoff
);
1458 mp_msg(MSGT_VO
, MSGL_V
,
1459 "Successfully enabled DPMS\n");
1462 mp_msg(MSGT_VO
, MSGL_WARN
, "Could not enable DPMS\n");
1471 static void saver_off(Display
* mDisplay
)
1475 if (screensaver_off
)
1477 screensaver_off
= 1;
1478 if (xss_suspend(mDisplay
, True
))
1481 if (DPMSQueryExtension(mDisplay
, ¬hing
, ¬hing
))
1486 DPMSInfo(mDisplay
, &state
, &onoff
);
1491 mp_msg(MSGT_VO
, MSGL_V
, "Disabling DPMS\n");
1493 stat
= DPMSDisable(mDisplay
); // monitor powersave off
1494 mp_msg(MSGT_VO
, MSGL_V
, "DPMSDisable stat: %d\n", stat
);
1500 static XErrorHandler old_handler
= NULL
;
1501 static int selectinput_err
= 0;
1502 static int x11_selectinput_errorhandler(Display
* display
,
1503 XErrorEvent
* event
)
1505 if (event
->error_code
== BadAccess
)
1507 selectinput_err
= 1;
1508 mp_msg(MSGT_VO
, MSGL_ERR
,
1509 "X11 error: BadAccess during XSelectInput Call\n");
1510 mp_msg(MSGT_VO
, MSGL_ERR
,
1511 "X11 error: The 'ButtonPressMask' mask of specified window has probably already used by another appication (see man XSelectInput)\n");
1512 /* If you think MPlayer should shutdown with this error,
1513 * comment out the following line */
1516 if (old_handler
!= NULL
)
1517 old_handler(display
, event
);
1519 x11_errorhandler(display
, event
);
1523 void vo_x11_selectinput_witherr(Display
* display
, Window w
,
1526 XSync(display
, False
);
1527 old_handler
= XSetErrorHandler(x11_selectinput_errorhandler
);
1528 selectinput_err
= 0;
1529 if (vo_nomouse_input
)
1531 XSelectInput(display
, w
,
1533 (~(ButtonPressMask
| ButtonReleaseMask
)));
1536 XSelectInput(display
, w
, event_mask
);
1538 XSync(display
, False
);
1539 XSetErrorHandler(old_handler
);
1540 if (selectinput_err
)
1542 mp_msg(MSGT_VO
, MSGL_ERR
,
1543 "X11 error: MPlayer discards mouse control (reconfiguring)\n");
1544 XSelectInput(display
, w
,
1547 (ButtonPressMask
| ButtonReleaseMask
|
1548 PointerMotionMask
)));
1552 #ifdef CONFIG_XF86VM
1553 void vo_vm_switch(struct vo
*vo
)
1555 struct vo_x11_state
*x11
= vo
->x11
;
1556 struct MPOpts
*opts
= vo
->opts
;
1557 Display
*mDisplay
= x11
->display
;
1558 int vm_event
, vm_error
;
1560 int i
, j
, have_vm
= 0;
1561 int X
= vo
->dwidth
, Y
= vo
->dheight
;
1562 int modeline_width
, modeline_height
;
1566 if (XF86VidModeQueryExtension(mDisplay
, &vm_event
, &vm_error
))
1568 XF86VidModeQueryVersion(mDisplay
, &vm_ver
, &vm_rev
);
1569 mp_msg(MSGT_VO
, MSGL_V
, "XF86VidMode extension v%i.%i\n", vm_ver
,
1573 mp_msg(MSGT_VO
, MSGL_WARN
,
1574 "XF86VidMode extension not available.\n");
1579 if (vidmodes
== NULL
)
1580 XF86VidModeGetAllModeLines(mDisplay
, x11
->screen
, &modecount
,
1583 modeline_width
= vidmodes
[0]->hdisplay
;
1584 modeline_height
= vidmodes
[0]->vdisplay
;
1586 for (i
= 1; i
< modecount
; i
++)
1587 if ((vidmodes
[i
]->hdisplay
>= X
)
1588 && (vidmodes
[i
]->vdisplay
>= Y
))
1589 if ((vidmodes
[i
]->hdisplay
<= modeline_width
)
1590 && (vidmodes
[i
]->vdisplay
<= modeline_height
))
1592 modeline_width
= vidmodes
[i
]->hdisplay
;
1593 modeline_height
= vidmodes
[i
]->vdisplay
;
1597 mp_tmsg(MSGT_VO
, MSGL_INFO
, "XF86VM: Selected video mode %dx%d for image size %dx%d.\n",
1598 modeline_width
, modeline_height
, X
, Y
);
1599 XF86VidModeLockModeSwitch(mDisplay
, x11
->screen
, 0);
1600 XF86VidModeSwitchToMode(mDisplay
, x11
->screen
, vidmodes
[j
]);
1601 XF86VidModeSwitchToMode(mDisplay
, x11
->screen
, vidmodes
[j
]);
1603 // FIXME: all this is more of a hack than proper solution
1604 X
= (opts
->vo_screenwidth
- modeline_width
) / 2;
1605 Y
= (opts
->vo_screenheight
- modeline_height
) / 2;
1606 XF86VidModeSetViewPort(mDisplay
, x11
->screen
, X
, Y
);
1609 vo
->dwidth
= modeline_width
;
1610 vo
->dheight
= modeline_height
;
1611 aspect_save_screenres(vo
, modeline_width
, modeline_height
);
1615 void vo_vm_close(struct vo
*vo
)
1617 Display
*dpy
= vo
->x11
->display
;
1618 struct MPOpts
*opts
= vo
->opts
;
1619 if (vidmodes
!= NULL
)
1625 XF86VidModeGetAllModeLines(dpy
, vo
->x11
->screen
, &modecount
,
1627 for (i
= 0; i
< modecount
; i
++)
1628 if ((vidmodes
[i
]->hdisplay
== opts
->vo_screenwidth
)
1629 && (vidmodes
[i
]->vdisplay
== opts
->vo_screenheight
))
1631 mp_msg(MSGT_VO
, MSGL_INFO
,
1632 "Returning to original mode %dx%d\n",
1633 opts
->vo_screenwidth
, opts
->vo_screenheight
);
1637 XF86VidModeSwitchToMode(dpy
, vo
->x11
->screen
, vidmodes
[i
]);
1638 XF86VidModeSwitchToMode(dpy
, vo
->x11
->screen
, vidmodes
[i
]);
1644 double vo_vm_get_fps(struct vo
*vo
)
1646 struct vo_x11_state
*x11
= vo
->x11
;
1648 XF86VidModeModeLine modeline
;
1649 if (!XF86VidModeGetModeLine(x11
->display
, x11
->screen
, &clock
, &modeline
))
1651 if (modeline
.privsize
)
1652 XFree(modeline
.private);
1653 return 1e3
* clock
/ modeline
.htotal
/ modeline
.vtotal
;
1657 #endif /* X11_FULLSCREEN */
1661 * Scan the available visuals on this Display/Screen. Try to find
1662 * the 'best' available TrueColor visual that has a decent color
1663 * depth (at least 15bit). If there are multiple visuals with depth
1664 * >= 15bit, we prefer visuals with a smaller color depth.
1666 int vo_find_depth_from_visuals(Display
* dpy
, int screen
,
1667 Visual
** visual_return
)
1669 XVisualInfo visual_tmpl
;
1670 XVisualInfo
*visuals
;
1672 int bestvisual
= -1;
1673 int bestvisual_depth
= -1;
1675 visual_tmpl
.screen
= screen
;
1676 visual_tmpl
.class = TrueColor
;
1677 visuals
= XGetVisualInfo(dpy
,
1678 VisualScreenMask
| VisualClassMask
,
1679 &visual_tmpl
, &nvisuals
);
1680 if (visuals
!= NULL
)
1682 for (i
= 0; i
< nvisuals
; i
++)
1684 mp_msg(MSGT_VO
, MSGL_V
,
1685 "vo: X11 truecolor visual %#lx, depth %d, R:%lX G:%lX B:%lX\n",
1686 visuals
[i
].visualid
, visuals
[i
].depth
,
1687 visuals
[i
].red_mask
, visuals
[i
].green_mask
,
1688 visuals
[i
].blue_mask
);
1690 * Save the visual index and its depth, if this is the first
1691 * truecolor visul, or a visual that is 'preferred' over the
1692 * previous 'best' visual.
1694 if (bestvisual_depth
== -1
1695 || (visuals
[i
].depth
>= 15
1696 && (visuals
[i
].depth
< bestvisual_depth
1697 || bestvisual_depth
< 15)))
1700 bestvisual_depth
= visuals
[i
].depth
;
1704 if (bestvisual
!= -1 && visual_return
!= NULL
)
1705 *visual_return
= visuals
[bestvisual
].visual
;
1709 return bestvisual_depth
;
1713 static Colormap cmap
= None
;
1714 static XColor cols
[256];
1715 static int cm_size
, red_mask
, green_mask
, blue_mask
;
1718 Colormap
vo_x11_create_colormap(struct vo
*vo
, XVisualInfo
*vinfo
)
1720 struct vo_x11_state
*x11
= vo
->x11
;
1721 unsigned k
, r
, g
, b
, ru
, gu
, bu
, m
, rv
, gv
, bv
, rvu
, gvu
, bvu
;
1723 if (vinfo
->class != DirectColor
)
1724 return XCreateColormap(x11
->display
, x11
->rootwin
, vinfo
->visual
,
1727 /* can this function get called twice or more? */
1730 cm_size
= vinfo
->colormap_size
;
1731 red_mask
= vinfo
->red_mask
;
1732 green_mask
= vinfo
->green_mask
;
1733 blue_mask
= vinfo
->blue_mask
;
1734 ru
= (red_mask
& (red_mask
- 1)) ^ red_mask
;
1735 gu
= (green_mask
& (green_mask
- 1)) ^ green_mask
;
1736 bu
= (blue_mask
& (blue_mask
- 1)) ^ blue_mask
;
1737 rvu
= 65536ull * ru
/ (red_mask
+ ru
);
1738 gvu
= 65536ull * gu
/ (green_mask
+ gu
);
1739 bvu
= 65536ull * bu
/ (blue_mask
+ bu
);
1742 m
= DoRed
| DoGreen
| DoBlue
;
1743 for (k
= 0; k
< cm_size
; k
++)
1747 cols
[k
].pixel
= r
| g
| b
;
1752 t
= (r
+ ru
) & red_mask
;
1756 t
= (g
+ gu
) & green_mask
;
1760 t
= (b
+ bu
) & blue_mask
;
1768 cmap
= XCreateColormap(x11
->display
, x11
->rootwin
, vinfo
->visual
, AllocAll
);
1769 XStoreColors(x11
->display
, cmap
, cols
, cm_size
);
1774 * Via colormaps/gamma ramps we can do gamma, brightness, contrast,
1775 * hue and red/green/blue intensity, but we cannot do saturation.
1776 * Currently only gamma, brightness and contrast are implemented.
1777 * Is there sufficient interest for hue and/or red/green/blue intensity?
1779 /* these values have range [-100,100] and are initially 0 */
1780 static int vo_gamma
= 0;
1781 static int vo_brightness
= 0;
1782 static int vo_contrast
= 0;
1784 static int transform_color(float val
,
1785 float brightness
, float contrast
, float gamma
) {
1786 float s
= pow(val
, gamma
);
1787 s
= (s
- 0.5) * contrast
+ 0.5;
1793 return (unsigned short) (s
* 65535);
1796 uint32_t vo_x11_set_equalizer(struct vo
*vo
, char *name
, int value
)
1798 float gamma
, brightness
, contrast
;
1803 * IMPLEMENTME: consider using XF86VidModeSetGammaRamp in the case
1804 * of TrueColor-ed window but be careful:
1805 * Unlike the colormaps, which are private for the X client
1806 * who created them and thus automatically destroyed on client
1807 * disconnect, this gamma ramp is a system-wide (X-server-wide)
1808 * setting and _must_ be restored before the process exits.
1809 * Unforunately when the process crashes (or gets killed
1810 * for some reason) it is impossible to restore the setting,
1811 * and such behaviour could be rather annoying for the users.
1816 if (!strcasecmp(name
, "brightness"))
1817 vo_brightness
= value
;
1818 else if (!strcasecmp(name
, "contrast"))
1819 vo_contrast
= value
;
1820 else if (!strcasecmp(name
, "gamma"))
1825 brightness
= 0.01 * vo_brightness
;
1826 contrast
= tan(0.0095 * (vo_contrast
+ 100) * M_PI
/ 4);
1827 gamma
= pow(2, -0.02 * vo_gamma
);
1829 rf
= (float) ((red_mask
& (red_mask
- 1)) ^ red_mask
) / red_mask
;
1830 gf
= (float) ((green_mask
& (green_mask
- 1)) ^ green_mask
) /
1832 bf
= (float) ((blue_mask
& (blue_mask
- 1)) ^ blue_mask
) / blue_mask
;
1834 /* now recalculate the colormap using the newly set value */
1835 for (k
= 0; k
< cm_size
; k
++)
1837 cols
[k
].red
= transform_color(rf
* k
, brightness
, contrast
, gamma
);
1838 cols
[k
].green
= transform_color(gf
* k
, brightness
, contrast
, gamma
);
1839 cols
[k
].blue
= transform_color(bf
* k
, brightness
, contrast
, gamma
);
1842 XStoreColors(vo
->x11
->display
, cmap
, cols
, cm_size
);
1843 XFlush(vo
->x11
->display
);
1847 uint32_t vo_x11_get_equalizer(char *name
, int *value
)
1851 if (!strcasecmp(name
, "brightness"))
1852 *value
= vo_brightness
;
1853 else if (!strcasecmp(name
, "contrast"))
1854 *value
= vo_contrast
;
1855 else if (!strcasecmp(name
, "gamma"))
1863 int vo_xv_set_eq(struct vo
*vo
, uint32_t xv_port
, char *name
, int value
)
1865 XvAttribute
*attributes
;
1866 int i
, howmany
, xv_atom
;
1868 mp_dbg(MSGT_VO
, MSGL_V
, "xv_set_eq called! (%s, %d)\n", name
, value
);
1870 /* get available attributes */
1871 attributes
= XvQueryPortAttributes(vo
->x11
->display
, xv_port
, &howmany
);
1872 for (i
= 0; i
< howmany
&& attributes
; i
++)
1873 if (attributes
[i
].flags
& XvSettable
)
1875 xv_atom
= XInternAtom(vo
->x11
->display
, attributes
[i
].name
, True
);
1876 /* since we have SET_DEFAULTS first in our list, we can check if it's available
1877 then trigger it if it's ok so that the other values are at default upon query */
1878 if (xv_atom
!= None
)
1880 int hue
= 0, port_value
, port_min
, port_max
;
1882 if (!strcmp(attributes
[i
].name
, "XV_BRIGHTNESS") &&
1883 (!strcasecmp(name
, "brightness")))
1885 else if (!strcmp(attributes
[i
].name
, "XV_CONTRAST") &&
1886 (!strcasecmp(name
, "contrast")))
1888 else if (!strcmp(attributes
[i
].name
, "XV_SATURATION") &&
1889 (!strcasecmp(name
, "saturation")))
1891 else if (!strcmp(attributes
[i
].name
, "XV_HUE") &&
1892 (!strcasecmp(name
, "hue")))
1897 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
1898 if (!strcmp(attributes
[i
].name
, "XV_RED_INTENSITY") &&
1899 (!strcasecmp(name
, "red_intensity")))
1901 else if (!strcmp(attributes
[i
].name
, "XV_GREEN_INTENSITY")
1902 && (!strcasecmp(name
, "green_intensity")))
1904 else if (!strcmp(attributes
[i
].name
, "XV_BLUE_INTENSITY")
1905 && (!strcasecmp(name
, "blue_intensity")))
1907 else if ((!strcmp(attributes
[i
].name
, "XV_ITURBT_709") //NVIDIA
1908 || !strcmp(attributes
[i
].name
, "XV_COLORSPACE"))//ATI
1909 && (!strcasecmp(name
, "bt_709")))
1914 port_min
= attributes
[i
].min_value
;
1915 port_max
= attributes
[i
].max_value
;
1917 /* nvidia hue workaround */
1918 if (hue
&& port_min
== 0 && port_max
== 360)
1922 0) ? (port_value
- 100) : (port_value
+ 100);
1928 (port_value
+ 100) * (port_max
- port_min
) / 200 +
1930 XvSetPortAttribute(vo
->x11
->display
, xv_port
, xv_atom
, port_value
);
1937 int vo_xv_get_eq(struct vo
*vo
, uint32_t xv_port
, char *name
, int *value
)
1940 XvAttribute
*attributes
;
1941 int i
, howmany
, xv_atom
;
1943 /* get available attributes */
1944 attributes
= XvQueryPortAttributes(vo
->x11
->display
, xv_port
, &howmany
);
1945 for (i
= 0; i
< howmany
&& attributes
; i
++)
1946 if (attributes
[i
].flags
& XvGettable
)
1948 xv_atom
= XInternAtom(vo
->x11
->display
, attributes
[i
].name
, True
);
1949 /* since we have SET_DEFAULTS first in our list, we can check if it's available
1950 then trigger it if it's ok so that the other values are at default upon query */
1951 if (xv_atom
!= None
)
1953 int val
, port_value
= 0, port_min
, port_max
;
1955 XvGetPortAttribute(vo
->x11
->display
, xv_port
, xv_atom
,
1958 port_min
= attributes
[i
].min_value
;
1959 port_max
= attributes
[i
].max_value
;
1961 (port_value
- port_min
) * 200 / (port_max
- port_min
) -
1964 if (!strcmp(attributes
[i
].name
, "XV_BRIGHTNESS") &&
1965 (!strcasecmp(name
, "brightness")))
1967 else if (!strcmp(attributes
[i
].name
, "XV_CONTRAST") &&
1968 (!strcasecmp(name
, "contrast")))
1970 else if (!strcmp(attributes
[i
].name
, "XV_SATURATION") &&
1971 (!strcasecmp(name
, "saturation")))
1973 else if (!strcmp(attributes
[i
].name
, "XV_HUE") &&
1974 (!strcasecmp(name
, "hue")))
1976 /* nasty nvidia detect */
1977 if (port_min
== 0 && port_max
== 360)
1978 *value
= (val
>= 0) ? (val
- 100) : (val
+ 100);
1982 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
1983 if (!strcmp(attributes
[i
].name
, "XV_RED_INTENSITY") &&
1984 (!strcasecmp(name
, "red_intensity")))
1986 else if (!strcmp(attributes
[i
].name
, "XV_GREEN_INTENSITY")
1987 && (!strcasecmp(name
, "green_intensity")))
1989 else if (!strcmp(attributes
[i
].name
, "XV_BLUE_INTENSITY")
1990 && (!strcasecmp(name
, "blue_intensity")))
1992 else if ((!strcmp(attributes
[i
].name
, "XV_ITURBT_709") //NVIDIA
1993 || !strcmp(attributes
[i
].name
, "XV_COLORSPACE"))//ATI
1994 && (!strcasecmp(name
, "bt_709")))
1999 mp_dbg(MSGT_VO
, MSGL_V
, "xv_get_eq called! (%s, %d)\n",
2008 * \brief Interns the requested atom if it is available.
2010 * \param atom_name String containing the name of the requested atom.
2012 * \return Returns the atom if available, else None is returned.
2015 static Atom
xv_intern_atom_if_exists(struct vo_x11_state
*x11
,
2016 char const *atom_name
)
2018 XvAttribute
* attributes
;
2020 Atom xv_atom
= None
;
2022 attributes
= XvQueryPortAttributes(x11
->display
, x11
->xv_port
, &attrib_count
);
2023 if( attributes
!=NULL
)
2025 for ( i
= 0; i
< attrib_count
; ++i
)
2027 if ( strcmp(attributes
[i
].name
, atom_name
) == 0 )
2029 xv_atom
= XInternAtom(x11
->display
, atom_name
, False
);
2030 break; // found what we want, break out
2033 XFree( attributes
);
2040 * \brief Try to enable vsync for xv.
2041 * \return Returns -1 if not available, 0 on failure and 1 on success.
2043 int vo_xv_enable_vsync(struct vo
*vo
)
2045 struct vo_x11_state
*x11
= vo
->x11
;
2046 Atom xv_atom
= xv_intern_atom_if_exists(x11
, "XV_SYNC_TO_VBLANK");
2047 if (xv_atom
== None
)
2049 return XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, 1) == Success
;
2053 * \brief Get maximum supported source image dimensions.
2055 * This function does not set the variables pointed to by
2056 * width and height if the information could not be retrieved,
2057 * so the caller is reponsible for properly initializing them.
2059 * \param width [out] The maximum width gets stored here.
2060 * \param height [out] The maximum height gets stored here.
2063 void vo_xv_get_max_img_dim(struct vo
*vo
, uint32_t * width
, uint32_t * height
)
2065 struct vo_x11_state
*x11
= vo
->x11
;
2066 XvEncodingInfo
* encodings
;
2067 //unsigned long num_encodings, idx; to int or too long?!
2068 unsigned int num_encodings
, idx
;
2070 XvQueryEncodings(x11
->display
, x11
->xv_port
, &num_encodings
, &encodings
);
2074 for ( idx
= 0; idx
< num_encodings
; ++idx
)
2076 if ( strcmp( encodings
[idx
].name
, "XV_IMAGE" ) == 0 )
2078 *width
= encodings
[idx
].width
;
2079 *height
= encodings
[idx
].height
;
2085 mp_msg( MSGT_VO
, MSGL_V
,
2086 "[xv common] Maximum source image dimensions: %ux%u\n",
2089 XvFreeEncodingInfo( encodings
);
2093 * \brief Print information about the colorkey method and source.
2095 * \param ck_handling Integer value containing the information about
2096 * colorkey handling (see x11_common.h).
2098 * Outputs the content of |ck_handling| as a readable message.
2101 static void vo_xv_print_ck_info(struct vo_x11_state
*x11
)
2103 mp_msg( MSGT_VO
, MSGL_V
, "[xv common] " );
2105 switch ( x11
->xv_ck_info
.method
)
2107 case CK_METHOD_NONE
:
2108 mp_msg( MSGT_VO
, MSGL_V
, "Drawing no colorkey.\n" ); return;
2109 case CK_METHOD_AUTOPAINT
:
2110 mp_msg( MSGT_VO
, MSGL_V
, "Colorkey is drawn by Xv." ); break;
2111 case CK_METHOD_MANUALFILL
:
2112 mp_msg( MSGT_VO
, MSGL_V
, "Drawing colorkey manually." ); break;
2113 case CK_METHOD_BACKGROUND
:
2114 mp_msg( MSGT_VO
, MSGL_V
, "Colorkey is drawn as window background." ); break;
2117 mp_msg( MSGT_VO
, MSGL_V
, "\n[xv common] " );
2119 switch ( x11
->xv_ck_info
.source
)
2122 mp_msg( MSGT_VO
, MSGL_V
, "Using colorkey from Xv (0x%06lx).\n",
2126 if ( x11
->xv_ck_info
.method
== CK_METHOD_AUTOPAINT
)
2128 mp_msg( MSGT_VO
, MSGL_V
,
2129 "Ignoring colorkey from MPlayer (0x%06lx).\n",
2134 mp_msg( MSGT_VO
, MSGL_V
,
2135 "Using colorkey from MPlayer (0x%06lx)."
2136 " Use -colorkey to change.\n",
2141 mp_msg( MSGT_VO
, MSGL_V
,
2142 "Setting and using colorkey from MPlayer (0x%06lx)."
2143 " Use -colorkey to change.\n",
2149 * \brief Init colorkey depending on the settings in xv_ck_info.
2151 * \return Returns 0 on failure and 1 on success.
2153 * Sets the colorkey variable according to the CK_SRC_* and CK_METHOD_*
2154 * flags in xv_ck_info.
2158 * - manual colorkey drawing ( CK_METHOD_MANUALFILL )
2159 * - set colorkey as window background ( CK_METHOD_BACKGROUND )
2160 * - let Xv paint the colorkey ( CK_METHOD_AUTOPAINT )
2162 * - use currently set colorkey ( CK_SRC_CUR )
2163 * - use colorkey in vo_colorkey ( CK_SRC_USE )
2164 * - use and set colorkey in vo_colorkey ( CK_SRC_SET )
2166 * NOTE: If vo_colorkey has bits set after the first 3 low order bytes
2167 * we don't draw anything as this means it was forced to off.
2169 int vo_xv_init_colorkey(struct vo
*vo
)
2171 struct vo_x11_state
*x11
= vo
->x11
;
2175 /* check if colorkeying is needed */
2176 xv_atom
= xv_intern_atom_if_exists(vo
->x11
, "XV_COLORKEY");
2178 /* if we have to deal with colorkeying ... */
2179 if( xv_atom
!= None
&& !(vo_colorkey
& 0xFF000000) )
2181 /* check if we should use the colorkey specified in vo_colorkey */
2182 if ( x11
->xv_ck_info
.source
!= CK_SRC_CUR
)
2184 x11
->xv_colorkey
= vo_colorkey
;
2186 /* check if we have to set the colorkey too */
2187 if ( x11
->xv_ck_info
.source
== CK_SRC_SET
)
2189 xv_atom
= XInternAtom(x11
->display
, "XV_COLORKEY",False
);
2191 rez
= XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, vo_colorkey
);
2192 if ( rez
!= Success
)
2194 mp_msg( MSGT_VO
, MSGL_FATAL
,
2195 "[xv common] Couldn't set colorkey!\n" );
2196 return 0; // error setting colorkey
2204 rez
=XvGetPortAttribute(x11
->display
,x11
->xv_port
, xv_atom
, &colorkey_ret
);
2205 if ( rez
== Success
)
2207 x11
->xv_colorkey
= colorkey_ret
;
2211 mp_msg( MSGT_VO
, MSGL_FATAL
,
2212 "[xv common] Couldn't get colorkey!"
2213 "Maybe the selected Xv port has no overlay.\n" );
2214 return 0; // error getting colorkey
2218 xv_atom
= xv_intern_atom_if_exists(vo
->x11
, "XV_AUTOPAINT_COLORKEY");
2220 /* should we draw the colorkey ourselves or activate autopainting? */
2221 if ( x11
->xv_ck_info
.method
== CK_METHOD_AUTOPAINT
)
2223 rez
= !Success
; // reset rez to something different than Success
2225 if ( xv_atom
!= None
) // autopaint is supported
2227 rez
= XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, 1);
2230 if ( rez
!= Success
)
2232 // fallback to manual colorkey drawing
2233 x11
->xv_ck_info
.method
= CK_METHOD_MANUALFILL
;
2236 else // disable colorkey autopainting if supported
2238 if ( xv_atom
!= None
) // we have autopaint attribute
2240 XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, 0);
2244 else // do no colorkey drawing at all
2246 x11
->xv_ck_info
.method
= CK_METHOD_NONE
;
2247 } /* end: should we draw colorkey */
2249 /* output information about the current colorkey settings */
2250 vo_xv_print_ck_info(x11
);
2252 return 1; // success
2256 * \brief Draw the colorkey on the video window.
2258 * Draws the colorkey depending on the set method ( colorkey_handling ).
2260 * Also draws the black bars ( when the video doesn't fit the display in
2261 * fullscreen ) separately, so they don't overlap with the video area.
2262 * It doesn't call XFlush.
2265 void vo_xv_draw_colorkey(struct vo
*vo
, int32_t x
, int32_t y
,
2266 int32_t w
, int32_t h
)
2268 struct MPOpts
*opts
= vo
->opts
;
2269 struct vo_x11_state
*x11
= vo
->x11
;
2270 if( x11
->xv_ck_info
.method
== CK_METHOD_MANUALFILL
||
2271 x11
->xv_ck_info
.method
== CK_METHOD_BACKGROUND
)//less tearing than XClearWindow()
2273 XSetForeground(x11
->display
, x11
->vo_gc
, x11
->xv_colorkey
);
2274 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2279 /* draw black bars if needed */
2280 /* TODO! move this to vo_x11_clearwindow_part() */
2283 XSetForeground(x11
->display
, x11
->vo_gc
, 0 );
2284 /* making non-overlap fills, requires 8 checks instead of 4 */
2286 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2288 opts
->vo_screenwidth
, y
);
2290 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2292 x
, opts
->vo_screenheight
);
2293 if (x
+ w
< opts
->vo_screenwidth
)
2294 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2296 opts
->vo_screenwidth
, opts
->vo_screenheight
);
2297 if (y
+ h
< opts
->vo_screenheight
)
2298 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2300 opts
->vo_screenwidth
, opts
->vo_screenheight
);
2304 /** \brief Tests if a valid argument for the ck suboption was given. */
2305 int xv_test_ck( void * arg
)
2307 strarg_t
* strarg
= (strarg_t
*)arg
;
2309 if ( strargcmp( strarg
, "use" ) == 0 ||
2310 strargcmp( strarg
, "set" ) == 0 ||
2311 strargcmp( strarg
, "cur" ) == 0 )
2318 /** \brief Tests if a valid arguments for the ck-method suboption was given. */
2319 int xv_test_ckm( void * arg
)
2321 strarg_t
* strarg
= (strarg_t
*)arg
;
2323 if ( strargcmp( strarg
, "bg" ) == 0 ||
2324 strargcmp( strarg
, "man" ) == 0 ||
2325 strargcmp( strarg
, "auto" ) == 0 )
2334 * \brief Modify the colorkey_handling var according to str
2336 * Checks if a valid pointer ( not NULL ) to the string
2337 * was given. And in that case modifies the colorkey_handling
2338 * var to reflect the requested behaviour.
2339 * If nothing happens the content of colorkey_handling stays
2342 * \param str Pointer to the string or NULL
2345 void xv_setup_colorkeyhandling(struct vo
*vo
, const char *ck_method_str
,
2348 struct vo_x11_state
*x11
= vo
->x11
;
2349 /* check if a valid pointer to the string was passed */
2352 if ( strncmp( ck_str
, "use", 3 ) == 0 )
2354 x11
->xv_ck_info
.source
= CK_SRC_USE
;
2356 else if ( strncmp( ck_str
, "set", 3 ) == 0 )
2358 x11
->xv_ck_info
.source
= CK_SRC_SET
;
2361 /* check if a valid pointer to the string was passed */
2362 if ( ck_method_str
)
2364 if ( strncmp( ck_method_str
, "bg", 2 ) == 0 )
2366 x11
->xv_ck_info
.method
= CK_METHOD_BACKGROUND
;
2368 else if ( strncmp( ck_method_str
, "man", 3 ) == 0 )
2370 x11
->xv_ck_info
.method
= CK_METHOD_MANUALFILL
;
2372 else if ( strncmp( ck_method_str
, "auto", 4 ) == 0 )
2374 x11
->xv_ck_info
.method
= CK_METHOD_AUTOPAINT
;
2381 struct vo_x11_state
*vo_x11_init_state(void)
2383 struct vo_x11_state
*s
= talloc_ptrtype(NULL
, s
);
2384 *s
= (struct vo_x11_state
){
2385 .xv_ck_info
= { CK_METHOD_MANUALFILL
, CK_SRC_CUR
},
2386 .olddecor
= MWM_DECOR_ALL
,
2387 .oldfuncs
= MWM_FUNC_MOVE
| MWM_FUNC_CLOSE
| MWM_FUNC_MINIMIZE
|
2388 MWM_FUNC_MAXIMIZE
| MWM_FUNC_RESIZE
,
2389 .old_gravity
= NorthWestGravity
,