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.
30 #include "libavutil/common.h"
31 #include "x11_common.h"
40 #include "video_out.h"
43 #include "osdep/timer.h"
47 #include <X11/Xutil.h>
48 #include <X11/Xatom.h>
51 #include <X11/extensions/scrnsaver.h>
55 #include <X11/extensions/dpms.h>
58 #ifdef CONFIG_XINERAMA
59 #include <X11/extensions/Xinerama.h>
63 #include <X11/extensions/xf86vmode.h>
67 #include <X11/XF86keysym.h>
71 #include <X11/extensions/Xv.h>
72 #include <X11/extensions/Xvlib.h>
74 #include "subopt-helper.h"
77 #include "input/input.h"
78 #include "input/keycodes.h"
80 #define WIN_LAYER_ONBOTTOM 2
81 #define WIN_LAYER_NORMAL 4
82 #define WIN_LAYER_ONTOP 6
83 #define WIN_LAYER_ABOVE_DOCK 10
85 int fs_layer
= WIN_LAYER_ABOVE_DOCK
;
87 int stop_xscreensaver
= 0;
89 static int dpms_disabled
= 0;
91 char *mDisplayName
= NULL
;
93 char **vo_fstype_list
;
95 /* 1 means that the WM is metacity (broken as hell) */
96 int metacity_hack
= 0;
99 XF86VidModeModeInfo
**vidmodes
= NULL
;
100 XF86VidModeModeLine modeline
;
103 static int vo_x11_get_fs_type(int supported
);
104 static void saver_off(Display
*);
105 static void saver_on(Display
*);
108 * Sends the EWMH fullscreen state event.
110 * action: could be one of _NET_WM_STATE_REMOVE -- remove state
111 * _NET_WM_STATE_ADD -- add state
112 * _NET_WM_STATE_TOGGLE -- toggle
114 void vo_x11_ewmh_fullscreen(struct vo_x11_state
*x11
, int action
)
116 assert(action
== _NET_WM_STATE_REMOVE
||
117 action
== _NET_WM_STATE_ADD
|| action
== _NET_WM_STATE_TOGGLE
);
119 if (x11
->fs_type
& vo_wm_FULLSCREEN
)
123 /* init X event structure for _NET_WM_FULLSCREEN client message */
124 xev
.xclient
.type
= ClientMessage
;
125 xev
.xclient
.serial
= 0;
126 xev
.xclient
.send_event
= True
;
127 xev
.xclient
.message_type
= x11
->XA_NET_WM_STATE
;
128 xev
.xclient
.window
= x11
->window
;
129 xev
.xclient
.format
= 32;
130 xev
.xclient
.data
.l
[0] = action
;
131 xev
.xclient
.data
.l
[1] = x11
->XA_NET_WM_STATE_FULLSCREEN
;
132 xev
.xclient
.data
.l
[2] = 0;
133 xev
.xclient
.data
.l
[3] = 0;
134 xev
.xclient
.data
.l
[4] = 0;
136 /* finally send that damn thing */
137 if (!XSendEvent(x11
->display
, DefaultRootWindow(x11
->display
), False
,
138 SubstructureRedirectMask
| SubstructureNotifyMask
,
141 mp_tmsg(MSGT_VO
, MSGL_ERR
, "\nX11: Couldn't send EWMH fullscreen event!\n");
146 static void vo_hidecursor(Display
* disp
, Window win
)
152 const char bm_no_data
[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
155 return; // do not hide if playing on the root window
157 colormap
= DefaultColormap(disp
, DefaultScreen(disp
));
158 if ( !XAllocNamedColor(disp
, colormap
, "black", &black
, &dummy
) )
160 return; // color alloc failed, give up
162 bm_no
= XCreateBitmapFromData(disp
, win
, bm_no_data
, 8, 8);
163 no_ptr
= XCreatePixmapCursor(disp
, bm_no
, bm_no
, &black
, &black
, 0, 0);
164 XDefineCursor(disp
, win
, no_ptr
);
165 XFreeCursor(disp
, no_ptr
);
167 XFreePixmap(disp
, bm_no
);
168 XFreeColors(disp
,colormap
,&black
.pixel
,1,0);
171 static void vo_showcursor(Display
* disp
, Window win
)
175 XDefineCursor(disp
, win
, 0);
178 static int x11_errorhandler(Display
* display
, XErrorEvent
* event
)
183 XGetErrorText(display
, event
->error_code
, (char *) &msg
, MSGLEN
);
185 mp_msg(MSGT_VO
, MSGL_ERR
, "X11 error: %s\n", msg
);
187 mp_msg(MSGT_VO
, MSGL_V
,
188 "Type: %x, display: %p, resourceid: %lx, serial: %lx\n",
189 event
->type
, event
->display
, event
->resourceid
, event
->serial
);
190 mp_msg(MSGT_VO
, MSGL_V
,
191 "Error code: %x, request code: %x, minor code: %x\n",
192 event
->error_code
, event
->request_code
, event
->minor_code
);
195 //exit_player("X11 error");
200 void fstype_help(void)
202 mp_tmsg(MSGT_VO
, MSGL_INFO
, "Available fullscreen layer change modes:\n");
203 mp_msg(MSGT_IDENTIFY
, MSGL_INFO
, "ID_FULL_SCREEN_TYPES\n");
205 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "none",
206 "don't set fullscreen window layer");
207 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "layer",
208 "use _WIN_LAYER hint with default layer");
209 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "layer=<0..15>",
210 "use _WIN_LAYER hint with a given layer number");
211 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "netwm",
212 "force NETWM style");
213 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "above",
214 "use _NETWM_STATE_ABOVE hint if available");
215 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "below",
216 "use _NETWM_STATE_BELOW hint if available");
217 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "fullscreen",
218 "use _NETWM_STATE_FULLSCREEN hint if available");
219 mp_msg(MSGT_VO
, MSGL_INFO
, " %-15s %s\n", "stays_on_top",
220 "use _NETWM_STATE_STAYS_ON_TOP hint if available");
221 mp_msg(MSGT_VO
, MSGL_INFO
,
222 "You can also negate the settings with simply putting '-' in the beginning");
223 mp_msg(MSGT_VO
, MSGL_INFO
, "\n");
226 static void fstype_dump(int fstype
)
230 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Current fstype setting honours");
231 if (fstype
& vo_wm_LAYER
)
232 mp_msg(MSGT_VO
, MSGL_V
, " LAYER");
233 if (fstype
& vo_wm_FULLSCREEN
)
234 mp_msg(MSGT_VO
, MSGL_V
, " FULLSCREEN");
235 if (fstype
& vo_wm_STAYS_ON_TOP
)
236 mp_msg(MSGT_VO
, MSGL_V
, " STAYS_ON_TOP");
237 if (fstype
& vo_wm_ABOVE
)
238 mp_msg(MSGT_VO
, MSGL_V
, " ABOVE");
239 if (fstype
& vo_wm_BELOW
)
240 mp_msg(MSGT_VO
, MSGL_V
, " BELOW");
241 mp_msg(MSGT_VO
, MSGL_V
, " X atoms\n");
243 mp_msg(MSGT_VO
, MSGL_V
,
244 "[x11] Current fstype setting doesn't honour any X atoms\n");
247 static int net_wm_support_state_test(struct vo_x11_state
*x11
, Atom atom
)
249 #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; } }
251 NET_WM_STATE_TEST(FULLSCREEN
);
252 NET_WM_STATE_TEST(ABOVE
);
253 NET_WM_STATE_TEST(STAYS_ON_TOP
);
254 NET_WM_STATE_TEST(BELOW
);
258 static int x11_get_property(struct vo_x11_state
*x11
, Atom type
, Atom
** args
,
259 unsigned long *nitems
)
262 unsigned long bytesafter
;
265 XGetWindowProperty(x11
->display
, x11
->rootwin
, type
, 0, 16384, False
,
266 AnyPropertyType
, &type
, &format
, nitems
,
267 &bytesafter
, (unsigned char **) args
)
271 static int vo_wm_detect(struct vo
*vo
)
273 struct vo_x11_state
*x11
= vo
->x11
;
276 unsigned long nitems
;
282 // -- supports layers
283 if (x11_get_property(x11
, x11
->XA_WIN_PROTOCOLS
, &args
, &nitems
))
285 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Detected wm supports layers.\n");
286 for (i
= 0; i
< nitems
; i
++)
288 if (args
[i
] == x11
->XA_WIN_LAYER
)
293 /* metacity is the only window manager I know which reports
294 * supporting only the _WIN_LAYER hint in _WIN_PROTOCOLS.
295 * (what's more support for it is broken) */
299 if (wm
&& (metacity_hack
== 1))
301 // metacity claims to support layers, but it is not the truth :-)
303 mp_msg(MSGT_VO
, MSGL_V
,
304 "[x11] Using workaround for Metacity bugs.\n");
308 if (x11_get_property(x11
, x11
->XA_NET_SUPPORTED
, &args
, &nitems
))
310 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Detected wm supports NetWM.\n");
311 for (i
= 0; i
< nitems
; i
++)
312 wm
|= net_wm_support_state_test(vo
->x11
, args
[i
]);
317 mp_msg(MSGT_VO
, MSGL_V
, "[x11] Unknown wm type...\n");
321 #define XA_INIT(x) x11->XA##x = XInternAtom(x11->display, #x, False)
322 static void init_atoms(struct vo_x11_state
*x11
)
324 XA_INIT(_NET_SUPPORTED
);
325 XA_INIT(_NET_WM_STATE
);
326 XA_INIT(_NET_WM_STATE_FULLSCREEN
);
327 XA_INIT(_NET_WM_STATE_ABOVE
);
328 XA_INIT(_NET_WM_STATE_STAYS_ON_TOP
);
329 XA_INIT(_NET_WM_STATE_BELOW
);
330 XA_INIT(_NET_WM_PID
);
331 XA_INIT(_NET_WM_NAME
);
332 XA_INIT(_NET_WM_ICON_NAME
);
333 XA_INIT(_WIN_PROTOCOLS
);
336 XA_INIT(WM_PROTOCOLS
);
337 XA_INIT(WM_DELETE_WINDOW
);
338 XA_INIT(UTF8_STRING
);
341 void update_xinerama_info(struct vo
*vo
) {
342 struct MPOpts
*opts
= vo
->opts
;
343 xinerama_x
= xinerama_y
= 0;
344 #ifdef CONFIG_XINERAMA
345 if (xinerama_screen
>= -1 && XineramaIsActive(vo
->x11
->display
))
347 int screen
= xinerama_screen
;
348 XineramaScreenInfo
*screens
;
351 screens
= XineramaQueryScreens(vo
->x11
->display
, &num_screens
);
352 if (screen
>= num_screens
)
353 screen
= num_screens
- 1;
355 int x
= vo
->dx
+ vo
->dwidth
/ 2;
356 int y
= vo
->dy
+ vo
->dheight
/ 2;
357 for (screen
= num_screens
- 1; screen
> 0; screen
--) {
358 int left
= screens
[screen
].x_org
;
359 int right
= left
+ screens
[screen
].width
;
360 int top
= screens
[screen
].y_org
;
361 int bottom
= top
+ screens
[screen
].height
;
362 if (left
<= x
&& x
<= right
&& top
<= y
&& y
<= bottom
)
368 opts
->vo_screenwidth
= screens
[screen
].width
;
369 opts
->vo_screenheight
= screens
[screen
].height
;
370 xinerama_x
= screens
[screen
].x_org
;
371 xinerama_y
= screens
[screen
].y_org
;
376 aspect_save_screenres(vo
, opts
->vo_screenwidth
, opts
->vo_screenheight
);
379 int vo_init(struct vo
*vo
)
381 struct MPOpts
*opts
= vo
->opts
;
382 struct vo_x11_state
*x11
= vo
->x11
;
387 // char * DisplayName = ":0.0";
388 // Display * mDisplay;
389 XImage
*mXImage
= NULL
;
392 XWindowAttributes attribs
;
396 WinID
= 0; // use root window
398 if (x11
->depthonscreen
)
400 saver_off(x11
->display
);
401 return 1; // already called
404 XSetErrorHandler(x11_errorhandler
);
408 if (!(mDisplayName
= getenv("DISPLAY")))
409 mDisplayName
= strdup(":0.0");
411 dispName
= XDisplayName(mDisplayName
);
414 mp_msg(MSGT_VO
, MSGL_V
, "X11 opening display: %s\n", dispName
);
416 x11
->display
= XOpenDisplay(dispName
);
419 mp_msg(MSGT_VO
, MSGL_ERR
,
420 "vo: couldn't open the X11 display (%s)!\n", dispName
);
423 x11
->screen
= DefaultScreen(x11
->display
); // screen ID
424 x11
->rootwin
= RootWindow(x11
->display
, x11
->screen
); // root window ID
426 x11
->xim
= XOpenIM(x11
->display
, NULL
, NULL
, NULL
);
434 XF86VidModeGetModeLine(x11
->display
, x11
->screen
, &clock
, &modeline
);
435 if (!opts
->vo_screenwidth
)
436 opts
->vo_screenwidth
= modeline
.hdisplay
;
437 if (!opts
->vo_screenheight
)
438 opts
->vo_screenheight
= modeline
.vdisplay
;
442 if (!opts
->vo_screenwidth
)
443 opts
->vo_screenwidth
= DisplayWidth(x11
->display
, x11
->screen
);
444 if (!opts
->vo_screenheight
)
445 opts
->vo_screenheight
= DisplayHeight(x11
->display
, x11
->screen
);
447 // get color depth (from root window, or the best visual):
448 XGetWindowAttributes(x11
->display
, x11
->rootwin
, &attribs
);
449 depth
= attribs
.depth
;
451 if (depth
!= 15 && depth
!= 16 && depth
!= 24 && depth
!= 32)
455 depth
= vo_find_depth_from_visuals(x11
->display
, x11
->screen
, &visual
);
457 mXImage
= XCreateImage(x11
->display
, visual
, depth
, ZPixmap
,
458 0, NULL
, 1, 1, 8, 1);
461 XGetImage(x11
->display
, x11
->rootwin
, 0, 0, 1, 1, AllPlanes
, ZPixmap
);
463 x11
->depthonscreen
= depth
; // display depth on screen
465 // get bits/pixel from XImage structure:
472 * for the depth==24 case, the XImage structures might use
473 * 24 or 32 bits of data per pixel. The x11->depthonscreen
474 * field stores the amount of data per pixel in the
477 * Maybe we should rename vo_depthonscreen to (or add) vo_bpp?
479 bpp
= mXImage
->bits_per_pixel
;
480 if ((x11
->depthonscreen
+ 7) / 8 != (bpp
+ 7) / 8)
481 x11
->depthonscreen
= bpp
; // by A'rpi
483 mXImage
->red_mask
| mXImage
->green_mask
| mXImage
->blue_mask
;
484 mp_msg(MSGT_VO
, MSGL_V
,
485 "vo: X11 color mask: %X (R:%lX G:%lX B:%lX)\n", mask
,
486 mXImage
->red_mask
, mXImage
->green_mask
, mXImage
->blue_mask
);
487 XDestroyImage(mXImage
);
489 if (((x11
->depthonscreen
+ 7) / 8) == 2)
492 x11
->depthonscreen
= 15;
493 else if (mask
== 0xFFFF)
494 x11
->depthonscreen
= 16;
496 // XCloseDisplay( mDisplay );
497 /* slightly improved local display detection AST */
498 if (strncmp(dispName
, "unix:", 5) == 0)
500 else if (strncmp(dispName
, "localhost:", 10) == 0)
502 if (*dispName
== ':' && atoi(dispName
+ 1) < 10)
503 x11
->display_is_local
= 1;
505 x11
->display_is_local
= 0;
506 mp_msg(MSGT_VO
, MSGL_V
,
507 "vo: X11 running at %dx%d with depth %d and %d bpp (\"%s\" => %s display)\n",
508 opts
->vo_screenwidth
, opts
->vo_screenheight
, depth
, x11
->depthonscreen
,
509 dispName
, x11
->display_is_local
? "local" : "remote");
511 x11
->wm_type
= vo_wm_detect(vo
);
513 x11
->fs_type
= vo_x11_get_fs_type(x11
->wm_type
);
515 fstype_dump(x11
->fs_type
);
517 saver_off(x11
->display
);
521 void vo_uninit(struct vo_x11_state
*x11
)
525 mp_msg(MSGT_VO
, MSGL_V
,
526 "vo: x11 uninit called but X11 not initialized..\n");
528 mp_msg(MSGT_VO
, MSGL_V
, "vo: uninit ...\n");
531 XSetErrorHandler(NULL
);
532 XCloseDisplay(x11
->display
);
533 x11
->depthonscreen
= 0;
541 static const struct mp_keymap keymap
[] = {
543 {wsPause
, KEY_PAUSE
}, {wsEscape
, KEY_ESC
}, {wsBackSpace
, KEY_BS
},
544 {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
},
574 #ifdef XF86XK_AudioPause
575 {XF86XK_MenuKB
, KEY_MENU
},
576 {XF86XK_AudioPlay
, KEY_PLAY
}, {XF86XK_AudioPause
, KEY_PAUSE
}, {XF86XK_AudioStop
, KEY_STOP
},
577 {XF86XK_AudioPrev
, KEY_PREV
}, {XF86XK_AudioNext
, KEY_NEXT
},
578 {XF86XK_AudioMute
, KEY_MUTE
}, {XF86XK_AudioLowerVolume
, KEY_VOLUME_DOWN
}, {XF86XK_AudioRaiseVolume
, KEY_VOLUME_UP
},
584 static int vo_x11_lookupkey(int key
)
586 static const char *passthrough_keys
= " -+*/<>`~!@#$%^&()_{}:;\"\',.?\\|=[]";
588 if ((key
>= 'a' && key
<= 'z') ||
589 (key
>= 'A' && key
<= 'Z') ||
590 (key
>= '0' && key
<= '9') ||
591 (key
> 0 && key
< 256 && strchr(passthrough_keys
, key
)))
595 mpkey
= lookup_keymap_table(keymap
, key
);
601 // ----- Motif header: -------
603 #define MWM_HINTS_FUNCTIONS (1L << 0)
604 #define MWM_HINTS_DECORATIONS (1L << 1)
605 #define MWM_HINTS_INPUT_MODE (1L << 2)
606 #define MWM_HINTS_STATUS (1L << 3)
608 #define MWM_FUNC_ALL (1L << 0)
609 #define MWM_FUNC_RESIZE (1L << 1)
610 #define MWM_FUNC_MOVE (1L << 2)
611 #define MWM_FUNC_MINIMIZE (1L << 3)
612 #define MWM_FUNC_MAXIMIZE (1L << 4)
613 #define MWM_FUNC_CLOSE (1L << 5)
615 #define MWM_DECOR_ALL (1L << 0)
616 #define MWM_DECOR_BORDER (1L << 1)
617 #define MWM_DECOR_RESIZEH (1L << 2)
618 #define MWM_DECOR_TITLE (1L << 3)
619 #define MWM_DECOR_MENU (1L << 4)
620 #define MWM_DECOR_MINIMIZE (1L << 5)
621 #define MWM_DECOR_MAXIMIZE (1L << 6)
623 #define MWM_INPUT_MODELESS 0
624 #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
625 #define MWM_INPUT_SYSTEM_MODAL 2
626 #define MWM_INPUT_FULL_APPLICATION_MODAL 3
627 #define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL
629 #define MWM_TEAROFF_WINDOW (1L<<0)
640 static MotifWmHints vo_MotifWmHints
;
641 static Atom vo_MotifHints
= None
;
643 void vo_x11_decoration(struct vo
*vo
, int d
)
645 struct vo_x11_state
*x11
= vo
->x11
;
648 unsigned long mn
, mb
;
655 XSetTransientForHint(x11
->display
, x11
->window
,
656 RootWindow(x11
->display
, x11
->screen
));
659 vo_MotifHints
= XInternAtom(x11
->display
, "_MOTIF_WM_HINTS", 0);
660 if (vo_MotifHints
!= None
)
664 MotifWmHints
*mhints
= NULL
;
666 XGetWindowProperty(x11
->display
, x11
->window
,
667 vo_MotifHints
, 0, 20, False
,
668 vo_MotifHints
, &mtype
, &mformat
, &mn
,
669 &mb
, (unsigned char **) &mhints
);
672 if (mhints
->flags
& MWM_HINTS_DECORATIONS
)
673 x11
->olddecor
= mhints
->decorations
;
674 if (mhints
->flags
& MWM_HINTS_FUNCTIONS
)
675 x11
->oldfuncs
= mhints
->functions
;
680 memset(&vo_MotifWmHints
, 0, sizeof(MotifWmHints
));
681 vo_MotifWmHints
.flags
=
682 MWM_HINTS_FUNCTIONS
| MWM_HINTS_DECORATIONS
;
685 vo_MotifWmHints
.functions
= x11
->oldfuncs
;
689 vo_MotifWmHints
.decorations
=
690 d
| ((vo_fsmode
& 2) ? 0 : MWM_DECOR_MENU
);
692 vo_MotifWmHints
.decorations
=
693 d
| ((vo_fsmode
& 2) ? MWM_DECOR_MENU
: 0);
695 XChangeProperty(x11
->display
, x11
->window
, vo_MotifHints
,
698 (unsigned char *) &vo_MotifWmHints
,
699 (vo_fsmode
& 4) ? 4 : 5);
703 void vo_x11_classhint(struct vo
*vo
, Window window
, const char *name
)
705 struct MPOpts
*opts
= vo
->opts
;
706 struct vo_x11_state
*x11
= vo
->x11
;
708 pid_t pid
= getpid();
710 wmClass
.res_name
= opts
->vo_winname
? opts
->vo_winname
: (char *)name
;
711 wmClass
.res_class
= "mplayer2";
712 XSetClassHint(x11
->display
, window
, &wmClass
);
713 XChangeProperty(x11
->display
, window
, x11
->XA_NET_WM_PID
, XA_CARDINAL
,
714 32, PropModeReplace
, (unsigned char *) &pid
, 1);
717 void vo_x11_uninit(struct vo
*vo
)
719 struct vo_x11_state
*x11
= vo
->x11
;
720 saver_on(x11
->display
);
721 if (x11
->window
!= None
)
722 vo_showcursor(x11
->display
, x11
->window
);
724 if (x11
->f_gc
!= None
)
726 XFreeGC(vo
->x11
->display
, x11
->f_gc
);
730 if (x11
->vo_gc
!= None
)
732 XFreeGC(vo
->x11
->display
, x11
->vo_gc
);
735 if (x11
->window
!= None
)
737 XClearWindow(x11
->display
, x11
->window
);
743 XDestroyIC(x11
->xic
);
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
, true);
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
;
786 if (x11
->vo_mouse_autohide
&& x11
->mouse_waiting_hide
&&
787 (GetTimerMS() - x11
->mouse_timer
>= 1000)) {
788 vo_hidecursor(display
, x11
->window
);
789 x11
->mouse_waiting_hide
= 0;
793 ret
|= check_resize(vo
);
794 while (XPending(display
))
796 XNextEvent(display
, &Event
);
797 // printf("\rEvent.type=%X \n",Event.type);
801 ret
|= VO_EVENT_EXPOSE
;
803 case ConfigureNotify
:
804 if (x11
->window
== None
)
806 ret
|= check_resize(vo
);
813 if (Event
.xkey
.state
& ShiftMask
)
814 modifiers
|= KEY_MODIFIER_SHIFT
;
815 if (Event
.xkey
.state
& ControlMask
)
816 modifiers
|= KEY_MODIFIER_CTRL
;
817 if (Event
.xkey
.state
& Mod1Mask
)
818 modifiers
|= KEY_MODIFIER_ALT
;
819 if (Event
.xkey
.state
& Mod4Mask
)
820 modifiers
|= KEY_MODIFIER_META
;
823 int len
= Xutf8LookupString(x11
->xic
, &Event
.xkey
, buf
,
824 sizeof(buf
), &keySym
,
826 int mpkey
= vo_x11_lookupkey(keySym
);
828 mplayer_put_key(vo
->key_fifo
, mpkey
| modifiers
);
829 } else if (status
== XLookupChars
830 || status
== XLookupBoth
)
832 struct bstr t
= { buf
, len
};
833 mplayer_put_key_utf8(vo
->key_fifo
, modifiers
, t
);
836 XLookupString(&Event
.xkey
, buf
, sizeof(buf
), &keySym
,
837 &x11
->compose_status
);
838 int mpkey
= vo_x11_lookupkey(keySym
);
840 mplayer_put_key(vo
->key_fifo
, mpkey
| modifiers
);
842 ret
|= VO_EVENT_KEYPRESS
;
846 vo_mouse_movement(vo
, Event
.xmotion
.x
, Event
.xmotion
.y
);
848 if (x11
->vo_mouse_autohide
)
850 vo_showcursor(display
, x11
->window
);
851 x11
->mouse_waiting_hide
= 1;
852 x11
->mouse_timer
= GetTimerMS();
856 if (x11
->vo_mouse_autohide
)
858 vo_showcursor(display
, x11
->window
);
859 x11
->mouse_waiting_hide
= 1;
860 x11
->mouse_timer
= GetTimerMS();
862 mplayer_put_key(vo
->key_fifo
,
863 (MOUSE_BTN0
+ Event
.xbutton
.button
- 1)
867 if (x11
->vo_mouse_autohide
)
869 vo_showcursor(display
, x11
->window
);
870 x11
->mouse_waiting_hide
= 1;
871 x11
->mouse_timer
= GetTimerMS();
873 mplayer_put_key(vo
->key_fifo
,
874 MOUSE_BTN0
+ Event
.xbutton
.button
- 1);
879 XGetAtomName(display
, Event
.xproperty
.atom
);
884 // fprintf(stderr,"[ws] PropertyNotify ( 0x%x ) %s ( 0x%x )\n",vo_window,name,Event.xproperty.atom );
890 x11
->vo_hint
.win_gravity
= x11
->old_gravity
;
891 XSetWMNormalHints(display
, x11
->window
, &x11
->vo_hint
);
895 mp_msg(MSGT_VO
, MSGL_WARN
, "Our window was destroyed, exiting\n");
896 mplayer_put_key(vo
->key_fifo
, KEY_CLOSE_WIN
);
899 if (Event
.xclient
.message_type
== x11
->XAWM_PROTOCOLS
&&
900 Event
.xclient
.data
.l
[0] == x11
->XAWM_DELETE_WINDOW
)
901 mplayer_put_key(vo
->key_fifo
, KEY_CLOSE_WIN
);
909 * \brief sets the size and position of the non-fullscreen window.
911 static void vo_x11_nofs_sizepos(struct vo
*vo
, int x
, int y
,
912 int width
, int height
)
914 struct vo_x11_state
*x11
= vo
->x11
;
915 if (width
== x11
->last_video_width
&& height
== x11
->last_video_height
) {
916 if (!vo
->opts
->force_window_position
&& !x11
->size_changed_during_fs
)
919 x11
->size_changed_during_fs
= true;
920 x11
->last_video_height
= height
;
921 x11
->last_video_width
= width
;
922 vo_x11_sizehint(vo
, x
, y
, width
, height
, 0);
926 x11
->vo_old_width
= width
;
927 x11
->vo_old_height
= height
;
932 vo
->dheight
= height
;
933 if (vo
->opts
->force_window_position
)
934 XMoveResizeWindow(vo
->x11
->display
, vo
->x11
->window
, x
, y
, width
,
937 XResizeWindow(vo
->x11
->display
, vo
->x11
->window
, width
, height
);
941 void vo_x11_sizehint(struct vo
*vo
, int x
, int y
, int width
, int height
, int max
)
943 struct vo_x11_state
*x11
= vo
->x11
;
944 x11
->vo_hint
.flags
= 0;
947 x11
->vo_hint
.flags
|= PAspect
;
948 x11
->vo_hint
.min_aspect
.x
= width
;
949 x11
->vo_hint
.min_aspect
.y
= height
;
950 x11
->vo_hint
.max_aspect
.x
= width
;
951 x11
->vo_hint
.max_aspect
.y
= height
;
954 x11
->vo_hint
.flags
|= PPosition
| PSize
;
957 x11
->vo_hint
.width
= width
;
958 x11
->vo_hint
.height
= height
;
961 x11
->vo_hint
.flags
|= PMaxSize
;
962 x11
->vo_hint
.max_width
= width
;
963 x11
->vo_hint
.max_height
= height
;
966 x11
->vo_hint
.max_width
= 0;
967 x11
->vo_hint
.max_height
= 0;
970 // Set minimum height/width to 4 to avoid off-by-one errors
971 // and because mga_vid requires a minimal size of 4 pixels.
972 x11
->vo_hint
.flags
|= PMinSize
;
973 x11
->vo_hint
.min_width
= x11
->vo_hint
.min_height
= 4;
975 // Set the base size. A window manager might display the window
976 // size to the user relative to this.
977 // Setting these to width/height might be nice, but e.g. fluxbox can't handle it.
978 x11
->vo_hint
.flags
|= PBaseSize
;
979 x11
->vo_hint
.base_width
= 0 /*width*/;
980 x11
->vo_hint
.base_height
= 0 /*height*/;
982 x11
->vo_hint
.flags
|= PWinGravity
;
983 x11
->vo_hint
.win_gravity
= StaticGravity
;
984 XSetWMNormalHints(x11
->display
, x11
->window
, &x11
->vo_hint
);
987 static int vo_x11_get_gnome_layer(struct vo_x11_state
*x11
, Window win
)
991 unsigned long nitems
;
992 unsigned long bytesafter
;
993 unsigned short *args
= NULL
;
995 if (XGetWindowProperty(x11
->display
, win
, x11
->XA_WIN_LAYER
, 0, 16384,
996 False
, AnyPropertyType
, &type
, &format
, &nitems
,
998 (unsigned char **) &args
) == Success
999 && nitems
> 0 && args
)
1001 mp_msg(MSGT_VO
, MSGL_V
, "[x11] original window layer is %d.\n",
1005 return WIN_LAYER_NORMAL
;
1008 // set a X text property that expects a UTF8_STRING type
1009 static void vo_x11_set_property_utf8(struct vo
*vo
, Atom name
, const char *t
)
1011 struct vo_x11_state
*x11
= vo
->x11
;
1013 XChangeProperty(x11
->display
, x11
->window
, name
, x11
->XAUTF8_STRING
, 8,
1014 PropModeReplace
, t
, strlen(t
));
1017 // set a X text property that expects a STRING or COMPOUND_TEXT type
1018 static void vo_x11_set_property_string(struct vo
*vo
, Atom name
, const char *t
)
1020 struct vo_x11_state
*x11
= vo
->x11
;
1021 XTextProperty prop
= {0};
1023 if (Xutf8TextListToTextProperty(x11
->display
, (char **)&t
, 1,
1024 XStdICCTextStyle
, &prop
) == Success
) {
1025 XSetTextProperty(x11
->display
, x11
->window
, &prop
, name
);
1027 // Strictly speaking this violates the ICCCM, but there's no way we
1028 // can do this correctly.
1029 vo_x11_set_property_utf8(vo
, name
, t
);
1036 static void vo_x11_update_window_title(struct vo
*vo
)
1038 struct vo_x11_state
*x11
= vo
->x11
;
1040 const char *title
= vo_get_window_title(vo
);
1041 vo_x11_set_property_string(vo
, XA_WM_NAME
, title
);
1042 vo_x11_set_property_string(vo
, XA_WM_ICON_NAME
, title
);
1043 vo_x11_set_property_utf8(vo
, x11
->XA_NET_WM_NAME
, title
);
1044 vo_x11_set_property_utf8(vo
, x11
->XA_NET_WM_ICON_NAME
, title
);
1048 static Window
vo_x11_create_smooth_window(struct vo_x11_state
*x11
, Window mRoot
,
1049 Visual
* vis
, int x
, int y
,
1050 unsigned int width
, unsigned int height
,
1051 int depth
, Colormap col_map
)
1053 unsigned long xswamask
= CWBorderPixel
;
1054 XSetWindowAttributes xswa
;
1057 if (col_map
!= CopyFromParent
)
1059 xswa
.colormap
= col_map
;
1060 xswamask
|= CWColormap
;
1062 xswa
.background_pixel
= 0;
1063 xswa
.border_pixel
= 0;
1064 xswa
.backing_store
= NotUseful
;
1065 xswa
.bit_gravity
= StaticGravity
;
1068 XCreateWindow(x11
->display
, x11
->rootwin
, x
, y
, width
, height
, 0, depth
,
1069 CopyFromParent
, vis
, xswamask
, &xswa
);
1070 XSetWMProtocols(x11
->display
, ret_win
, &x11
->XAWM_DELETE_WINDOW
, 1);
1071 if (x11
->f_gc
== None
)
1072 x11
->f_gc
= XCreateGC(x11
->display
, ret_win
, 0, 0);
1073 XSetForeground(x11
->display
, x11
->f_gc
, 0);
1079 * \brief create and setup a window suitable for display
1080 * \param vis Visual to use for creating the window
1081 * \param x x position of window
1082 * \param y y position of window
1083 * \param width width of window
1084 * \param height height of window
1085 * \param flags flags for window creation.
1086 * Only VOFLAG_FULLSCREEN is supported so far.
1087 * \param col_map Colourmap for window or CopyFromParent if a specific colormap isn't needed
1088 * \param classname name to use for the classhint
1090 * This also does the grunt-work like setting Window Manager hints etc.
1091 * If vo_window is already set it just moves and resizes it.
1093 void vo_x11_create_vo_window(struct vo
*vo
, XVisualInfo
*vis
, int x
, int y
,
1094 unsigned int width
, unsigned int height
, int flags
,
1095 Colormap col_map
, const char *classname
)
1097 struct MPOpts
*opts
= vo
->opts
;
1098 struct vo_x11_state
*x11
= vo
->x11
;
1099 Display
*mDisplay
= vo
->x11
->display
;
1101 vo_fs
= flags
& VOFLAG_FULLSCREEN
;
1102 x11
->window
= WinID
? (Window
)WinID
: x11
->rootwin
;
1103 if (col_map
!= CopyFromParent
) {
1104 unsigned long xswamask
= CWColormap
;
1105 XSetWindowAttributes xswa
;
1106 xswa
.colormap
= col_map
;
1107 XChangeWindowAttributes(mDisplay
, x11
->window
, xswamask
, &xswa
);
1108 XInstallColormap(mDisplay
, col_map
);
1111 // Expose events can only really be handled by us, so request them.
1112 vo_x11_selectinput_witherr(mDisplay
, x11
->window
, ExposureMask
);
1114 // Do not capture events since it might break the parent application
1115 // if it relies on events being forwarded to the parent of WinID.
1116 // It also is consistent with the w32_common.c code.
1117 vo_x11_selectinput_witherr(mDisplay
, x11
->window
,
1118 StructureNotifyMask
| KeyPressMask
| PointerMotionMask
|
1119 ButtonPressMask
| ButtonReleaseMask
| ExposureMask
);
1121 vo_x11_update_geometry(vo
, true);
1124 if (x11
->window
== None
) {
1127 vo
->dheight
= height
;
1128 x11
->window
= vo_x11_create_smooth_window(x11
, x11
->rootwin
, vis
->visual
,
1129 x
, y
, width
, height
, vis
->depth
, col_map
);
1130 x11
->window_state
= VOFLAG_HIDDEN
;
1132 if (flags
& VOFLAG_HIDDEN
)
1134 if (x11
->window_state
& VOFLAG_HIDDEN
) {
1136 x11
->window_state
&= ~VOFLAG_HIDDEN
;
1137 vo_x11_classhint(vo
, x11
->window
, classname
);
1138 vo_hidecursor(mDisplay
, x11
->window
);
1139 XSelectInput(mDisplay
, x11
->window
, StructureNotifyMask
);
1140 hint
.x
= x
; hint
.y
= y
;
1141 hint
.width
= width
; hint
.height
= height
;
1143 if (geometry_xy_changed
)
1144 hint
.flags
|= PPosition
;
1145 XSetWMNormalHints(mDisplay
, x11
->window
, &hint
);
1146 if (!vo_border
) vo_x11_decoration(vo
, 0);
1148 x11
->xic
= XCreateIC(x11
->xim
,
1149 XNInputStyle
, XIMPreeditNone
| XIMStatusNone
,
1150 XNClientWindow
, x11
->window
,
1151 XNFocusWindow
, x11
->window
,
1153 XSelectInput(mDisplay
, x11
->window
, NoEventMask
);
1154 vo_x11_selectinput_witherr(mDisplay
, x11
->window
,
1155 StructureNotifyMask
| KeyPressMask
| PointerMotionMask
|
1156 ButtonPressMask
| ButtonReleaseMask
| ExposureMask
);
1157 XMapWindow(mDisplay
, x11
->window
);
1158 vo_x11_clearwindow(vo
, x11
->window
);
1160 vo_x11_update_window_title(vo
);
1161 if (opts
->vo_ontop
) vo_x11_setlayer(vo
, x11
->window
, opts
->vo_ontop
);
1162 vo_x11_update_geometry(vo
, !geometry_xy_changed
);
1163 vo_x11_nofs_sizepos(vo
, vo
->dx
, vo
->dy
, width
, height
);
1164 if (!!vo_fs
!= !!(flags
& VOFLAG_FULLSCREEN
))
1165 vo_x11_fullscreen(vo
);
1167 // if we are already in fullscreen do not switch back and forth, just
1168 // set the size values right.
1169 vo
->dwidth
= vo
->opts
->vo_screenwidth
;
1170 vo
->dheight
= vo
->opts
->vo_screenheight
;
1173 if (x11
->vo_gc
!= None
)
1174 XFreeGC(mDisplay
, x11
->vo_gc
);
1175 x11
->vo_gc
= XCreateGC(mDisplay
, x11
->window
, 0, NULL
);
1177 XSync(mDisplay
, False
);
1178 x11
->vo_mouse_autohide
= 1;
1179 vo
->event_fd
= ConnectionNumber(x11
->display
);
1182 void vo_x11_clearwindow_part(struct vo
*vo
, Window vo_window
,
1183 int img_width
, int img_height
)
1185 struct vo_x11_state
*x11
= vo
->x11
;
1186 Display
*mDisplay
= vo
->x11
->display
;
1187 int u_dheight
, u_dwidth
, left_ov
, left_ov2
;
1189 if (x11
->f_gc
== None
)
1192 u_dheight
= vo
->dheight
;
1193 u_dwidth
= vo
->dwidth
;
1194 if ((u_dheight
<= img_height
) && (u_dwidth
<= img_width
))
1197 left_ov
= (u_dheight
- img_height
) / 2;
1198 left_ov2
= (u_dwidth
- img_width
) / 2;
1200 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, 0, 0, u_dwidth
, left_ov
);
1201 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, 0, u_dheight
- left_ov
- 1,
1202 u_dwidth
, left_ov
+ 1);
1204 if (u_dwidth
> img_width
)
1206 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, 0, left_ov
, left_ov2
,
1208 XFillRectangle(mDisplay
, vo_window
, x11
->f_gc
, u_dwidth
- left_ov2
- 1,
1209 left_ov
, left_ov2
+ 1, img_height
);
1215 void vo_x11_clearwindow(struct vo
*vo
, Window vo_window
)
1217 struct vo_x11_state
*x11
= vo
->x11
;
1218 struct MPOpts
*opts
= vo
->opts
;
1219 if (x11
->f_gc
== None
)
1221 XFillRectangle(x11
->display
, vo_window
, x11
->f_gc
, 0, 0,
1222 opts
->vo_screenwidth
, opts
->vo_screenheight
);
1224 XFlush(x11
->display
);
1228 void vo_x11_setlayer(struct vo
*vo
, Window vo_window
, int layer
)
1230 struct vo_x11_state
*x11
= vo
->x11
;
1234 if (x11
->fs_type
& vo_wm_LAYER
)
1236 XClientMessageEvent xev
;
1238 if (!x11
->orig_layer
)
1239 x11
->orig_layer
= vo_x11_get_gnome_layer(x11
, vo_window
);
1241 memset(&xev
, 0, sizeof(xev
));
1242 xev
.type
= ClientMessage
;
1243 xev
.display
= x11
->display
;
1244 xev
.window
= vo_window
;
1245 xev
.message_type
= x11
->XA_WIN_LAYER
;
1247 xev
.data
.l
[0] = layer
? fs_layer
: x11
->orig_layer
; // if not fullscreen, stay on default layer
1248 xev
.data
.l
[1] = CurrentTime
;
1249 mp_msg(MSGT_VO
, MSGL_V
,
1250 "[x11] Layered style stay on top (layer %ld).\n",
1252 XSendEvent(x11
->display
, x11
->rootwin
, False
, SubstructureNotifyMask
,
1254 } else if (x11
->fs_type
& vo_wm_NETWM
)
1256 XClientMessageEvent xev
;
1259 memset(&xev
, 0, sizeof(xev
));
1260 xev
.type
= ClientMessage
;
1261 xev
.message_type
= x11
->XA_NET_WM_STATE
;
1262 xev
.display
= x11
->display
;
1263 xev
.window
= vo_window
;
1265 xev
.data
.l
[0] = layer
;
1267 if (x11
->fs_type
& vo_wm_STAYS_ON_TOP
)
1268 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_STAYS_ON_TOP
;
1269 else if (x11
->fs_type
& vo_wm_ABOVE
)
1270 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_ABOVE
;
1271 else if (x11
->fs_type
& vo_wm_FULLSCREEN
)
1272 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_FULLSCREEN
;
1273 else if (x11
->fs_type
& vo_wm_BELOW
)
1274 // This is not fallback. We can safely assume that the situation
1275 // where only NETWM_STATE_BELOW is supported doesn't exist.
1276 xev
.data
.l
[1] = x11
->XA_NET_WM_STATE_BELOW
;
1278 XSendEvent(x11
->display
, x11
->rootwin
, False
, SubstructureRedirectMask
,
1280 state
= XGetAtomName(x11
->display
, xev
.data
.l
[1]);
1281 mp_msg(MSGT_VO
, MSGL_V
,
1282 "[x11] NET style stay on top (layer %d). Using state %s.\n",
1288 static int vo_x11_get_fs_type(int supported
)
1291 int type
= supported
;
1295 for (i
= 0; vo_fstype_list
[i
]; i
++)
1298 char *arg
= vo_fstype_list
[i
];
1300 if (vo_fstype_list
[i
][0] == '-')
1303 arg
= vo_fstype_list
[i
] + 1;
1306 if (!strncmp(arg
, "layer", 5))
1308 if (!neg
&& (arg
[5] == '='))
1310 char *endptr
= NULL
;
1311 int layer
= strtol(vo_fstype_list
[i
] + 6, &endptr
, 10);
1313 if (endptr
&& *endptr
== '\0' && layer
>= 0
1318 type
&= ~vo_wm_LAYER
;
1320 type
|= vo_wm_LAYER
;
1321 } else if (!strcmp(arg
, "above"))
1324 type
&= ~vo_wm_ABOVE
;
1326 type
|= vo_wm_ABOVE
;
1327 } else if (!strcmp(arg
, "fullscreen"))
1330 type
&= ~vo_wm_FULLSCREEN
;
1332 type
|= vo_wm_FULLSCREEN
;
1333 } else if (!strcmp(arg
, "stays_on_top"))
1336 type
&= ~vo_wm_STAYS_ON_TOP
;
1338 type
|= vo_wm_STAYS_ON_TOP
;
1339 } else if (!strcmp(arg
, "below"))
1342 type
&= ~vo_wm_BELOW
;
1344 type
|= vo_wm_BELOW
;
1345 } else if (!strcmp(arg
, "netwm"))
1348 type
&= ~vo_wm_NETWM
;
1350 type
|= vo_wm_NETWM
;
1351 } else if (!strcmp(arg
, "none"))
1352 type
= 0; // clear; keep parsing
1360 * \brief update vo->dx, vo->dy, vo->dwidth and vo->dheight with current values of vo->x11->window
1361 * \return returns current color depth of vo->x11->window
1363 int vo_x11_update_geometry(struct vo
*vo
, bool update_pos
)
1365 struct vo_x11_state
*x11
= vo
->x11
;
1366 unsigned depth
, w
, h
;
1369 XGetGeometry(x11
->display
, x11
->window
, &dummy_win
, &dummy_int
, &dummy_int
,
1370 &w
, &h
, &dummy_int
, &depth
);
1371 if (w
<= INT_MAX
&& h
<= INT_MAX
) {
1376 XTranslateCoordinates(x11
->display
, x11
->window
, x11
->rootwin
, 0, 0,
1377 &vo
->dx
, &vo
->dy
, &dummy_win
);
1379 return depth
<= INT_MAX
? depth
: 0;
1382 void vo_x11_fullscreen(struct vo
*vo
)
1384 struct MPOpts
*opts
= vo
->opts
;
1385 struct vo_x11_state
*x11
= vo
->x11
;
1389 w
= x11
->vo_old_width
;
1390 h
= x11
->vo_old_height
;
1401 vo_x11_ewmh_fullscreen(x11
, _NET_WM_STATE_REMOVE
); // removes fullscreen state if wm supports EWMH
1403 if (x11
->size_changed_during_fs
&& (x11
->fs_type
& vo_wm_FULLSCREEN
))
1404 vo_x11_nofs_sizepos(vo
, vo
->dx
, vo
->dy
, x11
->last_video_width
,
1405 x11
->last_video_height
);
1406 x11
->size_changed_during_fs
= false;
1410 vo_x11_ewmh_fullscreen(x11
, _NET_WM_STATE_ADD
); // sends fullscreen state to be added if wm supports EWMH
1413 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1415 x11
->vo_old_x
= vo
->dx
;
1416 x11
->vo_old_y
= vo
->dy
;
1417 x11
->vo_old_width
= vo
->dwidth
;
1418 x11
->vo_old_height
= vo
->dheight
;
1420 update_xinerama_info(vo
);
1423 w
= opts
->vo_screenwidth
;
1424 h
= opts
->vo_screenheight
;
1429 XGetWMNormalHints(x11
->display
, x11
->window
, &x11
->vo_hint
, &dummy
);
1430 if (!(x11
->vo_hint
.flags
& PWinGravity
))
1431 x11
->old_gravity
= NorthWestGravity
;
1433 x11
->old_gravity
= x11
->vo_hint
.win_gravity
;
1435 if (x11
->wm_type
== 0 && !(vo_fsmode
& 16))
1437 XUnmapWindow(x11
->display
, x11
->window
); // required for MWM
1438 XWithdrawWindow(x11
->display
, x11
->window
, x11
->screen
);
1442 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // not needed with EWMH fs
1444 vo_x11_decoration(vo
, vo_border
&& !vo_fs
);
1445 vo_x11_sizehint(vo
, x
, y
, w
, h
, 0);
1446 vo_x11_setlayer(vo
, x11
->window
, vo_fs
);
1449 XMoveResizeWindow(x11
->display
, x11
->window
, x
, y
, w
, h
);
1451 /* some WMs lose ontop after fullscreen */
1452 if ((!(vo_fs
)) & opts
->vo_ontop
)
1453 vo_x11_setlayer(vo
, x11
->window
, opts
->vo_ontop
);
1455 XMapRaised(x11
->display
, x11
->window
);
1456 if ( ! (x11
->fs_type
& vo_wm_FULLSCREEN
) ) // some WMs change window pos on map
1457 XMoveResizeWindow(x11
->display
, x11
->window
, x
, y
, w
, h
);
1458 XRaiseWindow(x11
->display
, x11
->window
);
1459 XFlush(x11
->display
);
1462 void vo_x11_ontop(struct vo
*vo
)
1464 struct MPOpts
*opts
= vo
->opts
;
1465 opts
->vo_ontop
= !opts
->vo_ontop
;
1467 vo_x11_setlayer(vo
, vo
->x11
->window
, opts
->vo_ontop
);
1470 void vo_x11_border(struct vo
*vo
)
1472 vo_border
= !vo_border
;
1473 vo_x11_decoration(vo
, vo_border
&& !vo_fs
);
1477 * XScreensaver stuff
1480 static int screensaver_off
;
1481 static unsigned int time_last
;
1483 void xscreensaver_heartbeat(struct vo_x11_state
*x11
)
1485 unsigned int time
= GetTimerMS();
1487 if (x11
->display
&& screensaver_off
&& (time
- time_last
) > 30000)
1491 XResetScreenSaver(x11
->display
);
1495 static int xss_suspend(Display
*mDisplay
, Bool suspend
)
1500 int event
, error
, major
, minor
;
1501 if (XScreenSaverQueryExtension(mDisplay
, &event
, &error
) != True
||
1502 XScreenSaverQueryVersion(mDisplay
, &major
, &minor
) != True
)
1504 if (major
< 1 || (major
== 1 && minor
< 1))
1506 XScreenSaverSuspend(mDisplay
, suspend
);
1512 * End of XScreensaver stuff
1515 static void saver_on(Display
* mDisplay
)
1518 if (!screensaver_off
)
1520 screensaver_off
= 0;
1521 if (xss_suspend(mDisplay
, False
))
1527 if (DPMSQueryExtension(mDisplay
, ¬hing
, ¬hing
))
1529 if (!DPMSEnable(mDisplay
))
1530 { // restoring power saving settings
1531 mp_msg(MSGT_VO
, MSGL_WARN
, "DPMS not available?\n");
1534 // DPMS does not seem to be enabled unless we call DPMSInfo
1538 DPMSForceLevel(mDisplay
, DPMSModeOn
);
1539 DPMSInfo(mDisplay
, &state
, &onoff
);
1542 mp_msg(MSGT_VO
, MSGL_V
,
1543 "Successfully enabled DPMS\n");
1546 mp_msg(MSGT_VO
, MSGL_WARN
, "Could not enable DPMS\n");
1555 static void saver_off(Display
* mDisplay
)
1559 if (screensaver_off
)
1561 screensaver_off
= 1;
1562 if (xss_suspend(mDisplay
, True
))
1565 if (DPMSQueryExtension(mDisplay
, ¬hing
, ¬hing
))
1570 DPMSInfo(mDisplay
, &state
, &onoff
);
1575 mp_msg(MSGT_VO
, MSGL_V
, "Disabling DPMS\n");
1577 stat
= DPMSDisable(mDisplay
); // monitor powersave off
1578 mp_msg(MSGT_VO
, MSGL_V
, "DPMSDisable stat: %d\n", stat
);
1584 static XErrorHandler old_handler
= NULL
;
1585 static int selectinput_err
= 0;
1586 static int x11_selectinput_errorhandler(Display
* display
,
1587 XErrorEvent
* event
)
1589 if (event
->error_code
== BadAccess
)
1591 selectinput_err
= 1;
1592 mp_msg(MSGT_VO
, MSGL_ERR
,
1593 "X11 error: BadAccess during XSelectInput Call\n");
1594 mp_msg(MSGT_VO
, MSGL_ERR
,
1595 "X11 error: The 'ButtonPressMask' mask of specified window has probably already used by another appication (see man XSelectInput)\n");
1596 /* If you think MPlayer should shutdown with this error,
1597 * comment out the following line */
1600 if (old_handler
!= NULL
)
1601 old_handler(display
, event
);
1603 x11_errorhandler(display
, event
);
1607 void vo_x11_selectinput_witherr(Display
* display
, Window w
,
1610 XSync(display
, False
);
1611 old_handler
= XSetErrorHandler(x11_selectinput_errorhandler
);
1612 selectinput_err
= 0;
1613 if (vo_nomouse_input
)
1615 XSelectInput(display
, w
,
1617 (~(ButtonPressMask
| ButtonReleaseMask
)));
1620 XSelectInput(display
, w
, event_mask
);
1622 XSync(display
, False
);
1623 XSetErrorHandler(old_handler
);
1624 if (selectinput_err
)
1626 mp_msg(MSGT_VO
, MSGL_ERR
,
1627 "X11 error: MPlayer discards mouse control (reconfiguring)\n");
1628 XSelectInput(display
, w
,
1631 (ButtonPressMask
| ButtonReleaseMask
|
1632 PointerMotionMask
)));
1636 #ifdef CONFIG_XF86VM
1637 void vo_vm_switch(struct vo
*vo
)
1639 struct vo_x11_state
*x11
= vo
->x11
;
1640 struct MPOpts
*opts
= vo
->opts
;
1641 Display
*mDisplay
= x11
->display
;
1642 int vm_event
, vm_error
;
1644 int i
, j
, have_vm
= 0;
1645 int X
= vo
->dwidth
, Y
= vo
->dheight
;
1646 int modeline_width
, modeline_height
;
1650 if (XF86VidModeQueryExtension(mDisplay
, &vm_event
, &vm_error
))
1652 XF86VidModeQueryVersion(mDisplay
, &vm_ver
, &vm_rev
);
1653 mp_msg(MSGT_VO
, MSGL_V
, "XF86VidMode extension v%i.%i\n", vm_ver
,
1657 mp_msg(MSGT_VO
, MSGL_WARN
,
1658 "XF86VidMode extension not available.\n");
1663 if (vidmodes
== NULL
)
1664 XF86VidModeGetAllModeLines(mDisplay
, x11
->screen
, &modecount
,
1667 modeline_width
= vidmodes
[0]->hdisplay
;
1668 modeline_height
= vidmodes
[0]->vdisplay
;
1670 for (i
= 1; i
< modecount
; i
++)
1671 if ((vidmodes
[i
]->hdisplay
>= X
)
1672 && (vidmodes
[i
]->vdisplay
>= Y
))
1673 if ((vidmodes
[i
]->hdisplay
<= modeline_width
)
1674 && (vidmodes
[i
]->vdisplay
<= modeline_height
))
1676 modeline_width
= vidmodes
[i
]->hdisplay
;
1677 modeline_height
= vidmodes
[i
]->vdisplay
;
1681 mp_tmsg(MSGT_VO
, MSGL_INFO
, "XF86VM: Selected video mode %dx%d for image size %dx%d.\n",
1682 modeline_width
, modeline_height
, X
, Y
);
1683 XF86VidModeLockModeSwitch(mDisplay
, x11
->screen
, 0);
1684 XF86VidModeSwitchToMode(mDisplay
, x11
->screen
, vidmodes
[j
]);
1685 XF86VidModeSwitchToMode(mDisplay
, x11
->screen
, vidmodes
[j
]);
1687 // FIXME: all this is more of a hack than proper solution
1688 X
= (opts
->vo_screenwidth
- modeline_width
) / 2;
1689 Y
= (opts
->vo_screenheight
- modeline_height
) / 2;
1690 XF86VidModeSetViewPort(mDisplay
, x11
->screen
, X
, Y
);
1693 vo
->dwidth
= modeline_width
;
1694 vo
->dheight
= modeline_height
;
1695 aspect_save_screenres(vo
, modeline_width
, modeline_height
);
1699 void vo_vm_close(struct vo
*vo
)
1701 Display
*dpy
= vo
->x11
->display
;
1702 struct MPOpts
*opts
= vo
->opts
;
1703 if (vidmodes
!= NULL
)
1709 XF86VidModeGetAllModeLines(dpy
, vo
->x11
->screen
, &modecount
,
1711 for (i
= 0; i
< modecount
; i
++)
1712 if ((vidmodes
[i
]->hdisplay
== opts
->vo_screenwidth
)
1713 && (vidmodes
[i
]->vdisplay
== opts
->vo_screenheight
))
1715 mp_msg(MSGT_VO
, MSGL_INFO
,
1716 "Returning to original mode %dx%d\n",
1717 opts
->vo_screenwidth
, opts
->vo_screenheight
);
1721 XF86VidModeSwitchToMode(dpy
, vo
->x11
->screen
, vidmodes
[i
]);
1722 XF86VidModeSwitchToMode(dpy
, vo
->x11
->screen
, vidmodes
[i
]);
1728 double vo_vm_get_fps(struct vo
*vo
)
1730 struct vo_x11_state
*x11
= vo
->x11
;
1732 XF86VidModeModeLine modeline
;
1733 if (!XF86VidModeGetModeLine(x11
->display
, x11
->screen
, &clock
, &modeline
))
1735 if (modeline
.privsize
)
1736 XFree(modeline
.private);
1737 return 1e3
* clock
/ modeline
.htotal
/ modeline
.vtotal
;
1741 #endif /* X11_FULLSCREEN */
1745 * Scan the available visuals on this Display/Screen. Try to find
1746 * the 'best' available TrueColor visual that has a decent color
1747 * depth (at least 15bit). If there are multiple visuals with depth
1748 * >= 15bit, we prefer visuals with a smaller color depth.
1750 int vo_find_depth_from_visuals(Display
* dpy
, int screen
,
1751 Visual
** visual_return
)
1753 XVisualInfo visual_tmpl
;
1754 XVisualInfo
*visuals
;
1756 int bestvisual
= -1;
1757 int bestvisual_depth
= -1;
1759 visual_tmpl
.screen
= screen
;
1760 visual_tmpl
.class = TrueColor
;
1761 visuals
= XGetVisualInfo(dpy
,
1762 VisualScreenMask
| VisualClassMask
,
1763 &visual_tmpl
, &nvisuals
);
1764 if (visuals
!= NULL
)
1766 for (i
= 0; i
< nvisuals
; i
++)
1768 mp_msg(MSGT_VO
, MSGL_V
,
1769 "vo: X11 truecolor visual %#lx, depth %d, R:%lX G:%lX B:%lX\n",
1770 visuals
[i
].visualid
, visuals
[i
].depth
,
1771 visuals
[i
].red_mask
, visuals
[i
].green_mask
,
1772 visuals
[i
].blue_mask
);
1774 * Save the visual index and its depth, if this is the first
1775 * truecolor visul, or a visual that is 'preferred' over the
1776 * previous 'best' visual.
1778 if (bestvisual_depth
== -1
1779 || (visuals
[i
].depth
>= 15
1780 && (visuals
[i
].depth
< bestvisual_depth
1781 || bestvisual_depth
< 15)))
1784 bestvisual_depth
= visuals
[i
].depth
;
1788 if (bestvisual
!= -1 && visual_return
!= NULL
)
1789 *visual_return
= visuals
[bestvisual
].visual
;
1793 return bestvisual_depth
;
1797 static Colormap cmap
= None
;
1798 static XColor cols
[256];
1799 static int cm_size
, red_mask
, green_mask
, blue_mask
;
1802 Colormap
vo_x11_create_colormap(struct vo
*vo
, XVisualInfo
*vinfo
)
1804 struct vo_x11_state
*x11
= vo
->x11
;
1805 unsigned k
, r
, g
, b
, ru
, gu
, bu
, m
, rv
, gv
, bv
, rvu
, gvu
, bvu
;
1807 if (vinfo
->class != DirectColor
)
1808 return XCreateColormap(x11
->display
, x11
->rootwin
, vinfo
->visual
,
1811 /* can this function get called twice or more? */
1814 cm_size
= vinfo
->colormap_size
;
1815 red_mask
= vinfo
->red_mask
;
1816 green_mask
= vinfo
->green_mask
;
1817 blue_mask
= vinfo
->blue_mask
;
1818 ru
= (red_mask
& (red_mask
- 1)) ^ red_mask
;
1819 gu
= (green_mask
& (green_mask
- 1)) ^ green_mask
;
1820 bu
= (blue_mask
& (blue_mask
- 1)) ^ blue_mask
;
1821 rvu
= 65536ull * ru
/ (red_mask
+ ru
);
1822 gvu
= 65536ull * gu
/ (green_mask
+ gu
);
1823 bvu
= 65536ull * bu
/ (blue_mask
+ bu
);
1826 m
= DoRed
| DoGreen
| DoBlue
;
1827 for (k
= 0; k
< cm_size
; k
++)
1831 cols
[k
].pixel
= r
| g
| b
;
1836 t
= (r
+ ru
) & red_mask
;
1840 t
= (g
+ gu
) & green_mask
;
1844 t
= (b
+ bu
) & blue_mask
;
1852 cmap
= XCreateColormap(x11
->display
, x11
->rootwin
, vinfo
->visual
, AllocAll
);
1853 XStoreColors(x11
->display
, cmap
, cols
, cm_size
);
1858 * Via colormaps/gamma ramps we can do gamma, brightness, contrast,
1859 * hue and red/green/blue intensity, but we cannot do saturation.
1860 * Currently only gamma, brightness and contrast are implemented.
1861 * Is there sufficient interest for hue and/or red/green/blue intensity?
1863 /* these values have range [-100,100] and are initially 0 */
1864 static int vo_gamma
= 0;
1865 static int vo_brightness
= 0;
1866 static int vo_contrast
= 0;
1868 static int transform_color(float val
,
1869 float brightness
, float contrast
, float gamma
) {
1870 float s
= pow(val
, gamma
);
1871 s
= (s
- 0.5) * contrast
+ 0.5;
1877 return (unsigned short) (s
* 65535);
1880 uint32_t vo_x11_set_equalizer(struct vo
*vo
, const char *name
, int value
)
1882 float gamma
, brightness
, contrast
;
1887 * IMPLEMENTME: consider using XF86VidModeSetGammaRamp in the case
1888 * of TrueColor-ed window but be careful:
1889 * Unlike the colormaps, which are private for the X client
1890 * who created them and thus automatically destroyed on client
1891 * disconnect, this gamma ramp is a system-wide (X-server-wide)
1892 * setting and _must_ be restored before the process exits.
1893 * Unforunately when the process crashes (or gets killed
1894 * for some reason) it is impossible to restore the setting,
1895 * and such behaviour could be rather annoying for the users.
1900 if (!strcasecmp(name
, "brightness"))
1901 vo_brightness
= value
;
1902 else if (!strcasecmp(name
, "contrast"))
1903 vo_contrast
= value
;
1904 else if (!strcasecmp(name
, "gamma"))
1909 brightness
= 0.01 * vo_brightness
;
1910 contrast
= tan(0.0095 * (vo_contrast
+ 100) * M_PI
/ 4);
1911 gamma
= pow(2, -0.02 * vo_gamma
);
1913 rf
= (float) ((red_mask
& (red_mask
- 1)) ^ red_mask
) / red_mask
;
1914 gf
= (float) ((green_mask
& (green_mask
- 1)) ^ green_mask
) /
1916 bf
= (float) ((blue_mask
& (blue_mask
- 1)) ^ blue_mask
) / blue_mask
;
1918 /* now recalculate the colormap using the newly set value */
1919 for (k
= 0; k
< cm_size
; k
++)
1921 cols
[k
].red
= transform_color(rf
* k
, brightness
, contrast
, gamma
);
1922 cols
[k
].green
= transform_color(gf
* k
, brightness
, contrast
, gamma
);
1923 cols
[k
].blue
= transform_color(bf
* k
, brightness
, contrast
, gamma
);
1926 XStoreColors(vo
->x11
->display
, cmap
, cols
, cm_size
);
1927 XFlush(vo
->x11
->display
);
1931 uint32_t vo_x11_get_equalizer(const char *name
, int *value
)
1935 if (!strcasecmp(name
, "brightness"))
1936 *value
= vo_brightness
;
1937 else if (!strcasecmp(name
, "contrast"))
1938 *value
= vo_contrast
;
1939 else if (!strcasecmp(name
, "gamma"))
1947 int vo_xv_set_eq(struct vo
*vo
, uint32_t xv_port
, const char *name
, int value
)
1949 XvAttribute
*attributes
;
1950 int i
, howmany
, xv_atom
;
1952 mp_dbg(MSGT_VO
, MSGL_V
, "xv_set_eq called! (%s, %d)\n", name
, value
);
1954 /* get available attributes */
1955 attributes
= XvQueryPortAttributes(vo
->x11
->display
, xv_port
, &howmany
);
1956 for (i
= 0; i
< howmany
&& attributes
; i
++)
1957 if (attributes
[i
].flags
& XvSettable
)
1959 xv_atom
= XInternAtom(vo
->x11
->display
, attributes
[i
].name
, True
);
1960 /* since we have SET_DEFAULTS first in our list, we can check if it's available
1961 then trigger it if it's ok so that the other values are at default upon query */
1962 if (xv_atom
!= None
)
1964 int hue
= 0, port_value
, port_min
, port_max
;
1966 if (!strcmp(attributes
[i
].name
, "XV_BRIGHTNESS") &&
1967 (!strcasecmp(name
, "brightness")))
1969 else if (!strcmp(attributes
[i
].name
, "XV_CONTRAST") &&
1970 (!strcasecmp(name
, "contrast")))
1972 else if (!strcmp(attributes
[i
].name
, "XV_SATURATION") &&
1973 (!strcasecmp(name
, "saturation")))
1975 else if (!strcmp(attributes
[i
].name
, "XV_HUE") &&
1976 (!strcasecmp(name
, "hue")))
1981 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
1982 if (!strcmp(attributes
[i
].name
, "XV_RED_INTENSITY") &&
1983 (!strcasecmp(name
, "red_intensity")))
1985 else if (!strcmp(attributes
[i
].name
, "XV_GREEN_INTENSITY")
1986 && (!strcasecmp(name
, "green_intensity")))
1988 else if (!strcmp(attributes
[i
].name
, "XV_BLUE_INTENSITY")
1989 && (!strcasecmp(name
, "blue_intensity")))
1991 else if ((!strcmp(attributes
[i
].name
, "XV_ITURBT_709") //NVIDIA
1992 || !strcmp(attributes
[i
].name
, "XV_COLORSPACE"))//ATI
1993 && (!strcasecmp(name
, "bt_709")))
1998 port_min
= attributes
[i
].min_value
;
1999 port_max
= attributes
[i
].max_value
;
2001 /* nvidia hue workaround */
2002 if (hue
&& port_min
== 0 && port_max
== 360)
2006 0) ? (port_value
- 100) : (port_value
+ 100);
2012 (port_value
+ 100) * (port_max
- port_min
) / 200 +
2014 XvSetPortAttribute(vo
->x11
->display
, xv_port
, xv_atom
, port_value
);
2021 int vo_xv_get_eq(struct vo
*vo
, uint32_t xv_port
, const char *name
, int *value
)
2024 XvAttribute
*attributes
;
2025 int i
, howmany
, xv_atom
;
2027 /* get available attributes */
2028 attributes
= XvQueryPortAttributes(vo
->x11
->display
, xv_port
, &howmany
);
2029 for (i
= 0; i
< howmany
&& attributes
; i
++)
2030 if (attributes
[i
].flags
& XvGettable
)
2032 xv_atom
= XInternAtom(vo
->x11
->display
, attributes
[i
].name
, True
);
2033 /* since we have SET_DEFAULTS first in our list, we can check if it's available
2034 then trigger it if it's ok so that the other values are at default upon query */
2035 if (xv_atom
!= None
)
2037 int val
, port_value
= 0, port_min
, port_max
;
2039 XvGetPortAttribute(vo
->x11
->display
, xv_port
, xv_atom
,
2042 port_min
= attributes
[i
].min_value
;
2043 port_max
= attributes
[i
].max_value
;
2045 (port_value
- port_min
) * 200 / (port_max
- port_min
) -
2048 if (!strcmp(attributes
[i
].name
, "XV_BRIGHTNESS") &&
2049 (!strcasecmp(name
, "brightness")))
2051 else if (!strcmp(attributes
[i
].name
, "XV_CONTRAST") &&
2052 (!strcasecmp(name
, "contrast")))
2054 else if (!strcmp(attributes
[i
].name
, "XV_SATURATION") &&
2055 (!strcasecmp(name
, "saturation")))
2057 else if (!strcmp(attributes
[i
].name
, "XV_HUE") &&
2058 (!strcasecmp(name
, "hue")))
2060 /* nasty nvidia detect */
2061 if (port_min
== 0 && port_max
== 360)
2062 *value
= (val
>= 0) ? (val
- 100) : (val
+ 100);
2066 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
2067 if (!strcmp(attributes
[i
].name
, "XV_RED_INTENSITY") &&
2068 (!strcasecmp(name
, "red_intensity")))
2070 else if (!strcmp(attributes
[i
].name
, "XV_GREEN_INTENSITY")
2071 && (!strcasecmp(name
, "green_intensity")))
2073 else if (!strcmp(attributes
[i
].name
, "XV_BLUE_INTENSITY")
2074 && (!strcasecmp(name
, "blue_intensity")))
2076 else if ((!strcmp(attributes
[i
].name
, "XV_ITURBT_709") //NVIDIA
2077 || !strcmp(attributes
[i
].name
, "XV_COLORSPACE"))//ATI
2078 && (!strcasecmp(name
, "bt_709")))
2083 mp_dbg(MSGT_VO
, MSGL_V
, "xv_get_eq called! (%s, %d)\n",
2092 * \brief Interns the requested atom if it is available.
2094 * \param atom_name String containing the name of the requested atom.
2096 * \return Returns the atom if available, else None is returned.
2099 static Atom
xv_intern_atom_if_exists(struct vo_x11_state
*x11
,
2100 char const *atom_name
)
2102 XvAttribute
* attributes
;
2104 Atom xv_atom
= None
;
2106 attributes
= XvQueryPortAttributes(x11
->display
, x11
->xv_port
, &attrib_count
);
2107 if( attributes
!=NULL
)
2109 for ( i
= 0; i
< attrib_count
; ++i
)
2111 if ( strcmp(attributes
[i
].name
, atom_name
) == 0 )
2113 xv_atom
= XInternAtom(x11
->display
, atom_name
, False
);
2114 break; // found what we want, break out
2117 XFree( attributes
);
2124 * \brief Try to enable vsync for xv.
2125 * \return Returns -1 if not available, 0 on failure and 1 on success.
2127 int vo_xv_enable_vsync(struct vo
*vo
)
2129 struct vo_x11_state
*x11
= vo
->x11
;
2130 Atom xv_atom
= xv_intern_atom_if_exists(x11
, "XV_SYNC_TO_VBLANK");
2131 if (xv_atom
== None
)
2133 return XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, 1) == Success
;
2137 * \brief Get maximum supported source image dimensions.
2139 * This function does not set the variables pointed to by
2140 * width and height if the information could not be retrieved,
2141 * so the caller is reponsible for properly initializing them.
2143 * \param width [out] The maximum width gets stored here.
2144 * \param height [out] The maximum height gets stored here.
2147 void vo_xv_get_max_img_dim(struct vo
*vo
, uint32_t * width
, uint32_t * height
)
2149 struct vo_x11_state
*x11
= vo
->x11
;
2150 XvEncodingInfo
* encodings
;
2151 //unsigned long num_encodings, idx; to int or too long?!
2152 unsigned int num_encodings
, idx
;
2154 XvQueryEncodings(x11
->display
, x11
->xv_port
, &num_encodings
, &encodings
);
2158 for ( idx
= 0; idx
< num_encodings
; ++idx
)
2160 if ( strcmp( encodings
[idx
].name
, "XV_IMAGE" ) == 0 )
2162 *width
= encodings
[idx
].width
;
2163 *height
= encodings
[idx
].height
;
2169 mp_msg( MSGT_VO
, MSGL_V
,
2170 "[xv common] Maximum source image dimensions: %ux%u\n",
2173 XvFreeEncodingInfo( encodings
);
2177 * \brief Print information about the colorkey method and source.
2179 * \param ck_handling Integer value containing the information about
2180 * colorkey handling (see x11_common.h).
2182 * Outputs the content of |ck_handling| as a readable message.
2185 static void vo_xv_print_ck_info(struct vo_x11_state
*x11
)
2187 mp_msg( MSGT_VO
, MSGL_V
, "[xv common] " );
2189 switch ( x11
->xv_ck_info
.method
)
2191 case CK_METHOD_NONE
:
2192 mp_msg( MSGT_VO
, MSGL_V
, "Drawing no colorkey.\n" ); return;
2193 case CK_METHOD_AUTOPAINT
:
2194 mp_msg( MSGT_VO
, MSGL_V
, "Colorkey is drawn by Xv." ); break;
2195 case CK_METHOD_MANUALFILL
:
2196 mp_msg( MSGT_VO
, MSGL_V
, "Drawing colorkey manually." ); break;
2197 case CK_METHOD_BACKGROUND
:
2198 mp_msg( MSGT_VO
, MSGL_V
, "Colorkey is drawn as window background." ); break;
2201 mp_msg( MSGT_VO
, MSGL_V
, "\n[xv common] " );
2203 switch ( x11
->xv_ck_info
.source
)
2206 mp_msg( MSGT_VO
, MSGL_V
, "Using colorkey from Xv (0x%06lx).\n",
2210 if ( x11
->xv_ck_info
.method
== CK_METHOD_AUTOPAINT
)
2212 mp_msg( MSGT_VO
, MSGL_V
,
2213 "Ignoring colorkey from MPlayer (0x%06lx).\n",
2218 mp_msg( MSGT_VO
, MSGL_V
,
2219 "Using colorkey from MPlayer (0x%06lx)."
2220 " Use -colorkey to change.\n",
2225 mp_msg( MSGT_VO
, MSGL_V
,
2226 "Setting and using colorkey from MPlayer (0x%06lx)."
2227 " Use -colorkey to change.\n",
2233 * \brief Init colorkey depending on the settings in xv_ck_info.
2235 * \return Returns 0 on failure and 1 on success.
2237 * Sets the colorkey variable according to the CK_SRC_* and CK_METHOD_*
2238 * flags in xv_ck_info.
2242 * - manual colorkey drawing ( CK_METHOD_MANUALFILL )
2243 * - set colorkey as window background ( CK_METHOD_BACKGROUND )
2244 * - let Xv paint the colorkey ( CK_METHOD_AUTOPAINT )
2246 * - use currently set colorkey ( CK_SRC_CUR )
2247 * - use colorkey in vo_colorkey ( CK_SRC_USE )
2248 * - use and set colorkey in vo_colorkey ( CK_SRC_SET )
2250 * NOTE: If vo_colorkey has bits set after the first 3 low order bytes
2251 * we don't draw anything as this means it was forced to off.
2253 int vo_xv_init_colorkey(struct vo
*vo
)
2255 struct vo_x11_state
*x11
= vo
->x11
;
2259 /* check if colorkeying is needed */
2260 xv_atom
= xv_intern_atom_if_exists(vo
->x11
, "XV_COLORKEY");
2262 /* if we have to deal with colorkeying ... */
2263 if( xv_atom
!= None
&& !(vo_colorkey
& 0xFF000000) )
2265 /* check if we should use the colorkey specified in vo_colorkey */
2266 if ( x11
->xv_ck_info
.source
!= CK_SRC_CUR
)
2268 x11
->xv_colorkey
= vo_colorkey
;
2270 /* check if we have to set the colorkey too */
2271 if ( x11
->xv_ck_info
.source
== CK_SRC_SET
)
2273 xv_atom
= XInternAtom(x11
->display
, "XV_COLORKEY",False
);
2275 rez
= XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, vo_colorkey
);
2276 if ( rez
!= Success
)
2278 mp_msg( MSGT_VO
, MSGL_FATAL
,
2279 "[xv common] Couldn't set colorkey!\n" );
2280 return 0; // error setting colorkey
2288 rez
=XvGetPortAttribute(x11
->display
,x11
->xv_port
, xv_atom
, &colorkey_ret
);
2289 if ( rez
== Success
)
2291 x11
->xv_colorkey
= colorkey_ret
;
2295 mp_msg( MSGT_VO
, MSGL_FATAL
,
2296 "[xv common] Couldn't get colorkey!"
2297 "Maybe the selected Xv port has no overlay.\n" );
2298 return 0; // error getting colorkey
2302 xv_atom
= xv_intern_atom_if_exists(vo
->x11
, "XV_AUTOPAINT_COLORKEY");
2304 /* should we draw the colorkey ourselves or activate autopainting? */
2305 if ( x11
->xv_ck_info
.method
== CK_METHOD_AUTOPAINT
)
2307 rez
= !Success
; // reset rez to something different than Success
2309 if ( xv_atom
!= None
) // autopaint is supported
2311 rez
= XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, 1);
2314 if ( rez
!= Success
)
2316 // fallback to manual colorkey drawing
2317 x11
->xv_ck_info
.method
= CK_METHOD_MANUALFILL
;
2320 else // disable colorkey autopainting if supported
2322 if ( xv_atom
!= None
) // we have autopaint attribute
2324 XvSetPortAttribute(x11
->display
, x11
->xv_port
, xv_atom
, 0);
2328 else // do no colorkey drawing at all
2330 x11
->xv_ck_info
.method
= CK_METHOD_NONE
;
2331 } /* end: should we draw colorkey */
2333 /* output information about the current colorkey settings */
2334 vo_xv_print_ck_info(x11
);
2336 return 1; // success
2340 * \brief Draw the colorkey on the video window.
2342 * Draws the colorkey depending on the set method ( colorkey_handling ).
2344 * Also draws the black bars ( when the video doesn't fit the display in
2345 * fullscreen ) separately, so they don't overlap with the video area.
2346 * It doesn't call XFlush.
2349 void vo_xv_draw_colorkey(struct vo
*vo
, int32_t x
, int32_t y
,
2350 int32_t w
, int32_t h
)
2352 struct vo_x11_state
*x11
= vo
->x11
;
2353 if( x11
->xv_ck_info
.method
== CK_METHOD_MANUALFILL
||
2354 x11
->xv_ck_info
.method
== CK_METHOD_BACKGROUND
)//less tearing than XClearWindow()
2356 XSetForeground(x11
->display
, x11
->vo_gc
, x11
->xv_colorkey
);
2357 XFillRectangle(x11
->display
, x11
->window
, x11
->vo_gc
,
2363 /** \brief Tests if a valid argument for the ck suboption was given. */
2364 int xv_test_ck( void * arg
)
2366 strarg_t
* strarg
= (strarg_t
*)arg
;
2368 if ( strargcmp( strarg
, "use" ) == 0 ||
2369 strargcmp( strarg
, "set" ) == 0 ||
2370 strargcmp( strarg
, "cur" ) == 0 )
2377 /** \brief Tests if a valid arguments for the ck-method suboption was given. */
2378 int xv_test_ckm( void * arg
)
2380 strarg_t
* strarg
= (strarg_t
*)arg
;
2382 if ( strargcmp( strarg
, "bg" ) == 0 ||
2383 strargcmp( strarg
, "man" ) == 0 ||
2384 strargcmp( strarg
, "auto" ) == 0 )
2393 * \brief Modify the colorkey_handling var according to str
2395 * Checks if a valid pointer ( not NULL ) to the string
2396 * was given. And in that case modifies the colorkey_handling
2397 * var to reflect the requested behaviour.
2398 * If nothing happens the content of colorkey_handling stays
2401 * \param str Pointer to the string or NULL
2404 void xv_setup_colorkeyhandling(struct vo
*vo
, const char *ck_method_str
,
2407 struct vo_x11_state
*x11
= vo
->x11
;
2408 /* check if a valid pointer to the string was passed */
2411 if ( strncmp( ck_str
, "use", 3 ) == 0 )
2413 x11
->xv_ck_info
.source
= CK_SRC_USE
;
2415 else if ( strncmp( ck_str
, "set", 3 ) == 0 )
2417 x11
->xv_ck_info
.source
= CK_SRC_SET
;
2420 /* check if a valid pointer to the string was passed */
2421 if ( ck_method_str
)
2423 if ( strncmp( ck_method_str
, "bg", 2 ) == 0 )
2425 x11
->xv_ck_info
.method
= CK_METHOD_BACKGROUND
;
2427 else if ( strncmp( ck_method_str
, "man", 3 ) == 0 )
2429 x11
->xv_ck_info
.method
= CK_METHOD_MANUALFILL
;
2431 else if ( strncmp( ck_method_str
, "auto", 4 ) == 0 )
2433 x11
->xv_ck_info
.method
= CK_METHOD_AUTOPAINT
;
2440 struct vo_x11_state
*vo_x11_init_state(void)
2442 struct vo_x11_state
*s
= talloc_ptrtype(NULL
, s
);
2443 *s
= (struct vo_x11_state
){
2444 .xv_ck_info
= { CK_METHOD_MANUALFILL
, CK_SRC_CUR
},
2445 .olddecor
= MWM_DECOR_ALL
,
2446 .oldfuncs
= MWM_FUNC_MOVE
| MWM_FUNC_CLOSE
| MWM_FUNC_MINIMIZE
|
2447 MWM_FUNC_MAXIMIZE
| MWM_FUNC_RESIZE
,
2448 .old_gravity
= NorthWestGravity
,