11 #include "x11_common.h"
19 #include "video_out.h"
23 #include "osdep/timer.h"
27 #include <X11/Xutil.h>
28 #include <X11/Xatom.h>
31 #include <X11/extensions/scrnsaver.h>
35 #include <X11/extensions/dpms.h>
39 #include <X11/extensions/Xinerama.h>
43 #include <X11/extensions/xf86vmode.h>
47 #include <X11/XF86keysym.h>
51 #include <X11/extensions/Xv.h>
52 #include <X11/extensions/Xvlib.h>
54 #include "subopt-helper.h"
57 #include "input/input.h"
58 #include "input/mouse.h"
61 #include "gui/interface.h"
65 #define WIN_LAYER_ONBOTTOM 2
66 #define WIN_LAYER_NORMAL 4
67 #define WIN_LAYER_ONTOP 6
68 #define WIN_LAYER_ABOVE_DOCK 10
70 extern int enable_mouse_movements
;
71 int fs_layer
= WIN_LAYER_ABOVE_DOCK
;
73 int stop_xscreensaver
= 0;
75 static int dpms_disabled
= 0;
77 char *mDisplayName
= NULL
;
79 char **vo_fstype_list
;
81 /* 1 means that the WM is metacity (broken as hell) */
82 int metacity_hack
= 0;
85 XF86VidModeModeInfo
**vidmodes
= NULL
;
86 XF86VidModeModeLine modeline
;
89 static int vo_x11_get_fs_type(int supported
);
90 static void saver_off(Display
*);
91 static void saver_on(Display
*);
94 * Sends the EWMH fullscreen state event.
96 * action: could be one of _NET_WM_STATE_REMOVE -- remove state
97 * _NET_WM_STATE_ADD -- add state
98 * _NET_WM_STATE_TOGGLE -- toggle
100 void vo_x11_ewmh_fullscreen(struct vo_x11_state
*x11
, int action
)
102 assert(action
== _NET_WM_STATE_REMOVE
||
103 action
== _NET_WM_STATE_ADD
|| action
== _NET_WM_STATE_TOGGLE
);
105 if (x11
->fs_type
& vo_wm_FULLSCREEN
)
109 /* init X event structure for _NET_WM_FULLSCREEN client message */
110 xev
.xclient
.type
= ClientMessage
;
111 xev
.xclient
.serial
= 0;
112 xev
.xclient
.send_event
= True
;
113 xev
.xclient
.message_type
= XInternAtom(x11
->display
,
114 "_NET_WM_STATE", False
);
115 xev
.xclient
.window
= x11
->window
;
116 xev
.xclient
.format
= 32;
117 xev
.xclient
.data
.l
[0] = action
;
118 xev
.xclient
.data
.l
[1] = XInternAtom(x11
->display
,
119 "_NET_WM_STATE_FULLSCREEN",
121 xev
.xclient
.data
.l
[2] = 0;
122 xev
.xclient
.data
.l
[3] = 0;
123 xev
.xclient
.data
.l
[4] = 0;
125 /* finally send that damn thing */
126 if (!XSendEvent(x11
->display
, DefaultRootWindow(x11
->display
), False
,
127 SubstructureRedirectMask
| SubstructureNotifyMask
,
130 mp_msg(MSGT_VO
, MSGL_ERR
, MSGTR_EwmhFullscreenStateFailed
);
135 static void vo_hidecursor(Display
* disp
, Window win
)
141 const char bm_no_data
[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
144 return; // do not hide if playing on the root window
146 colormap
= DefaultColormap(disp
, DefaultScreen(disp
));
147 if ( !XAllocNamedColor(disp
, colormap
, "black", &black
, &dummy
) )
149 return; // color alloc failed, give up
151 bm_no
= XCreateBitmapFromData(disp
, win
, bm_no_data
, 8, 8);
152 no_ptr
= XCreatePixmapCursor(disp
, bm_no
, bm_no
, &black
, &black
, 0, 0);
153 XDefineCursor(disp
, win
, no_ptr
);
154 XFreeCursor(disp
, no_ptr
);
156 XFreePixmap(disp
, bm_no
);
157 XFreeColors(disp
,colormap
,&black
.pixel
,1,0);
160 static void vo_showcursor(Display
* disp
, Window win
)
164 XDefineCursor(disp
, win
, 0);
167 static int x11_errorhandler(Display
* display
, XErrorEvent
* event
)
172 XGetErrorText(display
, event
->error_code
, (char *) &msg
, MSGLEN
);
174 mp_msg(MSGT_VO
, MSGL_ERR
, "X11 error: %s\n", msg
);
176 mp_msg(MSGT_VO
, MSGL_V
,
177 "Type: %x, display: %p, resourceid: %lx, serial: %lx\n",
178 event
->type
, event
->display
, event
->resourceid
, event
->serial
);
179 mp_msg(MSGT_VO
, MSGL_V
,
180 "Error code: %x, request code: %x, minor code: %x\n",
181 event
->error_code
, event
->request_code
, event
->minor_code
);
184 //exit_player("X11 error");
189 void fstype_help(void)
191 mp_msg(MSGT_VO
, MSGL_INFO
, MSGTR_AvailableFsType
);
192 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FULL_SCREEN_TYPES\n");
194 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "none",
195 "don't set fullscreen window layer");
196 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "layer",
197 "use _WIN_LAYER hint with default layer");
198 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "layer=<0..15>",
199 "use _WIN_LAYER hint with a given layer number");
200 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "netwm",
201 "force NETWM style");
202 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "above",
203 "use _NETWM_STATE_ABOVE hint if available");
204 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "below",
205 "use _NETWM_STATE_BELOW hint if available");
206 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "fullscreen",
207 "use _NETWM_STATE_FULLSCREEN hint if availale");
208 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "stays_on_top",
209 "use _NETWM_STATE_STAYS_ON_TOP hint if available");
210 mp_msg(MSGT_VO
, MSGL_INFO
,
211 "You can also negate the settings with simply putting '-' in the beginning");
212 mp_msg(MSGT_VO
, MSGL_INFO
, "\n");
215 static void fstype_dump(int fstype
)
219 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Current fstype setting honours");
220 if (fstype
& vo_wm_LAYER
)
221 mp_msg(MSGT_VO
, MSGL_V
, " LAYER");
222 if (fstype
& vo_wm_FULLSCREEN
)
223 mp_msg(MSGT_VO
, MSGL_V
, " FULLSCREEN");
224 if (fstype
& vo_wm_STAYS_ON_TOP
)
225 mp_msg(MSGT_VO
, MSGL_V
, " STAYS_ON_TOP");
226 if (fstype
& vo_wm_ABOVE
)
227 mp_msg(MSGT_VO
, MSGL_V
, " ABOVE");
228 if (fstype
& vo_wm_BELOW
)
229 mp_msg(MSGT_VO
, MSGL_V
, " BELOW");
230 mp_msg(MSGT_VO
, MSGL_V
, " X atoms\n");
232 mp_msg(MSGT_VO
, MSGL_V
,
233 "[x11] Current fstype setting doesn't honour any X atoms\n");
236 static int net_wm_support_state_test(struct vo_x11_state
*x11
, Atom atom
)
238 #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; } }
240 NET_WM_STATE_TEST(FULLSCREEN
);
241 NET_WM_STATE_TEST(ABOVE
);
242 NET_WM_STATE_TEST(STAYS_ON_TOP
);
243 NET_WM_STATE_TEST(BELOW
);
247 static int x11_get_property(struct vo_x11_state
*x11
, Atom type
, Atom
** args
,
248 unsigned long *nitems
)
251 unsigned long bytesafter
;
254 XGetWindowProperty(x11
->display
, x11
->rootwin
, type
, 0, 16384, False
,
255 AnyPropertyType
, &type
, &format
, nitems
,
256 &bytesafter
, (unsigned char **) args
)
260 static int vo_wm_detect(struct vo
*vo
)
262 struct vo_x11_state
*x11
= vo
->x11
;
265 unsigned long nitems
;
271 // -- supports layers
272 if (x11_get_property(x11
, x11
->XA_WIN_PROTOCOLS
, &args
, &nitems
))
274 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Detected wm supports layers.\n");
275 for (i
= 0; i
< nitems
; i
++)
277 if (args
[i
] == x11
->XA_WIN_LAYER
)
282 /* metacity is the only window manager I know which reports
283 * supporting only the _WIN_LAYER hint in _WIN_PROTOCOLS.
284 * (what's more support for it is broken) */
288 if (wm
&& (metacity_hack
== 1))
290 // metacity claims to support layers, but it is not the truth :-)
292 mp_msg(MSGT_VO
, MSGL_V
,
293 "[x11] Using workaround for Metacity bugs.\n");
297 if (x11_get_property(x11
, x11
->XA_NET_SUPPORTED
, &args
, &nitems
))
299 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Detected wm supports NetWM.\n");
300 for (i
= 0; i
< nitems
; i
++)
301 wm
|= net_wm_support_state_test(vo
->x11
, args
[i
]);
304 // ugly hack for broken OpenBox _NET_WM_STATE_FULLSCREEN support
305 // (in their implementation it only changes internal window state, nothing more!!!)
306 if (wm
& vo_wm_FULLSCREEN
)
308 if (x11_get_property(x11
, x11
->XA_BLACKBOX_PID
, &args
, &nitems
))
310 mp_msg(MSGT_VO
, MSGL_V
,
311 "[x11] Detected wm is a broken OpenBox.\n");
312 wm
^= vo_wm_FULLSCREEN
;
320 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Unknown wm type...\n");
324 #define XA_INIT(x) x11->XA##x = XInternAtom(x11->display, #x, False)
325 static void init_atoms(struct vo_x11_state
*x11
)
327 XA_INIT(_NET_SUPPORTED
);
328 XA_INIT(_NET_WM_STATE
);
329 XA_INIT(_NET_WM_STATE_FULLSCREEN
);
330 XA_INIT(_NET_WM_STATE_ABOVE
);
331 XA_INIT(_NET_WM_STATE_STAYS_ON_TOP
);
332 XA_INIT(_NET_WM_STATE_BELOW
);
333 XA_INIT(_NET_WM_PID
);
334 XA_INIT(_WIN_PROTOCOLS
);
337 XA_INIT(_BLACKBOX_PID
);
338 XA_INIT(WM_PROTOCOLS
);
339 XA_INIT(WM_DELETE_WINDOW
);
342 void update_xinerama_info(struct vo
*vo
) {
343 struct MPOpts
*opts
= vo
->opts
;
344 int screen
= xinerama_screen
;
345 xinerama_x
= xinerama_y
= 0;
347 if (screen
>= -1 && XineramaIsActive(vo
->x11
->display
))
349 XineramaScreenInfo
*screens
;
352 screens
= XineramaQueryScreens(vo
->x11
->display
, &num_screens
);
353 if (screen
>= num_screens
)
354 screen
= num_screens
- 1;
356 int x
= vo
->dx
+ vo
->dwidth
/ 2;
357 int y
= vo
->dy
+ vo
->dheight
/ 2;
358 for (screen
= num_screens
- 1; screen
> 0; screen
--) {
359 int left
= screens
[screen
].x_org
;
360 int right
= left
+ screens
[screen
].width
;
361 int top
= screens
[screen
].y_org
;
362 int bottom
= top
+ screens
[screen
].height
;
363 if (left
<= x
&& x
<= right
&& top
<= y
&& y
<= bottom
)
369 opts
->vo_screenwidth
= screens
[screen
].width
;
370 opts
->vo_screenheight
= screens
[screen
].height
;
371 xinerama_x
= screens
[screen
].x_org
;
372 xinerama_y
= screens
[screen
].y_org
;
377 aspect_save_screenres(opts
->vo_screenwidth
, opts
->vo_screenheight
);
380 int vo_init(struct vo
*vo
)
382 struct MPOpts
*opts
= vo
->opts
;
383 struct vo_x11_state
*x11
= vo
->x11
;
388 // char * DisplayName = ":0.0";
389 // Display * mDisplay;
390 XImage
*mXImage
= NULL
;
393 XWindowAttributes attribs
;
397 WinID
= 0; // use root window
399 if (x11
->depthonscreen
)
401 saver_off(x11
->display
);
402 return 1; // already called
405 XSetErrorHandler(x11_errorhandler
);
409 if (!(mDisplayName
= getenv("DISPLAY")))
410 mDisplayName
= strdup(":0.0");
412 dispName
= XDisplayName(mDisplayName
);
415 mp_msg(MSGT_VO
, MSGL_V
, "X11 opening display: %s\n", dispName
);
417 x11
->display
= XOpenDisplay(dispName
);
420 mp_msg(MSGT_VO
, MSGL_ERR
,
421 "vo: couldn't open the X11 display (%s)!\n", dispName
);
424 x11
->screen
= DefaultScreen(x11
->display
); // screen ID
425 x11
->rootwin
= RootWindow(x11
->display
, x11
->screen
); // root window ID
433 XF86VidModeGetModeLine(x11
->display
, x11
->screen
, &clock
, &modeline
);
434 if (!opts
->vo_screenwidth
)
435 opts
->vo_screenwidth
= modeline
.hdisplay
;
436 if (!opts
->vo_screenheight
)
437 opts
->vo_screenheight
= modeline
.vdisplay
;
441 if (!opts
->vo_screenwidth
)
442 opts
->vo_screenwidth
= DisplayWidth(x11
->display
, x11
->screen
);
443 if (!opts
->vo_screenheight
)
444 opts
->vo_screenheight
= DisplayHeight(x11
->display
, x11
->screen
);
446 // get color depth (from root window, or the best visual):
447 XGetWindowAttributes(x11
->display
, x11
->rootwin
, &attribs
);
448 depth
= attribs
.depth
;
450 if (depth
!= 15 && depth
!= 16 && depth
!= 24 && depth
!= 32)
454 depth
= vo_find_depth_from_visuals(x11
->display
, x11
->screen
, &visual
);
456 mXImage
= XCreateImage(x11
->display
, visual
, depth
, ZPixmap
,
457 0, NULL
, 1, 1, 8, 1);
460 XGetImage(x11
->display
, x11
->rootwin
, 0, 0, 1, 1, AllPlanes
, ZPixmap
);
462 x11
->depthonscreen
= depth
; // display depth on screen
464 // get bits/pixel from XImage structure:
471 * for the depth==24 case, the XImage structures might use
472 * 24 or 32 bits of data per pixel. The x11->depthonscreen
473 * field stores the amount of data per pixel in the
476 * Maybe we should rename vo_depthonscreen to (or add) vo_bpp?
478 bpp
= mXImage
->bits_per_pixel
;
479 if ((x11
->depthonscreen
+ 7) / 8 != (bpp
+ 7) / 8)
480 x11
->depthonscreen
= bpp
; // by A'rpi
482 mXImage
->red_mask
| mXImage
->green_mask
| mXImage
->blue_mask
;
483 mp_msg(MSGT_VO
, MSGL_V
,
484 "vo: X11 color mask: %X (R:%lX G:%lX B:%lX)\n", mask
,
485 mXImage
->red_mask
, mXImage
->green_mask
, mXImage
->blue_mask
);
486 XDestroyImage(mXImage
);
488 if (((x11
->depthonscreen
+ 7) / 8) == 2)
491 x11
->depthonscreen
= 15;
492 else if (mask
== 0xFFFF)
493 x11
->depthonscreen
= 16;
495 // XCloseDisplay( mDisplay );
496 /* slightly improved local display detection AST */
497 if (strncmp(dispName
, "unix:", 5) == 0)
499 else if (strncmp(dispName
, "localhost:", 10) == 0)
501 if (*dispName
== ':' && atoi(dispName
+ 1) < 10)
502 x11
->display_is_local
= 1;
504 x11
->display_is_local
= 0;
505 mp_msg(MSGT_VO
, MSGL_V
,
506 "vo: X11 running at %dx%d with depth %d and %d bpp (\"%s\" => %s display)\n",
507 opts
->vo_screenwidth
, opts
->vo_screenheight
, depth
, x11
->depthonscreen
,
508 dispName
, x11
->display_is_local
? "local" : "remote");
510 x11
->wm_type
= vo_wm_detect(vo
);
512 x11
->fs_type
= vo_x11_get_fs_type(x11
->wm_type
);
514 fstype_dump(x11
->fs_type
);
516 saver_off(x11
->display
);
520 void vo_uninit(struct vo_x11_state
*x11
)
524 mp_msg(MSGT_VO
, MSGL_V
,
525 "vo: x11 uninit called but X11 not initialized..\n");
528 // if( !vo_depthonscreen ) return;
529 mp_msg(MSGT_VO
, MSGL_V
, "vo: uninit ...\n");
530 XSetErrorHandler(NULL
);
531 XCloseDisplay(x11
->display
);
532 x11
->depthonscreen
= 0;
536 #include "osdep/keycodes.h"
539 #ifdef XF86XK_AudioPause
540 static void vo_x11_putkey_ext(int keysym
)
544 case XF86XK_AudioPause
:
545 mplayer_put_key(KEY_PAUSE
);
547 case XF86XK_AudioStop
:
548 mplayer_put_key(KEY_STOP
);
550 case XF86XK_AudioPrev
:
551 mplayer_put_key(KEY_PREV
);
553 case XF86XK_AudioNext
:
554 mplayer_put_key(KEY_NEXT
);
556 case XF86XK_AudioLowerVolume
:
557 mplayer_put_key(KEY_VOLUME_DOWN
);
559 case XF86XK_AudioRaiseVolume
:
560 mplayer_put_key(KEY_VOLUME_UP
);
568 void vo_x11_putkey(int key
)
573 mplayer_put_key(KEY_LEFT
);
576 mplayer_put_key(KEY_RIGHT
);
579 mplayer_put_key(KEY_UP
);
582 mplayer_put_key(KEY_DOWN
);
585 mplayer_put_key(' ');
588 mplayer_put_key(KEY_ESC
);
591 mplayer_put_key(KEY_TAB
);
594 mplayer_put_key(KEY_ENTER
);
597 mplayer_put_key(KEY_BS
);
600 mplayer_put_key(KEY_DELETE
);
603 mplayer_put_key(KEY_INSERT
);
606 mplayer_put_key(KEY_HOME
);
609 mplayer_put_key(KEY_END
);
612 mplayer_put_key(KEY_PAGE_UP
);
615 mplayer_put_key(KEY_PAGE_DOWN
);
618 mplayer_put_key(KEY_F
+ 1);
621 mplayer_put_key(KEY_F
+ 2);
624 mplayer_put_key(KEY_F
+ 3);
627 mplayer_put_key(KEY_F
+ 4);
630 mplayer_put_key(KEY_F
+ 5);
633 mplayer_put_key(KEY_F
+ 6);
636 mplayer_put_key(KEY_F
+ 7);
639 mplayer_put_key(KEY_F
+ 8);
642 mplayer_put_key(KEY_F
+ 9);
645 mplayer_put_key(KEY_F
+ 10);
648 mplayer_put_key(KEY_F
+ 11);
651 mplayer_put_key(KEY_F
+ 12);
655 mplayer_put_key('-');
659 mplayer_put_key('+');
663 mplayer_put_key('*');
667 mplayer_put_key('/');
670 mplayer_put_key('<');
673 mplayer_put_key('>');
676 mplayer_put_key(KEY_KP0
);
680 mplayer_put_key(KEY_KP1
);
684 mplayer_put_key(KEY_KP2
);
688 mplayer_put_key(KEY_KP3
);
692 mplayer_put_key(KEY_KP4
);
696 mplayer_put_key(KEY_KP5
);
700 mplayer_put_key(KEY_KP6
);
704 mplayer_put_key(KEY_KP7
);
708 mplayer_put_key(KEY_KP8
);
712 mplayer_put_key(KEY_KP9
);
715 mplayer_put_key(KEY_KPDEC
);
718 mplayer_put_key(KEY_KPINS
);
721 mplayer_put_key(KEY_KPDEL
);
724 mplayer_put_key(KEY_KPENTER
);
727 mplayer_put_key('`');
730 mplayer_put_key('~');
733 mplayer_put_key('!');
736 mplayer_put_key('@');
739 mplayer_put_key('#');
742 mplayer_put_key('$');
745 mplayer_put_key('%');
748 mplayer_put_key('^');
751 mplayer_put_key('&');
754 mplayer_put_key('(');
757 mplayer_put_key(')');
760 mplayer_put_key('_');
763 mplayer_put_key('{');
766 mplayer_put_key('}');
769 mplayer_put_key(':');
772 mplayer_put_key(';');
775 mplayer_put_key('\"');
778 mplayer_put_key('\'');
781 mplayer_put_key(',');
784 mplayer_put_key('.');
787 mplayer_put_key('?');
790 mplayer_put_key('\\');
793 mplayer_put_key('|');
796 mplayer_put_key('=');
799 mplayer_put_key('[');
802 mplayer_put_key(']');
807 if ((key
>= 'a' && key
<= 'z') || (key
>= 'A' && key
<= 'Z') ||
808 (key
>= '0' && key
<= '9'))
809 mplayer_put_key(key
);
815 // ----- Motif header: -------
817 #define MWM_HINTS_FUNCTIONS (1L << 0)
818 #define MWM_HINTS_DECORATIONS (1L << 1)
819 #define MWM_HINTS_INPUT_MODE (1L << 2)
820 #define MWM_HINTS_STATUS (1L << 3)
822 #define MWM_FUNC_ALL (1L << 0)
823 #define MWM_FUNC_RESIZE (1L << 1)
824 #define MWM_FUNC_MOVE (1L << 2)
825 #define MWM_FUNC_MINIMIZE (1L << 3)
826 #define MWM_FUNC_MAXIMIZE (1L << 4)
827 #define MWM_FUNC_CLOSE (1L << 5)
829 #define MWM_DECOR_ALL (1L << 0)
830 #define MWM_DECOR_BORDER (1L << 1)
831 #define MWM_DECOR_RESIZEH (1L << 2)
832 #define MWM_DECOR_TITLE (1L << 3)
833 #define MWM_DECOR_MENU (1L << 4)
834 #define MWM_DECOR_MINIMIZE (1L << 5)
835 #define MWM_DECOR_MAXIMIZE (1L << 6)
837 #define MWM_INPUT_MODELESS 0
838 #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
839 #define MWM_INPUT_SYSTEM_MODAL 2
840 #define MWM_INPUT_FULL_APPLICATION_MODAL 3
841 #define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL
843 #define MWM_TEAROFF_WINDOW (1L<<0)
854 static MotifWmHints vo_MotifWmHints
;
855 static Atom vo_MotifHints
= None
;
857 void vo_x11_decoration(struct vo
*vo
, int d
)
859 struct vo_x11_state
*x11
= vo
->x11
;
862 unsigned long mn
, mb
;
869 XSetTransientForHint(x11
->display
, x11
->window
,
870 RootWindow(x11
->display
, x11
->screen
));
873 vo_MotifHints
= XInternAtom(x11
->display
, "_MOTIF_WM_HINTS", 0);
874 if (vo_MotifHints
!= None
)
878 MotifWmHints
*mhints
= NULL
;
880 XGetWindowProperty(x11
->display
, x11
->window
,
881 vo_MotifHints
, 0, 20, False
,
882 vo_MotifHints
, &mtype
, &mformat
, &mn
,
883 &mb
, (unsigned char **) &mhints
);
886 if (mhints
->flags
& MWM_HINTS_DECORATIONS
)
887 x11
->olddecor
= mhints
->decorations
;
888 if (mhints
->flags
& MWM_HINTS_FUNCTIONS
)
889 x11
->oldfuncs
= mhints
->functions
;
894 memset(&vo_MotifWmHints
, 0, sizeof(MotifWmHints
));
895 vo_MotifWmHints
.flags
=
896 MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
899 vo_MotifWmHints
.functions
= x11
->oldfuncs
;
903 vo_MotifWmHints
.decorations
=
904 d
| ((vo_fsmode
& 2) ? 0 : MWM_DECOR_MENU
);
906 vo_MotifWmHints
.decorations
=
907 d
| ((vo_fsmode
& 2) ? MWM_DECOR_MENU
: 0);
909 XChangeProperty(x11
->display
, x11
->window
, vo_MotifHints
,
912 (unsigned char *) &vo_MotifWmHints
,
913 (vo_fsmode
& 4) ? 4 : 5);
917 void vo_x11_classhint(struct vo
*vo
, Window window
, char *name
)
919 struct vo_x11_state
*x11
= vo
->x11
;
921 pid_t pid
= getpid();
923 wmClass
.res_name
= name
;
924 wmClass
.res_class
= "MPlayer";
925 XSetClassHint(x11
->display
, window
, &wmClass
);
926 XChangeProperty(x11
->display
, window
, x11
->XA_NET_WM_PID
, XA_CARDINAL
,
927 32, PropModeReplace
, (unsigned char *) &pid
, 1);
930 void vo_x11_uninit(struct vo
*vo
)
932 struct vo_x11_state
*x11
= vo
->x11
;
933 saver_on(x11
->display
);
934 if (x11
->window
!= None
)
935 vo_showcursor(x11
->display
, x11
->window
);
939 XFreeGC(vo
->x11
->display
, x11
->f_gc
);
943 /* destroy window only if it's not controlled by the GUI */
949 XSetBackground(vo
->x11
->display
, x11
->vo_gc
, 0);
950 XFreeGC(vo
->x11
->display
, x11
->vo_gc
);
953 if (x11
->window
!= None
)
955 XClearWindow(x11
->display
, x11
->window
);
960 XUnmapWindow(x11
->display
, x11
->window
);
961 XDestroyWindow(x11
->display
, x11
->window
);
964 XNextEvent(x11
->display
, &xev
);
966 while (xev
.type
!= DestroyNotify
967 || xev
.xdestroywindow
.event
!= x11
->window
);
972 x11
->vo_old_width
= x11
->vo_old_height
= 0;
976 int vo_x11_check_events(struct vo
*vo
)
978 struct vo_x11_state
*x11
= vo
->x11
;
979 struct MPOpts
*opts
= vo
->opts
;
980 Display
*display
= vo
->x11
->display
;
986 // unsigned long vo_KeyTable[512];
988 if ((x11
->vo_mouse_autohide
) && x11
->mouse_waiting_hide
&&
989 (GetTimerMS() - x11
->mouse_timer
>= 1000)) {
990 vo_hidecursor(display
, x11
->window
);
991 x11
->mouse_waiting_hide
= 0;
994 while (XPending(display
))
996 XNextEvent(display
, &Event
);
1000 guiGetEvent(0, (char *) &Event
);
1001 if (x11
->window
!= Event
.xany
.window
)
1005 // printf("\rEvent.type=%X \n",Event.type);
1009 ret
|= VO_EVENT_EXPOSE
;
1011 case ConfigureNotify
:
1012 // if (!vo_fs && (Event.xconfigure.width == opts->vo_screenwidth || Event.xconfigure.height == opts->vo_screenheight)) break;
1013 // if (vo_fs && Event.xconfigure.width != opts->vo_screenwidth && Event.xconfigure.height != opts->vo_screenheight) break;
1014 if (x11
->window
== None
)
1016 vo
->dwidth
= Event
.xconfigure
.width
;
1017 vo
->dheight
= Event
.xconfigure
.height
;
1019 /* when resizing, x and y are zero :( */
1020 vo
->dx
= Event
.xconfigure
.x
;
1021 vo
->dy
= Event
.xconfigure
.y
;
1028 XGetGeometry(display
, x11
->window
, &root
, &foo
, &foo
,
1029 &foo
/*width */ , &foo
/*height */ , &foo
,
1031 XTranslateCoordinates(display
, x11
->window
, root
, 0, 0,
1032 &vo
->dx
, &vo
->dy
, &win
);
1035 ret
|= VO_EVENT_RESIZE
;
1042 if ( use_gui
) { break; }
1045 XLookupString(&Event
.xkey
, buf
, sizeof(buf
), &keySym
,
1046 &x11
->compose_status
);
1047 #ifdef XF86XK_AudioPause
1048 vo_x11_putkey_ext(keySym
);
1051 ((keySym
& 0xff00) !=
1052 0 ? ((keySym
& 0x00ff) + 256) : (keySym
));
1054 ret
|= VO_EVENT_KEYPRESS
;
1058 if(enable_mouse_movements
)
1061 sprintf(cmd_str
,"set_mouse_pos %i %i",Event
.xmotion
.x
, Event
.xmotion
.y
);
1062 mp_input_queue_cmd(mp_input_parse_cmd(cmd_str
));
1065 if (x11
->vo_mouse_autohide
)
1067 vo_showcursor(display
, x11
->window
);
1068 x11
->mouse_waiting_hide
= 1;
1069 x11
->mouse_timer
= GetTimerMS();
1073 if (x11
->vo_mouse_autohide
)
1075 vo_showcursor(display
, x11
->window
);
1076 x11
->mouse_waiting_hide
= 1;
1077 x11
->mouse_timer
= GetTimerMS();
1080 // Ignore mouse button 1-3 under GUI.
1081 if (use_gui
&& (Event
.xbutton
.button
>= 1)
1082 && (Event
.xbutton
.button
<= 3))
1085 mplayer_put_key((MOUSE_BTN0
+ Event
.xbutton
.button
-
1089 if (x11
->vo_mouse_autohide
)
1091 vo_showcursor(display
, x11
->window
);
1092 x11
->mouse_waiting_hide
= 1;
1093 x11
->mouse_timer
= GetTimerMS();
1096 // Ignore mouse button 1-3 under GUI.
1097 if (use_gui
&& (Event
.xbutton
.button
>= 1)
1098 && (Event
.xbutton
.button
<= 3))
1101 mplayer_put_key(MOUSE_BTN0
+ Event
.xbutton
.button
- 1);
1103 case PropertyNotify
:
1106 XGetAtomName(display
, Event
.xproperty
.atom
);
1111 // fprintf(stderr,"[ws] PropertyNotify ( 0x%x ) %s ( 0x%x )\n",vo_window,name,Event.xproperty.atom );
1117 x11
->vo_hint
.win_gravity
= x11
->old_gravity
;
1118 XSetWMNormalHints(display
, x11
->window
, &x11
->vo_hint
);
1122 if (Event
.xclient
.message_type
== x11
->XAWM_PROTOCOLS
&&
1123 Event
.xclient
.data
.l
[0] == x11
->XAWM_DELETE_WINDOW
)
1124 mplayer_put_key(KEY_CLOSE_WIN
);
1132 * \brief sets the size and position of the non-fullscreen window.
1134 static void vo_x11_nofs_sizepos(struct vo
*vo
, int x
, int y
,
1135 int width
, int height
)
1137 struct vo_x11_state
*x11
= vo
->x11
;
1138 vo_x11_sizehint(vo
, x
, y
, width
, height
, 0);
1142 x11
->vo_old_width
= width
;
1143 x11
->vo_old_height
= height
;
1148 vo
->dheight
= height
;
1149 XMoveResizeWindow(vo
->x11
->display
, vo
->x11
->window
, x
, y
, width
, height
);
1153 void vo_x11_sizehint(struct vo
*vo
, int x
, int y
, int width
, int height
, int max
)
1155 struct vo_x11_state
*x11
= vo
->x11
;
1156 x11
->vo_hint
.flags
= 0;
1159 x11
->vo_hint
.flags
|= PAspect
;
1160 x11
->vo_hint
.min_aspect
.x
= width
;
1161 x11
->vo_hint
.min_aspect
.y
= height
;
1162 x11
->vo_hint
.max_aspect
.x
= width
;
1163 x11
->vo_hint
.max_aspect
.y
= height
;
1166 x11
->vo_hint
.flags
|= PPosition
| PSize
;
1169 x11
->vo_hint
.width
= width
;
1170 x11
->vo_hint
.height
= height
;
1173 x11
->vo_hint
.flags
|= PMaxSize
;
1174 x11
->vo_hint
.max_width
= width
;
1175 x11
->vo_hint
.max_height
= height
;
1178 x11
->vo_hint
.max_width
= 0;
1179 x11
->vo_hint
.max_height
= 0;
1182 // Set minimum height/width to 4 to avoid off-by-one errors
1183 // and because mga_vid requires a minimal size of 4 pixels.
1184 x11
->vo_hint
.flags
|= PMinSize
;
1185 x11
->vo_hint
.min_width
= x11
->vo_hint
.min_height
= 4;
1187 x11
->vo_hint
.flags
|= PWinGravity
;
1188 x11
->vo_hint
.win_gravity
= StaticGravity
;
1189 XSetWMNormalHints(x11
->display
, x11
->window
, &x11
->vo_hint
);
1192 static int vo_x11_get_gnome_layer(struct vo_x11_state
*x11
, Window win
)
1196 unsigned long nitems
;
1197 unsigned long bytesafter
;
1198 unsigned short *args
= NULL
;
1200 if (XGetWindowProperty(x11
->display
, win
, x11
->XA_WIN_LAYER
, 0, 16384,
1201 False
, AnyPropertyType
, &type
, &format
, &nitems
,
1203 (unsigned char **) &args
) == Success
1204 && nitems
> 0 && args
)
1206 mp_msg(MSGT_VO
, MSGL_V
, "[x11] original window layer is %d.\n",
1210 return WIN_LAYER_NORMAL
;
1214 static Window
vo_x11_create_smooth_window(struct vo_x11_state
*x11
, Window mRoot
,
1215 Visual
* vis
, int x
, int y
,
1216 unsigned int width
, unsigned int height
,
1217 int depth
, Colormap col_map
)
1219 unsigned long xswamask
= CWBackingStore
| CWBorderPixel
;
1220 XSetWindowAttributes xswa
;
1223 if (col_map
!= CopyFromParent
)
1225 xswa
.colormap
= col_map
;
1226 xswamask
|= CWColormap
;
1228 xswa
.background_pixel
= 0;
1229 xswa
.border_pixel
= 0;
1230 xswa
.backing_store
= Always
;
1231 xswa
.bit_gravity
= StaticGravity
;
1234 XCreateWindow(x11
->display
, x11
->rootwin
, x
, y
, width
, height
, 0, depth
,
1235 CopyFromParent
, vis
, xswamask
, &xswa
);
1236 XSetWMProtocols(x11
->display
, ret_win
, &x11
->XAWM_DELETE_WINDOW
, 1);
1238 x11
->f_gc
= XCreateGC(x11
->display
, ret_win
, 0, 0);
1239 XSetForeground(x11
->display
, x11
->f_gc
, 0);
1245 * \brief create and setup a window suitable for display
1246 * \param vis Visual to use for creating the window
1247 * \param x x position of window
1248 * \param y y position of window
1249 * \param width width of window
1250 * \param height height of window
1251 * \param flags flags for window creation.
1252 * Only VOFLAG_FULLSCREEN is supported so far.
1253 * \param col_map Colourmap for window or CopyFromParent if a specific colormap isn't needed
1254 * \param classname name to use for the classhint
1255 * \param title title for the window
1257 * This also does the grunt-work like setting Window Manager hints etc.
1258 * If vo_window is already set it just moves and resizes it.
1260 void vo_x11_create_vo_window(struct vo
*vo
, XVisualInfo
*vis
, int x
, int y
,
1261 unsigned int width
, unsigned int height
, int flags
,
1263 const char *classname
, const char *title
)
1265 struct MPOpts
*opts
= vo
->opts
;
1266 struct vo_x11_state
*x11
= vo
->x11
;
1267 Display
*mDisplay
= vo
->x11
->display
;
1268 if (x11
->window
== None
) {
1273 vo
->dheight
= height
;
1274 x11
->window
= vo_x11_create_smooth_window(x11
, x11
->rootwin
, vis
->visual
,
1275 x
, y
, width
, height
, vis
->depth
, col_map
);
1276 vo_x11_classhint(vo
, x11
->window
, classname
);
1277 XStoreName(mDisplay
, x11
->window
, title
);
1278 vo_hidecursor(mDisplay
, x11
->window
);
1279 XSelectInput(mDisplay
, x11
->window
, StructureNotifyMask
);
1280 hint
.x
= x
; hint
.y
= y
;
1281 hint
.width
= width
; hint
.height
= height
;
1282 hint
.flags
= PPosition
| PSize
;
1283 XSetStandardProperties(mDisplay
, x11
->window
, title
, title
, None
, NULL
, 0, &hint
);
1284 vo_x11_sizehint(vo
, x
, y
, width
, height
, 0);
1286 XMapWindow(mDisplay
, x11
->window
);
1287 XClearWindow(mDisplay
, x11
->window
);
1290 XNextEvent(mDisplay
, &xev
);
1291 } while (xev
.type
!= MapNotify
|| xev
.xmap
.event
!= x11
->window
);
1292 XSelectInput(mDisplay
, x11
->window
, NoEventMask
);
1293 XSync(mDisplay
, False
);
1294 vo_x11_selectinput_witherr(mDisplay
, x11
->window
,
1295 StructureNotifyMask
| KeyPressMask
| PointerMotionMask
|
1296 ButtonPressMask
| ButtonReleaseMask
| ExposureMask
);
1298 if (opts
->vo_ontop
) vo_x11_setlayer(vo
, x11
->window
, opts
->vo_ontop
);
1299 vo_x11_nofs_sizepos(vo
, vo
->dx
, vo
->dy
, width
, height
);
1300 if (!!vo_fs
!= !!(flags
& VOFLAG_FULLSCREEN
))
1301 vo_x11_fullscreen(vo
);
1304 void vo_x11_clearwindow_part(struct vo
*vo
, Window vo_window
,
1305 int img_width
, int img_height
, int use_fs
)
1307 struct vo_x11_state
*x11
= vo
->x11
;
1308 struct MPOpts
*opts
= vo
->opts
;
1309 Display
*mDisplay
= vo
->x11
->display
;
1310 int u_dheight
, u_dwidth
, left_ov
, left_ov2
;
1315 u_dheight
= use_fs
? opts
->vo_screenheight
: vo
->dheight
;
1316 u_dwidth
= use_fs
? opts
->vo_screenwidth
: vo
->dwidth
;
1317 if ((u_dheight
<= img_height
) && (u_dwidth
<= img_width
))
1320 left_ov
= (u_dheight
- img_height
) / 2;
1321 left_ov2
= (u_dwidth
- img_width
) / 2;
1323 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, 0, 0, u_dwidth
, left_ov
);
1324 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, 0, u_dheight
- left_ov
- 1,
1325 u_dwidth
, left_ov
+ 1);
1327 if (u_dwidth
> img_width
)
1329 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, 0, left_ov
, left_ov2
,
1331 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, u_dwidth
- left_ov2
- 1,
1332 left_ov
, left_ov2
+ 1, img_height
);
1338 void vo_x11_clearwindow(struct vo
*vo
, Window vo_window
)
1340 struct vo_x11_state
*x11
= vo
->x11
;
1341 struct MPOpts
*opts
= vo
->opts
;
1344 XFillRectangle(x11
->display
, vo_window
, x11
->f_gc
, 0, 0,
1345 opts
->vo_screenwidth
, opts
->vo_screenheight
);
1347 XFlush(x11
->display
);
1351 void vo_x11_setlayer(struct vo
*vo
, Window vo_window
, int layer
)
1353 struct vo_x11_state
*x11
= vo
->x11
;
1357 if (x11
->fs_type
& vo_wm_LAYER
)
1359 XClientMessageEvent xev
;
1361 if (!x11
->orig_layer
)
1362 x11
->orig_layer
= vo_x11_get_gnome_layer(x11
, vo_window
);
1364 memset(&xev
, 0, sizeof(xev
));
1365 xev
.type
= ClientMessage
;
1366 xev
.display
= x11
->display
;
1367 xev
.window
= vo_window
;
1368 xev
.message_type
= x11
->XA_WIN_LAYER
;
1370 xev
.data
.l
[0] = layer
? fs_layer
: x11
->orig_layer
; // if not fullscreen, stay on default layer
1371 xev
.data
.l
[1] = CurrentTime
;
1372 mp_msg(MSGT_VO
, MSGL_V
,
1373 "[x11] Layered style stay on top (layer %ld).\n",
1375 XSendEvent(x11
->display
, x11
->rootwin
, False
, SubstructureNotifyMask
,
1377 } else if (x11
->fs_type
& vo_wm_NETWM
)
1379 XClientMessageEvent xev
;
1382 memset(&xev
, 0, sizeof(xev
));
1383 xev
.type
= ClientMessage
;
1384 xev
.message_type
= x11
->XA_NET_WM_STATE
;
1385 xev
.display
= x11
->display
;
1386 xev
.window
= vo_window
;
1388 xev
.data
.l
[0] = layer
;
1390 if (x11
->fs_type
& vo_wm_STAYS_ON_TOP
)
1391 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_STAYS_ON_TOP
;
1392 else if (x11
->fs_type
& vo_wm_ABOVE
)
1393 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_ABOVE
;
1394 else if (x11
->fs_type
& vo_wm_FULLSCREEN
)
1395 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_FULLSCREEN
;
1396 else if (x11
->fs_type
& vo_wm_BELOW
)
1397 // This is not fallback. We can safely assume that the situation
1398 // where only NETWM_STATE_BELOW is supported doesn't exist.
1399 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_BELOW
;
1401 XSendEvent(x11
->display
, x11
->rootwin
, False
, SubstructureRedirectMask
,
1403 state
= XGetAtomName(x11
->display
, xev
.data
.l
[1]);
1404 mp_msg(MSGT_VO
, MSGL_V
,
1405 "[x11] NET style stay on top (layer %d). Using state %s.\n",
1411 static int vo_x11_get_fs_type(int supported
)
1414 int type
= supported
;
1419 for (i
= 0; vo_fstype_list
[i
]; i
++)
1422 char *arg
= vo_fstype_list
[i
];
1424 if (vo_fstype_list
[i
][0] == '-')
1427 arg
= vo_fstype_list
[i
] + 1;
1430 if (!strncmp(arg
, "layer", 5))
1432 if (!neg
&& (arg
[5] == '='))
1434 char *endptr
= NULL
;
1435 int layer
= strtol(vo_fstype_list
[i
] + 6, &endptr
, 10);
1437 if (endptr
&& *endptr
== '\0' && layer
>= 0
1442 type
&= ~vo_wm_LAYER
;
1444 type
|= vo_wm_LAYER
;
1445 } else if (!strcmp(arg
, "above"))
1448 type
&= ~vo_wm_ABOVE
;
1450 type
|= vo_wm_ABOVE
;
1451 } else if (!strcmp(arg
, "fullscreen"))
1454 type
&= ~vo_wm_FULLSCREEN
;
1456 type
|= vo_wm_FULLSCREEN
;
1457 } else if (!strcmp(arg
, "stays_on_top"))
1460 type
&= ~vo_wm_STAYS_ON_TOP
;
1462 type
|= vo_wm_STAYS_ON_TOP
;
1463 } else if (!strcmp(arg
, "below"))
1466 type
&= ~vo_wm_BELOW
;
1468 type
|= vo_wm_BELOW
;
1469 } else if (!strcmp(arg
, "netwm"))
1472 type
&= ~vo_wm_NETWM
;
1474 type
|= vo_wm_NETWM
;
1475 } else if (!strcmp(arg
, "none"))
1483 void vo_x11_fullscreen(struct vo
*vo
)
1485 struct MPOpts
*opts
= vo
->opts
;
1486 struct vo_x11_state
*x11
= vo
->x11
;
1489 if (WinID
>= 0 || x11
->fs_flip
)
1495 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1499 w
= x11
->vo_old_width
;
1500 h
= x11
->vo_old_height
;
1503 vo_x11_ewmh_fullscreen(x11
, _NET_WM_STATE_REMOVE
); // removes fullscreen state if wm supports EWMH
1508 vo_x11_ewmh_fullscreen(x11
, _NET_WM_STATE_ADD
); // sends fullscreen state to be added if wm supports EWMH
1511 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1513 x11
->vo_old_x
= vo
->dx
;
1514 x11
->vo_old_y
= vo
->dy
;
1515 x11
->vo_old_width
= vo
->dwidth
;
1516 x11
->vo_old_height
= vo
->dheight
;
1518 update_xinerama_info(vo
);
1521 w
= opts
->vo_screenwidth
;
1522 h
= opts
->vo_screenheight
;
1527 XGetWMNormalHints(x11
->display
, x11
->window
, &x11
->vo_hint
, &dummy
);
1528 if (!(x11
->vo_hint
.flags
& PWinGravity
))
1529 x11
->old_gravity
= NorthWestGravity
;
1531 x11
->old_gravity
= x11
->vo_hint
.win_gravity
;
1533 if (x11
->wm_type
== 0 && !(vo_fsmode
& 16))
1535 XUnmapWindow(x11
->display
, x11
->window
); // required for MWM
1536 XWithdrawWindow(x11
->display
, x11
->window
, x11
->screen
);
1540 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1542 vo_x11_decoration(vo
, (vo_fs
) ? 0 : 1);
1543 vo_x11_sizehint(vo
, x
, y
, w
, h
, 0);
1544 vo_x11_setlayer(vo
, x11
->window
, vo_fs
);
1547 XMoveResizeWindow(x11
->display
, x11
->window
, x
, y
, w
, h
);
1549 /* some WMs lose ontop after fullscreen */
1550 if ((!(vo_fs
)) & opts
->vo_ontop
)
1551 vo_x11_setlayer(vo
, x11
->window
, opts
->vo_ontop
);
1553 XMapRaised(x11
->display
, x11
->window
);
1554 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // some WMs change window pos on map
1555 XMoveResizeWindow(x11
->display
, x11
->window
, x
, y
, w
, h
);
1556 XRaiseWindow(x11
->display
, x11
->window
);
1557 XFlush(x11
->display
);
1560 void vo_x11_ontop(struct vo
*vo
)
1562 struct MPOpts
*opts
= vo
->opts
;
1563 opts
->vo_ontop
= !opts
->vo_ontop
;
1565 vo_x11_setlayer(vo
, vo
->x11
->window
, opts
->vo_ontop
);
1569 * XScreensaver stuff
1572 static int screensaver_off
;
1573 static unsigned int time_last
;
1575 void xscreensaver_heartbeat(struct vo_x11_state
*x11
)
1577 unsigned int time
= GetTimerMS();
1579 if (x11
->display
&& screensaver_off
&& (time
- time_last
) > 30000)
1583 XResetScreenSaver(x11
->display
);
1587 static int xss_suspend(Display
*mDisplay
, Bool suspend
)
1592 int event
, error
, major
, minor
;
1593 if (XScreenSaverQueryExtension(mDisplay
, &event
, &error
) != True
||
1594 XScreenSaverQueryVersion(mDisplay
, &major
, &minor
) != True
)
1596 if (major
< 1 || major
== 1 && minor
< 1)
1598 XScreenSaverSuspend(mDisplay
, suspend
);
1604 * End of XScreensaver stuff
1607 static void saver_on(Display
* mDisplay
)
1610 if (!screensaver_off
)
1612 screensaver_off
= 0;
1613 if (xss_suspend(mDisplay
, False
))
1619 if (DPMSQueryExtension(mDisplay
, ¬hing
, ¬hing
))
1621 if (!DPMSEnable(mDisplay
))
1622 { // restoring power saving settings
1623 mp_msg(MSGT_VO
, MSGL_WARN
, "DPMS not available?\n");
1626 // DPMS does not seem to be enabled unless we call DPMSInfo
1630 DPMSForceLevel(mDisplay
, DPMSModeOn
);
1631 DPMSInfo(mDisplay
, &state
, &onoff
);
1634 mp_msg(MSGT_VO
, MSGL_V
,
1635 "Successfully enabled DPMS\n");
1638 mp_msg(MSGT_VO
, MSGL_WARN
, "Could not enable DPMS\n");
1647 static void saver_off(Display
* mDisplay
)
1651 if (screensaver_off
)
1653 screensaver_off
= 1;
1654 if (xss_suspend(mDisplay
, True
))
1657 if (DPMSQueryExtension(mDisplay
, ¬hing
, ¬hing
))
1662 DPMSInfo(mDisplay
, &state
, &onoff
);
1667 mp_msg(MSGT_VO
, MSGL_V
, "Disabling DPMS\n");
1669 stat
= DPMSDisable(mDisplay
); // monitor powersave off
1670 mp_msg(MSGT_VO
, MSGL_V
, "DPMSDisable stat: %d\n", stat
);
1676 static XErrorHandler old_handler
= NULL
;
1677 static int selectinput_err
= 0;
1678 static int x11_selectinput_errorhandler(Display
* display
,
1679 XErrorEvent
* event
)
1681 if (event
->error_code
== BadAccess
)
1683 selectinput_err
= 1;
1684 mp_msg(MSGT_VO
, MSGL_ERR
,
1685 "X11 error: BadAccess during XSelectInput Call\n");
1686 mp_msg(MSGT_VO
, MSGL_ERR
,
1687 "X11 error: The 'ButtonPressMask' mask of specified window has probably already used by another appication (see man XSelectInput)\n");
1688 /* If you think MPlayer should shutdown with this error,
1689 * comment out the following line */
1692 if (old_handler
!= NULL
)
1693 old_handler(display
, event
);
1695 x11_errorhandler(display
, event
);
1699 void vo_x11_selectinput_witherr(Display
* display
, Window w
,
1702 XSync(display
, False
);
1703 old_handler
= XSetErrorHandler(x11_selectinput_errorhandler
);
1704 selectinput_err
= 0;
1705 if (vo_nomouse_input
)
1707 XSelectInput(display
, w
,
1709 (~(ButtonPressMask
| ButtonReleaseMask
)));
1712 XSelectInput(display
, w
, event_mask
);
1714 XSync(display
, False
);
1715 XSetErrorHandler(old_handler
);
1716 if (selectinput_err
)
1718 mp_msg(MSGT_VO
, MSGL_ERR
,
1719 "X11 error: MPlayer discards mouse control (reconfiguring)\n");
1720 XSelectInput(display
, w
,
1723 (ButtonPressMask
| ButtonReleaseMask
|
1724 PointerMotionMask
)));
1729 void vo_vm_switch(struct vo
*vo
, uint32_t X
, uint32_t Y
, int *modeline_width
,
1730 int *modeline_height
)
1732 struct vo_x11_state
*x11
= vo
->x11
;
1733 struct MPOpts
*opts
= vo
->opts
;
1734 Display
*mDisplay
= x11
->display
;
1735 int vm_event
, vm_error
;
1737 int i
, j
, have_vm
= 0;
1741 if (XF86VidModeQueryExtension(mDisplay
, &vm_event
, &vm_error
))
1743 XF86VidModeQueryVersion(mDisplay
, &vm_ver
, &vm_rev
);
1744 mp_msg(MSGT_VO
, MSGL_V
, "XF86VidMode extension v%i.%i\n", vm_ver
,
1748 mp_msg(MSGT_VO
, MSGL_WARN
,
1749 "XF86VidMode extension not available.\n");
1753 if (vidmodes
== NULL
)
1754 XF86VidModeGetAllModeLines(mDisplay
, x11
->screen
, &modecount
,
1757 *modeline_width
= vidmodes
[0]->hdisplay
;
1758 *modeline_height
= vidmodes
[0]->vdisplay
;
1760 for (i
= 1; i
< modecount
; i
++)
1761 if ((vidmodes
[i
]->hdisplay
>= X
)
1762 && (vidmodes
[i
]->vdisplay
>= Y
))
1763 if ((vidmodes
[i
]->hdisplay
<= *modeline_width
)
1764 && (vidmodes
[i
]->vdisplay
<= *modeline_height
))
1766 *modeline_width
= vidmodes
[i
]->hdisplay
;
1767 *modeline_height
= vidmodes
[i
]->vdisplay
;
1771 mp_msg(MSGT_VO
, MSGL_INFO
, MSGTR_SelectedVideoMode
,
1772 *modeline_width
, *modeline_height
, X
, Y
);
1773 XF86VidModeLockModeSwitch(mDisplay
, x11
->screen
, 0);
1774 XF86VidModeSwitchToMode(mDisplay
, x11
->screen
, vidmodes
[j
]);
1775 XF86VidModeSwitchToMode(mDisplay
, x11
->screen
, vidmodes
[j
]);
1776 X
= (opts
->vo_screenwidth
- *modeline_width
) / 2;
1777 Y
= (opts
->vo_screenheight
- *modeline_height
) / 2;
1778 XF86VidModeSetViewPort(mDisplay
, x11
->screen
, X
, Y
);
1782 void vo_vm_close(struct vo
*vo
)
1784 Display
*dpy
= vo
->x11
->display
;
1785 struct MPOpts
*opts
= vo
->opts
;
1787 if (vidmodes
!= NULL
&& vo
->x11
->vo_window
!= None
)
1789 if (vidmodes
!= NULL
)
1795 screen
= DefaultScreen(dpy
);
1799 XF86VidModeGetAllModeLines(dpy
, vo
->x11
->screen
, &modecount
,
1801 for (i
= 0; i
< modecount
; i
++)
1802 if ((vidmodes
[i
]->hdisplay
== opts
->vo_screenwidth
)
1803 && (vidmodes
[i
]->vdisplay
== opts
->vo_screenheight
))
1805 mp_msg(MSGT_VO
, MSGL_INFO
,
1806 "Returning to original mode %dx%d\n",
1807 opts
->vo_screenwidth
, opts
->vo_screenheight
);
1811 XF86VidModeSwitchToMode(dpy
, screen
, vidmodes
[i
]);
1812 XF86VidModeSwitchToMode(dpy
, screen
, vidmodes
[i
]);
1819 #endif /* X11_FULLSCREEN */
1823 * Scan the available visuals on this Display/Screen. Try to find
1824 * the 'best' available TrueColor visual that has a decent color
1825 * depth (at least 15bit). If there are multiple visuals with depth
1826 * >= 15bit, we prefer visuals with a smaller color depth.
1828 int vo_find_depth_from_visuals(Display
* dpy
, int screen
,
1829 Visual
** visual_return
)
1831 XVisualInfo visual_tmpl
;
1832 XVisualInfo
*visuals
;
1834 int bestvisual
= -1;
1835 int bestvisual_depth
= -1;
1837 visual_tmpl
.screen
= screen
;
1838 visual_tmpl
.class = TrueColor
;
1839 visuals
= XGetVisualInfo(dpy
,
1840 VisualScreenMask
| VisualClassMask
,
1841 &visual_tmpl
, &nvisuals
);
1842 if (visuals
!= NULL
)
1844 for (i
= 0; i
< nvisuals
; i
++)
1846 mp_msg(MSGT_VO
, MSGL_V
,
1847 "vo: X11 truecolor visual %#lx, depth %d, R:%lX G:%lX B:%lX\n",
1848 visuals
[i
].visualid
, visuals
[i
].depth
,
1849 visuals
[i
].red_mask
, visuals
[i
].green_mask
,
1850 visuals
[i
].blue_mask
);
1852 * Save the visual index and its depth, if this is the first
1853 * truecolor visul, or a visual that is 'preferred' over the
1854 * previous 'best' visual.
1856 if (bestvisual_depth
== -1
1857 || (visuals
[i
].depth
>= 15
1858 && (visuals
[i
].depth
< bestvisual_depth
1859 || bestvisual_depth
< 15)))
1862 bestvisual_depth
= visuals
[i
].depth
;
1866 if (bestvisual
!= -1 && visual_return
!= NULL
)
1867 *visual_return
= visuals
[bestvisual
].visual
;
1871 return bestvisual_depth
;
1875 static Colormap cmap
= None
;
1876 static XColor cols
[256];
1877 static int cm_size
, red_mask
, green_mask
, blue_mask
;
1880 Colormap
vo_x11_create_colormap(struct vo
*vo
, XVisualInfo
*vinfo
)
1882 struct vo_x11_state
*x11
= vo
->x11
;
1883 unsigned k
, r
, g
, b
, ru
, gu
, bu
, m
, rv
, gv
, bv
, rvu
, gvu
, bvu
;
1885 if (vinfo
->class != DirectColor
)
1886 return XCreateColormap(x11
->display
, x11
->rootwin
, vinfo
->visual
,
1889 /* can this function get called twice or more? */
1892 cm_size
= vinfo
->colormap_size
;
1893 red_mask
= vinfo
->red_mask
;
1894 green_mask
= vinfo
->green_mask
;
1895 blue_mask
= vinfo
->blue_mask
;
1896 ru
= (red_mask
& (red_mask
- 1)) ^ red_mask
;
1897 gu
= (green_mask
& (green_mask
- 1)) ^ green_mask
;
1898 bu
= (blue_mask
& (blue_mask
- 1)) ^ blue_mask
;
1899 rvu
= 65536ull * ru
/ (red_mask
+ ru
);
1900 gvu
= 65536ull * gu
/ (green_mask
+ gu
);
1901 bvu
= 65536ull * bu
/ (blue_mask
+ bu
);
1904 m
= DoRed
| DoGreen
| DoBlue
;
1905 for (k
= 0; k
< cm_size
; k
++)
1909 cols
[k
].pixel
= r
| g
| b
;
1914 t
= (r
+ ru
) & red_mask
;
1918 t
= (g
+ gu
) & green_mask
;
1922 t
= (b
+ bu
) & blue_mask
;
1930 cmap
= XCreateColormap(x11
->display
, x11
->rootwin
, vinfo
->visual
, AllocAll
);
1931 XStoreColors(x11
->display
, cmap
, cols
, cm_size
);
1936 * Via colormaps/gamma ramps we can do gamma, brightness, contrast,
1937 * hue and red/green/blue intensity, but we cannot do saturation.
1938 * Currently only gamma, brightness and contrast are implemented.
1939 * Is there sufficient interest for hue and/or red/green/blue intensity?
1941 /* these values have range [-100,100] and are initially 0 */
1942 static int vo_gamma
= 0;
1943 static int vo_brightness
= 0;
1944 static int vo_contrast
= 0;
1946 static int transform_color(float val
,
1947 float brightness
, float contrast
, float gamma
) {
1948 float s
= pow(val
, gamma
);
1949 s
= (s
- 0.5) * contrast
+ 0.5;
1955 return (unsigned short) (s
* 65535);
1958 uint32_t vo_x11_set_equalizer(struct vo
*vo
, char *name
, int value
)
1960 float gamma
, brightness
, contrast
;
1965 * IMPLEMENTME: consider using XF86VidModeSetGammaRamp in the case
1966 * of TrueColor-ed window but be careful:
1967 * Unlike the colormaps, which are private for the X client
1968 * who created them and thus automatically destroyed on client
1969 * disconnect, this gamma ramp is a system-wide (X-server-wide)
1970 * setting and _must_ be restored before the process exits.
1971 * Unforunately when the process crashes (or gets killed
1972 * for some reason) it is impossible to restore the setting,
1973 * and such behaviour could be rather annoying for the users.
1978 if (!strcasecmp(name
, "brightness"))
1979 vo_brightness
= value
;
1980 else if (!strcasecmp(name
, "contrast"))
1981 vo_contrast
= value
;
1982 else if (!strcasecmp(name
, "gamma"))
1987 brightness
= 0.01 * vo_brightness
;
1988 contrast
= tan(0.0095 * (vo_contrast
+ 100) * M_PI
/ 4);
1989 gamma
= pow(2, -0.02 * vo_gamma
);
1991 rf
= (float) ((red_mask
& (red_mask
- 1)) ^ red_mask
) / red_mask
;
1992 gf
= (float) ((green_mask
& (green_mask
- 1)) ^ green_mask
) /
1994 bf
= (float) ((blue_mask
& (blue_mask
- 1)) ^ blue_mask
) / blue_mask
;
1996 /* now recalculate the colormap using the newly set value */
1997 for (k
= 0; k
< cm_size
; k
++)
1999 cols
[k
].red
= transform_color(rf
* k
, brightness
, contrast
, gamma
);
2000 cols
[k
].green
= transform_color(gf
* k
, brightness
, contrast
, gamma
);
2001 cols
[k
].blue
= transform_color(bf
* k
, brightness
, contrast
, gamma
);
2004 XStoreColors(vo
->x11
->display
, cmap
, cols
, cm_size
);
2005 XFlush(vo
->x11
->display
);
2009 uint32_t vo_x11_get_equalizer(char *name
, int *value
)
2013 if (!strcasecmp(name
, "brightness"))
2014 *value
= vo_brightness
;
2015 else if (!strcasecmp(name
, "contrast"))
2016 *value
= vo_contrast
;
2017 else if (!strcasecmp(name
, "gamma"))
2025 int vo_xv_set_eq(struct vo
*vo
, uint32_t xv_port
, char *name
, int value
)
2027 XvAttribute
*attributes
;
2028 int i
, howmany
, xv_atom
;
2030 mp_dbg(MSGT_VO
, MSGL_V
, "xv_set_eq called! (%s, %d)\n", name
, value
);
2032 /* get available attributes */
2033 attributes
= XvQueryPortAttributes(vo
->x11
->display
, xv_port
, &howmany
);
2034 for (i
= 0; i
< howmany
&& attributes
; i
++)
2035 if (attributes
[i
].flags
& XvSettable
)
2037 xv_atom
= XInternAtom(vo
->x11
->display
, attributes
[i
].name
, True
);
2038 /* since we have SET_DEFAULTS first in our list, we can check if it's available
2039 then trigger it if it's ok so that the other values are at default upon query */
2040 if (xv_atom
!= None
)
2042 int hue
= 0, port_value
, port_min
, port_max
;
2044 if (!strcmp(attributes
[i
].name
, "XV_BRIGHTNESS") &&
2045 (!strcasecmp(name
, "brightness")))
2047 else if (!strcmp(attributes
[i
].name
, "XV_CONTRAST") &&
2048 (!strcasecmp(name
, "contrast")))
2050 else if (!strcmp(attributes
[i
].name
, "XV_SATURATION") &&
2051 (!strcasecmp(name
, "saturation")))
2053 else if (!strcmp(attributes
[i
].name
, "XV_HUE") &&
2054 (!strcasecmp(name
, "hue")))
2059 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
2060 if (!strcmp(attributes
[i
].name
, "XV_RED_INTENSITY") &&
2061 (!strcasecmp(name
, "red_intensity")))
2063 else if (!strcmp(attributes
[i
].name
, "XV_GREEN_INTENSITY")
2064 && (!strcasecmp(name
, "green_intensity")))
2066 else if (!strcmp(attributes
[i
].name
, "XV_BLUE_INTENSITY")
2067 && (!strcasecmp(name
, "blue_intensity")))
2072 port_min
= attributes
[i
].min_value
;
2073 port_max
= attributes
[i
].max_value
;
2075 /* nvidia hue workaround */
2076 if (hue
&& port_min
== 0 && port_max
== 360)
2080 0) ? (port_value
- 100) : (port_value
+ 100);
2086 (port_value
+ 100) * (port_max
- port_min
) / 200 +
2088 XvSetPortAttribute(vo
->x11
->display
, xv_port
, xv_atom
, port_value
);
2095 int vo_xv_get_eq(struct vo
*vo
, uint32_t xv_port
, char *name
, int *value
)
2098 XvAttribute
*attributes
;
2099 int i
, howmany
, xv_atom
;
2101 /* get available attributes */
2102 attributes
= XvQueryPortAttributes(vo
->x11
->display
, xv_port
, &howmany
);
2103 for (i
= 0; i
< howmany
&& attributes
; i
++)
2104 if (attributes
[i
].flags
& XvGettable
)
2106 xv_atom
= XInternAtom(vo
->x11
->display
, attributes
[i
].name
, True
);
2107 /* since we have SET_DEFAULTS first in our list, we can check if it's available
2108 then trigger it if it's ok so that the other values are at default upon query */
2109 if (xv_atom
!= None
)
2111 int val
, port_value
= 0, port_min
, port_max
;
2113 XvGetPortAttribute(vo
->x11
->display
, xv_port
, xv_atom
,
2116 port_min
= attributes
[i
].min_value
;
2117 port_max
= attributes
[i
].max_value
;
2119 (port_value
- port_min
) * 200 / (port_max
- port_min
) -
2122 if (!strcmp(attributes
[i
].name
, "XV_BRIGHTNESS") &&
2123 (!strcasecmp(name
, "brightness")))
2125 else if (!strcmp(attributes
[i
].name
, "XV_CONTRAST") &&
2126 (!strcasecmp(name
, "contrast")))
2128 else if (!strcmp(attributes
[i
].name
, "XV_SATURATION") &&
2129 (!strcasecmp(name
, "saturation")))
2131 else if (!strcmp(attributes
[i
].name
, "XV_HUE") &&
2132 (!strcasecmp(name
, "hue")))
2134 /* nasty nvidia detect */
2135 if (port_min
== 0 && port_max
== 360)
2136 *value
= (val
>= 0) ? (val
- 100) : (val
+ 100);
2140 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
2141 if (!strcmp(attributes
[i
].name
, "XV_RED_INTENSITY") &&
2142 (!strcasecmp(name
, "red_intensity")))
2144 else if (!strcmp(attributes
[i
].name
, "XV_GREEN_INTENSITY")
2145 && (!strcasecmp(name
, "green_intensity")))
2147 else if (!strcmp(attributes
[i
].name
, "XV_BLUE_INTENSITY")
2148 && (!strcasecmp(name
, "blue_intensity")))
2153 mp_dbg(MSGT_VO
, MSGL_V
, "xv_get_eq called! (%s, %d)\n",
2162 * \brief Interns the requested atom if it is available.
2164 * \param atom_name String containing the name of the requested atom.
2166 * \return Returns the atom if available, else None is returned.
2169 static Atom
xv_intern_atom_if_exists(struct vo_x11_state
*x11
,
2170 char const *atom_name
)
2172 XvAttribute
* attributes
;
2174 Atom xv_atom
= None
;
2176 attributes
= XvQueryPortAttributes(x11
->display
, x11
->xv_port
, &attrib_count
);
2177 if( attributes
!=NULL
)
2179 for ( i
= 0; i
< attrib_count
; ++i
)
2181 if ( strcmp(attributes
[i
].name
, atom_name
) == 0 )
2183 xv_atom
= XInternAtom(x11
->display
, atom_name
, False
);
2184 break; // found what we want, break out
2187 XFree( attributes
);
2194 * \brief Try to enable vsync for xv.
2195 * \return Returns -1 if not available, 0 on failure and 1 on success.
2197 int vo_xv_enable_vsync(struct vo
*vo
)
2199 struct vo_x11_state
*x11
= vo
->x11
;
2200 Atom xv_atom
= xv_intern_atom_if_exists(x11
, "XV_SYNC_TO_VBLANK");
2201 if (xv_atom
== None
)
2203 return XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, 1) == Success
;
2207 * \brief Get maximum supported source image dimensions.
2209 * This function does not set the variables pointed to by
2210 * width and height if the information could not be retrieved,
2211 * so the caller is reponsible for properly initializing them.
2213 * \param width [out] The maximum width gets stored here.
2214 * \param height [out] The maximum height gets stored here.
2217 void vo_xv_get_max_img_dim(struct vo
*vo
, uint32_t * width
, uint32_t * height
)
2219 struct vo_x11_state
*x11
= vo
->x11
;
2220 XvEncodingInfo
* encodings
;
2221 //unsigned long num_encodings, idx; to int or too long?!
2222 unsigned int num_encodings
, idx
;
2224 XvQueryEncodings(x11
->display
, x11
->xv_port
, &num_encodings
, &encodings
);
2228 for ( idx
= 0; idx
< num_encodings
; ++idx
)
2230 if ( strcmp( encodings
[idx
].name
, "XV_IMAGE" ) == 0 )
2232 *width
= encodings
[idx
].width
;
2233 *height
= encodings
[idx
].height
;
2239 mp_msg( MSGT_VO
, MSGL_V
,
2240 "[xv common] Maximum source image dimensions: %ux%u\n",
2243 XvFreeEncodingInfo( encodings
);
2247 * \brief Print information about the colorkey method and source.
2249 * \param ck_handling Integer value containing the information about
2250 * colorkey handling (see x11_common.h).
2252 * Outputs the content of |ck_handling| as a readable message.
2255 static void vo_xv_print_ck_info(struct vo_x11_state
*x11
)
2257 mp_msg( MSGT_VO
, MSGL_V
, "[xv common] " );
2259 switch ( x11
->xv_ck_info
.method
)
2261 case CK_METHOD_NONE
:
2262 mp_msg( MSGT_VO
, MSGL_V
, "Drawing no colorkey.\n" ); return;
2263 case CK_METHOD_AUTOPAINT
:
2264 mp_msg( MSGT_VO
, MSGL_V
, "Colorkey is drawn by Xv." ); break;
2265 case CK_METHOD_MANUALFILL
:
2266 mp_msg( MSGT_VO
, MSGL_V
, "Drawing colorkey manually." ); break;
2267 case CK_METHOD_BACKGROUND
:
2268 mp_msg( MSGT_VO
, MSGL_V
, "Colorkey is drawn as window background." ); break;
2271 mp_msg( MSGT_VO
, MSGL_V
, "\n[xv common] " );
2273 switch ( x11
->xv_ck_info
.source
)
2276 mp_msg( MSGT_VO
, MSGL_V
, "Using colorkey from Xv (0x%06lx).\n",
2280 if ( x11
->xv_ck_info
.method
== CK_METHOD_AUTOPAINT
)
2282 mp_msg( MSGT_VO
, MSGL_V
,
2283 "Ignoring colorkey from MPlayer (0x%06lx).\n",
2288 mp_msg( MSGT_VO
, MSGL_V
,
2289 "Using colorkey from MPlayer (0x%06lx)."
2290 " Use -colorkey to change.\n",
2295 mp_msg( MSGT_VO
, MSGL_V
,
2296 "Setting and using colorkey from MPlayer (0x%06lx)."
2297 " Use -colorkey to change.\n",
2303 * \brief Init colorkey depending on the settings in xv_ck_info.
2305 * \return Returns 0 on failure and 1 on success.
2307 * Sets the colorkey variable according to the CK_SRC_* and CK_METHOD_*
2308 * flags in xv_ck_info.
2312 * - manual colorkey drawing ( CK_METHOD_MANUALFILL )
2313 * - set colorkey as window background ( CK_METHOD_BACKGROUND )
2314 * - let Xv paint the colorkey ( CK_METHOD_AUTOPAINT )
2316 * - use currently set colorkey ( CK_SRC_CUR )
2317 * - use colorkey in vo_colorkey ( CK_SRC_USE )
2318 * - use and set colorkey in vo_colorkey ( CK_SRC_SET )
2320 * NOTE: If vo_colorkey has bits set after the first 3 low order bytes
2321 * we don't draw anything as this means it was forced to off.
2323 int vo_xv_init_colorkey(struct vo
*vo
)
2325 struct vo_x11_state
*x11
= vo
->x11
;
2329 /* check if colorkeying is needed */
2330 xv_atom
= xv_intern_atom_if_exists(vo
->x11
, "XV_COLORKEY");
2332 /* if we have to deal with colorkeying ... */
2333 if( xv_atom
!= None
&& !(vo_colorkey
& 0xFF000000) )
2335 /* check if we should use the colorkey specified in vo_colorkey */
2336 if ( x11
->xv_ck_info
.source
!= CK_SRC_CUR
)
2338 x11
->xv_colorkey
= vo_colorkey
;
2340 /* check if we have to set the colorkey too */
2341 if ( x11
->xv_ck_info
.source
== CK_SRC_SET
)
2343 xv_atom
= XInternAtom(x11
->display
, "XV_COLORKEY",False
);
2345 rez
= XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, vo_colorkey
);
2346 if ( rez
!= Success
)
2348 mp_msg( MSGT_VO
, MSGL_FATAL
,
2349 "[xv common] Couldn't set colorkey!\n" );
2350 return 0; // error setting colorkey
2358 rez
=XvGetPortAttribute(x11
->display
,x11
->xv_port
, xv_atom
, &colorkey_ret
);
2359 if ( rez
== Success
)
2361 x11
->xv_colorkey
= colorkey_ret
;
2365 mp_msg( MSGT_VO
, MSGL_FATAL
,
2366 "[xv common] Couldn't get colorkey!"
2367 "Maybe the selected Xv port has no overlay.\n" );
2368 return 0; // error getting colorkey
2372 xv_atom
= xv_intern_atom_if_exists(vo
->x11
, "XV_AUTOPAINT_COLORKEY");
2374 /* should we draw the colorkey ourselves or activate autopainting? */
2375 if ( x11
->xv_ck_info
.method
== CK_METHOD_AUTOPAINT
)
2377 rez
= !Success
; // reset rez to something different than Success
2379 if ( xv_atom
!= None
) // autopaint is supported
2381 rez
= XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, 1);
2384 if ( rez
!= Success
)
2386 // fallback to manual colorkey drawing
2387 x11
->xv_ck_info
.method
= CK_METHOD_MANUALFILL
;
2390 else // disable colorkey autopainting if supported
2392 if ( xv_atom
!= None
) // we have autopaint attribute
2394 XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, 0);
2398 else // do no colorkey drawing at all
2400 x11
->xv_ck_info
.method
= CK_METHOD_NONE
;
2401 } /* end: should we draw colorkey */
2403 /* output information about the current colorkey settings */
2404 vo_xv_print_ck_info(x11
);
2406 return 1; // success
2410 * \brief Draw the colorkey on the video window.
2412 * Draws the colorkey depending on the set method ( colorkey_handling ).
2414 * Also draws the black bars ( when the video doesn't fit the display in
2415 * fullscreen ) separately, so they don't overlap with the video area.
2416 * It doesn't call XFlush.
2419 void vo_xv_draw_colorkey(struct vo
*vo
, int32_t x
, int32_t y
,
2420 int32_t w
, int32_t h
)
2422 struct MPOpts
*opts
= vo
->opts
;
2423 struct vo_x11_state
*x11
= vo
->x11
;
2424 if( x11
->xv_ck_info
.method
== CK_METHOD_MANUALFILL
||
2425 x11
->xv_ck_info
.method
== CK_METHOD_BACKGROUND
)//less tearing than XClearWindow()
2427 XSetForeground(x11
->display
, x11
->vo_gc
, x11
->xv_colorkey
);
2428 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2433 /* draw black bars if needed */
2434 /* TODO! move this to vo_x11_clearwindow_part() */
2437 XSetForeground(x11
->display
, x11
->vo_gc
, 0 );
2438 /* making non-overlap fills, requires 8 checks instead of 4 */
2440 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2442 opts
->vo_screenwidth
, y
);
2444 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2446 x
, opts
->vo_screenheight
);
2447 if (x
+ w
< opts
->vo_screenwidth
)
2448 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2450 opts
->vo_screenwidth
, opts
->vo_screenheight
);
2451 if (y
+ h
< opts
->vo_screenheight
)
2452 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2454 opts
->vo_screenwidth
, opts
->vo_screenheight
);
2458 /** \brief Tests if a valid argument for the ck suboption was given. */
2459 int xv_test_ck( void * arg
)
2461 strarg_t
* strarg
= (strarg_t
*)arg
;
2463 if ( strargcmp( strarg
, "use" ) == 0 ||
2464 strargcmp( strarg
, "set" ) == 0 ||
2465 strargcmp( strarg
, "cur" ) == 0 )
2472 /** \brief Tests if a valid arguments for the ck-method suboption was given. */
2473 int xv_test_ckm( void * arg
)
2475 strarg_t
* strarg
= (strarg_t
*)arg
;
2477 if ( strargcmp( strarg
, "bg" ) == 0 ||
2478 strargcmp( strarg
, "man" ) == 0 ||
2479 strargcmp( strarg
, "auto" ) == 0 )
2488 * \brief Modify the colorkey_handling var according to str
2490 * Checks if a valid pointer ( not NULL ) to the string
2491 * was given. And in that case modifies the colorkey_handling
2492 * var to reflect the requested behaviour.
2493 * If nothing happens the content of colorkey_handling stays
2496 * \param str Pointer to the string or NULL
2499 void xv_setup_colorkeyhandling(struct vo
*vo
, const char *ck_method_str
,
2502 struct vo_x11_state
*x11
= vo
->x11
;
2503 /* check if a valid pointer to the string was passed */
2506 if ( strncmp( ck_str
, "use", 3 ) == 0 )
2508 x11
->xv_ck_info
.source
= CK_SRC_USE
;
2510 else if ( strncmp( ck_str
, "set", 3 ) == 0 )
2512 x11
->xv_ck_info
.source
= CK_SRC_SET
;
2515 /* check if a valid pointer to the string was passed */
2516 if ( ck_method_str
)
2518 if ( strncmp( ck_method_str
, "bg", 2 ) == 0 )
2520 x11
->xv_ck_info
.method
= CK_METHOD_BACKGROUND
;
2522 else if ( strncmp( ck_method_str
, "man", 3 ) == 0 )
2524 x11
->xv_ck_info
.method
= CK_METHOD_MANUALFILL
;
2526 else if ( strncmp( ck_method_str
, "auto", 4 ) == 0 )
2528 x11
->xv_ck_info
.method
= CK_METHOD_AUTOPAINT
;
2535 void vo_x11_init_state(struct vo_x11_state
*s
)
2537 *s
= (struct vo_x11_state
){
2538 .xv_ck_info
= { CK_METHOD_MANUALFILL
, CK_SRC_CUR
},
2539 .olddecor
= MWM_DECOR_ALL
,
2540 .oldfuncs
= MWM_FUNC_MOVE
| MWM_FUNC_CLOSE
| MWM_FUNC_MINIMIZE
|
2541 MWM_FUNC_MAXIMIZE
| MWM_FUNC_RESIZE
,
2542 .old_gravity
= NorthWestGravity
,