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>
38 #ifdef CONFIG_XINERAMA
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
;
72 static int orig_layer
= 0;
73 static int old_gravity
= NorthWestGravity
;
75 int stop_xscreensaver
= 0;
77 static int dpms_disabled
= 0;
79 char *mDisplayName
= NULL
;
80 Display
*mDisplay
= NULL
;
85 /* output window id */
86 int vo_mouse_autohide
= 0;
88 int vo_fs_type
= 0; // needs to be accessible for GUI X11 code
89 static int vo_fs_flip
= 0;
90 char **vo_fstype_list
;
92 /* 1 means that the WM is metacity (broken as hell) */
93 int metacity_hack
= 0;
95 static Atom XA_NET_SUPPORTED
;
96 static Atom XA_NET_WM_STATE
;
97 static Atom XA_NET_WM_STATE_FULLSCREEN
;
98 static Atom XA_NET_WM_STATE_ABOVE
;
99 static Atom XA_NET_WM_STATE_STAYS_ON_TOP
;
100 static Atom XA_NET_WM_STATE_BELOW
;
101 static Atom XA_NET_WM_PID
;
102 static Atom XA_WIN_PROTOCOLS
;
103 static Atom XA_WIN_LAYER
;
104 static Atom XA_WIN_HINTS
;
105 static Atom XAWM_PROTOCOLS
;
106 static Atom XAWM_DELETE_WINDOW
;
108 #define XA_INIT(x) XA##x = XInternAtom(mDisplay, #x, False)
110 static int vo_old_x
= 0;
111 static int vo_old_y
= 0;
112 static int vo_old_width
= 0;
113 static int vo_old_height
= 0;
116 XF86VidModeModeInfo
**vidmodes
= NULL
;
117 XF86VidModeModeLine modeline
;
120 static int vo_x11_get_fs_type(int supported
);
124 * Sends the EWMH fullscreen state event.
126 * action: could be one of _NET_WM_STATE_REMOVE -- remove state
127 * _NET_WM_STATE_ADD -- add state
128 * _NET_WM_STATE_TOGGLE -- toggle
130 void vo_x11_ewmh_fullscreen(int action
)
132 assert(action
== _NET_WM_STATE_REMOVE
||
133 action
== _NET_WM_STATE_ADD
|| action
== _NET_WM_STATE_TOGGLE
);
135 if (vo_fs_type
& vo_wm_FULLSCREEN
)
139 /* init X event structure for _NET_WM_FULLSCREEN client message */
140 xev
.xclient
.type
= ClientMessage
;
141 xev
.xclient
.serial
= 0;
142 xev
.xclient
.send_event
= True
;
143 xev
.xclient
.message_type
= XA_NET_WM_STATE
;
144 xev
.xclient
.window
= vo_window
;
145 xev
.xclient
.format
= 32;
146 xev
.xclient
.data
.l
[0] = action
;
147 xev
.xclient
.data
.l
[1] = XA_NET_WM_STATE_FULLSCREEN
;
148 xev
.xclient
.data
.l
[2] = 0;
149 xev
.xclient
.data
.l
[3] = 0;
150 xev
.xclient
.data
.l
[4] = 0;
152 /* finally send that damn thing */
153 if (!XSendEvent(mDisplay
, DefaultRootWindow(mDisplay
), False
,
154 SubstructureRedirectMask
| SubstructureNotifyMask
,
157 mp_msg(MSGT_VO
, MSGL_ERR
, MSGTR_EwmhFullscreenStateFailed
);
162 void vo_hidecursor(Display
* disp
, Window win
)
168 static char bm_no_data
[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
171 return; // do not hide if playing on the root window
173 colormap
= DefaultColormap(disp
, DefaultScreen(disp
));
174 if ( !XAllocNamedColor(disp
, colormap
, "black", &black
, &dummy
) )
176 return; // color alloc failed, give up
178 bm_no
= XCreateBitmapFromData(disp
, win
, bm_no_data
, 8, 8);
179 no_ptr
= XCreatePixmapCursor(disp
, bm_no
, bm_no
, &black
, &black
, 0, 0);
180 XDefineCursor(disp
, win
, no_ptr
);
181 XFreeCursor(disp
, no_ptr
);
183 XFreePixmap(disp
, bm_no
);
184 XFreeColors(disp
,colormap
,&black
.pixel
,1,0);
187 void vo_showcursor(Display
* disp
, Window win
)
191 XDefineCursor(disp
, win
, 0);
194 static int x11_errorhandler(Display
* display
, XErrorEvent
* event
)
199 XGetErrorText(display
, event
->error_code
, (char *) &msg
, MSGLEN
);
201 mp_msg(MSGT_VO
, MSGL_ERR
, "X11 error: %s\n", msg
);
203 mp_msg(MSGT_VO
, MSGL_V
,
204 "Type: %x, display: %p, resourceid: %lx, serial: %lx\n",
205 event
->type
, event
->display
, event
->resourceid
, event
->serial
);
206 mp_msg(MSGT_VO
, MSGL_V
,
207 "Error code: %x, request code: %x, minor code: %x\n",
208 event
->error_code
, event
->request_code
, event
->minor_code
);
211 //exit_player("X11 error");
216 void fstype_help(void)
218 mp_msg(MSGT_VO
, MSGL_INFO
, MSGTR_AvailableFsType
);
219 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FULL_SCREEN_TYPES\n");
221 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "none",
222 "don't set fullscreen window layer");
223 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "layer",
224 "use _WIN_LAYER hint with default layer");
225 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "layer=<0..15>",
226 "use _WIN_LAYER hint with a given layer number");
227 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "netwm",
228 "force NETWM style");
229 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "above",
230 "use _NETWM_STATE_ABOVE hint if available");
231 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "below",
232 "use _NETWM_STATE_BELOW hint if available");
233 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "fullscreen",
234 "use _NETWM_STATE_FULLSCREEN hint if availale");
235 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "stays_on_top",
236 "use _NETWM_STATE_STAYS_ON_TOP hint if available");
237 mp_msg(MSGT_VO
, MSGL_INFO
,
238 "You can also negate the settings with simply putting '-' in the beginning");
239 mp_msg(MSGT_VO
, MSGL_INFO
, "\n");
242 static void fstype_dump(int fstype
)
246 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Current fstype setting honours");
247 if (fstype
& vo_wm_LAYER
)
248 mp_msg(MSGT_VO
, MSGL_V
, " LAYER");
249 if (fstype
& vo_wm_FULLSCREEN
)
250 mp_msg(MSGT_VO
, MSGL_V
, " FULLSCREEN");
251 if (fstype
& vo_wm_STAYS_ON_TOP
)
252 mp_msg(MSGT_VO
, MSGL_V
, " STAYS_ON_TOP");
253 if (fstype
& vo_wm_ABOVE
)
254 mp_msg(MSGT_VO
, MSGL_V
, " ABOVE");
255 if (fstype
& vo_wm_BELOW
)
256 mp_msg(MSGT_VO
, MSGL_V
, " BELOW");
257 mp_msg(MSGT_VO
, MSGL_V
, " X atoms\n");
259 mp_msg(MSGT_VO
, MSGL_V
,
260 "[x11] Current fstype setting doesn't honour any X atoms\n");
263 static int net_wm_support_state_test(Atom atom
)
265 #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; } }
267 NET_WM_STATE_TEST(FULLSCREEN
);
268 NET_WM_STATE_TEST(ABOVE
);
269 NET_WM_STATE_TEST(STAYS_ON_TOP
);
270 NET_WM_STATE_TEST(BELOW
);
274 static int x11_get_property(Atom type
, Atom
** args
, unsigned long *nitems
)
277 unsigned long bytesafter
;
280 XGetWindowProperty(mDisplay
, mRootWin
, type
, 0, 16384, False
,
281 AnyPropertyType
, &type
, &format
, nitems
,
282 &bytesafter
, (unsigned char **) args
)
286 static int vo_wm_detect(void)
290 unsigned long nitems
;
296 // -- supports layers
297 if (x11_get_property(XA_WIN_PROTOCOLS
, &args
, &nitems
))
299 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Detected wm supports layers.\n");
300 for (i
= 0; i
< nitems
; i
++)
302 if (args
[i
] == XA_WIN_LAYER
)
307 /* metacity is the only window manager I know which reports
308 * supporting only the _WIN_LAYER hint in _WIN_PROTOCOLS.
309 * (what's more support for it is broken) */
313 if (wm
&& (metacity_hack
== 1))
315 // metacity claims to support layers, but it is not the truth :-)
317 mp_msg(MSGT_VO
, MSGL_V
,
318 "[x11] Using workaround for Metacity bugs.\n");
322 if (x11_get_property(XA_NET_SUPPORTED
, &args
, &nitems
))
324 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Detected wm supports NetWM.\n");
325 for (i
= 0; i
< nitems
; i
++)
326 wm
|= net_wm_support_state_test(args
[i
]);
331 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Unknown wm type...\n");
335 static void init_atoms(void)
337 XA_INIT(_NET_SUPPORTED
);
338 XA_INIT(_NET_WM_STATE
);
339 XA_INIT(_NET_WM_STATE_FULLSCREEN
);
340 XA_INIT(_NET_WM_STATE_ABOVE
);
341 XA_INIT(_NET_WM_STATE_STAYS_ON_TOP
);
342 XA_INIT(_NET_WM_STATE_BELOW
);
343 XA_INIT(_NET_WM_PID
);
344 XA_INIT(_WIN_PROTOCOLS
);
347 XA_INIT(WM_PROTOCOLS
);
348 XA_INIT(WM_DELETE_WINDOW
);
351 void update_xinerama_info(void) {
352 int screen
= xinerama_screen
;
353 xinerama_x
= xinerama_y
= 0;
354 #ifdef CONFIG_XINERAMA
355 if (screen
>= -1 && XineramaIsActive(mDisplay
))
357 XineramaScreenInfo
*screens
;
360 screens
= XineramaQueryScreens(mDisplay
, &num_screens
);
361 if (screen
>= num_screens
)
362 screen
= num_screens
- 1;
364 int x
= vo_dx
+ vo_dwidth
/ 2;
365 int y
= vo_dy
+ vo_dheight
/ 2;
366 for (screen
= num_screens
- 1; screen
> 0; screen
--) {
367 int left
= screens
[screen
].x_org
;
368 int right
= left
+ screens
[screen
].width
;
369 int top
= screens
[screen
].y_org
;
370 int bottom
= top
+ screens
[screen
].height
;
371 if (left
<= x
&& x
<= right
&& top
<= y
&& y
<= bottom
)
377 vo_screenwidth
= screens
[screen
].width
;
378 vo_screenheight
= screens
[screen
].height
;
379 xinerama_x
= screens
[screen
].x_org
;
380 xinerama_y
= screens
[screen
].y_org
;
385 aspect_save_screenres(vo_screenwidth
, vo_screenheight
);
394 // char * DisplayName = ":0.0";
395 // Display * mDisplay;
396 XImage
*mXImage
= NULL
;
399 XWindowAttributes attribs
;
403 WinID
= 0; // use root window
405 if (vo_depthonscreen
)
408 return 1; // already called
411 XSetErrorHandler(x11_errorhandler
);
415 if (!(mDisplayName
= getenv("DISPLAY")))
416 mDisplayName
= strdup(":0.0");
418 dispName
= XDisplayName(mDisplayName
);
421 mp_msg(MSGT_VO
, MSGL_V
, "X11 opening display: %s\n", dispName
);
423 mDisplay
= XOpenDisplay(dispName
);
426 mp_msg(MSGT_VO
, MSGL_ERR
,
427 "vo: couldn't open the X11 display (%s)!\n", dispName
);
430 mScreen
= DefaultScreen(mDisplay
); // screen ID
431 mRootWin
= RootWindow(mDisplay
, mScreen
); // root window ID
439 XF86VidModeGetModeLine(mDisplay
, mScreen
, &clock
, &modeline
);
441 vo_screenwidth
= modeline
.hdisplay
;
442 if (!vo_screenheight
)
443 vo_screenheight
= modeline
.vdisplay
;
448 vo_screenwidth
= DisplayWidth(mDisplay
, mScreen
);
449 if (!vo_screenheight
)
450 vo_screenheight
= DisplayHeight(mDisplay
, mScreen
);
452 // get color depth (from root window, or the best visual):
453 XGetWindowAttributes(mDisplay
, mRootWin
, &attribs
);
454 depth
= attribs
.depth
;
456 if (depth
!= 15 && depth
!= 16 && depth
!= 24 && depth
!= 32)
460 depth
= vo_find_depth_from_visuals(mDisplay
, mScreen
, &visual
);
462 mXImage
= XCreateImage(mDisplay
, visual
, depth
, ZPixmap
,
463 0, NULL
, 1, 1, 8, 1);
466 XGetImage(mDisplay
, mRootWin
, 0, 0, 1, 1, AllPlanes
, ZPixmap
);
468 vo_depthonscreen
= depth
; // display depth on screen
470 // get bits/pixel from XImage structure:
477 * for the depth==24 case, the XImage structures might use
478 * 24 or 32 bits of data per pixel. The global variable
479 * vo_depthonscreen stores the amount of data per pixel in the
482 * Maybe we should rename vo_depthonscreen to (or add) vo_bpp?
484 bpp
= mXImage
->bits_per_pixel
;
485 if ((vo_depthonscreen
+ 7) / 8 != (bpp
+ 7) / 8)
486 vo_depthonscreen
= bpp
; // by A'rpi
488 mXImage
->red_mask
| mXImage
->green_mask
| mXImage
->blue_mask
;
489 mp_msg(MSGT_VO
, MSGL_V
,
490 "vo: X11 color mask: %X (R:%lX G:%lX B:%lX)\n", mask
,
491 mXImage
->red_mask
, mXImage
->green_mask
, mXImage
->blue_mask
);
492 XDestroyImage(mXImage
);
494 if (((vo_depthonscreen
+ 7) / 8) == 2)
497 vo_depthonscreen
= 15;
498 else if (mask
== 0xFFFF)
499 vo_depthonscreen
= 16;
501 // XCloseDisplay( mDisplay );
502 /* slightly improved local display detection AST */
503 if (strncmp(dispName
, "unix:", 5) == 0)
505 else if (strncmp(dispName
, "localhost:", 10) == 0)
507 if (*dispName
== ':' && atoi(dispName
+ 1) < 10)
511 mp_msg(MSGT_VO
, MSGL_V
,
512 "vo: X11 running at %dx%d with depth %d and %d bpp (\"%s\" => %s display)\n",
513 vo_screenwidth
, vo_screenheight
, depth
, vo_depthonscreen
,
514 dispName
, mLocalDisplay
? "local" : "remote");
516 vo_wm_type
= vo_wm_detect();
518 vo_fs_type
= vo_x11_get_fs_type(vo_wm_type
);
520 fstype_dump(vo_fs_type
);
530 mp_msg(MSGT_VO
, MSGL_V
,
531 "vo: x11 uninit called but X11 not initialized..\n");
534 // if( !vo_depthonscreen ) return;
535 mp_msg(MSGT_VO
, MSGL_V
, "vo: uninit ...\n");
536 XSetErrorHandler(NULL
);
537 XCloseDisplay(mDisplay
);
538 vo_depthonscreen
= 0;
542 #include "osdep/keycodes.h"
545 #ifdef XF86XK_AudioPause
546 static void vo_x11_putkey_ext(int keysym
)
551 mplayer_put_key(KEY_MENU
);
553 case XF86XK_AudioPlay
:
554 mplayer_put_key(KEY_PLAY
);
556 case XF86XK_AudioPause
:
557 mplayer_put_key(KEY_PAUSE
);
559 case XF86XK_AudioStop
:
560 mplayer_put_key(KEY_STOP
);
562 case XF86XK_AudioPrev
:
563 mplayer_put_key(KEY_PREV
);
565 case XF86XK_AudioNext
:
566 mplayer_put_key(KEY_NEXT
);
568 case XF86XK_AudioMute
:
569 mplayer_put_key(KEY_MUTE
);
571 case XF86XK_AudioLowerVolume
:
572 mplayer_put_key(KEY_VOLUME_DOWN
);
574 case XF86XK_AudioRaiseVolume
:
575 mplayer_put_key(KEY_VOLUME_UP
);
583 void vo_x11_putkey(int key
)
588 mplayer_put_key(KEY_LEFT
);
591 mplayer_put_key(KEY_RIGHT
);
594 mplayer_put_key(KEY_UP
);
597 mplayer_put_key(KEY_DOWN
);
600 mplayer_put_key(' ');
603 mplayer_put_key(KEY_ESC
);
606 mplayer_put_key(KEY_TAB
);
609 mplayer_put_key(KEY_ENTER
);
612 mplayer_put_key(KEY_BS
);
615 mplayer_put_key(KEY_DELETE
);
618 mplayer_put_key(KEY_INSERT
);
621 mplayer_put_key(KEY_HOME
);
624 mplayer_put_key(KEY_END
);
627 mplayer_put_key(KEY_PAGE_UP
);
630 mplayer_put_key(KEY_PAGE_DOWN
);
633 mplayer_put_key(KEY_F
+ 1);
636 mplayer_put_key(KEY_F
+ 2);
639 mplayer_put_key(KEY_F
+ 3);
642 mplayer_put_key(KEY_F
+ 4);
645 mplayer_put_key(KEY_F
+ 5);
648 mplayer_put_key(KEY_F
+ 6);
651 mplayer_put_key(KEY_F
+ 7);
654 mplayer_put_key(KEY_F
+ 8);
657 mplayer_put_key(KEY_F
+ 9);
660 mplayer_put_key(KEY_F
+ 10);
663 mplayer_put_key(KEY_F
+ 11);
666 mplayer_put_key(KEY_F
+ 12);
670 mplayer_put_key('-');
674 mplayer_put_key('+');
678 mplayer_put_key('*');
682 mplayer_put_key('/');
685 mplayer_put_key('<');
688 mplayer_put_key('>');
691 mplayer_put_key(KEY_KP0
);
695 mplayer_put_key(KEY_KP1
);
699 mplayer_put_key(KEY_KP2
);
703 mplayer_put_key(KEY_KP3
);
707 mplayer_put_key(KEY_KP4
);
711 mplayer_put_key(KEY_KP5
);
715 mplayer_put_key(KEY_KP6
);
719 mplayer_put_key(KEY_KP7
);
723 mplayer_put_key(KEY_KP8
);
727 mplayer_put_key(KEY_KP9
);
730 mplayer_put_key(KEY_KPDEC
);
733 mplayer_put_key(KEY_KPINS
);
736 mplayer_put_key(KEY_KPDEL
);
739 mplayer_put_key(KEY_KPENTER
);
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('?');
805 mplayer_put_key('\\');
808 mplayer_put_key('|');
811 mplayer_put_key('=');
814 mplayer_put_key('[');
817 mplayer_put_key(']');
822 if ((key
>= 'a' && key
<= 'z') || (key
>= 'A' && key
<= 'Z') ||
823 (key
>= '0' && key
<= '9'))
824 mplayer_put_key(key
);
830 // ----- Motif header: -------
832 #define MWM_HINTS_FUNCTIONS (1L << 0)
833 #define MWM_HINTS_DECORATIONS (1L << 1)
834 #define MWM_HINTS_INPUT_MODE (1L << 2)
835 #define MWM_HINTS_STATUS (1L << 3)
837 #define MWM_FUNC_ALL (1L << 0)
838 #define MWM_FUNC_RESIZE (1L << 1)
839 #define MWM_FUNC_MOVE (1L << 2)
840 #define MWM_FUNC_MINIMIZE (1L << 3)
841 #define MWM_FUNC_MAXIMIZE (1L << 4)
842 #define MWM_FUNC_CLOSE (1L << 5)
844 #define MWM_DECOR_ALL (1L << 0)
845 #define MWM_DECOR_BORDER (1L << 1)
846 #define MWM_DECOR_RESIZEH (1L << 2)
847 #define MWM_DECOR_TITLE (1L << 3)
848 #define MWM_DECOR_MENU (1L << 4)
849 #define MWM_DECOR_MINIMIZE (1L << 5)
850 #define MWM_DECOR_MAXIMIZE (1L << 6)
852 #define MWM_INPUT_MODELESS 0
853 #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
854 #define MWM_INPUT_SYSTEM_MODAL 2
855 #define MWM_INPUT_FULL_APPLICATION_MODAL 3
856 #define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL
858 #define MWM_TEAROFF_WINDOW (1L<<0)
869 static MotifWmHints vo_MotifWmHints
;
870 static Atom vo_MotifHints
= None
;
872 void vo_x11_decoration(Display
* vo_Display
, Window w
, int d
)
874 static unsigned int olddecor
= MWM_DECOR_ALL
;
875 static unsigned int oldfuncs
=
876 MWM_FUNC_MOVE
| MWM_FUNC_CLOSE
| MWM_FUNC_MINIMIZE
|
877 MWM_FUNC_MAXIMIZE
| MWM_FUNC_RESIZE
;
880 unsigned long mn
, mb
;
887 XSetTransientForHint(vo_Display
, w
,
888 RootWindow(vo_Display
, mScreen
));
891 vo_MotifHints
= XInternAtom(vo_Display
, "_MOTIF_WM_HINTS", 0);
892 if (vo_MotifHints
!= None
)
896 MotifWmHints
*mhints
= NULL
;
898 XGetWindowProperty(vo_Display
, w
, vo_MotifHints
, 0, 20, False
,
899 vo_MotifHints
, &mtype
, &mformat
, &mn
,
900 &mb
, (unsigned char **) &mhints
);
903 if (mhints
->flags
& MWM_HINTS_DECORATIONS
)
904 olddecor
= mhints
->decorations
;
905 if (mhints
->flags
& MWM_HINTS_FUNCTIONS
)
906 oldfuncs
= mhints
->functions
;
911 memset(&vo_MotifWmHints
, 0, sizeof(MotifWmHints
));
912 vo_MotifWmHints
.flags
=
913 MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
916 vo_MotifWmHints
.functions
= oldfuncs
;
920 vo_MotifWmHints
.decorations
=
921 d
| ((vo_fsmode
& 2) ? 0 : MWM_DECOR_MENU
);
923 vo_MotifWmHints
.decorations
=
924 d
| ((vo_fsmode
& 2) ? MWM_DECOR_MENU
: 0);
926 XChangeProperty(vo_Display
, w
, vo_MotifHints
, vo_MotifHints
, 32,
928 (unsigned char *) &vo_MotifWmHints
,
929 (vo_fsmode
& 4) ? 4 : 5);
933 void vo_x11_classhint(Display
* display
, Window window
, char *name
)
936 pid_t pid
= getpid();
938 wmClass
.res_name
= name
;
939 wmClass
.res_class
= "MPlayer";
940 XSetClassHint(display
, window
, &wmClass
);
941 XChangeProperty(display
, window
, XA_NET_WM_PID
, XA_CARDINAL
, 32,
942 PropModeReplace
, (unsigned char *) &pid
, 1);
945 Window vo_window
= None
;
951 void vo_setwindow(Window w
, GC g
)
958 void vo_x11_uninit(void)
961 if (vo_window
!= None
)
962 vo_showcursor(mDisplay
, vo_window
);
966 XFreeGC(mDisplay
, f_gc
);
970 /* destroy window only if it's not controlled by the GUI */
976 XSetBackground(mDisplay
, vo_gc
, 0);
977 XFreeGC(mDisplay
, vo_gc
);
980 if (vo_window
!= None
)
982 XClearWindow(mDisplay
, vo_window
);
987 XUnmapWindow(mDisplay
, vo_window
);
988 XDestroyWindow(mDisplay
, vo_window
);
991 XNextEvent(mDisplay
, &xev
);
993 while (xev
.type
!= DestroyNotify
994 || xev
.xdestroywindow
.event
!= vo_window
);
999 vo_old_width
= vo_old_height
= 0;
1003 static unsigned int mouse_timer
;
1004 static int mouse_waiting_hide
;
1006 int vo_x11_check_events(Display
* mydisplay
)
1012 static XComposeStatus stat
;
1014 // unsigned long vo_KeyTable[512];
1016 if ((vo_mouse_autohide
) && mouse_waiting_hide
&&
1017 (GetTimerMS() - mouse_timer
>= 1000)) {
1018 vo_hidecursor(mydisplay
, vo_window
);
1019 mouse_waiting_hide
= 0;
1022 while (XPending(mydisplay
))
1024 XNextEvent(mydisplay
, &Event
);
1028 guiGetEvent(0, (char *) &Event
);
1029 if (vo_window
!= Event
.xany
.window
)
1033 // printf("\rEvent.type=%X \n",Event.type);
1037 ret
|= VO_EVENT_EXPOSE
;
1039 case ConfigureNotify
:
1040 // if (!vo_fs && (Event.xconfigure.width == vo_screenwidth || Event.xconfigure.height == vo_screenheight)) break;
1041 // if (vo_fs && Event.xconfigure.width != vo_screenwidth && Event.xconfigure.height != vo_screenheight) break;
1042 if (vo_window
== None
)
1044 vo_x11_update_geometry();
1045 ret
|= VO_EVENT_RESIZE
;
1052 if ( use_gui
) { break; }
1055 XLookupString(&Event
.xkey
, buf
, sizeof(buf
), &keySym
,
1057 #ifdef XF86XK_AudioPause
1058 vo_x11_putkey_ext(keySym
);
1061 ((keySym
& 0xff00) !=
1062 0 ? ((keySym
& 0x00ff) + 256) : (keySym
));
1064 ret
|= VO_EVENT_KEYPRESS
;
1068 if(enable_mouse_movements
)
1071 sprintf(cmd_str
,"set_mouse_pos %i %i",Event
.xmotion
.x
, Event
.xmotion
.y
);
1072 mp_input_queue_cmd(mp_input_parse_cmd(cmd_str
));
1075 if (vo_mouse_autohide
)
1077 vo_showcursor(mydisplay
, vo_window
);
1078 mouse_waiting_hide
= 1;
1079 mouse_timer
= GetTimerMS();
1083 if (vo_mouse_autohide
)
1085 vo_showcursor(mydisplay
, vo_window
);
1086 mouse_waiting_hide
= 1;
1087 mouse_timer
= GetTimerMS();
1090 // Ignore mouse button 1-3 under GUI.
1091 if (use_gui
&& (Event
.xbutton
.button
>= 1)
1092 && (Event
.xbutton
.button
<= 3))
1095 mplayer_put_key((MOUSE_BTN0
+ Event
.xbutton
.button
-
1099 if (vo_mouse_autohide
)
1101 vo_showcursor(mydisplay
, vo_window
);
1102 mouse_waiting_hide
= 1;
1103 mouse_timer
= GetTimerMS();
1106 // Ignore mouse button 1-3 under GUI.
1107 if (use_gui
&& (Event
.xbutton
.button
>= 1)
1108 && (Event
.xbutton
.button
<= 3))
1111 mplayer_put_key(MOUSE_BTN0
+ Event
.xbutton
.button
- 1);
1113 case PropertyNotify
:
1116 XGetAtomName(mydisplay
, Event
.xproperty
.atom
);
1121 // fprintf(stderr,"[ws] PropertyNotify ( 0x%x ) %s ( 0x%x )\n",vo_window,name,Event.xproperty.atom );
1127 vo_hint
.win_gravity
= old_gravity
;
1128 XSetWMNormalHints(mDisplay
, vo_window
, &vo_hint
);
1132 if (Event
.xclient
.message_type
== XAWM_PROTOCOLS
&&
1133 Event
.xclient
.data
.l
[0] == XAWM_DELETE_WINDOW
)
1134 mplayer_put_key(KEY_CLOSE_WIN
);
1142 * \brief sets the size and position of the non-fullscreen window.
1144 void vo_x11_nofs_sizepos(int x
, int y
, int width
, int height
)
1146 vo_x11_sizehint(x
, y
, width
, height
, 0);
1150 vo_old_width
= width
;
1151 vo_old_height
= height
;
1156 vo_dheight
= height
;
1157 XMoveResizeWindow(mDisplay
, vo_window
, x
, y
, width
, height
);
1161 void vo_x11_sizehint(int x
, int y
, int width
, int height
, int max
)
1166 vo_hint
.flags
|= PAspect
;
1167 vo_hint
.min_aspect
.x
= width
;
1168 vo_hint
.min_aspect
.y
= height
;
1169 vo_hint
.max_aspect
.x
= width
;
1170 vo_hint
.max_aspect
.y
= height
;
1173 vo_hint
.flags
|= PPosition
| PSize
;
1176 vo_hint
.width
= width
;
1177 vo_hint
.height
= height
;
1180 vo_hint
.flags
|= PMaxSize
;
1181 vo_hint
.max_width
= width
;
1182 vo_hint
.max_height
= height
;
1185 vo_hint
.max_width
= 0;
1186 vo_hint
.max_height
= 0;
1189 // Set minimum height/width to 4 to avoid off-by-one errors
1190 // and because mga_vid requires a minimal size of 4 pixels.
1191 vo_hint
.flags
|= PMinSize
;
1192 vo_hint
.min_width
= vo_hint
.min_height
= 4;
1194 // Set the base size. A window manager might display the window
1195 // size to the user relative to this.
1196 // Setting these to width/height might be nice, but e.g. fluxbox can't handle it.
1197 vo_hint
.flags
|= PBaseSize
;
1198 vo_hint
.base_width
= 0 /*width*/;
1199 vo_hint
.base_height
= 0 /*height*/;
1201 vo_hint
.flags
|= PWinGravity
;
1202 vo_hint
.win_gravity
= StaticGravity
;
1203 XSetWMNormalHints(mDisplay
, vo_window
, &vo_hint
);
1206 static int vo_x11_get_gnome_layer(Display
* mDisplay
, Window win
)
1210 unsigned long nitems
;
1211 unsigned long bytesafter
;
1212 unsigned short *args
= NULL
;
1214 if (XGetWindowProperty(mDisplay
, win
, XA_WIN_LAYER
, 0, 16384,
1215 False
, AnyPropertyType
, &type
, &format
, &nitems
,
1217 (unsigned char **) &args
) == Success
1218 && nitems
> 0 && args
)
1220 mp_msg(MSGT_VO
, MSGL_V
, "[x11] original window layer is %d.\n",
1224 return WIN_LAYER_NORMAL
;
1228 Window
vo_x11_create_smooth_window(Display
* mDisplay
, Window mRoot
,
1229 Visual
* vis
, int x
, int y
,
1230 unsigned int width
, unsigned int height
,
1231 int depth
, Colormap col_map
)
1233 unsigned long xswamask
= CWBorderPixel
;
1234 XSetWindowAttributes xswa
;
1237 if (col_map
!= CopyFromParent
)
1239 xswa
.colormap
= col_map
;
1240 xswamask
|= CWColormap
;
1242 xswa
.background_pixel
= 0;
1243 xswa
.border_pixel
= 0;
1244 xswa
.backing_store
= NotUseful
;
1245 xswa
.bit_gravity
= StaticGravity
;
1248 XCreateWindow(mDisplay
, mRootWin
, x
, y
, width
, height
, 0, depth
,
1249 CopyFromParent
, vis
, xswamask
, &xswa
);
1250 XSetWMProtocols(mDisplay
, ret_win
, &XAWM_DELETE_WINDOW
, 1);
1252 f_gc
= XCreateGC(mDisplay
, ret_win
, 0, 0);
1253 XSetForeground(mDisplay
, f_gc
, 0);
1259 * \brief create and setup a window suitable for display
1260 * \param vis Visual to use for creating the window
1261 * \param x x position of window
1262 * \param y y position of window
1263 * \param width width of window
1264 * \param height height of window
1265 * \param flags flags for window creation.
1266 * Only VOFLAG_FULLSCREEN is supported so far.
1267 * \param col_map Colourmap for window or CopyFromParent if a specific colormap isn't needed
1268 * \param classname name to use for the classhint
1269 * \param title title for the window
1271 * This also does the grunt-work like setting Window Manager hints etc.
1272 * If vo_window is already set it just moves and resizes it.
1274 void vo_x11_create_vo_window(XVisualInfo
*vis
, int x
, int y
,
1275 unsigned int width
, unsigned int height
, int flags
,
1277 const char *classname
, const char *title
)
1281 vo_window
= WinID
? (Window
)WinID
: mRootWin
;
1282 if (col_map
!= CopyFromParent
) {
1283 unsigned long xswamask
= CWColormap
;
1284 XSetWindowAttributes xswa
;
1285 xswa
.colormap
= col_map
;
1286 XUnmapWindow(mDisplay
, vo_window
);
1287 XChangeWindowAttributes(mDisplay
, vo_window
, xswamask
, &xswa
);
1288 XMapWindow(mDisplay
, vo_window
);
1290 if (WinID
) vo_x11_update_geometry();
1291 vo_x11_selectinput_witherr(mDisplay
, vo_window
,
1292 StructureNotifyMask
| KeyPressMask
| PointerMotionMask
|
1293 ButtonPressMask
| ButtonReleaseMask
| ExposureMask
);
1296 if (vo_window
== None
) {
1301 vo_dheight
= height
;
1302 vo_window
= vo_x11_create_smooth_window(mDisplay
, mRootWin
, vis
->visual
,
1303 x
, y
, width
, height
, vis
->depth
, col_map
);
1304 vo_x11_classhint(mDisplay
, vo_window
, classname
);
1305 XStoreName(mDisplay
, vo_window
, title
);
1306 vo_hidecursor(mDisplay
, vo_window
);
1307 XSelectInput(mDisplay
, vo_window
, StructureNotifyMask
);
1308 hint
.x
= x
; hint
.y
= y
;
1309 hint
.width
= width
; hint
.height
= height
;
1310 hint
.flags
= PPosition
| PSize
;
1311 XSetStandardProperties(mDisplay
, vo_window
, title
, title
, None
, NULL
, 0, &hint
);
1312 vo_x11_sizehint(x
, y
, width
, height
, 0);
1313 if (!vo_border
) vo_x11_decoration(mDisplay
, vo_window
, 0);
1315 XMapWindow(mDisplay
, vo_window
);
1316 XClearWindow(mDisplay
, vo_window
);
1319 XNextEvent(mDisplay
, &xev
);
1320 } while (xev
.type
!= MapNotify
|| xev
.xmap
.event
!= vo_window
);
1321 XSelectInput(mDisplay
, vo_window
, NoEventMask
);
1322 XSync(mDisplay
, False
);
1323 vo_x11_selectinput_witherr(mDisplay
, vo_window
,
1324 StructureNotifyMask
| KeyPressMask
| PointerMotionMask
|
1325 ButtonPressMask
| ButtonReleaseMask
| ExposureMask
);
1327 if (vo_ontop
) vo_x11_setlayer(mDisplay
, vo_window
, vo_ontop
);
1328 vo_x11_nofs_sizepos(vo_dx
, vo_dy
, width
, height
);
1329 if (!!vo_fs
!= !!(flags
& VOFLAG_FULLSCREEN
))
1330 vo_x11_fullscreen();
1333 XFreeGC(mDisplay
, vo_gc
);
1334 vo_gc
= XCreateGC(mDisplay
, vo_window
, GCForeground
, &xgcv
);
1335 XSync(mDisplay
, False
);
1336 vo_mouse_autohide
= 1;
1339 void vo_x11_clearwindow_part(Display
* mDisplay
, Window vo_window
,
1340 int img_width
, int img_height
, int use_fs
)
1342 int u_dheight
, u_dwidth
, left_ov
, left_ov2
;
1347 u_dheight
= use_fs
? vo_screenheight
: vo_dheight
;
1348 u_dwidth
= use_fs
? vo_screenwidth
: vo_dwidth
;
1349 if ((u_dheight
<= img_height
) && (u_dwidth
<= img_width
))
1352 left_ov
= (u_dheight
- img_height
) / 2;
1353 left_ov2
= (u_dwidth
- img_width
) / 2;
1355 XFillRectangle(mDisplay
, vo_window
, f_gc
, 0, 0, u_dwidth
, left_ov
);
1356 XFillRectangle(mDisplay
, vo_window
, f_gc
, 0, u_dheight
- left_ov
- 1,
1357 u_dwidth
, left_ov
+ 1);
1359 if (u_dwidth
> img_width
)
1361 XFillRectangle(mDisplay
, vo_window
, f_gc
, 0, left_ov
, left_ov2
,
1363 XFillRectangle(mDisplay
, vo_window
, f_gc
, u_dwidth
- left_ov2
- 1,
1364 left_ov
, left_ov2
+ 1, img_height
);
1370 void vo_x11_clearwindow(Display
* mDisplay
, Window vo_window
)
1374 XFillRectangle(mDisplay
, vo_window
, f_gc
, 0, 0, vo_screenwidth
,
1381 void vo_x11_setlayer(Display
* mDisplay
, Window vo_window
, int layer
)
1386 if (vo_fs_type
& vo_wm_LAYER
)
1388 XClientMessageEvent xev
;
1391 orig_layer
= vo_x11_get_gnome_layer(mDisplay
, vo_window
);
1393 memset(&xev
, 0, sizeof(xev
));
1394 xev
.type
= ClientMessage
;
1395 xev
.display
= mDisplay
;
1396 xev
.window
= vo_window
;
1397 xev
.message_type
= XA_WIN_LAYER
;
1399 xev
.data
.l
[0] = layer
? fs_layer
: orig_layer
; // if not fullscreen, stay on default layer
1400 xev
.data
.l
[1] = CurrentTime
;
1401 mp_msg(MSGT_VO
, MSGL_V
,
1402 "[x11] Layered style stay on top (layer %ld).\n",
1404 XSendEvent(mDisplay
, mRootWin
, False
, SubstructureNotifyMask
,
1406 } else if (vo_fs_type
& vo_wm_NETWM
)
1408 XClientMessageEvent xev
;
1411 memset(&xev
, 0, sizeof(xev
));
1412 xev
.type
= ClientMessage
;
1413 xev
.message_type
= XA_NET_WM_STATE
;
1414 xev
.display
= mDisplay
;
1415 xev
.window
= vo_window
;
1417 xev
.data
.l
[0] = layer
;
1419 if (vo_fs_type
& vo_wm_STAYS_ON_TOP
)
1420 xev
.data
.l
[1] = XA_NET_WM_STATE_STAYS_ON_TOP
;
1421 else if (vo_fs_type
& vo_wm_ABOVE
)
1422 xev
.data
.l
[1] = XA_NET_WM_STATE_ABOVE
;
1423 else if (vo_fs_type
& vo_wm_FULLSCREEN
)
1424 xev
.data
.l
[1] = XA_NET_WM_STATE_FULLSCREEN
;
1425 else if (vo_fs_type
& vo_wm_BELOW
)
1426 // This is not fallback. We can safely assume that the situation
1427 // where only NETWM_STATE_BELOW is supported doesn't exist.
1428 xev
.data
.l
[1] = XA_NET_WM_STATE_BELOW
;
1430 XSendEvent(mDisplay
, mRootWin
, False
, SubstructureRedirectMask
,
1432 state
= XGetAtomName(mDisplay
, xev
.data
.l
[1]);
1433 mp_msg(MSGT_VO
, MSGL_V
,
1434 "[x11] NET style stay on top (layer %d). Using state %s.\n",
1440 static int vo_x11_get_fs_type(int supported
)
1443 int type
= supported
;
1448 for (i
= 0; vo_fstype_list
[i
]; i
++)
1451 char *arg
= vo_fstype_list
[i
];
1453 if (vo_fstype_list
[i
][0] == '-')
1456 arg
= vo_fstype_list
[i
] + 1;
1459 if (!strncmp(arg
, "layer", 5))
1461 if (!neg
&& (arg
[5] == '='))
1463 char *endptr
= NULL
;
1464 int layer
= strtol(vo_fstype_list
[i
] + 6, &endptr
, 10);
1466 if (endptr
&& *endptr
== '\0' && layer
>= 0
1471 type
&= ~vo_wm_LAYER
;
1473 type
|= vo_wm_LAYER
;
1474 } else if (!strcmp(arg
, "above"))
1477 type
&= ~vo_wm_ABOVE
;
1479 type
|= vo_wm_ABOVE
;
1480 } else if (!strcmp(arg
, "fullscreen"))
1483 type
&= ~vo_wm_FULLSCREEN
;
1485 type
|= vo_wm_FULLSCREEN
;
1486 } else if (!strcmp(arg
, "stays_on_top"))
1489 type
&= ~vo_wm_STAYS_ON_TOP
;
1491 type
|= vo_wm_STAYS_ON_TOP
;
1492 } else if (!strcmp(arg
, "below"))
1495 type
&= ~vo_wm_BELOW
;
1497 type
|= vo_wm_BELOW
;
1498 } else if (!strcmp(arg
, "netwm"))
1501 type
&= ~vo_wm_NETWM
;
1503 type
|= vo_wm_NETWM
;
1504 } else if (!strcmp(arg
, "none"))
1513 * \brief update vo_dx, vo_dy, vo_dwidth and vo_dheight with current values of vo_window
1514 * \return returns current color depth of vo_window
1516 int vo_x11_update_geometry(void) {
1517 unsigned depth
, w
, h
;
1520 XGetGeometry(mDisplay
, vo_window
, &dummy_win
, &dummy_int
, &dummy_int
,
1521 &w
, &h
, &dummy_int
, &depth
);
1522 if (w
<= INT_MAX
&& h
<= INT_MAX
) { vo_dwidth
= w
; vo_dheight
= h
; }
1523 XTranslateCoordinates(mDisplay
, vo_window
, mRootWin
, 0, 0, &vo_dx
, &vo_dy
,
1525 return depth
<= INT_MAX
? depth
: 0;
1528 void vo_x11_fullscreen(void)
1532 if (WinID
>= 0 || vo_fs_flip
)
1538 if ( ! (vo_fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1546 vo_x11_ewmh_fullscreen(_NET_WM_STATE_REMOVE
); // removes fullscreen state if wm supports EWMH
1551 vo_x11_ewmh_fullscreen(_NET_WM_STATE_ADD
); // sends fullscreen state to be added if wm supports EWMH
1554 if ( ! (vo_fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1558 vo_old_width
= vo_dwidth
;
1559 vo_old_height
= vo_dheight
;
1561 update_xinerama_info();
1565 h
= vo_screenheight
;
1570 XGetWMNormalHints(mDisplay
, vo_window
, &vo_hint
, &dummy
);
1571 if (!(vo_hint
.flags
& PWinGravity
))
1572 old_gravity
= NorthWestGravity
;
1574 old_gravity
= vo_hint
.win_gravity
;
1576 if (vo_wm_type
== 0 && !(vo_fsmode
& 16))
1578 XUnmapWindow(mDisplay
, vo_window
); // required for MWM
1579 XWithdrawWindow(mDisplay
, vo_window
, mScreen
);
1583 if ( ! (vo_fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1585 vo_x11_decoration(mDisplay
, vo_window
, vo_border
&& !vo_fs
);
1586 vo_x11_sizehint(x
, y
, w
, h
, 0);
1587 vo_x11_setlayer(mDisplay
, vo_window
, vo_fs
);
1590 XMoveResizeWindow(mDisplay
, vo_window
, x
, y
, w
, h
);
1592 /* some WMs lose ontop after fullscreen */
1593 if ((!(vo_fs
)) & vo_ontop
)
1594 vo_x11_setlayer(mDisplay
, vo_window
, vo_ontop
);
1596 XMapRaised(mDisplay
, vo_window
);
1597 if ( ! (vo_fs_type
& vo_wm_FULLSCREEN
) ) // some WMs change window pos on map
1598 XMoveResizeWindow(mDisplay
, vo_window
, x
, y
, w
, h
);
1599 XRaiseWindow(mDisplay
, vo_window
);
1603 void vo_x11_ontop(void)
1605 vo_ontop
= (!(vo_ontop
));
1607 vo_x11_setlayer(mDisplay
, vo_window
, vo_ontop
);
1610 void vo_x11_border(void)
1612 vo_border
= !vo_border
;
1613 vo_x11_decoration(mDisplay
, vo_window
, vo_border
&& !vo_fs
);
1617 * XScreensaver stuff
1620 static int screensaver_off
;
1621 static unsigned int time_last
;
1623 void xscreensaver_heartbeat(void)
1625 unsigned int time
= GetTimerMS();
1627 if (mDisplay
&& screensaver_off
&& (time
- time_last
) > 30000)
1631 XResetScreenSaver(mDisplay
);
1635 static int xss_suspend(Bool suspend
)
1640 int event
, error
, major
, minor
;
1641 if (XScreenSaverQueryExtension(mDisplay
, &event
, &error
) != True
||
1642 XScreenSaverQueryVersion(mDisplay
, &major
, &minor
) != True
)
1644 if (major
< 1 || (major
== 1 && minor
< 1))
1646 XScreenSaverSuspend(mDisplay
, suspend
);
1652 * End of XScreensaver stuff
1655 void saver_on(Display
* mDisplay
)
1658 if (!screensaver_off
)
1660 screensaver_off
= 0;
1661 if (xss_suspend(False
))
1667 if (DPMSQueryExtension(mDisplay
, ¬hing
, ¬hing
))
1669 if (!DPMSEnable(mDisplay
))
1670 { // restoring power saving settings
1671 mp_msg(MSGT_VO
, MSGL_WARN
, "DPMS not available?\n");
1674 // DPMS does not seem to be enabled unless we call DPMSInfo
1678 DPMSForceLevel(mDisplay
, DPMSModeOn
);
1679 DPMSInfo(mDisplay
, &state
, &onoff
);
1682 mp_msg(MSGT_VO
, MSGL_V
,
1683 "Successfully enabled DPMS\n");
1686 mp_msg(MSGT_VO
, MSGL_WARN
, "Could not enable DPMS\n");
1695 void saver_off(Display
* mDisplay
)
1699 if (screensaver_off
)
1701 screensaver_off
= 1;
1702 if (xss_suspend(True
))
1705 if (DPMSQueryExtension(mDisplay
, ¬hing
, ¬hing
))
1710 DPMSInfo(mDisplay
, &state
, &onoff
);
1715 mp_msg(MSGT_VO
, MSGL_V
, "Disabling DPMS\n");
1717 stat
= DPMSDisable(mDisplay
); // monitor powersave off
1718 mp_msg(MSGT_VO
, MSGL_V
, "DPMSDisable stat: %d\n", stat
);
1724 static XErrorHandler old_handler
= NULL
;
1725 static int selectinput_err
= 0;
1726 static int x11_selectinput_errorhandler(Display
* display
,
1727 XErrorEvent
* event
)
1729 if (event
->error_code
== BadAccess
)
1731 selectinput_err
= 1;
1732 mp_msg(MSGT_VO
, MSGL_ERR
,
1733 "X11 error: BadAccess during XSelectInput Call\n");
1734 mp_msg(MSGT_VO
, MSGL_ERR
,
1735 "X11 error: The 'ButtonPressMask' mask of specified window has probably already used by another appication (see man XSelectInput)\n");
1736 /* If you think MPlayer should shutdown with this error,
1737 * comment out the following line */
1740 if (old_handler
!= NULL
)
1741 old_handler(display
, event
);
1743 x11_errorhandler(display
, event
);
1747 void vo_x11_selectinput_witherr(Display
* display
, Window w
,
1750 XSync(display
, False
);
1751 old_handler
= XSetErrorHandler(x11_selectinput_errorhandler
);
1752 selectinput_err
= 0;
1753 if (vo_nomouse_input
)
1755 XSelectInput(display
, w
,
1757 (~(ButtonPressMask
| ButtonReleaseMask
)));
1760 XSelectInput(display
, w
, event_mask
);
1762 XSync(display
, False
);
1763 XSetErrorHandler(old_handler
);
1764 if (selectinput_err
)
1766 mp_msg(MSGT_VO
, MSGL_ERR
,
1767 "X11 error: MPlayer discards mouse control (reconfiguring)\n");
1768 XSelectInput(display
, w
,
1771 (ButtonPressMask
| ButtonReleaseMask
|
1772 PointerMotionMask
)));
1776 #ifdef CONFIG_XF86VM
1777 void vo_vm_switch(void)
1779 int vm_event
, vm_error
;
1781 int i
, j
, have_vm
= 0;
1782 int X
= vo_dwidth
, Y
= vo_dheight
;
1783 int modeline_width
, modeline_height
;
1787 if (XF86VidModeQueryExtension(mDisplay
, &vm_event
, &vm_error
))
1789 XF86VidModeQueryVersion(mDisplay
, &vm_ver
, &vm_rev
);
1790 mp_msg(MSGT_VO
, MSGL_V
, "XF86VidMode extension v%i.%i\n", vm_ver
,
1794 mp_msg(MSGT_VO
, MSGL_WARN
,
1795 "XF86VidMode extension not available.\n");
1800 if (vidmodes
== NULL
)
1801 XF86VidModeGetAllModeLines(mDisplay
, mScreen
, &modecount
,
1804 modeline_width
= vidmodes
[0]->hdisplay
;
1805 modeline_height
= vidmodes
[0]->vdisplay
;
1807 for (i
= 1; i
< modecount
; i
++)
1808 if ((vidmodes
[i
]->hdisplay
>= X
)
1809 && (vidmodes
[i
]->vdisplay
>= Y
))
1810 if ((vidmodes
[i
]->hdisplay
<= modeline_width
)
1811 && (vidmodes
[i
]->vdisplay
<= modeline_height
))
1813 modeline_width
= vidmodes
[i
]->hdisplay
;
1814 modeline_height
= vidmodes
[i
]->vdisplay
;
1818 mp_msg(MSGT_VO
, MSGL_INFO
, MSGTR_SelectedVideoMode
,
1819 modeline_width
, modeline_height
, X
, Y
);
1820 XF86VidModeLockModeSwitch(mDisplay
, mScreen
, 0);
1821 XF86VidModeSwitchToMode(mDisplay
, mScreen
, vidmodes
[j
]);
1822 XF86VidModeSwitchToMode(mDisplay
, mScreen
, vidmodes
[j
]);
1824 // FIXME: all this is more of a hack than proper solution
1825 X
= (vo_screenwidth
- modeline_width
) / 2;
1826 Y
= (vo_screenheight
- modeline_height
) / 2;
1827 XF86VidModeSetViewPort(mDisplay
, mScreen
, X
, Y
);
1830 vo_dwidth
= modeline_width
;
1831 vo_dheight
= modeline_height
;
1832 aspect_save_screenres(modeline_width
, modeline_height
);
1836 void vo_vm_close(void)
1839 if (vidmodes
!= NULL
&& vo_window
!= None
)
1841 if (vidmodes
!= NULL
)
1848 XF86VidModeGetAllModeLines(mDisplay
, mScreen
, &modecount
,
1850 for (i
= 0; i
< modecount
; i
++)
1851 if ((vidmodes
[i
]->hdisplay
== vo_screenwidth
)
1852 && (vidmodes
[i
]->vdisplay
== vo_screenheight
))
1854 mp_msg(MSGT_VO
, MSGL_INFO
,
1855 "Returning to original mode %dx%d\n",
1856 vo_screenwidth
, vo_screenheight
);
1860 XF86VidModeSwitchToMode(mDisplay
, mScreen
, vidmodes
[i
]);
1861 XF86VidModeSwitchToMode(mDisplay
, mScreen
, vidmodes
[i
]);
1868 #endif /* X11_FULLSCREEN */
1872 * Scan the available visuals on this Display/Screen. Try to find
1873 * the 'best' available TrueColor visual that has a decent color
1874 * depth (at least 15bit). If there are multiple visuals with depth
1875 * >= 15bit, we prefer visuals with a smaller color depth.
1877 int vo_find_depth_from_visuals(Display
* dpy
, int screen
,
1878 Visual
** visual_return
)
1880 XVisualInfo visual_tmpl
;
1881 XVisualInfo
*visuals
;
1883 int bestvisual
= -1;
1884 int bestvisual_depth
= -1;
1886 visual_tmpl
.screen
= screen
;
1887 visual_tmpl
.class = TrueColor
;
1888 visuals
= XGetVisualInfo(dpy
,
1889 VisualScreenMask
| VisualClassMask
,
1890 &visual_tmpl
, &nvisuals
);
1891 if (visuals
!= NULL
)
1893 for (i
= 0; i
< nvisuals
; i
++)
1895 mp_msg(MSGT_VO
, MSGL_V
,
1896 "vo: X11 truecolor visual %#lx, depth %d, R:%lX G:%lX B:%lX\n",
1897 visuals
[i
].visualid
, visuals
[i
].depth
,
1898 visuals
[i
].red_mask
, visuals
[i
].green_mask
,
1899 visuals
[i
].blue_mask
);
1901 * Save the visual index and its depth, if this is the first
1902 * truecolor visul, or a visual that is 'preferred' over the
1903 * previous 'best' visual.
1905 if (bestvisual_depth
== -1
1906 || (visuals
[i
].depth
>= 15
1907 && (visuals
[i
].depth
< bestvisual_depth
1908 || bestvisual_depth
< 15)))
1911 bestvisual_depth
= visuals
[i
].depth
;
1915 if (bestvisual
!= -1 && visual_return
!= NULL
)
1916 *visual_return
= visuals
[bestvisual
].visual
;
1920 return bestvisual_depth
;
1924 static Colormap cmap
= None
;
1925 static XColor cols
[256];
1926 static int cm_size
, red_mask
, green_mask
, blue_mask
;
1929 Colormap
vo_x11_create_colormap(XVisualInfo
* vinfo
)
1931 unsigned k
, r
, g
, b
, ru
, gu
, bu
, m
, rv
, gv
, bv
, rvu
, gvu
, bvu
;
1933 if (vinfo
->class != DirectColor
)
1934 return XCreateColormap(mDisplay
, mRootWin
, vinfo
->visual
,
1937 /* can this function get called twice or more? */
1940 cm_size
= vinfo
->colormap_size
;
1941 red_mask
= vinfo
->red_mask
;
1942 green_mask
= vinfo
->green_mask
;
1943 blue_mask
= vinfo
->blue_mask
;
1944 ru
= (red_mask
& (red_mask
- 1)) ^ red_mask
;
1945 gu
= (green_mask
& (green_mask
- 1)) ^ green_mask
;
1946 bu
= (blue_mask
& (blue_mask
- 1)) ^ blue_mask
;
1947 rvu
= 65536ull * ru
/ (red_mask
+ ru
);
1948 gvu
= 65536ull * gu
/ (green_mask
+ gu
);
1949 bvu
= 65536ull * bu
/ (blue_mask
+ bu
);
1952 m
= DoRed
| DoGreen
| DoBlue
;
1953 for (k
= 0; k
< cm_size
; k
++)
1957 cols
[k
].pixel
= r
| g
| b
;
1962 t
= (r
+ ru
) & red_mask
;
1966 t
= (g
+ gu
) & green_mask
;
1970 t
= (b
+ bu
) & blue_mask
;
1978 cmap
= XCreateColormap(mDisplay
, mRootWin
, vinfo
->visual
, AllocAll
);
1979 XStoreColors(mDisplay
, cmap
, cols
, cm_size
);
1984 * Via colormaps/gamma ramps we can do gamma, brightness, contrast,
1985 * hue and red/green/blue intensity, but we cannot do saturation.
1986 * Currently only gamma, brightness and contrast are implemented.
1987 * Is there sufficient interest for hue and/or red/green/blue intensity?
1989 /* these values have range [-100,100] and are initially 0 */
1990 static int vo_gamma
= 0;
1991 static int vo_brightness
= 0;
1992 static int vo_contrast
= 0;
1994 static int transform_color(float val
,
1995 float brightness
, float contrast
, float gamma
) {
1996 float s
= pow(val
, gamma
);
1997 s
= (s
- 0.5) * contrast
+ 0.5;
2003 return (unsigned short) (s
* 65535);
2006 uint32_t vo_x11_set_equalizer(char *name
, int value
)
2008 float gamma
, brightness
, contrast
;
2013 * IMPLEMENTME: consider using XF86VidModeSetGammaRamp in the case
2014 * of TrueColor-ed window but be careful:
2015 * Unlike the colormaps, which are private for the X client
2016 * who created them and thus automatically destroyed on client
2017 * disconnect, this gamma ramp is a system-wide (X-server-wide)
2018 * setting and _must_ be restored before the process exits.
2019 * Unforunately when the process crashes (or gets killed
2020 * for some reason) it is impossible to restore the setting,
2021 * and such behaviour could be rather annoying for the users.
2026 if (!strcasecmp(name
, "brightness"))
2027 vo_brightness
= value
;
2028 else if (!strcasecmp(name
, "contrast"))
2029 vo_contrast
= value
;
2030 else if (!strcasecmp(name
, "gamma"))
2035 brightness
= 0.01 * vo_brightness
;
2036 contrast
= tan(0.0095 * (vo_contrast
+ 100) * M_PI
/ 4);
2037 gamma
= pow(2, -0.02 * vo_gamma
);
2039 rf
= (float) ((red_mask
& (red_mask
- 1)) ^ red_mask
) / red_mask
;
2040 gf
= (float) ((green_mask
& (green_mask
- 1)) ^ green_mask
) /
2042 bf
= (float) ((blue_mask
& (blue_mask
- 1)) ^ blue_mask
) / blue_mask
;
2044 /* now recalculate the colormap using the newly set value */
2045 for (k
= 0; k
< cm_size
; k
++)
2047 cols
[k
].red
= transform_color(rf
* k
, brightness
, contrast
, gamma
);
2048 cols
[k
].green
= transform_color(gf
* k
, brightness
, contrast
, gamma
);
2049 cols
[k
].blue
= transform_color(bf
* k
, brightness
, contrast
, gamma
);
2052 XStoreColors(mDisplay
, cmap
, cols
, cm_size
);
2057 uint32_t vo_x11_get_equalizer(char *name
, int *value
)
2061 if (!strcasecmp(name
, "brightness"))
2062 *value
= vo_brightness
;
2063 else if (!strcasecmp(name
, "contrast"))
2064 *value
= vo_contrast
;
2065 else if (!strcasecmp(name
, "gamma"))
2073 int vo_xv_set_eq(uint32_t xv_port
, char *name
, int value
)
2075 XvAttribute
*attributes
;
2076 int i
, howmany
, xv_atom
;
2078 mp_dbg(MSGT_VO
, MSGL_V
, "xv_set_eq called! (%s, %d)\n", name
, value
);
2080 /* get available attributes */
2081 attributes
= XvQueryPortAttributes(mDisplay
, xv_port
, &howmany
);
2082 for (i
= 0; i
< howmany
&& attributes
; i
++)
2083 if (attributes
[i
].flags
& XvSettable
)
2085 xv_atom
= XInternAtom(mDisplay
, attributes
[i
].name
, True
);
2086 /* since we have SET_DEFAULTS first in our list, we can check if it's available
2087 then trigger it if it's ok so that the other values are at default upon query */
2088 if (xv_atom
!= None
)
2090 int hue
= 0, port_value
, port_min
, port_max
;
2092 if (!strcmp(attributes
[i
].name
, "XV_BRIGHTNESS") &&
2093 (!strcasecmp(name
, "brightness")))
2095 else if (!strcmp(attributes
[i
].name
, "XV_CONTRAST") &&
2096 (!strcasecmp(name
, "contrast")))
2098 else if (!strcmp(attributes
[i
].name
, "XV_SATURATION") &&
2099 (!strcasecmp(name
, "saturation")))
2101 else if (!strcmp(attributes
[i
].name
, "XV_HUE") &&
2102 (!strcasecmp(name
, "hue")))
2107 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
2108 if (!strcmp(attributes
[i
].name
, "XV_RED_INTENSITY") &&
2109 (!strcasecmp(name
, "red_intensity")))
2111 else if (!strcmp(attributes
[i
].name
, "XV_GREEN_INTENSITY")
2112 && (!strcasecmp(name
, "green_intensity")))
2114 else if (!strcmp(attributes
[i
].name
, "XV_BLUE_INTENSITY")
2115 && (!strcasecmp(name
, "blue_intensity")))
2120 port_min
= attributes
[i
].min_value
;
2121 port_max
= attributes
[i
].max_value
;
2123 /* nvidia hue workaround */
2124 if (hue
&& port_min
== 0 && port_max
== 360)
2128 0) ? (port_value
- 100) : (port_value
+ 100);
2134 (port_value
+ 100) * (port_max
- port_min
) / 200 +
2136 XvSetPortAttribute(mDisplay
, xv_port
, xv_atom
, port_value
);
2143 int vo_xv_get_eq(uint32_t xv_port
, char *name
, int *value
)
2146 XvAttribute
*attributes
;
2147 int i
, howmany
, xv_atom
;
2149 /* get available attributes */
2150 attributes
= XvQueryPortAttributes(mDisplay
, xv_port
, &howmany
);
2151 for (i
= 0; i
< howmany
&& attributes
; i
++)
2152 if (attributes
[i
].flags
& XvGettable
)
2154 xv_atom
= XInternAtom(mDisplay
, attributes
[i
].name
, True
);
2155 /* since we have SET_DEFAULTS first in our list, we can check if it's available
2156 then trigger it if it's ok so that the other values are at default upon query */
2157 if (xv_atom
!= None
)
2159 int val
, port_value
= 0, port_min
, port_max
;
2161 XvGetPortAttribute(mDisplay
, xv_port
, xv_atom
,
2164 port_min
= attributes
[i
].min_value
;
2165 port_max
= attributes
[i
].max_value
;
2167 (port_value
- port_min
) * 200 / (port_max
- port_min
) -
2170 if (!strcmp(attributes
[i
].name
, "XV_BRIGHTNESS") &&
2171 (!strcasecmp(name
, "brightness")))
2173 else if (!strcmp(attributes
[i
].name
, "XV_CONTRAST") &&
2174 (!strcasecmp(name
, "contrast")))
2176 else if (!strcmp(attributes
[i
].name
, "XV_SATURATION") &&
2177 (!strcasecmp(name
, "saturation")))
2179 else if (!strcmp(attributes
[i
].name
, "XV_HUE") &&
2180 (!strcasecmp(name
, "hue")))
2182 /* nasty nvidia detect */
2183 if (port_min
== 0 && port_max
== 360)
2184 *value
= (val
>= 0) ? (val
- 100) : (val
+ 100);
2188 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
2189 if (!strcmp(attributes
[i
].name
, "XV_RED_INTENSITY") &&
2190 (!strcasecmp(name
, "red_intensity")))
2192 else if (!strcmp(attributes
[i
].name
, "XV_GREEN_INTENSITY")
2193 && (!strcasecmp(name
, "green_intensity")))
2195 else if (!strcmp(attributes
[i
].name
, "XV_BLUE_INTENSITY")
2196 && (!strcasecmp(name
, "blue_intensity")))
2201 mp_dbg(MSGT_VO
, MSGL_V
, "xv_get_eq called! (%s, %d)\n",
2209 /** \brief contains flags changing the execution of the colorkeying code */
2210 xv_ck_info_t xv_ck_info
= { CK_METHOD_MANUALFILL
, CK_SRC_CUR
};
2211 unsigned long xv_colorkey
; ///< The color used for manual colorkeying.
2212 unsigned int xv_port
; ///< The selected Xv port.
2215 * \brief Interns the requested atom if it is available.
2217 * \param atom_name String containing the name of the requested atom.
2219 * \return Returns the atom if available, else None is returned.
2222 static Atom
xv_intern_atom_if_exists( char const * atom_name
)
2224 XvAttribute
* attributes
;
2226 Atom xv_atom
= None
;
2228 attributes
= XvQueryPortAttributes( mDisplay
, xv_port
, &attrib_count
);
2229 if( attributes
!=NULL
)
2231 for ( i
= 0; i
< attrib_count
; ++i
)
2233 if ( strcmp(attributes
[i
].name
, atom_name
) == 0 )
2235 xv_atom
= XInternAtom( mDisplay
, atom_name
, False
);
2236 break; // found what we want, break out
2239 XFree( attributes
);
2246 * \brief Try to enable vsync for xv.
2247 * \return Returns -1 if not available, 0 on failure and 1 on success.
2249 int vo_xv_enable_vsync(void)
2251 Atom xv_atom
= xv_intern_atom_if_exists("XV_SYNC_TO_VBLANK");
2252 if (xv_atom
== None
)
2254 return XvSetPortAttribute(mDisplay
, xv_port
, xv_atom
, 1) == Success
;
2258 * \brief Get maximum supported source image dimensions.
2260 * This function does not set the variables pointed to by
2261 * width and height if the information could not be retrieved,
2262 * so the caller is reponsible for properly initializing them.
2264 * \param width [out] The maximum width gets stored here.
2265 * \param height [out] The maximum height gets stored here.
2268 void vo_xv_get_max_img_dim( uint32_t * width
, uint32_t * height
)
2270 XvEncodingInfo
* encodings
;
2271 //unsigned long num_encodings, idx; to int or too long?!
2272 unsigned int num_encodings
, idx
;
2274 XvQueryEncodings( mDisplay
, xv_port
, &num_encodings
, &encodings
);
2278 for ( idx
= 0; idx
< num_encodings
; ++idx
)
2280 if ( strcmp( encodings
[idx
].name
, "XV_IMAGE" ) == 0 )
2282 *width
= encodings
[idx
].width
;
2283 *height
= encodings
[idx
].height
;
2289 mp_msg( MSGT_VO
, MSGL_V
,
2290 "[xv common] Maximum source image dimensions: %ux%u\n",
2293 XvFreeEncodingInfo( encodings
);
2297 * \brief Print information about the colorkey method and source.
2299 * \param ck_handling Integer value containing the information about
2300 * colorkey handling (see x11_common.h).
2302 * Outputs the content of |ck_handling| as a readable message.
2305 void vo_xv_print_ck_info(void)
2307 mp_msg( MSGT_VO
, MSGL_V
, "[xv common] " );
2309 switch ( xv_ck_info
.method
)
2311 case CK_METHOD_NONE
:
2312 mp_msg( MSGT_VO
, MSGL_V
, "Drawing no colorkey.\n" ); return;
2313 case CK_METHOD_AUTOPAINT
:
2314 mp_msg( MSGT_VO
, MSGL_V
, "Colorkey is drawn by Xv." ); break;
2315 case CK_METHOD_MANUALFILL
:
2316 mp_msg( MSGT_VO
, MSGL_V
, "Drawing colorkey manually." ); break;
2317 case CK_METHOD_BACKGROUND
:
2318 mp_msg( MSGT_VO
, MSGL_V
, "Colorkey is drawn as window background." ); break;
2321 mp_msg( MSGT_VO
, MSGL_V
, "\n[xv common] " );
2323 switch ( xv_ck_info
.source
)
2326 mp_msg( MSGT_VO
, MSGL_V
, "Using colorkey from Xv (0x%06lx).\n",
2330 if ( xv_ck_info
.method
== CK_METHOD_AUTOPAINT
)
2332 mp_msg( MSGT_VO
, MSGL_V
,
2333 "Ignoring colorkey from MPlayer (0x%06lx).\n",
2338 mp_msg( MSGT_VO
, MSGL_V
,
2339 "Using colorkey from MPlayer (0x%06lx)."
2340 " Use -colorkey to change.\n",
2345 mp_msg( MSGT_VO
, MSGL_V
,
2346 "Setting and using colorkey from MPlayer (0x%06lx)."
2347 " Use -colorkey to change.\n",
2353 * \brief Init colorkey depending on the settings in xv_ck_info.
2355 * \return Returns 0 on failure and 1 on success.
2357 * Sets the colorkey variable according to the CK_SRC_* and CK_METHOD_*
2358 * flags in xv_ck_info.
2362 * - manual colorkey drawing ( CK_METHOD_MANUALFILL )
2363 * - set colorkey as window background ( CK_METHOD_BACKGROUND )
2364 * - let Xv paint the colorkey ( CK_METHOD_AUTOPAINT )
2366 * - use currently set colorkey ( CK_SRC_CUR )
2367 * - use colorkey in vo_colorkey ( CK_SRC_USE )
2368 * - use and set colorkey in vo_colorkey ( CK_SRC_SET )
2370 * NOTE: If vo_colorkey has bits set after the first 3 low order bytes
2371 * we don't draw anything as this means it was forced to off.
2373 int vo_xv_init_colorkey(void)
2378 /* check if colorkeying is needed */
2379 xv_atom
= xv_intern_atom_if_exists( "XV_COLORKEY" );
2381 /* if we have to deal with colorkeying ... */
2382 if( xv_atom
!= None
&& !(vo_colorkey
& 0xFF000000) )
2384 /* check if we should use the colorkey specified in vo_colorkey */
2385 if ( xv_ck_info
.source
!= CK_SRC_CUR
)
2387 xv_colorkey
= vo_colorkey
;
2389 /* check if we have to set the colorkey too */
2390 if ( xv_ck_info
.source
== CK_SRC_SET
)
2392 xv_atom
= XInternAtom(mDisplay
, "XV_COLORKEY",False
);
2394 rez
= XvSetPortAttribute( mDisplay
, xv_port
, xv_atom
, vo_colorkey
);
2395 if ( rez
!= Success
)
2397 mp_msg( MSGT_VO
, MSGL_FATAL
,
2398 "[xv common] Couldn't set colorkey!\n" );
2399 return 0; // error setting colorkey
2407 rez
=XvGetPortAttribute(mDisplay
,xv_port
, xv_atom
, &colorkey_ret
);
2408 if ( rez
== Success
)
2410 xv_colorkey
= colorkey_ret
;
2414 mp_msg( MSGT_VO
, MSGL_FATAL
,
2415 "[xv common] Couldn't get colorkey!"
2416 "Maybe the selected Xv port has no overlay.\n" );
2417 return 0; // error getting colorkey
2421 xv_atom
= xv_intern_atom_if_exists( "XV_AUTOPAINT_COLORKEY" );
2423 /* should we draw the colorkey ourselves or activate autopainting? */
2424 if ( xv_ck_info
.method
== CK_METHOD_AUTOPAINT
)
2426 rez
= !Success
; // reset rez to something different than Success
2428 if ( xv_atom
!= None
) // autopaint is supported
2430 rez
= XvSetPortAttribute( mDisplay
, xv_port
, xv_atom
, 1 );
2433 if ( rez
!= Success
)
2435 // fallback to manual colorkey drawing
2436 xv_ck_info
.method
= CK_METHOD_MANUALFILL
;
2439 else // disable colorkey autopainting if supported
2441 if ( xv_atom
!= None
) // we have autopaint attribute
2443 XvSetPortAttribute( mDisplay
, xv_port
, xv_atom
, 0 );
2447 else // do no colorkey drawing at all
2449 xv_ck_info
.method
= CK_METHOD_NONE
;
2450 } /* end: should we draw colorkey */
2452 /* output information about the current colorkey settings */
2453 vo_xv_print_ck_info();
2455 return 1; // success
2459 * \brief Draw the colorkey on the video window.
2461 * Draws the colorkey depending on the set method ( colorkey_handling ).
2463 * Also draws the black bars ( when the video doesn't fit the display in
2464 * fullscreen ) separately, so they don't overlap with the video area.
2465 * It doesn't call XFlush.
2468 void vo_xv_draw_colorkey( int32_t x
, int32_t y
,
2469 int32_t w
, int32_t h
)
2471 if( xv_ck_info
.method
== CK_METHOD_MANUALFILL
||
2472 xv_ck_info
.method
== CK_METHOD_BACKGROUND
)//less tearing than XClearWindow()
2474 XSetForeground( mDisplay
, vo_gc
, xv_colorkey
);
2475 XFillRectangle( mDisplay
, vo_window
, vo_gc
,
2480 /* draw black bars if needed */
2481 /* TODO! move this to vo_x11_clearwindow_part() */
2484 XSetForeground( mDisplay
, vo_gc
, 0 );
2485 /* making non-overlap fills, requires 8 checks instead of 4 */
2487 XFillRectangle( mDisplay
, vo_window
, vo_gc
,
2491 XFillRectangle( mDisplay
, vo_window
, vo_gc
,
2493 x
, vo_screenheight
);
2494 if (x
+ w
< vo_screenwidth
)
2495 XFillRectangle( mDisplay
, vo_window
, vo_gc
,
2497 vo_screenwidth
, vo_screenheight
);
2498 if (y
+ h
< vo_screenheight
)
2499 XFillRectangle( mDisplay
, vo_window
, vo_gc
,
2501 vo_screenwidth
, vo_screenheight
);
2505 /** \brief Tests if a valid argument for the ck suboption was given. */
2506 int xv_test_ck( void * arg
)
2508 strarg_t
* strarg
= (strarg_t
*)arg
;
2510 if ( strargcmp( strarg
, "use" ) == 0 ||
2511 strargcmp( strarg
, "set" ) == 0 ||
2512 strargcmp( strarg
, "cur" ) == 0 )
2519 /** \brief Tests if a valid arguments for the ck-method suboption was given. */
2520 int xv_test_ckm( void * arg
)
2522 strarg_t
* strarg
= (strarg_t
*)arg
;
2524 if ( strargcmp( strarg
, "bg" ) == 0 ||
2525 strargcmp( strarg
, "man" ) == 0 ||
2526 strargcmp( strarg
, "auto" ) == 0 )
2535 * \brief Modify the colorkey_handling var according to str
2537 * Checks if a valid pointer ( not NULL ) to the string
2538 * was given. And in that case modifies the colorkey_handling
2539 * var to reflect the requested behaviour.
2540 * If nothing happens the content of colorkey_handling stays
2543 * \param str Pointer to the string or NULL
2546 void xv_setup_colorkeyhandling( char const * ck_method_str
,
2547 char const * ck_str
)
2549 /* check if a valid pointer to the string was passed */
2552 if ( strncmp( ck_str
, "use", 3 ) == 0 )
2554 xv_ck_info
.source
= CK_SRC_USE
;
2556 else if ( strncmp( ck_str
, "set", 3 ) == 0 )
2558 xv_ck_info
.source
= CK_SRC_SET
;
2561 /* check if a valid pointer to the string was passed */
2562 if ( ck_method_str
)
2564 if ( strncmp( ck_method_str
, "bg", 2 ) == 0 )
2566 xv_ck_info
.method
= CK_METHOD_BACKGROUND
;
2568 else if ( strncmp( ck_method_str
, "man", 3 ) == 0 )
2570 xv_ck_info
.method
= CK_METHOD_MANUALFILL
;
2572 else if ( strncmp( ck_method_str
, "auto", 4 ) == 0 )
2574 xv_ck_info
.method
= CK_METHOD_AUTOPAINT
;