11 #include "x11_common.h"
20 #include "video_out.h"
24 #include "osdep/timer.h"
28 #include <X11/Xutil.h>
29 #include <X11/Xatom.h>
32 #include <X11/extensions/scrnsaver.h>
36 #include <X11/extensions/dpms.h>
40 #include <X11/extensions/Xinerama.h>
44 #include <X11/extensions/xf86vmode.h>
48 #include <X11/XF86keysym.h>
52 #include <X11/extensions/Xv.h>
53 #include <X11/extensions/Xvlib.h>
55 #include "subopt-helper.h"
58 #include "input/input.h"
59 #include "input/mouse.h"
62 #include "gui/interface.h"
66 #define WIN_LAYER_ONBOTTOM 2
67 #define WIN_LAYER_NORMAL 4
68 #define WIN_LAYER_ONTOP 6
69 #define WIN_LAYER_ABOVE_DOCK 10
71 extern int enable_mouse_movements
;
72 int fs_layer
= WIN_LAYER_ABOVE_DOCK
;
74 int stop_xscreensaver
= 0;
76 static int dpms_disabled
= 0;
78 char *mDisplayName
= NULL
;
80 char **vo_fstype_list
;
82 /* 1 means that the WM is metacity (broken as hell) */
83 int metacity_hack
= 0;
86 XF86VidModeModeInfo
**vidmodes
= NULL
;
87 XF86VidModeModeLine modeline
;
90 static int vo_x11_get_fs_type(int supported
);
91 static void saver_off(Display
*);
92 static void saver_on(Display
*);
95 * Sends the EWMH fullscreen state event.
97 * action: could be one of _NET_WM_STATE_REMOVE -- remove state
98 * _NET_WM_STATE_ADD -- add state
99 * _NET_WM_STATE_TOGGLE -- toggle
101 void vo_x11_ewmh_fullscreen(struct vo_x11_state
*x11
, int action
)
103 assert(action
== _NET_WM_STATE_REMOVE
||
104 action
== _NET_WM_STATE_ADD
|| action
== _NET_WM_STATE_TOGGLE
);
106 if (x11
->fs_type
& vo_wm_FULLSCREEN
)
110 /* init X event structure for _NET_WM_FULLSCREEN client message */
111 xev
.xclient
.type
= ClientMessage
;
112 xev
.xclient
.serial
= 0;
113 xev
.xclient
.send_event
= True
;
114 xev
.xclient
.message_type
= XInternAtom(x11
->display
,
115 "_NET_WM_STATE", False
);
116 xev
.xclient
.window
= x11
->window
;
117 xev
.xclient
.format
= 32;
118 xev
.xclient
.data
.l
[0] = action
;
119 xev
.xclient
.data
.l
[1] = XInternAtom(x11
->display
,
120 "_NET_WM_STATE_FULLSCREEN",
122 xev
.xclient
.data
.l
[2] = 0;
123 xev
.xclient
.data
.l
[3] = 0;
124 xev
.xclient
.data
.l
[4] = 0;
126 /* finally send that damn thing */
127 if (!XSendEvent(x11
->display
, DefaultRootWindow(x11
->display
), False
,
128 SubstructureRedirectMask
| SubstructureNotifyMask
,
131 mp_msg(MSGT_VO
, MSGL_ERR
, MSGTR_EwmhFullscreenStateFailed
);
136 static void vo_hidecursor(Display
* disp
, Window win
)
142 const char bm_no_data
[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
145 return; // do not hide if playing on the root window
147 colormap
= DefaultColormap(disp
, DefaultScreen(disp
));
148 if ( !XAllocNamedColor(disp
, colormap
, "black", &black
, &dummy
) )
150 return; // color alloc failed, give up
152 bm_no
= XCreateBitmapFromData(disp
, win
, bm_no_data
, 8, 8);
153 no_ptr
= XCreatePixmapCursor(disp
, bm_no
, bm_no
, &black
, &black
, 0, 0);
154 XDefineCursor(disp
, win
, no_ptr
);
155 XFreeCursor(disp
, no_ptr
);
157 XFreePixmap(disp
, bm_no
);
158 XFreeColors(disp
,colormap
,&black
.pixel
,1,0);
161 static void vo_showcursor(Display
* disp
, Window win
)
165 XDefineCursor(disp
, win
, 0);
168 static int x11_errorhandler(Display
* display
, XErrorEvent
* event
)
173 XGetErrorText(display
, event
->error_code
, (char *) &msg
, MSGLEN
);
175 mp_msg(MSGT_VO
, MSGL_ERR
, "X11 error: %s\n", msg
);
177 mp_msg(MSGT_VO
, MSGL_V
,
178 "Type: %x, display: %p, resourceid: %lx, serial: %lx\n",
179 event
->type
, event
->display
, event
->resourceid
, event
->serial
);
180 mp_msg(MSGT_VO
, MSGL_V
,
181 "Error code: %x, request code: %x, minor code: %x\n",
182 event
->error_code
, event
->request_code
, event
->minor_code
);
185 //exit_player("X11 error");
190 void fstype_help(void)
192 mp_msg(MSGT_VO
, MSGL_INFO
, MSGTR_AvailableFsType
);
193 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FULL_SCREEN_TYPES\n");
195 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "none",
196 "don't set fullscreen window layer");
197 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "layer",
198 "use _WIN_LAYER hint with default layer");
199 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "layer=<0..15>",
200 "use _WIN_LAYER hint with a given layer number");
201 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "netwm",
202 "force NETWM style");
203 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "above",
204 "use _NETWM_STATE_ABOVE hint if available");
205 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "below",
206 "use _NETWM_STATE_BELOW hint if available");
207 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "fullscreen",
208 "use _NETWM_STATE_FULLSCREEN hint if availale");
209 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "stays_on_top",
210 "use _NETWM_STATE_STAYS_ON_TOP hint if available");
211 mp_msg(MSGT_VO
, MSGL_INFO
,
212 "You can also negate the settings with simply putting '-' in the beginning");
213 mp_msg(MSGT_VO
, MSGL_INFO
, "\n");
216 static void fstype_dump(int fstype
)
220 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Current fstype setting honours");
221 if (fstype
& vo_wm_LAYER
)
222 mp_msg(MSGT_VO
, MSGL_V
, " LAYER");
223 if (fstype
& vo_wm_FULLSCREEN
)
224 mp_msg(MSGT_VO
, MSGL_V
, " FULLSCREEN");
225 if (fstype
& vo_wm_STAYS_ON_TOP
)
226 mp_msg(MSGT_VO
, MSGL_V
, " STAYS_ON_TOP");
227 if (fstype
& vo_wm_ABOVE
)
228 mp_msg(MSGT_VO
, MSGL_V
, " ABOVE");
229 if (fstype
& vo_wm_BELOW
)
230 mp_msg(MSGT_VO
, MSGL_V
, " BELOW");
231 mp_msg(MSGT_VO
, MSGL_V
, " X atoms\n");
233 mp_msg(MSGT_VO
, MSGL_V
,
234 "[x11] Current fstype setting doesn't honour any X atoms\n");
237 static int net_wm_support_state_test(struct vo_x11_state
*x11
, Atom atom
)
239 #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; } }
241 NET_WM_STATE_TEST(FULLSCREEN
);
242 NET_WM_STATE_TEST(ABOVE
);
243 NET_WM_STATE_TEST(STAYS_ON_TOP
);
244 NET_WM_STATE_TEST(BELOW
);
248 static int x11_get_property(struct vo_x11_state
*x11
, Atom type
, Atom
** args
,
249 unsigned long *nitems
)
252 unsigned long bytesafter
;
255 XGetWindowProperty(x11
->display
, x11
->rootwin
, type
, 0, 16384, False
,
256 AnyPropertyType
, &type
, &format
, nitems
,
257 &bytesafter
, (unsigned char **) args
)
261 static int vo_wm_detect(struct vo
*vo
)
263 struct vo_x11_state
*x11
= vo
->x11
;
266 unsigned long nitems
;
272 // -- supports layers
273 if (x11_get_property(x11
, x11
->XA_WIN_PROTOCOLS
, &args
, &nitems
))
275 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Detected wm supports layers.\n");
276 for (i
= 0; i
< nitems
; i
++)
278 if (args
[i
] == x11
->XA_WIN_LAYER
)
283 /* metacity is the only window manager I know which reports
284 * supporting only the _WIN_LAYER hint in _WIN_PROTOCOLS.
285 * (what's more support for it is broken) */
289 if (wm
&& (metacity_hack
== 1))
291 // metacity claims to support layers, but it is not the truth :-)
293 mp_msg(MSGT_VO
, MSGL_V
,
294 "[x11] Using workaround for Metacity bugs.\n");
298 if (x11_get_property(x11
, x11
->XA_NET_SUPPORTED
, &args
, &nitems
))
300 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Detected wm supports NetWM.\n");
301 for (i
= 0; i
< nitems
; i
++)
302 wm
|= net_wm_support_state_test(vo
->x11
, args
[i
]);
305 // ugly hack for broken OpenBox _NET_WM_STATE_FULLSCREEN support
306 // (in their implementation it only changes internal window state, nothing more!!!)
307 if (wm
& vo_wm_FULLSCREEN
)
309 if (x11_get_property(x11
, x11
->XA_BLACKBOX_PID
, &args
, &nitems
))
311 mp_msg(MSGT_VO
, MSGL_V
,
312 "[x11] Detected wm is a broken OpenBox.\n");
313 wm
^= vo_wm_FULLSCREEN
;
321 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Unknown wm type...\n");
325 #define XA_INIT(x) x11->XA##x = XInternAtom(x11->display, #x, False)
326 static void init_atoms(struct vo_x11_state
*x11
)
328 XA_INIT(_NET_SUPPORTED
);
329 XA_INIT(_NET_WM_STATE
);
330 XA_INIT(_NET_WM_STATE_FULLSCREEN
);
331 XA_INIT(_NET_WM_STATE_ABOVE
);
332 XA_INIT(_NET_WM_STATE_STAYS_ON_TOP
);
333 XA_INIT(_NET_WM_STATE_BELOW
);
334 XA_INIT(_NET_WM_PID
);
335 XA_INIT(_WIN_PROTOCOLS
);
338 XA_INIT(_BLACKBOX_PID
);
339 XA_INIT(WM_PROTOCOLS
);
340 XA_INIT(WM_DELETE_WINDOW
);
343 void update_xinerama_info(struct vo
*vo
) {
344 struct MPOpts
*opts
= vo
->opts
;
345 int screen
= xinerama_screen
;
346 xinerama_x
= xinerama_y
= 0;
348 if (screen
>= -1 && XineramaIsActive(vo
->x11
->display
))
350 XineramaScreenInfo
*screens
;
353 screens
= XineramaQueryScreens(vo
->x11
->display
, &num_screens
);
354 if (screen
>= num_screens
)
355 screen
= num_screens
- 1;
357 int x
= vo
->dx
+ vo
->dwidth
/ 2;
358 int y
= vo
->dy
+ vo
->dheight
/ 2;
359 for (screen
= num_screens
- 1; screen
> 0; screen
--) {
360 int left
= screens
[screen
].x_org
;
361 int right
= left
+ screens
[screen
].width
;
362 int top
= screens
[screen
].y_org
;
363 int bottom
= top
+ screens
[screen
].height
;
364 if (left
<= x
&& x
<= right
&& top
<= y
&& y
<= bottom
)
370 opts
->vo_screenwidth
= screens
[screen
].width
;
371 opts
->vo_screenheight
= screens
[screen
].height
;
372 xinerama_x
= screens
[screen
].x_org
;
373 xinerama_y
= screens
[screen
].y_org
;
378 aspect_save_screenres(vo
, opts
->vo_screenwidth
, opts
->vo_screenheight
);
381 int vo_init(struct vo
*vo
)
383 struct MPOpts
*opts
= vo
->opts
;
384 struct vo_x11_state
*x11
= vo
->x11
;
389 // char * DisplayName = ":0.0";
390 // Display * mDisplay;
391 XImage
*mXImage
= NULL
;
394 XWindowAttributes attribs
;
398 WinID
= 0; // use root window
400 if (x11
->depthonscreen
)
402 saver_off(x11
->display
);
403 return 1; // already called
406 XSetErrorHandler(x11_errorhandler
);
410 if (!(mDisplayName
= getenv("DISPLAY")))
411 mDisplayName
= strdup(":0.0");
413 dispName
= XDisplayName(mDisplayName
);
416 mp_msg(MSGT_VO
, MSGL_V
, "X11 opening display: %s\n", dispName
);
418 x11
->display
= XOpenDisplay(dispName
);
421 mp_msg(MSGT_VO
, MSGL_ERR
,
422 "vo: couldn't open the X11 display (%s)!\n", dispName
);
425 x11
->screen
= DefaultScreen(x11
->display
); // screen ID
426 x11
->rootwin
= RootWindow(x11
->display
, x11
->screen
); // root window ID
434 XF86VidModeGetModeLine(x11
->display
, x11
->screen
, &clock
, &modeline
);
435 if (!opts
->vo_screenwidth
)
436 opts
->vo_screenwidth
= modeline
.hdisplay
;
437 if (!opts
->vo_screenheight
)
438 opts
->vo_screenheight
= modeline
.vdisplay
;
442 if (!opts
->vo_screenwidth
)
443 opts
->vo_screenwidth
= DisplayWidth(x11
->display
, x11
->screen
);
444 if (!opts
->vo_screenheight
)
445 opts
->vo_screenheight
= DisplayHeight(x11
->display
, x11
->screen
);
447 // get color depth (from root window, or the best visual):
448 XGetWindowAttributes(x11
->display
, x11
->rootwin
, &attribs
);
449 depth
= attribs
.depth
;
451 if (depth
!= 15 && depth
!= 16 && depth
!= 24 && depth
!= 32)
455 depth
= vo_find_depth_from_visuals(x11
->display
, x11
->screen
, &visual
);
457 mXImage
= XCreateImage(x11
->display
, visual
, depth
, ZPixmap
,
458 0, NULL
, 1, 1, 8, 1);
461 XGetImage(x11
->display
, x11
->rootwin
, 0, 0, 1, 1, AllPlanes
, ZPixmap
);
463 x11
->depthonscreen
= depth
; // display depth on screen
465 // get bits/pixel from XImage structure:
472 * for the depth==24 case, the XImage structures might use
473 * 24 or 32 bits of data per pixel. The x11->depthonscreen
474 * field stores the amount of data per pixel in the
477 * Maybe we should rename vo_depthonscreen to (or add) vo_bpp?
479 bpp
= mXImage
->bits_per_pixel
;
480 if ((x11
->depthonscreen
+ 7) / 8 != (bpp
+ 7) / 8)
481 x11
->depthonscreen
= bpp
; // by A'rpi
483 mXImage
->red_mask
| mXImage
->green_mask
| mXImage
->blue_mask
;
484 mp_msg(MSGT_VO
, MSGL_V
,
485 "vo: X11 color mask: %X (R:%lX G:%lX B:%lX)\n", mask
,
486 mXImage
->red_mask
, mXImage
->green_mask
, mXImage
->blue_mask
);
487 XDestroyImage(mXImage
);
489 if (((x11
->depthonscreen
+ 7) / 8) == 2)
492 x11
->depthonscreen
= 15;
493 else if (mask
== 0xFFFF)
494 x11
->depthonscreen
= 16;
496 // XCloseDisplay( mDisplay );
497 /* slightly improved local display detection AST */
498 if (strncmp(dispName
, "unix:", 5) == 0)
500 else if (strncmp(dispName
, "localhost:", 10) == 0)
502 if (*dispName
== ':' && atoi(dispName
+ 1) < 10)
503 x11
->display_is_local
= 1;
505 x11
->display_is_local
= 0;
506 mp_msg(MSGT_VO
, MSGL_V
,
507 "vo: X11 running at %dx%d with depth %d and %d bpp (\"%s\" => %s display)\n",
508 opts
->vo_screenwidth
, opts
->vo_screenheight
, depth
, x11
->depthonscreen
,
509 dispName
, x11
->display_is_local
? "local" : "remote");
511 x11
->wm_type
= vo_wm_detect(vo
);
513 x11
->fs_type
= vo_x11_get_fs_type(x11
->wm_type
);
515 fstype_dump(x11
->fs_type
);
517 saver_off(x11
->display
);
521 void vo_uninit(struct vo_x11_state
*x11
)
525 mp_msg(MSGT_VO
, MSGL_V
,
526 "vo: x11 uninit called but X11 not initialized..\n");
529 // if( !vo_depthonscreen ) return;
530 mp_msg(MSGT_VO
, MSGL_V
, "vo: uninit ...\n");
531 XSetErrorHandler(NULL
);
532 XCloseDisplay(x11
->display
);
533 x11
->depthonscreen
= 0;
538 #include "osdep/keycodes.h"
541 #ifdef XF86XK_AudioPause
542 static void vo_x11_putkey_ext(struct vo
*vo
, int keysym
)
544 struct mp_fifo
*f
= vo
->key_fifo
;
547 case XF86XK_AudioPause
:
548 mplayer_put_key(f
, KEY_PAUSE
);
550 case XF86XK_AudioStop
:
551 mplayer_put_key(f
, KEY_STOP
);
553 case XF86XK_AudioPrev
:
554 mplayer_put_key(f
, KEY_PREV
);
556 case XF86XK_AudioNext
:
557 mplayer_put_key(f
, KEY_NEXT
);
559 case XF86XK_AudioLowerVolume
:
560 mplayer_put_key(f
, KEY_VOLUME_DOWN
);
562 case XF86XK_AudioRaiseVolume
:
563 mplayer_put_key(f
, KEY_VOLUME_UP
);
571 void vo_x11_putkey(struct vo
*vo
, int key
)
573 struct mp_fifo
*f
= vo
->key_fifo
;
577 mplayer_put_key(f
, KEY_LEFT
);
580 mplayer_put_key(f
, KEY_RIGHT
);
583 mplayer_put_key(f
, KEY_UP
);
586 mplayer_put_key(f
, KEY_DOWN
);
589 mplayer_put_key(f
, ' ');
592 mplayer_put_key(f
, KEY_ESC
);
595 mplayer_put_key(f
, KEY_TAB
);
598 mplayer_put_key(f
, KEY_ENTER
);
601 mplayer_put_key(f
, KEY_BS
);
604 mplayer_put_key(f
, KEY_DELETE
);
607 mplayer_put_key(f
, KEY_INSERT
);
610 mplayer_put_key(f
, KEY_HOME
);
613 mplayer_put_key(f
, KEY_END
);
616 mplayer_put_key(f
, KEY_PAGE_UP
);
619 mplayer_put_key(f
, KEY_PAGE_DOWN
);
622 mplayer_put_key(f
, KEY_F
+ 1);
625 mplayer_put_key(f
, KEY_F
+ 2);
628 mplayer_put_key(f
, KEY_F
+ 3);
631 mplayer_put_key(f
, KEY_F
+ 4);
634 mplayer_put_key(f
, KEY_F
+ 5);
637 mplayer_put_key(f
, KEY_F
+ 6);
640 mplayer_put_key(f
, KEY_F
+ 7);
643 mplayer_put_key(f
, KEY_F
+ 8);
646 mplayer_put_key(f
, KEY_F
+ 9);
649 mplayer_put_key(f
, KEY_F
+ 10);
652 mplayer_put_key(f
, KEY_F
+ 11);
655 mplayer_put_key(f
, KEY_F
+ 12);
659 mplayer_put_key(f
, '-');
663 mplayer_put_key(f
, '+');
667 mplayer_put_key(f
, '*');
671 mplayer_put_key(f
, '/');
674 mplayer_put_key(f
, '<');
677 mplayer_put_key(f
, '>');
680 mplayer_put_key(f
, KEY_KP0
);
684 mplayer_put_key(f
, KEY_KP1
);
688 mplayer_put_key(f
, KEY_KP2
);
692 mplayer_put_key(f
, KEY_KP3
);
696 mplayer_put_key(f
, KEY_KP4
);
700 mplayer_put_key(f
, KEY_KP5
);
704 mplayer_put_key(f
, KEY_KP6
);
708 mplayer_put_key(f
, KEY_KP7
);
712 mplayer_put_key(f
, KEY_KP8
);
716 mplayer_put_key(f
, KEY_KP9
);
719 mplayer_put_key(f
, KEY_KPDEC
);
722 mplayer_put_key(f
, KEY_KPINS
);
725 mplayer_put_key(f
, KEY_KPDEL
);
728 mplayer_put_key(f
, KEY_KPENTER
);
731 mplayer_put_key(f
, '`');
734 mplayer_put_key(f
, '~');
737 mplayer_put_key(f
, '!');
740 mplayer_put_key(f
, '@');
743 mplayer_put_key(f
, '#');
746 mplayer_put_key(f
, '$');
749 mplayer_put_key(f
, '%');
752 mplayer_put_key(f
, '^');
755 mplayer_put_key(f
, '&');
758 mplayer_put_key(f
, '(');
761 mplayer_put_key(f
, ')');
764 mplayer_put_key(f
, '_');
767 mplayer_put_key(f
, '{');
770 mplayer_put_key(f
, '}');
773 mplayer_put_key(f
, ':');
776 mplayer_put_key(f
, ';');
779 mplayer_put_key(f
, '\"');
782 mplayer_put_key(f
, '\'');
785 mplayer_put_key(f
, ',');
788 mplayer_put_key(f
, '.');
791 mplayer_put_key(f
, '?');
794 mplayer_put_key(f
, '\\');
797 mplayer_put_key(f
, '|');
800 mplayer_put_key(f
, '=');
803 mplayer_put_key(f
, '[');
806 mplayer_put_key(f
, ']');
811 if ((key
>= 'a' && key
<= 'z') || (key
>= 'A' && key
<= 'Z') ||
812 (key
>= '0' && key
<= '9'))
813 mplayer_put_key(f
, key
);
819 // ----- Motif header: -------
821 #define MWM_HINTS_FUNCTIONS (1L << 0)
822 #define MWM_HINTS_DECORATIONS (1L << 1)
823 #define MWM_HINTS_INPUT_MODE (1L << 2)
824 #define MWM_HINTS_STATUS (1L << 3)
826 #define MWM_FUNC_ALL (1L << 0)
827 #define MWM_FUNC_RESIZE (1L << 1)
828 #define MWM_FUNC_MOVE (1L << 2)
829 #define MWM_FUNC_MINIMIZE (1L << 3)
830 #define MWM_FUNC_MAXIMIZE (1L << 4)
831 #define MWM_FUNC_CLOSE (1L << 5)
833 #define MWM_DECOR_ALL (1L << 0)
834 #define MWM_DECOR_BORDER (1L << 1)
835 #define MWM_DECOR_RESIZEH (1L << 2)
836 #define MWM_DECOR_TITLE (1L << 3)
837 #define MWM_DECOR_MENU (1L << 4)
838 #define MWM_DECOR_MINIMIZE (1L << 5)
839 #define MWM_DECOR_MAXIMIZE (1L << 6)
841 #define MWM_INPUT_MODELESS 0
842 #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
843 #define MWM_INPUT_SYSTEM_MODAL 2
844 #define MWM_INPUT_FULL_APPLICATION_MODAL 3
845 #define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL
847 #define MWM_TEAROFF_WINDOW (1L<<0)
858 static MotifWmHints vo_MotifWmHints
;
859 static Atom vo_MotifHints
= None
;
861 void vo_x11_decoration(struct vo
*vo
, int d
)
863 struct vo_x11_state
*x11
= vo
->x11
;
866 unsigned long mn
, mb
;
873 XSetTransientForHint(x11
->display
, x11
->window
,
874 RootWindow(x11
->display
, x11
->screen
));
877 vo_MotifHints
= XInternAtom(x11
->display
, "_MOTIF_WM_HINTS", 0);
878 if (vo_MotifHints
!= None
)
882 MotifWmHints
*mhints
= NULL
;
884 XGetWindowProperty(x11
->display
, x11
->window
,
885 vo_MotifHints
, 0, 20, False
,
886 vo_MotifHints
, &mtype
, &mformat
, &mn
,
887 &mb
, (unsigned char **) &mhints
);
890 if (mhints
->flags
& MWM_HINTS_DECORATIONS
)
891 x11
->olddecor
= mhints
->decorations
;
892 if (mhints
->flags
& MWM_HINTS_FUNCTIONS
)
893 x11
->oldfuncs
= mhints
->functions
;
898 memset(&vo_MotifWmHints
, 0, sizeof(MotifWmHints
));
899 vo_MotifWmHints
.flags
=
900 MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
903 vo_MotifWmHints
.functions
= x11
->oldfuncs
;
907 vo_MotifWmHints
.decorations
=
908 d
| ((vo_fsmode
& 2) ? 0 : MWM_DECOR_MENU
);
910 vo_MotifWmHints
.decorations
=
911 d
| ((vo_fsmode
& 2) ? MWM_DECOR_MENU
: 0);
913 XChangeProperty(x11
->display
, x11
->window
, vo_MotifHints
,
916 (unsigned char *) &vo_MotifWmHints
,
917 (vo_fsmode
& 4) ? 4 : 5);
921 void vo_x11_classhint(struct vo
*vo
, Window window
, char *name
)
923 struct vo_x11_state
*x11
= vo
->x11
;
925 pid_t pid
= getpid();
927 wmClass
.res_name
= name
;
928 wmClass
.res_class
= "MPlayer";
929 XSetClassHint(x11
->display
, window
, &wmClass
);
930 XChangeProperty(x11
->display
, window
, x11
->XA_NET_WM_PID
, XA_CARDINAL
,
931 32, PropModeReplace
, (unsigned char *) &pid
, 1);
934 void vo_x11_uninit(struct vo
*vo
)
936 struct vo_x11_state
*x11
= vo
->x11
;
937 saver_on(x11
->display
);
938 if (x11
->window
!= None
)
939 vo_showcursor(x11
->display
, x11
->window
);
943 XFreeGC(vo
->x11
->display
, x11
->f_gc
);
947 /* destroy window only if it's not controlled by the GUI */
953 XSetBackground(vo
->x11
->display
, x11
->vo_gc
, 0);
954 XFreeGC(vo
->x11
->display
, x11
->vo_gc
);
957 if (x11
->window
!= None
)
959 XClearWindow(x11
->display
, x11
->window
);
964 XUnmapWindow(x11
->display
, x11
->window
);
965 XDestroyWindow(x11
->display
, x11
->window
);
968 XNextEvent(x11
->display
, &xev
);
970 while (xev
.type
!= DestroyNotify
971 || xev
.xdestroywindow
.event
!= x11
->window
);
976 x11
->vo_old_width
= x11
->vo_old_height
= 0;
980 int vo_x11_check_events(struct vo
*vo
)
982 struct vo_x11_state
*x11
= vo
->x11
;
983 struct MPOpts
*opts
= vo
->opts
;
984 Display
*display
= vo
->x11
->display
;
990 // unsigned long vo_KeyTable[512];
992 if ((x11
->vo_mouse_autohide
) && x11
->mouse_waiting_hide
&&
993 (GetTimerMS() - x11
->mouse_timer
>= 1000)) {
994 vo_hidecursor(display
, x11
->window
);
995 x11
->mouse_waiting_hide
= 0;
998 while (XPending(display
))
1000 XNextEvent(display
, &Event
);
1004 guiGetEvent(0, (char *) &Event
);
1005 if (x11
->window
!= Event
.xany
.window
)
1009 // printf("\rEvent.type=%X \n",Event.type);
1013 ret
|= VO_EVENT_EXPOSE
;
1015 case ConfigureNotify
:
1016 // if (!vo_fs && (Event.xconfigure.width == opts->vo_screenwidth || Event.xconfigure.height == opts->vo_screenheight)) break;
1017 // if (vo_fs && Event.xconfigure.width != opts->vo_screenwidth && Event.xconfigure.height != opts->vo_screenheight) break;
1018 if (x11
->window
== None
)
1020 vo
->dwidth
= Event
.xconfigure
.width
;
1021 vo
->dheight
= Event
.xconfigure
.height
;
1023 /* when resizing, x and y are zero :( */
1024 vo
->dx
= Event
.xconfigure
.x
;
1025 vo
->dy
= Event
.xconfigure
.y
;
1032 XGetGeometry(display
, x11
->window
, &root
, &foo
, &foo
,
1033 &foo
/*width */ , &foo
/*height */ , &foo
,
1035 XTranslateCoordinates(display
, x11
->window
, root
, 0, 0,
1036 &vo
->dx
, &vo
->dy
, &win
);
1039 ret
|= VO_EVENT_RESIZE
;
1046 if ( use_gui
) { break; }
1049 XLookupString(&Event
.xkey
, buf
, sizeof(buf
), &keySym
,
1050 &x11
->compose_status
);
1051 #ifdef XF86XK_AudioPause
1052 vo_x11_putkey_ext(vo
, keySym
);
1055 ((keySym
& 0xff00) !=
1056 0 ? ((keySym
& 0x00ff) + 256) : (keySym
));
1057 vo_x11_putkey(vo
, key
);
1058 ret
|= VO_EVENT_KEYPRESS
;
1062 if(enable_mouse_movements
)
1065 sprintf(cmd_str
,"set_mouse_pos %i %i",Event
.xmotion
.x
, Event
.xmotion
.y
);
1066 mp_input_queue_cmd(vo
->input_ctx
,
1067 mp_input_parse_cmd(cmd_str
));
1070 if (x11
->vo_mouse_autohide
)
1072 vo_showcursor(display
, x11
->window
);
1073 x11
->mouse_waiting_hide
= 1;
1074 x11
->mouse_timer
= GetTimerMS();
1078 if (x11
->vo_mouse_autohide
)
1080 vo_showcursor(display
, x11
->window
);
1081 x11
->mouse_waiting_hide
= 1;
1082 x11
->mouse_timer
= GetTimerMS();
1085 // Ignore mouse button 1-3 under GUI.
1086 if (use_gui
&& (Event
.xbutton
.button
>= 1)
1087 && (Event
.xbutton
.button
<= 3))
1090 mplayer_put_key(vo
->key_fifo
,
1091 (MOUSE_BTN0
+ Event
.xbutton
.button
- 1)
1095 if (x11
->vo_mouse_autohide
)
1097 vo_showcursor(display
, x11
->window
);
1098 x11
->mouse_waiting_hide
= 1;
1099 x11
->mouse_timer
= GetTimerMS();
1102 // Ignore mouse button 1-3 under GUI.
1103 if (use_gui
&& (Event
.xbutton
.button
>= 1)
1104 && (Event
.xbutton
.button
<= 3))
1107 mplayer_put_key(vo
->key_fifo
,
1108 MOUSE_BTN0
+ Event
.xbutton
.button
- 1);
1110 case PropertyNotify
:
1113 XGetAtomName(display
, Event
.xproperty
.atom
);
1118 // fprintf(stderr,"[ws] PropertyNotify ( 0x%x ) %s ( 0x%x )\n",vo_window,name,Event.xproperty.atom );
1124 x11
->vo_hint
.win_gravity
= x11
->old_gravity
;
1125 XSetWMNormalHints(display
, x11
->window
, &x11
->vo_hint
);
1129 if (Event
.xclient
.message_type
== x11
->XAWM_PROTOCOLS
&&
1130 Event
.xclient
.data
.l
[0] == x11
->XAWM_DELETE_WINDOW
)
1131 mplayer_put_key(vo
->key_fifo
, KEY_CLOSE_WIN
);
1139 * \brief sets the size and position of the non-fullscreen window.
1141 static void vo_x11_nofs_sizepos(struct vo
*vo
, int x
, int y
,
1142 int width
, int height
)
1144 struct vo_x11_state
*x11
= vo
->x11
;
1145 vo_x11_sizehint(vo
, x
, y
, width
, height
, 0);
1149 x11
->vo_old_width
= width
;
1150 x11
->vo_old_height
= height
;
1155 vo
->dheight
= height
;
1156 XMoveResizeWindow(vo
->x11
->display
, vo
->x11
->window
, x
, y
, width
, height
);
1160 void vo_x11_sizehint(struct vo
*vo
, int x
, int y
, int width
, int height
, int max
)
1162 struct vo_x11_state
*x11
= vo
->x11
;
1163 x11
->vo_hint
.flags
= 0;
1166 x11
->vo_hint
.flags
|= PAspect
;
1167 x11
->vo_hint
.min_aspect
.x
= width
;
1168 x11
->vo_hint
.min_aspect
.y
= height
;
1169 x11
->vo_hint
.max_aspect
.x
= width
;
1170 x11
->vo_hint
.max_aspect
.y
= height
;
1173 x11
->vo_hint
.flags
|= PPosition
| PSize
;
1176 x11
->vo_hint
.width
= width
;
1177 x11
->vo_hint
.height
= height
;
1180 x11
->vo_hint
.flags
|= PMaxSize
;
1181 x11
->vo_hint
.max_width
= width
;
1182 x11
->vo_hint
.max_height
= height
;
1185 x11
->vo_hint
.max_width
= 0;
1186 x11
->vo_hint
.max_height
= 0;
1189 // Set minimum height/width to 4 to avoid off-by-one errors
1190 // and because mga_vid requires a minimal size of 4 pixels.
1191 x11
->vo_hint
.flags
|= PMinSize
;
1192 x11
->vo_hint
.min_width
= x11
->vo_hint
.min_height
= 4;
1194 x11
->vo_hint
.flags
|= PWinGravity
;
1195 x11
->vo_hint
.win_gravity
= StaticGravity
;
1196 XSetWMNormalHints(x11
->display
, x11
->window
, &x11
->vo_hint
);
1199 static int vo_x11_get_gnome_layer(struct vo_x11_state
*x11
, Window win
)
1203 unsigned long nitems
;
1204 unsigned long bytesafter
;
1205 unsigned short *args
= NULL
;
1207 if (XGetWindowProperty(x11
->display
, win
, x11
->XA_WIN_LAYER
, 0, 16384,
1208 False
, AnyPropertyType
, &type
, &format
, &nitems
,
1210 (unsigned char **) &args
) == Success
1211 && nitems
> 0 && args
)
1213 mp_msg(MSGT_VO
, MSGL_V
, "[x11] original window layer is %d.\n",
1217 return WIN_LAYER_NORMAL
;
1221 static Window
vo_x11_create_smooth_window(struct vo_x11_state
*x11
, Window mRoot
,
1222 Visual
* vis
, int x
, int y
,
1223 unsigned int width
, unsigned int height
,
1224 int depth
, Colormap col_map
)
1226 unsigned long xswamask
= CWBackingStore
| CWBorderPixel
;
1227 XSetWindowAttributes xswa
;
1230 if (col_map
!= CopyFromParent
)
1232 xswa
.colormap
= col_map
;
1233 xswamask
|= CWColormap
;
1235 xswa
.background_pixel
= 0;
1236 xswa
.border_pixel
= 0;
1237 xswa
.backing_store
= Always
;
1238 xswa
.bit_gravity
= StaticGravity
;
1241 XCreateWindow(x11
->display
, x11
->rootwin
, x
, y
, width
, height
, 0, depth
,
1242 CopyFromParent
, vis
, xswamask
, &xswa
);
1243 XSetWMProtocols(x11
->display
, ret_win
, &x11
->XAWM_DELETE_WINDOW
, 1);
1245 x11
->f_gc
= XCreateGC(x11
->display
, ret_win
, 0, 0);
1246 XSetForeground(x11
->display
, x11
->f_gc
, 0);
1252 * \brief create and setup a window suitable for display
1253 * \param vis Visual to use for creating the window
1254 * \param x x position of window
1255 * \param y y position of window
1256 * \param width width of window
1257 * \param height height of window
1258 * \param flags flags for window creation.
1259 * Only VOFLAG_FULLSCREEN is supported so far.
1260 * \param col_map Colourmap for window or CopyFromParent if a specific colormap isn't needed
1261 * \param classname name to use for the classhint
1262 * \param title title for the window
1264 * This also does the grunt-work like setting Window Manager hints etc.
1265 * If vo_window is already set it just moves and resizes it.
1267 void vo_x11_create_vo_window(struct vo
*vo
, XVisualInfo
*vis
, int x
, int y
,
1268 unsigned int width
, unsigned int height
, int flags
,
1270 const char *classname
, const char *title
)
1272 struct MPOpts
*opts
= vo
->opts
;
1273 struct vo_x11_state
*x11
= vo
->x11
;
1274 Display
*mDisplay
= vo
->x11
->display
;
1275 if (x11
->window
== None
) {
1280 vo
->dheight
= height
;
1281 x11
->window
= vo_x11_create_smooth_window(x11
, x11
->rootwin
, vis
->visual
,
1282 x
, y
, width
, height
, vis
->depth
, col_map
);
1283 vo_x11_classhint(vo
, x11
->window
, classname
);
1284 XStoreName(mDisplay
, x11
->window
, title
);
1285 vo_hidecursor(mDisplay
, x11
->window
);
1286 XSelectInput(mDisplay
, x11
->window
, StructureNotifyMask
);
1287 hint
.x
= x
; hint
.y
= y
;
1288 hint
.width
= width
; hint
.height
= height
;
1289 hint
.flags
= PPosition
| PSize
;
1290 XSetStandardProperties(mDisplay
, x11
->window
, title
, title
, None
, NULL
, 0, &hint
);
1291 vo_x11_sizehint(vo
, x
, y
, width
, height
, 0);
1293 XMapWindow(mDisplay
, x11
->window
);
1294 XClearWindow(mDisplay
, x11
->window
);
1297 XNextEvent(mDisplay
, &xev
);
1298 } while (xev
.type
!= MapNotify
|| xev
.xmap
.event
!= x11
->window
);
1299 XSelectInput(mDisplay
, x11
->window
, NoEventMask
);
1300 XSync(mDisplay
, False
);
1301 vo_x11_selectinput_witherr(mDisplay
, x11
->window
,
1302 StructureNotifyMask
| KeyPressMask
| PointerMotionMask
|
1303 ButtonPressMask
| ButtonReleaseMask
| ExposureMask
);
1305 if (opts
->vo_ontop
) vo_x11_setlayer(vo
, x11
->window
, opts
->vo_ontop
);
1306 vo_x11_nofs_sizepos(vo
, vo
->dx
, vo
->dy
, width
, height
);
1307 if (!!vo_fs
!= !!(flags
& VOFLAG_FULLSCREEN
))
1308 vo_x11_fullscreen(vo
);
1311 void vo_x11_clearwindow_part(struct vo
*vo
, Window vo_window
,
1312 int img_width
, int img_height
, int use_fs
)
1314 struct vo_x11_state
*x11
= vo
->x11
;
1315 struct MPOpts
*opts
= vo
->opts
;
1316 Display
*mDisplay
= vo
->x11
->display
;
1317 int u_dheight
, u_dwidth
, left_ov
, left_ov2
;
1322 u_dheight
= use_fs
? opts
->vo_screenheight
: vo
->dheight
;
1323 u_dwidth
= use_fs
? opts
->vo_screenwidth
: vo
->dwidth
;
1324 if ((u_dheight
<= img_height
) && (u_dwidth
<= img_width
))
1327 left_ov
= (u_dheight
- img_height
) / 2;
1328 left_ov2
= (u_dwidth
- img_width
) / 2;
1330 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, 0, 0, u_dwidth
, left_ov
);
1331 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, 0, u_dheight
- left_ov
- 1,
1332 u_dwidth
, left_ov
+ 1);
1334 if (u_dwidth
> img_width
)
1336 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, 0, left_ov
, left_ov2
,
1338 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, u_dwidth
- left_ov2
- 1,
1339 left_ov
, left_ov2
+ 1, img_height
);
1345 void vo_x11_clearwindow(struct vo
*vo
, Window vo_window
)
1347 struct vo_x11_state
*x11
= vo
->x11
;
1348 struct MPOpts
*opts
= vo
->opts
;
1351 XFillRectangle(x11
->display
, vo_window
, x11
->f_gc
, 0, 0,
1352 opts
->vo_screenwidth
, opts
->vo_screenheight
);
1354 XFlush(x11
->display
);
1358 void vo_x11_setlayer(struct vo
*vo
, Window vo_window
, int layer
)
1360 struct vo_x11_state
*x11
= vo
->x11
;
1364 if (x11
->fs_type
& vo_wm_LAYER
)
1366 XClientMessageEvent xev
;
1368 if (!x11
->orig_layer
)
1369 x11
->orig_layer
= vo_x11_get_gnome_layer(x11
, vo_window
);
1371 memset(&xev
, 0, sizeof(xev
));
1372 xev
.type
= ClientMessage
;
1373 xev
.display
= x11
->display
;
1374 xev
.window
= vo_window
;
1375 xev
.message_type
= x11
->XA_WIN_LAYER
;
1377 xev
.data
.l
[0] = layer
? fs_layer
: x11
->orig_layer
; // if not fullscreen, stay on default layer
1378 xev
.data
.l
[1] = CurrentTime
;
1379 mp_msg(MSGT_VO
, MSGL_V
,
1380 "[x11] Layered style stay on top (layer %ld).\n",
1382 XSendEvent(x11
->display
, x11
->rootwin
, False
, SubstructureNotifyMask
,
1384 } else if (x11
->fs_type
& vo_wm_NETWM
)
1386 XClientMessageEvent xev
;
1389 memset(&xev
, 0, sizeof(xev
));
1390 xev
.type
= ClientMessage
;
1391 xev
.message_type
= x11
->XA_NET_WM_STATE
;
1392 xev
.display
= x11
->display
;
1393 xev
.window
= vo_window
;
1395 xev
.data
.l
[0] = layer
;
1397 if (x11
->fs_type
& vo_wm_STAYS_ON_TOP
)
1398 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_STAYS_ON_TOP
;
1399 else if (x11
->fs_type
& vo_wm_ABOVE
)
1400 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_ABOVE
;
1401 else if (x11
->fs_type
& vo_wm_FULLSCREEN
)
1402 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_FULLSCREEN
;
1403 else if (x11
->fs_type
& vo_wm_BELOW
)
1404 // This is not fallback. We can safely assume that the situation
1405 // where only NETWM_STATE_BELOW is supported doesn't exist.
1406 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_BELOW
;
1408 XSendEvent(x11
->display
, x11
->rootwin
, False
, SubstructureRedirectMask
,
1410 state
= XGetAtomName(x11
->display
, xev
.data
.l
[1]);
1411 mp_msg(MSGT_VO
, MSGL_V
,
1412 "[x11] NET style stay on top (layer %d). Using state %s.\n",
1418 static int vo_x11_get_fs_type(int supported
)
1421 int type
= supported
;
1426 for (i
= 0; vo_fstype_list
[i
]; i
++)
1429 char *arg
= vo_fstype_list
[i
];
1431 if (vo_fstype_list
[i
][0] == '-')
1434 arg
= vo_fstype_list
[i
] + 1;
1437 if (!strncmp(arg
, "layer", 5))
1439 if (!neg
&& (arg
[5] == '='))
1441 char *endptr
= NULL
;
1442 int layer
= strtol(vo_fstype_list
[i
] + 6, &endptr
, 10);
1444 if (endptr
&& *endptr
== '\0' && layer
>= 0
1449 type
&= ~vo_wm_LAYER
;
1451 type
|= vo_wm_LAYER
;
1452 } else if (!strcmp(arg
, "above"))
1455 type
&= ~vo_wm_ABOVE
;
1457 type
|= vo_wm_ABOVE
;
1458 } else if (!strcmp(arg
, "fullscreen"))
1461 type
&= ~vo_wm_FULLSCREEN
;
1463 type
|= vo_wm_FULLSCREEN
;
1464 } else if (!strcmp(arg
, "stays_on_top"))
1467 type
&= ~vo_wm_STAYS_ON_TOP
;
1469 type
|= vo_wm_STAYS_ON_TOP
;
1470 } else if (!strcmp(arg
, "below"))
1473 type
&= ~vo_wm_BELOW
;
1475 type
|= vo_wm_BELOW
;
1476 } else if (!strcmp(arg
, "netwm"))
1479 type
&= ~vo_wm_NETWM
;
1481 type
|= vo_wm_NETWM
;
1482 } else if (!strcmp(arg
, "none"))
1490 void vo_x11_fullscreen(struct vo
*vo
)
1492 struct MPOpts
*opts
= vo
->opts
;
1493 struct vo_x11_state
*x11
= vo
->x11
;
1496 if (WinID
>= 0 || x11
->fs_flip
)
1502 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1506 w
= x11
->vo_old_width
;
1507 h
= x11
->vo_old_height
;
1510 vo_x11_ewmh_fullscreen(x11
, _NET_WM_STATE_REMOVE
); // removes fullscreen state if wm supports EWMH
1515 vo_x11_ewmh_fullscreen(x11
, _NET_WM_STATE_ADD
); // sends fullscreen state to be added if wm supports EWMH
1518 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1520 x11
->vo_old_x
= vo
->dx
;
1521 x11
->vo_old_y
= vo
->dy
;
1522 x11
->vo_old_width
= vo
->dwidth
;
1523 x11
->vo_old_height
= vo
->dheight
;
1525 update_xinerama_info(vo
);
1528 w
= opts
->vo_screenwidth
;
1529 h
= opts
->vo_screenheight
;
1534 XGetWMNormalHints(x11
->display
, x11
->window
, &x11
->vo_hint
, &dummy
);
1535 if (!(x11
->vo_hint
.flags
& PWinGravity
))
1536 x11
->old_gravity
= NorthWestGravity
;
1538 x11
->old_gravity
= x11
->vo_hint
.win_gravity
;
1540 if (x11
->wm_type
== 0 && !(vo_fsmode
& 16))
1542 XUnmapWindow(x11
->display
, x11
->window
); // required for MWM
1543 XWithdrawWindow(x11
->display
, x11
->window
, x11
->screen
);
1547 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1549 vo_x11_decoration(vo
, (vo_fs
) ? 0 : 1);
1550 vo_x11_sizehint(vo
, x
, y
, w
, h
, 0);
1551 vo_x11_setlayer(vo
, x11
->window
, vo_fs
);
1554 XMoveResizeWindow(x11
->display
, x11
->window
, x
, y
, w
, h
);
1556 /* some WMs lose ontop after fullscreen */
1557 if ((!(vo_fs
)) & opts
->vo_ontop
)
1558 vo_x11_setlayer(vo
, x11
->window
, opts
->vo_ontop
);
1560 XMapRaised(x11
->display
, x11
->window
);
1561 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // some WMs change window pos on map
1562 XMoveResizeWindow(x11
->display
, x11
->window
, x
, y
, w
, h
);
1563 XRaiseWindow(x11
->display
, x11
->window
);
1564 XFlush(x11
->display
);
1567 void vo_x11_ontop(struct vo
*vo
)
1569 struct MPOpts
*opts
= vo
->opts
;
1570 opts
->vo_ontop
= !opts
->vo_ontop
;
1572 vo_x11_setlayer(vo
, vo
->x11
->window
, opts
->vo_ontop
);
1576 * XScreensaver stuff
1579 static int screensaver_off
;
1580 static unsigned int time_last
;
1582 void xscreensaver_heartbeat(struct vo_x11_state
*x11
)
1584 unsigned int time
= GetTimerMS();
1586 if (x11
->display
&& screensaver_off
&& (time
- time_last
) > 30000)
1590 XResetScreenSaver(x11
->display
);
1594 static int xss_suspend(Display
*mDisplay
, Bool suspend
)
1599 int event
, error
, major
, minor
;
1600 if (XScreenSaverQueryExtension(mDisplay
, &event
, &error
) != True
||
1601 XScreenSaverQueryVersion(mDisplay
, &major
, &minor
) != True
)
1603 if (major
< 1 || major
== 1 && minor
< 1)
1605 XScreenSaverSuspend(mDisplay
, suspend
);
1611 * End of XScreensaver stuff
1614 static void saver_on(Display
* mDisplay
)
1617 if (!screensaver_off
)
1619 screensaver_off
= 0;
1620 if (xss_suspend(mDisplay
, False
))
1626 if (DPMSQueryExtension(mDisplay
, ¬hing
, ¬hing
))
1628 if (!DPMSEnable(mDisplay
))
1629 { // restoring power saving settings
1630 mp_msg(MSGT_VO
, MSGL_WARN
, "DPMS not available?\n");
1633 // DPMS does not seem to be enabled unless we call DPMSInfo
1637 DPMSForceLevel(mDisplay
, DPMSModeOn
);
1638 DPMSInfo(mDisplay
, &state
, &onoff
);
1641 mp_msg(MSGT_VO
, MSGL_V
,
1642 "Successfully enabled DPMS\n");
1645 mp_msg(MSGT_VO
, MSGL_WARN
, "Could not enable DPMS\n");
1654 static void saver_off(Display
* mDisplay
)
1658 if (screensaver_off
)
1660 screensaver_off
= 1;
1661 if (xss_suspend(mDisplay
, True
))
1664 if (DPMSQueryExtension(mDisplay
, ¬hing
, ¬hing
))
1669 DPMSInfo(mDisplay
, &state
, &onoff
);
1674 mp_msg(MSGT_VO
, MSGL_V
, "Disabling DPMS\n");
1676 stat
= DPMSDisable(mDisplay
); // monitor powersave off
1677 mp_msg(MSGT_VO
, MSGL_V
, "DPMSDisable stat: %d\n", stat
);
1683 static XErrorHandler old_handler
= NULL
;
1684 static int selectinput_err
= 0;
1685 static int x11_selectinput_errorhandler(Display
* display
,
1686 XErrorEvent
* event
)
1688 if (event
->error_code
== BadAccess
)
1690 selectinput_err
= 1;
1691 mp_msg(MSGT_VO
, MSGL_ERR
,
1692 "X11 error: BadAccess during XSelectInput Call\n");
1693 mp_msg(MSGT_VO
, MSGL_ERR
,
1694 "X11 error: The 'ButtonPressMask' mask of specified window has probably already used by another appication (see man XSelectInput)\n");
1695 /* If you think MPlayer should shutdown with this error,
1696 * comment out the following line */
1699 if (old_handler
!= NULL
)
1700 old_handler(display
, event
);
1702 x11_errorhandler(display
, event
);
1706 void vo_x11_selectinput_witherr(Display
* display
, Window w
,
1709 XSync(display
, False
);
1710 old_handler
= XSetErrorHandler(x11_selectinput_errorhandler
);
1711 selectinput_err
= 0;
1712 if (vo_nomouse_input
)
1714 XSelectInput(display
, w
,
1716 (~(ButtonPressMask
| ButtonReleaseMask
)));
1719 XSelectInput(display
, w
, event_mask
);
1721 XSync(display
, False
);
1722 XSetErrorHandler(old_handler
);
1723 if (selectinput_err
)
1725 mp_msg(MSGT_VO
, MSGL_ERR
,
1726 "X11 error: MPlayer discards mouse control (reconfiguring)\n");
1727 XSelectInput(display
, w
,
1730 (ButtonPressMask
| ButtonReleaseMask
|
1731 PointerMotionMask
)));
1736 void vo_vm_switch(struct vo
*vo
, uint32_t X
, uint32_t Y
, int *modeline_width
,
1737 int *modeline_height
)
1739 struct vo_x11_state
*x11
= vo
->x11
;
1740 struct MPOpts
*opts
= vo
->opts
;
1741 Display
*mDisplay
= x11
->display
;
1742 int vm_event
, vm_error
;
1744 int i
, j
, have_vm
= 0;
1748 if (XF86VidModeQueryExtension(mDisplay
, &vm_event
, &vm_error
))
1750 XF86VidModeQueryVersion(mDisplay
, &vm_ver
, &vm_rev
);
1751 mp_msg(MSGT_VO
, MSGL_V
, "XF86VidMode extension v%i.%i\n", vm_ver
,
1755 mp_msg(MSGT_VO
, MSGL_WARN
,
1756 "XF86VidMode extension not available.\n");
1760 if (vidmodes
== NULL
)
1761 XF86VidModeGetAllModeLines(mDisplay
, x11
->screen
, &modecount
,
1764 *modeline_width
= vidmodes
[0]->hdisplay
;
1765 *modeline_height
= vidmodes
[0]->vdisplay
;
1767 for (i
= 1; i
< modecount
; i
++)
1768 if ((vidmodes
[i
]->hdisplay
>= X
)
1769 && (vidmodes
[i
]->vdisplay
>= Y
))
1770 if ((vidmodes
[i
]->hdisplay
<= *modeline_width
)
1771 && (vidmodes
[i
]->vdisplay
<= *modeline_height
))
1773 *modeline_width
= vidmodes
[i
]->hdisplay
;
1774 *modeline_height
= vidmodes
[i
]->vdisplay
;
1778 mp_msg(MSGT_VO
, MSGL_INFO
, MSGTR_SelectedVideoMode
,
1779 *modeline_width
, *modeline_height
, X
, Y
);
1780 XF86VidModeLockModeSwitch(mDisplay
, x11
->screen
, 0);
1781 XF86VidModeSwitchToMode(mDisplay
, x11
->screen
, vidmodes
[j
]);
1782 XF86VidModeSwitchToMode(mDisplay
, x11
->screen
, vidmodes
[j
]);
1783 X
= (opts
->vo_screenwidth
- *modeline_width
) / 2;
1784 Y
= (opts
->vo_screenheight
- *modeline_height
) / 2;
1785 XF86VidModeSetViewPort(mDisplay
, x11
->screen
, X
, Y
);
1789 void vo_vm_close(struct vo
*vo
)
1791 Display
*dpy
= vo
->x11
->display
;
1792 struct MPOpts
*opts
= vo
->opts
;
1794 if (vidmodes
!= NULL
&& vo
->x11
->vo_window
!= None
)
1796 if (vidmodes
!= NULL
)
1802 screen
= DefaultScreen(dpy
);
1806 XF86VidModeGetAllModeLines(dpy
, vo
->x11
->screen
, &modecount
,
1808 for (i
= 0; i
< modecount
; i
++)
1809 if ((vidmodes
[i
]->hdisplay
== opts
->vo_screenwidth
)
1810 && (vidmodes
[i
]->vdisplay
== opts
->vo_screenheight
))
1812 mp_msg(MSGT_VO
, MSGL_INFO
,
1813 "Returning to original mode %dx%d\n",
1814 opts
->vo_screenwidth
, opts
->vo_screenheight
);
1818 XF86VidModeSwitchToMode(dpy
, screen
, vidmodes
[i
]);
1819 XF86VidModeSwitchToMode(dpy
, screen
, vidmodes
[i
]);
1826 #endif /* X11_FULLSCREEN */
1830 * Scan the available visuals on this Display/Screen. Try to find
1831 * the 'best' available TrueColor visual that has a decent color
1832 * depth (at least 15bit). If there are multiple visuals with depth
1833 * >= 15bit, we prefer visuals with a smaller color depth.
1835 int vo_find_depth_from_visuals(Display
* dpy
, int screen
,
1836 Visual
** visual_return
)
1838 XVisualInfo visual_tmpl
;
1839 XVisualInfo
*visuals
;
1841 int bestvisual
= -1;
1842 int bestvisual_depth
= -1;
1844 visual_tmpl
.screen
= screen
;
1845 visual_tmpl
.class = TrueColor
;
1846 visuals
= XGetVisualInfo(dpy
,
1847 VisualScreenMask
| VisualClassMask
,
1848 &visual_tmpl
, &nvisuals
);
1849 if (visuals
!= NULL
)
1851 for (i
= 0; i
< nvisuals
; i
++)
1853 mp_msg(MSGT_VO
, MSGL_V
,
1854 "vo: X11 truecolor visual %#lx, depth %d, R:%lX G:%lX B:%lX\n",
1855 visuals
[i
].visualid
, visuals
[i
].depth
,
1856 visuals
[i
].red_mask
, visuals
[i
].green_mask
,
1857 visuals
[i
].blue_mask
);
1859 * Save the visual index and its depth, if this is the first
1860 * truecolor visul, or a visual that is 'preferred' over the
1861 * previous 'best' visual.
1863 if (bestvisual_depth
== -1
1864 || (visuals
[i
].depth
>= 15
1865 && (visuals
[i
].depth
< bestvisual_depth
1866 || bestvisual_depth
< 15)))
1869 bestvisual_depth
= visuals
[i
].depth
;
1873 if (bestvisual
!= -1 && visual_return
!= NULL
)
1874 *visual_return
= visuals
[bestvisual
].visual
;
1878 return bestvisual_depth
;
1882 static Colormap cmap
= None
;
1883 static XColor cols
[256];
1884 static int cm_size
, red_mask
, green_mask
, blue_mask
;
1887 Colormap
vo_x11_create_colormap(struct vo
*vo
, XVisualInfo
*vinfo
)
1889 struct vo_x11_state
*x11
= vo
->x11
;
1890 unsigned k
, r
, g
, b
, ru
, gu
, bu
, m
, rv
, gv
, bv
, rvu
, gvu
, bvu
;
1892 if (vinfo
->class != DirectColor
)
1893 return XCreateColormap(x11
->display
, x11
->rootwin
, vinfo
->visual
,
1896 /* can this function get called twice or more? */
1899 cm_size
= vinfo
->colormap_size
;
1900 red_mask
= vinfo
->red_mask
;
1901 green_mask
= vinfo
->green_mask
;
1902 blue_mask
= vinfo
->blue_mask
;
1903 ru
= (red_mask
& (red_mask
- 1)) ^ red_mask
;
1904 gu
= (green_mask
& (green_mask
- 1)) ^ green_mask
;
1905 bu
= (blue_mask
& (blue_mask
- 1)) ^ blue_mask
;
1906 rvu
= 65536ull * ru
/ (red_mask
+ ru
);
1907 gvu
= 65536ull * gu
/ (green_mask
+ gu
);
1908 bvu
= 65536ull * bu
/ (blue_mask
+ bu
);
1911 m
= DoRed
| DoGreen
| DoBlue
;
1912 for (k
= 0; k
< cm_size
; k
++)
1916 cols
[k
].pixel
= r
| g
| b
;
1921 t
= (r
+ ru
) & red_mask
;
1925 t
= (g
+ gu
) & green_mask
;
1929 t
= (b
+ bu
) & blue_mask
;
1937 cmap
= XCreateColormap(x11
->display
, x11
->rootwin
, vinfo
->visual
, AllocAll
);
1938 XStoreColors(x11
->display
, cmap
, cols
, cm_size
);
1943 * Via colormaps/gamma ramps we can do gamma, brightness, contrast,
1944 * hue and red/green/blue intensity, but we cannot do saturation.
1945 * Currently only gamma, brightness and contrast are implemented.
1946 * Is there sufficient interest for hue and/or red/green/blue intensity?
1948 /* these values have range [-100,100] and are initially 0 */
1949 static int vo_gamma
= 0;
1950 static int vo_brightness
= 0;
1951 static int vo_contrast
= 0;
1953 static int transform_color(float val
,
1954 float brightness
, float contrast
, float gamma
) {
1955 float s
= pow(val
, gamma
);
1956 s
= (s
- 0.5) * contrast
+ 0.5;
1962 return (unsigned short) (s
* 65535);
1965 uint32_t vo_x11_set_equalizer(struct vo
*vo
, char *name
, int value
)
1967 float gamma
, brightness
, contrast
;
1972 * IMPLEMENTME: consider using XF86VidModeSetGammaRamp in the case
1973 * of TrueColor-ed window but be careful:
1974 * Unlike the colormaps, which are private for the X client
1975 * who created them and thus automatically destroyed on client
1976 * disconnect, this gamma ramp is a system-wide (X-server-wide)
1977 * setting and _must_ be restored before the process exits.
1978 * Unforunately when the process crashes (or gets killed
1979 * for some reason) it is impossible to restore the setting,
1980 * and such behaviour could be rather annoying for the users.
1985 if (!strcasecmp(name
, "brightness"))
1986 vo_brightness
= value
;
1987 else if (!strcasecmp(name
, "contrast"))
1988 vo_contrast
= value
;
1989 else if (!strcasecmp(name
, "gamma"))
1994 brightness
= 0.01 * vo_brightness
;
1995 contrast
= tan(0.0095 * (vo_contrast
+ 100) * M_PI
/ 4);
1996 gamma
= pow(2, -0.02 * vo_gamma
);
1998 rf
= (float) ((red_mask
& (red_mask
- 1)) ^ red_mask
) / red_mask
;
1999 gf
= (float) ((green_mask
& (green_mask
- 1)) ^ green_mask
) /
2001 bf
= (float) ((blue_mask
& (blue_mask
- 1)) ^ blue_mask
) / blue_mask
;
2003 /* now recalculate the colormap using the newly set value */
2004 for (k
= 0; k
< cm_size
; k
++)
2006 cols
[k
].red
= transform_color(rf
* k
, brightness
, contrast
, gamma
);
2007 cols
[k
].green
= transform_color(gf
* k
, brightness
, contrast
, gamma
);
2008 cols
[k
].blue
= transform_color(bf
* k
, brightness
, contrast
, gamma
);
2011 XStoreColors(vo
->x11
->display
, cmap
, cols
, cm_size
);
2012 XFlush(vo
->x11
->display
);
2016 uint32_t vo_x11_get_equalizer(char *name
, int *value
)
2020 if (!strcasecmp(name
, "brightness"))
2021 *value
= vo_brightness
;
2022 else if (!strcasecmp(name
, "contrast"))
2023 *value
= vo_contrast
;
2024 else if (!strcasecmp(name
, "gamma"))
2032 int vo_xv_set_eq(struct vo
*vo
, uint32_t xv_port
, char *name
, int value
)
2034 XvAttribute
*attributes
;
2035 int i
, howmany
, xv_atom
;
2037 mp_dbg(MSGT_VO
, MSGL_V
, "xv_set_eq called! (%s, %d)\n", name
, value
);
2039 /* get available attributes */
2040 attributes
= XvQueryPortAttributes(vo
->x11
->display
, xv_port
, &howmany
);
2041 for (i
= 0; i
< howmany
&& attributes
; i
++)
2042 if (attributes
[i
].flags
& XvSettable
)
2044 xv_atom
= XInternAtom(vo
->x11
->display
, attributes
[i
].name
, True
);
2045 /* since we have SET_DEFAULTS first in our list, we can check if it's available
2046 then trigger it if it's ok so that the other values are at default upon query */
2047 if (xv_atom
!= None
)
2049 int hue
= 0, port_value
, port_min
, port_max
;
2051 if (!strcmp(attributes
[i
].name
, "XV_BRIGHTNESS") &&
2052 (!strcasecmp(name
, "brightness")))
2054 else if (!strcmp(attributes
[i
].name
, "XV_CONTRAST") &&
2055 (!strcasecmp(name
, "contrast")))
2057 else if (!strcmp(attributes
[i
].name
, "XV_SATURATION") &&
2058 (!strcasecmp(name
, "saturation")))
2060 else if (!strcmp(attributes
[i
].name
, "XV_HUE") &&
2061 (!strcasecmp(name
, "hue")))
2066 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
2067 if (!strcmp(attributes
[i
].name
, "XV_RED_INTENSITY") &&
2068 (!strcasecmp(name
, "red_intensity")))
2070 else if (!strcmp(attributes
[i
].name
, "XV_GREEN_INTENSITY")
2071 && (!strcasecmp(name
, "green_intensity")))
2073 else if (!strcmp(attributes
[i
].name
, "XV_BLUE_INTENSITY")
2074 && (!strcasecmp(name
, "blue_intensity")))
2079 port_min
= attributes
[i
].min_value
;
2080 port_max
= attributes
[i
].max_value
;
2082 /* nvidia hue workaround */
2083 if (hue
&& port_min
== 0 && port_max
== 360)
2087 0) ? (port_value
- 100) : (port_value
+ 100);
2093 (port_value
+ 100) * (port_max
- port_min
) / 200 +
2095 XvSetPortAttribute(vo
->x11
->display
, xv_port
, xv_atom
, port_value
);
2102 int vo_xv_get_eq(struct vo
*vo
, uint32_t xv_port
, char *name
, int *value
)
2105 XvAttribute
*attributes
;
2106 int i
, howmany
, xv_atom
;
2108 /* get available attributes */
2109 attributes
= XvQueryPortAttributes(vo
->x11
->display
, xv_port
, &howmany
);
2110 for (i
= 0; i
< howmany
&& attributes
; i
++)
2111 if (attributes
[i
].flags
& XvGettable
)
2113 xv_atom
= XInternAtom(vo
->x11
->display
, attributes
[i
].name
, True
);
2114 /* since we have SET_DEFAULTS first in our list, we can check if it's available
2115 then trigger it if it's ok so that the other values are at default upon query */
2116 if (xv_atom
!= None
)
2118 int val
, port_value
= 0, port_min
, port_max
;
2120 XvGetPortAttribute(vo
->x11
->display
, xv_port
, xv_atom
,
2123 port_min
= attributes
[i
].min_value
;
2124 port_max
= attributes
[i
].max_value
;
2126 (port_value
- port_min
) * 200 / (port_max
- port_min
) -
2129 if (!strcmp(attributes
[i
].name
, "XV_BRIGHTNESS") &&
2130 (!strcasecmp(name
, "brightness")))
2132 else if (!strcmp(attributes
[i
].name
, "XV_CONTRAST") &&
2133 (!strcasecmp(name
, "contrast")))
2135 else if (!strcmp(attributes
[i
].name
, "XV_SATURATION") &&
2136 (!strcasecmp(name
, "saturation")))
2138 else if (!strcmp(attributes
[i
].name
, "XV_HUE") &&
2139 (!strcasecmp(name
, "hue")))
2141 /* nasty nvidia detect */
2142 if (port_min
== 0 && port_max
== 360)
2143 *value
= (val
>= 0) ? (val
- 100) : (val
+ 100);
2147 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
2148 if (!strcmp(attributes
[i
].name
, "XV_RED_INTENSITY") &&
2149 (!strcasecmp(name
, "red_intensity")))
2151 else if (!strcmp(attributes
[i
].name
, "XV_GREEN_INTENSITY")
2152 && (!strcasecmp(name
, "green_intensity")))
2154 else if (!strcmp(attributes
[i
].name
, "XV_BLUE_INTENSITY")
2155 && (!strcasecmp(name
, "blue_intensity")))
2160 mp_dbg(MSGT_VO
, MSGL_V
, "xv_get_eq called! (%s, %d)\n",
2169 * \brief Interns the requested atom if it is available.
2171 * \param atom_name String containing the name of the requested atom.
2173 * \return Returns the atom if available, else None is returned.
2176 static Atom
xv_intern_atom_if_exists(struct vo_x11_state
*x11
,
2177 char const *atom_name
)
2179 XvAttribute
* attributes
;
2181 Atom xv_atom
= None
;
2183 attributes
= XvQueryPortAttributes(x11
->display
, x11
->xv_port
, &attrib_count
);
2184 if( attributes
!=NULL
)
2186 for ( i
= 0; i
< attrib_count
; ++i
)
2188 if ( strcmp(attributes
[i
].name
, atom_name
) == 0 )
2190 xv_atom
= XInternAtom(x11
->display
, atom_name
, False
);
2191 break; // found what we want, break out
2194 XFree( attributes
);
2201 * \brief Try to enable vsync for xv.
2202 * \return Returns -1 if not available, 0 on failure and 1 on success.
2204 int vo_xv_enable_vsync(struct vo
*vo
)
2206 struct vo_x11_state
*x11
= vo
->x11
;
2207 Atom xv_atom
= xv_intern_atom_if_exists(x11
, "XV_SYNC_TO_VBLANK");
2208 if (xv_atom
== None
)
2210 return XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, 1) == Success
;
2214 * \brief Get maximum supported source image dimensions.
2216 * This function does not set the variables pointed to by
2217 * width and height if the information could not be retrieved,
2218 * so the caller is reponsible for properly initializing them.
2220 * \param width [out] The maximum width gets stored here.
2221 * \param height [out] The maximum height gets stored here.
2224 void vo_xv_get_max_img_dim(struct vo
*vo
, uint32_t * width
, uint32_t * height
)
2226 struct vo_x11_state
*x11
= vo
->x11
;
2227 XvEncodingInfo
* encodings
;
2228 //unsigned long num_encodings, idx; to int or too long?!
2229 unsigned int num_encodings
, idx
;
2231 XvQueryEncodings(x11
->display
, x11
->xv_port
, &num_encodings
, &encodings
);
2235 for ( idx
= 0; idx
< num_encodings
; ++idx
)
2237 if ( strcmp( encodings
[idx
].name
, "XV_IMAGE" ) == 0 )
2239 *width
= encodings
[idx
].width
;
2240 *height
= encodings
[idx
].height
;
2246 mp_msg( MSGT_VO
, MSGL_V
,
2247 "[xv common] Maximum source image dimensions: %ux%u\n",
2250 XvFreeEncodingInfo( encodings
);
2254 * \brief Print information about the colorkey method and source.
2256 * \param ck_handling Integer value containing the information about
2257 * colorkey handling (see x11_common.h).
2259 * Outputs the content of |ck_handling| as a readable message.
2262 static void vo_xv_print_ck_info(struct vo_x11_state
*x11
)
2264 mp_msg( MSGT_VO
, MSGL_V
, "[xv common] " );
2266 switch ( x11
->xv_ck_info
.method
)
2268 case CK_METHOD_NONE
:
2269 mp_msg( MSGT_VO
, MSGL_V
, "Drawing no colorkey.\n" ); return;
2270 case CK_METHOD_AUTOPAINT
:
2271 mp_msg( MSGT_VO
, MSGL_V
, "Colorkey is drawn by Xv." ); break;
2272 case CK_METHOD_MANUALFILL
:
2273 mp_msg( MSGT_VO
, MSGL_V
, "Drawing colorkey manually." ); break;
2274 case CK_METHOD_BACKGROUND
:
2275 mp_msg( MSGT_VO
, MSGL_V
, "Colorkey is drawn as window background." ); break;
2278 mp_msg( MSGT_VO
, MSGL_V
, "\n[xv common] " );
2280 switch ( x11
->xv_ck_info
.source
)
2283 mp_msg( MSGT_VO
, MSGL_V
, "Using colorkey from Xv (0x%06lx).\n",
2287 if ( x11
->xv_ck_info
.method
== CK_METHOD_AUTOPAINT
)
2289 mp_msg( MSGT_VO
, MSGL_V
,
2290 "Ignoring colorkey from MPlayer (0x%06lx).\n",
2295 mp_msg( MSGT_VO
, MSGL_V
,
2296 "Using colorkey from MPlayer (0x%06lx)."
2297 " Use -colorkey to change.\n",
2302 mp_msg( MSGT_VO
, MSGL_V
,
2303 "Setting and using colorkey from MPlayer (0x%06lx)."
2304 " Use -colorkey to change.\n",
2310 * \brief Init colorkey depending on the settings in xv_ck_info.
2312 * \return Returns 0 on failure and 1 on success.
2314 * Sets the colorkey variable according to the CK_SRC_* and CK_METHOD_*
2315 * flags in xv_ck_info.
2319 * - manual colorkey drawing ( CK_METHOD_MANUALFILL )
2320 * - set colorkey as window background ( CK_METHOD_BACKGROUND )
2321 * - let Xv paint the colorkey ( CK_METHOD_AUTOPAINT )
2323 * - use currently set colorkey ( CK_SRC_CUR )
2324 * - use colorkey in vo_colorkey ( CK_SRC_USE )
2325 * - use and set colorkey in vo_colorkey ( CK_SRC_SET )
2327 * NOTE: If vo_colorkey has bits set after the first 3 low order bytes
2328 * we don't draw anything as this means it was forced to off.
2330 int vo_xv_init_colorkey(struct vo
*vo
)
2332 struct vo_x11_state
*x11
= vo
->x11
;
2336 /* check if colorkeying is needed */
2337 xv_atom
= xv_intern_atom_if_exists(vo
->x11
, "XV_COLORKEY");
2339 /* if we have to deal with colorkeying ... */
2340 if( xv_atom
!= None
&& !(vo_colorkey
& 0xFF000000) )
2342 /* check if we should use the colorkey specified in vo_colorkey */
2343 if ( x11
->xv_ck_info
.source
!= CK_SRC_CUR
)
2345 x11
->xv_colorkey
= vo_colorkey
;
2347 /* check if we have to set the colorkey too */
2348 if ( x11
->xv_ck_info
.source
== CK_SRC_SET
)
2350 xv_atom
= XInternAtom(x11
->display
, "XV_COLORKEY",False
);
2352 rez
= XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, vo_colorkey
);
2353 if ( rez
!= Success
)
2355 mp_msg( MSGT_VO
, MSGL_FATAL
,
2356 "[xv common] Couldn't set colorkey!\n" );
2357 return 0; // error setting colorkey
2365 rez
=XvGetPortAttribute(x11
->display
,x11
->xv_port
, xv_atom
, &colorkey_ret
);
2366 if ( rez
== Success
)
2368 x11
->xv_colorkey
= colorkey_ret
;
2372 mp_msg( MSGT_VO
, MSGL_FATAL
,
2373 "[xv common] Couldn't get colorkey!"
2374 "Maybe the selected Xv port has no overlay.\n" );
2375 return 0; // error getting colorkey
2379 xv_atom
= xv_intern_atom_if_exists(vo
->x11
, "XV_AUTOPAINT_COLORKEY");
2381 /* should we draw the colorkey ourselves or activate autopainting? */
2382 if ( x11
->xv_ck_info
.method
== CK_METHOD_AUTOPAINT
)
2384 rez
= !Success
; // reset rez to something different than Success
2386 if ( xv_atom
!= None
) // autopaint is supported
2388 rez
= XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, 1);
2391 if ( rez
!= Success
)
2393 // fallback to manual colorkey drawing
2394 x11
->xv_ck_info
.method
= CK_METHOD_MANUALFILL
;
2397 else // disable colorkey autopainting if supported
2399 if ( xv_atom
!= None
) // we have autopaint attribute
2401 XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, 0);
2405 else // do no colorkey drawing at all
2407 x11
->xv_ck_info
.method
= CK_METHOD_NONE
;
2408 } /* end: should we draw colorkey */
2410 /* output information about the current colorkey settings */
2411 vo_xv_print_ck_info(x11
);
2413 return 1; // success
2417 * \brief Draw the colorkey on the video window.
2419 * Draws the colorkey depending on the set method ( colorkey_handling ).
2421 * Also draws the black bars ( when the video doesn't fit the display in
2422 * fullscreen ) separately, so they don't overlap with the video area.
2423 * It doesn't call XFlush.
2426 void vo_xv_draw_colorkey(struct vo
*vo
, int32_t x
, int32_t y
,
2427 int32_t w
, int32_t h
)
2429 struct MPOpts
*opts
= vo
->opts
;
2430 struct vo_x11_state
*x11
= vo
->x11
;
2431 if( x11
->xv_ck_info
.method
== CK_METHOD_MANUALFILL
||
2432 x11
->xv_ck_info
.method
== CK_METHOD_BACKGROUND
)//less tearing than XClearWindow()
2434 XSetForeground(x11
->display
, x11
->vo_gc
, x11
->xv_colorkey
);
2435 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2440 /* draw black bars if needed */
2441 /* TODO! move this to vo_x11_clearwindow_part() */
2444 XSetForeground(x11
->display
, x11
->vo_gc
, 0 );
2445 /* making non-overlap fills, requires 8 checks instead of 4 */
2447 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2449 opts
->vo_screenwidth
, y
);
2451 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2453 x
, opts
->vo_screenheight
);
2454 if (x
+ w
< opts
->vo_screenwidth
)
2455 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2457 opts
->vo_screenwidth
, opts
->vo_screenheight
);
2458 if (y
+ h
< opts
->vo_screenheight
)
2459 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2461 opts
->vo_screenwidth
, opts
->vo_screenheight
);
2465 /** \brief Tests if a valid argument for the ck suboption was given. */
2466 int xv_test_ck( void * arg
)
2468 strarg_t
* strarg
= (strarg_t
*)arg
;
2470 if ( strargcmp( strarg
, "use" ) == 0 ||
2471 strargcmp( strarg
, "set" ) == 0 ||
2472 strargcmp( strarg
, "cur" ) == 0 )
2479 /** \brief Tests if a valid arguments for the ck-method suboption was given. */
2480 int xv_test_ckm( void * arg
)
2482 strarg_t
* strarg
= (strarg_t
*)arg
;
2484 if ( strargcmp( strarg
, "bg" ) == 0 ||
2485 strargcmp( strarg
, "man" ) == 0 ||
2486 strargcmp( strarg
, "auto" ) == 0 )
2495 * \brief Modify the colorkey_handling var according to str
2497 * Checks if a valid pointer ( not NULL ) to the string
2498 * was given. And in that case modifies the colorkey_handling
2499 * var to reflect the requested behaviour.
2500 * If nothing happens the content of colorkey_handling stays
2503 * \param str Pointer to the string or NULL
2506 void xv_setup_colorkeyhandling(struct vo
*vo
, const char *ck_method_str
,
2509 struct vo_x11_state
*x11
= vo
->x11
;
2510 /* check if a valid pointer to the string was passed */
2513 if ( strncmp( ck_str
, "use", 3 ) == 0 )
2515 x11
->xv_ck_info
.source
= CK_SRC_USE
;
2517 else if ( strncmp( ck_str
, "set", 3 ) == 0 )
2519 x11
->xv_ck_info
.source
= CK_SRC_SET
;
2522 /* check if a valid pointer to the string was passed */
2523 if ( ck_method_str
)
2525 if ( strncmp( ck_method_str
, "bg", 2 ) == 0 )
2527 x11
->xv_ck_info
.method
= CK_METHOD_BACKGROUND
;
2529 else if ( strncmp( ck_method_str
, "man", 3 ) == 0 )
2531 x11
->xv_ck_info
.method
= CK_METHOD_MANUALFILL
;
2533 else if ( strncmp( ck_method_str
, "auto", 4 ) == 0 )
2535 x11
->xv_ck_info
.method
= CK_METHOD_AUTOPAINT
;
2542 struct vo_x11_state
*vo_x11_init_state(void)
2544 struct vo_x11_state
*s
= talloc_ptrtype(NULL
, s
);
2545 *s
= (struct vo_x11_state
){
2546 .xv_ck_info
= { CK_METHOD_MANUALFILL
, CK_SRC_CUR
},
2547 .olddecor
= MWM_DECOR_ALL
,
2548 .oldfuncs
= MWM_FUNC_MOVE
| MWM_FUNC_CLOSE
| MWM_FUNC_MINIMIZE
|
2549 MWM_FUNC_MAXIMIZE
| MWM_FUNC_RESIZE
,
2550 .old_gravity
= NorthWestGravity
,