2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include "libavutil/common.h"
30 #include "x11_common.h"
39 #include "video_out.h"
42 #include "osdep/timer.h"
46 #include <X11/Xutil.h>
47 #include <X11/Xatom.h>
50 #include <X11/extensions/scrnsaver.h>
54 #include <X11/extensions/dpms.h>
57 #ifdef CONFIG_XINERAMA
58 #include <X11/extensions/Xinerama.h>
62 #include <X11/extensions/xf86vmode.h>
66 #include <X11/XF86keysym.h>
70 #include <X11/extensions/Xv.h>
71 #include <X11/extensions/Xvlib.h>
73 #include "subopt-helper.h"
76 #include "input/input.h"
77 #include "input/mouse.h"
79 #define WIN_LAYER_ONBOTTOM 2
80 #define WIN_LAYER_NORMAL 4
81 #define WIN_LAYER_ONTOP 6
82 #define WIN_LAYER_ABOVE_DOCK 10
84 int fs_layer
= WIN_LAYER_ABOVE_DOCK
;
86 int stop_xscreensaver
= 0;
88 static int dpms_disabled
= 0;
90 char *mDisplayName
= NULL
;
92 char **vo_fstype_list
;
94 /* 1 means that the WM is metacity (broken as hell) */
95 int metacity_hack
= 0;
98 XF86VidModeModeInfo
**vidmodes
= NULL
;
99 XF86VidModeModeLine modeline
;
102 static int vo_x11_get_fs_type(int supported
);
103 static void saver_off(Display
*);
104 static void saver_on(Display
*);
107 * Sends the EWMH fullscreen state event.
109 * action: could be one of _NET_WM_STATE_REMOVE -- remove state
110 * _NET_WM_STATE_ADD -- add state
111 * _NET_WM_STATE_TOGGLE -- toggle
113 void vo_x11_ewmh_fullscreen(struct vo_x11_state
*x11
, int action
)
115 assert(action
== _NET_WM_STATE_REMOVE
||
116 action
== _NET_WM_STATE_ADD
|| action
== _NET_WM_STATE_TOGGLE
);
118 if (x11
->fs_type
& vo_wm_FULLSCREEN
)
122 /* init X event structure for _NET_WM_FULLSCREEN client message */
123 xev
.xclient
.type
= ClientMessage
;
124 xev
.xclient
.serial
= 0;
125 xev
.xclient
.send_event
= True
;
126 xev
.xclient
.message_type
= x11
->XA_NET_WM_STATE
;
127 xev
.xclient
.window
= x11
->window
;
128 xev
.xclient
.format
= 32;
129 xev
.xclient
.data
.l
[0] = action
;
130 xev
.xclient
.data
.l
[1] = x11
->XA_NET_WM_STATE_FULLSCREEN
;
131 xev
.xclient
.data
.l
[2] = 0;
132 xev
.xclient
.data
.l
[3] = 0;
133 xev
.xclient
.data
.l
[4] = 0;
135 /* finally send that damn thing */
136 if (!XSendEvent(x11
->display
, DefaultRootWindow(x11
->display
), False
,
137 SubstructureRedirectMask
| SubstructureNotifyMask
,
140 mp_tmsg(MSGT_VO
, MSGL_ERR
, "\nX11: Couldn't send EWMH fullscreen event!\n");
145 static void vo_hidecursor(Display
* disp
, Window win
)
151 const char bm_no_data
[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
154 return; // do not hide if playing on the root window
156 colormap
= DefaultColormap(disp
, DefaultScreen(disp
));
157 if ( !XAllocNamedColor(disp
, colormap
, "black", &black
, &dummy
) )
159 return; // color alloc failed, give up
161 bm_no
= XCreateBitmapFromData(disp
, win
, bm_no_data
, 8, 8);
162 no_ptr
= XCreatePixmapCursor(disp
, bm_no
, bm_no
, &black
, &black
, 0, 0);
163 XDefineCursor(disp
, win
, no_ptr
);
164 XFreeCursor(disp
, no_ptr
);
166 XFreePixmap(disp
, bm_no
);
167 XFreeColors(disp
,colormap
,&black
.pixel
,1,0);
170 static void vo_showcursor(Display
* disp
, Window win
)
174 XDefineCursor(disp
, win
, 0);
177 static int x11_errorhandler(Display
* display
, XErrorEvent
* event
)
182 XGetErrorText(display
, event
->error_code
, (char *) &msg
, MSGLEN
);
184 mp_msg(MSGT_VO
, MSGL_ERR
, "X11 error: %s\n", msg
);
186 mp_msg(MSGT_VO
, MSGL_V
,
187 "Type: %x, display: %p, resourceid: %lx, serial: %lx\n",
188 event
->type
, event
->display
, event
->resourceid
, event
->serial
);
189 mp_msg(MSGT_VO
, MSGL_V
,
190 "Error code: %x, request code: %x, minor code: %x\n",
191 event
->error_code
, event
->request_code
, event
->minor_code
);
194 //exit_player("X11 error");
199 void fstype_help(void)
201 mp_tmsg(MSGT_VO
, MSGL_INFO
, "Available fullscreen layer change modes:\n");
202 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FULL_SCREEN_TYPES\n");
204 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "none",
205 "don't set fullscreen window layer");
206 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "layer",
207 "use _WIN_LAYER hint with default layer");
208 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "layer=<0..15>",
209 "use _WIN_LAYER hint with a given layer number");
210 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "netwm",
211 "force NETWM style");
212 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "above",
213 "use _NETWM_STATE_ABOVE hint if available");
214 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "below",
215 "use _NETWM_STATE_BELOW hint if available");
216 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "fullscreen",
217 "use _NETWM_STATE_FULLSCREEN hint if available");
218 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "stays_on_top",
219 "use _NETWM_STATE_STAYS_ON_TOP hint if available");
220 mp_msg(MSGT_VO
, MSGL_INFO
,
221 "You can also negate the settings with simply putting '-' in the beginning");
222 mp_msg(MSGT_VO
, MSGL_INFO
, "\n");
225 static void fstype_dump(int fstype
)
229 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Current fstype setting honours");
230 if (fstype
& vo_wm_LAYER
)
231 mp_msg(MSGT_VO
, MSGL_V
, " LAYER");
232 if (fstype
& vo_wm_FULLSCREEN
)
233 mp_msg(MSGT_VO
, MSGL_V
, " FULLSCREEN");
234 if (fstype
& vo_wm_STAYS_ON_TOP
)
235 mp_msg(MSGT_VO
, MSGL_V
, " STAYS_ON_TOP");
236 if (fstype
& vo_wm_ABOVE
)
237 mp_msg(MSGT_VO
, MSGL_V
, " ABOVE");
238 if (fstype
& vo_wm_BELOW
)
239 mp_msg(MSGT_VO
, MSGL_V
, " BELOW");
240 mp_msg(MSGT_VO
, MSGL_V
, " X atoms\n");
242 mp_msg(MSGT_VO
, MSGL_V
,
243 "[x11] Current fstype setting doesn't honour any X atoms\n");
246 static int net_wm_support_state_test(struct vo_x11_state
*x11
, Atom atom
)
248 #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; } }
250 NET_WM_STATE_TEST(FULLSCREEN
);
251 NET_WM_STATE_TEST(ABOVE
);
252 NET_WM_STATE_TEST(STAYS_ON_TOP
);
253 NET_WM_STATE_TEST(BELOW
);
257 static int x11_get_property(struct vo_x11_state
*x11
, Atom type
, Atom
** args
,
258 unsigned long *nitems
)
261 unsigned long bytesafter
;
264 XGetWindowProperty(x11
->display
, x11
->rootwin
, type
, 0, 16384, False
,
265 AnyPropertyType
, &type
, &format
, nitems
,
266 &bytesafter
, (unsigned char **) args
)
270 static int vo_wm_detect(struct vo
*vo
)
272 struct vo_x11_state
*x11
= vo
->x11
;
275 unsigned long nitems
;
281 // -- supports layers
282 if (x11_get_property(x11
, x11
->XA_WIN_PROTOCOLS
, &args
, &nitems
))
284 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Detected wm supports layers.\n");
285 for (i
= 0; i
< nitems
; i
++)
287 if (args
[i
] == x11
->XA_WIN_LAYER
)
292 /* metacity is the only window manager I know which reports
293 * supporting only the _WIN_LAYER hint in _WIN_PROTOCOLS.
294 * (what's more support for it is broken) */
298 if (wm
&& (metacity_hack
== 1))
300 // metacity claims to support layers, but it is not the truth :-)
302 mp_msg(MSGT_VO
, MSGL_V
,
303 "[x11] Using workaround for Metacity bugs.\n");
307 if (x11_get_property(x11
, x11
->XA_NET_SUPPORTED
, &args
, &nitems
))
309 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Detected wm supports NetWM.\n");
310 for (i
= 0; i
< nitems
; i
++)
311 wm
|= net_wm_support_state_test(vo
->x11
, args
[i
]);
316 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Unknown wm type...\n");
320 #define XA_INIT(x) x11->XA##x = XInternAtom(x11->display, #x, False)
321 static void init_atoms(struct vo_x11_state
*x11
)
323 XA_INIT(_NET_SUPPORTED
);
324 XA_INIT(_NET_WM_STATE
);
325 XA_INIT(_NET_WM_STATE_FULLSCREEN
);
326 XA_INIT(_NET_WM_STATE_ABOVE
);
327 XA_INIT(_NET_WM_STATE_STAYS_ON_TOP
);
328 XA_INIT(_NET_WM_STATE_BELOW
);
329 XA_INIT(_NET_WM_PID
);
330 XA_INIT(_WIN_PROTOCOLS
);
333 XA_INIT(WM_PROTOCOLS
);
334 XA_INIT(WM_DELETE_WINDOW
);
337 void update_xinerama_info(struct vo
*vo
) {
338 struct MPOpts
*opts
= vo
->opts
;
339 xinerama_x
= xinerama_y
= 0;
340 #ifdef CONFIG_XINERAMA
341 if (xinerama_screen
>= -1 && XineramaIsActive(vo
->x11
->display
))
343 int screen
= xinerama_screen
;
344 XineramaScreenInfo
*screens
;
347 screens
= XineramaQueryScreens(vo
->x11
->display
, &num_screens
);
348 if (screen
>= num_screens
)
349 screen
= num_screens
- 1;
351 int x
= vo
->dx
+ vo
->dwidth
/ 2;
352 int y
= vo
->dy
+ vo
->dheight
/ 2;
353 for (screen
= num_screens
- 1; screen
> 0; screen
--) {
354 int left
= screens
[screen
].x_org
;
355 int right
= left
+ screens
[screen
].width
;
356 int top
= screens
[screen
].y_org
;
357 int bottom
= top
+ screens
[screen
].height
;
358 if (left
<= x
&& x
<= right
&& top
<= y
&& y
<= bottom
)
364 opts
->vo_screenwidth
= screens
[screen
].width
;
365 opts
->vo_screenheight
= screens
[screen
].height
;
366 xinerama_x
= screens
[screen
].x_org
;
367 xinerama_y
= screens
[screen
].y_org
;
372 aspect_save_screenres(vo
, opts
->vo_screenwidth
, opts
->vo_screenheight
);
375 int vo_init(struct vo
*vo
)
377 struct MPOpts
*opts
= vo
->opts
;
378 struct vo_x11_state
*x11
= vo
->x11
;
383 // char * DisplayName = ":0.0";
384 // Display * mDisplay;
385 XImage
*mXImage
= NULL
;
388 XWindowAttributes attribs
;
392 WinID
= 0; // use root window
394 if (x11
->depthonscreen
)
396 saver_off(x11
->display
);
397 return 1; // already called
400 XSetErrorHandler(x11_errorhandler
);
404 if (!(mDisplayName
= getenv("DISPLAY")))
405 mDisplayName
= strdup(":0.0");
407 dispName
= XDisplayName(mDisplayName
);
410 mp_msg(MSGT_VO
, MSGL_V
, "X11 opening display: %s\n", dispName
);
412 x11
->display
= XOpenDisplay(dispName
);
415 mp_msg(MSGT_VO
, MSGL_ERR
,
416 "vo: couldn't open the X11 display (%s)!\n", dispName
);
419 x11
->screen
= DefaultScreen(x11
->display
); // screen ID
420 x11
->rootwin
= RootWindow(x11
->display
, x11
->screen
); // root window ID
428 XF86VidModeGetModeLine(x11
->display
, x11
->screen
, &clock
, &modeline
);
429 if (!opts
->vo_screenwidth
)
430 opts
->vo_screenwidth
= modeline
.hdisplay
;
431 if (!opts
->vo_screenheight
)
432 opts
->vo_screenheight
= modeline
.vdisplay
;
436 if (!opts
->vo_screenwidth
)
437 opts
->vo_screenwidth
= DisplayWidth(x11
->display
, x11
->screen
);
438 if (!opts
->vo_screenheight
)
439 opts
->vo_screenheight
= DisplayHeight(x11
->display
, x11
->screen
);
441 // get color depth (from root window, or the best visual):
442 XGetWindowAttributes(x11
->display
, x11
->rootwin
, &attribs
);
443 depth
= attribs
.depth
;
445 if (depth
!= 15 && depth
!= 16 && depth
!= 24 && depth
!= 32)
449 depth
= vo_find_depth_from_visuals(x11
->display
, x11
->screen
, &visual
);
451 mXImage
= XCreateImage(x11
->display
, visual
, depth
, ZPixmap
,
452 0, NULL
, 1, 1, 8, 1);
455 XGetImage(x11
->display
, x11
->rootwin
, 0, 0, 1, 1, AllPlanes
, ZPixmap
);
457 x11
->depthonscreen
= depth
; // display depth on screen
459 // get bits/pixel from XImage structure:
466 * for the depth==24 case, the XImage structures might use
467 * 24 or 32 bits of data per pixel. The x11->depthonscreen
468 * field stores the amount of data per pixel in the
471 * Maybe we should rename vo_depthonscreen to (or add) vo_bpp?
473 bpp
= mXImage
->bits_per_pixel
;
474 if ((x11
->depthonscreen
+ 7) / 8 != (bpp
+ 7) / 8)
475 x11
->depthonscreen
= bpp
; // by A'rpi
477 mXImage
->red_mask
| mXImage
->green_mask
| mXImage
->blue_mask
;
478 mp_msg(MSGT_VO
, MSGL_V
,
479 "vo: X11 color mask: %X (R:%lX G:%lX B:%lX)\n", mask
,
480 mXImage
->red_mask
, mXImage
->green_mask
, mXImage
->blue_mask
);
481 XDestroyImage(mXImage
);
483 if (((x11
->depthonscreen
+ 7) / 8) == 2)
486 x11
->depthonscreen
= 15;
487 else if (mask
== 0xFFFF)
488 x11
->depthonscreen
= 16;
490 // XCloseDisplay( mDisplay );
491 /* slightly improved local display detection AST */
492 if (strncmp(dispName
, "unix:", 5) == 0)
494 else if (strncmp(dispName
, "localhost:", 10) == 0)
496 if (*dispName
== ':' && atoi(dispName
+ 1) < 10)
497 x11
->display_is_local
= 1;
499 x11
->display_is_local
= 0;
500 mp_msg(MSGT_VO
, MSGL_V
,
501 "vo: X11 running at %dx%d with depth %d and %d bpp (\"%s\" => %s display)\n",
502 opts
->vo_screenwidth
, opts
->vo_screenheight
, depth
, x11
->depthonscreen
,
503 dispName
, x11
->display_is_local
? "local" : "remote");
505 x11
->wm_type
= vo_wm_detect(vo
);
507 x11
->fs_type
= vo_x11_get_fs_type(x11
->wm_type
);
509 fstype_dump(x11
->fs_type
);
511 saver_off(x11
->display
);
515 void vo_uninit(struct vo_x11_state
*x11
)
519 mp_msg(MSGT_VO
, MSGL_V
,
520 "vo: x11 uninit called but X11 not initialized..\n");
522 mp_msg(MSGT_VO
, MSGL_V
, "vo: uninit ...\n");
523 XSetErrorHandler(NULL
);
524 XCloseDisplay(x11
->display
);
525 x11
->depthonscreen
= 0;
531 #include "osdep/keycodes.h"
534 #ifdef XF86XK_AudioPause
535 static const struct mp_keymap keysym_map
[] = {
536 {XF86XK_MenuKB
, KEY_MENU
},
537 {XF86XK_AudioPlay
, KEY_PLAY
}, {XF86XK_AudioPause
, KEY_PAUSE
}, {XF86XK_AudioStop
, KEY_STOP
},
538 {XF86XK_AudioPrev
, KEY_PREV
}, {XF86XK_AudioNext
, KEY_NEXT
},
539 {XF86XK_AudioMute
, KEY_MUTE
}, {XF86XK_AudioLowerVolume
, KEY_VOLUME_DOWN
}, {XF86XK_AudioRaiseVolume
, KEY_VOLUME_UP
},
543 static void vo_x11_putkey_ext(struct vo
*vo
, int keysym
)
545 struct mp_fifo
*f
= vo
->key_fifo
;
546 int mpkey
= lookup_keymap_table(keysym_map
, keysym
);
548 mplayer_put_key(f
, mpkey
);
552 static const struct mp_keymap keymap
[] = {
554 {wsEscape
, KEY_ESC
}, {wsBackSpace
, KEY_BS
}, {wsTab
, KEY_TAB
}, {wsEnter
, KEY_ENTER
},
557 {wsLeft
, KEY_LEFT
}, {wsRight
, KEY_RIGHT
}, {wsUp
, KEY_UP
}, {wsDown
, KEY_DOWN
},
560 {wsInsert
, KEY_INSERT
}, {wsDelete
, KEY_DELETE
}, {wsHome
, KEY_HOME
}, {wsEnd
, KEY_END
},
561 {wsPageUp
, KEY_PAGE_UP
}, {wsPageDown
, KEY_PAGE_DOWN
},
564 {wsF1
, KEY_F
+1}, {wsF2
, KEY_F
+2}, {wsF3
, KEY_F
+3}, {wsF4
, KEY_F
+4},
565 {wsF5
, KEY_F
+5}, {wsF6
, KEY_F
+6}, {wsF7
, KEY_F
+7}, {wsF8
, KEY_F
+8},
566 {wsF9
, KEY_F
+9}, {wsF10
, KEY_F
+10}, {wsF11
, KEY_F
+11}, {wsF12
, KEY_F
+12},
568 // numpad independent of numlock
569 {wsGrayMinus
, '-'}, {wsGrayPlus
, '+'}, {wsGrayMul
, '*'}, {wsGrayDiv
, '/'},
570 {wsGrayEnter
, KEY_KPENTER
},
572 // numpad with numlock
573 {wsGray0
, KEY_KP0
}, {wsGray1
, KEY_KP1
}, {wsGray2
, KEY_KP2
},
574 {wsGray3
, KEY_KP3
}, {wsGray4
, KEY_KP4
}, {wsGray5
, KEY_KP5
},
575 {wsGray6
, KEY_KP6
}, {wsGray7
, KEY_KP7
}, {wsGray8
, KEY_KP8
},
576 {wsGray9
, KEY_KP9
}, {wsGrayDecimal
, KEY_KPDEC
},
578 // numpad without numlock
579 {wsGrayInsert
, KEY_KPINS
}, {wsGrayEnd
, KEY_KP1
}, {wsGrayDown
, KEY_KP2
},
580 {wsGrayPgDn
, KEY_KP3
}, {wsGrayLeft
, KEY_KP4
}, {wsGray5Dup
, KEY_KP5
},
581 {wsGrayRight
, KEY_KP6
}, {wsGrayHome
, KEY_KP7
}, {wsGrayUp
, KEY_KP8
},
582 {wsGrayPgUp
, KEY_KP9
}, {wsGrayDelete
, KEY_KPDEL
},
587 void vo_x11_putkey(struct vo
*vo
, int key
)
589 static const char *passthrough_keys
= " -+*/<>`~!@#$%^&()_{}:;\"\',.?\\|=[]";
591 if ((key
>= 'a' && key
<= 'z') ||
592 (key
>= 'A' && key
<= 'Z') ||
593 (key
>= '0' && key
<= '9') ||
594 (key
> 0 && key
< 256 && strchr(passthrough_keys
, key
)))
598 mpkey
= lookup_keymap_table(keymap
, key
);
601 mplayer_put_key(vo
->key_fifo
, mpkey
);
605 // ----- Motif header: -------
607 #define MWM_HINTS_FUNCTIONS (1L << 0)
608 #define MWM_HINTS_DECORATIONS (1L << 1)
609 #define MWM_HINTS_INPUT_MODE (1L << 2)
610 #define MWM_HINTS_STATUS (1L << 3)
612 #define MWM_FUNC_ALL (1L << 0)
613 #define MWM_FUNC_RESIZE (1L << 1)
614 #define MWM_FUNC_MOVE (1L << 2)
615 #define MWM_FUNC_MINIMIZE (1L << 3)
616 #define MWM_FUNC_MAXIMIZE (1L << 4)
617 #define MWM_FUNC_CLOSE (1L << 5)
619 #define MWM_DECOR_ALL (1L << 0)
620 #define MWM_DECOR_BORDER (1L << 1)
621 #define MWM_DECOR_RESIZEH (1L << 2)
622 #define MWM_DECOR_TITLE (1L << 3)
623 #define MWM_DECOR_MENU (1L << 4)
624 #define MWM_DECOR_MINIMIZE (1L << 5)
625 #define MWM_DECOR_MAXIMIZE (1L << 6)
627 #define MWM_INPUT_MODELESS 0
628 #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
629 #define MWM_INPUT_SYSTEM_MODAL 2
630 #define MWM_INPUT_FULL_APPLICATION_MODAL 3
631 #define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL
633 #define MWM_TEAROFF_WINDOW (1L<<0)
644 static MotifWmHints vo_MotifWmHints
;
645 static Atom vo_MotifHints
= None
;
647 void vo_x11_decoration(struct vo
*vo
, int d
)
649 struct vo_x11_state
*x11
= vo
->x11
;
652 unsigned long mn
, mb
;
659 XSetTransientForHint(x11
->display
, x11
->window
,
660 RootWindow(x11
->display
, x11
->screen
));
663 vo_MotifHints
= XInternAtom(x11
->display
, "_MOTIF_WM_HINTS", 0);
664 if (vo_MotifHints
!= None
)
668 MotifWmHints
*mhints
= NULL
;
670 XGetWindowProperty(x11
->display
, x11
->window
,
671 vo_MotifHints
, 0, 20, False
,
672 vo_MotifHints
, &mtype
, &mformat
, &mn
,
673 &mb
, (unsigned char **) &mhints
);
676 if (mhints
->flags
& MWM_HINTS_DECORATIONS
)
677 x11
->olddecor
= mhints
->decorations
;
678 if (mhints
->flags
& MWM_HINTS_FUNCTIONS
)
679 x11
->oldfuncs
= mhints
->functions
;
684 memset(&vo_MotifWmHints
, 0, sizeof(MotifWmHints
));
685 vo_MotifWmHints
.flags
=
686 MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
689 vo_MotifWmHints
.functions
= x11
->oldfuncs
;
693 vo_MotifWmHints
.decorations
=
694 d
| ((vo_fsmode
& 2) ? 0 : MWM_DECOR_MENU
);
696 vo_MotifWmHints
.decorations
=
697 d
| ((vo_fsmode
& 2) ? MWM_DECOR_MENU
: 0);
699 XChangeProperty(x11
->display
, x11
->window
, vo_MotifHints
,
702 (unsigned char *) &vo_MotifWmHints
,
703 (vo_fsmode
& 4) ? 4 : 5);
707 void vo_x11_classhint(struct vo
*vo
, Window window
, const char *name
)
709 struct vo_x11_state
*x11
= vo
->x11
;
711 pid_t pid
= getpid();
713 wmClass
.res_name
= vo_winname
? vo_winname
: name
;
714 wmClass
.res_class
= "MPlayer";
715 XSetClassHint(x11
->display
, window
, &wmClass
);
716 XChangeProperty(x11
->display
, window
, x11
->XA_NET_WM_PID
, XA_CARDINAL
,
717 32, PropModeReplace
, (unsigned char *) &pid
, 1);
720 void vo_x11_uninit(struct vo
*vo
)
722 struct vo_x11_state
*x11
= vo
->x11
;
723 saver_on(x11
->display
);
724 if (x11
->window
!= None
)
725 vo_showcursor(x11
->display
, x11
->window
);
727 if (x11
->f_gc
!= None
)
729 XFreeGC(vo
->x11
->display
, x11
->f_gc
);
733 if (x11
->vo_gc
!= None
)
735 XSetBackground(vo
->x11
->display
, x11
->vo_gc
, 0);
736 XFreeGC(vo
->x11
->display
, x11
->vo_gc
);
739 if (x11
->window
!= None
)
741 XClearWindow(x11
->display
, x11
->window
);
746 XUnmapWindow(x11
->display
, x11
->window
);
747 XSelectInput(x11
->display
, x11
->window
, StructureNotifyMask
);
748 XDestroyWindow(x11
->display
, x11
->window
);
751 XNextEvent(x11
->display
, &xev
);
753 while (xev
.type
!= DestroyNotify
754 || xev
.xdestroywindow
.event
!= x11
->window
);
759 x11
->vo_old_width
= x11
->vo_old_height
= 0;
760 x11
->last_video_width
= 0;
761 x11
->last_video_height
= 0;
762 x11
->size_changed_during_fs
= false;
766 static int check_resize(struct vo
*vo
)
768 int old_w
= vo
->dwidth
, old_h
= vo
->dheight
;
769 int old_x
= vo
->dx
, old_y
= vo
->dy
;
771 vo_x11_update_geometry(vo
);
772 if (vo
->dwidth
!= old_w
|| vo
->dheight
!= old_h
)
773 rc
|= VO_EVENT_RESIZE
;
774 if (vo
->dx
!= old_x
|| vo
->dy
!= old_y
)
779 int vo_x11_check_events(struct vo
*vo
)
781 struct vo_x11_state
*x11
= vo
->x11
;
782 Display
*display
= vo
->x11
->display
;
788 if (x11
->vo_mouse_autohide
&& x11
->mouse_waiting_hide
&&
789 (GetTimerMS() - x11
->mouse_timer
>= 1000)) {
790 vo_hidecursor(display
, x11
->window
);
791 x11
->mouse_waiting_hide
= 0;
795 ret
|= check_resize(vo
);
796 while (XPending(display
))
798 XNextEvent(display
, &Event
);
799 // printf("\rEvent.type=%X \n",Event.type);
803 ret
|= VO_EVENT_EXPOSE
;
805 case ConfigureNotify
:
806 if (x11
->window
== None
)
808 ret
|= check_resize(vo
);
814 XLookupString(&Event
.xkey
, buf
, sizeof(buf
), &keySym
,
815 &x11
->compose_status
);
816 #ifdef XF86XK_AudioPause
817 vo_x11_putkey_ext(vo
, keySym
);
820 ((keySym
& 0xff00) !=
821 0 ? ((keySym
& 0x00ff) + 256) : (keySym
));
822 vo_x11_putkey(vo
, key
);
823 ret
|= VO_EVENT_KEYPRESS
;
827 vo_mouse_movement(vo
, Event
.xmotion
.x
, Event
.xmotion
.y
);
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();
843 mplayer_put_key(vo
->key_fifo
,
844 (MOUSE_BTN0
+ Event
.xbutton
.button
- 1)
848 if (x11
->vo_mouse_autohide
)
850 vo_showcursor(display
, x11
->window
);
851 x11
->mouse_waiting_hide
= 1;
852 x11
->mouse_timer
= GetTimerMS();
854 mplayer_put_key(vo
->key_fifo
,
855 MOUSE_BTN0
+ Event
.xbutton
.button
- 1);
860 XGetAtomName(display
, Event
.xproperty
.atom
);
865 // fprintf(stderr,"[ws] PropertyNotify ( 0x%x ) %s ( 0x%x )\n",vo_window,name,Event.xproperty.atom );
871 x11
->vo_hint
.win_gravity
= x11
->old_gravity
;
872 XSetWMNormalHints(display
, x11
->window
, &x11
->vo_hint
);
876 mp_msg(MSGT_VO
, MSGL_WARN
, "Our window was destroyed, exiting\n");
877 mplayer_put_key(vo
->key_fifo
, KEY_CLOSE_WIN
);
880 if (Event
.xclient
.message_type
== x11
->XAWM_PROTOCOLS
&&
881 Event
.xclient
.data
.l
[0] == x11
->XAWM_DELETE_WINDOW
)
882 mplayer_put_key(vo
->key_fifo
, KEY_CLOSE_WIN
);
890 * \brief sets the size and position of the non-fullscreen window.
892 static void vo_x11_nofs_sizepos(struct vo
*vo
, int x
, int y
,
893 int width
, int height
)
895 struct vo_x11_state
*x11
= vo
->x11
;
896 if (width
== x11
->last_video_width
&& height
== x11
->last_video_height
) {
897 if (!vo
->opts
->force_window_position
&& !x11
->size_changed_during_fs
)
900 x11
->size_changed_during_fs
= true;
901 x11
->last_video_height
= height
;
902 x11
->last_video_width
= width
;
903 vo_x11_sizehint(vo
, x
, y
, width
, height
, 0);
907 x11
->vo_old_width
= width
;
908 x11
->vo_old_height
= height
;
913 vo
->dheight
= height
;
914 if (vo
->opts
->force_window_position
)
915 XMoveResizeWindow(vo
->x11
->display
, vo
->x11
->window
, x
, y
, width
,
918 XResizeWindow(vo
->x11
->display
, vo
->x11
->window
, width
, height
);
922 void vo_x11_sizehint(struct vo
*vo
, int x
, int y
, int width
, int height
, int max
)
924 struct vo_x11_state
*x11
= vo
->x11
;
925 x11
->vo_hint
.flags
= 0;
928 x11
->vo_hint
.flags
|= PAspect
;
929 x11
->vo_hint
.min_aspect
.x
= width
;
930 x11
->vo_hint
.min_aspect
.y
= height
;
931 x11
->vo_hint
.max_aspect
.x
= width
;
932 x11
->vo_hint
.max_aspect
.y
= height
;
935 x11
->vo_hint
.flags
|= PPosition
| PSize
;
938 x11
->vo_hint
.width
= width
;
939 x11
->vo_hint
.height
= height
;
942 x11
->vo_hint
.flags
|= PMaxSize
;
943 x11
->vo_hint
.max_width
= width
;
944 x11
->vo_hint
.max_height
= height
;
947 x11
->vo_hint
.max_width
= 0;
948 x11
->vo_hint
.max_height
= 0;
951 // Set minimum height/width to 4 to avoid off-by-one errors
952 // and because mga_vid requires a minimal size of 4 pixels.
953 x11
->vo_hint
.flags
|= PMinSize
;
954 x11
->vo_hint
.min_width
= x11
->vo_hint
.min_height
= 4;
956 // Set the base size. A window manager might display the window
957 // size to the user relative to this.
958 // Setting these to width/height might be nice, but e.g. fluxbox can't handle it.
959 x11
->vo_hint
.flags
|= PBaseSize
;
960 x11
->vo_hint
.base_width
= 0 /*width*/;
961 x11
->vo_hint
.base_height
= 0 /*height*/;
963 x11
->vo_hint
.flags
|= PWinGravity
;
964 x11
->vo_hint
.win_gravity
= StaticGravity
;
965 XSetWMNormalHints(x11
->display
, x11
->window
, &x11
->vo_hint
);
968 static int vo_x11_get_gnome_layer(struct vo_x11_state
*x11
, Window win
)
972 unsigned long nitems
;
973 unsigned long bytesafter
;
974 unsigned short *args
= NULL
;
976 if (XGetWindowProperty(x11
->display
, win
, x11
->XA_WIN_LAYER
, 0, 16384,
977 False
, AnyPropertyType
, &type
, &format
, &nitems
,
979 (unsigned char **) &args
) == Success
980 && nitems
> 0 && args
)
982 mp_msg(MSGT_VO
, MSGL_V
, "[x11] original window layer is %d.\n",
986 return WIN_LAYER_NORMAL
;
990 static Window
vo_x11_create_smooth_window(struct vo_x11_state
*x11
, Window mRoot
,
991 Visual
* vis
, int x
, int y
,
992 unsigned int width
, unsigned int height
,
993 int depth
, Colormap col_map
)
995 unsigned long xswamask
= CWBorderPixel
;
996 XSetWindowAttributes xswa
;
999 if (col_map
!= CopyFromParent
)
1001 xswa
.colormap
= col_map
;
1002 xswamask
|= CWColormap
;
1004 xswa
.background_pixel
= 0;
1005 xswa
.border_pixel
= 0;
1006 xswa
.backing_store
= NotUseful
;
1007 xswa
.bit_gravity
= StaticGravity
;
1010 XCreateWindow(x11
->display
, x11
->rootwin
, x
, y
, width
, height
, 0, depth
,
1011 CopyFromParent
, vis
, xswamask
, &xswa
);
1012 XSetWMProtocols(x11
->display
, ret_win
, &x11
->XAWM_DELETE_WINDOW
, 1);
1013 if (x11
->f_gc
== None
)
1014 x11
->f_gc
= XCreateGC(x11
->display
, ret_win
, 0, 0);
1015 XSetForeground(x11
->display
, x11
->f_gc
, 0);
1021 * \brief create and setup a window suitable for display
1022 * \param vis Visual to use for creating the window
1023 * \param x x position of window
1024 * \param y y position of window
1025 * \param width width of window
1026 * \param height height of window
1027 * \param flags flags for window creation.
1028 * Only VOFLAG_FULLSCREEN is supported so far.
1029 * \param col_map Colourmap for window or CopyFromParent if a specific colormap isn't needed
1030 * \param classname name to use for the classhint
1031 * \param title title for the window
1033 * This also does the grunt-work like setting Window Manager hints etc.
1034 * If vo_window is already set it just moves and resizes it.
1036 void vo_x11_create_vo_window(struct vo
*vo
, XVisualInfo
*vis
, int x
, int y
,
1037 unsigned int width
, unsigned int height
, int flags
,
1039 const char *classname
, const char *title
)
1041 struct MPOpts
*opts
= vo
->opts
;
1042 struct vo_x11_state
*x11
= vo
->x11
;
1043 Display
*mDisplay
= vo
->x11
->display
;
1046 vo_fs
= flags
& VOFLAG_FULLSCREEN
;
1047 x11
->window
= WinID
? (Window
)WinID
: x11
->rootwin
;
1048 if (col_map
!= CopyFromParent
) {
1049 unsigned long xswamask
= CWColormap
;
1050 XSetWindowAttributes xswa
;
1051 xswa
.colormap
= col_map
;
1052 XChangeWindowAttributes(mDisplay
, x11
->window
, xswamask
, &xswa
);
1053 XInstallColormap(mDisplay
, col_map
);
1056 // Expose events can only really be handled by us, so request them.
1057 vo_x11_selectinput_witherr(mDisplay
, x11
->window
, ExposureMask
);
1059 // Do not capture events since it might break the parent application
1060 // if it relies on events being forwarded to the parent of WinID.
1061 // It also is consistent with the w32_common.c code.
1062 vo_x11_selectinput_witherr(mDisplay
, x11
->window
,
1063 StructureNotifyMask
| KeyPressMask
| PointerMotionMask
|
1064 ButtonPressMask
| ButtonReleaseMask
| ExposureMask
);
1066 vo_x11_update_geometry(vo
);
1069 if (x11
->window
== None
) {
1072 vo
->dheight
= height
;
1073 x11
->window
= vo_x11_create_smooth_window(x11
, x11
->rootwin
, vis
->visual
,
1074 x
, y
, width
, height
, vis
->depth
, col_map
);
1075 x11
->window_state
= VOFLAG_HIDDEN
;
1077 if (flags
& VOFLAG_HIDDEN
)
1079 if (x11
->window_state
& VOFLAG_HIDDEN
) {
1082 x11
->window_state
&= ~VOFLAG_HIDDEN
;
1083 vo_x11_classhint(vo
, x11
->window
, classname
);
1084 XStoreName(mDisplay
, x11
->window
, title
);
1085 vo_hidecursor(mDisplay
, x11
->window
);
1086 XSelectInput(mDisplay
, x11
->window
, StructureNotifyMask
);
1087 hint
.x
= x
; hint
.y
= y
;
1088 hint
.width
= width
; hint
.height
= height
;
1090 if (geometry_xy_changed
)
1091 hint
.flags
|= PPosition
;
1092 XSetStandardProperties(mDisplay
, x11
->window
, title
, title
, None
, NULL
, 0, &hint
);
1093 if (!vo_border
) vo_x11_decoration(vo
, 0);
1095 XMapWindow(mDisplay
, x11
->window
);
1096 vo_x11_clearwindow(vo
, x11
->window
);
1099 XNextEvent(mDisplay
, &xev
);
1100 } while (xev
.type
!= MapNotify
|| xev
.xmap
.event
!= x11
->window
);
1101 XSelectInput(mDisplay
, x11
->window
, NoEventMask
);
1102 XSync(mDisplay
, False
);
1103 vo_x11_selectinput_witherr(mDisplay
, x11
->window
,
1104 StructureNotifyMask
| KeyPressMask
| PointerMotionMask
|
1105 ButtonPressMask
| ButtonReleaseMask
| ExposureMask
);
1107 if (opts
->vo_ontop
) vo_x11_setlayer(vo
, x11
->window
, opts
->vo_ontop
);
1108 if (!geometry_xy_changed
)
1109 vo_x11_update_geometry(vo
);
1110 vo_x11_nofs_sizepos(vo
, vo
->dx
, vo
->dy
, width
, height
);
1111 if (!!vo_fs
!= !!(flags
& VOFLAG_FULLSCREEN
))
1112 vo_x11_fullscreen(vo
);
1114 // if we are already in fullscreen do not switch back and forth, just
1115 // set the size values right.
1116 vo
->dwidth
= vo
->opts
->vo_screenwidth
;
1117 vo
->dheight
= vo
->opts
->vo_screenheight
;
1120 if (x11
->vo_gc
!= None
)
1121 XFreeGC(mDisplay
, x11
->vo_gc
);
1122 x11
->vo_gc
= XCreateGC(mDisplay
, x11
->window
, GCForeground
, &xgcv
);
1123 XSync(mDisplay
, False
);
1124 x11
->vo_mouse_autohide
= 1;
1127 void vo_x11_clearwindow_part(struct vo
*vo
, Window vo_window
,
1128 int img_width
, int img_height
, int use_fs
)
1130 struct vo_x11_state
*x11
= vo
->x11
;
1131 struct MPOpts
*opts
= vo
->opts
;
1132 Display
*mDisplay
= vo
->x11
->display
;
1133 int u_dheight
, u_dwidth
, left_ov
, left_ov2
;
1135 if (x11
->f_gc
== None
)
1138 u_dheight
= use_fs
? opts
->vo_screenheight
: vo
->dheight
;
1139 u_dwidth
= use_fs
? opts
->vo_screenwidth
: vo
->dwidth
;
1140 if ((u_dheight
<= img_height
) && (u_dwidth
<= img_width
))
1143 left_ov
= (u_dheight
- img_height
) / 2;
1144 left_ov2
= (u_dwidth
- img_width
) / 2;
1146 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, 0, 0, u_dwidth
, left_ov
);
1147 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, 0, u_dheight
- left_ov
- 1,
1148 u_dwidth
, left_ov
+ 1);
1150 if (u_dwidth
> img_width
)
1152 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, 0, left_ov
, left_ov2
,
1154 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, u_dwidth
- left_ov2
- 1,
1155 left_ov
, left_ov2
+ 1, img_height
);
1161 void vo_x11_clearwindow(struct vo
*vo
, Window vo_window
)
1163 struct vo_x11_state
*x11
= vo
->x11
;
1164 struct MPOpts
*opts
= vo
->opts
;
1165 if (x11
->f_gc
== None
)
1167 XFillRectangle(x11
->display
, vo_window
, x11
->f_gc
, 0, 0,
1168 opts
->vo_screenwidth
, opts
->vo_screenheight
);
1170 XFlush(x11
->display
);
1174 void vo_x11_setlayer(struct vo
*vo
, Window vo_window
, int layer
)
1176 struct vo_x11_state
*x11
= vo
->x11
;
1180 if (x11
->fs_type
& vo_wm_LAYER
)
1182 XClientMessageEvent xev
;
1184 if (!x11
->orig_layer
)
1185 x11
->orig_layer
= vo_x11_get_gnome_layer(x11
, vo_window
);
1187 memset(&xev
, 0, sizeof(xev
));
1188 xev
.type
= ClientMessage
;
1189 xev
.display
= x11
->display
;
1190 xev
.window
= vo_window
;
1191 xev
.message_type
= x11
->XA_WIN_LAYER
;
1193 xev
.data
.l
[0] = layer
? fs_layer
: x11
->orig_layer
; // if not fullscreen, stay on default layer
1194 xev
.data
.l
[1] = CurrentTime
;
1195 mp_msg(MSGT_VO
, MSGL_V
,
1196 "[x11] Layered style stay on top (layer %ld).\n",
1198 XSendEvent(x11
->display
, x11
->rootwin
, False
, SubstructureNotifyMask
,
1200 } else if (x11
->fs_type
& vo_wm_NETWM
)
1202 XClientMessageEvent xev
;
1205 memset(&xev
, 0, sizeof(xev
));
1206 xev
.type
= ClientMessage
;
1207 xev
.message_type
= x11
->XA_NET_WM_STATE
;
1208 xev
.display
= x11
->display
;
1209 xev
.window
= vo_window
;
1211 xev
.data
.l
[0] = layer
;
1213 if (x11
->fs_type
& vo_wm_STAYS_ON_TOP
)
1214 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_STAYS_ON_TOP
;
1215 else if (x11
->fs_type
& vo_wm_ABOVE
)
1216 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_ABOVE
;
1217 else if (x11
->fs_type
& vo_wm_FULLSCREEN
)
1218 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_FULLSCREEN
;
1219 else if (x11
->fs_type
& vo_wm_BELOW
)
1220 // This is not fallback. We can safely assume that the situation
1221 // where only NETWM_STATE_BELOW is supported doesn't exist.
1222 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_BELOW
;
1224 XSendEvent(x11
->display
, x11
->rootwin
, False
, SubstructureRedirectMask
,
1226 state
= XGetAtomName(x11
->display
, xev
.data
.l
[1]);
1227 mp_msg(MSGT_VO
, MSGL_V
,
1228 "[x11] NET style stay on top (layer %d). Using state %s.\n",
1234 static int vo_x11_get_fs_type(int supported
)
1237 int type
= supported
;
1241 for (i
= 0; vo_fstype_list
[i
]; i
++)
1244 char *arg
= vo_fstype_list
[i
];
1246 if (vo_fstype_list
[i
][0] == '-')
1249 arg
= vo_fstype_list
[i
] + 1;
1252 if (!strncmp(arg
, "layer", 5))
1254 if (!neg
&& (arg
[5] == '='))
1256 char *endptr
= NULL
;
1257 int layer
= strtol(vo_fstype_list
[i
] + 6, &endptr
, 10);
1259 if (endptr
&& *endptr
== '\0' && layer
>= 0
1264 type
&= ~vo_wm_LAYER
;
1266 type
|= vo_wm_LAYER
;
1267 } else if (!strcmp(arg
, "above"))
1270 type
&= ~vo_wm_ABOVE
;
1272 type
|= vo_wm_ABOVE
;
1273 } else if (!strcmp(arg
, "fullscreen"))
1276 type
&= ~vo_wm_FULLSCREEN
;
1278 type
|= vo_wm_FULLSCREEN
;
1279 } else if (!strcmp(arg
, "stays_on_top"))
1282 type
&= ~vo_wm_STAYS_ON_TOP
;
1284 type
|= vo_wm_STAYS_ON_TOP
;
1285 } else if (!strcmp(arg
, "below"))
1288 type
&= ~vo_wm_BELOW
;
1290 type
|= vo_wm_BELOW
;
1291 } else if (!strcmp(arg
, "netwm"))
1294 type
&= ~vo_wm_NETWM
;
1296 type
|= vo_wm_NETWM
;
1297 } else if (!strcmp(arg
, "none"))
1298 type
= 0; // clear; keep parsing
1306 * \brief update vo->dx, vo->dy, vo->dwidth and vo->dheight with current values of vo->x11->window
1307 * \return returns current color depth of vo->x11->window
1309 int vo_x11_update_geometry(struct vo
*vo
)
1311 struct vo_x11_state
*x11
= vo
->x11
;
1312 unsigned depth
, w
, h
;
1315 XGetGeometry(x11
->display
, x11
->window
, &dummy_win
, &dummy_int
, &dummy_int
,
1316 &w
, &h
, &dummy_int
, &depth
);
1317 if (w
<= INT_MAX
&& h
<= INT_MAX
) {
1321 XTranslateCoordinates(x11
->display
, x11
->window
, x11
->rootwin
, 0, 0,
1322 &vo
->dx
, &vo
->dy
, &dummy_win
);
1324 XStoreName(x11
->display
, x11
->window
, vo_wintitle
);
1326 return depth
<= INT_MAX
? depth
: 0;
1329 void vo_x11_fullscreen(struct vo
*vo
)
1331 struct MPOpts
*opts
= vo
->opts
;
1332 struct vo_x11_state
*x11
= vo
->x11
;
1336 w
= x11
->vo_old_width
;
1337 h
= x11
->vo_old_height
;
1348 vo_x11_ewmh_fullscreen(x11
, _NET_WM_STATE_REMOVE
); // removes fullscreen state if wm supports EWMH
1350 if (x11
->size_changed_during_fs
&& (x11
->fs_type
& vo_wm_FULLSCREEN
))
1351 vo_x11_nofs_sizepos(vo
, vo
->dx
, vo
->dy
, x11
->last_video_width
,
1352 x11
->last_video_height
);
1353 x11
->size_changed_during_fs
= false;
1357 vo_x11_ewmh_fullscreen(x11
, _NET_WM_STATE_ADD
); // sends fullscreen state to be added if wm supports EWMH
1360 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1362 x11
->vo_old_x
= vo
->dx
;
1363 x11
->vo_old_y
= vo
->dy
;
1364 x11
->vo_old_width
= vo
->dwidth
;
1365 x11
->vo_old_height
= vo
->dheight
;
1367 update_xinerama_info(vo
);
1370 w
= opts
->vo_screenwidth
;
1371 h
= opts
->vo_screenheight
;
1376 XGetWMNormalHints(x11
->display
, x11
->window
, &x11
->vo_hint
, &dummy
);
1377 if (!(x11
->vo_hint
.flags
& PWinGravity
))
1378 x11
->old_gravity
= NorthWestGravity
;
1380 x11
->old_gravity
= x11
->vo_hint
.win_gravity
;
1382 if (x11
->wm_type
== 0 && !(vo_fsmode
& 16))
1384 XUnmapWindow(x11
->display
, x11
->window
); // required for MWM
1385 XWithdrawWindow(x11
->display
, x11
->window
, x11
->screen
);
1389 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1391 vo_x11_decoration(vo
, vo_border
&& !vo_fs
);
1392 vo_x11_sizehint(vo
, x
, y
, w
, h
, 0);
1393 vo_x11_setlayer(vo
, x11
->window
, vo_fs
);
1396 XMoveResizeWindow(x11
->display
, x11
->window
, x
, y
, w
, h
);
1398 /* some WMs lose ontop after fullscreen */
1399 if ((!(vo_fs
)) & opts
->vo_ontop
)
1400 vo_x11_setlayer(vo
, x11
->window
, opts
->vo_ontop
);
1402 XMapRaised(x11
->display
, x11
->window
);
1403 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // some WMs change window pos on map
1404 XMoveResizeWindow(x11
->display
, x11
->window
, x
, y
, w
, h
);
1405 XRaiseWindow(x11
->display
, x11
->window
);
1406 XFlush(x11
->display
);
1409 void vo_x11_ontop(struct vo
*vo
)
1411 struct MPOpts
*opts
= vo
->opts
;
1412 opts
->vo_ontop
= !opts
->vo_ontop
;
1414 vo_x11_setlayer(vo
, vo
->x11
->window
, opts
->vo_ontop
);
1417 void vo_x11_border(struct vo
*vo
)
1419 vo_border
= !vo_border
;
1420 vo_x11_decoration(vo
, vo_border
&& !vo_fs
);
1424 * XScreensaver stuff
1427 static int screensaver_off
;
1428 static unsigned int time_last
;
1430 void xscreensaver_heartbeat(struct vo_x11_state
*x11
)
1432 unsigned int time
= GetTimerMS();
1434 if (x11
->display
&& screensaver_off
&& (time
- time_last
) > 30000)
1438 XResetScreenSaver(x11
->display
);
1442 static int xss_suspend(Display
*mDisplay
, Bool suspend
)
1447 int event
, error
, major
, minor
;
1448 if (XScreenSaverQueryExtension(mDisplay
, &event
, &error
) != True
||
1449 XScreenSaverQueryVersion(mDisplay
, &major
, &minor
) != True
)
1451 if (major
< 1 || (major
== 1 && minor
< 1))
1453 XScreenSaverSuspend(mDisplay
, suspend
);
1459 * End of XScreensaver stuff
1462 static void saver_on(Display
* mDisplay
)
1465 if (!screensaver_off
)
1467 screensaver_off
= 0;
1468 if (xss_suspend(mDisplay
, False
))
1474 if (DPMSQueryExtension(mDisplay
, ¬hing
, ¬hing
))
1476 if (!DPMSEnable(mDisplay
))
1477 { // restoring power saving settings
1478 mp_msg(MSGT_VO
, MSGL_WARN
, "DPMS not available?\n");
1481 // DPMS does not seem to be enabled unless we call DPMSInfo
1485 DPMSForceLevel(mDisplay
, DPMSModeOn
);
1486 DPMSInfo(mDisplay
, &state
, &onoff
);
1489 mp_msg(MSGT_VO
, MSGL_V
,
1490 "Successfully enabled DPMS\n");
1493 mp_msg(MSGT_VO
, MSGL_WARN
, "Could not enable DPMS\n");
1502 static void saver_off(Display
* mDisplay
)
1506 if (screensaver_off
)
1508 screensaver_off
= 1;
1509 if (xss_suspend(mDisplay
, True
))
1512 if (DPMSQueryExtension(mDisplay
, ¬hing
, ¬hing
))
1517 DPMSInfo(mDisplay
, &state
, &onoff
);
1522 mp_msg(MSGT_VO
, MSGL_V
, "Disabling DPMS\n");
1524 stat
= DPMSDisable(mDisplay
); // monitor powersave off
1525 mp_msg(MSGT_VO
, MSGL_V
, "DPMSDisable stat: %d\n", stat
);
1531 static XErrorHandler old_handler
= NULL
;
1532 static int selectinput_err
= 0;
1533 static int x11_selectinput_errorhandler(Display
* display
,
1534 XErrorEvent
* event
)
1536 if (event
->error_code
== BadAccess
)
1538 selectinput_err
= 1;
1539 mp_msg(MSGT_VO
, MSGL_ERR
,
1540 "X11 error: BadAccess during XSelectInput Call\n");
1541 mp_msg(MSGT_VO
, MSGL_ERR
,
1542 "X11 error: The 'ButtonPressMask' mask of specified window has probably already used by another appication (see man XSelectInput)\n");
1543 /* If you think MPlayer should shutdown with this error,
1544 * comment out the following line */
1547 if (old_handler
!= NULL
)
1548 old_handler(display
, event
);
1550 x11_errorhandler(display
, event
);
1554 void vo_x11_selectinput_witherr(Display
* display
, Window w
,
1557 XSync(display
, False
);
1558 old_handler
= XSetErrorHandler(x11_selectinput_errorhandler
);
1559 selectinput_err
= 0;
1560 if (vo_nomouse_input
)
1562 XSelectInput(display
, w
,
1564 (~(ButtonPressMask
| ButtonReleaseMask
)));
1567 XSelectInput(display
, w
, event_mask
);
1569 XSync(display
, False
);
1570 XSetErrorHandler(old_handler
);
1571 if (selectinput_err
)
1573 mp_msg(MSGT_VO
, MSGL_ERR
,
1574 "X11 error: MPlayer discards mouse control (reconfiguring)\n");
1575 XSelectInput(display
, w
,
1578 (ButtonPressMask
| ButtonReleaseMask
|
1579 PointerMotionMask
)));
1583 #ifdef CONFIG_XF86VM
1584 void vo_vm_switch(struct vo
*vo
)
1586 struct vo_x11_state
*x11
= vo
->x11
;
1587 struct MPOpts
*opts
= vo
->opts
;
1588 Display
*mDisplay
= x11
->display
;
1589 int vm_event
, vm_error
;
1591 int i
, j
, have_vm
= 0;
1592 int X
= vo
->dwidth
, Y
= vo
->dheight
;
1593 int modeline_width
, modeline_height
;
1597 if (XF86VidModeQueryExtension(mDisplay
, &vm_event
, &vm_error
))
1599 XF86VidModeQueryVersion(mDisplay
, &vm_ver
, &vm_rev
);
1600 mp_msg(MSGT_VO
, MSGL_V
, "XF86VidMode extension v%i.%i\n", vm_ver
,
1604 mp_msg(MSGT_VO
, MSGL_WARN
,
1605 "XF86VidMode extension not available.\n");
1610 if (vidmodes
== NULL
)
1611 XF86VidModeGetAllModeLines(mDisplay
, x11
->screen
, &modecount
,
1614 modeline_width
= vidmodes
[0]->hdisplay
;
1615 modeline_height
= vidmodes
[0]->vdisplay
;
1617 for (i
= 1; i
< modecount
; i
++)
1618 if ((vidmodes
[i
]->hdisplay
>= X
)
1619 && (vidmodes
[i
]->vdisplay
>= Y
))
1620 if ((vidmodes
[i
]->hdisplay
<= modeline_width
)
1621 && (vidmodes
[i
]->vdisplay
<= modeline_height
))
1623 modeline_width
= vidmodes
[i
]->hdisplay
;
1624 modeline_height
= vidmodes
[i
]->vdisplay
;
1628 mp_tmsg(MSGT_VO
, MSGL_INFO
, "XF86VM: Selected video mode %dx%d for image size %dx%d.\n",
1629 modeline_width
, modeline_height
, X
, Y
);
1630 XF86VidModeLockModeSwitch(mDisplay
, x11
->screen
, 0);
1631 XF86VidModeSwitchToMode(mDisplay
, x11
->screen
, vidmodes
[j
]);
1632 XF86VidModeSwitchToMode(mDisplay
, x11
->screen
, vidmodes
[j
]);
1634 // FIXME: all this is more of a hack than proper solution
1635 X
= (opts
->vo_screenwidth
- modeline_width
) / 2;
1636 Y
= (opts
->vo_screenheight
- modeline_height
) / 2;
1637 XF86VidModeSetViewPort(mDisplay
, x11
->screen
, X
, Y
);
1640 vo
->dwidth
= modeline_width
;
1641 vo
->dheight
= modeline_height
;
1642 aspect_save_screenres(vo
, modeline_width
, modeline_height
);
1646 void vo_vm_close(struct vo
*vo
)
1648 Display
*dpy
= vo
->x11
->display
;
1649 struct MPOpts
*opts
= vo
->opts
;
1650 if (vidmodes
!= NULL
)
1656 XF86VidModeGetAllModeLines(dpy
, vo
->x11
->screen
, &modecount
,
1658 for (i
= 0; i
< modecount
; i
++)
1659 if ((vidmodes
[i
]->hdisplay
== opts
->vo_screenwidth
)
1660 && (vidmodes
[i
]->vdisplay
== opts
->vo_screenheight
))
1662 mp_msg(MSGT_VO
, MSGL_INFO
,
1663 "Returning to original mode %dx%d\n",
1664 opts
->vo_screenwidth
, opts
->vo_screenheight
);
1668 XF86VidModeSwitchToMode(dpy
, vo
->x11
->screen
, vidmodes
[i
]);
1669 XF86VidModeSwitchToMode(dpy
, vo
->x11
->screen
, vidmodes
[i
]);
1675 double vo_vm_get_fps(struct vo
*vo
)
1677 struct vo_x11_state
*x11
= vo
->x11
;
1679 XF86VidModeModeLine modeline
;
1680 if (!XF86VidModeGetModeLine(x11
->display
, x11
->screen
, &clock
, &modeline
))
1682 if (modeline
.privsize
)
1683 XFree(modeline
.private);
1684 return 1e3
* clock
/ modeline
.htotal
/ modeline
.vtotal
;
1688 #endif /* X11_FULLSCREEN */
1692 * Scan the available visuals on this Display/Screen. Try to find
1693 * the 'best' available TrueColor visual that has a decent color
1694 * depth (at least 15bit). If there are multiple visuals with depth
1695 * >= 15bit, we prefer visuals with a smaller color depth.
1697 int vo_find_depth_from_visuals(Display
* dpy
, int screen
,
1698 Visual
** visual_return
)
1700 XVisualInfo visual_tmpl
;
1701 XVisualInfo
*visuals
;
1703 int bestvisual
= -1;
1704 int bestvisual_depth
= -1;
1706 visual_tmpl
.screen
= screen
;
1707 visual_tmpl
.class = TrueColor
;
1708 visuals
= XGetVisualInfo(dpy
,
1709 VisualScreenMask
| VisualClassMask
,
1710 &visual_tmpl
, &nvisuals
);
1711 if (visuals
!= NULL
)
1713 for (i
= 0; i
< nvisuals
; i
++)
1715 mp_msg(MSGT_VO
, MSGL_V
,
1716 "vo: X11 truecolor visual %#lx, depth %d, R:%lX G:%lX B:%lX\n",
1717 visuals
[i
].visualid
, visuals
[i
].depth
,
1718 visuals
[i
].red_mask
, visuals
[i
].green_mask
,
1719 visuals
[i
].blue_mask
);
1721 * Save the visual index and its depth, if this is the first
1722 * truecolor visul, or a visual that is 'preferred' over the
1723 * previous 'best' visual.
1725 if (bestvisual_depth
== -1
1726 || (visuals
[i
].depth
>= 15
1727 && (visuals
[i
].depth
< bestvisual_depth
1728 || bestvisual_depth
< 15)))
1731 bestvisual_depth
= visuals
[i
].depth
;
1735 if (bestvisual
!= -1 && visual_return
!= NULL
)
1736 *visual_return
= visuals
[bestvisual
].visual
;
1740 return bestvisual_depth
;
1744 static Colormap cmap
= None
;
1745 static XColor cols
[256];
1746 static int cm_size
, red_mask
, green_mask
, blue_mask
;
1749 Colormap
vo_x11_create_colormap(struct vo
*vo
, XVisualInfo
*vinfo
)
1751 struct vo_x11_state
*x11
= vo
->x11
;
1752 unsigned k
, r
, g
, b
, ru
, gu
, bu
, m
, rv
, gv
, bv
, rvu
, gvu
, bvu
;
1754 if (vinfo
->class != DirectColor
)
1755 return XCreateColormap(x11
->display
, x11
->rootwin
, vinfo
->visual
,
1758 /* can this function get called twice or more? */
1761 cm_size
= vinfo
->colormap_size
;
1762 red_mask
= vinfo
->red_mask
;
1763 green_mask
= vinfo
->green_mask
;
1764 blue_mask
= vinfo
->blue_mask
;
1765 ru
= (red_mask
& (red_mask
- 1)) ^ red_mask
;
1766 gu
= (green_mask
& (green_mask
- 1)) ^ green_mask
;
1767 bu
= (blue_mask
& (blue_mask
- 1)) ^ blue_mask
;
1768 rvu
= 65536ull * ru
/ (red_mask
+ ru
);
1769 gvu
= 65536ull * gu
/ (green_mask
+ gu
);
1770 bvu
= 65536ull * bu
/ (blue_mask
+ bu
);
1773 m
= DoRed
| DoGreen
| DoBlue
;
1774 for (k
= 0; k
< cm_size
; k
++)
1778 cols
[k
].pixel
= r
| g
| b
;
1783 t
= (r
+ ru
) & red_mask
;
1787 t
= (g
+ gu
) & green_mask
;
1791 t
= (b
+ bu
) & blue_mask
;
1799 cmap
= XCreateColormap(x11
->display
, x11
->rootwin
, vinfo
->visual
, AllocAll
);
1800 XStoreColors(x11
->display
, cmap
, cols
, cm_size
);
1805 * Via colormaps/gamma ramps we can do gamma, brightness, contrast,
1806 * hue and red/green/blue intensity, but we cannot do saturation.
1807 * Currently only gamma, brightness and contrast are implemented.
1808 * Is there sufficient interest for hue and/or red/green/blue intensity?
1810 /* these values have range [-100,100] and are initially 0 */
1811 static int vo_gamma
= 0;
1812 static int vo_brightness
= 0;
1813 static int vo_contrast
= 0;
1815 static int transform_color(float val
,
1816 float brightness
, float contrast
, float gamma
) {
1817 float s
= pow(val
, gamma
);
1818 s
= (s
- 0.5) * contrast
+ 0.5;
1824 return (unsigned short) (s
* 65535);
1827 uint32_t vo_x11_set_equalizer(struct vo
*vo
, char *name
, int value
)
1829 float gamma
, brightness
, contrast
;
1834 * IMPLEMENTME: consider using XF86VidModeSetGammaRamp in the case
1835 * of TrueColor-ed window but be careful:
1836 * Unlike the colormaps, which are private for the X client
1837 * who created them and thus automatically destroyed on client
1838 * disconnect, this gamma ramp is a system-wide (X-server-wide)
1839 * setting and _must_ be restored before the process exits.
1840 * Unforunately when the process crashes (or gets killed
1841 * for some reason) it is impossible to restore the setting,
1842 * and such behaviour could be rather annoying for the users.
1847 if (!strcasecmp(name
, "brightness"))
1848 vo_brightness
= value
;
1849 else if (!strcasecmp(name
, "contrast"))
1850 vo_contrast
= value
;
1851 else if (!strcasecmp(name
, "gamma"))
1856 brightness
= 0.01 * vo_brightness
;
1857 contrast
= tan(0.0095 * (vo_contrast
+ 100) * M_PI
/ 4);
1858 gamma
= pow(2, -0.02 * vo_gamma
);
1860 rf
= (float) ((red_mask
& (red_mask
- 1)) ^ red_mask
) / red_mask
;
1861 gf
= (float) ((green_mask
& (green_mask
- 1)) ^ green_mask
) /
1863 bf
= (float) ((blue_mask
& (blue_mask
- 1)) ^ blue_mask
) / blue_mask
;
1865 /* now recalculate the colormap using the newly set value */
1866 for (k
= 0; k
< cm_size
; k
++)
1868 cols
[k
].red
= transform_color(rf
* k
, brightness
, contrast
, gamma
);
1869 cols
[k
].green
= transform_color(gf
* k
, brightness
, contrast
, gamma
);
1870 cols
[k
].blue
= transform_color(bf
* k
, brightness
, contrast
, gamma
);
1873 XStoreColors(vo
->x11
->display
, cmap
, cols
, cm_size
);
1874 XFlush(vo
->x11
->display
);
1878 uint32_t vo_x11_get_equalizer(char *name
, int *value
)
1882 if (!strcasecmp(name
, "brightness"))
1883 *value
= vo_brightness
;
1884 else if (!strcasecmp(name
, "contrast"))
1885 *value
= vo_contrast
;
1886 else if (!strcasecmp(name
, "gamma"))
1894 int vo_xv_set_eq(struct vo
*vo
, uint32_t xv_port
, char *name
, int value
)
1896 XvAttribute
*attributes
;
1897 int i
, howmany
, xv_atom
;
1899 mp_dbg(MSGT_VO
, MSGL_V
, "xv_set_eq called! (%s, %d)\n", name
, value
);
1901 /* get available attributes */
1902 attributes
= XvQueryPortAttributes(vo
->x11
->display
, xv_port
, &howmany
);
1903 for (i
= 0; i
< howmany
&& attributes
; i
++)
1904 if (attributes
[i
].flags
& XvSettable
)
1906 xv_atom
= XInternAtom(vo
->x11
->display
, attributes
[i
].name
, True
);
1907 /* since we have SET_DEFAULTS first in our list, we can check if it's available
1908 then trigger it if it's ok so that the other values are at default upon query */
1909 if (xv_atom
!= None
)
1911 int hue
= 0, port_value
, port_min
, port_max
;
1913 if (!strcmp(attributes
[i
].name
, "XV_BRIGHTNESS") &&
1914 (!strcasecmp(name
, "brightness")))
1916 else if (!strcmp(attributes
[i
].name
, "XV_CONTRAST") &&
1917 (!strcasecmp(name
, "contrast")))
1919 else if (!strcmp(attributes
[i
].name
, "XV_SATURATION") &&
1920 (!strcasecmp(name
, "saturation")))
1922 else if (!strcmp(attributes
[i
].name
, "XV_HUE") &&
1923 (!strcasecmp(name
, "hue")))
1928 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
1929 if (!strcmp(attributes
[i
].name
, "XV_RED_INTENSITY") &&
1930 (!strcasecmp(name
, "red_intensity")))
1932 else if (!strcmp(attributes
[i
].name
, "XV_GREEN_INTENSITY")
1933 && (!strcasecmp(name
, "green_intensity")))
1935 else if (!strcmp(attributes
[i
].name
, "XV_BLUE_INTENSITY")
1936 && (!strcasecmp(name
, "blue_intensity")))
1938 else if ((!strcmp(attributes
[i
].name
, "XV_ITURBT_709") //NVIDIA
1939 || !strcmp(attributes
[i
].name
, "XV_COLORSPACE"))//ATI
1940 && (!strcasecmp(name
, "bt_709")))
1945 port_min
= attributes
[i
].min_value
;
1946 port_max
= attributes
[i
].max_value
;
1948 /* nvidia hue workaround */
1949 if (hue
&& port_min
== 0 && port_max
== 360)
1953 0) ? (port_value
- 100) : (port_value
+ 100);
1959 (port_value
+ 100) * (port_max
- port_min
) / 200 +
1961 XvSetPortAttribute(vo
->x11
->display
, xv_port
, xv_atom
, port_value
);
1968 int vo_xv_get_eq(struct vo
*vo
, uint32_t xv_port
, char *name
, int *value
)
1971 XvAttribute
*attributes
;
1972 int i
, howmany
, xv_atom
;
1974 /* get available attributes */
1975 attributes
= XvQueryPortAttributes(vo
->x11
->display
, xv_port
, &howmany
);
1976 for (i
= 0; i
< howmany
&& attributes
; i
++)
1977 if (attributes
[i
].flags
& XvGettable
)
1979 xv_atom
= XInternAtom(vo
->x11
->display
, attributes
[i
].name
, True
);
1980 /* since we have SET_DEFAULTS first in our list, we can check if it's available
1981 then trigger it if it's ok so that the other values are at default upon query */
1982 if (xv_atom
!= None
)
1984 int val
, port_value
= 0, port_min
, port_max
;
1986 XvGetPortAttribute(vo
->x11
->display
, xv_port
, xv_atom
,
1989 port_min
= attributes
[i
].min_value
;
1990 port_max
= attributes
[i
].max_value
;
1992 (port_value
- port_min
) * 200 / (port_max
- port_min
) -
1995 if (!strcmp(attributes
[i
].name
, "XV_BRIGHTNESS") &&
1996 (!strcasecmp(name
, "brightness")))
1998 else if (!strcmp(attributes
[i
].name
, "XV_CONTRAST") &&
1999 (!strcasecmp(name
, "contrast")))
2001 else if (!strcmp(attributes
[i
].name
, "XV_SATURATION") &&
2002 (!strcasecmp(name
, "saturation")))
2004 else if (!strcmp(attributes
[i
].name
, "XV_HUE") &&
2005 (!strcasecmp(name
, "hue")))
2007 /* nasty nvidia detect */
2008 if (port_min
== 0 && port_max
== 360)
2009 *value
= (val
>= 0) ? (val
- 100) : (val
+ 100);
2013 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
2014 if (!strcmp(attributes
[i
].name
, "XV_RED_INTENSITY") &&
2015 (!strcasecmp(name
, "red_intensity")))
2017 else if (!strcmp(attributes
[i
].name
, "XV_GREEN_INTENSITY")
2018 && (!strcasecmp(name
, "green_intensity")))
2020 else if (!strcmp(attributes
[i
].name
, "XV_BLUE_INTENSITY")
2021 && (!strcasecmp(name
, "blue_intensity")))
2023 else if ((!strcmp(attributes
[i
].name
, "XV_ITURBT_709") //NVIDIA
2024 || !strcmp(attributes
[i
].name
, "XV_COLORSPACE"))//ATI
2025 && (!strcasecmp(name
, "bt_709")))
2030 mp_dbg(MSGT_VO
, MSGL_V
, "xv_get_eq called! (%s, %d)\n",
2039 * \brief Interns the requested atom if it is available.
2041 * \param atom_name String containing the name of the requested atom.
2043 * \return Returns the atom if available, else None is returned.
2046 static Atom
xv_intern_atom_if_exists(struct vo_x11_state
*x11
,
2047 char const *atom_name
)
2049 XvAttribute
* attributes
;
2051 Atom xv_atom
= None
;
2053 attributes
= XvQueryPortAttributes(x11
->display
, x11
->xv_port
, &attrib_count
);
2054 if( attributes
!=NULL
)
2056 for ( i
= 0; i
< attrib_count
; ++i
)
2058 if ( strcmp(attributes
[i
].name
, atom_name
) == 0 )
2060 xv_atom
= XInternAtom(x11
->display
, atom_name
, False
);
2061 break; // found what we want, break out
2064 XFree( attributes
);
2071 * \brief Try to enable vsync for xv.
2072 * \return Returns -1 if not available, 0 on failure and 1 on success.
2074 int vo_xv_enable_vsync(struct vo
*vo
)
2076 struct vo_x11_state
*x11
= vo
->x11
;
2077 Atom xv_atom
= xv_intern_atom_if_exists(x11
, "XV_SYNC_TO_VBLANK");
2078 if (xv_atom
== None
)
2080 return XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, 1) == Success
;
2084 * \brief Get maximum supported source image dimensions.
2086 * This function does not set the variables pointed to by
2087 * width and height if the information could not be retrieved,
2088 * so the caller is reponsible for properly initializing them.
2090 * \param width [out] The maximum width gets stored here.
2091 * \param height [out] The maximum height gets stored here.
2094 void vo_xv_get_max_img_dim(struct vo
*vo
, uint32_t * width
, uint32_t * height
)
2096 struct vo_x11_state
*x11
= vo
->x11
;
2097 XvEncodingInfo
* encodings
;
2098 //unsigned long num_encodings, idx; to int or too long?!
2099 unsigned int num_encodings
, idx
;
2101 XvQueryEncodings(x11
->display
, x11
->xv_port
, &num_encodings
, &encodings
);
2105 for ( idx
= 0; idx
< num_encodings
; ++idx
)
2107 if ( strcmp( encodings
[idx
].name
, "XV_IMAGE" ) == 0 )
2109 *width
= encodings
[idx
].width
;
2110 *height
= encodings
[idx
].height
;
2116 mp_msg( MSGT_VO
, MSGL_V
,
2117 "[xv common] Maximum source image dimensions: %ux%u\n",
2120 XvFreeEncodingInfo( encodings
);
2124 * \brief Print information about the colorkey method and source.
2126 * \param ck_handling Integer value containing the information about
2127 * colorkey handling (see x11_common.h).
2129 * Outputs the content of |ck_handling| as a readable message.
2132 static void vo_xv_print_ck_info(struct vo_x11_state
*x11
)
2134 mp_msg( MSGT_VO
, MSGL_V
, "[xv common] " );
2136 switch ( x11
->xv_ck_info
.method
)
2138 case CK_METHOD_NONE
:
2139 mp_msg( MSGT_VO
, MSGL_V
, "Drawing no colorkey.\n" ); return;
2140 case CK_METHOD_AUTOPAINT
:
2141 mp_msg( MSGT_VO
, MSGL_V
, "Colorkey is drawn by Xv." ); break;
2142 case CK_METHOD_MANUALFILL
:
2143 mp_msg( MSGT_VO
, MSGL_V
, "Drawing colorkey manually." ); break;
2144 case CK_METHOD_BACKGROUND
:
2145 mp_msg( MSGT_VO
, MSGL_V
, "Colorkey is drawn as window background." ); break;
2148 mp_msg( MSGT_VO
, MSGL_V
, "\n[xv common] " );
2150 switch ( x11
->xv_ck_info
.source
)
2153 mp_msg( MSGT_VO
, MSGL_V
, "Using colorkey from Xv (0x%06lx).\n",
2157 if ( x11
->xv_ck_info
.method
== CK_METHOD_AUTOPAINT
)
2159 mp_msg( MSGT_VO
, MSGL_V
,
2160 "Ignoring colorkey from MPlayer (0x%06lx).\n",
2165 mp_msg( MSGT_VO
, MSGL_V
,
2166 "Using colorkey from MPlayer (0x%06lx)."
2167 " Use -colorkey to change.\n",
2172 mp_msg( MSGT_VO
, MSGL_V
,
2173 "Setting and using colorkey from MPlayer (0x%06lx)."
2174 " Use -colorkey to change.\n",
2180 * \brief Init colorkey depending on the settings in xv_ck_info.
2182 * \return Returns 0 on failure and 1 on success.
2184 * Sets the colorkey variable according to the CK_SRC_* and CK_METHOD_*
2185 * flags in xv_ck_info.
2189 * - manual colorkey drawing ( CK_METHOD_MANUALFILL )
2190 * - set colorkey as window background ( CK_METHOD_BACKGROUND )
2191 * - let Xv paint the colorkey ( CK_METHOD_AUTOPAINT )
2193 * - use currently set colorkey ( CK_SRC_CUR )
2194 * - use colorkey in vo_colorkey ( CK_SRC_USE )
2195 * - use and set colorkey in vo_colorkey ( CK_SRC_SET )
2197 * NOTE: If vo_colorkey has bits set after the first 3 low order bytes
2198 * we don't draw anything as this means it was forced to off.
2200 int vo_xv_init_colorkey(struct vo
*vo
)
2202 struct vo_x11_state
*x11
= vo
->x11
;
2206 /* check if colorkeying is needed */
2207 xv_atom
= xv_intern_atom_if_exists(vo
->x11
, "XV_COLORKEY");
2209 /* if we have to deal with colorkeying ... */
2210 if( xv_atom
!= None
&& !(vo_colorkey
& 0xFF000000) )
2212 /* check if we should use the colorkey specified in vo_colorkey */
2213 if ( x11
->xv_ck_info
.source
!= CK_SRC_CUR
)
2215 x11
->xv_colorkey
= vo_colorkey
;
2217 /* check if we have to set the colorkey too */
2218 if ( x11
->xv_ck_info
.source
== CK_SRC_SET
)
2220 xv_atom
= XInternAtom(x11
->display
, "XV_COLORKEY",False
);
2222 rez
= XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, vo_colorkey
);
2223 if ( rez
!= Success
)
2225 mp_msg( MSGT_VO
, MSGL_FATAL
,
2226 "[xv common] Couldn't set colorkey!\n" );
2227 return 0; // error setting colorkey
2235 rez
=XvGetPortAttribute(x11
->display
,x11
->xv_port
, xv_atom
, &colorkey_ret
);
2236 if ( rez
== Success
)
2238 x11
->xv_colorkey
= colorkey_ret
;
2242 mp_msg( MSGT_VO
, MSGL_FATAL
,
2243 "[xv common] Couldn't get colorkey!"
2244 "Maybe the selected Xv port has no overlay.\n" );
2245 return 0; // error getting colorkey
2249 xv_atom
= xv_intern_atom_if_exists(vo
->x11
, "XV_AUTOPAINT_COLORKEY");
2251 /* should we draw the colorkey ourselves or activate autopainting? */
2252 if ( x11
->xv_ck_info
.method
== CK_METHOD_AUTOPAINT
)
2254 rez
= !Success
; // reset rez to something different than Success
2256 if ( xv_atom
!= None
) // autopaint is supported
2258 rez
= XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, 1);
2261 if ( rez
!= Success
)
2263 // fallback to manual colorkey drawing
2264 x11
->xv_ck_info
.method
= CK_METHOD_MANUALFILL
;
2267 else // disable colorkey autopainting if supported
2269 if ( xv_atom
!= None
) // we have autopaint attribute
2271 XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, 0);
2275 else // do no colorkey drawing at all
2277 x11
->xv_ck_info
.method
= CK_METHOD_NONE
;
2278 } /* end: should we draw colorkey */
2280 /* output information about the current colorkey settings */
2281 vo_xv_print_ck_info(x11
);
2283 return 1; // success
2287 * \brief Draw the colorkey on the video window.
2289 * Draws the colorkey depending on the set method ( colorkey_handling ).
2291 * Also draws the black bars ( when the video doesn't fit the display in
2292 * fullscreen ) separately, so they don't overlap with the video area.
2293 * It doesn't call XFlush.
2296 void vo_xv_draw_colorkey(struct vo
*vo
, int32_t x
, int32_t y
,
2297 int32_t w
, int32_t h
)
2299 struct MPOpts
*opts
= vo
->opts
;
2300 struct vo_x11_state
*x11
= vo
->x11
;
2301 if( x11
->xv_ck_info
.method
== CK_METHOD_MANUALFILL
||
2302 x11
->xv_ck_info
.method
== CK_METHOD_BACKGROUND
)//less tearing than XClearWindow()
2304 XSetForeground(x11
->display
, x11
->vo_gc
, x11
->xv_colorkey
);
2305 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2310 /* draw black bars if needed */
2311 /* TODO! move this to vo_x11_clearwindow_part() */
2314 XSetForeground(x11
->display
, x11
->vo_gc
, 0 );
2315 /* making non-overlap fills, requires 8 checks instead of 4 */
2317 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2319 opts
->vo_screenwidth
, y
);
2321 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2323 x
, opts
->vo_screenheight
);
2324 if (x
+ w
< opts
->vo_screenwidth
)
2325 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2327 opts
->vo_screenwidth
, opts
->vo_screenheight
);
2328 if (y
+ h
< opts
->vo_screenheight
)
2329 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2331 opts
->vo_screenwidth
, opts
->vo_screenheight
);
2335 /** \brief Tests if a valid argument for the ck suboption was given. */
2336 int xv_test_ck( void * arg
)
2338 strarg_t
* strarg
= (strarg_t
*)arg
;
2340 if ( strargcmp( strarg
, "use" ) == 0 ||
2341 strargcmp( strarg
, "set" ) == 0 ||
2342 strargcmp( strarg
, "cur" ) == 0 )
2349 /** \brief Tests if a valid arguments for the ck-method suboption was given. */
2350 int xv_test_ckm( void * arg
)
2352 strarg_t
* strarg
= (strarg_t
*)arg
;
2354 if ( strargcmp( strarg
, "bg" ) == 0 ||
2355 strargcmp( strarg
, "man" ) == 0 ||
2356 strargcmp( strarg
, "auto" ) == 0 )
2365 * \brief Modify the colorkey_handling var according to str
2367 * Checks if a valid pointer ( not NULL ) to the string
2368 * was given. And in that case modifies the colorkey_handling
2369 * var to reflect the requested behaviour.
2370 * If nothing happens the content of colorkey_handling stays
2373 * \param str Pointer to the string or NULL
2376 void xv_setup_colorkeyhandling(struct vo
*vo
, const char *ck_method_str
,
2379 struct vo_x11_state
*x11
= vo
->x11
;
2380 /* check if a valid pointer to the string was passed */
2383 if ( strncmp( ck_str
, "use", 3 ) == 0 )
2385 x11
->xv_ck_info
.source
= CK_SRC_USE
;
2387 else if ( strncmp( ck_str
, "set", 3 ) == 0 )
2389 x11
->xv_ck_info
.source
= CK_SRC_SET
;
2392 /* check if a valid pointer to the string was passed */
2393 if ( ck_method_str
)
2395 if ( strncmp( ck_method_str
, "bg", 2 ) == 0 )
2397 x11
->xv_ck_info
.method
= CK_METHOD_BACKGROUND
;
2399 else if ( strncmp( ck_method_str
, "man", 3 ) == 0 )
2401 x11
->xv_ck_info
.method
= CK_METHOD_MANUALFILL
;
2403 else if ( strncmp( ck_method_str
, "auto", 4 ) == 0 )
2405 x11
->xv_ck_info
.method
= CK_METHOD_AUTOPAINT
;
2412 struct vo_x11_state
*vo_x11_init_state(void)
2414 struct vo_x11_state
*s
= talloc_ptrtype(NULL
, s
);
2415 *s
= (struct vo_x11_state
){
2416 .xv_ck_info
= { CK_METHOD_MANUALFILL
, CK_SRC_CUR
},
2417 .olddecor
= MWM_DECOR_ALL
,
2418 .oldfuncs
= MWM_FUNC_MOVE
| MWM_FUNC_CLOSE
| MWM_FUNC_MINIMIZE
|
2419 MWM_FUNC_MAXIMIZE
| MWM_FUNC_RESIZE
,
2420 .old_gravity
= NorthWestGravity
,