9 #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>
40 #include <X11/XF86keysym.h>
44 #include <X11/extensions/Xv.h>
45 #include <X11/extensions/Xvlib.h>
48 #include "../input/input.h"
49 #include "../input/mouse.h"
52 #include "../Gui/interface.h"
53 #include "../mplayer.h"
56 #define WIN_LAYER_ONBOTTOM 2
57 #define WIN_LAYER_NORMAL 4
58 #define WIN_LAYER_ONTOP 6
59 #define WIN_LAYER_ABOVE_DOCK 10
61 int fs_layer
= WIN_LAYER_ABOVE_DOCK
;
62 static int orig_layer
= 0;
63 static int old_gravity
= NorthWestGravity
;
65 int stop_xscreensaver
= 0;
67 static int dpms_disabled
= 0;
68 static int timeout_save
= 0;
69 static int kdescreensaver_was_running
= 0;
71 char *mDisplayName
= NULL
;
72 Display
*mDisplay
= NULL
;
77 /* output window id */
79 int vo_mouse_autohide
= 0;
81 int vo_fs_type
= 0; // needs to be accessible for GUI X11 code
82 static int vo_fs_flip
= 0;
83 char **vo_fstype_list
;
85 /* if equal to 1 means that WM is a metacity (broken as hell) */
86 int metacity_hack
= 0;
88 static Atom XA_NET_SUPPORTED
;
89 static Atom XA_NET_WM_STATE
;
90 static Atom XA_NET_WM_STATE_FULLSCREEN
;
91 static Atom XA_NET_WM_STATE_ABOVE
;
92 static Atom XA_NET_WM_STATE_STAYS_ON_TOP
;
93 static Atom XA_NET_WM_STATE_BELOW
;
94 static Atom XA_NET_WM_PID
;
95 static Atom XA_WIN_PROTOCOLS
;
96 static Atom XA_WIN_LAYER
;
97 static Atom XA_WIN_HINTS
;
98 static Atom XA_BLACKBOX_PID
;
100 #define XA_INIT(x) XA##x = XInternAtom(mDisplay, #x, False)
102 static int vo_old_x
= 0;
103 static int vo_old_y
= 0;
104 static int vo_old_width
= 0;
105 static int vo_old_height
= 0;
108 int xinerama_screen
= 0;
113 XF86VidModeModeInfo
**vidmodes
= NULL
;
114 XF86VidModeModeLine modeline
;
117 static int vo_x11_get_fs_type(int supported
);
121 * Sends the EWMH fullscreen state event.
123 * action: could be on of _NET_WM_STATE_REMOVE -- remove state
124 * _NET_WM_STATE_ADD -- add state
125 * _NET_WM_STATE_TOGGLE -- toggle
127 void vo_x11_ewmh_fullscreen(int action
)
129 assert(action
== _NET_WM_STATE_REMOVE
||
130 action
== _NET_WM_STATE_ADD
|| action
== _NET_WM_STATE_TOGGLE
);
132 if (vo_fs_type
& vo_wm_FULLSCREEN
)
136 /* init X event structure for _NET_WM_FULLSCREEN client msg */
137 xev
.xclient
.type
= ClientMessage
;
138 xev
.xclient
.serial
= 0;
139 xev
.xclient
.send_event
= True
;
140 xev
.xclient
.message_type
= XInternAtom(mDisplay
,
141 "_NET_WM_STATE", False
);
142 xev
.xclient
.window
= vo_window
;
143 xev
.xclient
.format
= 32;
144 xev
.xclient
.data
.l
[0] = action
;
145 xev
.xclient
.data
.l
[1] = XInternAtom(mDisplay
,
146 "_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 unsigned char bm_no_data
[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
171 return; // do not hide, if we're playing at rootwin
173 colormap
= DefaultColormap(disp
, DefaultScreen(disp
));
174 XAllocNamedColor(disp
, colormap
, "black", &black
, &dummy
);
175 bm_no
= XCreateBitmapFromData(disp
, win
, bm_no_data
, 8, 8);
176 no_ptr
= XCreatePixmapCursor(disp
, bm_no
, bm_no
, &black
, &black
, 0, 0);
177 XDefineCursor(disp
, win
, no_ptr
);
178 XFreeCursor(disp
, no_ptr
);
180 XFreePixmap(disp
, bm_no
);
183 void vo_showcursor(Display
* disp
, Window win
)
187 XDefineCursor(disp
, win
, 0);
190 static int x11_errorhandler(Display
* display
, XErrorEvent
* event
)
195 XGetErrorText(display
, event
->error_code
, (char *) &msg
, MSGLEN
);
197 mp_msg(MSGT_VO
, MSGL_ERR
, "X11 error: %s\n", msg
);
199 mp_msg(MSGT_VO
, MSGL_V
,
200 "Type: %x, display: %x, resourceid: %x, serial: %x\n",
201 event
->type
, event
->display
, event
->resourceid
, event
->serial
);
202 mp_msg(MSGT_VO
, MSGL_V
,
203 "Error code: %x, request code: %x, minor code: %x\n",
204 event
->error_code
, event
->request_code
, event
->minor_code
);
207 //exit_player("X11 error");
211 void fstype_help(void)
213 mp_msg(MSGT_VO
, MSGL_INFO
, MSGTR_AvailableFsType
);
215 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "none",
216 "don't set fullscreen window layer");
217 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "layer",
218 "use _WIN_LAYER hint with default layer");
219 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "layer=<0..15>",
220 "use _WIN_LAYER hint with a given layer number");
221 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "netwm",
222 "force NETWM style");
223 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "above",
224 "use _NETWM_STATE_ABOVE hint if available");
225 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "below",
226 "use _NETWM_STATE_BELOW hint if available");
227 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "fullscreen",
228 "use _NETWM_STATE_FULLSCREEN hint if availale");
229 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "stays_on_top",
230 "use _NETWM_STATE_STAYS_ON_TOP hint if available");
231 mp_msg(MSGT_VO
, MSGL_INFO
,
232 "You can also negate the settings with simply putting '-' in the beginning");
235 static void fstype_dump(int fstype
)
239 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Current fstype setting honours");
240 if (fstype
& vo_wm_LAYER
)
241 mp_msg(MSGT_VO
, MSGL_V
, " LAYER");
242 if (fstype
& vo_wm_FULLSCREEN
)
243 mp_msg(MSGT_VO
, MSGL_V
, " FULLSCREEN");
244 if (fstype
& vo_wm_STAYS_ON_TOP
)
245 mp_msg(MSGT_VO
, MSGL_V
, " STAYS_ON_TOP");
246 if (fstype
& vo_wm_ABOVE
)
247 mp_msg(MSGT_VO
, MSGL_V
, " ABOVE");
248 if (fstype
& vo_wm_BELOW
)
249 mp_msg(MSGT_VO
, MSGL_V
, " BELOW");
250 mp_msg(MSGT_VO
, MSGL_V
, " X atoms\n");
252 mp_msg(MSGT_VO
, MSGL_V
,
253 "[x11] Current fstype setting doesn't honour any X atoms\n");
256 static int net_wm_support_state_test(Atom atom
)
258 #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; } }
260 NET_WM_STATE_TEST(FULLSCREEN
);
261 NET_WM_STATE_TEST(ABOVE
);
262 NET_WM_STATE_TEST(STAYS_ON_TOP
);
263 NET_WM_STATE_TEST(BELOW
);
267 static int x11_get_property(Atom type
, Atom
** args
, unsigned long *nitems
)
270 unsigned long bytesafter
;
273 XGetWindowProperty(mDisplay
, mRootWin
, type
, 0, 16384, False
,
274 AnyPropertyType
, &type
, &format
, nitems
,
275 &bytesafter
, (unsigned char **) args
)
279 static int vo_wm_detect(void)
283 unsigned long nitems
;
289 // -- supports layers
290 if (x11_get_property(XA_WIN_PROTOCOLS
, &args
, &nitems
))
292 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Detected wm supports layers.\n");
293 for (i
= 0; i
< nitems
; i
++)
295 if (args
[i
] == XA_WIN_LAYER
)
300 // metacity is the only manager I know which reports support only for _WIN_LAYER
301 // hint in _WIN_PROTOCOLS (what's more support for it is broken)
305 if (wm
&& (metacity_hack
== 1))
307 // metacity reports that it supports layers, but it is not really truth :-)
309 mp_msg(MSGT_VO
, MSGL_V
,
310 "[x11] Using workaround for Metacity bugs.\n");
314 if (x11_get_property(XA_NET_SUPPORTED
, &args
, &nitems
))
316 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Detected wm supports NetWM.\n");
317 for (i
= 0; i
< nitems
; i
++)
318 wm
|= net_wm_support_state_test(args
[i
]);
321 // ugly hack for broken OpenBox _NET_WM_STATE_FULLSCREEN support
322 // (in their implementation it only changes internal state of window, nothing more!!!)
323 if (wm
& vo_wm_FULLSCREEN
)
325 if (x11_get_property(XA_BLACKBOX_PID
, &args
, &nitems
))
327 mp_msg(MSGT_VO
, MSGL_V
,
328 "[x11] Detected wm is a broken OpenBox.\n");
329 wm
^= vo_wm_FULLSCREEN
;
337 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Unknown wm type...\n");
341 static void init_atoms(void)
343 XA_INIT(_NET_SUPPORTED
);
344 XA_INIT(_NET_WM_STATE
);
345 XA_INIT(_NET_WM_STATE_FULLSCREEN
);
346 XA_INIT(_NET_WM_STATE_ABOVE
);
347 XA_INIT(_NET_WM_STATE_STAYS_ON_TOP
);
348 XA_INIT(_NET_WM_STATE_BELOW
);
349 XA_INIT(_NET_WM_PID
);
350 XA_INIT(_WIN_PROTOCOLS
);
353 XA_INIT(_BLACKBOX_PID
);
362 // char * DisplayName = ":0.0";
363 // Display * mDisplay;
364 XImage
*mXImage
= NULL
;
367 XWindowAttributes attribs
;
371 WinID
= 0; // use root win
373 if (vo_depthonscreen
)
374 return 1; // already called
376 XSetErrorHandler(x11_errorhandler
);
380 if (!(mDisplayName
= getenv("DISPLAY")))
381 mDisplayName
= strdup(":0.0");
383 dispName
= XDisplayName(mDisplayName
);
386 mp_msg(MSGT_VO
, MSGL_V
, "X11 opening display: %s\n", dispName
);
388 mDisplay
= XOpenDisplay(dispName
);
391 mp_msg(MSGT_VO
, MSGL_ERR
,
392 "vo: couldn't open the X11 display (%s)!\n", dispName
);
395 mScreen
= DefaultScreen(mDisplay
); // Screen ID.
396 mRootWin
= RootWindow(mDisplay
, mScreen
); // Root window ID.
401 if (XineramaIsActive(mDisplay
))
403 XineramaScreenInfo
*screens
;
406 screens
= XineramaQueryScreens(mDisplay
, &num_screens
);
407 if (xinerama_screen
>= num_screens
)
410 vo_screenwidth
= screens
[xinerama_screen
].width
;
411 if (!vo_screenheight
)
412 vo_screenheight
= screens
[xinerama_screen
].height
;
413 xinerama_x
= screens
[xinerama_screen
].x_org
;
414 xinerama_y
= screens
[xinerama_screen
].y_org
;
423 XF86VidModeGetModeLine(mDisplay
, mScreen
, &clock
, &modeline
);
425 vo_screenwidth
= modeline
.hdisplay
;
426 if (!vo_screenheight
)
427 vo_screenheight
= modeline
.vdisplay
;
432 vo_screenwidth
= DisplayWidth(mDisplay
, mScreen
);
433 if (!vo_screenheight
)
434 vo_screenheight
= DisplayHeight(mDisplay
, mScreen
);
436 // get color depth (from root window, or the best visual):
437 XGetWindowAttributes(mDisplay
, mRootWin
, &attribs
);
438 depth
= attribs
.depth
;
440 if (depth
!= 15 && depth
!= 16 && depth
!= 24 && depth
!= 32)
444 depth
= vo_find_depth_from_visuals(mDisplay
, mScreen
, &visual
);
446 mXImage
= XCreateImage(mDisplay
, visual
, depth
, ZPixmap
,
447 0, NULL
, 1, 1, 8, 1);
450 XGetImage(mDisplay
, mRootWin
, 0, 0, 1, 1, AllPlanes
, ZPixmap
);
452 vo_depthonscreen
= depth
; // display depth on screen
454 // get bits/pixel from XImage structure:
461 * for the depth==24 case, the XImage structures might use
462 * 24 or 32 bits of data per pixel. The global variable
463 * vo_depthonscreen stores the amount of data per pixel in the
466 * Maybe we should rename vo_depthonscreen to (or add) vo_bpp?
468 bpp
= mXImage
->bits_per_pixel
;
469 if ((vo_depthonscreen
+ 7) / 8 != (bpp
+ 7) / 8)
470 vo_depthonscreen
= bpp
; // by A'rpi
472 mXImage
->red_mask
| mXImage
->green_mask
| mXImage
->blue_mask
;
473 mp_msg(MSGT_VO
, MSGL_V
,
474 "vo: X11 color mask: %X (R:%lX G:%lX B:%lX)\n", mask
,
475 mXImage
->red_mask
, mXImage
->green_mask
, mXImage
->blue_mask
);
476 XDestroyImage(mXImage
);
478 if (((vo_depthonscreen
+ 7) / 8) == 2)
481 vo_depthonscreen
= 15;
482 else if (mask
== 0xFFFF)
483 vo_depthonscreen
= 16;
485 // XCloseDisplay( mDisplay );
486 /* slightly improved local display detection AST */
487 if (strncmp(dispName
, "unix:", 5) == 0)
489 else if (strncmp(dispName
, "localhost:", 10) == 0)
491 if (*dispName
== ':' && atoi(dispName
+ 1) < 10)
495 mp_msg(MSGT_VO
, MSGL_INFO
,
496 "vo: X11 running at %dx%d with depth %d and %d bpp (\"%s\" => %s display)\n",
497 vo_screenwidth
, vo_screenheight
, depth
, vo_depthonscreen
,
498 dispName
, mLocalDisplay
? "local" : "remote");
500 vo_wm_type
= vo_wm_detect();
502 vo_fs_type
= vo_x11_get_fs_type(vo_wm_type
);
504 fstype_dump(vo_fs_type
);
514 mp_msg(MSGT_VO
, MSGL_V
,
515 "vo: x11 uninit called but X11 not inited..\n");
518 // if( !vo_depthonscreen ) return;
519 mp_msg(MSGT_VO
, MSGL_V
, "vo: uninit ...\n");
520 XSetErrorHandler(NULL
);
521 XCloseDisplay(mDisplay
);
522 vo_depthonscreen
= 0;
526 #include "../osdep/keycodes.h"
529 extern void mplayer_put_key(int code
);
531 #ifdef XF86XK_AudioPause
532 void vo_x11_putkey_ext(int keysym
)
536 case XF86XK_AudioPause
:
537 mplayer_put_key(KEY_XF86_PAUSE
);
539 case XF86XK_AudioStop
:
540 mplayer_put_key(KEY_XF86_STOP
);
542 case XF86XK_AudioPrev
:
543 mplayer_put_key(KEY_XF86_PREV
);
545 case XF86XK_AudioNext
:
546 mplayer_put_key(KEY_XF86_NEXT
);
554 void vo_x11_putkey(int key
)
559 mplayer_put_key(KEY_LEFT
);
562 mplayer_put_key(KEY_RIGHT
);
565 mplayer_put_key(KEY_UP
);
568 mplayer_put_key(KEY_DOWN
);
571 mplayer_put_key(' ');
574 mplayer_put_key(KEY_ESC
);
577 mplayer_put_key(KEY_ENTER
);
580 mplayer_put_key(KEY_BS
);
583 mplayer_put_key(KEY_DELETE
);
586 mplayer_put_key(KEY_INSERT
);
589 mplayer_put_key(KEY_HOME
);
592 mplayer_put_key(KEY_END
);
595 mplayer_put_key(KEY_PAGE_UP
);
598 mplayer_put_key(KEY_PAGE_DOWN
);
601 mplayer_put_key(KEY_F
+ 1);
604 mplayer_put_key(KEY_F
+ 2);
607 mplayer_put_key(KEY_F
+ 3);
610 mplayer_put_key(KEY_F
+ 4);
613 mplayer_put_key(KEY_F
+ 5);
616 mplayer_put_key(KEY_F
+ 6);
619 mplayer_put_key(KEY_F
+ 7);
622 mplayer_put_key(KEY_F
+ 8);
625 mplayer_put_key(KEY_F
+ 9);
628 mplayer_put_key(KEY_F
+ 10);
631 mplayer_put_key(KEY_F
+ 11);
634 mplayer_put_key(KEY_F
+ 12);
638 mplayer_put_key('q');
642 mplayer_put_key('p');
646 mplayer_put_key('-');
650 mplayer_put_key('+');
654 mplayer_put_key('*');
658 mplayer_put_key('/');
661 mplayer_put_key('<');
664 mplayer_put_key('>');
667 mplayer_put_key(KEY_KP0
);
671 mplayer_put_key(KEY_KP1
);
675 mplayer_put_key(KEY_KP2
);
679 mplayer_put_key(KEY_KP3
);
683 mplayer_put_key(KEY_KP4
);
687 mplayer_put_key(KEY_KP5
);
691 mplayer_put_key(KEY_KP6
);
695 mplayer_put_key(KEY_KP7
);
699 mplayer_put_key(KEY_KP8
);
703 mplayer_put_key(KEY_KP9
);
706 mplayer_put_key(KEY_KPDEC
);
709 mplayer_put_key(KEY_KPINS
);
712 mplayer_put_key(KEY_KPDEL
);
715 mplayer_put_key(KEY_KPENTER
);
719 mplayer_put_key('m');
723 mplayer_put_key('o');
727 mplayer_put_key('`');
730 mplayer_put_key('~');
733 mplayer_put_key('!');
736 mplayer_put_key('@');
739 mplayer_put_key('#');
742 mplayer_put_key('$');
745 mplayer_put_key('%');
748 mplayer_put_key('^');
751 mplayer_put_key('&');
754 mplayer_put_key('(');
757 mplayer_put_key(')');
760 mplayer_put_key('_');
763 mplayer_put_key('{');
766 mplayer_put_key('}');
769 mplayer_put_key(':');
772 mplayer_put_key(';');
775 mplayer_put_key('\"');
778 mplayer_put_key('\'');
781 mplayer_put_key(',');
784 mplayer_put_key('.');
787 mplayer_put_key('?');
790 mplayer_put_key('\\');
793 mplayer_put_key('|');
796 mplayer_put_key('=');
799 mplayer_put_key('[');
802 mplayer_put_key(']');
807 if ((key
>= 'a' && key
<= 'z') || (key
>= 'A' && key
<= 'Z') ||
808 (key
>= '0' && key
<= '9'))
809 mplayer_put_key(key
);
815 // ----- Motif header: -------
817 #define MWM_HINTS_FUNCTIONS (1L << 0)
818 #define MWM_HINTS_DECORATIONS (1L << 1)
819 #define MWM_HINTS_INPUT_MODE (1L << 2)
820 #define MWM_HINTS_STATUS (1L << 3)
822 #define MWM_FUNC_ALL (1L << 0)
823 #define MWM_FUNC_RESIZE (1L << 1)
824 #define MWM_FUNC_MOVE (1L << 2)
825 #define MWM_FUNC_MINIMIZE (1L << 3)
826 #define MWM_FUNC_MAXIMIZE (1L << 4)
827 #define MWM_FUNC_CLOSE (1L << 5)
829 #define MWM_DECOR_ALL (1L << 0)
830 #define MWM_DECOR_BORDER (1L << 1)
831 #define MWM_DECOR_RESIZEH (1L << 2)
832 #define MWM_DECOR_TITLE (1L << 3)
833 #define MWM_DECOR_MENU (1L << 4)
834 #define MWM_DECOR_MINIMIZE (1L << 5)
835 #define MWM_DECOR_MAXIMIZE (1L << 6)
837 #define MWM_INPUT_MODELESS 0
838 #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
839 #define MWM_INPUT_SYSTEM_MODAL 2
840 #define MWM_INPUT_FULL_APPLICATION_MODAL 3
841 #define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL
843 #define MWM_TEAROFF_WINDOW (1L<<0)
854 extern MotifWmHints vo_MotifWmHints
;
855 extern Atom vo_MotifHints
;
856 extern int vo_depthonscreen
;
857 extern int vo_screenwidth
;
858 extern int vo_screenheight
;
860 static MotifWmHints vo_MotifWmHints
;
861 static Atom vo_MotifHints
= None
;
863 void vo_x11_decoration(Display
* vo_Display
, Window w
, int d
)
865 static unsigned int olddecor
= MWM_DECOR_ALL
;
866 static unsigned int oldfuncs
=
867 MWM_FUNC_MOVE
| MWM_FUNC_CLOSE
| MWM_FUNC_MINIMIZE
|
868 MWM_FUNC_MAXIMIZE
| MWM_FUNC_RESIZE
;
871 unsigned long mn
, mb
;
878 XSetTransientForHint(vo_Display
, w
,
879 RootWindow(vo_Display
, mScreen
));
882 vo_MotifHints
= XInternAtom(vo_Display
, "_MOTIF_WM_HINTS", 0);
883 if (vo_MotifHints
!= None
)
887 MotifWmHints
*mhints
= NULL
;
889 XGetWindowProperty(vo_Display
, w
, vo_MotifHints
, 0, 20, False
,
890 vo_MotifHints
, &mtype
, &mformat
, &mn
,
891 &mb
, (unsigned char **) &mhints
);
894 if (mhints
->flags
& MWM_HINTS_DECORATIONS
)
895 olddecor
= mhints
->decorations
;
896 if (mhints
->flags
& MWM_HINTS_FUNCTIONS
)
897 oldfuncs
= mhints
->functions
;
902 memset(&vo_MotifWmHints
, 0, sizeof(MotifWmHints
));
903 vo_MotifWmHints
.flags
=
904 MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
907 vo_MotifWmHints
.functions
= oldfuncs
;
911 vo_MotifWmHints
.decorations
=
912 d
| ((vo_fsmode
& 2) ? 0 : MWM_DECOR_MENU
);
914 vo_MotifWmHints
.decorations
=
915 d
| ((vo_fsmode
& 2) ? MWM_DECOR_MENU
: 0);
917 XChangeProperty(vo_Display
, w
, vo_MotifHints
, vo_MotifHints
, 32,
919 (unsigned char *) &vo_MotifWmHints
,
920 (vo_fsmode
& 4) ? 4 : 5);
924 void vo_x11_classhint(Display
* display
, Window window
, char *name
)
927 pid_t pid
= getpid();
929 wmClass
.res_name
= name
;
930 wmClass
.res_class
= "MPlayer";
931 XSetClassHint(display
, window
, &wmClass
);
932 XChangeProperty(display
, window
, XA_NET_WM_PID
, XA_CARDINAL
, 32,
933 PropModeReplace
, (unsigned char *) &pid
, 1);
936 Window vo_window
= None
;
942 void vo_setwindow(Window w
, GC g
)
952 if (vo_window
!= None
)
953 vo_showcursor(mDisplay
, vo_window
);
957 XFreeGC(mDisplay
, f_gc
);
961 /* destroy window only if it's not controlled by GUI */
967 XSetBackground(mDisplay
, vo_gc
, 0);
968 XFreeGC(mDisplay
, vo_gc
);
971 if (vo_window
!= None
)
973 XClearWindow(mDisplay
, vo_window
);
978 XUnmapWindow(mDisplay
, vo_window
);
979 XDestroyWindow(mDisplay
, vo_window
);
982 XNextEvent(mDisplay
, &xev
);
984 while (xev
.type
!= DestroyNotify
985 || xev
.xdestroywindow
.event
!= vo_window
);
990 vo_old_width
= vo_old_height
= 0;
994 int vo_mouse_timer_const
= 30;
995 static int vo_mouse_counter
= 30;
997 int vo_x11_check_events(Display
* mydisplay
)
1003 static XComposeStatus stat
;
1005 // unsigned long vo_KeyTable[512];
1007 if ((vo_mouse_autohide
) && (--vo_mouse_counter
== 0))
1008 vo_hidecursor(mydisplay
, vo_window
);
1010 while (XPending(mydisplay
))
1012 XNextEvent(mydisplay
, &Event
);
1016 guiGetEvent(0, (char *) &Event
);
1017 if (vo_window
!= Event
.xany
.window
)
1021 // printf("\rEvent.type=%X \n",Event.type);
1025 ret
|= VO_EVENT_EXPOSE
;
1027 case ConfigureNotify
:
1028 // if (!vo_fs && (Event.xconfigure.width == vo_screenwidth || Event.xconfigure.height == vo_screenheight)) break;
1029 // if (vo_fs && Event.xconfigure.width != vo_screenwidth && Event.xconfigure.height != vo_screenheight) break;
1030 if (vo_window
== None
)
1032 vo_dwidth
= Event
.xconfigure
.width
;
1033 vo_dheight
= Event
.xconfigure
.height
;
1035 /* when resizing, x and y are zero :( */
1036 vo_dx
= Event
.xconfigure
.x
;
1037 vo_dy
= Event
.xconfigure
.y
;
1044 XGetGeometry(mydisplay
, vo_window
, &root
, &foo
, &foo
,
1045 &foo
/*width */ , &foo
/*height */ , &foo
,
1047 XTranslateCoordinates(mydisplay
, vo_window
, root
, 0, 0,
1048 &vo_dx
, &vo_dy
, &win
);
1051 ret
|= VO_EVENT_RESIZE
;
1057 XLookupString(&Event
.xkey
, buf
, sizeof(buf
), &keySym
,
1059 #ifdef XF86XK_AudioPause
1060 vo_x11_putkey_ext(keySym
);
1063 ((keySym
& 0xff00) !=
1064 0 ? ((keySym
& 0x00ff) + 256) : (keySym
));
1066 if ((use_gui
) && (key
== wsEnter
))
1070 ret
|= VO_EVENT_KEYPRESS
;
1074 if (vo_mouse_autohide
)
1076 vo_showcursor(mydisplay
, vo_window
);
1077 vo_mouse_counter
= vo_mouse_timer_const
;
1081 if (vo_mouse_autohide
)
1083 vo_showcursor(mydisplay
, vo_window
);
1084 vo_mouse_counter
= vo_mouse_timer_const
;
1086 // Ignore mouse whell press event
1087 if (Event
.xbutton
.button
> 3)
1089 mplayer_put_key(MOUSE_BTN0
+ Event
.xbutton
.button
- 1);
1093 // Ignor mouse button 1 - 3 under gui
1094 if (use_gui
&& (Event
.xbutton
.button
>= 1)
1095 && (Event
.xbutton
.button
<= 3))
1098 mplayer_put_key((MOUSE_BTN0
+ Event
.xbutton
.button
-
1102 if (vo_mouse_autohide
)
1104 vo_showcursor(mydisplay
, vo_window
);
1105 vo_mouse_counter
= vo_mouse_timer_const
;
1108 // Ignor mouse button 1 - 3 under gui
1109 if (use_gui
&& (Event
.xbutton
.button
>= 1)
1110 && (Event
.xbutton
.button
<= 3))
1113 mplayer_put_key(MOUSE_BTN0
+ Event
.xbutton
.button
- 1);
1115 case PropertyNotify
:
1118 XGetAtomName(mydisplay
, Event
.xproperty
.atom
);
1123 // fprintf(stderr,"[ws] PropertyNotify ( 0x%x ) %s ( 0x%x )\n",vo_window,name,Event.xproperty.atom );
1129 vo_hint
.win_gravity
= old_gravity
;
1130 XSetWMNormalHints(mDisplay
, vo_window
, &vo_hint
);
1138 void vo_x11_sizehint(int x
, int y
, int width
, int height
, int max
)
1140 vo_hint
.flags
= PPosition
| PSize
| PWinGravity
;
1143 vo_hint
.flags
|= PAspect
;
1144 vo_hint
.min_aspect
.x
= width
;
1145 vo_hint
.min_aspect
.y
= height
;
1146 vo_hint
.max_aspect
.x
= width
;
1147 vo_hint
.max_aspect
.y
= height
;
1152 vo_hint
.width
= width
;
1153 vo_hint
.height
= height
;
1156 vo_hint
.max_width
= width
;
1157 vo_hint
.max_height
= height
;
1158 vo_hint
.flags
|= PMaxSize
;
1161 vo_hint
.max_width
= 0;
1162 vo_hint
.max_height
= 0;
1165 // set min height/width to 4 to avoid off by one errors
1166 // and because mga_vid requires a minial size of 4 pixel
1167 vo_hint
.min_width
= vo_hint
.min_height
= 4;
1168 vo_hint
.flags
|= PMinSize
;
1170 vo_hint
.win_gravity
= StaticGravity
;
1171 XSetWMNormalHints(mDisplay
, vo_window
, &vo_hint
);
1174 static int vo_x11_get_gnome_layer(Display
* mDisplay
, Window win
)
1178 unsigned long nitems
;
1179 unsigned long bytesafter
;
1180 unsigned short *args
= NULL
;
1182 if (XGetWindowProperty(mDisplay
, win
, XA_WIN_LAYER
, 0, 16384,
1183 False
, AnyPropertyType
, &type
, &format
, &nitems
,
1185 (unsigned char **) &args
) == Success
1186 && nitems
> 0 && args
)
1188 mp_msg(MSGT_VO
, MSGL_V
, "[x11] original window layer is %d.\n",
1192 return WIN_LAYER_NORMAL
;
1196 Window
vo_x11_create_smooth_window(Display
* mDisplay
, Window mRoot
,
1197 Visual
* vis
, int x
, int y
,
1198 unsigned int width
, unsigned int height
,
1199 int depth
, Colormap col_map
)
1201 unsigned long xswamask
= CWBackingStore
| CWBorderPixel
;
1202 XSetWindowAttributes xswa
;
1205 if (col_map
!= CopyFromParent
)
1207 xswa
.colormap
= col_map
;
1208 xswamask
|= CWColormap
;
1210 xswa
.background_pixel
= 0;
1211 xswa
.border_pixel
= 0;
1212 xswa
.backing_store
= Always
;
1213 xswa
.bit_gravity
= StaticGravity
;
1216 XCreateWindow(mDisplay
, mRootWin
, x
, y
, width
, height
, 0, depth
,
1217 CopyFromParent
, vis
, xswamask
, &xswa
);
1219 f_gc
= XCreateGC(mDisplay
, ret_win
, 0, 0);
1220 XSetForeground(mDisplay
, f_gc
, 0);
1226 void vo_x11_clearwindow_part(Display
* mDisplay
, Window vo_window
,
1227 int img_width
, int img_height
, int use_fs
)
1229 int u_dheight
, u_dwidth
, left_ov
, left_ov2
;
1234 u_dheight
= use_fs
? vo_screenheight
: vo_dheight
;
1235 u_dwidth
= use_fs
? vo_screenwidth
: vo_dwidth
;
1236 if ((u_dheight
<= img_height
) && (u_dwidth
<= img_width
))
1239 left_ov
= (u_dheight
- img_height
) / 2;
1240 left_ov2
= (u_dwidth
- img_width
) / 2;
1242 XFillRectangle(mDisplay
, vo_window
, f_gc
, 0, 0, u_dwidth
, left_ov
);
1243 XFillRectangle(mDisplay
, vo_window
, f_gc
, 0, u_dheight
- left_ov
- 1,
1244 u_dwidth
, left_ov
+ 1);
1246 if (u_dwidth
> img_width
)
1248 XFillRectangle(mDisplay
, vo_window
, f_gc
, 0, left_ov
, left_ov2
,
1250 XFillRectangle(mDisplay
, vo_window
, f_gc
, u_dwidth
- left_ov2
- 1,
1251 left_ov
, left_ov2
, img_height
);
1257 void vo_x11_clearwindow(Display
* mDisplay
, Window vo_window
)
1261 XFillRectangle(mDisplay
, vo_window
, f_gc
, 0, 0, vo_screenwidth
,
1268 void vo_x11_setlayer(Display
* mDisplay
, Window vo_window
, int layer
)
1273 if (vo_fs_type
& vo_wm_LAYER
)
1275 XClientMessageEvent xev
;
1278 orig_layer
= vo_x11_get_gnome_layer(mDisplay
, vo_window
);
1280 memset(&xev
, 0, sizeof(xev
));
1281 xev
.type
= ClientMessage
;
1282 xev
.display
= mDisplay
;
1283 xev
.window
= vo_window
;
1284 xev
.message_type
= XA_WIN_LAYER
;
1286 xev
.data
.l
[0] = layer
? fs_layer
: orig_layer
; // if not fullscreen, stay on default layer
1287 xev
.data
.l
[1] = CurrentTime
;
1288 mp_msg(MSGT_VO
, MSGL_V
,
1289 "[x11] Layered style stay on top (layer %d).\n",
1291 XSendEvent(mDisplay
, mRootWin
, False
, SubstructureNotifyMask
,
1293 } else if (vo_fs_type
& vo_wm_NETWM
)
1295 XClientMessageEvent xev
;
1298 memset(&xev
, 0, sizeof(xev
));
1299 xev
.type
= ClientMessage
;
1300 xev
.message_type
= XA_NET_WM_STATE
;
1301 xev
.display
= mDisplay
;
1302 xev
.window
= vo_window
;
1304 xev
.data
.l
[0] = layer
;
1306 if (vo_fs_type
& vo_wm_STAYS_ON_TOP
)
1307 xev
.data
.l
[1] = XA_NET_WM_STATE_STAYS_ON_TOP
;
1308 else if (vo_fs_type
& vo_wm_ABOVE
)
1309 xev
.data
.l
[1] = XA_NET_WM_STATE_ABOVE
;
1310 else if (vo_fs_type
& vo_wm_FULLSCREEN
)
1311 xev
.data
.l
[1] = XA_NET_WM_STATE_FULLSCREEN
;
1312 else if (vo_fs_type
& vo_wm_BELOW
)
1313 // This is not fallback. We can safely assume that situation where
1314 // only NETWM_STATE_BELOW is supported and others not, doesn't exist.
1315 xev
.data
.l
[1] = XA_NET_WM_STATE_BELOW
;
1317 XSendEvent(mDisplay
, mRootWin
, False
, SubstructureRedirectMask
,
1319 state
= XGetAtomName(mDisplay
, xev
.data
.l
[1]);
1320 mp_msg(MSGT_VO
, MSGL_V
,
1321 "[x11] NET style stay on top (layer %d). Using state %s.\n",
1327 static int vo_x11_get_fs_type(int supported
)
1330 int type
= supported
;
1335 for (i
= 0; vo_fstype_list
[i
]; i
++)
1338 char *arg
= vo_fstype_list
[i
];
1340 if (vo_fstype_list
[i
][0] == '-')
1343 arg
= vo_fstype_list
[i
] + 1;
1346 if (!strncmp(arg
, "layer", 5))
1348 if (!neg
&& (arg
[5] == '='))
1350 char *endptr
= NULL
;
1351 int layer
= strtol(vo_fstype_list
[i
] + 6, &endptr
, 10);
1353 if (endptr
&& *endptr
== '\0' && layer
>= 0
1358 type
&= ~vo_wm_LAYER
;
1360 type
|= vo_wm_LAYER
;
1361 } else if (!strcmp(arg
, "above"))
1364 type
&= ~vo_wm_ABOVE
;
1366 type
|= vo_wm_ABOVE
;
1367 } else if (!strcmp(arg
, "fullscreen"))
1370 type
&= ~vo_wm_FULLSCREEN
;
1372 type
|= vo_wm_FULLSCREEN
;
1373 } else if (!strcmp(arg
, "stays_on_top"))
1376 type
&= ~vo_wm_STAYS_ON_TOP
;
1378 type
|= vo_wm_STAYS_ON_TOP
;
1379 } else if (!strcmp(arg
, "below"))
1382 type
&= ~vo_wm_BELOW
;
1384 type
|= vo_wm_BELOW
;
1385 } else if (!strcmp(arg
, "netwm"))
1388 type
&= ~vo_wm_NETWM
;
1390 type
|= vo_wm_NETWM
;
1391 } else if (!strcmp(arg
, "none"))
1399 void vo_x11_fullscreen(void)
1403 if (WinID
>= 0 || vo_fs_flip
)
1409 if ( ! (vo_fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1411 if (vo_dwidth
!= vo_screenwidth
&& vo_dheight
!= vo_screenheight
)
1419 vo_x11_ewmh_fullscreen(_NET_WM_STATE_REMOVE
); // removes fullscreen state if wm supports EWMH
1424 vo_x11_ewmh_fullscreen(_NET_WM_STATE_ADD
); // sends fullscreen state to be added if wm supports EWMH
1427 if ( ! (vo_fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1430 (vo_dwidth
== vo_screenwidth
&& vo_dwidth
!= vo_old_width
) &&
1431 (vo_dheight
== vo_screenheight
&& vo_dheight
!= vo_old_height
))
1435 vo_old_width
= vo_dwidth
;
1436 vo_old_height
= vo_dheight
;
1440 h
= vo_screenheight
;
1446 XGetWMNormalHints(mDisplay
, vo_window
, &vo_hint
, &dummy
);
1447 if (!(vo_hint
.flags
& PWinGravity
))
1448 old_gravity
= NorthWestGravity
;
1450 old_gravity
= vo_hint
.win_gravity
;
1452 if (vo_wm_type
== 0 && !(vo_fsmode
& 16))
1454 XUnmapWindow(mDisplay
, vo_window
); // required for MWM
1455 XWithdrawWindow(mDisplay
, vo_window
, mScreen
);
1459 if ( ! (vo_fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1461 vo_x11_decoration(mDisplay
, vo_window
, (vo_fs
) ? 0 : 1);
1462 vo_x11_sizehint(x
, y
, w
, h
, 0);
1463 vo_x11_setlayer(mDisplay
, vo_window
, vo_fs
);
1465 if ((!(vo_fs
)) & vo_ontop
)
1466 vo_x11_setlayer(mDisplay
, vo_window
, vo_ontop
);
1468 XMoveResizeWindow(mDisplay
, vo_window
, x
, y
, w
, h
);
1470 #ifdef HAVE_XINERAMA
1471 vo_x11_xinerama_move(mDisplay
, vo_window
);
1474 XMapRaised(mDisplay
, vo_window
);
1475 XRaiseWindow(mDisplay
, vo_window
);
1479 void vo_x11_ontop(void)
1481 vo_ontop
= (!(vo_ontop
));
1483 vo_x11_setlayer(mDisplay
, vo_window
, vo_ontop
);
1487 * XScreensaver stuff
1490 static int got_badwindow
;
1491 static XErrorHandler old_handler
;
1493 static int badwindow_handler(Display
* dpy
, XErrorEvent
* error
)
1495 if (error
->error_code
!= BadWindow
)
1496 return (*old_handler
) (dpy
, error
);
1498 got_badwindow
= True
;
1502 static Window
find_xscreensaver_window(Display
* dpy
)
1505 Window root
= RootWindowOfScreen(DefaultScreenOfDisplay(dpy
));
1506 Window root2
, parent
, *kids
;
1509 unsigned int nkids
= 0;
1511 xs_version
= XInternAtom(dpy
, "_SCREENSAVER_VERSION", True
);
1513 if (!(xs_version
!= None
&&
1514 XQueryTree(dpy
, root
, &root2
, &parent
, &kids
, &nkids
) &&
1518 old_handler
= XSetErrorHandler(badwindow_handler
);
1520 for (i
= 0; i
< nkids
; i
++)
1524 unsigned long nitems
, bytesafter
;
1528 got_badwindow
= False
;
1530 XGetWindowProperty(dpy
, kids
[i
], xs_version
, 0, 200, False
,
1531 XA_STRING
, &type
, &format
, &nitems
,
1532 &bytesafter
, (unsigned char **) &v
);
1537 if (status
== Success
&& type
!= None
)
1544 XSetErrorHandler(old_handler
);
1549 static Window xs_windowid
= 0;
1550 static Atom deactivate
;
1551 static Atom screensaver
;
1553 static unsigned int time_last
;
1555 void xscreensaver_heartbeat(void)
1557 unsigned int time
= GetTimerMS();
1560 if (mDisplay
&& xs_windowid
&&
1561 ((time
- time_last
) > 30000 || (time
- time_last
) < 0))
1565 ev
.xany
.type
= ClientMessage
;
1566 ev
.xclient
.display
= mDisplay
;
1567 ev
.xclient
.window
= xs_windowid
;
1568 ev
.xclient
.message_type
= screensaver
;
1569 ev
.xclient
.format
= 32;
1570 memset(&ev
.xclient
.data
, 0, sizeof(ev
.xclient
.data
));
1571 ev
.xclient
.data
.l
[0] = (long) deactivate
;
1573 mp_msg(MSGT_VO
, MSGL_DBG2
, "Pinging xscreensaver.\n");
1574 XSendEvent(mDisplay
, xs_windowid
, False
, 0L, &ev
);
1575 XSync(mDisplay
, False
);
1579 static void xscreensaver_disable(Display
* dpy
)
1581 mp_msg(MSGT_VO
, MSGL_DBG2
, "xscreensaver_disable()\n");
1583 xs_windowid
= find_xscreensaver_window(dpy
);
1586 mp_msg(MSGT_VO
, MSGL_INFO
,
1587 "xscreensaver_disable: Could not find xscreensaver window.\n");
1590 mp_msg(MSGT_VO
, MSGL_INFO
,
1591 "xscreensaver_disable: xscreensaver wid=%d.\n", xs_windowid
);
1593 deactivate
= XInternAtom(dpy
, "DEACTIVATE", False
);
1594 screensaver
= XInternAtom(dpy
, "SCREENSAVER", False
);
1597 static void xscreensaver_enable(void)
1603 * End of XScreensaver stuff
1606 void saver_on(Display
* mDisplay
)
1614 if (DPMSQueryExtension(mDisplay
, ¬hing
, ¬hing
))
1616 if (!DPMSEnable(mDisplay
))
1617 { // restoring power saving settings
1618 mp_msg(MSGT_VO
, MSGL_WARN
, "DPMS not available?\n");
1621 // DPMS does not seem to be enabled unless we call DPMSInfo
1625 DPMSForceLevel(mDisplay
, DPMSModeOn
);
1626 DPMSInfo(mDisplay
, &state
, &onoff
);
1629 mp_msg(MSGT_VO
, MSGL_INFO
,
1630 "Successfully enabled DPMS\n");
1633 mp_msg(MSGT_VO
, MSGL_WARN
, "Could not enable DPMS\n");
1643 int dummy
, interval
, prefer_blank
, allow_exp
;
1645 XGetScreenSaver(mDisplay
, &dummy
, &interval
, &prefer_blank
,
1647 XSetScreenSaver(mDisplay
, timeout_save
, interval
, prefer_blank
,
1649 XGetScreenSaver(mDisplay
, &timeout_save
, &interval
, &prefer_blank
,
1654 if (stop_xscreensaver
)
1655 xscreensaver_enable();
1656 if (kdescreensaver_was_running
&& stop_xscreensaver
)
1659 ("dcop kdesktop KScreensaverIface enable true 2>/dev/null >/dev/null");
1660 kdescreensaver_was_running
= 0;
1666 void saver_off(Display
* mDisplay
)
1669 int interval
, prefer_blank
, allow_exp
;
1674 if (DPMSQueryExtension(mDisplay
, ¬hing
, ¬hing
))
1679 DPMSInfo(mDisplay
, &state
, &onoff
);
1684 mp_msg(MSGT_VO
, MSGL_INFO
, "Disabling DPMS\n");
1686 stat
= DPMSDisable(mDisplay
); // monitor powersave off
1687 mp_msg(MSGT_VO
, MSGL_V
, "DPMSDisable stat: %d\n", stat
);
1693 XGetScreenSaver(mDisplay
, &timeout_save
, &interval
, &prefer_blank
,
1696 XSetScreenSaver(mDisplay
, 0, interval
, prefer_blank
,
1699 // turning off screensaver
1700 if (stop_xscreensaver
)
1701 xscreensaver_disable(mDisplay
);
1702 if (stop_xscreensaver
&& !kdescreensaver_was_running
)
1704 kdescreensaver_was_running
=
1706 ("dcop kdesktop KScreensaverIface isEnabled 2>/dev/null | sed 's/1/true/g' | grep true 2>/dev/null >/dev/null")
1708 if (kdescreensaver_was_running
)
1710 ("dcop kdesktop KScreensaverIface enable false 2>/dev/null >/dev/null");
1714 static XErrorHandler old_handler
= NULL
;
1715 static int selectinput_err
= 0;
1716 static int x11_selectinput_errorhandler(Display
* display
,
1717 XErrorEvent
* event
)
1719 if (event
->error_code
== BadAccess
)
1721 selectinput_err
= 1;
1722 mp_msg(MSGT_VO
, MSGL_ERR
,
1723 "X11 error: BadAccess during XSelectInput Call\n");
1724 mp_msg(MSGT_VO
, MSGL_ERR
,
1725 "X11 error: The 'ButtonPressMask' mask of specified window has probably already used by another appication (see man XSelectInput)\n");
1726 /* If you think mplayer should shutdown with this error, comments out following line */
1729 if (old_handler
!= NULL
)
1730 old_handler(display
, event
);
1732 x11_errorhandler(display
, event
);
1736 void vo_x11_selectinput_witherr(Display
* display
, Window w
,
1739 XSync(display
, False
);
1740 old_handler
= XSetErrorHandler(x11_selectinput_errorhandler
);
1741 selectinput_err
= 0;
1742 if (vo_nomouse_input
)
1744 XSelectInput(display
, w
,
1746 (~(ButtonPressMask
| ButtonReleaseMask
)));
1749 XSelectInput(display
, w
, event_mask
);
1751 XSync(display
, False
);
1752 XSetErrorHandler(old_handler
);
1753 if (selectinput_err
)
1755 mp_msg(MSGT_VO
, MSGL_ERR
,
1756 "X11 error: MPlayer discards mouse control (reconfiguring)\n");
1757 XSelectInput(display
, w
,
1760 (ButtonPressMask
| ButtonReleaseMask
|
1761 PointerMotionMask
)));
1765 #ifdef HAVE_XINERAMA
1766 void vo_x11_xinerama_move(Display
* dsp
, Window w
)
1768 if (XineramaIsActive(dsp
) && !geometry_xy_changed
)
1770 /* printf("XXXX Xinerama screen: x: %hd y: %hd\n",xinerama_x,xinerama_y); */
1771 XMoveWindow(dsp
, w
, xinerama_x
, xinerama_y
);
1777 void vo_vm_switch(uint32_t X
, uint32_t Y
, int *modeline_width
,
1778 int *modeline_height
)
1780 unsigned int vm_event
, vm_error
;
1781 unsigned int vm_ver
, vm_rev
;
1782 int i
, j
, have_vm
= 0;
1786 if (XF86VidModeQueryExtension(mDisplay
, &vm_event
, &vm_error
))
1788 XF86VidModeQueryVersion(mDisplay
, &vm_ver
, &vm_rev
);
1789 mp_msg(MSGT_VO
, MSGL_V
, "XF86VidMode Extension v%i.%i\n", vm_ver
,
1793 mp_msg(MSGT_VO
, MSGL_WARN
,
1794 "XF86VidMode Extenstion not available.\n");
1798 if (vidmodes
== NULL
)
1799 XF86VidModeGetAllModeLines(mDisplay
, mScreen
, &modecount
,
1802 *modeline_width
= vidmodes
[0]->hdisplay
;
1803 *modeline_height
= vidmodes
[0]->vdisplay
;
1805 for (i
= 1; i
< modecount
; i
++)
1806 if ((vidmodes
[i
]->hdisplay
>= X
)
1807 && (vidmodes
[i
]->vdisplay
>= Y
))
1808 if ((vidmodes
[i
]->hdisplay
<= *modeline_width
)
1809 && (vidmodes
[i
]->vdisplay
<= *modeline_height
))
1811 *modeline_width
= vidmodes
[i
]->hdisplay
;
1812 *modeline_height
= vidmodes
[i
]->vdisplay
;
1816 mp_msg(MSGT_VO
, MSGL_INFO
,
1817 "XF86VM: Selected video mode %dx%d for image size %dx%d.\n",
1818 *modeline_width
, *modeline_height
, X
, Y
);
1819 XF86VidModeLockModeSwitch(mDisplay
, mScreen
, 0);
1820 XF86VidModeSwitchToMode(mDisplay
, mScreen
, vidmodes
[j
]);
1821 XF86VidModeSwitchToMode(mDisplay
, mScreen
, vidmodes
[j
]);
1822 X
= (vo_screenwidth
- *modeline_width
) / 2;
1823 Y
= (vo_screenheight
- *modeline_height
) / 2;
1824 XF86VidModeSetViewPort(mDisplay
, mScreen
, X
, Y
);
1828 void vo_vm_close(Display
* dpy
)
1831 if (vidmodes
!= NULL
&& vo_window
!= None
)
1833 if (vidmodes
!= NULL
)
1839 screen
= DefaultScreen(dpy
);
1843 XF86VidModeGetAllModeLines(mDisplay
, mScreen
, &modecount
,
1845 for (i
= 0; i
< modecount
; i
++)
1846 if ((vidmodes
[i
]->hdisplay
== vo_screenwidth
)
1847 && (vidmodes
[i
]->vdisplay
== vo_screenheight
))
1849 mp_msg(MSGT_VO
, MSGL_INFO
,
1850 "Returning to original mode %dx%d\n",
1851 vo_screenwidth
, vo_screenheight
);
1855 XF86VidModeSwitchToMode(dpy
, screen
, vidmodes
[i
]);
1856 XF86VidModeSwitchToMode(dpy
, screen
, vidmodes
[i
]);
1863 #endif /* X11_FULLSCREEN */
1867 * Scan the available visuals on this Display/Screen. Try to find
1868 * the 'best' available TrueColor visual that has a decent color
1869 * depth (at least 15bit). If there are multiple visuals with depth
1870 * >= 15bit, we prefer visuals with a smaller color depth.
1872 int vo_find_depth_from_visuals(Display
* dpy
, int screen
,
1873 Visual
** visual_return
)
1875 XVisualInfo visual_tmpl
;
1876 XVisualInfo
*visuals
;
1878 int bestvisual
= -1;
1879 int bestvisual_depth
= -1;
1881 visual_tmpl
.screen
= screen
;
1882 visual_tmpl
.class = TrueColor
;
1883 visuals
= XGetVisualInfo(dpy
,
1884 VisualScreenMask
| VisualClassMask
,
1885 &visual_tmpl
, &nvisuals
);
1886 if (visuals
!= NULL
)
1888 for (i
= 0; i
< nvisuals
; i
++)
1890 mp_msg(MSGT_VO
, MSGL_V
,
1891 "vo: X11 truecolor visual %#x, depth %d, R:%lX G:%lX B:%lX\n",
1892 visuals
[i
].visualid
, visuals
[i
].depth
,
1893 visuals
[i
].red_mask
, visuals
[i
].green_mask
,
1894 visuals
[i
].blue_mask
);
1896 * save the visual index and it's depth, if this is the first
1897 * truecolor visul, or a visual that is 'preferred' over the
1898 * previous 'best' visual
1900 if (bestvisual_depth
== -1
1901 || (visuals
[i
].depth
>= 15
1902 && (visuals
[i
].depth
< bestvisual_depth
1903 || bestvisual_depth
< 15)))
1906 bestvisual_depth
= visuals
[i
].depth
;
1910 if (bestvisual
!= -1 && visual_return
!= NULL
)
1911 *visual_return
= visuals
[bestvisual
].visual
;
1915 return bestvisual_depth
;
1919 static Colormap cmap
= None
;
1920 static XColor cols
[256];
1921 static int cm_size
, red_mask
, green_mask
, blue_mask
;
1924 Colormap
vo_x11_create_colormap(XVisualInfo
* vinfo
)
1926 unsigned k
, r
, g
, b
, ru
, gu
, bu
, m
, rv
, gv
, bv
, rvu
, gvu
, bvu
;
1928 if (vinfo
->class != DirectColor
)
1929 return XCreateColormap(mDisplay
, mRootWin
, vinfo
->visual
,
1932 /* can this function get called twice or more? */
1935 cm_size
= vinfo
->colormap_size
;
1936 red_mask
= vinfo
->red_mask
;
1937 green_mask
= vinfo
->green_mask
;
1938 blue_mask
= vinfo
->blue_mask
;
1939 ru
= (red_mask
& (red_mask
- 1)) ^ red_mask
;
1940 gu
= (green_mask
& (green_mask
- 1)) ^ green_mask
;
1941 bu
= (blue_mask
& (blue_mask
- 1)) ^ blue_mask
;
1942 rvu
= 65536ull * ru
/ (red_mask
+ ru
);
1943 gvu
= 65536ull * gu
/ (green_mask
+ gu
);
1944 bvu
= 65536ull * bu
/ (blue_mask
+ bu
);
1947 m
= DoRed
| DoGreen
| DoBlue
;
1948 for (k
= 0; k
< cm_size
; k
++)
1952 cols
[k
].pixel
= r
| g
| b
;
1957 t
= (r
+ ru
) & red_mask
;
1961 t
= (g
+ gu
) & green_mask
;
1965 t
= (b
+ bu
) & blue_mask
;
1973 cmap
= XCreateColormap(mDisplay
, mRootWin
, vinfo
->visual
, AllocAll
);
1974 XStoreColors(mDisplay
, cmap
, cols
, cm_size
);
1979 * Via colormaps/gamma ramps we can do gamma, brightness, contrast,
1980 * hue and red/green/blue intensity, but we cannot do saturation.
1981 * Currently only gamma, brightness and contrast are implemented.
1982 * Is there sufficient interest for hue and/or red/green/blue intensity?
1984 /* these values have range [-100,100] and are initially 0 */
1985 static int vo_gamma
= 0;
1986 static int vo_brightness
= 0;
1987 static int vo_contrast
= 0;
1990 uint32_t vo_x11_set_equalizer(char *name
, int value
)
1992 float gamma
, brightness
, contrast
;
1997 * IMPLEMENTME: consider using XF86VidModeSetGammaRamp in the case
1998 * of TrueColor-ed window but be careful:
1999 * unlike the colormaps, which are private for the X client
2000 * who created them and thus automatically destroyed on client
2001 * disconnect, this gamma ramp is a system-wide (X-server-wide)
2002 * setting and _must_ be restored before the process exit.
2003 * Unforunately when the process crashes (or get killed
2004 * for some reason) it is impossible to restore the setting,
2005 * and such behaviour could be rather annoying for the users.
2010 if (!strcasecmp(name
, "brightness"))
2011 vo_brightness
= value
;
2012 else if (!strcasecmp(name
, "contrast"))
2013 vo_contrast
= value
;
2014 else if (!strcasecmp(name
, "gamma"))
2019 brightness
= 0.01 * vo_brightness
;
2020 contrast
= tan(0.0095 * (vo_contrast
+ 100) * M_PI
/ 4);
2021 gamma
= pow(2, -0.02 * vo_gamma
);
2023 rf
= (float) ((red_mask
& (red_mask
- 1)) ^ red_mask
) / red_mask
;
2024 gf
= (float) ((green_mask
& (green_mask
- 1)) ^ green_mask
) /
2026 bf
= (float) ((blue_mask
& (blue_mask
- 1)) ^ blue_mask
) / blue_mask
;
2028 /* now recalculate the colormap using the newly set value */
2029 for (k
= 0; k
< cm_size
; k
++)
2033 s
= pow(rf
* k
, gamma
);
2034 s
= (s
- 0.5) * contrast
+ 0.5;
2040 cols
[k
].red
= (unsigned short) (s
* 65535);
2042 s
= pow(gf
* k
, gamma
);
2043 s
= (s
- 0.5) * contrast
+ 0.5;
2049 cols
[k
].green
= (unsigned short) (s
* 65535);
2051 s
= pow(bf
* k
, gamma
);
2052 s
= (s
- 0.5) * contrast
+ 0.5;
2058 cols
[k
].blue
= (unsigned short) (s
* 65535);
2061 XStoreColors(mDisplay
, cmap
, cols
, cm_size
);
2066 uint32_t vo_x11_get_equalizer(char *name
, int *value
)
2070 if (!strcasecmp(name
, "brightness"))
2071 *value
= vo_brightness
;
2072 else if (!strcasecmp(name
, "contrast"))
2073 *value
= vo_contrast
;
2074 else if (!strcasecmp(name
, "gamma"))
2082 int vo_xv_set_eq(uint32_t xv_port
, char *name
, int value
)
2084 XvAttribute
*attributes
;
2085 int i
, howmany
, xv_atom
;
2087 mp_dbg(MSGT_VO
, MSGL_V
, "xv_set_eq called! (%s, %d)\n", name
, value
);
2089 /* get available attributes */
2090 attributes
= XvQueryPortAttributes(mDisplay
, xv_port
, &howmany
);
2091 for (i
= 0; i
< howmany
&& attributes
; i
++)
2092 if (attributes
[i
].flags
& XvSettable
)
2094 xv_atom
= XInternAtom(mDisplay
, attributes
[i
].name
, True
);
2095 /* since we have SET_DEFAULTS first in our list, we can check if it's available
2096 then trigger it if it's ok so that the other values are at default upon query */
2097 if (xv_atom
!= None
)
2099 int hue
= 0, port_value
, port_min
, port_max
;
2101 if (!strcmp(attributes
[i
].name
, "XV_BRIGHTNESS") &&
2102 (!strcasecmp(name
, "brightness")))
2104 else if (!strcmp(attributes
[i
].name
, "XV_CONTRAST") &&
2105 (!strcasecmp(name
, "contrast")))
2107 else if (!strcmp(attributes
[i
].name
, "XV_SATURATION") &&
2108 (!strcasecmp(name
, "saturation")))
2110 else if (!strcmp(attributes
[i
].name
, "XV_HUE") &&
2111 (!strcasecmp(name
, "hue")))
2116 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
2117 if (!strcmp(attributes
[i
].name
, "XV_RED_INTENSITY") &&
2118 (!strcasecmp(name
, "red_intensity")))
2120 else if (!strcmp(attributes
[i
].name
, "XV_GREEN_INTENSITY")
2121 && (!strcasecmp(name
, "green_intensity")))
2123 else if (!strcmp(attributes
[i
].name
, "XV_BLUE_INTENSITY")
2124 && (!strcasecmp(name
, "blue_intensity")))
2129 port_min
= attributes
[i
].min_value
;
2130 port_max
= attributes
[i
].max_value
;
2132 /* nvidia hue workaround */
2133 if (hue
&& port_min
== 0 && port_max
== 360)
2137 0) ? (port_value
- 100) : (port_value
+ 100);
2143 (port_value
+ 100) * (port_max
- port_min
) / 200 +
2145 XvSetPortAttribute(mDisplay
, xv_port
, xv_atom
, port_value
);
2152 int vo_xv_get_eq(uint32_t xv_port
, char *name
, int *value
)
2155 XvAttribute
*attributes
;
2156 int i
, howmany
, xv_atom
;
2158 /* get available attributes */
2159 attributes
= XvQueryPortAttributes(mDisplay
, xv_port
, &howmany
);
2160 for (i
= 0; i
< howmany
&& attributes
; i
++)
2161 if (attributes
[i
].flags
& XvGettable
)
2163 xv_atom
= XInternAtom(mDisplay
, attributes
[i
].name
, True
);
2164 /* since we have SET_DEFAULTS first in our list, we can check if it's available
2165 then trigger it if it's ok so that the other values are at default upon query */
2166 if (xv_atom
!= None
)
2168 int val
, port_value
= 0, port_min
, port_max
;
2170 XvGetPortAttribute(mDisplay
, xv_port
, xv_atom
,
2173 port_min
= attributes
[i
].min_value
;
2174 port_max
= attributes
[i
].max_value
;
2176 (port_value
- port_min
) * 200 / (port_max
- port_min
) -
2179 if (!strcmp(attributes
[i
].name
, "XV_BRIGHTNESS") &&
2180 (!strcasecmp(name
, "brightness")))
2182 else if (!strcmp(attributes
[i
].name
, "XV_CONTRAST") &&
2183 (!strcasecmp(name
, "contrast")))
2185 else if (!strcmp(attributes
[i
].name
, "XV_SATURATION") &&
2186 (!strcasecmp(name
, "saturation")))
2188 else if (!strcmp(attributes
[i
].name
, "XV_HUE") &&
2189 (!strcasecmp(name
, "hue")))
2191 /* nasty nvidia detect */
2192 if (port_min
== 0 && port_max
== 360)
2193 *value
= (val
>= 0) ? (val
- 100) : (val
+ 100);
2197 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
2198 if (!strcmp(attributes
[i
].name
, "XV_RED_INTENSITY") &&
2199 (!strcasecmp(name
, "red_intensity")))
2201 else if (!strcmp(attributes
[i
].name
, "XV_GREEN_INTENSITY")
2202 && (!strcasecmp(name
, "green_intensity")))
2204 else if (!strcmp(attributes
[i
].name
, "XV_BLUE_INTENSITY")
2205 && (!strcasecmp(name
, "blue_intensity")))
2210 mp_dbg(MSGT_VO
, MSGL_V
, "xv_get_eq called! (%s, %d)\n",