12 #include "x11_common.h"
21 #include "video_out.h"
25 #include "osdep/timer.h"
29 #include <X11/Xutil.h>
30 #include <X11/Xatom.h>
33 #include <X11/extensions/scrnsaver.h>
37 #include <X11/extensions/dpms.h>
40 #ifdef CONFIG_XINERAMA
41 #include <X11/extensions/Xinerama.h>
45 #include <X11/extensions/xf86vmode.h>
49 #include <X11/XF86keysym.h>
53 #include <X11/extensions/Xv.h>
54 #include <X11/extensions/Xvlib.h>
56 #include "subopt-helper.h"
59 #include "input/input.h"
60 #include "input/mouse.h"
63 #include "gui/interface.h"
67 #define WIN_LAYER_ONBOTTOM 2
68 #define WIN_LAYER_NORMAL 4
69 #define WIN_LAYER_ONTOP 6
70 #define WIN_LAYER_ABOVE_DOCK 10
72 extern int enable_mouse_movements
;
73 int fs_layer
= WIN_LAYER_ABOVE_DOCK
;
75 int stop_xscreensaver
= 0;
77 static int dpms_disabled
= 0;
79 char *mDisplayName
= NULL
;
81 char **vo_fstype_list
;
83 /* 1 means that the WM is metacity (broken as hell) */
84 int metacity_hack
= 0;
87 XF86VidModeModeInfo
**vidmodes
= NULL
;
88 XF86VidModeModeLine modeline
;
91 static int vo_x11_get_fs_type(int supported
);
92 static void saver_off(Display
*);
93 static void saver_on(Display
*);
96 * Sends the EWMH fullscreen state event.
98 * action: could be one of _NET_WM_STATE_REMOVE -- remove state
99 * _NET_WM_STATE_ADD -- add state
100 * _NET_WM_STATE_TOGGLE -- toggle
102 void vo_x11_ewmh_fullscreen(struct vo_x11_state
*x11
, int action
)
104 assert(action
== _NET_WM_STATE_REMOVE
||
105 action
== _NET_WM_STATE_ADD
|| action
== _NET_WM_STATE_TOGGLE
);
107 if (x11
->fs_type
& vo_wm_FULLSCREEN
)
111 /* init X event structure for _NET_WM_FULLSCREEN client message */
112 xev
.xclient
.type
= ClientMessage
;
113 xev
.xclient
.serial
= 0;
114 xev
.xclient
.send_event
= True
;
115 xev
.xclient
.message_type
= x11
->XA_NET_WM_STATE
;
116 xev
.xclient
.window
= x11
->window
;
117 xev
.xclient
.format
= 32;
118 xev
.xclient
.data
.l
[0] = action
;
119 xev
.xclient
.data
.l
[1] = x11
->XA_NET_WM_STATE_FULLSCREEN
;
120 xev
.xclient
.data
.l
[2] = 0;
121 xev
.xclient
.data
.l
[3] = 0;
122 xev
.xclient
.data
.l
[4] = 0;
124 /* finally send that damn thing */
125 if (!XSendEvent(x11
->display
, DefaultRootWindow(x11
->display
), False
,
126 SubstructureRedirectMask
| SubstructureNotifyMask
,
129 mp_msg(MSGT_VO
, MSGL_ERR
, MSGTR_EwmhFullscreenStateFailed
);
134 static void vo_hidecursor(Display
* disp
, Window win
)
140 const char bm_no_data
[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
143 return; // do not hide if playing on the root window
145 colormap
= DefaultColormap(disp
, DefaultScreen(disp
));
146 if ( !XAllocNamedColor(disp
, colormap
, "black", &black
, &dummy
) )
148 return; // color alloc failed, give up
150 bm_no
= XCreateBitmapFromData(disp
, win
, bm_no_data
, 8, 8);
151 no_ptr
= XCreatePixmapCursor(disp
, bm_no
, bm_no
, &black
, &black
, 0, 0);
152 XDefineCursor(disp
, win
, no_ptr
);
153 XFreeCursor(disp
, no_ptr
);
155 XFreePixmap(disp
, bm_no
);
156 XFreeColors(disp
,colormap
,&black
.pixel
,1,0);
159 static void vo_showcursor(Display
* disp
, Window win
)
163 XDefineCursor(disp
, win
, 0);
166 static int x11_errorhandler(Display
* display
, XErrorEvent
* event
)
171 XGetErrorText(display
, event
->error_code
, (char *) &msg
, MSGLEN
);
173 mp_msg(MSGT_VO
, MSGL_ERR
, "X11 error: %s\n", msg
);
175 mp_msg(MSGT_VO
, MSGL_V
,
176 "Type: %x, display: %p, resourceid: %lx, serial: %lx\n",
177 event
->type
, event
->display
, event
->resourceid
, event
->serial
);
178 mp_msg(MSGT_VO
, MSGL_V
,
179 "Error code: %x, request code: %x, minor code: %x\n",
180 event
->error_code
, event
->request_code
, event
->minor_code
);
183 //exit_player("X11 error");
188 void fstype_help(void)
190 mp_msg(MSGT_VO
, MSGL_INFO
, MSGTR_AvailableFsType
);
191 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FULL_SCREEN_TYPES\n");
193 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "none",
194 "don't set fullscreen window layer");
195 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "layer",
196 "use _WIN_LAYER hint with default layer");
197 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "layer=<0..15>",
198 "use _WIN_LAYER hint with a given layer number");
199 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "netwm",
200 "force NETWM style");
201 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "above",
202 "use _NETWM_STATE_ABOVE hint if available");
203 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "below",
204 "use _NETWM_STATE_BELOW hint if available");
205 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "fullscreen",
206 "use _NETWM_STATE_FULLSCREEN hint if availale");
207 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "stays_on_top",
208 "use _NETWM_STATE_STAYS_ON_TOP hint if available");
209 mp_msg(MSGT_VO
, MSGL_INFO
,
210 "You can also negate the settings with simply putting '-' in the beginning");
211 mp_msg(MSGT_VO
, MSGL_INFO
, "\n");
214 static void fstype_dump(int fstype
)
218 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Current fstype setting honours");
219 if (fstype
& vo_wm_LAYER
)
220 mp_msg(MSGT_VO
, MSGL_V
, " LAYER");
221 if (fstype
& vo_wm_FULLSCREEN
)
222 mp_msg(MSGT_VO
, MSGL_V
, " FULLSCREEN");
223 if (fstype
& vo_wm_STAYS_ON_TOP
)
224 mp_msg(MSGT_VO
, MSGL_V
, " STAYS_ON_TOP");
225 if (fstype
& vo_wm_ABOVE
)
226 mp_msg(MSGT_VO
, MSGL_V
, " ABOVE");
227 if (fstype
& vo_wm_BELOW
)
228 mp_msg(MSGT_VO
, MSGL_V
, " BELOW");
229 mp_msg(MSGT_VO
, MSGL_V
, " X atoms\n");
231 mp_msg(MSGT_VO
, MSGL_V
,
232 "[x11] Current fstype setting doesn't honour any X atoms\n");
235 static int net_wm_support_state_test(struct vo_x11_state
*x11
, Atom atom
)
237 #define NET_WM_STATE_TEST(x) { if (atom == x11->XA_NET_WM_STATE_##x) { mp_msg( MSGT_VO,MSGL_V, "[x11] Detected wm supports " #x " state.\n" ); return vo_wm_##x; } }
239 NET_WM_STATE_TEST(FULLSCREEN
);
240 NET_WM_STATE_TEST(ABOVE
);
241 NET_WM_STATE_TEST(STAYS_ON_TOP
);
242 NET_WM_STATE_TEST(BELOW
);
246 static int x11_get_property(struct vo_x11_state
*x11
, Atom type
, Atom
** args
,
247 unsigned long *nitems
)
250 unsigned long bytesafter
;
253 XGetWindowProperty(x11
->display
, x11
->rootwin
, type
, 0, 16384, False
,
254 AnyPropertyType
, &type
, &format
, nitems
,
255 &bytesafter
, (unsigned char **) args
)
259 static int vo_wm_detect(struct vo
*vo
)
261 struct vo_x11_state
*x11
= vo
->x11
;
264 unsigned long nitems
;
270 // -- supports layers
271 if (x11_get_property(x11
, x11
->XA_WIN_PROTOCOLS
, &args
, &nitems
))
273 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Detected wm supports layers.\n");
274 for (i
= 0; i
< nitems
; i
++)
276 if (args
[i
] == x11
->XA_WIN_LAYER
)
281 /* metacity is the only window manager I know which reports
282 * supporting only the _WIN_LAYER hint in _WIN_PROTOCOLS.
283 * (what's more support for it is broken) */
287 if (wm
&& (metacity_hack
== 1))
289 // metacity claims to support layers, but it is not the truth :-)
291 mp_msg(MSGT_VO
, MSGL_V
,
292 "[x11] Using workaround for Metacity bugs.\n");
296 if (x11_get_property(x11
, x11
->XA_NET_SUPPORTED
, &args
, &nitems
))
298 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Detected wm supports NetWM.\n");
299 for (i
= 0; i
< nitems
; i
++)
300 wm
|= net_wm_support_state_test(vo
->x11
, args
[i
]);
305 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Unknown wm type...\n");
309 #define XA_INIT(x) x11->XA##x = XInternAtom(x11->display, #x, False)
310 static void init_atoms(struct vo_x11_state
*x11
)
312 XA_INIT(_NET_SUPPORTED
);
313 XA_INIT(_NET_WM_STATE
);
314 XA_INIT(_NET_WM_STATE_FULLSCREEN
);
315 XA_INIT(_NET_WM_STATE_ABOVE
);
316 XA_INIT(_NET_WM_STATE_STAYS_ON_TOP
);
317 XA_INIT(_NET_WM_STATE_BELOW
);
318 XA_INIT(_NET_WM_PID
);
319 XA_INIT(_WIN_PROTOCOLS
);
322 XA_INIT(WM_PROTOCOLS
);
323 XA_INIT(WM_DELETE_WINDOW
);
326 void update_xinerama_info(struct vo
*vo
) {
327 struct MPOpts
*opts
= vo
->opts
;
328 int screen
= xinerama_screen
;
329 xinerama_x
= xinerama_y
= 0;
330 #ifdef CONFIG_XINERAMA
331 if (screen
>= -1 && XineramaIsActive(vo
->x11
->display
))
333 XineramaScreenInfo
*screens
;
336 screens
= XineramaQueryScreens(vo
->x11
->display
, &num_screens
);
337 if (screen
>= num_screens
)
338 screen
= num_screens
- 1;
340 int x
= vo
->dx
+ vo
->dwidth
/ 2;
341 int y
= vo
->dy
+ vo
->dheight
/ 2;
342 for (screen
= num_screens
- 1; screen
> 0; screen
--) {
343 int left
= screens
[screen
].x_org
;
344 int right
= left
+ screens
[screen
].width
;
345 int top
= screens
[screen
].y_org
;
346 int bottom
= top
+ screens
[screen
].height
;
347 if (left
<= x
&& x
<= right
&& top
<= y
&& y
<= bottom
)
353 opts
->vo_screenwidth
= screens
[screen
].width
;
354 opts
->vo_screenheight
= screens
[screen
].height
;
355 xinerama_x
= screens
[screen
].x_org
;
356 xinerama_y
= screens
[screen
].y_org
;
361 aspect_save_screenres(vo
, opts
->vo_screenwidth
, opts
->vo_screenheight
);
364 int vo_init(struct vo
*vo
)
366 struct MPOpts
*opts
= vo
->opts
;
367 struct vo_x11_state
*x11
= vo
->x11
;
372 // char * DisplayName = ":0.0";
373 // Display * mDisplay;
374 XImage
*mXImage
= NULL
;
377 XWindowAttributes attribs
;
381 WinID
= 0; // use root window
383 if (x11
->depthonscreen
)
385 saver_off(x11
->display
);
386 return 1; // already called
389 XSetErrorHandler(x11_errorhandler
);
393 if (!(mDisplayName
= getenv("DISPLAY")))
394 mDisplayName
= strdup(":0.0");
396 dispName
= XDisplayName(mDisplayName
);
399 mp_msg(MSGT_VO
, MSGL_V
, "X11 opening display: %s\n", dispName
);
401 x11
->display
= XOpenDisplay(dispName
);
404 mp_msg(MSGT_VO
, MSGL_ERR
,
405 "vo: couldn't open the X11 display (%s)!\n", dispName
);
408 x11
->screen
= DefaultScreen(x11
->display
); // screen ID
409 x11
->rootwin
= RootWindow(x11
->display
, x11
->screen
); // root window ID
417 XF86VidModeGetModeLine(x11
->display
, x11
->screen
, &clock
, &modeline
);
418 if (!opts
->vo_screenwidth
)
419 opts
->vo_screenwidth
= modeline
.hdisplay
;
420 if (!opts
->vo_screenheight
)
421 opts
->vo_screenheight
= modeline
.vdisplay
;
425 if (!opts
->vo_screenwidth
)
426 opts
->vo_screenwidth
= DisplayWidth(x11
->display
, x11
->screen
);
427 if (!opts
->vo_screenheight
)
428 opts
->vo_screenheight
= DisplayHeight(x11
->display
, x11
->screen
);
430 // get color depth (from root window, or the best visual):
431 XGetWindowAttributes(x11
->display
, x11
->rootwin
, &attribs
);
432 depth
= attribs
.depth
;
434 if (depth
!= 15 && depth
!= 16 && depth
!= 24 && depth
!= 32)
438 depth
= vo_find_depth_from_visuals(x11
->display
, x11
->screen
, &visual
);
440 mXImage
= XCreateImage(x11
->display
, visual
, depth
, ZPixmap
,
441 0, NULL
, 1, 1, 8, 1);
444 XGetImage(x11
->display
, x11
->rootwin
, 0, 0, 1, 1, AllPlanes
, ZPixmap
);
446 x11
->depthonscreen
= depth
; // display depth on screen
448 // get bits/pixel from XImage structure:
455 * for the depth==24 case, the XImage structures might use
456 * 24 or 32 bits of data per pixel. The x11->depthonscreen
457 * field stores the amount of data per pixel in the
460 * Maybe we should rename vo_depthonscreen to (or add) vo_bpp?
462 bpp
= mXImage
->bits_per_pixel
;
463 if ((x11
->depthonscreen
+ 7) / 8 != (bpp
+ 7) / 8)
464 x11
->depthonscreen
= bpp
; // by A'rpi
466 mXImage
->red_mask
| mXImage
->green_mask
| mXImage
->blue_mask
;
467 mp_msg(MSGT_VO
, MSGL_V
,
468 "vo: X11 color mask: %X (R:%lX G:%lX B:%lX)\n", mask
,
469 mXImage
->red_mask
, mXImage
->green_mask
, mXImage
->blue_mask
);
470 XDestroyImage(mXImage
);
472 if (((x11
->depthonscreen
+ 7) / 8) == 2)
475 x11
->depthonscreen
= 15;
476 else if (mask
== 0xFFFF)
477 x11
->depthonscreen
= 16;
479 // XCloseDisplay( mDisplay );
480 /* slightly improved local display detection AST */
481 if (strncmp(dispName
, "unix:", 5) == 0)
483 else if (strncmp(dispName
, "localhost:", 10) == 0)
485 if (*dispName
== ':' && atoi(dispName
+ 1) < 10)
486 x11
->display_is_local
= 1;
488 x11
->display_is_local
= 0;
489 mp_msg(MSGT_VO
, MSGL_V
,
490 "vo: X11 running at %dx%d with depth %d and %d bpp (\"%s\" => %s display)\n",
491 opts
->vo_screenwidth
, opts
->vo_screenheight
, depth
, x11
->depthonscreen
,
492 dispName
, x11
->display_is_local
? "local" : "remote");
494 x11
->wm_type
= vo_wm_detect(vo
);
496 x11
->fs_type
= vo_x11_get_fs_type(x11
->wm_type
);
498 fstype_dump(x11
->fs_type
);
500 saver_off(x11
->display
);
504 void vo_uninit(struct vo_x11_state
*x11
)
508 mp_msg(MSGT_VO
, MSGL_V
,
509 "vo: x11 uninit called but X11 not initialized..\n");
512 // if( !vo_depthonscreen ) return;
513 mp_msg(MSGT_VO
, MSGL_V
, "vo: uninit ...\n");
514 XSetErrorHandler(NULL
);
515 XCloseDisplay(x11
->display
);
516 x11
->depthonscreen
= 0;
521 #include "osdep/keycodes.h"
524 #ifdef XF86XK_AudioPause
525 static void vo_x11_putkey_ext(struct vo
*vo
, int keysym
)
527 struct mp_fifo
*f
= vo
->key_fifo
;
531 mplayer_put_key(f
, KEY_MENU
);
533 case XF86XK_AudioPlay
:
534 mplayer_put_key(f
, KEY_PLAY
);
536 case XF86XK_AudioPause
:
537 mplayer_put_key(f
, KEY_PAUSE
);
539 case XF86XK_AudioStop
:
540 mplayer_put_key(f
, KEY_STOP
);
542 case XF86XK_AudioPrev
:
543 mplayer_put_key(f
, KEY_PREV
);
545 case XF86XK_AudioNext
:
546 mplayer_put_key(f
, KEY_NEXT
);
548 case XF86XK_AudioMute
:
549 mplayer_put_key(f
, KEY_MUTE
);
551 case XF86XK_AudioLowerVolume
:
552 mplayer_put_key(f
, KEY_VOLUME_DOWN
);
554 case XF86XK_AudioRaiseVolume
:
555 mplayer_put_key(f
, KEY_VOLUME_UP
);
563 void vo_x11_putkey(struct vo
*vo
, int key
)
565 struct mp_fifo
*f
= vo
->key_fifo
;
569 mplayer_put_key(f
, KEY_LEFT
);
572 mplayer_put_key(f
, KEY_RIGHT
);
575 mplayer_put_key(f
, KEY_UP
);
578 mplayer_put_key(f
, KEY_DOWN
);
581 mplayer_put_key(f
, ' ');
584 mplayer_put_key(f
, KEY_ESC
);
587 mplayer_put_key(f
, KEY_TAB
);
590 mplayer_put_key(f
, KEY_ENTER
);
593 mplayer_put_key(f
, KEY_BS
);
596 mplayer_put_key(f
, KEY_DELETE
);
599 mplayer_put_key(f
, KEY_INSERT
);
602 mplayer_put_key(f
, KEY_HOME
);
605 mplayer_put_key(f
, KEY_END
);
608 mplayer_put_key(f
, KEY_PAGE_UP
);
611 mplayer_put_key(f
, KEY_PAGE_DOWN
);
614 mplayer_put_key(f
, KEY_F
+ 1);
617 mplayer_put_key(f
, KEY_F
+ 2);
620 mplayer_put_key(f
, KEY_F
+ 3);
623 mplayer_put_key(f
, KEY_F
+ 4);
626 mplayer_put_key(f
, KEY_F
+ 5);
629 mplayer_put_key(f
, KEY_F
+ 6);
632 mplayer_put_key(f
, KEY_F
+ 7);
635 mplayer_put_key(f
, KEY_F
+ 8);
638 mplayer_put_key(f
, KEY_F
+ 9);
641 mplayer_put_key(f
, KEY_F
+ 10);
644 mplayer_put_key(f
, KEY_F
+ 11);
647 mplayer_put_key(f
, KEY_F
+ 12);
651 mplayer_put_key(f
, '-');
655 mplayer_put_key(f
, '+');
659 mplayer_put_key(f
, '*');
663 mplayer_put_key(f
, '/');
666 mplayer_put_key(f
, '<');
669 mplayer_put_key(f
, '>');
672 mplayer_put_key(f
, KEY_KP0
);
676 mplayer_put_key(f
, KEY_KP1
);
680 mplayer_put_key(f
, KEY_KP2
);
684 mplayer_put_key(f
, KEY_KP3
);
688 mplayer_put_key(f
, KEY_KP4
);
692 mplayer_put_key(f
, KEY_KP5
);
696 mplayer_put_key(f
, KEY_KP6
);
700 mplayer_put_key(f
, KEY_KP7
);
704 mplayer_put_key(f
, KEY_KP8
);
708 mplayer_put_key(f
, KEY_KP9
);
711 mplayer_put_key(f
, KEY_KPDEC
);
714 mplayer_put_key(f
, KEY_KPINS
);
717 mplayer_put_key(f
, KEY_KPDEL
);
720 mplayer_put_key(f
, KEY_KPENTER
);
723 mplayer_put_key(f
, '`');
726 mplayer_put_key(f
, '~');
729 mplayer_put_key(f
, '!');
732 mplayer_put_key(f
, '@');
735 mplayer_put_key(f
, '#');
738 mplayer_put_key(f
, '$');
741 mplayer_put_key(f
, '%');
744 mplayer_put_key(f
, '^');
747 mplayer_put_key(f
, '&');
750 mplayer_put_key(f
, '(');
753 mplayer_put_key(f
, ')');
756 mplayer_put_key(f
, '_');
759 mplayer_put_key(f
, '{');
762 mplayer_put_key(f
, '}');
765 mplayer_put_key(f
, ':');
768 mplayer_put_key(f
, ';');
771 mplayer_put_key(f
, '\"');
774 mplayer_put_key(f
, '\'');
777 mplayer_put_key(f
, ',');
780 mplayer_put_key(f
, '.');
783 mplayer_put_key(f
, '?');
786 mplayer_put_key(f
, '\\');
789 mplayer_put_key(f
, '|');
792 mplayer_put_key(f
, '=');
795 mplayer_put_key(f
, '[');
798 mplayer_put_key(f
, ']');
803 if ((key
>= 'a' && key
<= 'z') || (key
>= 'A' && key
<= 'Z') ||
804 (key
>= '0' && key
<= '9'))
805 mplayer_put_key(f
, key
);
811 // ----- Motif header: -------
813 #define MWM_HINTS_FUNCTIONS (1L << 0)
814 #define MWM_HINTS_DECORATIONS (1L << 1)
815 #define MWM_HINTS_INPUT_MODE (1L << 2)
816 #define MWM_HINTS_STATUS (1L << 3)
818 #define MWM_FUNC_ALL (1L << 0)
819 #define MWM_FUNC_RESIZE (1L << 1)
820 #define MWM_FUNC_MOVE (1L << 2)
821 #define MWM_FUNC_MINIMIZE (1L << 3)
822 #define MWM_FUNC_MAXIMIZE (1L << 4)
823 #define MWM_FUNC_CLOSE (1L << 5)
825 #define MWM_DECOR_ALL (1L << 0)
826 #define MWM_DECOR_BORDER (1L << 1)
827 #define MWM_DECOR_RESIZEH (1L << 2)
828 #define MWM_DECOR_TITLE (1L << 3)
829 #define MWM_DECOR_MENU (1L << 4)
830 #define MWM_DECOR_MINIMIZE (1L << 5)
831 #define MWM_DECOR_MAXIMIZE (1L << 6)
833 #define MWM_INPUT_MODELESS 0
834 #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
835 #define MWM_INPUT_SYSTEM_MODAL 2
836 #define MWM_INPUT_FULL_APPLICATION_MODAL 3
837 #define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL
839 #define MWM_TEAROFF_WINDOW (1L<<0)
850 static MotifWmHints vo_MotifWmHints
;
851 static Atom vo_MotifHints
= None
;
853 void vo_x11_decoration(struct vo
*vo
, int d
)
855 struct vo_x11_state
*x11
= vo
->x11
;
858 unsigned long mn
, mb
;
865 XSetTransientForHint(x11
->display
, x11
->window
,
866 RootWindow(x11
->display
, x11
->screen
));
869 vo_MotifHints
= XInternAtom(x11
->display
, "_MOTIF_WM_HINTS", 0);
870 if (vo_MotifHints
!= None
)
874 MotifWmHints
*mhints
= NULL
;
876 XGetWindowProperty(x11
->display
, x11
->window
,
877 vo_MotifHints
, 0, 20, False
,
878 vo_MotifHints
, &mtype
, &mformat
, &mn
,
879 &mb
, (unsigned char **) &mhints
);
882 if (mhints
->flags
& MWM_HINTS_DECORATIONS
)
883 x11
->olddecor
= mhints
->decorations
;
884 if (mhints
->flags
& MWM_HINTS_FUNCTIONS
)
885 x11
->oldfuncs
= mhints
->functions
;
890 memset(&vo_MotifWmHints
, 0, sizeof(MotifWmHints
));
891 vo_MotifWmHints
.flags
=
892 MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
895 vo_MotifWmHints
.functions
= x11
->oldfuncs
;
899 vo_MotifWmHints
.decorations
=
900 d
| ((vo_fsmode
& 2) ? 0 : MWM_DECOR_MENU
);
902 vo_MotifWmHints
.decorations
=
903 d
| ((vo_fsmode
& 2) ? MWM_DECOR_MENU
: 0);
905 XChangeProperty(x11
->display
, x11
->window
, vo_MotifHints
,
908 (unsigned char *) &vo_MotifWmHints
,
909 (vo_fsmode
& 4) ? 4 : 5);
913 void vo_x11_classhint(struct vo
*vo
, Window window
, char *name
)
915 struct vo_x11_state
*x11
= vo
->x11
;
917 pid_t pid
= getpid();
919 wmClass
.res_name
= name
;
920 wmClass
.res_class
= "MPlayer";
921 XSetClassHint(x11
->display
, window
, &wmClass
);
922 XChangeProperty(x11
->display
, window
, x11
->XA_NET_WM_PID
, XA_CARDINAL
,
923 32, PropModeReplace
, (unsigned char *) &pid
, 1);
926 void vo_x11_uninit(struct vo
*vo
)
928 struct vo_x11_state
*x11
= vo
->x11
;
929 saver_on(x11
->display
);
930 if (x11
->window
!= None
)
931 vo_showcursor(x11
->display
, x11
->window
);
935 XFreeGC(vo
->x11
->display
, x11
->f_gc
);
939 /* destroy window only if it's not controlled by the GUI */
945 XSetBackground(vo
->x11
->display
, x11
->vo_gc
, 0);
946 XFreeGC(vo
->x11
->display
, x11
->vo_gc
);
949 if (x11
->window
!= None
)
951 XClearWindow(x11
->display
, x11
->window
);
956 XUnmapWindow(x11
->display
, x11
->window
);
957 XDestroyWindow(x11
->display
, x11
->window
);
960 XNextEvent(x11
->display
, &xev
);
962 while (xev
.type
!= DestroyNotify
963 || xev
.xdestroywindow
.event
!= x11
->window
);
968 x11
->vo_old_width
= x11
->vo_old_height
= 0;
972 int vo_x11_check_events(struct vo
*vo
)
974 struct vo_x11_state
*x11
= vo
->x11
;
975 struct MPOpts
*opts
= vo
->opts
;
976 Display
*display
= vo
->x11
->display
;
982 // unsigned long vo_KeyTable[512];
984 if ((x11
->vo_mouse_autohide
) && x11
->mouse_waiting_hide
&&
985 (GetTimerMS() - x11
->mouse_timer
>= 1000)) {
986 vo_hidecursor(display
, x11
->window
);
987 x11
->mouse_waiting_hide
= 0;
990 while (XPending(display
))
992 XNextEvent(display
, &Event
);
996 guiGetEvent(0, (char *) &Event
);
997 if (x11
->window
!= Event
.xany
.window
)
1001 // printf("\rEvent.type=%X \n",Event.type);
1005 ret
|= VO_EVENT_EXPOSE
;
1007 case ConfigureNotify
:
1008 // if (!vo_fs && (Event.xconfigure.width == opts->vo_screenwidth || Event.xconfigure.height == opts->vo_screenheight)) break;
1009 // if (vo_fs && Event.xconfigure.width != opts->vo_screenwidth && Event.xconfigure.height != opts->vo_screenheight) break;
1010 if (x11
->window
== None
)
1012 vo_x11_update_geometry(vo
);
1013 ret
|= VO_EVENT_RESIZE
;
1020 if ( use_gui
) { break; }
1023 XLookupString(&Event
.xkey
, buf
, sizeof(buf
), &keySym
,
1024 &x11
->compose_status
);
1025 #ifdef XF86XK_AudioPause
1026 vo_x11_putkey_ext(vo
, keySym
);
1029 ((keySym
& 0xff00) !=
1030 0 ? ((keySym
& 0x00ff) + 256) : (keySym
));
1031 vo_x11_putkey(vo
, key
);
1032 ret
|= VO_EVENT_KEYPRESS
;
1036 if(enable_mouse_movements
)
1039 sprintf(cmd_str
,"set_mouse_pos %i %i",Event
.xmotion
.x
, Event
.xmotion
.y
);
1040 mp_input_queue_cmd(vo
->input_ctx
,
1041 mp_input_parse_cmd(cmd_str
));
1044 if (x11
->vo_mouse_autohide
)
1046 vo_showcursor(display
, x11
->window
);
1047 x11
->mouse_waiting_hide
= 1;
1048 x11
->mouse_timer
= GetTimerMS();
1052 if (x11
->vo_mouse_autohide
)
1054 vo_showcursor(display
, x11
->window
);
1055 x11
->mouse_waiting_hide
= 1;
1056 x11
->mouse_timer
= GetTimerMS();
1059 // Ignore mouse button 1-3 under GUI.
1060 if (use_gui
&& (Event
.xbutton
.button
>= 1)
1061 && (Event
.xbutton
.button
<= 3))
1064 mplayer_put_key(vo
->key_fifo
,
1065 (MOUSE_BTN0
+ Event
.xbutton
.button
- 1)
1069 if (x11
->vo_mouse_autohide
)
1071 vo_showcursor(display
, x11
->window
);
1072 x11
->mouse_waiting_hide
= 1;
1073 x11
->mouse_timer
= GetTimerMS();
1076 // Ignore mouse button 1-3 under GUI.
1077 if (use_gui
&& (Event
.xbutton
.button
>= 1)
1078 && (Event
.xbutton
.button
<= 3))
1081 mplayer_put_key(vo
->key_fifo
,
1082 MOUSE_BTN0
+ Event
.xbutton
.button
- 1);
1084 case PropertyNotify
:
1087 XGetAtomName(display
, Event
.xproperty
.atom
);
1092 // fprintf(stderr,"[ws] PropertyNotify ( 0x%x ) %s ( 0x%x )\n",vo_window,name,Event.xproperty.atom );
1098 x11
->vo_hint
.win_gravity
= x11
->old_gravity
;
1099 XSetWMNormalHints(display
, x11
->window
, &x11
->vo_hint
);
1103 if (Event
.xclient
.message_type
== x11
->XAWM_PROTOCOLS
&&
1104 Event
.xclient
.data
.l
[0] == x11
->XAWM_DELETE_WINDOW
)
1105 mplayer_put_key(vo
->key_fifo
, KEY_CLOSE_WIN
);
1113 * \brief sets the size and position of the non-fullscreen window.
1115 static void vo_x11_nofs_sizepos(struct vo
*vo
, int x
, int y
,
1116 int width
, int height
)
1118 struct vo_x11_state
*x11
= vo
->x11
;
1119 vo_x11_sizehint(vo
, x
, y
, width
, height
, 0);
1123 x11
->vo_old_width
= width
;
1124 x11
->vo_old_height
= height
;
1129 vo
->dheight
= height
;
1130 XMoveResizeWindow(vo
->x11
->display
, vo
->x11
->window
, x
, y
, width
, height
);
1134 void vo_x11_sizehint(struct vo
*vo
, int x
, int y
, int width
, int height
, int max
)
1136 struct vo_x11_state
*x11
= vo
->x11
;
1137 x11
->vo_hint
.flags
= 0;
1140 x11
->vo_hint
.flags
|= PAspect
;
1141 x11
->vo_hint
.min_aspect
.x
= width
;
1142 x11
->vo_hint
.min_aspect
.y
= height
;
1143 x11
->vo_hint
.max_aspect
.x
= width
;
1144 x11
->vo_hint
.max_aspect
.y
= height
;
1147 x11
->vo_hint
.flags
|= PPosition
| PSize
;
1150 x11
->vo_hint
.width
= width
;
1151 x11
->vo_hint
.height
= height
;
1154 x11
->vo_hint
.flags
|= PMaxSize
;
1155 x11
->vo_hint
.max_width
= width
;
1156 x11
->vo_hint
.max_height
= height
;
1159 x11
->vo_hint
.max_width
= 0;
1160 x11
->vo_hint
.max_height
= 0;
1163 // Set minimum height/width to 4 to avoid off-by-one errors
1164 // and because mga_vid requires a minimal size of 4 pixels.
1165 x11
->vo_hint
.flags
|= PMinSize
;
1166 x11
->vo_hint
.min_width
= x11
->vo_hint
.min_height
= 4;
1168 x11
->vo_hint
.flags
|= PWinGravity
;
1169 x11
->vo_hint
.win_gravity
= StaticGravity
;
1170 XSetWMNormalHints(x11
->display
, x11
->window
, &x11
->vo_hint
);
1173 static int vo_x11_get_gnome_layer(struct vo_x11_state
*x11
, Window win
)
1177 unsigned long nitems
;
1178 unsigned long bytesafter
;
1179 unsigned short *args
= NULL
;
1181 if (XGetWindowProperty(x11
->display
, win
, x11
->XA_WIN_LAYER
, 0, 16384,
1182 False
, AnyPropertyType
, &type
, &format
, &nitems
,
1184 (unsigned char **) &args
) == Success
1185 && nitems
> 0 && args
)
1187 mp_msg(MSGT_VO
, MSGL_V
, "[x11] original window layer is %d.\n",
1191 return WIN_LAYER_NORMAL
;
1195 static Window
vo_x11_create_smooth_window(struct vo_x11_state
*x11
, Window mRoot
,
1196 Visual
* vis
, int x
, int y
,
1197 unsigned int width
, unsigned int height
,
1198 int depth
, Colormap col_map
)
1200 unsigned long xswamask
= CWBorderPixel
;
1201 XSetWindowAttributes xswa
;
1204 if (col_map
!= CopyFromParent
)
1206 xswa
.colormap
= col_map
;
1207 xswamask
|= CWColormap
;
1209 xswa
.background_pixel
= 0;
1210 xswa
.border_pixel
= 0;
1211 xswa
.backing_store
= NotUseful
;
1212 xswa
.bit_gravity
= StaticGravity
;
1215 XCreateWindow(x11
->display
, x11
->rootwin
, x
, y
, width
, height
, 0, depth
,
1216 CopyFromParent
, vis
, xswamask
, &xswa
);
1217 XSetWMProtocols(x11
->display
, ret_win
, &x11
->XAWM_DELETE_WINDOW
, 1);
1219 x11
->f_gc
= XCreateGC(x11
->display
, ret_win
, 0, 0);
1220 XSetForeground(x11
->display
, x11
->f_gc
, 0);
1226 * \brief create and setup a window suitable for display
1227 * \param vis Visual to use for creating the window
1228 * \param x x position of window
1229 * \param y y position of window
1230 * \param width width of window
1231 * \param height height of window
1232 * \param flags flags for window creation.
1233 * Only VOFLAG_FULLSCREEN is supported so far.
1234 * \param col_map Colourmap for window or CopyFromParent if a specific colormap isn't needed
1235 * \param classname name to use for the classhint
1236 * \param title title for the window
1238 * This also does the grunt-work like setting Window Manager hints etc.
1239 * If vo_window is already set it just moves and resizes it.
1241 void vo_x11_create_vo_window(struct vo
*vo
, XVisualInfo
*vis
, int x
, int y
,
1242 unsigned int width
, unsigned int height
, int flags
,
1244 const char *classname
, const char *title
)
1246 struct MPOpts
*opts
= vo
->opts
;
1247 struct vo_x11_state
*x11
= vo
->x11
;
1248 Display
*mDisplay
= vo
->x11
->display
;
1251 x11
->window
= WinID
? (Window
)WinID
: x11
->rootwin
;
1252 if (col_map
!= CopyFromParent
) {
1253 unsigned long xswamask
= CWColormap
;
1254 XSetWindowAttributes xswa
;
1255 xswa
.colormap
= col_map
;
1256 XUnmapWindow(mDisplay
, x11
->window
);
1257 XChangeWindowAttributes(mDisplay
, x11
->window
, xswamask
, &xswa
);
1258 XMapWindow(mDisplay
, x11
->window
);
1260 if (WinID
) vo_x11_update_geometry(vo
);
1261 vo_x11_selectinput_witherr(mDisplay
, x11
->window
,
1262 StructureNotifyMask
| KeyPressMask
| PointerMotionMask
|
1263 ButtonPressMask
| ButtonReleaseMask
| ExposureMask
);
1266 if (x11
->window
== None
) {
1271 vo
->dheight
= height
;
1272 x11
->window
= vo_x11_create_smooth_window(x11
, x11
->rootwin
, vis
->visual
,
1273 x
, y
, width
, height
, vis
->depth
, col_map
);
1274 vo_x11_classhint(vo
, x11
->window
, classname
);
1275 XStoreName(mDisplay
, x11
->window
, title
);
1276 vo_hidecursor(mDisplay
, x11
->window
);
1277 XSelectInput(mDisplay
, x11
->window
, StructureNotifyMask
);
1278 hint
.x
= x
; hint
.y
= y
;
1279 hint
.width
= width
; hint
.height
= height
;
1280 hint
.flags
= PPosition
| PSize
;
1281 XSetStandardProperties(mDisplay
, x11
->window
, title
, title
, None
, NULL
, 0, &hint
);
1282 vo_x11_sizehint(vo
, x
, y
, width
, height
, 0);
1283 if (!vo_border
) vo_x11_decoration(vo
, 0);
1285 XMapWindow(mDisplay
, x11
->window
);
1286 XClearWindow(mDisplay
, x11
->window
);
1289 XNextEvent(mDisplay
, &xev
);
1290 } while (xev
.type
!= MapNotify
|| xev
.xmap
.event
!= x11
->window
);
1291 XSelectInput(mDisplay
, x11
->window
, NoEventMask
);
1292 XSync(mDisplay
, False
);
1293 vo_x11_selectinput_witherr(mDisplay
, x11
->window
,
1294 StructureNotifyMask
| KeyPressMask
| PointerMotionMask
|
1295 ButtonPressMask
| ButtonReleaseMask
| ExposureMask
);
1297 if (opts
->vo_ontop
) vo_x11_setlayer(vo
, x11
->window
, opts
->vo_ontop
);
1298 vo_x11_nofs_sizepos(vo
, vo
->dx
, vo
->dy
, width
, height
);
1299 if (!!vo_fs
!= !!(flags
& VOFLAG_FULLSCREEN
))
1300 vo_x11_fullscreen(vo
);
1302 if (x11
->vo_gc
!= None
)
1303 XFreeGC(mDisplay
, x11
->vo_gc
);
1304 x11
->vo_gc
= XCreateGC(mDisplay
, x11
->window
, GCForeground
, &xgcv
);
1305 XSync(mDisplay
, False
);
1306 x11
->vo_mouse_autohide
= 1;
1309 void vo_x11_clearwindow_part(struct vo
*vo
, Window vo_window
,
1310 int img_width
, int img_height
, int use_fs
)
1312 struct vo_x11_state
*x11
= vo
->x11
;
1313 struct MPOpts
*opts
= vo
->opts
;
1314 Display
*mDisplay
= vo
->x11
->display
;
1315 int u_dheight
, u_dwidth
, left_ov
, left_ov2
;
1320 u_dheight
= use_fs
? opts
->vo_screenheight
: vo
->dheight
;
1321 u_dwidth
= use_fs
? opts
->vo_screenwidth
: vo
->dwidth
;
1322 if ((u_dheight
<= img_height
) && (u_dwidth
<= img_width
))
1325 left_ov
= (u_dheight
- img_height
) / 2;
1326 left_ov2
= (u_dwidth
- img_width
) / 2;
1328 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, 0, 0, u_dwidth
, left_ov
);
1329 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, 0, u_dheight
- left_ov
- 1,
1330 u_dwidth
, left_ov
+ 1);
1332 if (u_dwidth
> img_width
)
1334 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, 0, left_ov
, left_ov2
,
1336 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, u_dwidth
- left_ov2
- 1,
1337 left_ov
, left_ov2
+ 1, img_height
);
1343 void vo_x11_clearwindow(struct vo
*vo
, Window vo_window
)
1345 struct vo_x11_state
*x11
= vo
->x11
;
1346 struct MPOpts
*opts
= vo
->opts
;
1349 XFillRectangle(x11
->display
, vo_window
, x11
->f_gc
, 0, 0,
1350 opts
->vo_screenwidth
, opts
->vo_screenheight
);
1352 XFlush(x11
->display
);
1356 void vo_x11_setlayer(struct vo
*vo
, Window vo_window
, int layer
)
1358 struct vo_x11_state
*x11
= vo
->x11
;
1362 if (x11
->fs_type
& vo_wm_LAYER
)
1364 XClientMessageEvent xev
;
1366 if (!x11
->orig_layer
)
1367 x11
->orig_layer
= vo_x11_get_gnome_layer(x11
, vo_window
);
1369 memset(&xev
, 0, sizeof(xev
));
1370 xev
.type
= ClientMessage
;
1371 xev
.display
= x11
->display
;
1372 xev
.window
= vo_window
;
1373 xev
.message_type
= x11
->XA_WIN_LAYER
;
1375 xev
.data
.l
[0] = layer
? fs_layer
: x11
->orig_layer
; // if not fullscreen, stay on default layer
1376 xev
.data
.l
[1] = CurrentTime
;
1377 mp_msg(MSGT_VO
, MSGL_V
,
1378 "[x11] Layered style stay on top (layer %ld).\n",
1380 XSendEvent(x11
->display
, x11
->rootwin
, False
, SubstructureNotifyMask
,
1382 } else if (x11
->fs_type
& vo_wm_NETWM
)
1384 XClientMessageEvent xev
;
1387 memset(&xev
, 0, sizeof(xev
));
1388 xev
.type
= ClientMessage
;
1389 xev
.message_type
= x11
->XA_NET_WM_STATE
;
1390 xev
.display
= x11
->display
;
1391 xev
.window
= vo_window
;
1393 xev
.data
.l
[0] = layer
;
1395 if (x11
->fs_type
& vo_wm_STAYS_ON_TOP
)
1396 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_STAYS_ON_TOP
;
1397 else if (x11
->fs_type
& vo_wm_ABOVE
)
1398 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_ABOVE
;
1399 else if (x11
->fs_type
& vo_wm_FULLSCREEN
)
1400 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_FULLSCREEN
;
1401 else if (x11
->fs_type
& vo_wm_BELOW
)
1402 // This is not fallback. We can safely assume that the situation
1403 // where only NETWM_STATE_BELOW is supported doesn't exist.
1404 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_BELOW
;
1406 XSendEvent(x11
->display
, x11
->rootwin
, False
, SubstructureRedirectMask
,
1408 state
= XGetAtomName(x11
->display
, xev
.data
.l
[1]);
1409 mp_msg(MSGT_VO
, MSGL_V
,
1410 "[x11] NET style stay on top (layer %d). Using state %s.\n",
1416 static int vo_x11_get_fs_type(int supported
)
1419 int type
= supported
;
1424 for (i
= 0; vo_fstype_list
[i
]; i
++)
1427 char *arg
= vo_fstype_list
[i
];
1429 if (vo_fstype_list
[i
][0] == '-')
1432 arg
= vo_fstype_list
[i
] + 1;
1435 if (!strncmp(arg
, "layer", 5))
1437 if (!neg
&& (arg
[5] == '='))
1439 char *endptr
= NULL
;
1440 int layer
= strtol(vo_fstype_list
[i
] + 6, &endptr
, 10);
1442 if (endptr
&& *endptr
== '\0' && layer
>= 0
1447 type
&= ~vo_wm_LAYER
;
1449 type
|= vo_wm_LAYER
;
1450 } else if (!strcmp(arg
, "above"))
1453 type
&= ~vo_wm_ABOVE
;
1455 type
|= vo_wm_ABOVE
;
1456 } else if (!strcmp(arg
, "fullscreen"))
1459 type
&= ~vo_wm_FULLSCREEN
;
1461 type
|= vo_wm_FULLSCREEN
;
1462 } else if (!strcmp(arg
, "stays_on_top"))
1465 type
&= ~vo_wm_STAYS_ON_TOP
;
1467 type
|= vo_wm_STAYS_ON_TOP
;
1468 } else if (!strcmp(arg
, "below"))
1471 type
&= ~vo_wm_BELOW
;
1473 type
|= vo_wm_BELOW
;
1474 } else if (!strcmp(arg
, "netwm"))
1477 type
&= ~vo_wm_NETWM
;
1479 type
|= vo_wm_NETWM
;
1480 } else if (!strcmp(arg
, "none"))
1489 * \brief update vo->dx, vo->dy, vo->dwidth and vo->dheight with current values of vo->x11->window
1490 * \return returns current color depth of vo->x11->window
1492 int vo_x11_update_geometry(struct vo
*vo
)
1494 struct vo_x11_state
*x11
= vo
->x11
;
1495 unsigned depth
, w
, h
;
1498 XGetGeometry(x11
->display
, x11
->window
, &dummy_win
, &dummy_int
, &dummy_int
,
1499 &w
, &h
, &dummy_int
, &depth
);
1500 if (w
<= INT_MAX
&& h
<= INT_MAX
) {
1504 XTranslateCoordinates(x11
->display
, x11
->window
, x11
->rootwin
, 0, 0,
1505 &vo
->dx
, &vo
->dy
, &dummy_win
);
1506 return depth
<= INT_MAX
? depth
: 0;
1509 void vo_x11_fullscreen(struct vo
*vo
)
1511 struct MPOpts
*opts
= vo
->opts
;
1512 struct vo_x11_state
*x11
= vo
->x11
;
1515 if (WinID
>= 0 || x11
->fs_flip
)
1521 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1525 w
= x11
->vo_old_width
;
1526 h
= x11
->vo_old_height
;
1529 vo_x11_ewmh_fullscreen(x11
, _NET_WM_STATE_REMOVE
); // removes fullscreen state if wm supports EWMH
1534 vo_x11_ewmh_fullscreen(x11
, _NET_WM_STATE_ADD
); // sends fullscreen state to be added if wm supports EWMH
1537 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1539 x11
->vo_old_x
= vo
->dx
;
1540 x11
->vo_old_y
= vo
->dy
;
1541 x11
->vo_old_width
= vo
->dwidth
;
1542 x11
->vo_old_height
= vo
->dheight
;
1544 update_xinerama_info(vo
);
1547 w
= opts
->vo_screenwidth
;
1548 h
= opts
->vo_screenheight
;
1553 XGetWMNormalHints(x11
->display
, x11
->window
, &x11
->vo_hint
, &dummy
);
1554 if (!(x11
->vo_hint
.flags
& PWinGravity
))
1555 x11
->old_gravity
= NorthWestGravity
;
1557 x11
->old_gravity
= x11
->vo_hint
.win_gravity
;
1559 if (x11
->wm_type
== 0 && !(vo_fsmode
& 16))
1561 XUnmapWindow(x11
->display
, x11
->window
); // required for MWM
1562 XWithdrawWindow(x11
->display
, x11
->window
, x11
->screen
);
1566 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1568 vo_x11_decoration(vo
, vo_border
&& !vo_fs
);
1569 vo_x11_sizehint(vo
, x
, y
, w
, h
, 0);
1570 vo_x11_setlayer(vo
, x11
->window
, vo_fs
);
1573 XMoveResizeWindow(x11
->display
, x11
->window
, x
, y
, w
, h
);
1575 /* some WMs lose ontop after fullscreen */
1576 if ((!(vo_fs
)) & opts
->vo_ontop
)
1577 vo_x11_setlayer(vo
, x11
->window
, opts
->vo_ontop
);
1579 XMapRaised(x11
->display
, x11
->window
);
1580 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // some WMs change window pos on map
1581 XMoveResizeWindow(x11
->display
, x11
->window
, x
, y
, w
, h
);
1582 XRaiseWindow(x11
->display
, x11
->window
);
1583 XFlush(x11
->display
);
1586 void vo_x11_ontop(struct vo
*vo
)
1588 struct MPOpts
*opts
= vo
->opts
;
1589 opts
->vo_ontop
= !opts
->vo_ontop
;
1591 vo_x11_setlayer(vo
, vo
->x11
->window
, opts
->vo_ontop
);
1594 void vo_x11_border(struct vo
*vo
)
1596 vo_border
= !vo_border
;
1597 vo_x11_decoration(vo
, vo_border
&& !vo_fs
);
1601 * XScreensaver stuff
1604 static int screensaver_off
;
1605 static unsigned int time_last
;
1607 void xscreensaver_heartbeat(struct vo_x11_state
*x11
)
1609 unsigned int time
= GetTimerMS();
1611 if (x11
->display
&& screensaver_off
&& (time
- time_last
) > 30000)
1615 XResetScreenSaver(x11
->display
);
1619 static int xss_suspend(Display
*mDisplay
, Bool suspend
)
1624 int event
, error
, major
, minor
;
1625 if (XScreenSaverQueryExtension(mDisplay
, &event
, &error
) != True
||
1626 XScreenSaverQueryVersion(mDisplay
, &major
, &minor
) != True
)
1628 if (major
< 1 || (major
== 1 && minor
< 1))
1630 XScreenSaverSuspend(mDisplay
, suspend
);
1636 * End of XScreensaver stuff
1639 static void saver_on(Display
* mDisplay
)
1642 if (!screensaver_off
)
1644 screensaver_off
= 0;
1645 if (xss_suspend(mDisplay
, False
))
1651 if (DPMSQueryExtension(mDisplay
, ¬hing
, ¬hing
))
1653 if (!DPMSEnable(mDisplay
))
1654 { // restoring power saving settings
1655 mp_msg(MSGT_VO
, MSGL_WARN
, "DPMS not available?\n");
1658 // DPMS does not seem to be enabled unless we call DPMSInfo
1662 DPMSForceLevel(mDisplay
, DPMSModeOn
);
1663 DPMSInfo(mDisplay
, &state
, &onoff
);
1666 mp_msg(MSGT_VO
, MSGL_V
,
1667 "Successfully enabled DPMS\n");
1670 mp_msg(MSGT_VO
, MSGL_WARN
, "Could not enable DPMS\n");
1679 static void saver_off(Display
* mDisplay
)
1683 if (screensaver_off
)
1685 screensaver_off
= 1;
1686 if (xss_suspend(mDisplay
, True
))
1689 if (DPMSQueryExtension(mDisplay
, ¬hing
, ¬hing
))
1694 DPMSInfo(mDisplay
, &state
, &onoff
);
1699 mp_msg(MSGT_VO
, MSGL_V
, "Disabling DPMS\n");
1701 stat
= DPMSDisable(mDisplay
); // monitor powersave off
1702 mp_msg(MSGT_VO
, MSGL_V
, "DPMSDisable stat: %d\n", stat
);
1708 static XErrorHandler old_handler
= NULL
;
1709 static int selectinput_err
= 0;
1710 static int x11_selectinput_errorhandler(Display
* display
,
1711 XErrorEvent
* event
)
1713 if (event
->error_code
== BadAccess
)
1715 selectinput_err
= 1;
1716 mp_msg(MSGT_VO
, MSGL_ERR
,
1717 "X11 error: BadAccess during XSelectInput Call\n");
1718 mp_msg(MSGT_VO
, MSGL_ERR
,
1719 "X11 error: The 'ButtonPressMask' mask of specified window has probably already used by another appication (see man XSelectInput)\n");
1720 /* If you think MPlayer should shutdown with this error,
1721 * comment out the following line */
1724 if (old_handler
!= NULL
)
1725 old_handler(display
, event
);
1727 x11_errorhandler(display
, event
);
1731 void vo_x11_selectinput_witherr(Display
* display
, Window w
,
1734 XSync(display
, False
);
1735 old_handler
= XSetErrorHandler(x11_selectinput_errorhandler
);
1736 selectinput_err
= 0;
1737 if (vo_nomouse_input
)
1739 XSelectInput(display
, w
,
1741 (~(ButtonPressMask
| ButtonReleaseMask
)));
1744 XSelectInput(display
, w
, event_mask
);
1746 XSync(display
, False
);
1747 XSetErrorHandler(old_handler
);
1748 if (selectinput_err
)
1750 mp_msg(MSGT_VO
, MSGL_ERR
,
1751 "X11 error: MPlayer discards mouse control (reconfiguring)\n");
1752 XSelectInput(display
, w
,
1755 (ButtonPressMask
| ButtonReleaseMask
|
1756 PointerMotionMask
)));
1760 #ifdef CONFIG_XF86VM
1761 void vo_vm_switch(struct vo
*vo
)
1763 struct vo_x11_state
*x11
= vo
->x11
;
1764 struct MPOpts
*opts
= vo
->opts
;
1765 Display
*mDisplay
= x11
->display
;
1766 int vm_event
, vm_error
;
1768 int i
, j
, have_vm
= 0;
1769 int X
= vo
->dwidth
, Y
= vo
->dheight
;
1770 int modeline_width
, modeline_height
;
1774 if (XF86VidModeQueryExtension(mDisplay
, &vm_event
, &vm_error
))
1776 XF86VidModeQueryVersion(mDisplay
, &vm_ver
, &vm_rev
);
1777 mp_msg(MSGT_VO
, MSGL_V
, "XF86VidMode extension v%i.%i\n", vm_ver
,
1781 mp_msg(MSGT_VO
, MSGL_WARN
,
1782 "XF86VidMode extension not available.\n");
1787 if (vidmodes
== NULL
)
1788 XF86VidModeGetAllModeLines(mDisplay
, x11
->screen
, &modecount
,
1791 modeline_width
= vidmodes
[0]->hdisplay
;
1792 modeline_height
= vidmodes
[0]->vdisplay
;
1794 for (i
= 1; i
< modecount
; i
++)
1795 if ((vidmodes
[i
]->hdisplay
>= X
)
1796 && (vidmodes
[i
]->vdisplay
>= Y
))
1797 if ((vidmodes
[i
]->hdisplay
<= modeline_width
)
1798 && (vidmodes
[i
]->vdisplay
<= modeline_height
))
1800 modeline_width
= vidmodes
[i
]->hdisplay
;
1801 modeline_height
= vidmodes
[i
]->vdisplay
;
1805 mp_msg(MSGT_VO
, MSGL_INFO
, MSGTR_SelectedVideoMode
,
1806 modeline_width
, modeline_height
, X
, Y
);
1807 XF86VidModeLockModeSwitch(mDisplay
, x11
->screen
, 0);
1808 XF86VidModeSwitchToMode(mDisplay
, x11
->screen
, vidmodes
[j
]);
1809 XF86VidModeSwitchToMode(mDisplay
, x11
->screen
, vidmodes
[j
]);
1811 // FIXME: all this is more of a hack than proper solution
1812 X
= (opts
->vo_screenwidth
- modeline_width
) / 2;
1813 Y
= (opts
->vo_screenheight
- modeline_height
) / 2;
1814 XF86VidModeSetViewPort(mDisplay
, x11
->screen
, X
, Y
);
1817 vo
->dwidth
= modeline_width
;
1818 vo
->dheight
= modeline_height
;
1819 aspect_save_screenres(vo
, modeline_width
, modeline_height
);
1823 void vo_vm_close(struct vo
*vo
)
1825 Display
*dpy
= vo
->x11
->display
;
1826 struct MPOpts
*opts
= vo
->opts
;
1828 if (vidmodes
!= NULL
&& vo
->x11
->vo_window
!= None
)
1830 if (vidmodes
!= NULL
)
1837 XF86VidModeGetAllModeLines(dpy
, vo
->x11
->screen
, &modecount
,
1839 for (i
= 0; i
< modecount
; i
++)
1840 if ((vidmodes
[i
]->hdisplay
== opts
->vo_screenwidth
)
1841 && (vidmodes
[i
]->vdisplay
== opts
->vo_screenheight
))
1843 mp_msg(MSGT_VO
, MSGL_INFO
,
1844 "Returning to original mode %dx%d\n",
1845 opts
->vo_screenwidth
, opts
->vo_screenheight
);
1849 XF86VidModeSwitchToMode(dpy
, vo
->x11
->screen
, vidmodes
[i
]);
1850 XF86VidModeSwitchToMode(dpy
, vo
->x11
->screen
, vidmodes
[i
]);
1857 #endif /* X11_FULLSCREEN */
1861 * Scan the available visuals on this Display/Screen. Try to find
1862 * the 'best' available TrueColor visual that has a decent color
1863 * depth (at least 15bit). If there are multiple visuals with depth
1864 * >= 15bit, we prefer visuals with a smaller color depth.
1866 int vo_find_depth_from_visuals(Display
* dpy
, int screen
,
1867 Visual
** visual_return
)
1869 XVisualInfo visual_tmpl
;
1870 XVisualInfo
*visuals
;
1872 int bestvisual
= -1;
1873 int bestvisual_depth
= -1;
1875 visual_tmpl
.screen
= screen
;
1876 visual_tmpl
.class = TrueColor
;
1877 visuals
= XGetVisualInfo(dpy
,
1878 VisualScreenMask
| VisualClassMask
,
1879 &visual_tmpl
, &nvisuals
);
1880 if (visuals
!= NULL
)
1882 for (i
= 0; i
< nvisuals
; i
++)
1884 mp_msg(MSGT_VO
, MSGL_V
,
1885 "vo: X11 truecolor visual %#lx, depth %d, R:%lX G:%lX B:%lX\n",
1886 visuals
[i
].visualid
, visuals
[i
].depth
,
1887 visuals
[i
].red_mask
, visuals
[i
].green_mask
,
1888 visuals
[i
].blue_mask
);
1890 * Save the visual index and its depth, if this is the first
1891 * truecolor visul, or a visual that is 'preferred' over the
1892 * previous 'best' visual.
1894 if (bestvisual_depth
== -1
1895 || (visuals
[i
].depth
>= 15
1896 && (visuals
[i
].depth
< bestvisual_depth
1897 || bestvisual_depth
< 15)))
1900 bestvisual_depth
= visuals
[i
].depth
;
1904 if (bestvisual
!= -1 && visual_return
!= NULL
)
1905 *visual_return
= visuals
[bestvisual
].visual
;
1909 return bestvisual_depth
;
1913 static Colormap cmap
= None
;
1914 static XColor cols
[256];
1915 static int cm_size
, red_mask
, green_mask
, blue_mask
;
1918 Colormap
vo_x11_create_colormap(struct vo
*vo
, XVisualInfo
*vinfo
)
1920 struct vo_x11_state
*x11
= vo
->x11
;
1921 unsigned k
, r
, g
, b
, ru
, gu
, bu
, m
, rv
, gv
, bv
, rvu
, gvu
, bvu
;
1923 if (vinfo
->class != DirectColor
)
1924 return XCreateColormap(x11
->display
, x11
->rootwin
, vinfo
->visual
,
1927 /* can this function get called twice or more? */
1930 cm_size
= vinfo
->colormap_size
;
1931 red_mask
= vinfo
->red_mask
;
1932 green_mask
= vinfo
->green_mask
;
1933 blue_mask
= vinfo
->blue_mask
;
1934 ru
= (red_mask
& (red_mask
- 1)) ^ red_mask
;
1935 gu
= (green_mask
& (green_mask
- 1)) ^ green_mask
;
1936 bu
= (blue_mask
& (blue_mask
- 1)) ^ blue_mask
;
1937 rvu
= 65536ull * ru
/ (red_mask
+ ru
);
1938 gvu
= 65536ull * gu
/ (green_mask
+ gu
);
1939 bvu
= 65536ull * bu
/ (blue_mask
+ bu
);
1942 m
= DoRed
| DoGreen
| DoBlue
;
1943 for (k
= 0; k
< cm_size
; k
++)
1947 cols
[k
].pixel
= r
| g
| b
;
1952 t
= (r
+ ru
) & red_mask
;
1956 t
= (g
+ gu
) & green_mask
;
1960 t
= (b
+ bu
) & blue_mask
;
1968 cmap
= XCreateColormap(x11
->display
, x11
->rootwin
, vinfo
->visual
, AllocAll
);
1969 XStoreColors(x11
->display
, cmap
, cols
, cm_size
);
1974 * Via colormaps/gamma ramps we can do gamma, brightness, contrast,
1975 * hue and red/green/blue intensity, but we cannot do saturation.
1976 * Currently only gamma, brightness and contrast are implemented.
1977 * Is there sufficient interest for hue and/or red/green/blue intensity?
1979 /* these values have range [-100,100] and are initially 0 */
1980 static int vo_gamma
= 0;
1981 static int vo_brightness
= 0;
1982 static int vo_contrast
= 0;
1984 static int transform_color(float val
,
1985 float brightness
, float contrast
, float gamma
) {
1986 float s
= pow(val
, gamma
);
1987 s
= (s
- 0.5) * contrast
+ 0.5;
1993 return (unsigned short) (s
* 65535);
1996 uint32_t vo_x11_set_equalizer(struct vo
*vo
, char *name
, int value
)
1998 float gamma
, brightness
, contrast
;
2003 * IMPLEMENTME: consider using XF86VidModeSetGammaRamp in the case
2004 * of TrueColor-ed window but be careful:
2005 * Unlike the colormaps, which are private for the X client
2006 * who created them and thus automatically destroyed on client
2007 * disconnect, this gamma ramp is a system-wide (X-server-wide)
2008 * setting and _must_ be restored before the process exits.
2009 * Unforunately when the process crashes (or gets killed
2010 * for some reason) it is impossible to restore the setting,
2011 * and such behaviour could be rather annoying for the users.
2016 if (!strcasecmp(name
, "brightness"))
2017 vo_brightness
= value
;
2018 else if (!strcasecmp(name
, "contrast"))
2019 vo_contrast
= value
;
2020 else if (!strcasecmp(name
, "gamma"))
2025 brightness
= 0.01 * vo_brightness
;
2026 contrast
= tan(0.0095 * (vo_contrast
+ 100) * M_PI
/ 4);
2027 gamma
= pow(2, -0.02 * vo_gamma
);
2029 rf
= (float) ((red_mask
& (red_mask
- 1)) ^ red_mask
) / red_mask
;
2030 gf
= (float) ((green_mask
& (green_mask
- 1)) ^ green_mask
) /
2032 bf
= (float) ((blue_mask
& (blue_mask
- 1)) ^ blue_mask
) / blue_mask
;
2034 /* now recalculate the colormap using the newly set value */
2035 for (k
= 0; k
< cm_size
; k
++)
2037 cols
[k
].red
= transform_color(rf
* k
, brightness
, contrast
, gamma
);
2038 cols
[k
].green
= transform_color(gf
* k
, brightness
, contrast
, gamma
);
2039 cols
[k
].blue
= transform_color(bf
* k
, brightness
, contrast
, gamma
);
2042 XStoreColors(vo
->x11
->display
, cmap
, cols
, cm_size
);
2043 XFlush(vo
->x11
->display
);
2047 uint32_t vo_x11_get_equalizer(char *name
, int *value
)
2051 if (!strcasecmp(name
, "brightness"))
2052 *value
= vo_brightness
;
2053 else if (!strcasecmp(name
, "contrast"))
2054 *value
= vo_contrast
;
2055 else if (!strcasecmp(name
, "gamma"))
2063 int vo_xv_set_eq(struct vo
*vo
, uint32_t xv_port
, char *name
, int value
)
2065 XvAttribute
*attributes
;
2066 int i
, howmany
, xv_atom
;
2068 mp_dbg(MSGT_VO
, MSGL_V
, "xv_set_eq called! (%s, %d)\n", name
, value
);
2070 /* get available attributes */
2071 attributes
= XvQueryPortAttributes(vo
->x11
->display
, xv_port
, &howmany
);
2072 for (i
= 0; i
< howmany
&& attributes
; i
++)
2073 if (attributes
[i
].flags
& XvSettable
)
2075 xv_atom
= XInternAtom(vo
->x11
->display
, attributes
[i
].name
, True
);
2076 /* since we have SET_DEFAULTS first in our list, we can check if it's available
2077 then trigger it if it's ok so that the other values are at default upon query */
2078 if (xv_atom
!= None
)
2080 int hue
= 0, port_value
, port_min
, port_max
;
2082 if (!strcmp(attributes
[i
].name
, "XV_BRIGHTNESS") &&
2083 (!strcasecmp(name
, "brightness")))
2085 else if (!strcmp(attributes
[i
].name
, "XV_CONTRAST") &&
2086 (!strcasecmp(name
, "contrast")))
2088 else if (!strcmp(attributes
[i
].name
, "XV_SATURATION") &&
2089 (!strcasecmp(name
, "saturation")))
2091 else if (!strcmp(attributes
[i
].name
, "XV_HUE") &&
2092 (!strcasecmp(name
, "hue")))
2097 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
2098 if (!strcmp(attributes
[i
].name
, "XV_RED_INTENSITY") &&
2099 (!strcasecmp(name
, "red_intensity")))
2101 else if (!strcmp(attributes
[i
].name
, "XV_GREEN_INTENSITY")
2102 && (!strcasecmp(name
, "green_intensity")))
2104 else if (!strcmp(attributes
[i
].name
, "XV_BLUE_INTENSITY")
2105 && (!strcasecmp(name
, "blue_intensity")))
2110 port_min
= attributes
[i
].min_value
;
2111 port_max
= attributes
[i
].max_value
;
2113 /* nvidia hue workaround */
2114 if (hue
&& port_min
== 0 && port_max
== 360)
2118 0) ? (port_value
- 100) : (port_value
+ 100);
2124 (port_value
+ 100) * (port_max
- port_min
) / 200 +
2126 XvSetPortAttribute(vo
->x11
->display
, xv_port
, xv_atom
, port_value
);
2133 int vo_xv_get_eq(struct vo
*vo
, uint32_t xv_port
, char *name
, int *value
)
2136 XvAttribute
*attributes
;
2137 int i
, howmany
, xv_atom
;
2139 /* get available attributes */
2140 attributes
= XvQueryPortAttributes(vo
->x11
->display
, xv_port
, &howmany
);
2141 for (i
= 0; i
< howmany
&& attributes
; i
++)
2142 if (attributes
[i
].flags
& XvGettable
)
2144 xv_atom
= XInternAtom(vo
->x11
->display
, attributes
[i
].name
, True
);
2145 /* since we have SET_DEFAULTS first in our list, we can check if it's available
2146 then trigger it if it's ok so that the other values are at default upon query */
2147 if (xv_atom
!= None
)
2149 int val
, port_value
= 0, port_min
, port_max
;
2151 XvGetPortAttribute(vo
->x11
->display
, xv_port
, xv_atom
,
2154 port_min
= attributes
[i
].min_value
;
2155 port_max
= attributes
[i
].max_value
;
2157 (port_value
- port_min
) * 200 / (port_max
- port_min
) -
2160 if (!strcmp(attributes
[i
].name
, "XV_BRIGHTNESS") &&
2161 (!strcasecmp(name
, "brightness")))
2163 else if (!strcmp(attributes
[i
].name
, "XV_CONTRAST") &&
2164 (!strcasecmp(name
, "contrast")))
2166 else if (!strcmp(attributes
[i
].name
, "XV_SATURATION") &&
2167 (!strcasecmp(name
, "saturation")))
2169 else if (!strcmp(attributes
[i
].name
, "XV_HUE") &&
2170 (!strcasecmp(name
, "hue")))
2172 /* nasty nvidia detect */
2173 if (port_min
== 0 && port_max
== 360)
2174 *value
= (val
>= 0) ? (val
- 100) : (val
+ 100);
2178 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
2179 if (!strcmp(attributes
[i
].name
, "XV_RED_INTENSITY") &&
2180 (!strcasecmp(name
, "red_intensity")))
2182 else if (!strcmp(attributes
[i
].name
, "XV_GREEN_INTENSITY")
2183 && (!strcasecmp(name
, "green_intensity")))
2185 else if (!strcmp(attributes
[i
].name
, "XV_BLUE_INTENSITY")
2186 && (!strcasecmp(name
, "blue_intensity")))
2191 mp_dbg(MSGT_VO
, MSGL_V
, "xv_get_eq called! (%s, %d)\n",
2200 * \brief Interns the requested atom if it is available.
2202 * \param atom_name String containing the name of the requested atom.
2204 * \return Returns the atom if available, else None is returned.
2207 static Atom
xv_intern_atom_if_exists(struct vo_x11_state
*x11
,
2208 char const *atom_name
)
2210 XvAttribute
* attributes
;
2212 Atom xv_atom
= None
;
2214 attributes
= XvQueryPortAttributes(x11
->display
, x11
->xv_port
, &attrib_count
);
2215 if( attributes
!=NULL
)
2217 for ( i
= 0; i
< attrib_count
; ++i
)
2219 if ( strcmp(attributes
[i
].name
, atom_name
) == 0 )
2221 xv_atom
= XInternAtom(x11
->display
, atom_name
, False
);
2222 break; // found what we want, break out
2225 XFree( attributes
);
2232 * \brief Try to enable vsync for xv.
2233 * \return Returns -1 if not available, 0 on failure and 1 on success.
2235 int vo_xv_enable_vsync(struct vo
*vo
)
2237 struct vo_x11_state
*x11
= vo
->x11
;
2238 Atom xv_atom
= xv_intern_atom_if_exists(x11
, "XV_SYNC_TO_VBLANK");
2239 if (xv_atom
== None
)
2241 return XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, 1) == Success
;
2245 * \brief Get maximum supported source image dimensions.
2247 * This function does not set the variables pointed to by
2248 * width and height if the information could not be retrieved,
2249 * so the caller is reponsible for properly initializing them.
2251 * \param width [out] The maximum width gets stored here.
2252 * \param height [out] The maximum height gets stored here.
2255 void vo_xv_get_max_img_dim(struct vo
*vo
, uint32_t * width
, uint32_t * height
)
2257 struct vo_x11_state
*x11
= vo
->x11
;
2258 XvEncodingInfo
* encodings
;
2259 //unsigned long num_encodings, idx; to int or too long?!
2260 unsigned int num_encodings
, idx
;
2262 XvQueryEncodings(x11
->display
, x11
->xv_port
, &num_encodings
, &encodings
);
2266 for ( idx
= 0; idx
< num_encodings
; ++idx
)
2268 if ( strcmp( encodings
[idx
].name
, "XV_IMAGE" ) == 0 )
2270 *width
= encodings
[idx
].width
;
2271 *height
= encodings
[idx
].height
;
2277 mp_msg( MSGT_VO
, MSGL_V
,
2278 "[xv common] Maximum source image dimensions: %ux%u\n",
2281 XvFreeEncodingInfo( encodings
);
2285 * \brief Print information about the colorkey method and source.
2287 * \param ck_handling Integer value containing the information about
2288 * colorkey handling (see x11_common.h).
2290 * Outputs the content of |ck_handling| as a readable message.
2293 static void vo_xv_print_ck_info(struct vo_x11_state
*x11
)
2295 mp_msg( MSGT_VO
, MSGL_V
, "[xv common] " );
2297 switch ( x11
->xv_ck_info
.method
)
2299 case CK_METHOD_NONE
:
2300 mp_msg( MSGT_VO
, MSGL_V
, "Drawing no colorkey.\n" ); return;
2301 case CK_METHOD_AUTOPAINT
:
2302 mp_msg( MSGT_VO
, MSGL_V
, "Colorkey is drawn by Xv." ); break;
2303 case CK_METHOD_MANUALFILL
:
2304 mp_msg( MSGT_VO
, MSGL_V
, "Drawing colorkey manually." ); break;
2305 case CK_METHOD_BACKGROUND
:
2306 mp_msg( MSGT_VO
, MSGL_V
, "Colorkey is drawn as window background." ); break;
2309 mp_msg( MSGT_VO
, MSGL_V
, "\n[xv common] " );
2311 switch ( x11
->xv_ck_info
.source
)
2314 mp_msg( MSGT_VO
, MSGL_V
, "Using colorkey from Xv (0x%06lx).\n",
2318 if ( x11
->xv_ck_info
.method
== CK_METHOD_AUTOPAINT
)
2320 mp_msg( MSGT_VO
, MSGL_V
,
2321 "Ignoring colorkey from MPlayer (0x%06lx).\n",
2326 mp_msg( MSGT_VO
, MSGL_V
,
2327 "Using colorkey from MPlayer (0x%06lx)."
2328 " Use -colorkey to change.\n",
2333 mp_msg( MSGT_VO
, MSGL_V
,
2334 "Setting and using colorkey from MPlayer (0x%06lx)."
2335 " Use -colorkey to change.\n",
2341 * \brief Init colorkey depending on the settings in xv_ck_info.
2343 * \return Returns 0 on failure and 1 on success.
2345 * Sets the colorkey variable according to the CK_SRC_* and CK_METHOD_*
2346 * flags in xv_ck_info.
2350 * - manual colorkey drawing ( CK_METHOD_MANUALFILL )
2351 * - set colorkey as window background ( CK_METHOD_BACKGROUND )
2352 * - let Xv paint the colorkey ( CK_METHOD_AUTOPAINT )
2354 * - use currently set colorkey ( CK_SRC_CUR )
2355 * - use colorkey in vo_colorkey ( CK_SRC_USE )
2356 * - use and set colorkey in vo_colorkey ( CK_SRC_SET )
2358 * NOTE: If vo_colorkey has bits set after the first 3 low order bytes
2359 * we don't draw anything as this means it was forced to off.
2361 int vo_xv_init_colorkey(struct vo
*vo
)
2363 struct vo_x11_state
*x11
= vo
->x11
;
2367 /* check if colorkeying is needed */
2368 xv_atom
= xv_intern_atom_if_exists(vo
->x11
, "XV_COLORKEY");
2370 /* if we have to deal with colorkeying ... */
2371 if( xv_atom
!= None
&& !(vo_colorkey
& 0xFF000000) )
2373 /* check if we should use the colorkey specified in vo_colorkey */
2374 if ( x11
->xv_ck_info
.source
!= CK_SRC_CUR
)
2376 x11
->xv_colorkey
= vo_colorkey
;
2378 /* check if we have to set the colorkey too */
2379 if ( x11
->xv_ck_info
.source
== CK_SRC_SET
)
2381 xv_atom
= XInternAtom(x11
->display
, "XV_COLORKEY",False
);
2383 rez
= XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, vo_colorkey
);
2384 if ( rez
!= Success
)
2386 mp_msg( MSGT_VO
, MSGL_FATAL
,
2387 "[xv common] Couldn't set colorkey!\n" );
2388 return 0; // error setting colorkey
2396 rez
=XvGetPortAttribute(x11
->display
,x11
->xv_port
, xv_atom
, &colorkey_ret
);
2397 if ( rez
== Success
)
2399 x11
->xv_colorkey
= colorkey_ret
;
2403 mp_msg( MSGT_VO
, MSGL_FATAL
,
2404 "[xv common] Couldn't get colorkey!"
2405 "Maybe the selected Xv port has no overlay.\n" );
2406 return 0; // error getting colorkey
2410 xv_atom
= xv_intern_atom_if_exists(vo
->x11
, "XV_AUTOPAINT_COLORKEY");
2412 /* should we draw the colorkey ourselves or activate autopainting? */
2413 if ( x11
->xv_ck_info
.method
== CK_METHOD_AUTOPAINT
)
2415 rez
= !Success
; // reset rez to something different than Success
2417 if ( xv_atom
!= None
) // autopaint is supported
2419 rez
= XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, 1);
2422 if ( rez
!= Success
)
2424 // fallback to manual colorkey drawing
2425 x11
->xv_ck_info
.method
= CK_METHOD_MANUALFILL
;
2428 else // disable colorkey autopainting if supported
2430 if ( xv_atom
!= None
) // we have autopaint attribute
2432 XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, 0);
2436 else // do no colorkey drawing at all
2438 x11
->xv_ck_info
.method
= CK_METHOD_NONE
;
2439 } /* end: should we draw colorkey */
2441 /* output information about the current colorkey settings */
2442 vo_xv_print_ck_info(x11
);
2444 return 1; // success
2448 * \brief Draw the colorkey on the video window.
2450 * Draws the colorkey depending on the set method ( colorkey_handling ).
2452 * Also draws the black bars ( when the video doesn't fit the display in
2453 * fullscreen ) separately, so they don't overlap with the video area.
2454 * It doesn't call XFlush.
2457 void vo_xv_draw_colorkey(struct vo
*vo
, int32_t x
, int32_t y
,
2458 int32_t w
, int32_t h
)
2460 struct MPOpts
*opts
= vo
->opts
;
2461 struct vo_x11_state
*x11
= vo
->x11
;
2462 if( x11
->xv_ck_info
.method
== CK_METHOD_MANUALFILL
||
2463 x11
->xv_ck_info
.method
== CK_METHOD_BACKGROUND
)//less tearing than XClearWindow()
2465 XSetForeground(x11
->display
, x11
->vo_gc
, x11
->xv_colorkey
);
2466 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2471 /* draw black bars if needed */
2472 /* TODO! move this to vo_x11_clearwindow_part() */
2475 XSetForeground(x11
->display
, x11
->vo_gc
, 0 );
2476 /* making non-overlap fills, requires 8 checks instead of 4 */
2478 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2480 opts
->vo_screenwidth
, y
);
2482 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2484 x
, opts
->vo_screenheight
);
2485 if (x
+ w
< opts
->vo_screenwidth
)
2486 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2488 opts
->vo_screenwidth
, opts
->vo_screenheight
);
2489 if (y
+ h
< opts
->vo_screenheight
)
2490 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2492 opts
->vo_screenwidth
, opts
->vo_screenheight
);
2496 /** \brief Tests if a valid argument for the ck suboption was given. */
2497 int xv_test_ck( void * arg
)
2499 strarg_t
* strarg
= (strarg_t
*)arg
;
2501 if ( strargcmp( strarg
, "use" ) == 0 ||
2502 strargcmp( strarg
, "set" ) == 0 ||
2503 strargcmp( strarg
, "cur" ) == 0 )
2510 /** \brief Tests if a valid arguments for the ck-method suboption was given. */
2511 int xv_test_ckm( void * arg
)
2513 strarg_t
* strarg
= (strarg_t
*)arg
;
2515 if ( strargcmp( strarg
, "bg" ) == 0 ||
2516 strargcmp( strarg
, "man" ) == 0 ||
2517 strargcmp( strarg
, "auto" ) == 0 )
2526 * \brief Modify the colorkey_handling var according to str
2528 * Checks if a valid pointer ( not NULL ) to the string
2529 * was given. And in that case modifies the colorkey_handling
2530 * var to reflect the requested behaviour.
2531 * If nothing happens the content of colorkey_handling stays
2534 * \param str Pointer to the string or NULL
2537 void xv_setup_colorkeyhandling(struct vo
*vo
, const char *ck_method_str
,
2540 struct vo_x11_state
*x11
= vo
->x11
;
2541 /* check if a valid pointer to the string was passed */
2544 if ( strncmp( ck_str
, "use", 3 ) == 0 )
2546 x11
->xv_ck_info
.source
= CK_SRC_USE
;
2548 else if ( strncmp( ck_str
, "set", 3 ) == 0 )
2550 x11
->xv_ck_info
.source
= CK_SRC_SET
;
2553 /* check if a valid pointer to the string was passed */
2554 if ( ck_method_str
)
2556 if ( strncmp( ck_method_str
, "bg", 2 ) == 0 )
2558 x11
->xv_ck_info
.method
= CK_METHOD_BACKGROUND
;
2560 else if ( strncmp( ck_method_str
, "man", 3 ) == 0 )
2562 x11
->xv_ck_info
.method
= CK_METHOD_MANUALFILL
;
2564 else if ( strncmp( ck_method_str
, "auto", 4 ) == 0 )
2566 x11
->xv_ck_info
.method
= CK_METHOD_AUTOPAINT
;
2573 struct vo_x11_state
*vo_x11_init_state(void)
2575 struct vo_x11_state
*s
= talloc_ptrtype(NULL
, s
);
2576 *s
= (struct vo_x11_state
){
2577 .xv_ck_info
= { CK_METHOD_MANUALFILL
, CK_SRC_CUR
},
2578 .olddecor
= MWM_DECOR_ALL
,
2579 .oldfuncs
= MWM_FUNC_MOVE
| MWM_FUNC_CLOSE
| MWM_FUNC_MINIMIZE
|
2580 MWM_FUNC_MAXIMIZE
| MWM_FUNC_RESIZE
,
2581 .old_gravity
= NorthWestGravity
,