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 const struct keymap keysym_map
[] = {
526 {XF86XK_MenuKB
, KEY_MENU
},
527 {XF86XK_AudioPlay
, KEY_PLAY
}, {XF86XK_AudioPause
, KEY_PAUSE
}, {XF86XK_AudioStop
, KEY_STOP
},
528 {XF86XK_AudioPrev
, KEY_PREV
}, {XF86XK_AudioNext
, KEY_NEXT
},
529 {XF86XK_AudioMute
, KEY_MUTE
}, {XF86XK_AudioLowerVolume
, KEY_VOLUME_DOWN
}, {XF86XK_AudioRaiseVolume
, KEY_VOLUME_UP
},
533 static void vo_x11_putkey_ext(struct vo
*vo
, int keysym
)
535 struct mp_fifo
*f
= vo
->key_fifo
;
536 int mpkey
= lookup_keymap_table(keysym_map
, keysym
);
538 mplayer_put_key(f
, mpkey
);
542 static const struct keymap keymap
[] = {
544 {wsEscape
, KEY_ESC
}, {wsBackSpace
, KEY_BS
}, {wsTab
, KEY_TAB
}, {wsEnter
, KEY_ENTER
},
547 {wsLeft
, KEY_LEFT
}, {wsRight
, KEY_RIGHT
}, {wsUp
, KEY_UP
}, {wsDown
, KEY_DOWN
},
550 {wsInsert
, KEY_INSERT
}, {wsDelete
, KEY_DELETE
}, {wsHome
, KEY_HOME
}, {wsEnd
, KEY_END
},
551 {wsPageUp
, KEY_PAGE_UP
}, {wsPageDown
, KEY_PAGE_DOWN
},
554 {wsF1
, KEY_F
+1}, {wsF2
, KEY_F
+2}, {wsF3
, KEY_F
+3}, {wsF4
, KEY_F
+4},
555 {wsF5
, KEY_F
+5}, {wsF6
, KEY_F
+6}, {wsF7
, KEY_F
+7}, {wsF8
, KEY_F
+8},
556 {wsF9
, KEY_F
+9}, {wsF10
, KEY_F
+10}, {wsF11
, KEY_F
+11}, {wsF12
, KEY_F
+12},
558 // numpad independent of numlock
559 {wsGrayMinus
, '-'}, {wsGrayPlus
, '+'}, {wsGrayMul
, '*'}, {wsGrayDiv
, '/'},
560 {wsGrayEnter
, KEY_KPENTER
},
562 // numpad with numlock
563 {wsGray0
, KEY_KP0
}, {wsGray1
, KEY_KP1
}, {wsGray2
, KEY_KP2
},
564 {wsGray3
, KEY_KP3
}, {wsGray4
, KEY_KP4
}, {wsGray5
, KEY_KP5
},
565 {wsGray6
, KEY_KP6
}, {wsGray7
, KEY_KP7
}, {wsGray8
, KEY_KP8
},
566 {wsGray9
, KEY_KP9
}, {wsGrayDecimal
, KEY_KPDEC
},
568 // numpad without numlock
569 {wsGrayInsert
, KEY_KPINS
}, {wsGrayEnd
, KEY_KP1
}, {wsGrayDown
, KEY_KP2
},
570 {wsGrayPgDn
, KEY_KP3
}, {wsGrayLeft
, KEY_KP4
}, {wsGray5Dup
, KEY_KP5
},
571 {wsGrayRight
, KEY_KP6
}, {wsGrayHome
, KEY_KP7
}, {wsGrayUp
, KEY_KP8
},
572 {wsGrayPgUp
, KEY_KP9
}, {wsGrayDelete
, KEY_KPDEL
},
577 void vo_x11_putkey(struct vo
*vo
, int key
)
579 static const char *passthrough_keys
= " -+*/<>`~!@#$%^&()_{}:;\"\',.?\\|=[]";
582 if ((key
>= 'a' && key
<= 'z') ||
583 (key
>= 'A' && key
<= 'Z') ||
584 (key
>= '0' && key
<= '9') ||
585 (key
> 0 && key
< 256 && strchr(passthrough_keys
, key
)))
589 mpkey
= lookup_keymap_table(keymap
, key
);
592 mplayer_put_key(vo
->key_fifo
, mpkey
);
596 // ----- Motif header: -------
598 #define MWM_HINTS_FUNCTIONS (1L << 0)
599 #define MWM_HINTS_DECORATIONS (1L << 1)
600 #define MWM_HINTS_INPUT_MODE (1L << 2)
601 #define MWM_HINTS_STATUS (1L << 3)
603 #define MWM_FUNC_ALL (1L << 0)
604 #define MWM_FUNC_RESIZE (1L << 1)
605 #define MWM_FUNC_MOVE (1L << 2)
606 #define MWM_FUNC_MINIMIZE (1L << 3)
607 #define MWM_FUNC_MAXIMIZE (1L << 4)
608 #define MWM_FUNC_CLOSE (1L << 5)
610 #define MWM_DECOR_ALL (1L << 0)
611 #define MWM_DECOR_BORDER (1L << 1)
612 #define MWM_DECOR_RESIZEH (1L << 2)
613 #define MWM_DECOR_TITLE (1L << 3)
614 #define MWM_DECOR_MENU (1L << 4)
615 #define MWM_DECOR_MINIMIZE (1L << 5)
616 #define MWM_DECOR_MAXIMIZE (1L << 6)
618 #define MWM_INPUT_MODELESS 0
619 #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
620 #define MWM_INPUT_SYSTEM_MODAL 2
621 #define MWM_INPUT_FULL_APPLICATION_MODAL 3
622 #define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL
624 #define MWM_TEAROFF_WINDOW (1L<<0)
635 static MotifWmHints vo_MotifWmHints
;
636 static Atom vo_MotifHints
= None
;
638 void vo_x11_decoration(struct vo
*vo
, int d
)
640 struct vo_x11_state
*x11
= vo
->x11
;
643 unsigned long mn
, mb
;
650 XSetTransientForHint(x11
->display
, x11
->window
,
651 RootWindow(x11
->display
, x11
->screen
));
654 vo_MotifHints
= XInternAtom(x11
->display
, "_MOTIF_WM_HINTS", 0);
655 if (vo_MotifHints
!= None
)
659 MotifWmHints
*mhints
= NULL
;
661 XGetWindowProperty(x11
->display
, x11
->window
,
662 vo_MotifHints
, 0, 20, False
,
663 vo_MotifHints
, &mtype
, &mformat
, &mn
,
664 &mb
, (unsigned char **) &mhints
);
667 if (mhints
->flags
& MWM_HINTS_DECORATIONS
)
668 x11
->olddecor
= mhints
->decorations
;
669 if (mhints
->flags
& MWM_HINTS_FUNCTIONS
)
670 x11
->oldfuncs
= mhints
->functions
;
675 memset(&vo_MotifWmHints
, 0, sizeof(MotifWmHints
));
676 vo_MotifWmHints
.flags
=
677 MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
680 vo_MotifWmHints
.functions
= x11
->oldfuncs
;
684 vo_MotifWmHints
.decorations
=
685 d
| ((vo_fsmode
& 2) ? 0 : MWM_DECOR_MENU
);
687 vo_MotifWmHints
.decorations
=
688 d
| ((vo_fsmode
& 2) ? MWM_DECOR_MENU
: 0);
690 XChangeProperty(x11
->display
, x11
->window
, vo_MotifHints
,
693 (unsigned char *) &vo_MotifWmHints
,
694 (vo_fsmode
& 4) ? 4 : 5);
698 void vo_x11_classhint(struct vo
*vo
, Window window
, char *name
)
700 struct vo_x11_state
*x11
= vo
->x11
;
702 pid_t pid
= getpid();
704 wmClass
.res_name
= name
;
705 wmClass
.res_class
= "MPlayer";
706 XSetClassHint(x11
->display
, window
, &wmClass
);
707 XChangeProperty(x11
->display
, window
, x11
->XA_NET_WM_PID
, XA_CARDINAL
,
708 32, PropModeReplace
, (unsigned char *) &pid
, 1);
711 void vo_x11_uninit(struct vo
*vo
)
713 struct vo_x11_state
*x11
= vo
->x11
;
714 saver_on(x11
->display
);
715 if (x11
->window
!= None
)
716 vo_showcursor(x11
->display
, x11
->window
);
720 XFreeGC(vo
->x11
->display
, x11
->f_gc
);
724 /* destroy window only if it's not controlled by the GUI */
730 XSetBackground(vo
->x11
->display
, x11
->vo_gc
, 0);
731 XFreeGC(vo
->x11
->display
, x11
->vo_gc
);
734 if (x11
->window
!= None
)
736 XClearWindow(x11
->display
, x11
->window
);
741 XUnmapWindow(x11
->display
, x11
->window
);
742 XDestroyWindow(x11
->display
, x11
->window
);
745 XNextEvent(x11
->display
, &xev
);
747 while (xev
.type
!= DestroyNotify
748 || xev
.xdestroywindow
.event
!= x11
->window
);
753 x11
->vo_old_width
= x11
->vo_old_height
= 0;
757 int vo_x11_check_events(struct vo
*vo
)
759 struct vo_x11_state
*x11
= vo
->x11
;
760 struct MPOpts
*opts
= vo
->opts
;
761 Display
*display
= vo
->x11
->display
;
767 // unsigned long vo_KeyTable[512];
769 if ((x11
->vo_mouse_autohide
) && x11
->mouse_waiting_hide
&&
770 (GetTimerMS() - x11
->mouse_timer
>= 1000)) {
771 vo_hidecursor(display
, x11
->window
);
772 x11
->mouse_waiting_hide
= 0;
775 while (XPending(display
))
777 XNextEvent(display
, &Event
);
781 guiGetEvent(0, (char *) &Event
);
782 if (x11
->window
!= Event
.xany
.window
)
786 // printf("\rEvent.type=%X \n",Event.type);
790 ret
|= VO_EVENT_EXPOSE
;
792 case ConfigureNotify
:
793 // if (!vo_fs && (Event.xconfigure.width == opts->vo_screenwidth || Event.xconfigure.height == opts->vo_screenheight)) break;
794 // if (vo_fs && Event.xconfigure.width != opts->vo_screenwidth && Event.xconfigure.height != opts->vo_screenheight) break;
795 if (x11
->window
== None
)
797 vo_x11_update_geometry(vo
);
798 ret
|= VO_EVENT_RESIZE
;
805 if ( use_gui
) { break; }
808 XLookupString(&Event
.xkey
, buf
, sizeof(buf
), &keySym
,
809 &x11
->compose_status
);
810 #ifdef XF86XK_AudioPause
811 vo_x11_putkey_ext(vo
, keySym
);
814 ((keySym
& 0xff00) !=
815 0 ? ((keySym
& 0x00ff) + 256) : (keySym
));
816 vo_x11_putkey(vo
, key
);
817 ret
|= VO_EVENT_KEYPRESS
;
821 if(enable_mouse_movements
)
824 sprintf(cmd_str
,"set_mouse_pos %i %i",Event
.xmotion
.x
, Event
.xmotion
.y
);
825 mp_input_queue_cmd(vo
->input_ctx
,
826 mp_input_parse_cmd(cmd_str
));
829 if (x11
->vo_mouse_autohide
)
831 vo_showcursor(display
, x11
->window
);
832 x11
->mouse_waiting_hide
= 1;
833 x11
->mouse_timer
= GetTimerMS();
837 if (x11
->vo_mouse_autohide
)
839 vo_showcursor(display
, x11
->window
);
840 x11
->mouse_waiting_hide
= 1;
841 x11
->mouse_timer
= GetTimerMS();
844 // Ignore mouse button 1-3 under GUI.
845 if (use_gui
&& (Event
.xbutton
.button
>= 1)
846 && (Event
.xbutton
.button
<= 3))
849 mplayer_put_key(vo
->key_fifo
,
850 (MOUSE_BTN0
+ Event
.xbutton
.button
- 1)
854 if (x11
->vo_mouse_autohide
)
856 vo_showcursor(display
, x11
->window
);
857 x11
->mouse_waiting_hide
= 1;
858 x11
->mouse_timer
= GetTimerMS();
861 // Ignore mouse button 1-3 under GUI.
862 if (use_gui
&& (Event
.xbutton
.button
>= 1)
863 && (Event
.xbutton
.button
<= 3))
866 mplayer_put_key(vo
->key_fifo
,
867 MOUSE_BTN0
+ Event
.xbutton
.button
- 1);
872 XGetAtomName(display
, Event
.xproperty
.atom
);
877 // fprintf(stderr,"[ws] PropertyNotify ( 0x%x ) %s ( 0x%x )\n",vo_window,name,Event.xproperty.atom );
883 x11
->vo_hint
.win_gravity
= x11
->old_gravity
;
884 XSetWMNormalHints(display
, x11
->window
, &x11
->vo_hint
);
888 if (Event
.xclient
.message_type
== x11
->XAWM_PROTOCOLS
&&
889 Event
.xclient
.data
.l
[0] == x11
->XAWM_DELETE_WINDOW
)
890 mplayer_put_key(vo
->key_fifo
, KEY_CLOSE_WIN
);
898 * \brief sets the size and position of the non-fullscreen window.
900 static void vo_x11_nofs_sizepos(struct vo
*vo
, int x
, int y
,
901 int width
, int height
)
903 struct vo_x11_state
*x11
= vo
->x11
;
904 vo_x11_sizehint(vo
, x
, y
, width
, height
, 0);
908 x11
->vo_old_width
= width
;
909 x11
->vo_old_height
= height
;
914 vo
->dheight
= height
;
915 XMoveResizeWindow(vo
->x11
->display
, vo
->x11
->window
, x
, y
, width
, height
);
919 void vo_x11_sizehint(struct vo
*vo
, int x
, int y
, int width
, int height
, int max
)
921 struct vo_x11_state
*x11
= vo
->x11
;
922 x11
->vo_hint
.flags
= 0;
925 x11
->vo_hint
.flags
|= PAspect
;
926 x11
->vo_hint
.min_aspect
.x
= width
;
927 x11
->vo_hint
.min_aspect
.y
= height
;
928 x11
->vo_hint
.max_aspect
.x
= width
;
929 x11
->vo_hint
.max_aspect
.y
= height
;
932 x11
->vo_hint
.flags
|= PPosition
| PSize
;
935 x11
->vo_hint
.width
= width
;
936 x11
->vo_hint
.height
= height
;
939 x11
->vo_hint
.flags
|= PMaxSize
;
940 x11
->vo_hint
.max_width
= width
;
941 x11
->vo_hint
.max_height
= height
;
944 x11
->vo_hint
.max_width
= 0;
945 x11
->vo_hint
.max_height
= 0;
948 // Set minimum height/width to 4 to avoid off-by-one errors
949 // and because mga_vid requires a minimal size of 4 pixels.
950 x11
->vo_hint
.flags
|= PMinSize
;
951 x11
->vo_hint
.min_width
= x11
->vo_hint
.min_height
= 4;
953 // Set the base size. A window manager might display the window
954 // size to the user relative to this.
955 // Setting these to width/height might be nice, but e.g. fluxbox can't handle it.
956 x11
->vo_hint
.flags
|= PBaseSize
;
957 x11
->vo_hint
.base_width
= 0 /*width*/;
958 x11
->vo_hint
.base_height
= 0 /*height*/;
960 x11
->vo_hint
.flags
|= PWinGravity
;
961 x11
->vo_hint
.win_gravity
= StaticGravity
;
962 XSetWMNormalHints(x11
->display
, x11
->window
, &x11
->vo_hint
);
965 static int vo_x11_get_gnome_layer(struct vo_x11_state
*x11
, Window win
)
969 unsigned long nitems
;
970 unsigned long bytesafter
;
971 unsigned short *args
= NULL
;
973 if (XGetWindowProperty(x11
->display
, win
, x11
->XA_WIN_LAYER
, 0, 16384,
974 False
, AnyPropertyType
, &type
, &format
, &nitems
,
976 (unsigned char **) &args
) == Success
977 && nitems
> 0 && args
)
979 mp_msg(MSGT_VO
, MSGL_V
, "[x11] original window layer is %d.\n",
983 return WIN_LAYER_NORMAL
;
987 static Window
vo_x11_create_smooth_window(struct vo_x11_state
*x11
, Window mRoot
,
988 Visual
* vis
, int x
, int y
,
989 unsigned int width
, unsigned int height
,
990 int depth
, Colormap col_map
)
992 unsigned long xswamask
= CWBorderPixel
;
993 XSetWindowAttributes xswa
;
996 if (col_map
!= CopyFromParent
)
998 xswa
.colormap
= col_map
;
999 xswamask
|= CWColormap
;
1001 xswa
.background_pixel
= 0;
1002 xswa
.border_pixel
= 0;
1003 xswa
.backing_store
= NotUseful
;
1004 xswa
.bit_gravity
= StaticGravity
;
1007 XCreateWindow(x11
->display
, x11
->rootwin
, x
, y
, width
, height
, 0, depth
,
1008 CopyFromParent
, vis
, xswamask
, &xswa
);
1009 XSetWMProtocols(x11
->display
, ret_win
, &x11
->XAWM_DELETE_WINDOW
, 1);
1011 x11
->f_gc
= XCreateGC(x11
->display
, ret_win
, 0, 0);
1012 XSetForeground(x11
->display
, x11
->f_gc
, 0);
1018 * \brief create and setup a window suitable for display
1019 * \param vis Visual to use for creating the window
1020 * \param x x position of window
1021 * \param y y position of window
1022 * \param width width of window
1023 * \param height height of window
1024 * \param flags flags for window creation.
1025 * Only VOFLAG_FULLSCREEN is supported so far.
1026 * \param col_map Colourmap for window or CopyFromParent if a specific colormap isn't needed
1027 * \param classname name to use for the classhint
1028 * \param title title for the window
1030 * This also does the grunt-work like setting Window Manager hints etc.
1031 * If vo_window is already set it just moves and resizes it.
1033 void vo_x11_create_vo_window(struct vo
*vo
, XVisualInfo
*vis
, int x
, int y
,
1034 unsigned int width
, unsigned int height
, int flags
,
1036 const char *classname
, const char *title
)
1038 struct MPOpts
*opts
= vo
->opts
;
1039 struct vo_x11_state
*x11
= vo
->x11
;
1040 Display
*mDisplay
= vo
->x11
->display
;
1043 x11
->window
= WinID
? (Window
)WinID
: x11
->rootwin
;
1044 if (col_map
!= CopyFromParent
) {
1045 unsigned long xswamask
= CWColormap
;
1046 XSetWindowAttributes xswa
;
1047 xswa
.colormap
= col_map
;
1048 XUnmapWindow(mDisplay
, x11
->window
);
1049 XChangeWindowAttributes(mDisplay
, x11
->window
, xswamask
, &xswa
);
1050 XMapWindow(mDisplay
, x11
->window
);
1052 if (WinID
) vo_x11_update_geometry(vo
);
1053 vo_x11_selectinput_witherr(mDisplay
, x11
->window
,
1054 StructureNotifyMask
| KeyPressMask
| PointerMotionMask
|
1055 ButtonPressMask
| ButtonReleaseMask
| ExposureMask
);
1058 if (x11
->window
== None
) {
1063 vo
->dheight
= height
;
1064 x11
->window
= vo_x11_create_smooth_window(x11
, x11
->rootwin
, vis
->visual
,
1065 x
, y
, width
, height
, vis
->depth
, col_map
);
1066 vo_x11_classhint(vo
, x11
->window
, classname
);
1067 XStoreName(mDisplay
, x11
->window
, title
);
1068 vo_hidecursor(mDisplay
, x11
->window
);
1069 XSelectInput(mDisplay
, x11
->window
, StructureNotifyMask
);
1070 hint
.x
= x
; hint
.y
= y
;
1071 hint
.width
= width
; hint
.height
= height
;
1072 hint
.flags
= PPosition
| PSize
;
1073 XSetStandardProperties(mDisplay
, x11
->window
, title
, title
, None
, NULL
, 0, &hint
);
1074 vo_x11_sizehint(vo
, x
, y
, width
, height
, 0);
1075 if (!vo_border
) vo_x11_decoration(vo
, 0);
1077 XMapWindow(mDisplay
, x11
->window
);
1078 XClearWindow(mDisplay
, x11
->window
);
1081 XNextEvent(mDisplay
, &xev
);
1082 } while (xev
.type
!= MapNotify
|| xev
.xmap
.event
!= x11
->window
);
1083 XSelectInput(mDisplay
, x11
->window
, NoEventMask
);
1084 XSync(mDisplay
, False
);
1085 vo_x11_selectinput_witherr(mDisplay
, x11
->window
,
1086 StructureNotifyMask
| KeyPressMask
| PointerMotionMask
|
1087 ButtonPressMask
| ButtonReleaseMask
| ExposureMask
);
1089 if (opts
->vo_ontop
) vo_x11_setlayer(vo
, x11
->window
, opts
->vo_ontop
);
1090 vo_x11_nofs_sizepos(vo
, vo
->dx
, vo
->dy
, width
, height
);
1091 if (!!vo_fs
!= !!(flags
& VOFLAG_FULLSCREEN
))
1092 vo_x11_fullscreen(vo
);
1094 if (x11
->vo_gc
!= None
)
1095 XFreeGC(mDisplay
, x11
->vo_gc
);
1096 x11
->vo_gc
= XCreateGC(mDisplay
, x11
->window
, GCForeground
, &xgcv
);
1097 XSync(mDisplay
, False
);
1098 x11
->vo_mouse_autohide
= 1;
1101 void vo_x11_clearwindow_part(struct vo
*vo
, Window vo_window
,
1102 int img_width
, int img_height
, int use_fs
)
1104 struct vo_x11_state
*x11
= vo
->x11
;
1105 struct MPOpts
*opts
= vo
->opts
;
1106 Display
*mDisplay
= vo
->x11
->display
;
1107 int u_dheight
, u_dwidth
, left_ov
, left_ov2
;
1112 u_dheight
= use_fs
? opts
->vo_screenheight
: vo
->dheight
;
1113 u_dwidth
= use_fs
? opts
->vo_screenwidth
: vo
->dwidth
;
1114 if ((u_dheight
<= img_height
) && (u_dwidth
<= img_width
))
1117 left_ov
= (u_dheight
- img_height
) / 2;
1118 left_ov2
= (u_dwidth
- img_width
) / 2;
1120 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, 0, 0, u_dwidth
, left_ov
);
1121 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, 0, u_dheight
- left_ov
- 1,
1122 u_dwidth
, left_ov
+ 1);
1124 if (u_dwidth
> img_width
)
1126 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, 0, left_ov
, left_ov2
,
1128 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, u_dwidth
- left_ov2
- 1,
1129 left_ov
, left_ov2
+ 1, img_height
);
1135 void vo_x11_clearwindow(struct vo
*vo
, Window vo_window
)
1137 struct vo_x11_state
*x11
= vo
->x11
;
1138 struct MPOpts
*opts
= vo
->opts
;
1141 XFillRectangle(x11
->display
, vo_window
, x11
->f_gc
, 0, 0,
1142 opts
->vo_screenwidth
, opts
->vo_screenheight
);
1144 XFlush(x11
->display
);
1148 void vo_x11_setlayer(struct vo
*vo
, Window vo_window
, int layer
)
1150 struct vo_x11_state
*x11
= vo
->x11
;
1154 if (x11
->fs_type
& vo_wm_LAYER
)
1156 XClientMessageEvent xev
;
1158 if (!x11
->orig_layer
)
1159 x11
->orig_layer
= vo_x11_get_gnome_layer(x11
, vo_window
);
1161 memset(&xev
, 0, sizeof(xev
));
1162 xev
.type
= ClientMessage
;
1163 xev
.display
= x11
->display
;
1164 xev
.window
= vo_window
;
1165 xev
.message_type
= x11
->XA_WIN_LAYER
;
1167 xev
.data
.l
[0] = layer
? fs_layer
: x11
->orig_layer
; // if not fullscreen, stay on default layer
1168 xev
.data
.l
[1] = CurrentTime
;
1169 mp_msg(MSGT_VO
, MSGL_V
,
1170 "[x11] Layered style stay on top (layer %ld).\n",
1172 XSendEvent(x11
->display
, x11
->rootwin
, False
, SubstructureNotifyMask
,
1174 } else if (x11
->fs_type
& vo_wm_NETWM
)
1176 XClientMessageEvent xev
;
1179 memset(&xev
, 0, sizeof(xev
));
1180 xev
.type
= ClientMessage
;
1181 xev
.message_type
= x11
->XA_NET_WM_STATE
;
1182 xev
.display
= x11
->display
;
1183 xev
.window
= vo_window
;
1185 xev
.data
.l
[0] = layer
;
1187 if (x11
->fs_type
& vo_wm_STAYS_ON_TOP
)
1188 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_STAYS_ON_TOP
;
1189 else if (x11
->fs_type
& vo_wm_ABOVE
)
1190 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_ABOVE
;
1191 else if (x11
->fs_type
& vo_wm_FULLSCREEN
)
1192 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_FULLSCREEN
;
1193 else if (x11
->fs_type
& vo_wm_BELOW
)
1194 // This is not fallback. We can safely assume that the situation
1195 // where only NETWM_STATE_BELOW is supported doesn't exist.
1196 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_BELOW
;
1198 XSendEvent(x11
->display
, x11
->rootwin
, False
, SubstructureRedirectMask
,
1200 state
= XGetAtomName(x11
->display
, xev
.data
.l
[1]);
1201 mp_msg(MSGT_VO
, MSGL_V
,
1202 "[x11] NET style stay on top (layer %d). Using state %s.\n",
1208 static int vo_x11_get_fs_type(int supported
)
1211 int type
= supported
;
1216 for (i
= 0; vo_fstype_list
[i
]; i
++)
1219 char *arg
= vo_fstype_list
[i
];
1221 if (vo_fstype_list
[i
][0] == '-')
1224 arg
= vo_fstype_list
[i
] + 1;
1227 if (!strncmp(arg
, "layer", 5))
1229 if (!neg
&& (arg
[5] == '='))
1231 char *endptr
= NULL
;
1232 int layer
= strtol(vo_fstype_list
[i
] + 6, &endptr
, 10);
1234 if (endptr
&& *endptr
== '\0' && layer
>= 0
1239 type
&= ~vo_wm_LAYER
;
1241 type
|= vo_wm_LAYER
;
1242 } else if (!strcmp(arg
, "above"))
1245 type
&= ~vo_wm_ABOVE
;
1247 type
|= vo_wm_ABOVE
;
1248 } else if (!strcmp(arg
, "fullscreen"))
1251 type
&= ~vo_wm_FULLSCREEN
;
1253 type
|= vo_wm_FULLSCREEN
;
1254 } else if (!strcmp(arg
, "stays_on_top"))
1257 type
&= ~vo_wm_STAYS_ON_TOP
;
1259 type
|= vo_wm_STAYS_ON_TOP
;
1260 } else if (!strcmp(arg
, "below"))
1263 type
&= ~vo_wm_BELOW
;
1265 type
|= vo_wm_BELOW
;
1266 } else if (!strcmp(arg
, "netwm"))
1269 type
&= ~vo_wm_NETWM
;
1271 type
|= vo_wm_NETWM
;
1272 } else if (!strcmp(arg
, "none"))
1281 * \brief update vo->dx, vo->dy, vo->dwidth and vo->dheight with current values of vo->x11->window
1282 * \return returns current color depth of vo->x11->window
1284 int vo_x11_update_geometry(struct vo
*vo
)
1286 struct vo_x11_state
*x11
= vo
->x11
;
1287 unsigned depth
, w
, h
;
1290 XGetGeometry(x11
->display
, x11
->window
, &dummy_win
, &dummy_int
, &dummy_int
,
1291 &w
, &h
, &dummy_int
, &depth
);
1292 if (w
<= INT_MAX
&& h
<= INT_MAX
) {
1296 XTranslateCoordinates(x11
->display
, x11
->window
, x11
->rootwin
, 0, 0,
1297 &vo
->dx
, &vo
->dy
, &dummy_win
);
1298 return depth
<= INT_MAX
? depth
: 0;
1301 void vo_x11_fullscreen(struct vo
*vo
)
1303 struct MPOpts
*opts
= vo
->opts
;
1304 struct vo_x11_state
*x11
= vo
->x11
;
1307 if (WinID
>= 0 || x11
->fs_flip
)
1313 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1317 w
= x11
->vo_old_width
;
1318 h
= x11
->vo_old_height
;
1321 vo_x11_ewmh_fullscreen(x11
, _NET_WM_STATE_REMOVE
); // removes fullscreen state if wm supports EWMH
1326 vo_x11_ewmh_fullscreen(x11
, _NET_WM_STATE_ADD
); // sends fullscreen state to be added if wm supports EWMH
1329 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1331 x11
->vo_old_x
= vo
->dx
;
1332 x11
->vo_old_y
= vo
->dy
;
1333 x11
->vo_old_width
= vo
->dwidth
;
1334 x11
->vo_old_height
= vo
->dheight
;
1336 update_xinerama_info(vo
);
1339 w
= opts
->vo_screenwidth
;
1340 h
= opts
->vo_screenheight
;
1345 XGetWMNormalHints(x11
->display
, x11
->window
, &x11
->vo_hint
, &dummy
);
1346 if (!(x11
->vo_hint
.flags
& PWinGravity
))
1347 x11
->old_gravity
= NorthWestGravity
;
1349 x11
->old_gravity
= x11
->vo_hint
.win_gravity
;
1351 if (x11
->wm_type
== 0 && !(vo_fsmode
& 16))
1353 XUnmapWindow(x11
->display
, x11
->window
); // required for MWM
1354 XWithdrawWindow(x11
->display
, x11
->window
, x11
->screen
);
1358 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1360 vo_x11_decoration(vo
, vo_border
&& !vo_fs
);
1361 vo_x11_sizehint(vo
, x
, y
, w
, h
, 0);
1362 vo_x11_setlayer(vo
, x11
->window
, vo_fs
);
1365 XMoveResizeWindow(x11
->display
, x11
->window
, x
, y
, w
, h
);
1367 /* some WMs lose ontop after fullscreen */
1368 if ((!(vo_fs
)) & opts
->vo_ontop
)
1369 vo_x11_setlayer(vo
, x11
->window
, opts
->vo_ontop
);
1371 XMapRaised(x11
->display
, x11
->window
);
1372 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // some WMs change window pos on map
1373 XMoveResizeWindow(x11
->display
, x11
->window
, x
, y
, w
, h
);
1374 XRaiseWindow(x11
->display
, x11
->window
);
1375 XFlush(x11
->display
);
1378 void vo_x11_ontop(struct vo
*vo
)
1380 struct MPOpts
*opts
= vo
->opts
;
1381 opts
->vo_ontop
= !opts
->vo_ontop
;
1383 vo_x11_setlayer(vo
, vo
->x11
->window
, opts
->vo_ontop
);
1386 void vo_x11_border(struct vo
*vo
)
1388 vo_border
= !vo_border
;
1389 vo_x11_decoration(vo
, vo_border
&& !vo_fs
);
1393 * XScreensaver stuff
1396 static int screensaver_off
;
1397 static unsigned int time_last
;
1399 void xscreensaver_heartbeat(struct vo_x11_state
*x11
)
1401 unsigned int time
= GetTimerMS();
1403 if (x11
->display
&& screensaver_off
&& (time
- time_last
) > 30000)
1407 XResetScreenSaver(x11
->display
);
1411 static int xss_suspend(Display
*mDisplay
, Bool suspend
)
1416 int event
, error
, major
, minor
;
1417 if (XScreenSaverQueryExtension(mDisplay
, &event
, &error
) != True
||
1418 XScreenSaverQueryVersion(mDisplay
, &major
, &minor
) != True
)
1420 if (major
< 1 || (major
== 1 && minor
< 1))
1422 XScreenSaverSuspend(mDisplay
, suspend
);
1428 * End of XScreensaver stuff
1431 static void saver_on(Display
* mDisplay
)
1434 if (!screensaver_off
)
1436 screensaver_off
= 0;
1437 if (xss_suspend(mDisplay
, False
))
1443 if (DPMSQueryExtension(mDisplay
, ¬hing
, ¬hing
))
1445 if (!DPMSEnable(mDisplay
))
1446 { // restoring power saving settings
1447 mp_msg(MSGT_VO
, MSGL_WARN
, "DPMS not available?\n");
1450 // DPMS does not seem to be enabled unless we call DPMSInfo
1454 DPMSForceLevel(mDisplay
, DPMSModeOn
);
1455 DPMSInfo(mDisplay
, &state
, &onoff
);
1458 mp_msg(MSGT_VO
, MSGL_V
,
1459 "Successfully enabled DPMS\n");
1462 mp_msg(MSGT_VO
, MSGL_WARN
, "Could not enable DPMS\n");
1471 static void saver_off(Display
* mDisplay
)
1475 if (screensaver_off
)
1477 screensaver_off
= 1;
1478 if (xss_suspend(mDisplay
, True
))
1481 if (DPMSQueryExtension(mDisplay
, ¬hing
, ¬hing
))
1486 DPMSInfo(mDisplay
, &state
, &onoff
);
1491 mp_msg(MSGT_VO
, MSGL_V
, "Disabling DPMS\n");
1493 stat
= DPMSDisable(mDisplay
); // monitor powersave off
1494 mp_msg(MSGT_VO
, MSGL_V
, "DPMSDisable stat: %d\n", stat
);
1500 static XErrorHandler old_handler
= NULL
;
1501 static int selectinput_err
= 0;
1502 static int x11_selectinput_errorhandler(Display
* display
,
1503 XErrorEvent
* event
)
1505 if (event
->error_code
== BadAccess
)
1507 selectinput_err
= 1;
1508 mp_msg(MSGT_VO
, MSGL_ERR
,
1509 "X11 error: BadAccess during XSelectInput Call\n");
1510 mp_msg(MSGT_VO
, MSGL_ERR
,
1511 "X11 error: The 'ButtonPressMask' mask of specified window has probably already used by another appication (see man XSelectInput)\n");
1512 /* If you think MPlayer should shutdown with this error,
1513 * comment out the following line */
1516 if (old_handler
!= NULL
)
1517 old_handler(display
, event
);
1519 x11_errorhandler(display
, event
);
1523 void vo_x11_selectinput_witherr(Display
* display
, Window w
,
1526 XSync(display
, False
);
1527 old_handler
= XSetErrorHandler(x11_selectinput_errorhandler
);
1528 selectinput_err
= 0;
1529 if (vo_nomouse_input
)
1531 XSelectInput(display
, w
,
1533 (~(ButtonPressMask
| ButtonReleaseMask
)));
1536 XSelectInput(display
, w
, event_mask
);
1538 XSync(display
, False
);
1539 XSetErrorHandler(old_handler
);
1540 if (selectinput_err
)
1542 mp_msg(MSGT_VO
, MSGL_ERR
,
1543 "X11 error: MPlayer discards mouse control (reconfiguring)\n");
1544 XSelectInput(display
, w
,
1547 (ButtonPressMask
| ButtonReleaseMask
|
1548 PointerMotionMask
)));
1552 #ifdef CONFIG_XF86VM
1553 void vo_vm_switch(struct vo
*vo
)
1555 struct vo_x11_state
*x11
= vo
->x11
;
1556 struct MPOpts
*opts
= vo
->opts
;
1557 Display
*mDisplay
= x11
->display
;
1558 int vm_event
, vm_error
;
1560 int i
, j
, have_vm
= 0;
1561 int X
= vo
->dwidth
, Y
= vo
->dheight
;
1562 int modeline_width
, modeline_height
;
1566 if (XF86VidModeQueryExtension(mDisplay
, &vm_event
, &vm_error
))
1568 XF86VidModeQueryVersion(mDisplay
, &vm_ver
, &vm_rev
);
1569 mp_msg(MSGT_VO
, MSGL_V
, "XF86VidMode extension v%i.%i\n", vm_ver
,
1573 mp_msg(MSGT_VO
, MSGL_WARN
,
1574 "XF86VidMode extension not available.\n");
1579 if (vidmodes
== NULL
)
1580 XF86VidModeGetAllModeLines(mDisplay
, x11
->screen
, &modecount
,
1583 modeline_width
= vidmodes
[0]->hdisplay
;
1584 modeline_height
= vidmodes
[0]->vdisplay
;
1586 for (i
= 1; i
< modecount
; i
++)
1587 if ((vidmodes
[i
]->hdisplay
>= X
)
1588 && (vidmodes
[i
]->vdisplay
>= Y
))
1589 if ((vidmodes
[i
]->hdisplay
<= modeline_width
)
1590 && (vidmodes
[i
]->vdisplay
<= modeline_height
))
1592 modeline_width
= vidmodes
[i
]->hdisplay
;
1593 modeline_height
= vidmodes
[i
]->vdisplay
;
1597 mp_msg(MSGT_VO
, MSGL_INFO
, MSGTR_SelectedVideoMode
,
1598 modeline_width
, modeline_height
, X
, Y
);
1599 XF86VidModeLockModeSwitch(mDisplay
, x11
->screen
, 0);
1600 XF86VidModeSwitchToMode(mDisplay
, x11
->screen
, vidmodes
[j
]);
1601 XF86VidModeSwitchToMode(mDisplay
, x11
->screen
, vidmodes
[j
]);
1603 // FIXME: all this is more of a hack than proper solution
1604 X
= (opts
->vo_screenwidth
- modeline_width
) / 2;
1605 Y
= (opts
->vo_screenheight
- modeline_height
) / 2;
1606 XF86VidModeSetViewPort(mDisplay
, x11
->screen
, X
, Y
);
1609 vo
->dwidth
= modeline_width
;
1610 vo
->dheight
= modeline_height
;
1611 aspect_save_screenres(vo
, modeline_width
, modeline_height
);
1615 void vo_vm_close(struct vo
*vo
)
1617 Display
*dpy
= vo
->x11
->display
;
1618 struct MPOpts
*opts
= vo
->opts
;
1620 if (vidmodes
!= NULL
&& vo
->x11
->vo_window
!= None
)
1622 if (vidmodes
!= NULL
)
1629 XF86VidModeGetAllModeLines(dpy
, vo
->x11
->screen
, &modecount
,
1631 for (i
= 0; i
< modecount
; i
++)
1632 if ((vidmodes
[i
]->hdisplay
== opts
->vo_screenwidth
)
1633 && (vidmodes
[i
]->vdisplay
== opts
->vo_screenheight
))
1635 mp_msg(MSGT_VO
, MSGL_INFO
,
1636 "Returning to original mode %dx%d\n",
1637 opts
->vo_screenwidth
, opts
->vo_screenheight
);
1641 XF86VidModeSwitchToMode(dpy
, vo
->x11
->screen
, vidmodes
[i
]);
1642 XF86VidModeSwitchToMode(dpy
, vo
->x11
->screen
, vidmodes
[i
]);
1649 #endif /* X11_FULLSCREEN */
1653 * Scan the available visuals on this Display/Screen. Try to find
1654 * the 'best' available TrueColor visual that has a decent color
1655 * depth (at least 15bit). If there are multiple visuals with depth
1656 * >= 15bit, we prefer visuals with a smaller color depth.
1658 int vo_find_depth_from_visuals(Display
* dpy
, int screen
,
1659 Visual
** visual_return
)
1661 XVisualInfo visual_tmpl
;
1662 XVisualInfo
*visuals
;
1664 int bestvisual
= -1;
1665 int bestvisual_depth
= -1;
1667 visual_tmpl
.screen
= screen
;
1668 visual_tmpl
.class = TrueColor
;
1669 visuals
= XGetVisualInfo(dpy
,
1670 VisualScreenMask
| VisualClassMask
,
1671 &visual_tmpl
, &nvisuals
);
1672 if (visuals
!= NULL
)
1674 for (i
= 0; i
< nvisuals
; i
++)
1676 mp_msg(MSGT_VO
, MSGL_V
,
1677 "vo: X11 truecolor visual %#lx, depth %d, R:%lX G:%lX B:%lX\n",
1678 visuals
[i
].visualid
, visuals
[i
].depth
,
1679 visuals
[i
].red_mask
, visuals
[i
].green_mask
,
1680 visuals
[i
].blue_mask
);
1682 * Save the visual index and its depth, if this is the first
1683 * truecolor visul, or a visual that is 'preferred' over the
1684 * previous 'best' visual.
1686 if (bestvisual_depth
== -1
1687 || (visuals
[i
].depth
>= 15
1688 && (visuals
[i
].depth
< bestvisual_depth
1689 || bestvisual_depth
< 15)))
1692 bestvisual_depth
= visuals
[i
].depth
;
1696 if (bestvisual
!= -1 && visual_return
!= NULL
)
1697 *visual_return
= visuals
[bestvisual
].visual
;
1701 return bestvisual_depth
;
1705 static Colormap cmap
= None
;
1706 static XColor cols
[256];
1707 static int cm_size
, red_mask
, green_mask
, blue_mask
;
1710 Colormap
vo_x11_create_colormap(struct vo
*vo
, XVisualInfo
*vinfo
)
1712 struct vo_x11_state
*x11
= vo
->x11
;
1713 unsigned k
, r
, g
, b
, ru
, gu
, bu
, m
, rv
, gv
, bv
, rvu
, gvu
, bvu
;
1715 if (vinfo
->class != DirectColor
)
1716 return XCreateColormap(x11
->display
, x11
->rootwin
, vinfo
->visual
,
1719 /* can this function get called twice or more? */
1722 cm_size
= vinfo
->colormap_size
;
1723 red_mask
= vinfo
->red_mask
;
1724 green_mask
= vinfo
->green_mask
;
1725 blue_mask
= vinfo
->blue_mask
;
1726 ru
= (red_mask
& (red_mask
- 1)) ^ red_mask
;
1727 gu
= (green_mask
& (green_mask
- 1)) ^ green_mask
;
1728 bu
= (blue_mask
& (blue_mask
- 1)) ^ blue_mask
;
1729 rvu
= 65536ull * ru
/ (red_mask
+ ru
);
1730 gvu
= 65536ull * gu
/ (green_mask
+ gu
);
1731 bvu
= 65536ull * bu
/ (blue_mask
+ bu
);
1734 m
= DoRed
| DoGreen
| DoBlue
;
1735 for (k
= 0; k
< cm_size
; k
++)
1739 cols
[k
].pixel
= r
| g
| b
;
1744 t
= (r
+ ru
) & red_mask
;
1748 t
= (g
+ gu
) & green_mask
;
1752 t
= (b
+ bu
) & blue_mask
;
1760 cmap
= XCreateColormap(x11
->display
, x11
->rootwin
, vinfo
->visual
, AllocAll
);
1761 XStoreColors(x11
->display
, cmap
, cols
, cm_size
);
1766 * Via colormaps/gamma ramps we can do gamma, brightness, contrast,
1767 * hue and red/green/blue intensity, but we cannot do saturation.
1768 * Currently only gamma, brightness and contrast are implemented.
1769 * Is there sufficient interest for hue and/or red/green/blue intensity?
1771 /* these values have range [-100,100] and are initially 0 */
1772 static int vo_gamma
= 0;
1773 static int vo_brightness
= 0;
1774 static int vo_contrast
= 0;
1776 static int transform_color(float val
,
1777 float brightness
, float contrast
, float gamma
) {
1778 float s
= pow(val
, gamma
);
1779 s
= (s
- 0.5) * contrast
+ 0.5;
1785 return (unsigned short) (s
* 65535);
1788 uint32_t vo_x11_set_equalizer(struct vo
*vo
, char *name
, int value
)
1790 float gamma
, brightness
, contrast
;
1795 * IMPLEMENTME: consider using XF86VidModeSetGammaRamp in the case
1796 * of TrueColor-ed window but be careful:
1797 * Unlike the colormaps, which are private for the X client
1798 * who created them and thus automatically destroyed on client
1799 * disconnect, this gamma ramp is a system-wide (X-server-wide)
1800 * setting and _must_ be restored before the process exits.
1801 * Unforunately when the process crashes (or gets killed
1802 * for some reason) it is impossible to restore the setting,
1803 * and such behaviour could be rather annoying for the users.
1808 if (!strcasecmp(name
, "brightness"))
1809 vo_brightness
= value
;
1810 else if (!strcasecmp(name
, "contrast"))
1811 vo_contrast
= value
;
1812 else if (!strcasecmp(name
, "gamma"))
1817 brightness
= 0.01 * vo_brightness
;
1818 contrast
= tan(0.0095 * (vo_contrast
+ 100) * M_PI
/ 4);
1819 gamma
= pow(2, -0.02 * vo_gamma
);
1821 rf
= (float) ((red_mask
& (red_mask
- 1)) ^ red_mask
) / red_mask
;
1822 gf
= (float) ((green_mask
& (green_mask
- 1)) ^ green_mask
) /
1824 bf
= (float) ((blue_mask
& (blue_mask
- 1)) ^ blue_mask
) / blue_mask
;
1826 /* now recalculate the colormap using the newly set value */
1827 for (k
= 0; k
< cm_size
; k
++)
1829 cols
[k
].red
= transform_color(rf
* k
, brightness
, contrast
, gamma
);
1830 cols
[k
].green
= transform_color(gf
* k
, brightness
, contrast
, gamma
);
1831 cols
[k
].blue
= transform_color(bf
* k
, brightness
, contrast
, gamma
);
1834 XStoreColors(vo
->x11
->display
, cmap
, cols
, cm_size
);
1835 XFlush(vo
->x11
->display
);
1839 uint32_t vo_x11_get_equalizer(char *name
, int *value
)
1843 if (!strcasecmp(name
, "brightness"))
1844 *value
= vo_brightness
;
1845 else if (!strcasecmp(name
, "contrast"))
1846 *value
= vo_contrast
;
1847 else if (!strcasecmp(name
, "gamma"))
1855 int vo_xv_set_eq(struct vo
*vo
, uint32_t xv_port
, char *name
, int value
)
1857 XvAttribute
*attributes
;
1858 int i
, howmany
, xv_atom
;
1860 mp_dbg(MSGT_VO
, MSGL_V
, "xv_set_eq called! (%s, %d)\n", name
, value
);
1862 /* get available attributes */
1863 attributes
= XvQueryPortAttributes(vo
->x11
->display
, xv_port
, &howmany
);
1864 for (i
= 0; i
< howmany
&& attributes
; i
++)
1865 if (attributes
[i
].flags
& XvSettable
)
1867 xv_atom
= XInternAtom(vo
->x11
->display
, attributes
[i
].name
, True
);
1868 /* since we have SET_DEFAULTS first in our list, we can check if it's available
1869 then trigger it if it's ok so that the other values are at default upon query */
1870 if (xv_atom
!= None
)
1872 int hue
= 0, port_value
, port_min
, port_max
;
1874 if (!strcmp(attributes
[i
].name
, "XV_BRIGHTNESS") &&
1875 (!strcasecmp(name
, "brightness")))
1877 else if (!strcmp(attributes
[i
].name
, "XV_CONTRAST") &&
1878 (!strcasecmp(name
, "contrast")))
1880 else if (!strcmp(attributes
[i
].name
, "XV_SATURATION") &&
1881 (!strcasecmp(name
, "saturation")))
1883 else if (!strcmp(attributes
[i
].name
, "XV_HUE") &&
1884 (!strcasecmp(name
, "hue")))
1889 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
1890 if (!strcmp(attributes
[i
].name
, "XV_RED_INTENSITY") &&
1891 (!strcasecmp(name
, "red_intensity")))
1893 else if (!strcmp(attributes
[i
].name
, "XV_GREEN_INTENSITY")
1894 && (!strcasecmp(name
, "green_intensity")))
1896 else if (!strcmp(attributes
[i
].name
, "XV_BLUE_INTENSITY")
1897 && (!strcasecmp(name
, "blue_intensity")))
1902 port_min
= attributes
[i
].min_value
;
1903 port_max
= attributes
[i
].max_value
;
1905 /* nvidia hue workaround */
1906 if (hue
&& port_min
== 0 && port_max
== 360)
1910 0) ? (port_value
- 100) : (port_value
+ 100);
1916 (port_value
+ 100) * (port_max
- port_min
) / 200 +
1918 XvSetPortAttribute(vo
->x11
->display
, xv_port
, xv_atom
, port_value
);
1925 int vo_xv_get_eq(struct vo
*vo
, uint32_t xv_port
, char *name
, int *value
)
1928 XvAttribute
*attributes
;
1929 int i
, howmany
, xv_atom
;
1931 /* get available attributes */
1932 attributes
= XvQueryPortAttributes(vo
->x11
->display
, xv_port
, &howmany
);
1933 for (i
= 0; i
< howmany
&& attributes
; i
++)
1934 if (attributes
[i
].flags
& XvGettable
)
1936 xv_atom
= XInternAtom(vo
->x11
->display
, attributes
[i
].name
, True
);
1937 /* since we have SET_DEFAULTS first in our list, we can check if it's available
1938 then trigger it if it's ok so that the other values are at default upon query */
1939 if (xv_atom
!= None
)
1941 int val
, port_value
= 0, port_min
, port_max
;
1943 XvGetPortAttribute(vo
->x11
->display
, xv_port
, xv_atom
,
1946 port_min
= attributes
[i
].min_value
;
1947 port_max
= attributes
[i
].max_value
;
1949 (port_value
- port_min
) * 200 / (port_max
- port_min
) -
1952 if (!strcmp(attributes
[i
].name
, "XV_BRIGHTNESS") &&
1953 (!strcasecmp(name
, "brightness")))
1955 else if (!strcmp(attributes
[i
].name
, "XV_CONTRAST") &&
1956 (!strcasecmp(name
, "contrast")))
1958 else if (!strcmp(attributes
[i
].name
, "XV_SATURATION") &&
1959 (!strcasecmp(name
, "saturation")))
1961 else if (!strcmp(attributes
[i
].name
, "XV_HUE") &&
1962 (!strcasecmp(name
, "hue")))
1964 /* nasty nvidia detect */
1965 if (port_min
== 0 && port_max
== 360)
1966 *value
= (val
>= 0) ? (val
- 100) : (val
+ 100);
1970 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
1971 if (!strcmp(attributes
[i
].name
, "XV_RED_INTENSITY") &&
1972 (!strcasecmp(name
, "red_intensity")))
1974 else if (!strcmp(attributes
[i
].name
, "XV_GREEN_INTENSITY")
1975 && (!strcasecmp(name
, "green_intensity")))
1977 else if (!strcmp(attributes
[i
].name
, "XV_BLUE_INTENSITY")
1978 && (!strcasecmp(name
, "blue_intensity")))
1983 mp_dbg(MSGT_VO
, MSGL_V
, "xv_get_eq called! (%s, %d)\n",
1992 * \brief Interns the requested atom if it is available.
1994 * \param atom_name String containing the name of the requested atom.
1996 * \return Returns the atom if available, else None is returned.
1999 static Atom
xv_intern_atom_if_exists(struct vo_x11_state
*x11
,
2000 char const *atom_name
)
2002 XvAttribute
* attributes
;
2004 Atom xv_atom
= None
;
2006 attributes
= XvQueryPortAttributes(x11
->display
, x11
->xv_port
, &attrib_count
);
2007 if( attributes
!=NULL
)
2009 for ( i
= 0; i
< attrib_count
; ++i
)
2011 if ( strcmp(attributes
[i
].name
, atom_name
) == 0 )
2013 xv_atom
= XInternAtom(x11
->display
, atom_name
, False
);
2014 break; // found what we want, break out
2017 XFree( attributes
);
2024 * \brief Try to enable vsync for xv.
2025 * \return Returns -1 if not available, 0 on failure and 1 on success.
2027 int vo_xv_enable_vsync(struct vo
*vo
)
2029 struct vo_x11_state
*x11
= vo
->x11
;
2030 Atom xv_atom
= xv_intern_atom_if_exists(x11
, "XV_SYNC_TO_VBLANK");
2031 if (xv_atom
== None
)
2033 return XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, 1) == Success
;
2037 * \brief Get maximum supported source image dimensions.
2039 * This function does not set the variables pointed to by
2040 * width and height if the information could not be retrieved,
2041 * so the caller is reponsible for properly initializing them.
2043 * \param width [out] The maximum width gets stored here.
2044 * \param height [out] The maximum height gets stored here.
2047 void vo_xv_get_max_img_dim(struct vo
*vo
, uint32_t * width
, uint32_t * height
)
2049 struct vo_x11_state
*x11
= vo
->x11
;
2050 XvEncodingInfo
* encodings
;
2051 //unsigned long num_encodings, idx; to int or too long?!
2052 unsigned int num_encodings
, idx
;
2054 XvQueryEncodings(x11
->display
, x11
->xv_port
, &num_encodings
, &encodings
);
2058 for ( idx
= 0; idx
< num_encodings
; ++idx
)
2060 if ( strcmp( encodings
[idx
].name
, "XV_IMAGE" ) == 0 )
2062 *width
= encodings
[idx
].width
;
2063 *height
= encodings
[idx
].height
;
2069 mp_msg( MSGT_VO
, MSGL_V
,
2070 "[xv common] Maximum source image dimensions: %ux%u\n",
2073 XvFreeEncodingInfo( encodings
);
2077 * \brief Print information about the colorkey method and source.
2079 * \param ck_handling Integer value containing the information about
2080 * colorkey handling (see x11_common.h).
2082 * Outputs the content of |ck_handling| as a readable message.
2085 static void vo_xv_print_ck_info(struct vo_x11_state
*x11
)
2087 mp_msg( MSGT_VO
, MSGL_V
, "[xv common] " );
2089 switch ( x11
->xv_ck_info
.method
)
2091 case CK_METHOD_NONE
:
2092 mp_msg( MSGT_VO
, MSGL_V
, "Drawing no colorkey.\n" ); return;
2093 case CK_METHOD_AUTOPAINT
:
2094 mp_msg( MSGT_VO
, MSGL_V
, "Colorkey is drawn by Xv." ); break;
2095 case CK_METHOD_MANUALFILL
:
2096 mp_msg( MSGT_VO
, MSGL_V
, "Drawing colorkey manually." ); break;
2097 case CK_METHOD_BACKGROUND
:
2098 mp_msg( MSGT_VO
, MSGL_V
, "Colorkey is drawn as window background." ); break;
2101 mp_msg( MSGT_VO
, MSGL_V
, "\n[xv common] " );
2103 switch ( x11
->xv_ck_info
.source
)
2106 mp_msg( MSGT_VO
, MSGL_V
, "Using colorkey from Xv (0x%06lx).\n",
2110 if ( x11
->xv_ck_info
.method
== CK_METHOD_AUTOPAINT
)
2112 mp_msg( MSGT_VO
, MSGL_V
,
2113 "Ignoring colorkey from MPlayer (0x%06lx).\n",
2118 mp_msg( MSGT_VO
, MSGL_V
,
2119 "Using colorkey from MPlayer (0x%06lx)."
2120 " Use -colorkey to change.\n",
2125 mp_msg( MSGT_VO
, MSGL_V
,
2126 "Setting and using colorkey from MPlayer (0x%06lx)."
2127 " Use -colorkey to change.\n",
2133 * \brief Init colorkey depending on the settings in xv_ck_info.
2135 * \return Returns 0 on failure and 1 on success.
2137 * Sets the colorkey variable according to the CK_SRC_* and CK_METHOD_*
2138 * flags in xv_ck_info.
2142 * - manual colorkey drawing ( CK_METHOD_MANUALFILL )
2143 * - set colorkey as window background ( CK_METHOD_BACKGROUND )
2144 * - let Xv paint the colorkey ( CK_METHOD_AUTOPAINT )
2146 * - use currently set colorkey ( CK_SRC_CUR )
2147 * - use colorkey in vo_colorkey ( CK_SRC_USE )
2148 * - use and set colorkey in vo_colorkey ( CK_SRC_SET )
2150 * NOTE: If vo_colorkey has bits set after the first 3 low order bytes
2151 * we don't draw anything as this means it was forced to off.
2153 int vo_xv_init_colorkey(struct vo
*vo
)
2155 struct vo_x11_state
*x11
= vo
->x11
;
2159 /* check if colorkeying is needed */
2160 xv_atom
= xv_intern_atom_if_exists(vo
->x11
, "XV_COLORKEY");
2162 /* if we have to deal with colorkeying ... */
2163 if( xv_atom
!= None
&& !(vo_colorkey
& 0xFF000000) )
2165 /* check if we should use the colorkey specified in vo_colorkey */
2166 if ( x11
->xv_ck_info
.source
!= CK_SRC_CUR
)
2168 x11
->xv_colorkey
= vo_colorkey
;
2170 /* check if we have to set the colorkey too */
2171 if ( x11
->xv_ck_info
.source
== CK_SRC_SET
)
2173 xv_atom
= XInternAtom(x11
->display
, "XV_COLORKEY",False
);
2175 rez
= XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, vo_colorkey
);
2176 if ( rez
!= Success
)
2178 mp_msg( MSGT_VO
, MSGL_FATAL
,
2179 "[xv common] Couldn't set colorkey!\n" );
2180 return 0; // error setting colorkey
2188 rez
=XvGetPortAttribute(x11
->display
,x11
->xv_port
, xv_atom
, &colorkey_ret
);
2189 if ( rez
== Success
)
2191 x11
->xv_colorkey
= colorkey_ret
;
2195 mp_msg( MSGT_VO
, MSGL_FATAL
,
2196 "[xv common] Couldn't get colorkey!"
2197 "Maybe the selected Xv port has no overlay.\n" );
2198 return 0; // error getting colorkey
2202 xv_atom
= xv_intern_atom_if_exists(vo
->x11
, "XV_AUTOPAINT_COLORKEY");
2204 /* should we draw the colorkey ourselves or activate autopainting? */
2205 if ( x11
->xv_ck_info
.method
== CK_METHOD_AUTOPAINT
)
2207 rez
= !Success
; // reset rez to something different than Success
2209 if ( xv_atom
!= None
) // autopaint is supported
2211 rez
= XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, 1);
2214 if ( rez
!= Success
)
2216 // fallback to manual colorkey drawing
2217 x11
->xv_ck_info
.method
= CK_METHOD_MANUALFILL
;
2220 else // disable colorkey autopainting if supported
2222 if ( xv_atom
!= None
) // we have autopaint attribute
2224 XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, 0);
2228 else // do no colorkey drawing at all
2230 x11
->xv_ck_info
.method
= CK_METHOD_NONE
;
2231 } /* end: should we draw colorkey */
2233 /* output information about the current colorkey settings */
2234 vo_xv_print_ck_info(x11
);
2236 return 1; // success
2240 * \brief Draw the colorkey on the video window.
2242 * Draws the colorkey depending on the set method ( colorkey_handling ).
2244 * Also draws the black bars ( when the video doesn't fit the display in
2245 * fullscreen ) separately, so they don't overlap with the video area.
2246 * It doesn't call XFlush.
2249 void vo_xv_draw_colorkey(struct vo
*vo
, int32_t x
, int32_t y
,
2250 int32_t w
, int32_t h
)
2252 struct MPOpts
*opts
= vo
->opts
;
2253 struct vo_x11_state
*x11
= vo
->x11
;
2254 if( x11
->xv_ck_info
.method
== CK_METHOD_MANUALFILL
||
2255 x11
->xv_ck_info
.method
== CK_METHOD_BACKGROUND
)//less tearing than XClearWindow()
2257 XSetForeground(x11
->display
, x11
->vo_gc
, x11
->xv_colorkey
);
2258 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2263 /* draw black bars if needed */
2264 /* TODO! move this to vo_x11_clearwindow_part() */
2267 XSetForeground(x11
->display
, x11
->vo_gc
, 0 );
2268 /* making non-overlap fills, requires 8 checks instead of 4 */
2270 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2272 opts
->vo_screenwidth
, y
);
2274 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2276 x
, opts
->vo_screenheight
);
2277 if (x
+ w
< opts
->vo_screenwidth
)
2278 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2280 opts
->vo_screenwidth
, opts
->vo_screenheight
);
2281 if (y
+ h
< opts
->vo_screenheight
)
2282 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2284 opts
->vo_screenwidth
, opts
->vo_screenheight
);
2288 /** \brief Tests if a valid argument for the ck suboption was given. */
2289 int xv_test_ck( void * arg
)
2291 strarg_t
* strarg
= (strarg_t
*)arg
;
2293 if ( strargcmp( strarg
, "use" ) == 0 ||
2294 strargcmp( strarg
, "set" ) == 0 ||
2295 strargcmp( strarg
, "cur" ) == 0 )
2302 /** \brief Tests if a valid arguments for the ck-method suboption was given. */
2303 int xv_test_ckm( void * arg
)
2305 strarg_t
* strarg
= (strarg_t
*)arg
;
2307 if ( strargcmp( strarg
, "bg" ) == 0 ||
2308 strargcmp( strarg
, "man" ) == 0 ||
2309 strargcmp( strarg
, "auto" ) == 0 )
2318 * \brief Modify the colorkey_handling var according to str
2320 * Checks if a valid pointer ( not NULL ) to the string
2321 * was given. And in that case modifies the colorkey_handling
2322 * var to reflect the requested behaviour.
2323 * If nothing happens the content of colorkey_handling stays
2326 * \param str Pointer to the string or NULL
2329 void xv_setup_colorkeyhandling(struct vo
*vo
, const char *ck_method_str
,
2332 struct vo_x11_state
*x11
= vo
->x11
;
2333 /* check if a valid pointer to the string was passed */
2336 if ( strncmp( ck_str
, "use", 3 ) == 0 )
2338 x11
->xv_ck_info
.source
= CK_SRC_USE
;
2340 else if ( strncmp( ck_str
, "set", 3 ) == 0 )
2342 x11
->xv_ck_info
.source
= CK_SRC_SET
;
2345 /* check if a valid pointer to the string was passed */
2346 if ( ck_method_str
)
2348 if ( strncmp( ck_method_str
, "bg", 2 ) == 0 )
2350 x11
->xv_ck_info
.method
= CK_METHOD_BACKGROUND
;
2352 else if ( strncmp( ck_method_str
, "man", 3 ) == 0 )
2354 x11
->xv_ck_info
.method
= CK_METHOD_MANUALFILL
;
2356 else if ( strncmp( ck_method_str
, "auto", 4 ) == 0 )
2358 x11
->xv_ck_info
.method
= CK_METHOD_AUTOPAINT
;
2365 struct vo_x11_state
*vo_x11_init_state(void)
2367 struct vo_x11_state
*s
= talloc_ptrtype(NULL
, s
);
2368 *s
= (struct vo_x11_state
){
2369 .xv_ck_info
= { CK_METHOD_MANUALFILL
, CK_SRC_CUR
},
2370 .olddecor
= MWM_DECOR_ALL
,
2371 .oldfuncs
= MWM_FUNC_MOVE
| MWM_FUNC_CLOSE
| MWM_FUNC_MINIMIZE
|
2372 MWM_FUNC_MAXIMIZE
| MWM_FUNC_RESIZE
,
2373 .old_gravity
= NorthWestGravity
,