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"
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 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
);
181 XFreeColors(disp
,colormap
,&black
.pixel
,1,0);
184 void vo_showcursor(Display
* disp
, Window win
)
188 XDefineCursor(disp
, win
, 0);
191 static int x11_errorhandler(Display
* display
, XErrorEvent
* event
)
196 XGetErrorText(display
, event
->error_code
, (char *) &msg
, MSGLEN
);
198 mp_msg(MSGT_VO
, MSGL_ERR
, "X11 error: %s\n", msg
);
200 mp_msg(MSGT_VO
, MSGL_V
,
201 "Type: %x, display: %x, resourceid: %x, serial: %x\n",
202 event
->type
, event
->display
, event
->resourceid
, event
->serial
);
203 mp_msg(MSGT_VO
, MSGL_V
,
204 "Error code: %x, request code: %x, minor code: %x\n",
205 event
->error_code
, event
->request_code
, event
->minor_code
);
208 //exit_player("X11 error");
212 void fstype_help(void)
214 mp_msg(MSGT_VO
, MSGL_INFO
, MSGTR_AvailableFsType
);
216 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "none",
217 "don't set fullscreen window layer");
218 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "layer",
219 "use _WIN_LAYER hint with default layer");
220 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "layer=<0..15>",
221 "use _WIN_LAYER hint with a given layer number");
222 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "netwm",
223 "force NETWM style");
224 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "above",
225 "use _NETWM_STATE_ABOVE hint if available");
226 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "below",
227 "use _NETWM_STATE_BELOW hint if available");
228 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "fullscreen",
229 "use _NETWM_STATE_FULLSCREEN hint if availale");
230 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "stays_on_top",
231 "use _NETWM_STATE_STAYS_ON_TOP hint if available");
232 mp_msg(MSGT_VO
, MSGL_INFO
,
233 "You can also negate the settings with simply putting '-' in the beginning");
234 mp_msg(MSGT_VO
, MSGL_INFO
, "\n\n");
237 static void fstype_dump(int fstype
)
241 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Current fstype setting honours");
242 if (fstype
& vo_wm_LAYER
)
243 mp_msg(MSGT_VO
, MSGL_V
, " LAYER");
244 if (fstype
& vo_wm_FULLSCREEN
)
245 mp_msg(MSGT_VO
, MSGL_V
, " FULLSCREEN");
246 if (fstype
& vo_wm_STAYS_ON_TOP
)
247 mp_msg(MSGT_VO
, MSGL_V
, " STAYS_ON_TOP");
248 if (fstype
& vo_wm_ABOVE
)
249 mp_msg(MSGT_VO
, MSGL_V
, " ABOVE");
250 if (fstype
& vo_wm_BELOW
)
251 mp_msg(MSGT_VO
, MSGL_V
, " BELOW");
252 mp_msg(MSGT_VO
, MSGL_V
, " X atoms\n");
254 mp_msg(MSGT_VO
, MSGL_V
,
255 "[x11] Current fstype setting doesn't honour any X atoms\n");
258 static int net_wm_support_state_test(Atom atom
)
260 #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; } }
262 NET_WM_STATE_TEST(FULLSCREEN
);
263 NET_WM_STATE_TEST(ABOVE
);
264 NET_WM_STATE_TEST(STAYS_ON_TOP
);
265 NET_WM_STATE_TEST(BELOW
);
269 static int x11_get_property(Atom type
, Atom
** args
, unsigned long *nitems
)
272 unsigned long bytesafter
;
275 XGetWindowProperty(mDisplay
, mRootWin
, type
, 0, 16384, False
,
276 AnyPropertyType
, &type
, &format
, nitems
,
277 &bytesafter
, (unsigned char **) args
)
281 static int vo_wm_detect(void)
285 unsigned long nitems
;
291 // -- supports layers
292 if (x11_get_property(XA_WIN_PROTOCOLS
, &args
, &nitems
))
294 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Detected wm supports layers.\n");
295 for (i
= 0; i
< nitems
; i
++)
297 if (args
[i
] == XA_WIN_LAYER
)
302 // metacity is the only manager I know which reports support only for _WIN_LAYER
303 // hint in _WIN_PROTOCOLS (what's more support for it is broken)
307 if (wm
&& (metacity_hack
== 1))
309 // metacity reports that it supports layers, but it is not really truth :-)
311 mp_msg(MSGT_VO
, MSGL_V
,
312 "[x11] Using workaround for Metacity bugs.\n");
316 if (x11_get_property(XA_NET_SUPPORTED
, &args
, &nitems
))
318 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Detected wm supports NetWM.\n");
319 for (i
= 0; i
< nitems
; i
++)
320 wm
|= net_wm_support_state_test(args
[i
]);
323 // ugly hack for broken OpenBox _NET_WM_STATE_FULLSCREEN support
324 // (in their implementation it only changes internal state of window, nothing more!!!)
325 if (wm
& vo_wm_FULLSCREEN
)
327 if (x11_get_property(XA_BLACKBOX_PID
, &args
, &nitems
))
329 mp_msg(MSGT_VO
, MSGL_V
,
330 "[x11] Detected wm is a broken OpenBox.\n");
331 wm
^= vo_wm_FULLSCREEN
;
339 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Unknown wm type...\n");
343 static void init_atoms(void)
345 XA_INIT(_NET_SUPPORTED
);
346 XA_INIT(_NET_WM_STATE
);
347 XA_INIT(_NET_WM_STATE_FULLSCREEN
);
348 XA_INIT(_NET_WM_STATE_ABOVE
);
349 XA_INIT(_NET_WM_STATE_STAYS_ON_TOP
);
350 XA_INIT(_NET_WM_STATE_BELOW
);
351 XA_INIT(_NET_WM_PID
);
352 XA_INIT(_WIN_PROTOCOLS
);
355 XA_INIT(_BLACKBOX_PID
);
364 // char * DisplayName = ":0.0";
365 // Display * mDisplay;
366 XImage
*mXImage
= NULL
;
369 XWindowAttributes attribs
;
373 WinID
= 0; // use root win
375 if (vo_depthonscreen
)
378 return 1; // already called
381 XSetErrorHandler(x11_errorhandler
);
385 if (!(mDisplayName
= getenv("DISPLAY")))
386 mDisplayName
= strdup(":0.0");
388 dispName
= XDisplayName(mDisplayName
);
391 mp_msg(MSGT_VO
, MSGL_V
, "X11 opening display: %s\n", dispName
);
393 mDisplay
= XOpenDisplay(dispName
);
396 mp_msg(MSGT_VO
, MSGL_ERR
,
397 "vo: couldn't open the X11 display (%s)!\n", dispName
);
400 mScreen
= DefaultScreen(mDisplay
); // Screen ID.
401 mRootWin
= RootWindow(mDisplay
, mScreen
); // Root window ID.
406 if (XineramaIsActive(mDisplay
))
408 XineramaScreenInfo
*screens
;
411 screens
= XineramaQueryScreens(mDisplay
, &num_screens
);
412 if (xinerama_screen
>= num_screens
)
415 vo_screenwidth
= screens
[xinerama_screen
].width
;
416 if (!vo_screenheight
)
417 vo_screenheight
= screens
[xinerama_screen
].height
;
418 xinerama_x
= screens
[xinerama_screen
].x_org
;
419 xinerama_y
= screens
[xinerama_screen
].y_org
;
428 XF86VidModeGetModeLine(mDisplay
, mScreen
, &clock
, &modeline
);
430 vo_screenwidth
= modeline
.hdisplay
;
431 if (!vo_screenheight
)
432 vo_screenheight
= modeline
.vdisplay
;
437 vo_screenwidth
= DisplayWidth(mDisplay
, mScreen
);
438 if (!vo_screenheight
)
439 vo_screenheight
= DisplayHeight(mDisplay
, mScreen
);
441 // get color depth (from root window, or the best visual):
442 XGetWindowAttributes(mDisplay
, mRootWin
, &attribs
);
443 depth
= attribs
.depth
;
445 if (depth
!= 15 && depth
!= 16 && depth
!= 24 && depth
!= 32)
449 depth
= vo_find_depth_from_visuals(mDisplay
, mScreen
, &visual
);
451 mXImage
= XCreateImage(mDisplay
, visual
, depth
, ZPixmap
,
452 0, NULL
, 1, 1, 8, 1);
455 XGetImage(mDisplay
, mRootWin
, 0, 0, 1, 1, AllPlanes
, ZPixmap
);
457 vo_depthonscreen
= depth
; // display depth on screen
459 // get bits/pixel from XImage structure:
466 * for the depth==24 case, the XImage structures might use
467 * 24 or 32 bits of data per pixel. The global variable
468 * vo_depthonscreen stores the amount of data per pixel in the
471 * Maybe we should rename vo_depthonscreen to (or add) vo_bpp?
473 bpp
= mXImage
->bits_per_pixel
;
474 if ((vo_depthonscreen
+ 7) / 8 != (bpp
+ 7) / 8)
475 vo_depthonscreen
= bpp
; // by A'rpi
477 mXImage
->red_mask
| mXImage
->green_mask
| mXImage
->blue_mask
;
478 mp_msg(MSGT_VO
, MSGL_V
,
479 "vo: X11 color mask: %X (R:%lX G:%lX B:%lX)\n", mask
,
480 mXImage
->red_mask
, mXImage
->green_mask
, mXImage
->blue_mask
);
481 XDestroyImage(mXImage
);
483 if (((vo_depthonscreen
+ 7) / 8) == 2)
486 vo_depthonscreen
= 15;
487 else if (mask
== 0xFFFF)
488 vo_depthonscreen
= 16;
490 // XCloseDisplay( mDisplay );
491 /* slightly improved local display detection AST */
492 if (strncmp(dispName
, "unix:", 5) == 0)
494 else if (strncmp(dispName
, "localhost:", 10) == 0)
496 if (*dispName
== ':' && atoi(dispName
+ 1) < 10)
500 mp_msg(MSGT_VO
, MSGL_INFO
,
501 "vo: X11 running at %dx%d with depth %d and %d bpp (\"%s\" => %s display)\n",
502 vo_screenwidth
, vo_screenheight
, depth
, vo_depthonscreen
,
503 dispName
, mLocalDisplay
? "local" : "remote");
505 vo_wm_type
= vo_wm_detect();
507 vo_fs_type
= vo_x11_get_fs_type(vo_wm_type
);
509 fstype_dump(vo_fs_type
);
519 mp_msg(MSGT_VO
, MSGL_V
,
520 "vo: x11 uninit called but X11 not inited..\n");
523 // if( !vo_depthonscreen ) return;
524 mp_msg(MSGT_VO
, MSGL_V
, "vo: uninit ...\n");
525 XSetErrorHandler(NULL
);
526 XCloseDisplay(mDisplay
);
527 vo_depthonscreen
= 0;
531 #include "osdep/keycodes.h"
534 extern void mplayer_put_key(int code
);
536 #ifdef XF86XK_AudioPause
537 void vo_x11_putkey_ext(int keysym
)
541 case XF86XK_AudioPause
:
542 mplayer_put_key(KEY_XF86_PAUSE
);
544 case XF86XK_AudioStop
:
545 mplayer_put_key(KEY_XF86_STOP
);
547 case XF86XK_AudioPrev
:
548 mplayer_put_key(KEY_XF86_PREV
);
550 case XF86XK_AudioNext
:
551 mplayer_put_key(KEY_XF86_NEXT
);
559 void vo_x11_putkey(int key
)
564 mplayer_put_key(KEY_LEFT
);
567 mplayer_put_key(KEY_RIGHT
);
570 mplayer_put_key(KEY_UP
);
573 mplayer_put_key(KEY_DOWN
);
576 mplayer_put_key(' ');
579 mplayer_put_key(KEY_ESC
);
582 mplayer_put_key(KEY_ENTER
);
585 mplayer_put_key(KEY_BS
);
588 mplayer_put_key(KEY_DELETE
);
591 mplayer_put_key(KEY_INSERT
);
594 mplayer_put_key(KEY_HOME
);
597 mplayer_put_key(KEY_END
);
600 mplayer_put_key(KEY_PAGE_UP
);
603 mplayer_put_key(KEY_PAGE_DOWN
);
606 mplayer_put_key(KEY_F
+ 1);
609 mplayer_put_key(KEY_F
+ 2);
612 mplayer_put_key(KEY_F
+ 3);
615 mplayer_put_key(KEY_F
+ 4);
618 mplayer_put_key(KEY_F
+ 5);
621 mplayer_put_key(KEY_F
+ 6);
624 mplayer_put_key(KEY_F
+ 7);
627 mplayer_put_key(KEY_F
+ 8);
630 mplayer_put_key(KEY_F
+ 9);
633 mplayer_put_key(KEY_F
+ 10);
636 mplayer_put_key(KEY_F
+ 11);
639 mplayer_put_key(KEY_F
+ 12);
643 mplayer_put_key('q');
647 mplayer_put_key('p');
651 mplayer_put_key('-');
655 mplayer_put_key('+');
659 mplayer_put_key('*');
663 mplayer_put_key('/');
666 mplayer_put_key('<');
669 mplayer_put_key('>');
672 mplayer_put_key(KEY_KP0
);
676 mplayer_put_key(KEY_KP1
);
680 mplayer_put_key(KEY_KP2
);
684 mplayer_put_key(KEY_KP3
);
688 mplayer_put_key(KEY_KP4
);
692 mplayer_put_key(KEY_KP5
);
696 mplayer_put_key(KEY_KP6
);
700 mplayer_put_key(KEY_KP7
);
704 mplayer_put_key(KEY_KP8
);
708 mplayer_put_key(KEY_KP9
);
711 mplayer_put_key(KEY_KPDEC
);
714 mplayer_put_key(KEY_KPINS
);
717 mplayer_put_key(KEY_KPDEL
);
720 mplayer_put_key(KEY_KPENTER
);
724 mplayer_put_key('m');
728 mplayer_put_key('o');
732 mplayer_put_key('`');
735 mplayer_put_key('~');
738 mplayer_put_key('!');
741 mplayer_put_key('@');
744 mplayer_put_key('#');
747 mplayer_put_key('$');
750 mplayer_put_key('%');
753 mplayer_put_key('^');
756 mplayer_put_key('&');
759 mplayer_put_key('(');
762 mplayer_put_key(')');
765 mplayer_put_key('_');
768 mplayer_put_key('{');
771 mplayer_put_key('}');
774 mplayer_put_key(':');
777 mplayer_put_key(';');
780 mplayer_put_key('\"');
783 mplayer_put_key('\'');
786 mplayer_put_key(',');
789 mplayer_put_key('.');
792 mplayer_put_key('?');
795 mplayer_put_key('\\');
798 mplayer_put_key('|');
801 mplayer_put_key('=');
804 mplayer_put_key('[');
807 mplayer_put_key(']');
812 if ((key
>= 'a' && key
<= 'z') || (key
>= 'A' && key
<= 'Z') ||
813 (key
>= '0' && key
<= '9'))
814 mplayer_put_key(key
);
820 // ----- Motif header: -------
822 #define MWM_HINTS_FUNCTIONS (1L << 0)
823 #define MWM_HINTS_DECORATIONS (1L << 1)
824 #define MWM_HINTS_INPUT_MODE (1L << 2)
825 #define MWM_HINTS_STATUS (1L << 3)
827 #define MWM_FUNC_ALL (1L << 0)
828 #define MWM_FUNC_RESIZE (1L << 1)
829 #define MWM_FUNC_MOVE (1L << 2)
830 #define MWM_FUNC_MINIMIZE (1L << 3)
831 #define MWM_FUNC_MAXIMIZE (1L << 4)
832 #define MWM_FUNC_CLOSE (1L << 5)
834 #define MWM_DECOR_ALL (1L << 0)
835 #define MWM_DECOR_BORDER (1L << 1)
836 #define MWM_DECOR_RESIZEH (1L << 2)
837 #define MWM_DECOR_TITLE (1L << 3)
838 #define MWM_DECOR_MENU (1L << 4)
839 #define MWM_DECOR_MINIMIZE (1L << 5)
840 #define MWM_DECOR_MAXIMIZE (1L << 6)
842 #define MWM_INPUT_MODELESS 0
843 #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
844 #define MWM_INPUT_SYSTEM_MODAL 2
845 #define MWM_INPUT_FULL_APPLICATION_MODAL 3
846 #define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL
848 #define MWM_TEAROFF_WINDOW (1L<<0)
859 extern int vo_depthonscreen
;
860 extern int vo_screenwidth
;
861 extern int vo_screenheight
;
863 static MotifWmHints vo_MotifWmHints
;
864 static Atom vo_MotifHints
= None
;
866 void vo_x11_decoration(Display
* vo_Display
, Window w
, int d
)
868 static unsigned int olddecor
= MWM_DECOR_ALL
;
869 static unsigned int oldfuncs
=
870 MWM_FUNC_MOVE
| MWM_FUNC_CLOSE
| MWM_FUNC_MINIMIZE
|
871 MWM_FUNC_MAXIMIZE
| MWM_FUNC_RESIZE
;
874 unsigned long mn
, mb
;
881 XSetTransientForHint(vo_Display
, w
,
882 RootWindow(vo_Display
, mScreen
));
885 vo_MotifHints
= XInternAtom(vo_Display
, "_MOTIF_WM_HINTS", 0);
886 if (vo_MotifHints
!= None
)
890 MotifWmHints
*mhints
= NULL
;
892 XGetWindowProperty(vo_Display
, w
, vo_MotifHints
, 0, 20, False
,
893 vo_MotifHints
, &mtype
, &mformat
, &mn
,
894 &mb
, (unsigned char **) &mhints
);
897 if (mhints
->flags
& MWM_HINTS_DECORATIONS
)
898 olddecor
= mhints
->decorations
;
899 if (mhints
->flags
& MWM_HINTS_FUNCTIONS
)
900 oldfuncs
= mhints
->functions
;
905 memset(&vo_MotifWmHints
, 0, sizeof(MotifWmHints
));
906 vo_MotifWmHints
.flags
=
907 MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
910 vo_MotifWmHints
.functions
= oldfuncs
;
914 vo_MotifWmHints
.decorations
=
915 d
| ((vo_fsmode
& 2) ? 0 : MWM_DECOR_MENU
);
917 vo_MotifWmHints
.decorations
=
918 d
| ((vo_fsmode
& 2) ? MWM_DECOR_MENU
: 0);
920 XChangeProperty(vo_Display
, w
, vo_MotifHints
, vo_MotifHints
, 32,
922 (unsigned char *) &vo_MotifWmHints
,
923 (vo_fsmode
& 4) ? 4 : 5);
927 void vo_x11_classhint(Display
* display
, Window window
, char *name
)
930 pid_t pid
= getpid();
932 wmClass
.res_name
= name
;
933 wmClass
.res_class
= "MPlayer";
934 XSetClassHint(display
, window
, &wmClass
);
935 XChangeProperty(display
, window
, XA_NET_WM_PID
, XA_CARDINAL
, 32,
936 PropModeReplace
, (unsigned char *) &pid
, 1);
939 Window vo_window
= None
;
945 void vo_setwindow(Window w
, GC g
)
955 if (vo_window
!= None
)
956 vo_showcursor(mDisplay
, vo_window
);
960 XFreeGC(mDisplay
, f_gc
);
964 /* destroy window only if it's not controlled by GUI */
970 XSetBackground(mDisplay
, vo_gc
, 0);
971 XFreeGC(mDisplay
, vo_gc
);
974 if (vo_window
!= None
)
976 XClearWindow(mDisplay
, vo_window
);
981 XUnmapWindow(mDisplay
, vo_window
);
982 XDestroyWindow(mDisplay
, vo_window
);
985 XNextEvent(mDisplay
, &xev
);
987 while (xev
.type
!= DestroyNotify
988 || xev
.xdestroywindow
.event
!= vo_window
);
993 vo_old_width
= vo_old_height
= 0;
997 int vo_mouse_timer_const
= 30;
998 static int vo_mouse_counter
= 30;
1000 int vo_x11_check_events(Display
* mydisplay
)
1006 static XComposeStatus stat
;
1008 // unsigned long vo_KeyTable[512];
1010 if ((vo_mouse_autohide
) && (--vo_mouse_counter
== 0))
1011 vo_hidecursor(mydisplay
, vo_window
);
1013 while (XPending(mydisplay
))
1015 XNextEvent(mydisplay
, &Event
);
1019 guiGetEvent(0, (char *) &Event
);
1020 if (vo_window
!= Event
.xany
.window
)
1024 // printf("\rEvent.type=%X \n",Event.type);
1028 ret
|= VO_EVENT_EXPOSE
;
1030 case ConfigureNotify
:
1031 // if (!vo_fs && (Event.xconfigure.width == vo_screenwidth || Event.xconfigure.height == vo_screenheight)) break;
1032 // if (vo_fs && Event.xconfigure.width != vo_screenwidth && Event.xconfigure.height != vo_screenheight) break;
1033 if (vo_window
== None
)
1035 vo_dwidth
= Event
.xconfigure
.width
;
1036 vo_dheight
= Event
.xconfigure
.height
;
1038 /* when resizing, x and y are zero :( */
1039 vo_dx
= Event
.xconfigure
.x
;
1040 vo_dy
= Event
.xconfigure
.y
;
1047 XGetGeometry(mydisplay
, vo_window
, &root
, &foo
, &foo
,
1048 &foo
/*width */ , &foo
/*height */ , &foo
,
1050 XTranslateCoordinates(mydisplay
, vo_window
, root
, 0, 0,
1051 &vo_dx
, &vo_dy
, &win
);
1054 ret
|= VO_EVENT_RESIZE
;
1061 if ( use_gui
) { break; }
1064 XLookupString(&Event
.xkey
, buf
, sizeof(buf
), &keySym
,
1066 #ifdef XF86XK_AudioPause
1067 vo_x11_putkey_ext(keySym
);
1070 ((keySym
& 0xff00) !=
1071 0 ? ((keySym
& 0x00ff) + 256) : (keySym
));
1073 ret
|= VO_EVENT_KEYPRESS
;
1077 if (vo_mouse_autohide
)
1079 vo_showcursor(mydisplay
, vo_window
);
1080 vo_mouse_counter
= vo_mouse_timer_const
;
1084 if (vo_mouse_autohide
)
1086 vo_showcursor(mydisplay
, vo_window
);
1087 vo_mouse_counter
= vo_mouse_timer_const
;
1089 // Ignore mouse whell press event
1090 if (Event
.xbutton
.button
> 3)
1092 mplayer_put_key(MOUSE_BTN0
+ Event
.xbutton
.button
- 1);
1096 // Ignor mouse button 1 - 3 under gui
1097 if (use_gui
&& (Event
.xbutton
.button
>= 1)
1098 && (Event
.xbutton
.button
<= 3))
1101 mplayer_put_key((MOUSE_BTN0
+ Event
.xbutton
.button
-
1105 if (vo_mouse_autohide
)
1107 vo_showcursor(mydisplay
, vo_window
);
1108 vo_mouse_counter
= vo_mouse_timer_const
;
1111 // Ignor mouse button 1 - 3 under gui
1112 if (use_gui
&& (Event
.xbutton
.button
>= 1)
1113 && (Event
.xbutton
.button
<= 3))
1116 mplayer_put_key(MOUSE_BTN0
+ Event
.xbutton
.button
- 1);
1118 case PropertyNotify
:
1121 XGetAtomName(mydisplay
, Event
.xproperty
.atom
);
1126 // fprintf(stderr,"[ws] PropertyNotify ( 0x%x ) %s ( 0x%x )\n",vo_window,name,Event.xproperty.atom );
1132 vo_hint
.win_gravity
= old_gravity
;
1133 XSetWMNormalHints(mDisplay
, vo_window
, &vo_hint
);
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
)
1149 vo_old_width
= width
;
1150 vo_old_height
= height
;
1155 vo_dheight
= height
;
1156 XMoveResizeWindow(mDisplay
, vo_window
, x
, y
, width
, height
);
1160 void vo_x11_sizehint(int x
, int y
, int width
, int height
, int max
)
1162 vo_hint
.flags
= PPosition
| PSize
| PWinGravity
;
1165 vo_hint
.flags
|= PAspect
;
1166 vo_hint
.min_aspect
.x
= width
;
1167 vo_hint
.min_aspect
.y
= height
;
1168 vo_hint
.max_aspect
.x
= width
;
1169 vo_hint
.max_aspect
.y
= height
;
1174 vo_hint
.width
= width
;
1175 vo_hint
.height
= height
;
1178 vo_hint
.max_width
= width
;
1179 vo_hint
.max_height
= height
;
1180 vo_hint
.flags
|= PMaxSize
;
1183 vo_hint
.max_width
= 0;
1184 vo_hint
.max_height
= 0;
1187 // set min height/width to 4 to avoid off by one errors
1188 // and because mga_vid requires a minial size of 4 pixel
1189 vo_hint
.min_width
= vo_hint
.min_height
= 4;
1190 vo_hint
.flags
|= PMinSize
;
1192 vo_hint
.win_gravity
= StaticGravity
;
1193 XSetWMNormalHints(mDisplay
, vo_window
, &vo_hint
);
1196 static int vo_x11_get_gnome_layer(Display
* mDisplay
, Window win
)
1200 unsigned long nitems
;
1201 unsigned long bytesafter
;
1202 unsigned short *args
= NULL
;
1204 if (XGetWindowProperty(mDisplay
, win
, XA_WIN_LAYER
, 0, 16384,
1205 False
, AnyPropertyType
, &type
, &format
, &nitems
,
1207 (unsigned char **) &args
) == Success
1208 && nitems
> 0 && args
)
1210 mp_msg(MSGT_VO
, MSGL_V
, "[x11] original window layer is %d.\n",
1214 return WIN_LAYER_NORMAL
;
1218 Window
vo_x11_create_smooth_window(Display
* mDisplay
, Window mRoot
,
1219 Visual
* vis
, int x
, int y
,
1220 unsigned int width
, unsigned int height
,
1221 int depth
, Colormap col_map
)
1223 unsigned long xswamask
= CWBackingStore
| CWBorderPixel
;
1224 XSetWindowAttributes xswa
;
1227 if (col_map
!= CopyFromParent
)
1229 xswa
.colormap
= col_map
;
1230 xswamask
|= CWColormap
;
1232 xswa
.background_pixel
= 0;
1233 xswa
.border_pixel
= 0;
1234 xswa
.backing_store
= Always
;
1235 xswa
.bit_gravity
= StaticGravity
;
1238 XCreateWindow(mDisplay
, mRootWin
, x
, y
, width
, height
, 0, depth
,
1239 CopyFromParent
, vis
, xswamask
, &xswa
);
1241 f_gc
= XCreateGC(mDisplay
, ret_win
, 0, 0);
1242 XSetForeground(mDisplay
, f_gc
, 0);
1248 void vo_x11_clearwindow_part(Display
* mDisplay
, Window vo_window
,
1249 int img_width
, int img_height
, int use_fs
)
1251 int u_dheight
, u_dwidth
, left_ov
, left_ov2
;
1256 u_dheight
= use_fs
? vo_screenheight
: vo_dheight
;
1257 u_dwidth
= use_fs
? vo_screenwidth
: vo_dwidth
;
1258 if ((u_dheight
<= img_height
) && (u_dwidth
<= img_width
))
1261 left_ov
= (u_dheight
- img_height
) / 2;
1262 left_ov2
= (u_dwidth
- img_width
) / 2;
1264 XFillRectangle(mDisplay
, vo_window
, f_gc
, 0, 0, u_dwidth
, left_ov
);
1265 XFillRectangle(mDisplay
, vo_window
, f_gc
, 0, u_dheight
- left_ov
- 1,
1266 u_dwidth
, left_ov
+ 1);
1268 if (u_dwidth
> img_width
)
1270 XFillRectangle(mDisplay
, vo_window
, f_gc
, 0, left_ov
, left_ov2
,
1272 XFillRectangle(mDisplay
, vo_window
, f_gc
, u_dwidth
- left_ov2
- 1,
1273 left_ov
, left_ov2
, img_height
);
1279 void vo_x11_clearwindow(Display
* mDisplay
, Window vo_window
)
1283 XFillRectangle(mDisplay
, vo_window
, f_gc
, 0, 0, vo_screenwidth
,
1290 void vo_x11_setlayer(Display
* mDisplay
, Window vo_window
, int layer
)
1295 if (vo_fs_type
& vo_wm_LAYER
)
1297 XClientMessageEvent xev
;
1300 orig_layer
= vo_x11_get_gnome_layer(mDisplay
, vo_window
);
1302 memset(&xev
, 0, sizeof(xev
));
1303 xev
.type
= ClientMessage
;
1304 xev
.display
= mDisplay
;
1305 xev
.window
= vo_window
;
1306 xev
.message_type
= XA_WIN_LAYER
;
1308 xev
.data
.l
[0] = layer
? fs_layer
: orig_layer
; // if not fullscreen, stay on default layer
1309 xev
.data
.l
[1] = CurrentTime
;
1310 mp_msg(MSGT_VO
, MSGL_V
,
1311 "[x11] Layered style stay on top (layer %d).\n",
1313 XSendEvent(mDisplay
, mRootWin
, False
, SubstructureNotifyMask
,
1315 } else if (vo_fs_type
& vo_wm_NETWM
)
1317 XClientMessageEvent xev
;
1320 memset(&xev
, 0, sizeof(xev
));
1321 xev
.type
= ClientMessage
;
1322 xev
.message_type
= XA_NET_WM_STATE
;
1323 xev
.display
= mDisplay
;
1324 xev
.window
= vo_window
;
1326 xev
.data
.l
[0] = layer
;
1328 if (vo_fs_type
& vo_wm_STAYS_ON_TOP
)
1329 xev
.data
.l
[1] = XA_NET_WM_STATE_STAYS_ON_TOP
;
1330 else if (vo_fs_type
& vo_wm_ABOVE
)
1331 xev
.data
.l
[1] = XA_NET_WM_STATE_ABOVE
;
1332 else if (vo_fs_type
& vo_wm_FULLSCREEN
)
1333 xev
.data
.l
[1] = XA_NET_WM_STATE_FULLSCREEN
;
1334 else if (vo_fs_type
& vo_wm_BELOW
)
1335 // This is not fallback. We can safely assume that situation where
1336 // only NETWM_STATE_BELOW is supported and others not, doesn't exist.
1337 xev
.data
.l
[1] = XA_NET_WM_STATE_BELOW
;
1339 XSendEvent(mDisplay
, mRootWin
, False
, SubstructureRedirectMask
,
1341 state
= XGetAtomName(mDisplay
, xev
.data
.l
[1]);
1342 mp_msg(MSGT_VO
, MSGL_V
,
1343 "[x11] NET style stay on top (layer %d). Using state %s.\n",
1349 static int vo_x11_get_fs_type(int supported
)
1352 int type
= supported
;
1357 for (i
= 0; vo_fstype_list
[i
]; i
++)
1360 char *arg
= vo_fstype_list
[i
];
1362 if (vo_fstype_list
[i
][0] == '-')
1365 arg
= vo_fstype_list
[i
] + 1;
1368 if (!strncmp(arg
, "layer", 5))
1370 if (!neg
&& (arg
[5] == '='))
1372 char *endptr
= NULL
;
1373 int layer
= strtol(vo_fstype_list
[i
] + 6, &endptr
, 10);
1375 if (endptr
&& *endptr
== '\0' && layer
>= 0
1380 type
&= ~vo_wm_LAYER
;
1382 type
|= vo_wm_LAYER
;
1383 } else if (!strcmp(arg
, "above"))
1386 type
&= ~vo_wm_ABOVE
;
1388 type
|= vo_wm_ABOVE
;
1389 } else if (!strcmp(arg
, "fullscreen"))
1392 type
&= ~vo_wm_FULLSCREEN
;
1394 type
|= vo_wm_FULLSCREEN
;
1395 } else if (!strcmp(arg
, "stays_on_top"))
1398 type
&= ~vo_wm_STAYS_ON_TOP
;
1400 type
|= vo_wm_STAYS_ON_TOP
;
1401 } else if (!strcmp(arg
, "below"))
1404 type
&= ~vo_wm_BELOW
;
1406 type
|= vo_wm_BELOW
;
1407 } else if (!strcmp(arg
, "netwm"))
1410 type
&= ~vo_wm_NETWM
;
1412 type
|= vo_wm_NETWM
;
1413 } else if (!strcmp(arg
, "none"))
1421 void vo_x11_fullscreen(void)
1425 if (WinID
>= 0 || vo_fs_flip
)
1431 if ( ! (vo_fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1433 if (vo_dwidth
!= vo_screenwidth
&& vo_dheight
!= vo_screenheight
)
1441 vo_x11_ewmh_fullscreen(_NET_WM_STATE_REMOVE
); // removes fullscreen state if wm supports EWMH
1446 vo_x11_ewmh_fullscreen(_NET_WM_STATE_ADD
); // sends fullscreen state to be added if wm supports EWMH
1449 if ( ! (vo_fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1452 (vo_dwidth
== vo_screenwidth
&& vo_dwidth
!= vo_old_width
) &&
1453 (vo_dheight
== vo_screenheight
&& vo_dheight
!= vo_old_height
))
1457 vo_old_width
= vo_dwidth
;
1458 vo_old_height
= vo_dheight
;
1462 h
= vo_screenheight
;
1468 XGetWMNormalHints(mDisplay
, vo_window
, &vo_hint
, &dummy
);
1469 if (!(vo_hint
.flags
& PWinGravity
))
1470 old_gravity
= NorthWestGravity
;
1472 old_gravity
= vo_hint
.win_gravity
;
1474 if (vo_wm_type
== 0 && !(vo_fsmode
& 16))
1476 XUnmapWindow(mDisplay
, vo_window
); // required for MWM
1477 XWithdrawWindow(mDisplay
, vo_window
, mScreen
);
1481 if ( ! (vo_fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1483 vo_x11_decoration(mDisplay
, vo_window
, (vo_fs
) ? 0 : 1);
1484 vo_x11_sizehint(x
, y
, w
, h
, 0);
1485 vo_x11_setlayer(mDisplay
, vo_window
, vo_fs
);
1487 if ((!(vo_fs
)) & vo_ontop
)
1488 vo_x11_setlayer(mDisplay
, vo_window
, vo_ontop
);
1490 XMoveResizeWindow(mDisplay
, vo_window
, x
, y
, w
, h
);
1492 #ifdef HAVE_XINERAMA
1493 vo_x11_xinerama_move(mDisplay
, vo_window
);
1496 XMapRaised(mDisplay
, vo_window
);
1497 XRaiseWindow(mDisplay
, vo_window
);
1501 void vo_x11_ontop(void)
1503 vo_ontop
= (!(vo_ontop
));
1505 vo_x11_setlayer(mDisplay
, vo_window
, vo_ontop
);
1509 * XScreensaver stuff
1512 static int got_badwindow
;
1513 static XErrorHandler old_handler
;
1515 static int badwindow_handler(Display
* dpy
, XErrorEvent
* error
)
1517 if (error
->error_code
!= BadWindow
)
1518 return (*old_handler
) (dpy
, error
);
1520 got_badwindow
= True
;
1524 static Window
find_xscreensaver_window(Display
* dpy
)
1527 Window root
= RootWindowOfScreen(DefaultScreenOfDisplay(dpy
));
1528 Window root2
, parent
, *kids
;
1531 unsigned int nkids
= 0;
1533 xs_version
= XInternAtom(dpy
, "_SCREENSAVER_VERSION", True
);
1535 if (!(xs_version
!= None
&&
1536 XQueryTree(dpy
, root
, &root2
, &parent
, &kids
, &nkids
) &&
1540 old_handler
= XSetErrorHandler(badwindow_handler
);
1542 for (i
= 0; i
< nkids
; i
++)
1546 unsigned long nitems
, bytesafter
;
1550 got_badwindow
= False
;
1552 XGetWindowProperty(dpy
, kids
[i
], xs_version
, 0, 200, False
,
1553 XA_STRING
, &type
, &format
, &nitems
,
1554 &bytesafter
, (unsigned char **) &v
);
1559 if (status
== Success
&& type
!= None
)
1566 XSetErrorHandler(old_handler
);
1571 static Window xs_windowid
= 0;
1572 static Atom deactivate
;
1573 static Atom screensaver
;
1575 static unsigned int time_last
;
1577 void xscreensaver_heartbeat(void)
1579 unsigned int time
= GetTimerMS();
1582 if (mDisplay
&& xs_windowid
&&
1583 ((time
- time_last
) > 30000 || (time
- time_last
) < 0))
1587 ev
.xany
.type
= ClientMessage
;
1588 ev
.xclient
.display
= mDisplay
;
1589 ev
.xclient
.window
= xs_windowid
;
1590 ev
.xclient
.message_type
= screensaver
;
1591 ev
.xclient
.format
= 32;
1592 memset(&ev
.xclient
.data
, 0, sizeof(ev
.xclient
.data
));
1593 ev
.xclient
.data
.l
[0] = (long) deactivate
;
1595 mp_msg(MSGT_VO
, MSGL_DBG2
, "Pinging xscreensaver.\n");
1596 XSendEvent(mDisplay
, xs_windowid
, False
, 0L, &ev
);
1597 XSync(mDisplay
, False
);
1601 static void xscreensaver_disable(Display
* dpy
)
1603 mp_msg(MSGT_VO
, MSGL_DBG2
, "xscreensaver_disable()\n");
1605 xs_windowid
= find_xscreensaver_window(dpy
);
1608 mp_msg(MSGT_VO
, MSGL_INFO
,
1609 "xscreensaver_disable: Could not find xscreensaver window.\n");
1612 mp_msg(MSGT_VO
, MSGL_INFO
,
1613 "xscreensaver_disable: xscreensaver wid=%d.\n", xs_windowid
);
1615 deactivate
= XInternAtom(dpy
, "DEACTIVATE", False
);
1616 screensaver
= XInternAtom(dpy
, "SCREENSAVER", False
);
1619 static void xscreensaver_enable(void)
1625 * End of XScreensaver stuff
1628 void saver_on(Display
* mDisplay
)
1636 if (DPMSQueryExtension(mDisplay
, ¬hing
, ¬hing
))
1638 if (!DPMSEnable(mDisplay
))
1639 { // restoring power saving settings
1640 mp_msg(MSGT_VO
, MSGL_WARN
, "DPMS not available?\n");
1643 // DPMS does not seem to be enabled unless we call DPMSInfo
1647 DPMSForceLevel(mDisplay
, DPMSModeOn
);
1648 DPMSInfo(mDisplay
, &state
, &onoff
);
1651 mp_msg(MSGT_VO
, MSGL_V
,
1652 "Successfully enabled DPMS\n");
1655 mp_msg(MSGT_VO
, MSGL_WARN
, "Could not enable DPMS\n");
1665 int dummy
, interval
, prefer_blank
, allow_exp
;
1667 XGetScreenSaver(mDisplay
, &dummy
, &interval
, &prefer_blank
,
1669 XSetScreenSaver(mDisplay
, timeout_save
, interval
, prefer_blank
,
1671 XGetScreenSaver(mDisplay
, &timeout_save
, &interval
, &prefer_blank
,
1676 if (stop_xscreensaver
)
1677 xscreensaver_enable();
1678 if (kdescreensaver_was_running
&& stop_xscreensaver
)
1681 ("dcop kdesktop KScreensaverIface enable true 2>/dev/null >/dev/null");
1682 kdescreensaver_was_running
= 0;
1688 void saver_off(Display
* mDisplay
)
1691 int interval
, prefer_blank
, allow_exp
;
1696 if (DPMSQueryExtension(mDisplay
, ¬hing
, ¬hing
))
1701 DPMSInfo(mDisplay
, &state
, &onoff
);
1706 mp_msg(MSGT_VO
, MSGL_V
, "Disabling DPMS\n");
1708 stat
= DPMSDisable(mDisplay
); // monitor powersave off
1709 mp_msg(MSGT_VO
, MSGL_V
, "DPMSDisable stat: %d\n", stat
);
1715 XGetScreenSaver(mDisplay
, &timeout_save
, &interval
, &prefer_blank
,
1718 XSetScreenSaver(mDisplay
, 0, interval
, prefer_blank
,
1721 // turning off screensaver
1722 if (stop_xscreensaver
)
1723 xscreensaver_disable(mDisplay
);
1724 if (stop_xscreensaver
&& !kdescreensaver_was_running
)
1726 kdescreensaver_was_running
=
1728 ("dcop kdesktop KScreensaverIface isEnabled 2>/dev/null | sed 's/1/true/g' | grep true 2>/dev/null >/dev/null")
1730 if (kdescreensaver_was_running
)
1732 ("dcop kdesktop KScreensaverIface enable false 2>/dev/null >/dev/null");
1736 static XErrorHandler old_handler
= NULL
;
1737 static int selectinput_err
= 0;
1738 static int x11_selectinput_errorhandler(Display
* display
,
1739 XErrorEvent
* event
)
1741 if (event
->error_code
== BadAccess
)
1743 selectinput_err
= 1;
1744 mp_msg(MSGT_VO
, MSGL_ERR
,
1745 "X11 error: BadAccess during XSelectInput Call\n");
1746 mp_msg(MSGT_VO
, MSGL_ERR
,
1747 "X11 error: The 'ButtonPressMask' mask of specified window has probably already used by another appication (see man XSelectInput)\n");
1748 /* If you think mplayer should shutdown with this error, comments out following line */
1751 if (old_handler
!= NULL
)
1752 old_handler(display
, event
);
1754 x11_errorhandler(display
, event
);
1758 void vo_x11_selectinput_witherr(Display
* display
, Window w
,
1761 XSync(display
, False
);
1762 old_handler
= XSetErrorHandler(x11_selectinput_errorhandler
);
1763 selectinput_err
= 0;
1764 if (vo_nomouse_input
)
1766 XSelectInput(display
, w
,
1768 (~(ButtonPressMask
| ButtonReleaseMask
)));
1771 XSelectInput(display
, w
, event_mask
);
1773 XSync(display
, False
);
1774 XSetErrorHandler(old_handler
);
1775 if (selectinput_err
)
1777 mp_msg(MSGT_VO
, MSGL_ERR
,
1778 "X11 error: MPlayer discards mouse control (reconfiguring)\n");
1779 XSelectInput(display
, w
,
1782 (ButtonPressMask
| ButtonReleaseMask
|
1783 PointerMotionMask
)));
1787 #ifdef HAVE_XINERAMA
1788 void vo_x11_xinerama_move(Display
* dsp
, Window w
)
1790 if (XineramaIsActive(dsp
) && !geometry_xy_changed
)
1792 /* printf("XXXX Xinerama screen: x: %hd y: %hd\n",xinerama_x,xinerama_y); */
1793 XMoveWindow(dsp
, w
, xinerama_x
, xinerama_y
);
1799 void vo_vm_switch(uint32_t X
, uint32_t Y
, int *modeline_width
,
1800 int *modeline_height
)
1802 int vm_event
, vm_error
;
1804 int i
, j
, have_vm
= 0;
1808 if (XF86VidModeQueryExtension(mDisplay
, &vm_event
, &vm_error
))
1810 XF86VidModeQueryVersion(mDisplay
, &vm_ver
, &vm_rev
);
1811 mp_msg(MSGT_VO
, MSGL_V
, "XF86VidMode Extension v%i.%i\n", vm_ver
,
1815 mp_msg(MSGT_VO
, MSGL_WARN
,
1816 "XF86VidMode Extenstion not available.\n");
1820 if (vidmodes
== NULL
)
1821 XF86VidModeGetAllModeLines(mDisplay
, mScreen
, &modecount
,
1824 *modeline_width
= vidmodes
[0]->hdisplay
;
1825 *modeline_height
= vidmodes
[0]->vdisplay
;
1827 for (i
= 1; i
< modecount
; i
++)
1828 if ((vidmodes
[i
]->hdisplay
>= X
)
1829 && (vidmodes
[i
]->vdisplay
>= Y
))
1830 if ((vidmodes
[i
]->hdisplay
<= *modeline_width
)
1831 && (vidmodes
[i
]->vdisplay
<= *modeline_height
))
1833 *modeline_width
= vidmodes
[i
]->hdisplay
;
1834 *modeline_height
= vidmodes
[i
]->vdisplay
;
1838 mp_msg(MSGT_VO
, MSGL_INFO
,
1839 "XF86VM: Selected video mode %dx%d for image size %dx%d.\n",
1840 *modeline_width
, *modeline_height
, X
, Y
);
1841 XF86VidModeLockModeSwitch(mDisplay
, mScreen
, 0);
1842 XF86VidModeSwitchToMode(mDisplay
, mScreen
, vidmodes
[j
]);
1843 XF86VidModeSwitchToMode(mDisplay
, mScreen
, vidmodes
[j
]);
1844 X
= (vo_screenwidth
- *modeline_width
) / 2;
1845 Y
= (vo_screenheight
- *modeline_height
) / 2;
1846 XF86VidModeSetViewPort(mDisplay
, mScreen
, X
, Y
);
1850 void vo_vm_close(Display
* dpy
)
1853 if (vidmodes
!= NULL
&& vo_window
!= None
)
1855 if (vidmodes
!= NULL
)
1861 screen
= DefaultScreen(dpy
);
1865 XF86VidModeGetAllModeLines(mDisplay
, mScreen
, &modecount
,
1867 for (i
= 0; i
< modecount
; i
++)
1868 if ((vidmodes
[i
]->hdisplay
== vo_screenwidth
)
1869 && (vidmodes
[i
]->vdisplay
== vo_screenheight
))
1871 mp_msg(MSGT_VO
, MSGL_INFO
,
1872 "Returning to original mode %dx%d\n",
1873 vo_screenwidth
, vo_screenheight
);
1877 XF86VidModeSwitchToMode(dpy
, screen
, vidmodes
[i
]);
1878 XF86VidModeSwitchToMode(dpy
, screen
, vidmodes
[i
]);
1885 #endif /* X11_FULLSCREEN */
1889 * Scan the available visuals on this Display/Screen. Try to find
1890 * the 'best' available TrueColor visual that has a decent color
1891 * depth (at least 15bit). If there are multiple visuals with depth
1892 * >= 15bit, we prefer visuals with a smaller color depth.
1894 int vo_find_depth_from_visuals(Display
* dpy
, int screen
,
1895 Visual
** visual_return
)
1897 XVisualInfo visual_tmpl
;
1898 XVisualInfo
*visuals
;
1900 int bestvisual
= -1;
1901 int bestvisual_depth
= -1;
1903 visual_tmpl
.screen
= screen
;
1904 visual_tmpl
.class = TrueColor
;
1905 visuals
= XGetVisualInfo(dpy
,
1906 VisualScreenMask
| VisualClassMask
,
1907 &visual_tmpl
, &nvisuals
);
1908 if (visuals
!= NULL
)
1910 for (i
= 0; i
< nvisuals
; i
++)
1912 mp_msg(MSGT_VO
, MSGL_V
,
1913 "vo: X11 truecolor visual %#x, depth %d, R:%lX G:%lX B:%lX\n",
1914 visuals
[i
].visualid
, visuals
[i
].depth
,
1915 visuals
[i
].red_mask
, visuals
[i
].green_mask
,
1916 visuals
[i
].blue_mask
);
1918 * save the visual index and it's depth, if this is the first
1919 * truecolor visul, or a visual that is 'preferred' over the
1920 * previous 'best' visual
1922 if (bestvisual_depth
== -1
1923 || (visuals
[i
].depth
>= 15
1924 && (visuals
[i
].depth
< bestvisual_depth
1925 || bestvisual_depth
< 15)))
1928 bestvisual_depth
= visuals
[i
].depth
;
1932 if (bestvisual
!= -1 && visual_return
!= NULL
)
1933 *visual_return
= visuals
[bestvisual
].visual
;
1937 return bestvisual_depth
;
1941 static Colormap cmap
= None
;
1942 static XColor cols
[256];
1943 static int cm_size
, red_mask
, green_mask
, blue_mask
;
1946 Colormap
vo_x11_create_colormap(XVisualInfo
* vinfo
)
1948 unsigned k
, r
, g
, b
, ru
, gu
, bu
, m
, rv
, gv
, bv
, rvu
, gvu
, bvu
;
1950 if (vinfo
->class != DirectColor
)
1951 return XCreateColormap(mDisplay
, mRootWin
, vinfo
->visual
,
1954 /* can this function get called twice or more? */
1957 cm_size
= vinfo
->colormap_size
;
1958 red_mask
= vinfo
->red_mask
;
1959 green_mask
= vinfo
->green_mask
;
1960 blue_mask
= vinfo
->blue_mask
;
1961 ru
= (red_mask
& (red_mask
- 1)) ^ red_mask
;
1962 gu
= (green_mask
& (green_mask
- 1)) ^ green_mask
;
1963 bu
= (blue_mask
& (blue_mask
- 1)) ^ blue_mask
;
1964 rvu
= 65536ull * ru
/ (red_mask
+ ru
);
1965 gvu
= 65536ull * gu
/ (green_mask
+ gu
);
1966 bvu
= 65536ull * bu
/ (blue_mask
+ bu
);
1969 m
= DoRed
| DoGreen
| DoBlue
;
1970 for (k
= 0; k
< cm_size
; k
++)
1974 cols
[k
].pixel
= r
| g
| b
;
1979 t
= (r
+ ru
) & red_mask
;
1983 t
= (g
+ gu
) & green_mask
;
1987 t
= (b
+ bu
) & blue_mask
;
1995 cmap
= XCreateColormap(mDisplay
, mRootWin
, vinfo
->visual
, AllocAll
);
1996 XStoreColors(mDisplay
, cmap
, cols
, cm_size
);
2001 * Via colormaps/gamma ramps we can do gamma, brightness, contrast,
2002 * hue and red/green/blue intensity, but we cannot do saturation.
2003 * Currently only gamma, brightness and contrast are implemented.
2004 * Is there sufficient interest for hue and/or red/green/blue intensity?
2006 /* these values have range [-100,100] and are initially 0 */
2007 static int vo_gamma
= 0;
2008 static int vo_brightness
= 0;
2009 static int vo_contrast
= 0;
2012 uint32_t vo_x11_set_equalizer(char *name
, int value
)
2014 float gamma
, brightness
, contrast
;
2019 * IMPLEMENTME: consider using XF86VidModeSetGammaRamp in the case
2020 * of TrueColor-ed window but be careful:
2021 * unlike the colormaps, which are private for the X client
2022 * who created them and thus automatically destroyed on client
2023 * disconnect, this gamma ramp is a system-wide (X-server-wide)
2024 * setting and _must_ be restored before the process exit.
2025 * Unforunately when the process crashes (or get killed
2026 * for some reason) it is impossible to restore the setting,
2027 * and such behaviour could be rather annoying for the users.
2032 if (!strcasecmp(name
, "brightness"))
2033 vo_brightness
= value
;
2034 else if (!strcasecmp(name
, "contrast"))
2035 vo_contrast
= value
;
2036 else if (!strcasecmp(name
, "gamma"))
2041 brightness
= 0.01 * vo_brightness
;
2042 contrast
= tan(0.0095 * (vo_contrast
+ 100) * M_PI
/ 4);
2043 gamma
= pow(2, -0.02 * vo_gamma
);
2045 rf
= (float) ((red_mask
& (red_mask
- 1)) ^ red_mask
) / red_mask
;
2046 gf
= (float) ((green_mask
& (green_mask
- 1)) ^ green_mask
) /
2048 bf
= (float) ((blue_mask
& (blue_mask
- 1)) ^ blue_mask
) / blue_mask
;
2050 /* now recalculate the colormap using the newly set value */
2051 for (k
= 0; k
< cm_size
; k
++)
2055 s
= pow(rf
* k
, gamma
);
2056 s
= (s
- 0.5) * contrast
+ 0.5;
2062 cols
[k
].red
= (unsigned short) (s
* 65535);
2064 s
= pow(gf
* k
, gamma
);
2065 s
= (s
- 0.5) * contrast
+ 0.5;
2071 cols
[k
].green
= (unsigned short) (s
* 65535);
2073 s
= pow(bf
* k
, gamma
);
2074 s
= (s
- 0.5) * contrast
+ 0.5;
2080 cols
[k
].blue
= (unsigned short) (s
* 65535);
2083 XStoreColors(mDisplay
, cmap
, cols
, cm_size
);
2088 uint32_t vo_x11_get_equalizer(char *name
, int *value
)
2092 if (!strcasecmp(name
, "brightness"))
2093 *value
= vo_brightness
;
2094 else if (!strcasecmp(name
, "contrast"))
2095 *value
= vo_contrast
;
2096 else if (!strcasecmp(name
, "gamma"))
2104 int vo_xv_set_eq(uint32_t xv_port
, char *name
, int value
)
2106 XvAttribute
*attributes
;
2107 int i
, howmany
, xv_atom
;
2109 mp_dbg(MSGT_VO
, MSGL_V
, "xv_set_eq called! (%s, %d)\n", name
, value
);
2111 /* get available attributes */
2112 attributes
= XvQueryPortAttributes(mDisplay
, xv_port
, &howmany
);
2113 for (i
= 0; i
< howmany
&& attributes
; i
++)
2114 if (attributes
[i
].flags
& XvSettable
)
2116 xv_atom
= XInternAtom(mDisplay
, attributes
[i
].name
, True
);
2117 /* since we have SET_DEFAULTS first in our list, we can check if it's available
2118 then trigger it if it's ok so that the other values are at default upon query */
2119 if (xv_atom
!= None
)
2121 int hue
= 0, port_value
, port_min
, port_max
;
2123 if (!strcmp(attributes
[i
].name
, "XV_BRIGHTNESS") &&
2124 (!strcasecmp(name
, "brightness")))
2126 else if (!strcmp(attributes
[i
].name
, "XV_CONTRAST") &&
2127 (!strcasecmp(name
, "contrast")))
2129 else if (!strcmp(attributes
[i
].name
, "XV_SATURATION") &&
2130 (!strcasecmp(name
, "saturation")))
2132 else if (!strcmp(attributes
[i
].name
, "XV_HUE") &&
2133 (!strcasecmp(name
, "hue")))
2138 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
2139 if (!strcmp(attributes
[i
].name
, "XV_RED_INTENSITY") &&
2140 (!strcasecmp(name
, "red_intensity")))
2142 else if (!strcmp(attributes
[i
].name
, "XV_GREEN_INTENSITY")
2143 && (!strcasecmp(name
, "green_intensity")))
2145 else if (!strcmp(attributes
[i
].name
, "XV_BLUE_INTENSITY")
2146 && (!strcasecmp(name
, "blue_intensity")))
2151 port_min
= attributes
[i
].min_value
;
2152 port_max
= attributes
[i
].max_value
;
2154 /* nvidia hue workaround */
2155 if (hue
&& port_min
== 0 && port_max
== 360)
2159 0) ? (port_value
- 100) : (port_value
+ 100);
2165 (port_value
+ 100) * (port_max
- port_min
) / 200 +
2167 XvSetPortAttribute(mDisplay
, xv_port
, xv_atom
, port_value
);
2174 int vo_xv_get_eq(uint32_t xv_port
, char *name
, int *value
)
2177 XvAttribute
*attributes
;
2178 int i
, howmany
, xv_atom
;
2180 /* get available attributes */
2181 attributes
= XvQueryPortAttributes(mDisplay
, xv_port
, &howmany
);
2182 for (i
= 0; i
< howmany
&& attributes
; i
++)
2183 if (attributes
[i
].flags
& XvGettable
)
2185 xv_atom
= XInternAtom(mDisplay
, attributes
[i
].name
, True
);
2186 /* since we have SET_DEFAULTS first in our list, we can check if it's available
2187 then trigger it if it's ok so that the other values are at default upon query */
2188 if (xv_atom
!= None
)
2190 int val
, port_value
= 0, port_min
, port_max
;
2192 XvGetPortAttribute(mDisplay
, xv_port
, xv_atom
,
2195 port_min
= attributes
[i
].min_value
;
2196 port_max
= attributes
[i
].max_value
;
2198 (port_value
- port_min
) * 200 / (port_max
- port_min
) -
2201 if (!strcmp(attributes
[i
].name
, "XV_BRIGHTNESS") &&
2202 (!strcasecmp(name
, "brightness")))
2204 else if (!strcmp(attributes
[i
].name
, "XV_CONTRAST") &&
2205 (!strcasecmp(name
, "contrast")))
2207 else if (!strcmp(attributes
[i
].name
, "XV_SATURATION") &&
2208 (!strcasecmp(name
, "saturation")))
2210 else if (!strcmp(attributes
[i
].name
, "XV_HUE") &&
2211 (!strcasecmp(name
, "hue")))
2213 /* nasty nvidia detect */
2214 if (port_min
== 0 && port_max
== 360)
2215 *value
= (val
>= 0) ? (val
- 100) : (val
+ 100);
2219 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
2220 if (!strcmp(attributes
[i
].name
, "XV_RED_INTENSITY") &&
2221 (!strcasecmp(name
, "red_intensity")))
2223 else if (!strcmp(attributes
[i
].name
, "XV_GREEN_INTENSITY")
2224 && (!strcasecmp(name
, "green_intensity")))
2226 else if (!strcmp(attributes
[i
].name
, "XV_BLUE_INTENSITY")
2227 && (!strcasecmp(name
, "blue_intensity")))
2232 mp_dbg(MSGT_VO
, MSGL_V
, "xv_get_eq called! (%s, %d)\n",