9
#include "x11_common.h"
19
#include "video_out.h"
23
#include "osdep/timer.h"
27
#include <X11/Xutil.h>
28
#include <X11/Xatom.h>
31
#include <X11/extensions/dpms.h>
35
#include <X11/extensions/Xinerama.h>
39
#include <X11/extensions/xf86vmode.h>
43
#include <X11/XF86keysym.h>
47
#include <X11/extensions/Xv.h>
48
#include <X11/extensions/Xvlib.h>
50
#include "subopt-helper.h"
53
#include "input/input.h"
54
#include "input/mouse.h"
57
#include "Gui/interface.h"
61
#define WIN_LAYER_ONBOTTOM 2
62
#define WIN_LAYER_NORMAL 4
63
#define WIN_LAYER_ONTOP 6
64
#define WIN_LAYER_ABOVE_DOCK 10
66
int fs_layer = WIN_LAYER_ABOVE_DOCK;
67
static int orig_layer = 0;
68
static int old_gravity = NorthWestGravity;
70
int stop_xscreensaver = 0;
72
static int dpms_disabled = 0;
73
static int timeout_save = 0;
74
static int kdescreensaver_was_running = 0;
76
char *mDisplayName = NULL;
77
Display *mDisplay = NULL;
82
/* output window id */
83
int vo_mouse_autohide = 0;
85
int vo_fs_type = 0; // needs to be accessible for GUI X11 code
86
static int vo_fs_flip = 0;
87
char **vo_fstype_list;
89
/* if equal to 1 means that WM is a metacity (broken as hell) */
90
int metacity_hack = 0;
92
static Atom XA_NET_SUPPORTED;
93
static Atom XA_NET_WM_STATE;
94
static Atom XA_NET_WM_STATE_FULLSCREEN;
95
static Atom XA_NET_WM_STATE_ABOVE;
96
static Atom XA_NET_WM_STATE_STAYS_ON_TOP;
97
static Atom XA_NET_WM_STATE_BELOW;
98
static Atom XA_NET_WM_PID;
99
static Atom XA_WIN_PROTOCOLS;
100
static Atom XA_WIN_LAYER;
101
static Atom XA_WIN_HINTS;
102
static Atom XA_BLACKBOX_PID;
104
#define XA_INIT(x) XA##x = XInternAtom(mDisplay, #x, False)
106
static int vo_old_x = 0;
107
static int vo_old_y = 0;
108
static int vo_old_width = 0;
109
static int vo_old_height = 0;
112
int xinerama_screen = 0;
117
XF86VidModeModeInfo **vidmodes = NULL;
118
XF86VidModeModeLine modeline;
121
static int vo_x11_get_fs_type(int supported);
125
* Sends the EWMH fullscreen state event.
127
* action: could be on of _NET_WM_STATE_REMOVE -- remove state
128
* _NET_WM_STATE_ADD -- add state
129
* _NET_WM_STATE_TOGGLE -- toggle
131
void vo_x11_ewmh_fullscreen(int action)
133
assert(action == _NET_WM_STATE_REMOVE ||
134
action == _NET_WM_STATE_ADD || action == _NET_WM_STATE_TOGGLE);
136
if (vo_fs_type & vo_wm_FULLSCREEN)
140
/* init X event structure for _NET_WM_FULLSCREEN client msg */
141
xev.xclient.type = ClientMessage;
142
xev.xclient.serial = 0;
143
xev.xclient.send_event = True;
144
xev.xclient.message_type = XInternAtom(mDisplay,
145
"_NET_WM_STATE", False);
146
xev.xclient.window = vo_window;
147
xev.xclient.format = 32;
148
xev.xclient.data.l[0] = action;
149
xev.xclient.data.l[1] = XInternAtom(mDisplay,
150
"_NET_WM_STATE_FULLSCREEN",
152
xev.xclient.data.l[2] = 0;
153
xev.xclient.data.l[3] = 0;
154
xev.xclient.data.l[4] = 0;
156
/* finally send that damn thing */
157
if (!XSendEvent(mDisplay, DefaultRootWindow(mDisplay), False,
158
SubstructureRedirectMask | SubstructureNotifyMask,
161
mp_msg(MSGT_VO, MSGL_ERR, MSGTR_EwmhFullscreenStateFailed);
166
void vo_hidecursor(Display * disp, Window win)
172
static char bm_no_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
175
return; // do not hide, if we're playing at rootwin
177
colormap = DefaultColormap(disp, DefaultScreen(disp));
178
if ( !XAllocNamedColor(disp, colormap, "black", &black, &dummy) )
180
return; // color alloc failed, give up
182
bm_no = XCreateBitmapFromData(disp, win, bm_no_data, 8, 8);
183
no_ptr = XCreatePixmapCursor(disp, bm_no, bm_no, &black, &black, 0, 0);
184
XDefineCursor(disp, win, no_ptr);
185
XFreeCursor(disp, no_ptr);
187
XFreePixmap(disp, bm_no);
188
XFreeColors(disp,colormap,&black.pixel,1,0);
191
void vo_showcursor(Display * disp, Window win)
195
XDefineCursor(disp, win, 0);
198
static int x11_errorhandler(Display * display, XErrorEvent * event)
203
XGetErrorText(display, event->error_code, (char *) &msg, MSGLEN);
205
mp_msg(MSGT_VO, MSGL_ERR, "X11 error: %s\n", msg);
207
mp_msg(MSGT_VO, MSGL_V,
208
"Type: %x, display: %p, resourceid: %lx, serial: %lx\n",
209
event->type, event->display, event->resourceid, event->serial);
210
mp_msg(MSGT_VO, MSGL_V,
211
"Error code: %x, request code: %x, minor code: %x\n",
212
event->error_code, event->request_code, event->minor_code);
215
//exit_player("X11 error");
219
void fstype_help(void)
221
mp_msg(MSGT_VO, MSGL_INFO, MSGTR_AvailableFsType);
223
mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_FULL_SCREEN_TYPES\n");
225
mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "none",
226
"don't set fullscreen window layer");
227
mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "layer",
228
"use _WIN_LAYER hint with default layer");
229
mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "layer=<0..15>",
230
"use _WIN_LAYER hint with a given layer number");
231
mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "netwm",
232
"force NETWM style");
233
mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "above",
234
"use _NETWM_STATE_ABOVE hint if available");
235
mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "below",
236
"use _NETWM_STATE_BELOW hint if available");
237
mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "fullscreen",
238
"use _NETWM_STATE_FULLSCREEN hint if availale");
239
mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "stays_on_top",
240
"use _NETWM_STATE_STAYS_ON_TOP hint if available");
241
mp_msg(MSGT_VO, MSGL_INFO,
242
"You can also negate the settings with simply putting '-' in the beginning");
243
mp_msg(MSGT_VO, MSGL_INFO, "\n\n");
246
static void fstype_dump(int fstype)
250
mp_msg(MSGT_VO, MSGL_V, "[x11] Current fstype setting honours");
251
if (fstype & vo_wm_LAYER)
252
mp_msg(MSGT_VO, MSGL_V, " LAYER");
253
if (fstype & vo_wm_FULLSCREEN)
254
mp_msg(MSGT_VO, MSGL_V, " FULLSCREEN");
255
if (fstype & vo_wm_STAYS_ON_TOP)
256
mp_msg(MSGT_VO, MSGL_V, " STAYS_ON_TOP");
257
if (fstype & vo_wm_ABOVE)
258
mp_msg(MSGT_VO, MSGL_V, " ABOVE");
259
if (fstype & vo_wm_BELOW)
260
mp_msg(MSGT_VO, MSGL_V, " BELOW");
261
mp_msg(MSGT_VO, MSGL_V, " X atoms\n");
263
mp_msg(MSGT_VO, MSGL_V,
264
"[x11] Current fstype setting doesn't honour any X atoms\n");
267
static int net_wm_support_state_test(Atom atom)
269
#define NET_WM_STATE_TEST(x) { if (atom == XA_NET_WM_STATE_##x) { mp_msg( MSGT_VO,MSGL_V, "[x11] Detected wm supports " #x " state.\n" ); return vo_wm_##x; } }
271
NET_WM_STATE_TEST(FULLSCREEN);
272
NET_WM_STATE_TEST(ABOVE);
273
NET_WM_STATE_TEST(STAYS_ON_TOP);
274
NET_WM_STATE_TEST(BELOW);
278
static int x11_get_property(Atom type, Atom ** args, unsigned long *nitems)
281
unsigned long bytesafter;
284
XGetWindowProperty(mDisplay, mRootWin, type, 0, 16384, False,
285
AnyPropertyType, &type, &format, nitems,
286
&bytesafter, (unsigned char **) args)
290
static int vo_wm_detect(void)
294
unsigned long nitems;
300
// -- supports layers
301
if (x11_get_property(XA_WIN_PROTOCOLS, &args, &nitems))
303
mp_msg(MSGT_VO, MSGL_V, "[x11] Detected wm supports layers.\n");
304
for (i = 0; i < nitems; i++)
306
if (args[i] == XA_WIN_LAYER)
311
// metacity is the only manager I know which reports support only for _WIN_LAYER
312
// hint in _WIN_PROTOCOLS (what's more support for it is broken)
316
if (wm && (metacity_hack == 1))
318
// metacity reports that it supports layers, but it is not really truth :-)
320
mp_msg(MSGT_VO, MSGL_V,
321
"[x11] Using workaround for Metacity bugs.\n");
325
if (x11_get_property(XA_NET_SUPPORTED, &args, &nitems))
327
mp_msg(MSGT_VO, MSGL_V, "[x11] Detected wm supports NetWM.\n");
328
for (i = 0; i < nitems; i++)
329
wm |= net_wm_support_state_test(args[i]);
332
// ugly hack for broken OpenBox _NET_WM_STATE_FULLSCREEN support
333
// (in their implementation it only changes internal state of window, nothing more!!!)
334
if (wm & vo_wm_FULLSCREEN)
336
if (x11_get_property(XA_BLACKBOX_PID, &args, &nitems))
338
mp_msg(MSGT_VO, MSGL_V,
339
"[x11] Detected wm is a broken OpenBox.\n");
340
wm ^= vo_wm_FULLSCREEN;
348
mp_msg(MSGT_VO, MSGL_V, "[x11] Unknown wm type...\n");
352
static void init_atoms(void)
354
XA_INIT(_NET_SUPPORTED);
355
XA_INIT(_NET_WM_STATE);
356
XA_INIT(_NET_WM_STATE_FULLSCREEN);
357
XA_INIT(_NET_WM_STATE_ABOVE);
358
XA_INIT(_NET_WM_STATE_STAYS_ON_TOP);
359
XA_INIT(_NET_WM_STATE_BELOW);
360
XA_INIT(_NET_WM_PID);
361
XA_INIT(_WIN_PROTOCOLS);
364
XA_INIT(_BLACKBOX_PID);
373
// char * DisplayName = ":0.0";
374
// Display * mDisplay;
375
XImage *mXImage = NULL;
378
XWindowAttributes attribs;
382
WinID = 0; // use root win
384
if (vo_depthonscreen)
387
return 1; // already called
390
XSetErrorHandler(x11_errorhandler);
394
if (!(mDisplayName = getenv("DISPLAY")))
395
mDisplayName = strdup(":0.0");
397
dispName = XDisplayName(mDisplayName);
400
mp_msg(MSGT_VO, MSGL_V, "X11 opening display: %s\n", dispName);
402
mDisplay = XOpenDisplay(dispName);
405
mp_msg(MSGT_VO, MSGL_ERR,
406
"vo: couldn't open the X11 display (%s)!\n", dispName);
409
mScreen = DefaultScreen(mDisplay); // Screen ID.
410
mRootWin = RootWindow(mDisplay, mScreen); // Root window ID.
415
if (XineramaIsActive(mDisplay))
417
XineramaScreenInfo *screens;
420
screens = XineramaQueryScreens(mDisplay, &num_screens);
421
if (xinerama_screen >= num_screens)
424
vo_screenwidth = screens[xinerama_screen].width;
425
if (!vo_screenheight)
426
vo_screenheight = screens[xinerama_screen].height;
427
xinerama_x = screens[xinerama_screen].x_org;
428
xinerama_y = screens[xinerama_screen].y_org;
437
XF86VidModeGetModeLine(mDisplay, mScreen, &clock, &modeline);
439
vo_screenwidth = modeline.hdisplay;
440
if (!vo_screenheight)
441
vo_screenheight = modeline.vdisplay;
446
vo_screenwidth = DisplayWidth(mDisplay, mScreen);
447
if (!vo_screenheight)
448
vo_screenheight = DisplayHeight(mDisplay, mScreen);
450
// get color depth (from root window, or the best visual):
451
XGetWindowAttributes(mDisplay, mRootWin, &attribs);
452
depth = attribs.depth;
454
if (depth != 15 && depth != 16 && depth != 24 && depth != 32)
458
depth = vo_find_depth_from_visuals(mDisplay, mScreen, &visual);
460
mXImage = XCreateImage(mDisplay, visual, depth, ZPixmap,
461
0, NULL, 1, 1, 8, 1);
464
XGetImage(mDisplay, mRootWin, 0, 0, 1, 1, AllPlanes, ZPixmap);
466
vo_depthonscreen = depth; // display depth on screen
468
// get bits/pixel from XImage structure:
475
* for the depth==24 case, the XImage structures might use
476
* 24 or 32 bits of data per pixel. The global variable
477
* vo_depthonscreen stores the amount of data per pixel in the
480
* Maybe we should rename vo_depthonscreen to (or add) vo_bpp?
482
bpp = mXImage->bits_per_pixel;
483
if ((vo_depthonscreen + 7) / 8 != (bpp + 7) / 8)
484
vo_depthonscreen = bpp; // by A'rpi
486
mXImage->red_mask | mXImage->green_mask | mXImage->blue_mask;
487
mp_msg(MSGT_VO, MSGL_V,
488
"vo: X11 color mask: %X (R:%lX G:%lX B:%lX)\n", mask,
489
mXImage->red_mask, mXImage->green_mask, mXImage->blue_mask);
490
XDestroyImage(mXImage);
492
if (((vo_depthonscreen + 7) / 8) == 2)
495
vo_depthonscreen = 15;
496
else if (mask == 0xFFFF)
497
vo_depthonscreen = 16;
499
// XCloseDisplay( mDisplay );
500
/* slightly improved local display detection AST */
501
if (strncmp(dispName, "unix:", 5) == 0)
503
else if (strncmp(dispName, "localhost:", 10) == 0)
505
if (*dispName == ':' && atoi(dispName + 1) < 10)
509
mp_msg(MSGT_VO, MSGL_V,
510
"vo: X11 running at %dx%d with depth %d and %d bpp (\"%s\" => %s display)\n",
511
vo_screenwidth, vo_screenheight, depth, vo_depthonscreen,
512
dispName, mLocalDisplay ? "local" : "remote");
514
vo_wm_type = vo_wm_detect();
516
vo_fs_type = vo_x11_get_fs_type(vo_wm_type);
518
fstype_dump(vo_fs_type);
528
mp_msg(MSGT_VO, MSGL_V,
529
"vo: x11 uninit called but X11 not inited..\n");
532
// if( !vo_depthonscreen ) return;
533
mp_msg(MSGT_VO, MSGL_V, "vo: uninit ...\n");
534
XSetErrorHandler(NULL);
535
XCloseDisplay(mDisplay);
536
vo_depthonscreen = 0;
540
#include "osdep/keycodes.h"
543
extern void mplayer_put_key(int code);
545
#ifdef XF86XK_AudioPause
546
void vo_x11_putkey_ext(int keysym)
550
case XF86XK_AudioPause:
551
mplayer_put_key(KEY_PAUSE);
553
case XF86XK_AudioStop:
554
mplayer_put_key(KEY_STOP);
556
case XF86XK_AudioPrev:
557
mplayer_put_key(KEY_PREV);
559
case XF86XK_AudioNext:
560
mplayer_put_key(KEY_NEXT);
568
void vo_x11_putkey(int key)
573
mplayer_put_key(KEY_LEFT);
576
mplayer_put_key(KEY_RIGHT);
579
mplayer_put_key(KEY_UP);
582
mplayer_put_key(KEY_DOWN);
585
mplayer_put_key(' ');
588
mplayer_put_key(KEY_ESC);
591
mplayer_put_key(KEY_TAB);
594
mplayer_put_key(KEY_ENTER);
597
mplayer_put_key(KEY_BS);
600
mplayer_put_key(KEY_DELETE);
603
mplayer_put_key(KEY_INSERT);
606
mplayer_put_key(KEY_HOME);
609
mplayer_put_key(KEY_END);
612
mplayer_put_key(KEY_PAGE_UP);
615
mplayer_put_key(KEY_PAGE_DOWN);
618
mplayer_put_key(KEY_F + 1);
621
mplayer_put_key(KEY_F + 2);
624
mplayer_put_key(KEY_F + 3);
627
mplayer_put_key(KEY_F + 4);
630
mplayer_put_key(KEY_F + 5);
633
mplayer_put_key(KEY_F + 6);
636
mplayer_put_key(KEY_F + 7);
639
mplayer_put_key(KEY_F + 8);
642
mplayer_put_key(KEY_F + 9);
645
mplayer_put_key(KEY_F + 10);
648
mplayer_put_key(KEY_F + 11);
651
mplayer_put_key(KEY_F + 12);
655
mplayer_put_key('-');
659
mplayer_put_key('+');
663
mplayer_put_key('*');
667
mplayer_put_key('/');
670
mplayer_put_key('<');
673
mplayer_put_key('>');
676
mplayer_put_key(KEY_KP0);
680
mplayer_put_key(KEY_KP1);
684
mplayer_put_key(KEY_KP2);
688
mplayer_put_key(KEY_KP3);
692
mplayer_put_key(KEY_KP4);
696
mplayer_put_key(KEY_KP5);
700
mplayer_put_key(KEY_KP6);
704
mplayer_put_key(KEY_KP7);
708
mplayer_put_key(KEY_KP8);
712
mplayer_put_key(KEY_KP9);
715
mplayer_put_key(KEY_KPDEC);
718
mplayer_put_key(KEY_KPINS);
721
mplayer_put_key(KEY_KPDEL);
724
mplayer_put_key(KEY_KPENTER);
727
mplayer_put_key('`');
730
mplayer_put_key('~');
733
mplayer_put_key('!');
736
mplayer_put_key('@');
739
mplayer_put_key('#');
742
mplayer_put_key('$');
745
mplayer_put_key('%');
748
mplayer_put_key('^');
751
mplayer_put_key('&');
754
mplayer_put_key('(');
757
mplayer_put_key(')');
760
mplayer_put_key('_');
763
mplayer_put_key('{');
766
mplayer_put_key('}');
769
mplayer_put_key(':');
772
mplayer_put_key(';');
775
mplayer_put_key('\"');
778
mplayer_put_key('\'');
781
mplayer_put_key(',');
784
mplayer_put_key('.');
787
mplayer_put_key('?');
790
mplayer_put_key('\\');
793
mplayer_put_key('|');
796
mplayer_put_key('=');
799
mplayer_put_key('[');
802
mplayer_put_key(']');
807
if ((key >= 'a' && key <= 'z') || (key >= 'A' && key <= 'Z') ||
808
(key >= '0' && key <= '9'))
809
mplayer_put_key(key);
815
// ----- Motif header: -------
817
#define MWM_HINTS_FUNCTIONS (1L << 0)
818
#define MWM_HINTS_DECORATIONS (1L << 1)
819
#define MWM_HINTS_INPUT_MODE (1L << 2)
820
#define MWM_HINTS_STATUS (1L << 3)
822
#define MWM_FUNC_ALL (1L << 0)
823
#define MWM_FUNC_RESIZE (1L << 1)
824
#define MWM_FUNC_MOVE (1L << 2)
825
#define MWM_FUNC_MINIMIZE (1L << 3)
826
#define MWM_FUNC_MAXIMIZE (1L << 4)
827
#define MWM_FUNC_CLOSE (1L << 5)
829
#define MWM_DECOR_ALL (1L << 0)
830
#define MWM_DECOR_BORDER (1L << 1)
831
#define MWM_DECOR_RESIZEH (1L << 2)
832
#define MWM_DECOR_TITLE (1L << 3)
833
#define MWM_DECOR_MENU (1L << 4)
834
#define MWM_DECOR_MINIMIZE (1L << 5)
835
#define MWM_DECOR_MAXIMIZE (1L << 6)
837
#define MWM_INPUT_MODELESS 0
838
#define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
839
#define MWM_INPUT_SYSTEM_MODAL 2
840
#define MWM_INPUT_FULL_APPLICATION_MODAL 3
841
#define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL
843
#define MWM_TEAROFF_WINDOW (1L<<0)
854
static MotifWmHints vo_MotifWmHints;
855
static Atom vo_MotifHints = None;
857
void vo_x11_decoration(Display * vo_Display, Window w, int d)
859
static unsigned int olddecor = MWM_DECOR_ALL;
860
static unsigned int oldfuncs =
861
MWM_FUNC_MOVE | MWM_FUNC_CLOSE | MWM_FUNC_MINIMIZE |
862
MWM_FUNC_MAXIMIZE | MWM_FUNC_RESIZE;
865
unsigned long mn, mb;
872
XSetTransientForHint(vo_Display, w,
873
RootWindow(vo_Display, mScreen));
876
vo_MotifHints = XInternAtom(vo_Display, "_MOTIF_WM_HINTS", 0);
877
if (vo_MotifHints != None)
881
MotifWmHints *mhints = NULL;
883
XGetWindowProperty(vo_Display, w, vo_MotifHints, 0, 20, False,
884
vo_MotifHints, &mtype, &mformat, &mn,
885
&mb, (unsigned char **) &mhints);
888
if (mhints->flags & MWM_HINTS_DECORATIONS)
889
olddecor = mhints->decorations;
890
if (mhints->flags & MWM_HINTS_FUNCTIONS)
891
oldfuncs = mhints->functions;
896
memset(&vo_MotifWmHints, 0, sizeof(MotifWmHints));
897
vo_MotifWmHints.flags =
898
MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
901
vo_MotifWmHints.functions = oldfuncs;
905
vo_MotifWmHints.decorations =
906
d | ((vo_fsmode & 2) ? 0 : MWM_DECOR_MENU);
908
vo_MotifWmHints.decorations =
909
d | ((vo_fsmode & 2) ? MWM_DECOR_MENU : 0);
911
XChangeProperty(vo_Display, w, vo_MotifHints, vo_MotifHints, 32,
913
(unsigned char *) &vo_MotifWmHints,
914
(vo_fsmode & 4) ? 4 : 5);
918
void vo_x11_classhint(Display * display, Window window, char *name)
921
pid_t pid = getpid();
923
wmClass.res_name = name;
924
wmClass.res_class = "MPlayer";
925
XSetClassHint(display, window, &wmClass);
926
XChangeProperty(display, window, XA_NET_WM_PID, XA_CARDINAL, 32,
927
PropModeReplace, (unsigned char *) &pid, 1);
930
Window vo_window = None;
936
void vo_setwindow(Window w, GC g)
946
if (vo_window != None)
947
vo_showcursor(mDisplay, vo_window);
951
XFreeGC(mDisplay, f_gc);
955
/* destroy window only if it's not controlled by GUI */
961
XSetBackground(mDisplay, vo_gc, 0);
962
XFreeGC(mDisplay, vo_gc);
965
if (vo_window != None)
967
XClearWindow(mDisplay, vo_window);
972
XUnmapWindow(mDisplay, vo_window);
973
XDestroyWindow(mDisplay, vo_window);
976
XNextEvent(mDisplay, &xev);
978
while (xev.type != DestroyNotify
979
|| xev.xdestroywindow.event != vo_window);
984
vo_old_width = vo_old_height = 0;
988
int vo_mouse_timer_const = 30;
989
static int vo_mouse_counter = 30;
991
int vo_x11_check_events(Display * mydisplay)
997
static XComposeStatus stat;
999
// unsigned long vo_KeyTable[512];
1001
if ((vo_mouse_autohide) && (--vo_mouse_counter == 0))
1002
vo_hidecursor(mydisplay, vo_window);
1004
while (XPending(mydisplay))
1006
XNextEvent(mydisplay, &Event);
1010
guiGetEvent(0, (char *) &Event);
1011
if (vo_window != Event.xany.window)
1015
// printf("\rEvent.type=%X \n",Event.type);
1019
ret |= VO_EVENT_EXPOSE;
1021
case ConfigureNotify:
1022
// if (!vo_fs && (Event.xconfigure.width == vo_screenwidth || Event.xconfigure.height == vo_screenheight)) break;
1023
// if (vo_fs && Event.xconfigure.width != vo_screenwidth && Event.xconfigure.height != vo_screenheight) break;
1024
if (vo_window == None)
1026
vo_dwidth = Event.xconfigure.width;
1027
vo_dheight = Event.xconfigure.height;
1029
/* when resizing, x and y are zero :( */
1030
vo_dx = Event.xconfigure.x;
1031
vo_dy = Event.xconfigure.y;
1038
XGetGeometry(mydisplay, vo_window, &root, &foo, &foo,
1039
&foo /*width */ , &foo /*height */ , &foo,
1041
XTranslateCoordinates(mydisplay, vo_window, root, 0, 0,
1042
&vo_dx, &vo_dy, &win);
1045
ret |= VO_EVENT_RESIZE;
1052
if ( use_gui ) { break; }
1055
XLookupString(&Event.xkey, buf, sizeof(buf), &keySym,
1057
#ifdef XF86XK_AudioPause
1058
vo_x11_putkey_ext(keySym);
1061
((keySym & 0xff00) !=
1062
0 ? ((keySym & 0x00ff) + 256) : (keySym));
1064
ret |= VO_EVENT_KEYPRESS;
1068
if (vo_mouse_autohide)
1070
vo_showcursor(mydisplay, vo_window);
1071
vo_mouse_counter = vo_mouse_timer_const;
1075
if (vo_mouse_autohide)
1077
vo_showcursor(mydisplay, vo_window);
1078
vo_mouse_counter = vo_mouse_timer_const;
1080
// Ignore mouse whell press event
1081
if (Event.xbutton.button > 3)
1083
mplayer_put_key(MOUSE_BTN0 + Event.xbutton.button - 1);
1087
// Ignor mouse button 1 - 3 under gui
1088
if (use_gui && (Event.xbutton.button >= 1)
1089
&& (Event.xbutton.button <= 3))
1092
mplayer_put_key((MOUSE_BTN0 + Event.xbutton.button -
1096
if (vo_mouse_autohide)
1098
vo_showcursor(mydisplay, vo_window);
1099
vo_mouse_counter = vo_mouse_timer_const;
1102
// Ignor mouse button 1 - 3 under gui
1103
if (use_gui && (Event.xbutton.button >= 1)
1104
&& (Event.xbutton.button <= 3))
1107
mplayer_put_key(MOUSE_BTN0 + Event.xbutton.button - 1);
1109
case PropertyNotify:
1112
XGetAtomName(mydisplay, Event.xproperty.atom);
1117
// fprintf(stderr,"[ws] PropertyNotify ( 0x%x ) %s ( 0x%x )\n",vo_window,name,Event.xproperty.atom );
1123
vo_hint.win_gravity = old_gravity;
1124
XSetWMNormalHints(mDisplay, vo_window, &vo_hint);
1133
* \brief sets the size and position of the non-fullscreen window.
1135
void vo_x11_nofs_sizepos(int x, int y, int width, int height)
1140
vo_old_width = width;
1141
vo_old_height = height;
1146
vo_dheight = height;
1147
XMoveResizeWindow(mDisplay, vo_window, x, y, width, height);
1151
void vo_x11_sizehint(int x, int y, int width, int height, int max)
1153
vo_hint.flags = PPosition | PSize | PWinGravity;
1156
vo_hint.flags |= PAspect;
1157
vo_hint.min_aspect.x = width;
1158
vo_hint.min_aspect.y = height;
1159
vo_hint.max_aspect.x = width;
1160
vo_hint.max_aspect.y = height;
1165
vo_hint.width = width;
1166
vo_hint.height = height;
1169
vo_hint.max_width = width;
1170
vo_hint.max_height = height;
1171
vo_hint.flags |= PMaxSize;
1174
vo_hint.max_width = 0;
1175
vo_hint.max_height = 0;
1178
// set min height/width to 4 to avoid off by one errors
1179
// and because mga_vid requires a minial size of 4 pixel
1180
vo_hint.min_width = vo_hint.min_height = 4;
1181
vo_hint.flags |= PMinSize;
1183
vo_hint.win_gravity = StaticGravity;
1184
XSetWMNormalHints(mDisplay, vo_window, &vo_hint);
1187
static int vo_x11_get_gnome_layer(Display * mDisplay, Window win)
1191
unsigned long nitems;
1192
unsigned long bytesafter;
1193
unsigned short *args = NULL;
1195
if (XGetWindowProperty(mDisplay, win, XA_WIN_LAYER, 0, 16384,
1196
False, AnyPropertyType, &type, &format, &nitems,
1198
(unsigned char **) &args) == Success
1199
&& nitems > 0 && args)
1201
mp_msg(MSGT_VO, MSGL_V, "[x11] original window layer is %d.\n",
1205
return WIN_LAYER_NORMAL;
1209
Window vo_x11_create_smooth_window(Display * mDisplay, Window mRoot,
1210
Visual * vis, int x, int y,
1211
unsigned int width, unsigned int height,
1212
int depth, Colormap col_map)
1214
unsigned long xswamask = CWBackingStore | CWBorderPixel;
1215
XSetWindowAttributes xswa;
1218
if (col_map != CopyFromParent)
1220
xswa.colormap = col_map;
1221
xswamask |= CWColormap;
1223
xswa.background_pixel = 0;
1224
xswa.border_pixel = 0;
1225
xswa.backing_store = Always;
1226
xswa.bit_gravity = StaticGravity;
1229
XCreateWindow(mDisplay, mRootWin, x, y, width, height, 0, depth,
1230
CopyFromParent, vis, xswamask, &xswa);
1232
f_gc = XCreateGC(mDisplay, ret_win, 0, 0);
1233
XSetForeground(mDisplay, f_gc, 0);
1239
void vo_x11_clearwindow_part(Display * mDisplay, Window vo_window,
1240
int img_width, int img_height, int use_fs)
1242
int u_dheight, u_dwidth, left_ov, left_ov2;
1247
u_dheight = use_fs ? vo_screenheight : vo_dheight;
1248
u_dwidth = use_fs ? vo_screenwidth : vo_dwidth;
1249
if ((u_dheight <= img_height) && (u_dwidth <= img_width))
1252
left_ov = (u_dheight - img_height) / 2;
1253
left_ov2 = (u_dwidth - img_width) / 2;
1255
XFillRectangle(mDisplay, vo_window, f_gc, 0, 0, u_dwidth, left_ov);
1256
XFillRectangle(mDisplay, vo_window, f_gc, 0, u_dheight - left_ov - 1,
1257
u_dwidth, left_ov + 1);
1259
if (u_dwidth > img_width)
1261
XFillRectangle(mDisplay, vo_window, f_gc, 0, left_ov, left_ov2,
1263
XFillRectangle(mDisplay, vo_window, f_gc, u_dwidth - left_ov2 - 1,
1264
left_ov, left_ov2, img_height);
1270
void vo_x11_clearwindow(Display * mDisplay, Window vo_window)
1274
XFillRectangle(mDisplay, vo_window, f_gc, 0, 0, vo_screenwidth,
1281
void vo_x11_setlayer(Display * mDisplay, Window vo_window, int layer)
1286
if (vo_fs_type & vo_wm_LAYER)
1288
XClientMessageEvent xev;
1291
orig_layer = vo_x11_get_gnome_layer(mDisplay, vo_window);
1293
memset(&xev, 0, sizeof(xev));
1294
xev.type = ClientMessage;
1295
xev.display = mDisplay;
1296
xev.window = vo_window;
1297
xev.message_type = XA_WIN_LAYER;
1299
xev.data.l[0] = layer ? fs_layer : orig_layer; // if not fullscreen, stay on default layer
1300
xev.data.l[1] = CurrentTime;
1301
mp_msg(MSGT_VO, MSGL_V,
1302
"[x11] Layered style stay on top (layer %ld).\n",
1304
XSendEvent(mDisplay, mRootWin, False, SubstructureNotifyMask,
1306
} else if (vo_fs_type & vo_wm_NETWM)
1308
XClientMessageEvent xev;
1311
memset(&xev, 0, sizeof(xev));
1312
xev.type = ClientMessage;
1313
xev.message_type = XA_NET_WM_STATE;
1314
xev.display = mDisplay;
1315
xev.window = vo_window;
1317
xev.data.l[0] = layer;
1319
if (vo_fs_type & vo_wm_STAYS_ON_TOP)
1320
xev.data.l[1] = XA_NET_WM_STATE_STAYS_ON_TOP;
1321
else if (vo_fs_type & vo_wm_ABOVE)
1322
xev.data.l[1] = XA_NET_WM_STATE_ABOVE;
1323
else if (vo_fs_type & vo_wm_FULLSCREEN)
1324
xev.data.l[1] = XA_NET_WM_STATE_FULLSCREEN;
1325
else if (vo_fs_type & vo_wm_BELOW)
1326
// This is not fallback. We can safely assume that situation where
1327
// only NETWM_STATE_BELOW is supported and others not, doesn't exist.
1328
xev.data.l[1] = XA_NET_WM_STATE_BELOW;
1330
XSendEvent(mDisplay, mRootWin, False, SubstructureRedirectMask,
1332
state = XGetAtomName(mDisplay, xev.data.l[1]);
1333
mp_msg(MSGT_VO, MSGL_V,
1334
"[x11] NET style stay on top (layer %d). Using state %s.\n",
1340
static int vo_x11_get_fs_type(int supported)
1343
int type = supported;
1348
for (i = 0; vo_fstype_list[i]; i++)
1351
char *arg = vo_fstype_list[i];
1353
if (vo_fstype_list[i][0] == '-')
1356
arg = vo_fstype_list[i] + 1;
1359
if (!strncmp(arg, "layer", 5))
1361
if (!neg && (arg[5] == '='))
1363
char *endptr = NULL;
1364
int layer = strtol(vo_fstype_list[i] + 6, &endptr, 10);
1366
if (endptr && *endptr == '\0' && layer >= 0
1371
type &= ~vo_wm_LAYER;
1373
type |= vo_wm_LAYER;
1374
} else if (!strcmp(arg, "above"))
1377
type &= ~vo_wm_ABOVE;
1379
type |= vo_wm_ABOVE;
1380
} else if (!strcmp(arg, "fullscreen"))
1383
type &= ~vo_wm_FULLSCREEN;
1385
type |= vo_wm_FULLSCREEN;
1386
} else if (!strcmp(arg, "stays_on_top"))
1389
type &= ~vo_wm_STAYS_ON_TOP;
1391
type |= vo_wm_STAYS_ON_TOP;
1392
} else if (!strcmp(arg, "below"))
1395
type &= ~vo_wm_BELOW;
1397
type |= vo_wm_BELOW;
1398
} else if (!strcmp(arg, "netwm"))
1401
type &= ~vo_wm_NETWM;
1403
type |= vo_wm_NETWM;
1404
} else if (!strcmp(arg, "none"))
1412
void vo_x11_fullscreen(void)
1416
if (WinID >= 0 || vo_fs_flip)
1422
if ( ! (vo_fs_type & vo_wm_FULLSCREEN) ) // not needed with EWMH fs
1424
if (vo_dwidth != vo_screenwidth && vo_dheight != vo_screenheight)
1432
vo_x11_ewmh_fullscreen(_NET_WM_STATE_REMOVE); // removes fullscreen state if wm supports EWMH
1437
vo_x11_ewmh_fullscreen(_NET_WM_STATE_ADD); // sends fullscreen state to be added if wm supports EWMH
1440
if ( ! (vo_fs_type & vo_wm_FULLSCREEN) ) // not needed with EWMH fs
1443
(vo_dwidth == vo_screenwidth && vo_dwidth != vo_old_width) &&
1444
(vo_dheight == vo_screenheight && vo_dheight != vo_old_height))
1448
vo_old_width = vo_dwidth;
1449
vo_old_height = vo_dheight;
1453
h = vo_screenheight;
1459
XGetWMNormalHints(mDisplay, vo_window, &vo_hint, &dummy);
1460
if (!(vo_hint.flags & PWinGravity))
1461
old_gravity = NorthWestGravity;
1463
old_gravity = vo_hint.win_gravity;
1465
if (vo_wm_type == 0 && !(vo_fsmode & 16))
1467
XUnmapWindow(mDisplay, vo_window); // required for MWM
1468
XWithdrawWindow(mDisplay, vo_window, mScreen);
1472
if ( ! (vo_fs_type & vo_wm_FULLSCREEN) ) // not needed with EWMH fs
1474
vo_x11_decoration(mDisplay, vo_window, (vo_fs) ? 0 : 1);
1475
vo_x11_sizehint(x, y, w, h, 0);
1476
vo_x11_setlayer(mDisplay, vo_window, vo_fs);
1479
XMoveResizeWindow(mDisplay, vo_window, x, y, w, h);
1481
/* some WMs lose ontop after fullscreeen */
1482
if ((!(vo_fs)) & vo_ontop)
1483
vo_x11_setlayer(mDisplay, vo_window, vo_ontop);
1485
#ifdef HAVE_XINERAMA
1486
vo_x11_xinerama_move(mDisplay, vo_window);
1489
XMapRaised(mDisplay, vo_window);
1490
XRaiseWindow(mDisplay, vo_window);
1494
void vo_x11_ontop(void)
1496
vo_ontop = (!(vo_ontop));
1498
vo_x11_setlayer(mDisplay, vo_window, vo_ontop);
1502
* XScreensaver stuff
1505
static int got_badwindow;
1506
static XErrorHandler old_handler;
1508
static int badwindow_handler(Display * dpy, XErrorEvent * error)
1510
if (error->error_code != BadWindow)
1511
return (*old_handler) (dpy, error);
1513
got_badwindow = True;
1517
static Window find_xscreensaver_window(Display * dpy)
1520
Window root = RootWindowOfScreen(DefaultScreenOfDisplay(dpy));
1521
Window root2, parent, *kids;
1524
unsigned int nkids = 0;
1526
xs_version = XInternAtom(dpy, "_SCREENSAVER_VERSION", True);
1528
if (!(xs_version != None &&
1529
XQueryTree(dpy, root, &root2, &parent, &kids, &nkids) &&
1533
old_handler = XSetErrorHandler(badwindow_handler);
1535
for (i = 0; i < nkids; i++)
1539
unsigned long nitems, bytesafter;
1543
got_badwindow = False;
1545
XGetWindowProperty(dpy, kids[i], xs_version, 0, 200, False,
1546
XA_STRING, &type, &format, &nitems,
1547
&bytesafter, (unsigned char **) &v);
1552
if (status == Success && type != None)
1559
XSetErrorHandler(old_handler);
1564
static Window xs_windowid = 0;
1565
static Atom deactivate;
1566
static Atom screensaver;
1568
static unsigned int time_last;
1570
void xscreensaver_heartbeat(void)
1572
unsigned int time = GetTimerMS();
1575
if (mDisplay && xs_windowid &&
1576
((time - time_last) > 30000 || (time - time_last) < 0))
1580
ev.xany.type = ClientMessage;
1581
ev.xclient.display = mDisplay;
1582
ev.xclient.window = xs_windowid;
1583
ev.xclient.message_type = screensaver;
1584
ev.xclient.format = 32;
1585
memset(&ev.xclient.data, 0, sizeof(ev.xclient.data));
1586
ev.xclient.data.l[0] = (long) deactivate;
1588
mp_msg(MSGT_VO, MSGL_DBG2, "Pinging xscreensaver.\n");
1589
old_handler = XSetErrorHandler(badwindow_handler);
1590
XSendEvent(mDisplay, xs_windowid, False, 0L, &ev);
1591
XSync(mDisplay, False);
1592
XSetErrorHandler(old_handler);
1596
static void xscreensaver_disable(Display * dpy)
1598
mp_msg(MSGT_VO, MSGL_DBG2, "xscreensaver_disable()\n");
1600
xs_windowid = find_xscreensaver_window(dpy);
1603
mp_msg(MSGT_VO, MSGL_INFO, MSGTR_CouldNotFindXScreenSaver);
1606
mp_msg(MSGT_VO, MSGL_INFO,
1607
"xscreensaver_disable: xscreensaver wid=%ld.\n", xs_windowid);
1609
deactivate = XInternAtom(dpy, "DEACTIVATE", False);
1610
screensaver = XInternAtom(dpy, "SCREENSAVER", False);
1613
static void xscreensaver_enable(void)
1619
* End of XScreensaver stuff
1622
void saver_on(Display * mDisplay)
1630
if (DPMSQueryExtension(mDisplay, ¬hing, ¬hing))
1632
if (!DPMSEnable(mDisplay))
1633
{ // restoring power saving settings
1634
mp_msg(MSGT_VO, MSGL_WARN, "DPMS not available?\n");
1637
// DPMS does not seem to be enabled unless we call DPMSInfo
1641
DPMSForceLevel(mDisplay, DPMSModeOn);
1642
DPMSInfo(mDisplay, &state, &onoff);
1645
mp_msg(MSGT_VO, MSGL_V,
1646
"Successfully enabled DPMS\n");
1649
mp_msg(MSGT_VO, MSGL_WARN, "Could not enable DPMS\n");
1659
int dummy, interval, prefer_blank, allow_exp;
1661
XGetScreenSaver(mDisplay, &dummy, &interval, &prefer_blank,
1663
XSetScreenSaver(mDisplay, timeout_save, interval, prefer_blank,
1665
XGetScreenSaver(mDisplay, &timeout_save, &interval, &prefer_blank,
1670
if (stop_xscreensaver)
1671
xscreensaver_enable();
1672
if (kdescreensaver_was_running && stop_xscreensaver)
1675
("dcop kdesktop KScreensaverIface enable true 2>/dev/null >/dev/null");
1676
kdescreensaver_was_running = 0;
1682
void saver_off(Display * mDisplay)
1685
int interval, prefer_blank, allow_exp;
1690
if (DPMSQueryExtension(mDisplay, ¬hing, ¬hing))
1695
DPMSInfo(mDisplay, &state, &onoff);
1700
mp_msg(MSGT_VO, MSGL_V, "Disabling DPMS\n");
1702
stat = DPMSDisable(mDisplay); // monitor powersave off
1703
mp_msg(MSGT_VO, MSGL_V, "DPMSDisable stat: %d\n", stat);
1709
XGetScreenSaver(mDisplay, &timeout_save, &interval, &prefer_blank,
1712
XSetScreenSaver(mDisplay, 0, interval, prefer_blank,
1715
// turning off screensaver
1716
if (stop_xscreensaver)
1717
xscreensaver_disable(mDisplay);
1718
if (stop_xscreensaver && !kdescreensaver_was_running)
1720
kdescreensaver_was_running =
1722
("dcop kdesktop KScreensaverIface isEnabled 2>/dev/null | sed 's/1/true/g' | grep true 2>/dev/null >/dev/null")
1724
if (kdescreensaver_was_running)
1726
("dcop kdesktop KScreensaverIface enable false 2>/dev/null >/dev/null");
1730
static XErrorHandler old_handler = NULL;
1731
static int selectinput_err = 0;
1732
static int x11_selectinput_errorhandler(Display * display,
1733
XErrorEvent * event)
1735
if (event->error_code == BadAccess)
1737
selectinput_err = 1;
1738
mp_msg(MSGT_VO, MSGL_ERR,
1739
"X11 error: BadAccess during XSelectInput Call\n");
1740
mp_msg(MSGT_VO, MSGL_ERR,
1741
"X11 error: The 'ButtonPressMask' mask of specified window has probably already used by another appication (see man XSelectInput)\n");
1742
/* If you think mplayer should shutdown with this error, comments out following line */
1745
if (old_handler != NULL)
1746
old_handler(display, event);
1748
x11_errorhandler(display, event);
1752
void vo_x11_selectinput_witherr(Display * display, Window w,
1755
XSync(display, False);
1756
old_handler = XSetErrorHandler(x11_selectinput_errorhandler);
1757
selectinput_err = 0;
1758
if (vo_nomouse_input)
1760
XSelectInput(display, w,
1762
(~(ButtonPressMask | ButtonReleaseMask)));
1765
XSelectInput(display, w, event_mask);
1767
XSync(display, False);
1768
XSetErrorHandler(old_handler);
1769
if (selectinput_err)
1771
mp_msg(MSGT_VO, MSGL_ERR,
1772
"X11 error: MPlayer discards mouse control (reconfiguring)\n");
1773
XSelectInput(display, w,
1776
(ButtonPressMask | ButtonReleaseMask |
1777
PointerMotionMask)));
1781
#ifdef HAVE_XINERAMA
1782
void vo_x11_xinerama_move(Display * dsp, Window w)
1784
if (XineramaIsActive(dsp) && !geometry_xy_changed)
1786
/* printf("XXXX Xinerama screen: x: %hd y: %hd\n",xinerama_x,xinerama_y); */
1787
XMoveWindow(dsp, w, xinerama_x, xinerama_y);
1793
void vo_vm_switch(uint32_t X, uint32_t Y, int *modeline_width,
1794
int *modeline_height)
1796
int vm_event, vm_error;
1798
int i, j, have_vm = 0;
1802
if (XF86VidModeQueryExtension(mDisplay, &vm_event, &vm_error))
1804
XF86VidModeQueryVersion(mDisplay, &vm_ver, &vm_rev);
1805
mp_msg(MSGT_VO, MSGL_V, "XF86VidMode Extension v%i.%i\n", vm_ver,
1809
mp_msg(MSGT_VO, MSGL_WARN,
1810
"XF86VidMode Extenstion not available.\n");
1814
if (vidmodes == NULL)
1815
XF86VidModeGetAllModeLines(mDisplay, mScreen, &modecount,
1818
*modeline_width = vidmodes[0]->hdisplay;
1819
*modeline_height = vidmodes[0]->vdisplay;
1821
for (i = 1; i < modecount; i++)
1822
if ((vidmodes[i]->hdisplay >= X)
1823
&& (vidmodes[i]->vdisplay >= Y))
1824
if ((vidmodes[i]->hdisplay <= *modeline_width)
1825
&& (vidmodes[i]->vdisplay <= *modeline_height))
1827
*modeline_width = vidmodes[i]->hdisplay;
1828
*modeline_height = vidmodes[i]->vdisplay;
1832
mp_msg(MSGT_VO, MSGL_INFO, MSGTR_SelectedVideoMode,
1833
*modeline_width, *modeline_height, X, Y);
1834
XF86VidModeLockModeSwitch(mDisplay, mScreen, 0);
1835
XF86VidModeSwitchToMode(mDisplay, mScreen, vidmodes[j]);
1836
XF86VidModeSwitchToMode(mDisplay, mScreen, vidmodes[j]);
1837
X = (vo_screenwidth - *modeline_width) / 2;
1838
Y = (vo_screenheight - *modeline_height) / 2;
1839
XF86VidModeSetViewPort(mDisplay, mScreen, X, Y);
1843
void vo_vm_close(Display * dpy)
1846
if (vidmodes != NULL && vo_window != None)
1848
if (vidmodes != NULL)
1854
screen = DefaultScreen(dpy);
1858
XF86VidModeGetAllModeLines(mDisplay, mScreen, &modecount,
1860
for (i = 0; i < modecount; i++)
1861
if ((vidmodes[i]->hdisplay == vo_screenwidth)
1862
&& (vidmodes[i]->vdisplay == vo_screenheight))
1864
mp_msg(MSGT_VO, MSGL_INFO,
1865
"Returning to original mode %dx%d\n",
1866
vo_screenwidth, vo_screenheight);
1870
XF86VidModeSwitchToMode(dpy, screen, vidmodes[i]);
1871
XF86VidModeSwitchToMode(dpy, screen, vidmodes[i]);
1878
#endif /* X11_FULLSCREEN */
1882
* Scan the available visuals on this Display/Screen. Try to find
1883
* the 'best' available TrueColor visual that has a decent color
1884
* depth (at least 15bit). If there are multiple visuals with depth
1885
* >= 15bit, we prefer visuals with a smaller color depth.
1887
int vo_find_depth_from_visuals(Display * dpy, int screen,
1888
Visual ** visual_return)
1890
XVisualInfo visual_tmpl;
1891
XVisualInfo *visuals;
1893
int bestvisual = -1;
1894
int bestvisual_depth = -1;
1896
visual_tmpl.screen = screen;
1897
visual_tmpl.class = TrueColor;
1898
visuals = XGetVisualInfo(dpy,
1899
VisualScreenMask | VisualClassMask,
1900
&visual_tmpl, &nvisuals);
1901
if (visuals != NULL)
1903
for (i = 0; i < nvisuals; i++)
1905
mp_msg(MSGT_VO, MSGL_V,
1906
"vo: X11 truecolor visual %#lx, depth %d, R:%lX G:%lX B:%lX\n",
1907
visuals[i].visualid, visuals[i].depth,
1908
visuals[i].red_mask, visuals[i].green_mask,
1909
visuals[i].blue_mask);
1911
* save the visual index and it's depth, if this is the first
1912
* truecolor visul, or a visual that is 'preferred' over the
1913
* previous 'best' visual
1915
if (bestvisual_depth == -1
1916
|| (visuals[i].depth >= 15
1917
&& (visuals[i].depth < bestvisual_depth
1918
|| bestvisual_depth < 15)))
1921
bestvisual_depth = visuals[i].depth;
1925
if (bestvisual != -1 && visual_return != NULL)
1926
*visual_return = visuals[bestvisual].visual;
1930
return bestvisual_depth;
1934
static Colormap cmap = None;
1935
static XColor cols[256];
1936
static int cm_size, red_mask, green_mask, blue_mask;
1939
Colormap vo_x11_create_colormap(XVisualInfo * vinfo)
1941
unsigned k, r, g, b, ru, gu, bu, m, rv, gv, bv, rvu, gvu, bvu;
1943
if (vinfo->class != DirectColor)
1944
return XCreateColormap(mDisplay, mRootWin, vinfo->visual,
1947
/* can this function get called twice or more? */
1950
cm_size = vinfo->colormap_size;
1951
red_mask = vinfo->red_mask;
1952
green_mask = vinfo->green_mask;
1953
blue_mask = vinfo->blue_mask;
1954
ru = (red_mask & (red_mask - 1)) ^ red_mask;
1955
gu = (green_mask & (green_mask - 1)) ^ green_mask;
1956
bu = (blue_mask & (blue_mask - 1)) ^ blue_mask;
1957
rvu = 65536ull * ru / (red_mask + ru);
1958
gvu = 65536ull * gu / (green_mask + gu);
1959
bvu = 65536ull * bu / (blue_mask + bu);
1962
m = DoRed | DoGreen | DoBlue;
1963
for (k = 0; k < cm_size; k++)
1967
cols[k].pixel = r | g | b;
1972
t = (r + ru) & red_mask;
1976
t = (g + gu) & green_mask;
1980
t = (b + bu) & blue_mask;
1988
cmap = XCreateColormap(mDisplay, mRootWin, vinfo->visual, AllocAll);
1989
XStoreColors(mDisplay, cmap, cols, cm_size);
1994
* Via colormaps/gamma ramps we can do gamma, brightness, contrast,
1995
* hue and red/green/blue intensity, but we cannot do saturation.
1996
* Currently only gamma, brightness and contrast are implemented.
1997
* Is there sufficient interest for hue and/or red/green/blue intensity?
1999
/* these values have range [-100,100] and are initially 0 */
2000
static int vo_gamma = 0;
2001
static int vo_brightness = 0;
2002
static int vo_contrast = 0;
2005
uint32_t vo_x11_set_equalizer(char *name, int value)
2007
float gamma, brightness, contrast;
2012
* IMPLEMENTME: consider using XF86VidModeSetGammaRamp in the case
2013
* of TrueColor-ed window but be careful:
2014
* unlike the colormaps, which are private for the X client
2015
* who created them and thus automatically destroyed on client
2016
* disconnect, this gamma ramp is a system-wide (X-server-wide)
2017
* setting and _must_ be restored before the process exit.
2018
* Unforunately when the process crashes (or get killed
2019
* for some reason) it is impossible to restore the setting,
2020
* and such behaviour could be rather annoying for the users.
2025
if (!strcasecmp(name, "brightness"))
2026
vo_brightness = value;
2027
else if (!strcasecmp(name, "contrast"))
2028
vo_contrast = value;
2029
else if (!strcasecmp(name, "gamma"))
2034
brightness = 0.01 * vo_brightness;
2035
contrast = tan(0.0095 * (vo_contrast + 100) * M_PI / 4);
2036
gamma = pow(2, -0.02 * vo_gamma);
2038
rf = (float) ((red_mask & (red_mask - 1)) ^ red_mask) / red_mask;
2039
gf = (float) ((green_mask & (green_mask - 1)) ^ green_mask) /
2041
bf = (float) ((blue_mask & (blue_mask - 1)) ^ blue_mask) / blue_mask;
2043
/* now recalculate the colormap using the newly set value */
2044
for (k = 0; k < cm_size; k++)
2048
s = pow(rf * k, gamma);
2049
s = (s - 0.5) * contrast + 0.5;
2055
cols[k].red = (unsigned short) (s * 65535);
2057
s = pow(gf * k, gamma);
2058
s = (s - 0.5) * contrast + 0.5;
2064
cols[k].green = (unsigned short) (s * 65535);
2066
s = pow(bf * k, gamma);
2067
s = (s - 0.5) * contrast + 0.5;
2073
cols[k].blue = (unsigned short) (s * 65535);
2076
XStoreColors(mDisplay, cmap, cols, cm_size);
2081
uint32_t vo_x11_get_equalizer(char *name, int *value)
2085
if (!strcasecmp(name, "brightness"))
2086
*value = vo_brightness;
2087
else if (!strcasecmp(name, "contrast"))
2088
*value = vo_contrast;
2089
else if (!strcasecmp(name, "gamma"))
2097
int vo_xv_set_eq(uint32_t xv_port, char *name, int value)
2099
XvAttribute *attributes;
2100
int i, howmany, xv_atom;
2102
mp_dbg(MSGT_VO, MSGL_V, "xv_set_eq called! (%s, %d)\n", name, value);
2104
/* get available attributes */
2105
attributes = XvQueryPortAttributes(mDisplay, xv_port, &howmany);
2106
for (i = 0; i < howmany && attributes; i++)
2107
if (attributes[i].flags & XvSettable)
2109
xv_atom = XInternAtom(mDisplay, attributes[i].name, True);
2110
/* since we have SET_DEFAULTS first in our list, we can check if it's available
2111
then trigger it if it's ok so that the other values are at default upon query */
2112
if (xv_atom != None)
2114
int hue = 0, port_value, port_min, port_max;
2116
if (!strcmp(attributes[i].name, "XV_BRIGHTNESS") &&
2117
(!strcasecmp(name, "brightness")))
2119
else if (!strcmp(attributes[i].name, "XV_CONTRAST") &&
2120
(!strcasecmp(name, "contrast")))
2122
else if (!strcmp(attributes[i].name, "XV_SATURATION") &&
2123
(!strcasecmp(name, "saturation")))
2125
else if (!strcmp(attributes[i].name, "XV_HUE") &&
2126
(!strcasecmp(name, "hue")))
2131
/* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
2132
if (!strcmp(attributes[i].name, "XV_RED_INTENSITY") &&
2133
(!strcasecmp(name, "red_intensity")))
2135
else if (!strcmp(attributes[i].name, "XV_GREEN_INTENSITY")
2136
&& (!strcasecmp(name, "green_intensity")))
2138
else if (!strcmp(attributes[i].name, "XV_BLUE_INTENSITY")
2139
&& (!strcasecmp(name, "blue_intensity")))
2144
port_min = attributes[i].min_value;
2145
port_max = attributes[i].max_value;
2147
/* nvidia hue workaround */
2148
if (hue && port_min == 0 && port_max == 360)
2152
0) ? (port_value - 100) : (port_value + 100);
2158
(port_value + 100) * (port_max - port_min) / 200 +
2160
XvSetPortAttribute(mDisplay, xv_port, xv_atom, port_value);
2167
int vo_xv_get_eq(uint32_t xv_port, char *name, int *value)
2170
XvAttribute *attributes;
2171
int i, howmany, xv_atom;
2173
/* get available attributes */
2174
attributes = XvQueryPortAttributes(mDisplay, xv_port, &howmany);
2175
for (i = 0; i < howmany && attributes; i++)
2176
if (attributes[i].flags & XvGettable)
2178
xv_atom = XInternAtom(mDisplay, attributes[i].name, True);
2179
/* since we have SET_DEFAULTS first in our list, we can check if it's available
2180
then trigger it if it's ok so that the other values are at default upon query */
2181
if (xv_atom != None)
2183
int val, port_value = 0, port_min, port_max;
2185
XvGetPortAttribute(mDisplay, xv_port, xv_atom,
2188
port_min = attributes[i].min_value;
2189
port_max = attributes[i].max_value;
2191
(port_value - port_min) * 200 / (port_max - port_min) -
2194
if (!strcmp(attributes[i].name, "XV_BRIGHTNESS") &&
2195
(!strcasecmp(name, "brightness")))
2197
else if (!strcmp(attributes[i].name, "XV_CONTRAST") &&
2198
(!strcasecmp(name, "contrast")))
2200
else if (!strcmp(attributes[i].name, "XV_SATURATION") &&
2201
(!strcasecmp(name, "saturation")))
2203
else if (!strcmp(attributes[i].name, "XV_HUE") &&
2204
(!strcasecmp(name, "hue")))
2206
/* nasty nvidia detect */
2207
if (port_min == 0 && port_max == 360)
2208
*value = (val >= 0) ? (val - 100) : (val + 100);
2212
/* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
2213
if (!strcmp(attributes[i].name, "XV_RED_INTENSITY") &&
2214
(!strcasecmp(name, "red_intensity")))
2216
else if (!strcmp(attributes[i].name, "XV_GREEN_INTENSITY")
2217
&& (!strcasecmp(name, "green_intensity")))
2219
else if (!strcmp(attributes[i].name, "XV_BLUE_INTENSITY")
2220
&& (!strcasecmp(name, "blue_intensity")))
2225
mp_dbg(MSGT_VO, MSGL_V, "xv_get_eq called! (%s, %d)\n",
2233
/** \brief contains flags changing the execution of the colorkeying code */
2234
xv_ck_info_t xv_ck_info = { CK_METHOD_MANUALFILL, CK_SRC_CUR };
2235
unsigned long xv_colorkey; ///< The color used for manual colorkeying.
2236
unsigned int xv_port; ///< The selected Xv port.
2239
* \brief Interns the requested atom if it is available.
2241
* \param atom_name String containing the name of the requested atom.
2243
* \return Returns the atom if available, else None is returned.
2246
static Atom xv_intern_atom_if_exists( char const * atom_name )
2248
XvAttribute * attributes;
2250
Atom xv_atom = None;
2252
attributes = XvQueryPortAttributes( mDisplay, xv_port, &attrib_count );
2253
if( attributes!=NULL )
2255
for ( i = 0; i < attrib_count; ++i )
2257
if ( strcmp(attributes[i].name, atom_name ) == 0 )
2259
xv_atom = XInternAtom( mDisplay, atom_name, False );
2260
break; // found what we want, break out
2263
XFree( attributes );
2270
* \brief Try to enable vsync for xv.
2271
* \return Returns -1 if not available, 0 on failure and 1 on success.
2273
int vo_xv_enable_vsync()
2275
Atom xv_atom = xv_intern_atom_if_exists("XV_SYNC_TO_VBLANK");
2276
if (xv_atom == None)
2278
return XvSetPortAttribute(mDisplay, xv_port, xv_atom, 1) == Success;
2282
* \brief Get maximum supported source image dimensions.
2284
* This function does not set the variables pointed to by
2285
* width and height if the information could not be retreived.
2286
* So the caller is reponsible for initing them properly.
2288
* \param width [out] The maximum width gets stored here.
2289
* \param height [out] The maximum height gets stored here.
2292
void vo_xv_get_max_img_dim( uint32_t * width, uint32_t * height )
2294
XvEncodingInfo * encodings;
2295
//unsigned long num_encodings, idx; to int or too long?!
2296
unsigned int num_encodings, idx;
2298
XvQueryEncodings( mDisplay, xv_port, &num_encodings, &encodings);
2302
for ( idx = 0; idx < num_encodings; ++idx )
2304
if ( strcmp( encodings[idx].name, "XV_IMAGE" ) == 0 )
2306
*width = encodings[idx].width;
2307
*height = encodings[idx].height;
2313
mp_msg( MSGT_VO, MSGL_V,
2314
"[xv common] Maximum source image dimensions: %ux%u\n",
2317
XvFreeEncodingInfo( encodings );
2321
* \brief Print information about the colorkey method and source.
2323
* \param ck_handling Integer value containing the information about
2324
* colorkey handling (see x11_common.h).
2326
* Outputs the content of |ck_handling| as a readable message.
2329
void vo_xv_print_ck_info()
2331
mp_msg( MSGT_VO, MSGL_V, "[xv common] " );
2333
switch ( xv_ck_info.method )
2335
case CK_METHOD_NONE:
2336
mp_msg( MSGT_VO, MSGL_V, "Drawing no colorkey.\n" ); return;
2337
case CK_METHOD_AUTOPAINT:
2338
mp_msg( MSGT_VO, MSGL_V, "Colorkey is drawn by Xv." ); break;
2339
case CK_METHOD_MANUALFILL:
2340
mp_msg( MSGT_VO, MSGL_V, "Drawing colorkey manually." ); break;
2341
case CK_METHOD_BACKGROUND:
2342
mp_msg( MSGT_VO, MSGL_V, "Colorkey is drawn as window background." ); break;
2345
mp_msg( MSGT_VO, MSGL_V, "\n[xv common] " );
2347
switch ( xv_ck_info.source )
2350
mp_msg( MSGT_VO, MSGL_V, "Using colorkey from Xv (0x%06lx).\n",
2354
if ( xv_ck_info.method == CK_METHOD_AUTOPAINT )
2356
mp_msg( MSGT_VO, MSGL_V,
2357
"Ignoring colorkey from MPlayer (0x%06lx).\n",
2362
mp_msg( MSGT_VO, MSGL_V,
2363
"Using colorkey from MPlayer (0x%06lx)."
2364
" Use -colorkey to change.\n",
2369
mp_msg( MSGT_VO, MSGL_V,
2370
"Setting and using colorkey from MPlayer (0x%06lx)."
2371
" Use -colorkey to change.\n",
2377
* \brief Init colorkey depending on the settings in xv_ck_info.
2379
* \return Returns 0 on failure and 1 on success.
2381
* Sets the colorkey variable according to the CK_SRC_* and CK_METHOD_*
2382
* flags in xv_ck_info.
2386
* - manual colorkey drawing ( CK_METHOD_MANUALFILL )
2387
* - set colorkey as window background ( CK_METHOD_BACKGROUND )
2388
* - let Xv paint the colorkey ( CK_METHOD_AUTOPAINT )
2390
* - use currently set colorkey ( CK_SRC_CUR )
2391
* - use colorkey in vo_colorkey ( CK_SRC_USE )
2392
* - use and set colorkey in vo_colorkey ( CK_SRC_SET )
2394
* NOTE: If vo_colorkey has bits set after the first 3 low order bytes
2395
* we don't draw anything as this means it was forced to off.
2397
int vo_xv_init_colorkey()
2402
/* check if colorkeying is needed */
2403
xv_atom = xv_intern_atom_if_exists( "XV_COLORKEY" );
2405
/* if we have to deal with colorkeying ... */
2406
if( xv_atom != None && !(vo_colorkey & 0xFF000000) )
2408
/* check if we should use the colorkey specified in vo_colorkey */
2409
if ( xv_ck_info.source != CK_SRC_CUR )
2411
xv_colorkey = vo_colorkey;
2413
/* check if we have to set the colorkey too */
2414
if ( xv_ck_info.source == CK_SRC_SET )
2416
xv_atom = XInternAtom(mDisplay, "XV_COLORKEY",False);
2418
rez = XvSetPortAttribute( mDisplay, xv_port, xv_atom, vo_colorkey );
2419
if ( rez != Success )
2421
mp_msg( MSGT_VO, MSGL_FATAL,
2422
"[xv common] Couldn't set colorkey!\n" );
2423
return 0; // error setting colorkey
2431
rez=XvGetPortAttribute(mDisplay,xv_port, xv_atom, &colorkey_ret);
2432
if ( rez == Success )
2434
xv_colorkey = colorkey_ret;
2438
mp_msg( MSGT_VO, MSGL_FATAL,
2439
"[xv common] Couldn't get colorkey!"
2440
"Maybe the selected Xv port has no overlay.\n" );
2441
return 0; // error getting colorkey
2445
xv_atom = xv_intern_atom_if_exists( "XV_AUTOPAINT_COLORKEY" );
2447
/* should we draw the colorkey ourselves or activate autopainting? */
2448
if ( xv_ck_info.method == CK_METHOD_AUTOPAINT )
2450
rez = !Success; // reset rez to something different than Success
2452
if ( xv_atom != None ) // autopaint is supported
2454
rez = XvSetPortAttribute( mDisplay, xv_port, xv_atom, 1 );
2457
if ( rez != Success )
2459
// fallback to manual colorkey drawing
2460
xv_ck_info.method = CK_METHOD_MANUALFILL;
2463
else // disable colorkey autopainting if supported
2465
if ( xv_atom != None ) // we have autopaint attribute
2467
XvSetPortAttribute( mDisplay, xv_port, xv_atom, 0 );
2471
else // do no colorkey drawing at all
2473
xv_ck_info.method = CK_METHOD_NONE;
2474
} /* end: should we draw colorkey */
2476
/* output information about the curren colorkey settings */
2477
vo_xv_print_ck_info();
2479
return 1; // success
2483
* \brief Draw the colorkey on the video window.
2485
* Draws the colorkey depending on the set method ( colorkey_handling ).
2487
* It also draws the black bars ( when the video doesn't fit to the
2488
* display in full screen ) seperately, so they don't overlap with the
2490
* It doesn't call XFlush
2493
inline void vo_xv_draw_colorkey( int32_t x, int32_t y,
2494
int32_t w, int32_t h )
2496
if( xv_ck_info.method == CK_METHOD_MANUALFILL ||
2497
xv_ck_info.method == CK_METHOD_BACKGROUND )//less tearing than XClearWindow()
2499
XSetForeground( mDisplay, vo_gc, xv_colorkey );
2500
XFillRectangle( mDisplay, vo_window, vo_gc,
2505
/* draw black bars if needed */
2506
/* TODO! move this to vo_x11_clearwindow_part() */
2509
XSetForeground( mDisplay, vo_gc, 0 );
2510
/* making non overlap fills, requiare 8 checks instead of 4*/
2512
XFillRectangle( mDisplay, vo_window, vo_gc,
2516
XFillRectangle( mDisplay, vo_window, vo_gc,
2518
x, vo_screenheight);
2519
if (x + w < vo_screenwidth)
2520
XFillRectangle( mDisplay, vo_window, vo_gc,
2522
vo_screenwidth, vo_screenheight);
2523
if (y + h < vo_screenheight)
2524
XFillRectangle( mDisplay, vo_window, vo_gc,
2526
vo_screenwidth, vo_screenheight);
2530
/** \brief tests if a valid arg for the ck suboption was given */
2531
int xv_test_ck( void * arg )
2533
strarg_t * strarg = (strarg_t *)arg;
2535
if ( strargcmp( strarg, "use" ) == 0 ||
2536
strargcmp( strarg, "set" ) == 0 ||
2537
strargcmp( strarg, "cur" ) == 0 )
2544
/** \brief tests if a valid arg for the ck-method suboption was given */
2545
int xv_test_ckm( void * arg )
2547
strarg_t * strarg = (strarg_t *)arg;
2549
if ( strargcmp( strarg, "bg" ) == 0 ||
2550
strargcmp( strarg, "man" ) == 0 ||
2551
strargcmp( strarg, "auto" ) == 0 )
2560
* \brief Modify the colorkey_handling var according to str
2562
* Checks if a valid pointer ( not NULL ) to the string
2563
* was given. And in that case modifies the colorkey_handling
2564
* var to reflect the requested behaviour.
2565
* If nothing happens the content of colorkey_handling stays
2568
* \param str Pointer to the string or NULL
2571
void xv_setup_colorkeyhandling( char const * ck_method_str,
2572
char const * ck_str )
2574
/* check if a valid pointer to the string was passed */
2577
if ( strncmp( ck_str, "use", 3 ) == 0 )
2579
xv_ck_info.source = CK_SRC_USE;
2581
else if ( strncmp( ck_str, "set", 3 ) == 0 )
2583
xv_ck_info.source = CK_SRC_SET;
2586
/* check if a valid pointer to the string was passed */
2587
if ( ck_method_str )
2589
if ( strncmp( ck_method_str, "bg", 2 ) == 0 )
2591
xv_ck_info.method = CK_METHOD_BACKGROUND;
2593
else if ( strncmp( ck_method_str, "man", 3 ) == 0 )
2595
xv_ck_info.method = CK_METHOD_MANUALFILL;
2597
else if ( strncmp( ck_method_str, "auto", 4 ) == 0 )
2599
xv_ck_info.method = CK_METHOD_AUTOPAINT;