10 #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/dpms.h>
35 #include <X11/extensions/Xinerama.h>
39 #include <X11/extensions/xf86vmode.h>
43 #include <X11/XF86keysym.h>
47 #include <X11/extensions/Xv.h>
48 #include <X11/extensions/Xvlib.h>
50 #include "subopt-helper.h"
53 #include "input/input.h"
54 #include "input/mouse.h"
57 #include "gui/interface.h"
61 #define WIN_LAYER_ONBOTTOM 2
62 #define WIN_LAYER_NORMAL 4
63 #define WIN_LAYER_ONTOP 6
64 #define WIN_LAYER_ABOVE_DOCK 10
66 extern int enable_mouse_movements
;
67 int fs_layer
= WIN_LAYER_ABOVE_DOCK
;
68 static int orig_layer
= 0;
69 static int old_gravity
= NorthWestGravity
;
71 int stop_xscreensaver
= 0;
73 static int dpms_disabled
= 0;
74 static int timeout_save
= 0;
75 static int kdescreensaver_was_running
= 0;
77 char *mDisplayName
= NULL
;
78 Display
*mDisplay
= NULL
;
83 /* output window id */
84 int vo_mouse_autohide
= 0;
86 int vo_fs_type
= 0; // needs to be accessible for GUI X11 code
87 static int vo_fs_flip
= 0;
88 char **vo_fstype_list
;
90 /* 1 means that the WM is metacity (broken as hell) */
91 int metacity_hack
= 0;
93 static Atom XA_NET_SUPPORTED
;
94 static Atom XA_NET_WM_STATE
;
95 static Atom XA_NET_WM_STATE_FULLSCREEN
;
96 static Atom XA_NET_WM_STATE_ABOVE
;
97 static Atom XA_NET_WM_STATE_STAYS_ON_TOP
;
98 static Atom XA_NET_WM_STATE_BELOW
;
99 static Atom XA_NET_WM_PID
;
100 static Atom XA_WIN_PROTOCOLS
;
101 static Atom XA_WIN_LAYER
;
102 static Atom XA_WIN_HINTS
;
103 static Atom XA_BLACKBOX_PID
;
104 static Atom XAWM_PROTOCOLS
;
105 static Atom XAWM_DELETE_WINDOW
;
107 #define XA_INIT(x) XA##x = XInternAtom(mDisplay, #x, False)
109 static int vo_old_x
= 0;
110 static int vo_old_y
= 0;
111 static int vo_old_width
= 0;
112 static int vo_old_height
= 0;
115 XF86VidModeModeInfo
**vidmodes
= NULL
;
116 XF86VidModeModeLine modeline
;
119 static int vo_x11_get_fs_type(int supported
);
123 * Sends the EWMH fullscreen state event.
125 * action: could be one of _NET_WM_STATE_REMOVE -- remove state
126 * _NET_WM_STATE_ADD -- add state
127 * _NET_WM_STATE_TOGGLE -- toggle
129 void vo_x11_ewmh_fullscreen(int action
)
131 assert(action
== _NET_WM_STATE_REMOVE
||
132 action
== _NET_WM_STATE_ADD
|| action
== _NET_WM_STATE_TOGGLE
);
134 if (vo_fs_type
& vo_wm_FULLSCREEN
)
138 /* init X event structure for _NET_WM_FULLSCREEN client message */
139 xev
.xclient
.type
= ClientMessage
;
140 xev
.xclient
.serial
= 0;
141 xev
.xclient
.send_event
= True
;
142 xev
.xclient
.message_type
= XInternAtom(mDisplay
,
143 "_NET_WM_STATE", False
);
144 xev
.xclient
.window
= vo_window
;
145 xev
.xclient
.format
= 32;
146 xev
.xclient
.data
.l
[0] = action
;
147 xev
.xclient
.data
.l
[1] = XInternAtom(mDisplay
,
148 "_NET_WM_STATE_FULLSCREEN",
150 xev
.xclient
.data
.l
[2] = 0;
151 xev
.xclient
.data
.l
[3] = 0;
152 xev
.xclient
.data
.l
[4] = 0;
154 /* finally send that damn thing */
155 if (!XSendEvent(mDisplay
, DefaultRootWindow(mDisplay
), False
,
156 SubstructureRedirectMask
| SubstructureNotifyMask
,
159 mp_msg(MSGT_VO
, MSGL_ERR
, MSGTR_EwmhFullscreenStateFailed
);
164 void vo_hidecursor(Display
* disp
, Window win
)
170 static char bm_no_data
[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
173 return; // do not hide if playing on the root window
175 colormap
= DefaultColormap(disp
, DefaultScreen(disp
));
176 if ( !XAllocNamedColor(disp
, colormap
, "black", &black
, &dummy
) )
178 return; // color alloc failed, give up
180 bm_no
= XCreateBitmapFromData(disp
, win
, bm_no_data
, 8, 8);
181 no_ptr
= XCreatePixmapCursor(disp
, bm_no
, bm_no
, &black
, &black
, 0, 0);
182 XDefineCursor(disp
, win
, no_ptr
);
183 XFreeCursor(disp
, no_ptr
);
185 XFreePixmap(disp
, bm_no
);
186 XFreeColors(disp
,colormap
,&black
.pixel
,1,0);
189 void vo_showcursor(Display
* disp
, Window win
)
193 XDefineCursor(disp
, win
, 0);
196 static int x11_errorhandler(Display
* display
, XErrorEvent
* event
)
201 XGetErrorText(display
, event
->error_code
, (char *) &msg
, MSGLEN
);
203 mp_msg(MSGT_VO
, MSGL_ERR
, "X11 error: %s\n", msg
);
205 mp_msg(MSGT_VO
, MSGL_V
,
206 "Type: %x, display: %p, resourceid: %lx, serial: %lx\n",
207 event
->type
, event
->display
, event
->resourceid
, event
->serial
);
208 mp_msg(MSGT_VO
, MSGL_V
,
209 "Error code: %x, request code: %x, minor code: %x\n",
210 event
->error_code
, event
->request_code
, event
->minor_code
);
213 //exit_player("X11 error");
218 void fstype_help(void)
220 mp_msg(MSGT_VO
, MSGL_INFO
, MSGTR_AvailableFsType
);
221 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FULL_SCREEN_TYPES\n");
223 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "none",
224 "don't set fullscreen window layer");
225 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "layer",
226 "use _WIN_LAYER hint with default layer");
227 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "layer=<0..15>",
228 "use _WIN_LAYER hint with a given layer number");
229 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "netwm",
230 "force NETWM style");
231 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "above",
232 "use _NETWM_STATE_ABOVE hint if available");
233 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "below",
234 "use _NETWM_STATE_BELOW hint if available");
235 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "fullscreen",
236 "use _NETWM_STATE_FULLSCREEN hint if availale");
237 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "stays_on_top",
238 "use _NETWM_STATE_STAYS_ON_TOP hint if available");
239 mp_msg(MSGT_VO
, MSGL_INFO
,
240 "You can also negate the settings with simply putting '-' in the beginning");
241 mp_msg(MSGT_VO
, MSGL_INFO
, "\n");
244 static void fstype_dump(int fstype
)
248 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Current fstype setting honours");
249 if (fstype
& vo_wm_LAYER
)
250 mp_msg(MSGT_VO
, MSGL_V
, " LAYER");
251 if (fstype
& vo_wm_FULLSCREEN
)
252 mp_msg(MSGT_VO
, MSGL_V
, " FULLSCREEN");
253 if (fstype
& vo_wm_STAYS_ON_TOP
)
254 mp_msg(MSGT_VO
, MSGL_V
, " STAYS_ON_TOP");
255 if (fstype
& vo_wm_ABOVE
)
256 mp_msg(MSGT_VO
, MSGL_V
, " ABOVE");
257 if (fstype
& vo_wm_BELOW
)
258 mp_msg(MSGT_VO
, MSGL_V
, " BELOW");
259 mp_msg(MSGT_VO
, MSGL_V
, " X atoms\n");
261 mp_msg(MSGT_VO
, MSGL_V
,
262 "[x11] Current fstype setting doesn't honour any X atoms\n");
265 static int net_wm_support_state_test(Atom atom
)
267 #define NET_WM_STATE_TEST(x) { if (atom == XA_NET_WM_STATE_##x) { mp_msg( MSGT_VO,MSGL_V, "[x11] Detected wm supports " #x " state.\n" ); return vo_wm_##x; } }
269 NET_WM_STATE_TEST(FULLSCREEN
);
270 NET_WM_STATE_TEST(ABOVE
);
271 NET_WM_STATE_TEST(STAYS_ON_TOP
);
272 NET_WM_STATE_TEST(BELOW
);
276 static int x11_get_property(Atom type
, Atom
** args
, unsigned long *nitems
)
279 unsigned long bytesafter
;
282 XGetWindowProperty(mDisplay
, mRootWin
, type
, 0, 16384, False
,
283 AnyPropertyType
, &type
, &format
, nitems
,
284 &bytesafter
, (unsigned char **) args
)
288 static int vo_wm_detect(void)
292 unsigned long nitems
;
298 // -- supports layers
299 if (x11_get_property(XA_WIN_PROTOCOLS
, &args
, &nitems
))
301 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Detected wm supports layers.\n");
302 for (i
= 0; i
< nitems
; i
++)
304 if (args
[i
] == XA_WIN_LAYER
)
309 /* metacity is the only window manager I know which reports
310 * supporting only the _WIN_LAYER hint in _WIN_PROTOCOLS.
311 * (what's more support for it is broken) */
315 if (wm
&& (metacity_hack
== 1))
317 // metacity claims to support layers, but it is not the truth :-)
319 mp_msg(MSGT_VO
, MSGL_V
,
320 "[x11] Using workaround for Metacity bugs.\n");
324 if (x11_get_property(XA_NET_SUPPORTED
, &args
, &nitems
))
326 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Detected wm supports NetWM.\n");
327 for (i
= 0; i
< nitems
; i
++)
328 wm
|= net_wm_support_state_test(args
[i
]);
331 // ugly hack for broken OpenBox _NET_WM_STATE_FULLSCREEN support
332 // (in their implementation it only changes internal window state, nothing more!!!)
333 if (wm
& vo_wm_FULLSCREEN
)
335 if (x11_get_property(XA_BLACKBOX_PID
, &args
, &nitems
))
337 mp_msg(MSGT_VO
, MSGL_V
,
338 "[x11] Detected wm is a broken OpenBox.\n");
339 wm
^= vo_wm_FULLSCREEN
;
347 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Unknown wm type...\n");
351 static void init_atoms(void)
353 XA_INIT(_NET_SUPPORTED
);
354 XA_INIT(_NET_WM_STATE
);
355 XA_INIT(_NET_WM_STATE_FULLSCREEN
);
356 XA_INIT(_NET_WM_STATE_ABOVE
);
357 XA_INIT(_NET_WM_STATE_STAYS_ON_TOP
);
358 XA_INIT(_NET_WM_STATE_BELOW
);
359 XA_INIT(_NET_WM_PID
);
360 XA_INIT(_WIN_PROTOCOLS
);
363 XA_INIT(_BLACKBOX_PID
);
364 XA_INIT(WM_PROTOCOLS
);
365 XA_INIT(WM_DELETE_WINDOW
);
368 void update_xinerama_info(void) {
369 int screen
= xinerama_screen
;
370 xinerama_x
= xinerama_y
= 0;
372 if (screen
>= -1 && XineramaIsActive(mDisplay
))
374 XineramaScreenInfo
*screens
;
377 screens
= XineramaQueryScreens(mDisplay
, &num_screens
);
378 if (screen
>= num_screens
)
379 screen
= num_screens
- 1;
381 int x
= vo_dx
+ vo_dwidth
/ 2;
382 int y
= vo_dy
+ vo_dheight
/ 2;
383 for (screen
= num_screens
- 1; screen
> 0; screen
--) {
384 int left
= screens
[screen
].x_org
;
385 int right
= left
+ screens
[screen
].width
;
386 int top
= screens
[screen
].y_org
;
387 int bottom
= top
+ screens
[screen
].height
;
388 if (left
<= x
&& x
<= right
&& top
<= y
&& y
<= bottom
)
394 vo_screenwidth
= screens
[screen
].width
;
395 vo_screenheight
= screens
[screen
].height
;
396 xinerama_x
= screens
[screen
].x_org
;
397 xinerama_y
= screens
[screen
].y_org
;
402 aspect_save_screenres(vo_screenwidth
, vo_screenheight
);
411 // char * DisplayName = ":0.0";
412 // Display * mDisplay;
413 XImage
*mXImage
= NULL
;
416 XWindowAttributes attribs
;
420 WinID
= 0; // use root window
422 if (vo_depthonscreen
)
425 return 1; // already called
428 XSetErrorHandler(x11_errorhandler
);
432 if (!(mDisplayName
= getenv("DISPLAY")))
433 mDisplayName
= strdup(":0.0");
435 dispName
= XDisplayName(mDisplayName
);
438 mp_msg(MSGT_VO
, MSGL_V
, "X11 opening display: %s\n", dispName
);
440 mDisplay
= XOpenDisplay(dispName
);
443 mp_msg(MSGT_VO
, MSGL_ERR
,
444 "vo: couldn't open the X11 display (%s)!\n", dispName
);
447 mScreen
= DefaultScreen(mDisplay
); // screen ID
448 mRootWin
= RootWindow(mDisplay
, mScreen
); // root window ID
456 XF86VidModeGetModeLine(mDisplay
, mScreen
, &clock
, &modeline
);
458 vo_screenwidth
= modeline
.hdisplay
;
459 if (!vo_screenheight
)
460 vo_screenheight
= modeline
.vdisplay
;
465 vo_screenwidth
= DisplayWidth(mDisplay
, mScreen
);
466 if (!vo_screenheight
)
467 vo_screenheight
= DisplayHeight(mDisplay
, mScreen
);
469 // get color depth (from root window, or the best visual):
470 XGetWindowAttributes(mDisplay
, mRootWin
, &attribs
);
471 depth
= attribs
.depth
;
473 if (depth
!= 15 && depth
!= 16 && depth
!= 24 && depth
!= 32)
477 depth
= vo_find_depth_from_visuals(mDisplay
, mScreen
, &visual
);
479 mXImage
= XCreateImage(mDisplay
, visual
, depth
, ZPixmap
,
480 0, NULL
, 1, 1, 8, 1);
483 XGetImage(mDisplay
, mRootWin
, 0, 0, 1, 1, AllPlanes
, ZPixmap
);
485 vo_depthonscreen
= depth
; // display depth on screen
487 // get bits/pixel from XImage structure:
494 * for the depth==24 case, the XImage structures might use
495 * 24 or 32 bits of data per pixel. The global variable
496 * vo_depthonscreen stores the amount of data per pixel in the
499 * Maybe we should rename vo_depthonscreen to (or add) vo_bpp?
501 bpp
= mXImage
->bits_per_pixel
;
502 if ((vo_depthonscreen
+ 7) / 8 != (bpp
+ 7) / 8)
503 vo_depthonscreen
= bpp
; // by A'rpi
505 mXImage
->red_mask
| mXImage
->green_mask
| mXImage
->blue_mask
;
506 mp_msg(MSGT_VO
, MSGL_V
,
507 "vo: X11 color mask: %X (R:%lX G:%lX B:%lX)\n", mask
,
508 mXImage
->red_mask
, mXImage
->green_mask
, mXImage
->blue_mask
);
509 XDestroyImage(mXImage
);
511 if (((vo_depthonscreen
+ 7) / 8) == 2)
514 vo_depthonscreen
= 15;
515 else if (mask
== 0xFFFF)
516 vo_depthonscreen
= 16;
518 // XCloseDisplay( mDisplay );
519 /* slightly improved local display detection AST */
520 if (strncmp(dispName
, "unix:", 5) == 0)
522 else if (strncmp(dispName
, "localhost:", 10) == 0)
524 if (*dispName
== ':' && atoi(dispName
+ 1) < 10)
528 mp_msg(MSGT_VO
, MSGL_V
,
529 "vo: X11 running at %dx%d with depth %d and %d bpp (\"%s\" => %s display)\n",
530 vo_screenwidth
, vo_screenheight
, depth
, vo_depthonscreen
,
531 dispName
, mLocalDisplay
? "local" : "remote");
533 vo_wm_type
= vo_wm_detect();
535 vo_fs_type
= vo_x11_get_fs_type(vo_wm_type
);
537 fstype_dump(vo_fs_type
);
547 mp_msg(MSGT_VO
, MSGL_V
,
548 "vo: x11 uninit called but X11 not inited..\n");
551 // if( !vo_depthonscreen ) return;
552 mp_msg(MSGT_VO
, MSGL_V
, "vo: uninit ...\n");
553 XSetErrorHandler(NULL
);
554 XCloseDisplay(mDisplay
);
555 vo_depthonscreen
= 0;
559 #include "osdep/keycodes.h"
562 #ifdef XF86XK_AudioPause
563 static void vo_x11_putkey_ext(int keysym
)
567 case XF86XK_AudioPause
:
568 mplayer_put_key(KEY_PAUSE
);
570 case XF86XK_AudioStop
:
571 mplayer_put_key(KEY_STOP
);
573 case XF86XK_AudioPrev
:
574 mplayer_put_key(KEY_PREV
);
576 case XF86XK_AudioNext
:
577 mplayer_put_key(KEY_NEXT
);
579 case XF86XK_AudioLowerVolume
:
580 mplayer_put_key(KEY_VOLUME_DOWN
);
582 case XF86XK_AudioRaiseVolume
:
583 mplayer_put_key(KEY_VOLUME_UP
);
591 void vo_x11_putkey(int key
)
596 mplayer_put_key(KEY_LEFT
);
599 mplayer_put_key(KEY_RIGHT
);
602 mplayer_put_key(KEY_UP
);
605 mplayer_put_key(KEY_DOWN
);
608 mplayer_put_key(' ');
611 mplayer_put_key(KEY_ESC
);
614 mplayer_put_key(KEY_TAB
);
617 mplayer_put_key(KEY_ENTER
);
620 mplayer_put_key(KEY_BS
);
623 mplayer_put_key(KEY_DELETE
);
626 mplayer_put_key(KEY_INSERT
);
629 mplayer_put_key(KEY_HOME
);
632 mplayer_put_key(KEY_END
);
635 mplayer_put_key(KEY_PAGE_UP
);
638 mplayer_put_key(KEY_PAGE_DOWN
);
641 mplayer_put_key(KEY_F
+ 1);
644 mplayer_put_key(KEY_F
+ 2);
647 mplayer_put_key(KEY_F
+ 3);
650 mplayer_put_key(KEY_F
+ 4);
653 mplayer_put_key(KEY_F
+ 5);
656 mplayer_put_key(KEY_F
+ 6);
659 mplayer_put_key(KEY_F
+ 7);
662 mplayer_put_key(KEY_F
+ 8);
665 mplayer_put_key(KEY_F
+ 9);
668 mplayer_put_key(KEY_F
+ 10);
671 mplayer_put_key(KEY_F
+ 11);
674 mplayer_put_key(KEY_F
+ 12);
678 mplayer_put_key('-');
682 mplayer_put_key('+');
686 mplayer_put_key('*');
690 mplayer_put_key('/');
693 mplayer_put_key('<');
696 mplayer_put_key('>');
699 mplayer_put_key(KEY_KP0
);
703 mplayer_put_key(KEY_KP1
);
707 mplayer_put_key(KEY_KP2
);
711 mplayer_put_key(KEY_KP3
);
715 mplayer_put_key(KEY_KP4
);
719 mplayer_put_key(KEY_KP5
);
723 mplayer_put_key(KEY_KP6
);
727 mplayer_put_key(KEY_KP7
);
731 mplayer_put_key(KEY_KP8
);
735 mplayer_put_key(KEY_KP9
);
738 mplayer_put_key(KEY_KPDEC
);
741 mplayer_put_key(KEY_KPINS
);
744 mplayer_put_key(KEY_KPDEL
);
747 mplayer_put_key(KEY_KPENTER
);
750 mplayer_put_key('`');
753 mplayer_put_key('~');
756 mplayer_put_key('!');
759 mplayer_put_key('@');
762 mplayer_put_key('#');
765 mplayer_put_key('$');
768 mplayer_put_key('%');
771 mplayer_put_key('^');
774 mplayer_put_key('&');
777 mplayer_put_key('(');
780 mplayer_put_key(')');
783 mplayer_put_key('_');
786 mplayer_put_key('{');
789 mplayer_put_key('}');
792 mplayer_put_key(':');
795 mplayer_put_key(';');
798 mplayer_put_key('\"');
801 mplayer_put_key('\'');
804 mplayer_put_key(',');
807 mplayer_put_key('.');
810 mplayer_put_key('?');
813 mplayer_put_key('\\');
816 mplayer_put_key('|');
819 mplayer_put_key('=');
822 mplayer_put_key('[');
825 mplayer_put_key(']');
830 if ((key
>= 'a' && key
<= 'z') || (key
>= 'A' && key
<= 'Z') ||
831 (key
>= '0' && key
<= '9'))
832 mplayer_put_key(key
);
838 // ----- Motif header: -------
840 #define MWM_HINTS_FUNCTIONS (1L << 0)
841 #define MWM_HINTS_DECORATIONS (1L << 1)
842 #define MWM_HINTS_INPUT_MODE (1L << 2)
843 #define MWM_HINTS_STATUS (1L << 3)
845 #define MWM_FUNC_ALL (1L << 0)
846 #define MWM_FUNC_RESIZE (1L << 1)
847 #define MWM_FUNC_MOVE (1L << 2)
848 #define MWM_FUNC_MINIMIZE (1L << 3)
849 #define MWM_FUNC_MAXIMIZE (1L << 4)
850 #define MWM_FUNC_CLOSE (1L << 5)
852 #define MWM_DECOR_ALL (1L << 0)
853 #define MWM_DECOR_BORDER (1L << 1)
854 #define MWM_DECOR_RESIZEH (1L << 2)
855 #define MWM_DECOR_TITLE (1L << 3)
856 #define MWM_DECOR_MENU (1L << 4)
857 #define MWM_DECOR_MINIMIZE (1L << 5)
858 #define MWM_DECOR_MAXIMIZE (1L << 6)
860 #define MWM_INPUT_MODELESS 0
861 #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
862 #define MWM_INPUT_SYSTEM_MODAL 2
863 #define MWM_INPUT_FULL_APPLICATION_MODAL 3
864 #define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL
866 #define MWM_TEAROFF_WINDOW (1L<<0)
877 static MotifWmHints vo_MotifWmHints
;
878 static Atom vo_MotifHints
= None
;
880 void vo_x11_decoration(Display
* vo_Display
, Window w
, int d
)
882 static unsigned int olddecor
= MWM_DECOR_ALL
;
883 static unsigned int oldfuncs
=
884 MWM_FUNC_MOVE
| MWM_FUNC_CLOSE
| MWM_FUNC_MINIMIZE
|
885 MWM_FUNC_MAXIMIZE
| MWM_FUNC_RESIZE
;
888 unsigned long mn
, mb
;
895 XSetTransientForHint(vo_Display
, w
,
896 RootWindow(vo_Display
, mScreen
));
899 vo_MotifHints
= XInternAtom(vo_Display
, "_MOTIF_WM_HINTS", 0);
900 if (vo_MotifHints
!= None
)
904 MotifWmHints
*mhints
= NULL
;
906 XGetWindowProperty(vo_Display
, w
, vo_MotifHints
, 0, 20, False
,
907 vo_MotifHints
, &mtype
, &mformat
, &mn
,
908 &mb
, (unsigned char **) &mhints
);
911 if (mhints
->flags
& MWM_HINTS_DECORATIONS
)
912 olddecor
= mhints
->decorations
;
913 if (mhints
->flags
& MWM_HINTS_FUNCTIONS
)
914 oldfuncs
= mhints
->functions
;
919 memset(&vo_MotifWmHints
, 0, sizeof(MotifWmHints
));
920 vo_MotifWmHints
.flags
=
921 MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
924 vo_MotifWmHints
.functions
= oldfuncs
;
928 vo_MotifWmHints
.decorations
=
929 d
| ((vo_fsmode
& 2) ? 0 : MWM_DECOR_MENU
);
931 vo_MotifWmHints
.decorations
=
932 d
| ((vo_fsmode
& 2) ? MWM_DECOR_MENU
: 0);
934 XChangeProperty(vo_Display
, w
, vo_MotifHints
, vo_MotifHints
, 32,
936 (unsigned char *) &vo_MotifWmHints
,
937 (vo_fsmode
& 4) ? 4 : 5);
941 void vo_x11_classhint(Display
* display
, Window window
, char *name
)
944 pid_t pid
= getpid();
946 wmClass
.res_name
= name
;
947 wmClass
.res_class
= "MPlayer";
948 XSetClassHint(display
, window
, &wmClass
);
949 XChangeProperty(display
, window
, XA_NET_WM_PID
, XA_CARDINAL
, 32,
950 PropModeReplace
, (unsigned char *) &pid
, 1);
953 Window vo_window
= None
;
959 void vo_setwindow(Window w
, GC g
)
966 void vo_x11_uninit(void)
969 if (vo_window
!= None
)
970 vo_showcursor(mDisplay
, vo_window
);
974 XFreeGC(mDisplay
, f_gc
);
978 /* destroy window only if it's not controlled by the GUI */
984 XSetBackground(mDisplay
, vo_gc
, 0);
985 XFreeGC(mDisplay
, vo_gc
);
988 if (vo_window
!= None
)
990 XClearWindow(mDisplay
, vo_window
);
995 XUnmapWindow(mDisplay
, vo_window
);
996 XDestroyWindow(mDisplay
, vo_window
);
999 XNextEvent(mDisplay
, &xev
);
1001 while (xev
.type
!= DestroyNotify
1002 || xev
.xdestroywindow
.event
!= vo_window
);
1007 vo_old_width
= vo_old_height
= 0;
1011 static unsigned int mouse_timer
;
1012 static int mouse_waiting_hide
;
1014 int vo_x11_check_events(Display
* mydisplay
)
1020 static XComposeStatus stat
;
1022 // unsigned long vo_KeyTable[512];
1024 if ((vo_mouse_autohide
) && mouse_waiting_hide
&&
1025 (GetTimerMS() - mouse_timer
>= 1000)) {
1026 vo_hidecursor(mydisplay
, vo_window
);
1027 mouse_waiting_hide
= 0;
1030 while (XPending(mydisplay
))
1032 XNextEvent(mydisplay
, &Event
);
1036 guiGetEvent(0, (char *) &Event
);
1037 if (vo_window
!= Event
.xany
.window
)
1041 // printf("\rEvent.type=%X \n",Event.type);
1045 ret
|= VO_EVENT_EXPOSE
;
1047 case ConfigureNotify
:
1048 // if (!vo_fs && (Event.xconfigure.width == vo_screenwidth || Event.xconfigure.height == vo_screenheight)) break;
1049 // if (vo_fs && Event.xconfigure.width != vo_screenwidth && Event.xconfigure.height != vo_screenheight) break;
1050 if (vo_window
== None
)
1052 vo_dwidth
= Event
.xconfigure
.width
;
1053 vo_dheight
= Event
.xconfigure
.height
;
1055 /* when resizing, x and y are zero :( */
1056 vo_dx
= Event
.xconfigure
.x
;
1057 vo_dy
= Event
.xconfigure
.y
;
1064 XGetGeometry(mydisplay
, vo_window
, &root
, &foo
, &foo
,
1065 &foo
/*width */ , &foo
/*height */ , &foo
,
1067 XTranslateCoordinates(mydisplay
, vo_window
, root
, 0, 0,
1068 &vo_dx
, &vo_dy
, &win
);
1071 ret
|= VO_EVENT_RESIZE
;
1078 if ( use_gui
) { break; }
1081 XLookupString(&Event
.xkey
, buf
, sizeof(buf
), &keySym
,
1083 #ifdef XF86XK_AudioPause
1084 vo_x11_putkey_ext(keySym
);
1087 ((keySym
& 0xff00) !=
1088 0 ? ((keySym
& 0x00ff) + 256) : (keySym
));
1090 ret
|= VO_EVENT_KEYPRESS
;
1094 if(enable_mouse_movements
)
1097 sprintf(cmd_str
,"set_mouse_pos %i %i",Event
.xmotion
.x
, Event
.xmotion
.y
);
1098 mp_input_queue_cmd(mp_input_parse_cmd(cmd_str
));
1101 if (vo_mouse_autohide
)
1103 vo_showcursor(mydisplay
, vo_window
);
1104 mouse_waiting_hide
= 1;
1105 mouse_timer
= GetTimerMS();
1109 if (vo_mouse_autohide
)
1111 vo_showcursor(mydisplay
, vo_window
);
1112 mouse_waiting_hide
= 1;
1113 mouse_timer
= GetTimerMS();
1116 // Ignore mouse button 1-3 under GUI.
1117 if (use_gui
&& (Event
.xbutton
.button
>= 1)
1118 && (Event
.xbutton
.button
<= 3))
1121 mplayer_put_key((MOUSE_BTN0
+ Event
.xbutton
.button
-
1125 if (vo_mouse_autohide
)
1127 vo_showcursor(mydisplay
, vo_window
);
1128 mouse_waiting_hide
= 1;
1129 mouse_timer
= GetTimerMS();
1132 // Ignore mouse button 1-3 under GUI.
1133 if (use_gui
&& (Event
.xbutton
.button
>= 1)
1134 && (Event
.xbutton
.button
<= 3))
1137 mplayer_put_key(MOUSE_BTN0
+ Event
.xbutton
.button
- 1);
1139 case PropertyNotify
:
1142 XGetAtomName(mydisplay
, Event
.xproperty
.atom
);
1147 // fprintf(stderr,"[ws] PropertyNotify ( 0x%x ) %s ( 0x%x )\n",vo_window,name,Event.xproperty.atom );
1153 vo_hint
.win_gravity
= old_gravity
;
1154 XSetWMNormalHints(mDisplay
, vo_window
, &vo_hint
);
1158 if (Event
.xclient
.message_type
== XAWM_PROTOCOLS
&&
1159 Event
.xclient
.data
.l
[0] == XAWM_DELETE_WINDOW
)
1160 mplayer_put_key(KEY_CLOSE_WIN
);
1168 * \brief sets the size and position of the non-fullscreen window.
1170 void vo_x11_nofs_sizepos(int x
, int y
, int width
, int height
)
1172 vo_x11_sizehint(x
, y
, width
, height
, 0);
1176 vo_old_width
= width
;
1177 vo_old_height
= height
;
1182 vo_dheight
= height
;
1183 XMoveResizeWindow(mDisplay
, vo_window
, x
, y
, width
, height
);
1187 void vo_x11_sizehint(int x
, int y
, int width
, int height
, int max
)
1192 vo_hint
.flags
|= PAspect
;
1193 vo_hint
.min_aspect
.x
= width
;
1194 vo_hint
.min_aspect
.y
= height
;
1195 vo_hint
.max_aspect
.x
= width
;
1196 vo_hint
.max_aspect
.y
= height
;
1199 vo_hint
.flags
|= PPosition
| PSize
;
1202 vo_hint
.width
= width
;
1203 vo_hint
.height
= height
;
1206 vo_hint
.flags
|= PMaxSize
;
1207 vo_hint
.max_width
= width
;
1208 vo_hint
.max_height
= height
;
1211 vo_hint
.max_width
= 0;
1212 vo_hint
.max_height
= 0;
1215 // Set minimum height/width to 4 to avoid off-by-one errors
1216 // and because mga_vid requires a minimal size of 4 pixels.
1217 vo_hint
.flags
|= PMinSize
;
1218 vo_hint
.min_width
= vo_hint
.min_height
= 4;
1220 vo_hint
.flags
|= PWinGravity
;
1221 vo_hint
.win_gravity
= StaticGravity
;
1222 XSetWMNormalHints(mDisplay
, vo_window
, &vo_hint
);
1225 static int vo_x11_get_gnome_layer(Display
* mDisplay
, Window win
)
1229 unsigned long nitems
;
1230 unsigned long bytesafter
;
1231 unsigned short *args
= NULL
;
1233 if (XGetWindowProperty(mDisplay
, win
, XA_WIN_LAYER
, 0, 16384,
1234 False
, AnyPropertyType
, &type
, &format
, &nitems
,
1236 (unsigned char **) &args
) == Success
1237 && nitems
> 0 && args
)
1239 mp_msg(MSGT_VO
, MSGL_V
, "[x11] original window layer is %d.\n",
1243 return WIN_LAYER_NORMAL
;
1247 Window
vo_x11_create_smooth_window(Display
* mDisplay
, Window mRoot
,
1248 Visual
* vis
, int x
, int y
,
1249 unsigned int width
, unsigned int height
,
1250 int depth
, Colormap col_map
)
1252 unsigned long xswamask
= CWBackingStore
| CWBorderPixel
;
1253 XSetWindowAttributes xswa
;
1256 if (col_map
!= CopyFromParent
)
1258 xswa
.colormap
= col_map
;
1259 xswamask
|= CWColormap
;
1261 xswa
.background_pixel
= 0;
1262 xswa
.border_pixel
= 0;
1263 xswa
.backing_store
= Always
;
1264 xswa
.bit_gravity
= StaticGravity
;
1267 XCreateWindow(mDisplay
, mRootWin
, x
, y
, width
, height
, 0, depth
,
1268 CopyFromParent
, vis
, xswamask
, &xswa
);
1269 XSetWMProtocols(mDisplay
, ret_win
, &XAWM_DELETE_WINDOW
, 1);
1271 f_gc
= XCreateGC(mDisplay
, ret_win
, 0, 0);
1272 XSetForeground(mDisplay
, f_gc
, 0);
1278 * \brief create and setup a window suitable for display
1279 * \param vis Visual to use for creating the window
1280 * \param x x position of window
1281 * \param y y position of window
1282 * \param width width of window
1283 * \param height height of window
1284 * \param flags flags for window creation.
1285 * Only VOFLAG_FULLSCREEN is supported so far.
1286 * \param col_map Colourmap for window or CopyFromParent if a specific colormap isn't needed
1287 * \param classname name to use for the classhint
1288 * \param title title for the window
1290 * This also does the grunt-work like setting Window Manager hints etc.
1291 * If vo_window is already set it just moves and resizes it.
1293 void vo_x11_create_vo_window(XVisualInfo
*vis
, int x
, int y
,
1294 unsigned int width
, unsigned int height
, int flags
,
1296 const char *classname
, const char *title
)
1298 if (vo_window
== None
) {
1303 vo_dheight
= height
;
1304 vo_window
= vo_x11_create_smooth_window(mDisplay
, mRootWin
, vis
->visual
,
1305 x
, y
, width
, height
, vis
->depth
, col_map
);
1306 vo_x11_classhint(mDisplay
, vo_window
, classname
);
1307 XStoreName(mDisplay
, vo_window
, title
);
1308 vo_hidecursor(mDisplay
, vo_window
);
1309 XSelectInput(mDisplay
, vo_window
, StructureNotifyMask
);
1310 hint
.x
= x
; hint
.y
= y
;
1311 hint
.width
= width
; hint
.height
= height
;
1312 hint
.flags
= PPosition
| PSize
;
1313 XSetStandardProperties(mDisplay
, vo_window
, title
, title
, None
, NULL
, 0, &hint
);
1314 vo_x11_sizehint(x
, y
, width
, height
, 0);
1316 XMapWindow(mDisplay
, vo_window
);
1317 XClearWindow(mDisplay
, vo_window
);
1320 XNextEvent(mDisplay
, &xev
);
1321 } while (xev
.type
!= MapNotify
|| xev
.xmap
.event
!= vo_window
);
1322 XSelectInput(mDisplay
, vo_window
, NoEventMask
);
1323 XSync(mDisplay
, False
);
1324 vo_x11_selectinput_witherr(mDisplay
, vo_window
,
1325 StructureNotifyMask
| KeyPressMask
| PointerMotionMask
|
1326 ButtonPressMask
| ButtonReleaseMask
| ExposureMask
);
1328 if (vo_ontop
) vo_x11_setlayer(mDisplay
, vo_window
, vo_ontop
);
1329 vo_x11_nofs_sizepos(vo_dx
, vo_dy
, width
, height
);
1330 if (!!vo_fs
!= !!(flags
& VOFLAG_FULLSCREEN
))
1331 vo_x11_fullscreen();
1334 void vo_x11_clearwindow_part(Display
* mDisplay
, Window vo_window
,
1335 int img_width
, int img_height
, int use_fs
)
1337 int u_dheight
, u_dwidth
, left_ov
, left_ov2
;
1342 u_dheight
= use_fs
? vo_screenheight
: vo_dheight
;
1343 u_dwidth
= use_fs
? vo_screenwidth
: vo_dwidth
;
1344 if ((u_dheight
<= img_height
) && (u_dwidth
<= img_width
))
1347 left_ov
= (u_dheight
- img_height
) / 2;
1348 left_ov2
= (u_dwidth
- img_width
) / 2;
1350 XFillRectangle(mDisplay
, vo_window
, f_gc
, 0, 0, u_dwidth
, left_ov
);
1351 XFillRectangle(mDisplay
, vo_window
, f_gc
, 0, u_dheight
- left_ov
- 1,
1352 u_dwidth
, left_ov
+ 1);
1354 if (u_dwidth
> img_width
)
1356 XFillRectangle(mDisplay
, vo_window
, f_gc
, 0, left_ov
, left_ov2
,
1358 XFillRectangle(mDisplay
, vo_window
, f_gc
, u_dwidth
- left_ov2
- 1,
1359 left_ov
, left_ov2
+ 1, img_height
);
1365 void vo_x11_clearwindow(Display
* mDisplay
, Window vo_window
)
1369 XFillRectangle(mDisplay
, vo_window
, f_gc
, 0, 0, vo_screenwidth
,
1376 void vo_x11_setlayer(Display
* mDisplay
, Window vo_window
, int layer
)
1381 if (vo_fs_type
& vo_wm_LAYER
)
1383 XClientMessageEvent xev
;
1386 orig_layer
= vo_x11_get_gnome_layer(mDisplay
, vo_window
);
1388 memset(&xev
, 0, sizeof(xev
));
1389 xev
.type
= ClientMessage
;
1390 xev
.display
= mDisplay
;
1391 xev
.window
= vo_window
;
1392 xev
.message_type
= XA_WIN_LAYER
;
1394 xev
.data
.l
[0] = layer
? fs_layer
: orig_layer
; // if not fullscreen, stay on default layer
1395 xev
.data
.l
[1] = CurrentTime
;
1396 mp_msg(MSGT_VO
, MSGL_V
,
1397 "[x11] Layered style stay on top (layer %ld).\n",
1399 XSendEvent(mDisplay
, mRootWin
, False
, SubstructureNotifyMask
,
1401 } else if (vo_fs_type
& vo_wm_NETWM
)
1403 XClientMessageEvent xev
;
1406 memset(&xev
, 0, sizeof(xev
));
1407 xev
.type
= ClientMessage
;
1408 xev
.message_type
= XA_NET_WM_STATE
;
1409 xev
.display
= mDisplay
;
1410 xev
.window
= vo_window
;
1412 xev
.data
.l
[0] = layer
;
1414 if (vo_fs_type
& vo_wm_STAYS_ON_TOP
)
1415 xev
.data
.l
[1] = XA_NET_WM_STATE_STAYS_ON_TOP
;
1416 else if (vo_fs_type
& vo_wm_ABOVE
)
1417 xev
.data
.l
[1] = XA_NET_WM_STATE_ABOVE
;
1418 else if (vo_fs_type
& vo_wm_FULLSCREEN
)
1419 xev
.data
.l
[1] = XA_NET_WM_STATE_FULLSCREEN
;
1420 else if (vo_fs_type
& vo_wm_BELOW
)
1421 // This is not fallback. We can safely assume that the situation
1422 // where only NETWM_STATE_BELOW is supported doesn't exist.
1423 xev
.data
.l
[1] = XA_NET_WM_STATE_BELOW
;
1425 XSendEvent(mDisplay
, mRootWin
, False
, SubstructureRedirectMask
,
1427 state
= XGetAtomName(mDisplay
, xev
.data
.l
[1]);
1428 mp_msg(MSGT_VO
, MSGL_V
,
1429 "[x11] NET style stay on top (layer %d). Using state %s.\n",
1435 static int vo_x11_get_fs_type(int supported
)
1438 int type
= supported
;
1443 for (i
= 0; vo_fstype_list
[i
]; i
++)
1446 char *arg
= vo_fstype_list
[i
];
1448 if (vo_fstype_list
[i
][0] == '-')
1451 arg
= vo_fstype_list
[i
] + 1;
1454 if (!strncmp(arg
, "layer", 5))
1456 if (!neg
&& (arg
[5] == '='))
1458 char *endptr
= NULL
;
1459 int layer
= strtol(vo_fstype_list
[i
] + 6, &endptr
, 10);
1461 if (endptr
&& *endptr
== '\0' && layer
>= 0
1466 type
&= ~vo_wm_LAYER
;
1468 type
|= vo_wm_LAYER
;
1469 } else if (!strcmp(arg
, "above"))
1472 type
&= ~vo_wm_ABOVE
;
1474 type
|= vo_wm_ABOVE
;
1475 } else if (!strcmp(arg
, "fullscreen"))
1478 type
&= ~vo_wm_FULLSCREEN
;
1480 type
|= vo_wm_FULLSCREEN
;
1481 } else if (!strcmp(arg
, "stays_on_top"))
1484 type
&= ~vo_wm_STAYS_ON_TOP
;
1486 type
|= vo_wm_STAYS_ON_TOP
;
1487 } else if (!strcmp(arg
, "below"))
1490 type
&= ~vo_wm_BELOW
;
1492 type
|= vo_wm_BELOW
;
1493 } else if (!strcmp(arg
, "netwm"))
1496 type
&= ~vo_wm_NETWM
;
1498 type
|= vo_wm_NETWM
;
1499 } else if (!strcmp(arg
, "none"))
1507 void vo_x11_fullscreen(void)
1511 if (WinID
>= 0 || vo_fs_flip
)
1517 if ( ! (vo_fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1525 vo_x11_ewmh_fullscreen(_NET_WM_STATE_REMOVE
); // removes fullscreen state if wm supports EWMH
1530 vo_x11_ewmh_fullscreen(_NET_WM_STATE_ADD
); // sends fullscreen state to be added if wm supports EWMH
1533 if ( ! (vo_fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1537 vo_old_width
= vo_dwidth
;
1538 vo_old_height
= vo_dheight
;
1540 update_xinerama_info();
1544 h
= vo_screenheight
;
1549 XGetWMNormalHints(mDisplay
, vo_window
, &vo_hint
, &dummy
);
1550 if (!(vo_hint
.flags
& PWinGravity
))
1551 old_gravity
= NorthWestGravity
;
1553 old_gravity
= vo_hint
.win_gravity
;
1555 if (vo_wm_type
== 0 && !(vo_fsmode
& 16))
1557 XUnmapWindow(mDisplay
, vo_window
); // required for MWM
1558 XWithdrawWindow(mDisplay
, vo_window
, mScreen
);
1562 if ( ! (vo_fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1564 vo_x11_decoration(mDisplay
, vo_window
, (vo_fs
) ? 0 : 1);
1565 vo_x11_sizehint(x
, y
, w
, h
, 0);
1566 vo_x11_setlayer(mDisplay
, vo_window
, vo_fs
);
1569 XMoveResizeWindow(mDisplay
, vo_window
, x
, y
, w
, h
);
1571 /* some WMs lose ontop after fullscreen */
1572 if ((!(vo_fs
)) & vo_ontop
)
1573 vo_x11_setlayer(mDisplay
, vo_window
, vo_ontop
);
1575 XMapRaised(mDisplay
, vo_window
);
1576 if ( ! (vo_fs_type
& vo_wm_FULLSCREEN
) ) // some WMs change window pos on map
1577 XMoveResizeWindow(mDisplay
, vo_window
, x
, y
, w
, h
);
1578 XRaiseWindow(mDisplay
, vo_window
);
1582 void vo_x11_ontop(void)
1584 vo_ontop
= (!(vo_ontop
));
1586 vo_x11_setlayer(mDisplay
, vo_window
, vo_ontop
);
1590 * XScreensaver stuff
1593 static int got_badwindow
;
1594 static XErrorHandler old_handler
;
1596 static int badwindow_handler(Display
* dpy
, XErrorEvent
* error
)
1598 if (error
->error_code
!= BadWindow
)
1599 return (*old_handler
) (dpy
, error
);
1601 got_badwindow
= True
;
1605 static Window
find_xscreensaver_window(Display
* dpy
)
1608 Window root
= RootWindowOfScreen(DefaultScreenOfDisplay(dpy
));
1609 Window root2
, parent
, *kids
;
1612 unsigned int nkids
= 0;
1614 xs_version
= XInternAtom(dpy
, "_SCREENSAVER_VERSION", True
);
1616 if (!(xs_version
!= None
&&
1617 XQueryTree(dpy
, root
, &root2
, &parent
, &kids
, &nkids
) &&
1621 old_handler
= XSetErrorHandler(badwindow_handler
);
1623 for (i
= 0; i
< nkids
; i
++)
1627 unsigned long nitems
, bytesafter
;
1631 got_badwindow
= False
;
1633 XGetWindowProperty(dpy
, kids
[i
], xs_version
, 0, 200, False
,
1634 XA_STRING
, &type
, &format
, &nitems
,
1635 &bytesafter
, (unsigned char **) &v
);
1640 if (status
== Success
&& type
!= None
)
1647 XSetErrorHandler(old_handler
);
1652 static Window xs_windowid
= 0;
1653 static Atom deactivate
;
1654 static Atom screensaver
;
1656 static unsigned int time_last
;
1658 void xscreensaver_heartbeat(void)
1660 unsigned int time
= GetTimerMS();
1663 if (mDisplay
&& xs_windowid
&& (time
- time_last
) > 30000)
1667 ev
.xany
.type
= ClientMessage
;
1668 ev
.xclient
.display
= mDisplay
;
1669 ev
.xclient
.window
= xs_windowid
;
1670 ev
.xclient
.message_type
= screensaver
;
1671 ev
.xclient
.format
= 32;
1672 memset(&ev
.xclient
.data
, 0, sizeof(ev
.xclient
.data
));
1673 ev
.xclient
.data
.l
[0] = (long) deactivate
;
1675 mp_msg(MSGT_VO
, MSGL_DBG2
, "Pinging xscreensaver.\n");
1676 old_handler
= XSetErrorHandler(badwindow_handler
);
1677 XSendEvent(mDisplay
, xs_windowid
, False
, 0L, &ev
);
1678 XSync(mDisplay
, False
);
1679 XSetErrorHandler(old_handler
);
1683 static void xscreensaver_disable(Display
* dpy
)
1685 mp_msg(MSGT_VO
, MSGL_DBG2
, "xscreensaver_disable()\n");
1687 xs_windowid
= find_xscreensaver_window(dpy
);
1690 mp_msg(MSGT_VO
, MSGL_INFO
, MSGTR_CouldNotFindXScreenSaver
);
1693 mp_msg(MSGT_VO
, MSGL_INFO
,
1694 "xscreensaver_disable: xscreensaver wid=%ld.\n", xs_windowid
);
1696 deactivate
= XInternAtom(dpy
, "DEACTIVATE", False
);
1697 screensaver
= XInternAtom(dpy
, "SCREENSAVER", False
);
1700 static void xscreensaver_enable(void)
1706 * End of XScreensaver stuff
1709 void saver_on(Display
* mDisplay
)
1717 if (DPMSQueryExtension(mDisplay
, ¬hing
, ¬hing
))
1719 if (!DPMSEnable(mDisplay
))
1720 { // restoring power saving settings
1721 mp_msg(MSGT_VO
, MSGL_WARN
, "DPMS not available?\n");
1724 // DPMS does not seem to be enabled unless we call DPMSInfo
1728 DPMSForceLevel(mDisplay
, DPMSModeOn
);
1729 DPMSInfo(mDisplay
, &state
, &onoff
);
1732 mp_msg(MSGT_VO
, MSGL_V
,
1733 "Successfully enabled DPMS\n");
1736 mp_msg(MSGT_VO
, MSGL_WARN
, "Could not enable DPMS\n");
1746 int dummy
, interval
, prefer_blank
, allow_exp
;
1748 XGetScreenSaver(mDisplay
, &dummy
, &interval
, &prefer_blank
,
1750 XSetScreenSaver(mDisplay
, timeout_save
, interval
, prefer_blank
,
1752 XGetScreenSaver(mDisplay
, &timeout_save
, &interval
, &prefer_blank
,
1757 if (stop_xscreensaver
)
1758 xscreensaver_enable();
1759 if (kdescreensaver_was_running
&& stop_xscreensaver
)
1762 ("dcop kdesktop KScreensaverIface enable true 2>/dev/null >/dev/null");
1763 kdescreensaver_was_running
= 0;
1769 void saver_off(Display
* mDisplay
)
1772 int interval
, prefer_blank
, allow_exp
;
1777 if (DPMSQueryExtension(mDisplay
, ¬hing
, ¬hing
))
1782 DPMSInfo(mDisplay
, &state
, &onoff
);
1787 mp_msg(MSGT_VO
, MSGL_V
, "Disabling DPMS\n");
1789 stat
= DPMSDisable(mDisplay
); // monitor powersave off
1790 mp_msg(MSGT_VO
, MSGL_V
, "DPMSDisable stat: %d\n", stat
);
1796 XGetScreenSaver(mDisplay
, &timeout_save
, &interval
, &prefer_blank
,
1799 XSetScreenSaver(mDisplay
, 0, interval
, prefer_blank
,
1802 // turning off screensaver
1803 if (stop_xscreensaver
)
1804 xscreensaver_disable(mDisplay
);
1805 if (stop_xscreensaver
&& !kdescreensaver_was_running
)
1807 kdescreensaver_was_running
=
1809 ("dcop kdesktop KScreensaverIface isEnabled 2>/dev/null | sed 's/1/true/g' | grep true 2>/dev/null >/dev/null")
1811 if (kdescreensaver_was_running
)
1813 ("dcop kdesktop KScreensaverIface enable false 2>/dev/null >/dev/null");
1817 static XErrorHandler old_handler
= NULL
;
1818 static int selectinput_err
= 0;
1819 static int x11_selectinput_errorhandler(Display
* display
,
1820 XErrorEvent
* event
)
1822 if (event
->error_code
== BadAccess
)
1824 selectinput_err
= 1;
1825 mp_msg(MSGT_VO
, MSGL_ERR
,
1826 "X11 error: BadAccess during XSelectInput Call\n");
1827 mp_msg(MSGT_VO
, MSGL_ERR
,
1828 "X11 error: The 'ButtonPressMask' mask of specified window has probably already used by another appication (see man XSelectInput)\n");
1829 /* If you think MPlayer should shutdown with this error,
1830 * comment out the following line */
1833 if (old_handler
!= NULL
)
1834 old_handler(display
, event
);
1836 x11_errorhandler(display
, event
);
1840 void vo_x11_selectinput_witherr(Display
* display
, Window w
,
1843 XSync(display
, False
);
1844 old_handler
= XSetErrorHandler(x11_selectinput_errorhandler
);
1845 selectinput_err
= 0;
1846 if (vo_nomouse_input
)
1848 XSelectInput(display
, w
,
1850 (~(ButtonPressMask
| ButtonReleaseMask
)));
1853 XSelectInput(display
, w
, event_mask
);
1855 XSync(display
, False
);
1856 XSetErrorHandler(old_handler
);
1857 if (selectinput_err
)
1859 mp_msg(MSGT_VO
, MSGL_ERR
,
1860 "X11 error: MPlayer discards mouse control (reconfiguring)\n");
1861 XSelectInput(display
, w
,
1864 (ButtonPressMask
| ButtonReleaseMask
|
1865 PointerMotionMask
)));
1870 void vo_vm_switch(uint32_t X
, uint32_t Y
, int *modeline_width
,
1871 int *modeline_height
)
1873 int vm_event
, vm_error
;
1875 int i
, j
, have_vm
= 0;
1879 if (XF86VidModeQueryExtension(mDisplay
, &vm_event
, &vm_error
))
1881 XF86VidModeQueryVersion(mDisplay
, &vm_ver
, &vm_rev
);
1882 mp_msg(MSGT_VO
, MSGL_V
, "XF86VidMode extension v%i.%i\n", vm_ver
,
1886 mp_msg(MSGT_VO
, MSGL_WARN
,
1887 "XF86VidMode extension not available.\n");
1891 if (vidmodes
== NULL
)
1892 XF86VidModeGetAllModeLines(mDisplay
, mScreen
, &modecount
,
1895 *modeline_width
= vidmodes
[0]->hdisplay
;
1896 *modeline_height
= vidmodes
[0]->vdisplay
;
1898 for (i
= 1; i
< modecount
; i
++)
1899 if ((vidmodes
[i
]->hdisplay
>= X
)
1900 && (vidmodes
[i
]->vdisplay
>= Y
))
1901 if ((vidmodes
[i
]->hdisplay
<= *modeline_width
)
1902 && (vidmodes
[i
]->vdisplay
<= *modeline_height
))
1904 *modeline_width
= vidmodes
[i
]->hdisplay
;
1905 *modeline_height
= vidmodes
[i
]->vdisplay
;
1909 mp_msg(MSGT_VO
, MSGL_INFO
, MSGTR_SelectedVideoMode
,
1910 *modeline_width
, *modeline_height
, X
, Y
);
1911 XF86VidModeLockModeSwitch(mDisplay
, mScreen
, 0);
1912 XF86VidModeSwitchToMode(mDisplay
, mScreen
, vidmodes
[j
]);
1913 XF86VidModeSwitchToMode(mDisplay
, mScreen
, vidmodes
[j
]);
1914 X
= (vo_screenwidth
- *modeline_width
) / 2;
1915 Y
= (vo_screenheight
- *modeline_height
) / 2;
1916 XF86VidModeSetViewPort(mDisplay
, mScreen
, X
, Y
);
1920 void vo_vm_close(Display
* dpy
)
1923 if (vidmodes
!= NULL
&& vo_window
!= None
)
1925 if (vidmodes
!= NULL
)
1931 screen
= DefaultScreen(dpy
);
1935 XF86VidModeGetAllModeLines(mDisplay
, mScreen
, &modecount
,
1937 for (i
= 0; i
< modecount
; i
++)
1938 if ((vidmodes
[i
]->hdisplay
== vo_screenwidth
)
1939 && (vidmodes
[i
]->vdisplay
== vo_screenheight
))
1941 mp_msg(MSGT_VO
, MSGL_INFO
,
1942 "Returning to original mode %dx%d\n",
1943 vo_screenwidth
, vo_screenheight
);
1947 XF86VidModeSwitchToMode(dpy
, screen
, vidmodes
[i
]);
1948 XF86VidModeSwitchToMode(dpy
, screen
, vidmodes
[i
]);
1955 #endif /* X11_FULLSCREEN */
1959 * Scan the available visuals on this Display/Screen. Try to find
1960 * the 'best' available TrueColor visual that has a decent color
1961 * depth (at least 15bit). If there are multiple visuals with depth
1962 * >= 15bit, we prefer visuals with a smaller color depth.
1964 int vo_find_depth_from_visuals(Display
* dpy
, int screen
,
1965 Visual
** visual_return
)
1967 XVisualInfo visual_tmpl
;
1968 XVisualInfo
*visuals
;
1970 int bestvisual
= -1;
1971 int bestvisual_depth
= -1;
1973 visual_tmpl
.screen
= screen
;
1974 visual_tmpl
.class = TrueColor
;
1975 visuals
= XGetVisualInfo(dpy
,
1976 VisualScreenMask
| VisualClassMask
,
1977 &visual_tmpl
, &nvisuals
);
1978 if (visuals
!= NULL
)
1980 for (i
= 0; i
< nvisuals
; i
++)
1982 mp_msg(MSGT_VO
, MSGL_V
,
1983 "vo: X11 truecolor visual %#lx, depth %d, R:%lX G:%lX B:%lX\n",
1984 visuals
[i
].visualid
, visuals
[i
].depth
,
1985 visuals
[i
].red_mask
, visuals
[i
].green_mask
,
1986 visuals
[i
].blue_mask
);
1988 * Save the visual index and its depth, if this is the first
1989 * truecolor visul, or a visual that is 'preferred' over the
1990 * previous 'best' visual.
1992 if (bestvisual_depth
== -1
1993 || (visuals
[i
].depth
>= 15
1994 && (visuals
[i
].depth
< bestvisual_depth
1995 || bestvisual_depth
< 15)))
1998 bestvisual_depth
= visuals
[i
].depth
;
2002 if (bestvisual
!= -1 && visual_return
!= NULL
)
2003 *visual_return
= visuals
[bestvisual
].visual
;
2007 return bestvisual_depth
;
2011 static Colormap cmap
= None
;
2012 static XColor cols
[256];
2013 static int cm_size
, red_mask
, green_mask
, blue_mask
;
2016 Colormap
vo_x11_create_colormap(XVisualInfo
* vinfo
)
2018 unsigned k
, r
, g
, b
, ru
, gu
, bu
, m
, rv
, gv
, bv
, rvu
, gvu
, bvu
;
2020 if (vinfo
->class != DirectColor
)
2021 return XCreateColormap(mDisplay
, mRootWin
, vinfo
->visual
,
2024 /* can this function get called twice or more? */
2027 cm_size
= vinfo
->colormap_size
;
2028 red_mask
= vinfo
->red_mask
;
2029 green_mask
= vinfo
->green_mask
;
2030 blue_mask
= vinfo
->blue_mask
;
2031 ru
= (red_mask
& (red_mask
- 1)) ^ red_mask
;
2032 gu
= (green_mask
& (green_mask
- 1)) ^ green_mask
;
2033 bu
= (blue_mask
& (blue_mask
- 1)) ^ blue_mask
;
2034 rvu
= 65536ull * ru
/ (red_mask
+ ru
);
2035 gvu
= 65536ull * gu
/ (green_mask
+ gu
);
2036 bvu
= 65536ull * bu
/ (blue_mask
+ bu
);
2039 m
= DoRed
| DoGreen
| DoBlue
;
2040 for (k
= 0; k
< cm_size
; k
++)
2044 cols
[k
].pixel
= r
| g
| b
;
2049 t
= (r
+ ru
) & red_mask
;
2053 t
= (g
+ gu
) & green_mask
;
2057 t
= (b
+ bu
) & blue_mask
;
2065 cmap
= XCreateColormap(mDisplay
, mRootWin
, vinfo
->visual
, AllocAll
);
2066 XStoreColors(mDisplay
, cmap
, cols
, cm_size
);
2071 * Via colormaps/gamma ramps we can do gamma, brightness, contrast,
2072 * hue and red/green/blue intensity, but we cannot do saturation.
2073 * Currently only gamma, brightness and contrast are implemented.
2074 * Is there sufficient interest for hue and/or red/green/blue intensity?
2076 /* these values have range [-100,100] and are initially 0 */
2077 static int vo_gamma
= 0;
2078 static int vo_brightness
= 0;
2079 static int vo_contrast
= 0;
2082 uint32_t vo_x11_set_equalizer(char *name
, int value
)
2084 float gamma
, brightness
, contrast
;
2089 * IMPLEMENTME: consider using XF86VidModeSetGammaRamp in the case
2090 * of TrueColor-ed window but be careful:
2091 * Unlike the colormaps, which are private for the X client
2092 * who created them and thus automatically destroyed on client
2093 * disconnect, this gamma ramp is a system-wide (X-server-wide)
2094 * setting and _must_ be restored before the process exits.
2095 * Unforunately when the process crashes (or gets killed
2096 * for some reason) it is impossible to restore the setting,
2097 * and such behaviour could be rather annoying for the users.
2102 if (!strcasecmp(name
, "brightness"))
2103 vo_brightness
= value
;
2104 else if (!strcasecmp(name
, "contrast"))
2105 vo_contrast
= value
;
2106 else if (!strcasecmp(name
, "gamma"))
2111 brightness
= 0.01 * vo_brightness
;
2112 contrast
= tan(0.0095 * (vo_contrast
+ 100) * M_PI
/ 4);
2113 gamma
= pow(2, -0.02 * vo_gamma
);
2115 rf
= (float) ((red_mask
& (red_mask
- 1)) ^ red_mask
) / red_mask
;
2116 gf
= (float) ((green_mask
& (green_mask
- 1)) ^ green_mask
) /
2118 bf
= (float) ((blue_mask
& (blue_mask
- 1)) ^ blue_mask
) / blue_mask
;
2120 /* now recalculate the colormap using the newly set value */
2121 for (k
= 0; k
< cm_size
; k
++)
2125 s
= pow(rf
* k
, gamma
);
2126 s
= (s
- 0.5) * contrast
+ 0.5;
2132 cols
[k
].red
= (unsigned short) (s
* 65535);
2134 s
= pow(gf
* k
, gamma
);
2135 s
= (s
- 0.5) * contrast
+ 0.5;
2141 cols
[k
].green
= (unsigned short) (s
* 65535);
2143 s
= pow(bf
* k
, gamma
);
2144 s
= (s
- 0.5) * contrast
+ 0.5;
2150 cols
[k
].blue
= (unsigned short) (s
* 65535);
2153 XStoreColors(mDisplay
, cmap
, cols
, cm_size
);
2158 uint32_t vo_x11_get_equalizer(char *name
, int *value
)
2162 if (!strcasecmp(name
, "brightness"))
2163 *value
= vo_brightness
;
2164 else if (!strcasecmp(name
, "contrast"))
2165 *value
= vo_contrast
;
2166 else if (!strcasecmp(name
, "gamma"))
2174 int vo_xv_set_eq(uint32_t xv_port
, char *name
, int value
)
2176 XvAttribute
*attributes
;
2177 int i
, howmany
, xv_atom
;
2179 mp_dbg(MSGT_VO
, MSGL_V
, "xv_set_eq called! (%s, %d)\n", name
, value
);
2181 /* get available attributes */
2182 attributes
= XvQueryPortAttributes(mDisplay
, xv_port
, &howmany
);
2183 for (i
= 0; i
< howmany
&& attributes
; i
++)
2184 if (attributes
[i
].flags
& XvSettable
)
2186 xv_atom
= XInternAtom(mDisplay
, attributes
[i
].name
, True
);
2187 /* since we have SET_DEFAULTS first in our list, we can check if it's available
2188 then trigger it if it's ok so that the other values are at default upon query */
2189 if (xv_atom
!= None
)
2191 int hue
= 0, port_value
, port_min
, port_max
;
2193 if (!strcmp(attributes
[i
].name
, "XV_BRIGHTNESS") &&
2194 (!strcasecmp(name
, "brightness")))
2196 else if (!strcmp(attributes
[i
].name
, "XV_CONTRAST") &&
2197 (!strcasecmp(name
, "contrast")))
2199 else if (!strcmp(attributes
[i
].name
, "XV_SATURATION") &&
2200 (!strcasecmp(name
, "saturation")))
2202 else if (!strcmp(attributes
[i
].name
, "XV_HUE") &&
2203 (!strcasecmp(name
, "hue")))
2208 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
2209 if (!strcmp(attributes
[i
].name
, "XV_RED_INTENSITY") &&
2210 (!strcasecmp(name
, "red_intensity")))
2212 else if (!strcmp(attributes
[i
].name
, "XV_GREEN_INTENSITY")
2213 && (!strcasecmp(name
, "green_intensity")))
2215 else if (!strcmp(attributes
[i
].name
, "XV_BLUE_INTENSITY")
2216 && (!strcasecmp(name
, "blue_intensity")))
2221 port_min
= attributes
[i
].min_value
;
2222 port_max
= attributes
[i
].max_value
;
2224 /* nvidia hue workaround */
2225 if (hue
&& port_min
== 0 && port_max
== 360)
2229 0) ? (port_value
- 100) : (port_value
+ 100);
2235 (port_value
+ 100) * (port_max
- port_min
) / 200 +
2237 XvSetPortAttribute(mDisplay
, xv_port
, xv_atom
, port_value
);
2244 int vo_xv_get_eq(uint32_t xv_port
, char *name
, int *value
)
2247 XvAttribute
*attributes
;
2248 int i
, howmany
, xv_atom
;
2250 /* get available attributes */
2251 attributes
= XvQueryPortAttributes(mDisplay
, xv_port
, &howmany
);
2252 for (i
= 0; i
< howmany
&& attributes
; i
++)
2253 if (attributes
[i
].flags
& XvGettable
)
2255 xv_atom
= XInternAtom(mDisplay
, attributes
[i
].name
, True
);
2256 /* since we have SET_DEFAULTS first in our list, we can check if it's available
2257 then trigger it if it's ok so that the other values are at default upon query */
2258 if (xv_atom
!= None
)
2260 int val
, port_value
= 0, port_min
, port_max
;
2262 XvGetPortAttribute(mDisplay
, xv_port
, xv_atom
,
2265 port_min
= attributes
[i
].min_value
;
2266 port_max
= attributes
[i
].max_value
;
2268 (port_value
- port_min
) * 200 / (port_max
- port_min
) -
2271 if (!strcmp(attributes
[i
].name
, "XV_BRIGHTNESS") &&
2272 (!strcasecmp(name
, "brightness")))
2274 else if (!strcmp(attributes
[i
].name
, "XV_CONTRAST") &&
2275 (!strcasecmp(name
, "contrast")))
2277 else if (!strcmp(attributes
[i
].name
, "XV_SATURATION") &&
2278 (!strcasecmp(name
, "saturation")))
2280 else if (!strcmp(attributes
[i
].name
, "XV_HUE") &&
2281 (!strcasecmp(name
, "hue")))
2283 /* nasty nvidia detect */
2284 if (port_min
== 0 && port_max
== 360)
2285 *value
= (val
>= 0) ? (val
- 100) : (val
+ 100);
2289 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
2290 if (!strcmp(attributes
[i
].name
, "XV_RED_INTENSITY") &&
2291 (!strcasecmp(name
, "red_intensity")))
2293 else if (!strcmp(attributes
[i
].name
, "XV_GREEN_INTENSITY")
2294 && (!strcasecmp(name
, "green_intensity")))
2296 else if (!strcmp(attributes
[i
].name
, "XV_BLUE_INTENSITY")
2297 && (!strcasecmp(name
, "blue_intensity")))
2302 mp_dbg(MSGT_VO
, MSGL_V
, "xv_get_eq called! (%s, %d)\n",
2310 /** \brief contains flags changing the execution of the colorkeying code */
2311 xv_ck_info_t xv_ck_info
= { CK_METHOD_MANUALFILL
, CK_SRC_CUR
};
2312 unsigned long xv_colorkey
; ///< The color used for manual colorkeying.
2313 unsigned int xv_port
; ///< The selected Xv port.
2316 * \brief Interns the requested atom if it is available.
2318 * \param atom_name String containing the name of the requested atom.
2320 * \return Returns the atom if available, else None is returned.
2323 static Atom
xv_intern_atom_if_exists( char const * atom_name
)
2325 XvAttribute
* attributes
;
2327 Atom xv_atom
= None
;
2329 attributes
= XvQueryPortAttributes( mDisplay
, xv_port
, &attrib_count
);
2330 if( attributes
!=NULL
)
2332 for ( i
= 0; i
< attrib_count
; ++i
)
2334 if ( strcmp(attributes
[i
].name
, atom_name
) == 0 )
2336 xv_atom
= XInternAtom( mDisplay
, atom_name
, False
);
2337 break; // found what we want, break out
2340 XFree( attributes
);
2347 * \brief Try to enable vsync for xv.
2348 * \return Returns -1 if not available, 0 on failure and 1 on success.
2350 int vo_xv_enable_vsync(void)
2352 Atom xv_atom
= xv_intern_atom_if_exists("XV_SYNC_TO_VBLANK");
2353 if (xv_atom
== None
)
2355 return XvSetPortAttribute(mDisplay
, xv_port
, xv_atom
, 1) == Success
;
2359 * \brief Get maximum supported source image dimensions.
2361 * This function does not set the variables pointed to by
2362 * width and height if the information could not be retrieved,
2363 * so the caller is reponsible for properly initializing them.
2365 * \param width [out] The maximum width gets stored here.
2366 * \param height [out] The maximum height gets stored here.
2369 void vo_xv_get_max_img_dim( uint32_t * width
, uint32_t * height
)
2371 XvEncodingInfo
* encodings
;
2372 //unsigned long num_encodings, idx; to int or too long?!
2373 unsigned int num_encodings
, idx
;
2375 XvQueryEncodings( mDisplay
, xv_port
, &num_encodings
, &encodings
);
2379 for ( idx
= 0; idx
< num_encodings
; ++idx
)
2381 if ( strcmp( encodings
[idx
].name
, "XV_IMAGE" ) == 0 )
2383 *width
= encodings
[idx
].width
;
2384 *height
= encodings
[idx
].height
;
2390 mp_msg( MSGT_VO
, MSGL_V
,
2391 "[xv common] Maximum source image dimensions: %ux%u\n",
2394 XvFreeEncodingInfo( encodings
);
2398 * \brief Print information about the colorkey method and source.
2400 * \param ck_handling Integer value containing the information about
2401 * colorkey handling (see x11_common.h).
2403 * Outputs the content of |ck_handling| as a readable message.
2406 void vo_xv_print_ck_info(void)
2408 mp_msg( MSGT_VO
, MSGL_V
, "[xv common] " );
2410 switch ( xv_ck_info
.method
)
2412 case CK_METHOD_NONE
:
2413 mp_msg( MSGT_VO
, MSGL_V
, "Drawing no colorkey.\n" ); return;
2414 case CK_METHOD_AUTOPAINT
:
2415 mp_msg( MSGT_VO
, MSGL_V
, "Colorkey is drawn by Xv." ); break;
2416 case CK_METHOD_MANUALFILL
:
2417 mp_msg( MSGT_VO
, MSGL_V
, "Drawing colorkey manually." ); break;
2418 case CK_METHOD_BACKGROUND
:
2419 mp_msg( MSGT_VO
, MSGL_V
, "Colorkey is drawn as window background." ); break;
2422 mp_msg( MSGT_VO
, MSGL_V
, "\n[xv common] " );
2424 switch ( xv_ck_info
.source
)
2427 mp_msg( MSGT_VO
, MSGL_V
, "Using colorkey from Xv (0x%06lx).\n",
2431 if ( xv_ck_info
.method
== CK_METHOD_AUTOPAINT
)
2433 mp_msg( MSGT_VO
, MSGL_V
,
2434 "Ignoring colorkey from MPlayer (0x%06lx).\n",
2439 mp_msg( MSGT_VO
, MSGL_V
,
2440 "Using colorkey from MPlayer (0x%06lx)."
2441 " Use -colorkey to change.\n",
2446 mp_msg( MSGT_VO
, MSGL_V
,
2447 "Setting and using colorkey from MPlayer (0x%06lx)."
2448 " Use -colorkey to change.\n",
2454 * \brief Init colorkey depending on the settings in xv_ck_info.
2456 * \return Returns 0 on failure and 1 on success.
2458 * Sets the colorkey variable according to the CK_SRC_* and CK_METHOD_*
2459 * flags in xv_ck_info.
2463 * - manual colorkey drawing ( CK_METHOD_MANUALFILL )
2464 * - set colorkey as window background ( CK_METHOD_BACKGROUND )
2465 * - let Xv paint the colorkey ( CK_METHOD_AUTOPAINT )
2467 * - use currently set colorkey ( CK_SRC_CUR )
2468 * - use colorkey in vo_colorkey ( CK_SRC_USE )
2469 * - use and set colorkey in vo_colorkey ( CK_SRC_SET )
2471 * NOTE: If vo_colorkey has bits set after the first 3 low order bytes
2472 * we don't draw anything as this means it was forced to off.
2474 int vo_xv_init_colorkey(void)
2479 /* check if colorkeying is needed */
2480 xv_atom
= xv_intern_atom_if_exists( "XV_COLORKEY" );
2482 /* if we have to deal with colorkeying ... */
2483 if( xv_atom
!= None
&& !(vo_colorkey
& 0xFF000000) )
2485 /* check if we should use the colorkey specified in vo_colorkey */
2486 if ( xv_ck_info
.source
!= CK_SRC_CUR
)
2488 xv_colorkey
= vo_colorkey
;
2490 /* check if we have to set the colorkey too */
2491 if ( xv_ck_info
.source
== CK_SRC_SET
)
2493 xv_atom
= XInternAtom(mDisplay
, "XV_COLORKEY",False
);
2495 rez
= XvSetPortAttribute( mDisplay
, xv_port
, xv_atom
, vo_colorkey
);
2496 if ( rez
!= Success
)
2498 mp_msg( MSGT_VO
, MSGL_FATAL
,
2499 "[xv common] Couldn't set colorkey!\n" );
2500 return 0; // error setting colorkey
2508 rez
=XvGetPortAttribute(mDisplay
,xv_port
, xv_atom
, &colorkey_ret
);
2509 if ( rez
== Success
)
2511 xv_colorkey
= colorkey_ret
;
2515 mp_msg( MSGT_VO
, MSGL_FATAL
,
2516 "[xv common] Couldn't get colorkey!"
2517 "Maybe the selected Xv port has no overlay.\n" );
2518 return 0; // error getting colorkey
2522 xv_atom
= xv_intern_atom_if_exists( "XV_AUTOPAINT_COLORKEY" );
2524 /* should we draw the colorkey ourselves or activate autopainting? */
2525 if ( xv_ck_info
.method
== CK_METHOD_AUTOPAINT
)
2527 rez
= !Success
; // reset rez to something different than Success
2529 if ( xv_atom
!= None
) // autopaint is supported
2531 rez
= XvSetPortAttribute( mDisplay
, xv_port
, xv_atom
, 1 );
2534 if ( rez
!= Success
)
2536 // fallback to manual colorkey drawing
2537 xv_ck_info
.method
= CK_METHOD_MANUALFILL
;
2540 else // disable colorkey autopainting if supported
2542 if ( xv_atom
!= None
) // we have autopaint attribute
2544 XvSetPortAttribute( mDisplay
, xv_port
, xv_atom
, 0 );
2548 else // do no colorkey drawing at all
2550 xv_ck_info
.method
= CK_METHOD_NONE
;
2551 } /* end: should we draw colorkey */
2553 /* output information about the current colorkey settings */
2554 vo_xv_print_ck_info();
2556 return 1; // success
2560 * \brief Draw the colorkey on the video window.
2562 * Draws the colorkey depending on the set method ( colorkey_handling ).
2564 * Also draws the black bars ( when the video doesn't fit the display in
2565 * fullscreen ) separately, so they don't overlap with the video area.
2566 * It doesn't call XFlush.
2569 void vo_xv_draw_colorkey( int32_t x
, int32_t y
,
2570 int32_t w
, int32_t h
)
2572 if( xv_ck_info
.method
== CK_METHOD_MANUALFILL
||
2573 xv_ck_info
.method
== CK_METHOD_BACKGROUND
)//less tearing than XClearWindow()
2575 XSetForeground( mDisplay
, vo_gc
, xv_colorkey
);
2576 XFillRectangle( mDisplay
, vo_window
, vo_gc
,
2581 /* draw black bars if needed */
2582 /* TODO! move this to vo_x11_clearwindow_part() */
2585 XSetForeground( mDisplay
, vo_gc
, 0 );
2586 /* making non-overlap fills, requires 8 checks instead of 4 */
2588 XFillRectangle( mDisplay
, vo_window
, vo_gc
,
2592 XFillRectangle( mDisplay
, vo_window
, vo_gc
,
2594 x
, vo_screenheight
);
2595 if (x
+ w
< vo_screenwidth
)
2596 XFillRectangle( mDisplay
, vo_window
, vo_gc
,
2598 vo_screenwidth
, vo_screenheight
);
2599 if (y
+ h
< vo_screenheight
)
2600 XFillRectangle( mDisplay
, vo_window
, vo_gc
,
2602 vo_screenwidth
, vo_screenheight
);
2606 /** \brief Tests if a valid argument for the ck suboption was given. */
2607 int xv_test_ck( void * arg
)
2609 strarg_t
* strarg
= (strarg_t
*)arg
;
2611 if ( strargcmp( strarg
, "use" ) == 0 ||
2612 strargcmp( strarg
, "set" ) == 0 ||
2613 strargcmp( strarg
, "cur" ) == 0 )
2620 /** \brief Tests if a valid arguments for the ck-method suboption was given. */
2621 int xv_test_ckm( void * arg
)
2623 strarg_t
* strarg
= (strarg_t
*)arg
;
2625 if ( strargcmp( strarg
, "bg" ) == 0 ||
2626 strargcmp( strarg
, "man" ) == 0 ||
2627 strargcmp( strarg
, "auto" ) == 0 )
2636 * \brief Modify the colorkey_handling var according to str
2638 * Checks if a valid pointer ( not NULL ) to the string
2639 * was given. And in that case modifies the colorkey_handling
2640 * var to reflect the requested behaviour.
2641 * If nothing happens the content of colorkey_handling stays
2644 * \param str Pointer to the string or NULL
2647 void xv_setup_colorkeyhandling( char const * ck_method_str
,
2648 char const * ck_str
)
2650 /* check if a valid pointer to the string was passed */
2653 if ( strncmp( ck_str
, "use", 3 ) == 0 )
2655 xv_ck_info
.source
= CK_SRC_USE
;
2657 else if ( strncmp( ck_str
, "set", 3 ) == 0 )
2659 xv_ck_info
.source
= CK_SRC_SET
;
2662 /* check if a valid pointer to the string was passed */
2663 if ( ck_method_str
)
2665 if ( strncmp( ck_method_str
, "bg", 2 ) == 0 )
2667 xv_ck_info
.method
= CK_METHOD_BACKGROUND
;
2669 else if ( strncmp( ck_method_str
, "man", 3 ) == 0 )
2671 xv_ck_info
.method
= CK_METHOD_MANUALFILL
;
2673 else if ( strncmp( ck_method_str
, "auto", 4 ) == 0 )
2675 xv_ck_info
.method
= CK_METHOD_AUTOPAINT
;