10l initial patch by Oded Shimon <ods15 at ods15.dyndns.org>
[mplayer/greg.git] / libvo / x11_common.c
blob4d2f4f445bddf0b315404f524981df0c49a11b3b
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <math.h>
5 #include <inttypes.h>
7 #include "config.h"
8 #include "mp_msg.h"
9 #include "x11_common.h"
11 #ifdef X11_FULLSCREEN
13 #include <string.h>
14 #include <unistd.h>
15 #include <sys/mman.h>
16 #include <signal.h>
17 #include <assert.h>
19 #include "video_out.h"
20 #include "aspect.h"
21 #include "geometry.h"
22 #include "help_mp.h"
23 #include "osdep/timer.h"
25 #include <X11/Xmd.h>
26 #include <X11/Xlib.h>
27 #include <X11/Xutil.h>
28 #include <X11/Xatom.h>
30 #ifdef HAVE_XDPMS
31 #include <X11/extensions/dpms.h>
32 #endif
34 #ifdef HAVE_XINERAMA
35 #include <X11/extensions/Xinerama.h>
36 #endif
38 #ifdef HAVE_XF86VM
39 #include <X11/extensions/xf86vmode.h>
40 #include <X11/XF86keysym.h>
41 #endif
43 #ifdef HAVE_XV
44 #include <X11/extensions/Xv.h>
45 #include <X11/extensions/Xvlib.h>
46 #endif
48 #include "input/input.h"
49 #include "input/mouse.h"
51 #ifdef HAVE_NEW_GUI
52 #include "Gui/interface.h"
53 #include "mplayer.h"
54 #endif
56 #define WIN_LAYER_ONBOTTOM 2
57 #define WIN_LAYER_NORMAL 4
58 #define WIN_LAYER_ONTOP 6
59 #define WIN_LAYER_ABOVE_DOCK 10
61 int fs_layer = WIN_LAYER_ABOVE_DOCK;
62 static int orig_layer = 0;
63 static int old_gravity = NorthWestGravity;
65 int stop_xscreensaver = 0;
67 static int dpms_disabled = 0;
68 static int timeout_save = 0;
69 static int kdescreensaver_was_running = 0;
71 char *mDisplayName = NULL;
72 Display *mDisplay = NULL;
73 Window mRootWin;
74 int mScreen;
75 int mLocalDisplay;
77 /* output window id */
78 int WinID = -1;
79 int vo_mouse_autohide = 0;
80 int vo_wm_type = 0;
81 int vo_fs_type = 0; // needs to be accessible for GUI X11 code
82 static int vo_fs_flip = 0;
83 char **vo_fstype_list;
85 /* if equal to 1 means that WM is a metacity (broken as hell) */
86 int metacity_hack = 0;
88 static Atom XA_NET_SUPPORTED;
89 static Atom XA_NET_WM_STATE;
90 static Atom XA_NET_WM_STATE_FULLSCREEN;
91 static Atom XA_NET_WM_STATE_ABOVE;
92 static Atom XA_NET_WM_STATE_STAYS_ON_TOP;
93 static Atom XA_NET_WM_STATE_BELOW;
94 static Atom XA_NET_WM_PID;
95 static Atom XA_WIN_PROTOCOLS;
96 static Atom XA_WIN_LAYER;
97 static Atom XA_WIN_HINTS;
98 static Atom XA_BLACKBOX_PID;
100 #define XA_INIT(x) XA##x = XInternAtom(mDisplay, #x, False)
102 static int vo_old_x = 0;
103 static int vo_old_y = 0;
104 static int vo_old_width = 0;
105 static int vo_old_height = 0;
107 #ifdef HAVE_XINERAMA
108 int xinerama_screen = 0;
109 int xinerama_x = 0;
110 int xinerama_y = 0;
111 #endif
112 #ifdef HAVE_XF86VM
113 XF86VidModeModeInfo **vidmodes = NULL;
114 XF86VidModeModeLine modeline;
115 #endif
117 static int vo_x11_get_fs_type(int supported);
121 * Sends the EWMH fullscreen state event.
123 * action: could be on of _NET_WM_STATE_REMOVE -- remove state
124 * _NET_WM_STATE_ADD -- add state
125 * _NET_WM_STATE_TOGGLE -- toggle
127 void vo_x11_ewmh_fullscreen(int action)
129 assert(action == _NET_WM_STATE_REMOVE ||
130 action == _NET_WM_STATE_ADD || action == _NET_WM_STATE_TOGGLE);
132 if (vo_fs_type & vo_wm_FULLSCREEN)
134 XEvent xev;
136 /* init X event structure for _NET_WM_FULLSCREEN client msg */
137 xev.xclient.type = ClientMessage;
138 xev.xclient.serial = 0;
139 xev.xclient.send_event = True;
140 xev.xclient.message_type = XInternAtom(mDisplay,
141 "_NET_WM_STATE", False);
142 xev.xclient.window = vo_window;
143 xev.xclient.format = 32;
144 xev.xclient.data.l[0] = action;
145 xev.xclient.data.l[1] = XInternAtom(mDisplay,
146 "_NET_WM_STATE_FULLSCREEN",
147 False);
148 xev.xclient.data.l[2] = 0;
149 xev.xclient.data.l[3] = 0;
150 xev.xclient.data.l[4] = 0;
152 /* finally send that damn thing */
153 if (!XSendEvent(mDisplay, DefaultRootWindow(mDisplay), False,
154 SubstructureRedirectMask | SubstructureNotifyMask,
155 &xev))
157 mp_msg(MSGT_VO, MSGL_ERR, MSGTR_EwmhFullscreenStateFailed);
162 void vo_hidecursor(Display * disp, Window win)
164 Cursor no_ptr;
165 Pixmap bm_no;
166 XColor black, dummy;
167 Colormap colormap;
168 static char bm_no_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
170 if (WinID == 0)
171 return; // do not hide, if we're playing at rootwin
173 colormap = DefaultColormap(disp, DefaultScreen(disp));
174 XAllocNamedColor(disp, colormap, "black", &black, &dummy);
175 bm_no = XCreateBitmapFromData(disp, win, bm_no_data, 8, 8);
176 no_ptr = XCreatePixmapCursor(disp, bm_no, bm_no, &black, &black, 0, 0);
177 XDefineCursor(disp, win, no_ptr);
178 XFreeCursor(disp, no_ptr);
179 if (bm_no != None)
180 XFreePixmap(disp, bm_no);
181 XFreeColors(disp,colormap,&black.pixel,1,0);
184 void vo_showcursor(Display * disp, Window win)
186 if (WinID == 0)
187 return;
188 XDefineCursor(disp, win, 0);
191 static int x11_errorhandler(Display * display, XErrorEvent * event)
193 #define MSGLEN 60
194 char msg[MSGLEN];
196 XGetErrorText(display, event->error_code, (char *) &msg, MSGLEN);
198 mp_msg(MSGT_VO, MSGL_ERR, "X11 error: %s\n", msg);
200 mp_msg(MSGT_VO, MSGL_V,
201 "Type: %x, display: %x, resourceid: %x, serial: %x\n",
202 event->type, event->display, event->resourceid, event->serial);
203 mp_msg(MSGT_VO, MSGL_V,
204 "Error code: %x, request code: %x, minor code: %x\n",
205 event->error_code, event->request_code, event->minor_code);
207 abort();
208 //exit_player("X11 error");
209 #undef MSGLEN
212 void fstype_help(void)
214 mp_msg(MSGT_VO, MSGL_INFO, MSGTR_AvailableFsType);
216 mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "none",
217 "don't set fullscreen window layer");
218 mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "layer",
219 "use _WIN_LAYER hint with default layer");
220 mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "layer=<0..15>",
221 "use _WIN_LAYER hint with a given layer number");
222 mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "netwm",
223 "force NETWM style");
224 mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "above",
225 "use _NETWM_STATE_ABOVE hint if available");
226 mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "below",
227 "use _NETWM_STATE_BELOW hint if available");
228 mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "fullscreen",
229 "use _NETWM_STATE_FULLSCREEN hint if availale");
230 mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "stays_on_top",
231 "use _NETWM_STATE_STAYS_ON_TOP hint if available");
232 mp_msg(MSGT_VO, MSGL_INFO,
233 "You can also negate the settings with simply putting '-' in the beginning");
234 mp_msg(MSGT_VO, MSGL_INFO, "\n\n");
237 static void fstype_dump(int fstype)
239 if (fstype)
241 mp_msg(MSGT_VO, MSGL_V, "[x11] Current fstype setting honours");
242 if (fstype & vo_wm_LAYER)
243 mp_msg(MSGT_VO, MSGL_V, " LAYER");
244 if (fstype & vo_wm_FULLSCREEN)
245 mp_msg(MSGT_VO, MSGL_V, " FULLSCREEN");
246 if (fstype & vo_wm_STAYS_ON_TOP)
247 mp_msg(MSGT_VO, MSGL_V, " STAYS_ON_TOP");
248 if (fstype & vo_wm_ABOVE)
249 mp_msg(MSGT_VO, MSGL_V, " ABOVE");
250 if (fstype & vo_wm_BELOW)
251 mp_msg(MSGT_VO, MSGL_V, " BELOW");
252 mp_msg(MSGT_VO, MSGL_V, " X atoms\n");
253 } else
254 mp_msg(MSGT_VO, MSGL_V,
255 "[x11] Current fstype setting doesn't honour any X atoms\n");
258 static int net_wm_support_state_test(Atom atom)
260 #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; } }
262 NET_WM_STATE_TEST(FULLSCREEN);
263 NET_WM_STATE_TEST(ABOVE);
264 NET_WM_STATE_TEST(STAYS_ON_TOP);
265 NET_WM_STATE_TEST(BELOW);
266 return 0;
269 static int x11_get_property(Atom type, Atom ** args, unsigned long *nitems)
271 int format;
272 unsigned long bytesafter;
274 return (Success ==
275 XGetWindowProperty(mDisplay, mRootWin, type, 0, 16384, False,
276 AnyPropertyType, &type, &format, nitems,
277 &bytesafter, (unsigned char **) args)
278 && *nitems > 0);
281 static int vo_wm_detect(void)
283 int i;
284 int wm = 0;
285 unsigned long nitems;
286 Atom *args = NULL;
288 if (WinID >= 0)
289 return 0;
291 // -- supports layers
292 if (x11_get_property(XA_WIN_PROTOCOLS, &args, &nitems))
294 mp_msg(MSGT_VO, MSGL_V, "[x11] Detected wm supports layers.\n");
295 for (i = 0; i < nitems; i++)
297 if (args[i] == XA_WIN_LAYER)
299 wm |= vo_wm_LAYER;
300 metacity_hack |= 1;
301 } else
302 // metacity is the only manager I know which reports support only for _WIN_LAYER
303 // hint in _WIN_PROTOCOLS (what's more support for it is broken)
304 metacity_hack |= 2;
306 XFree(args);
307 if (wm && (metacity_hack == 1))
309 // metacity reports that it supports layers, but it is not really truth :-)
310 wm ^= vo_wm_LAYER;
311 mp_msg(MSGT_VO, MSGL_V,
312 "[x11] Using workaround for Metacity bugs.\n");
315 // --- netwm
316 if (x11_get_property(XA_NET_SUPPORTED, &args, &nitems))
318 mp_msg(MSGT_VO, MSGL_V, "[x11] Detected wm supports NetWM.\n");
319 for (i = 0; i < nitems; i++)
320 wm |= net_wm_support_state_test(args[i]);
321 XFree(args);
322 #if 0
323 // ugly hack for broken OpenBox _NET_WM_STATE_FULLSCREEN support
324 // (in their implementation it only changes internal state of window, nothing more!!!)
325 if (wm & vo_wm_FULLSCREEN)
327 if (x11_get_property(XA_BLACKBOX_PID, &args, &nitems))
329 mp_msg(MSGT_VO, MSGL_V,
330 "[x11] Detected wm is a broken OpenBox.\n");
331 wm ^= vo_wm_FULLSCREEN;
333 XFree(args);
335 #endif
338 if (wm == 0)
339 mp_msg(MSGT_VO, MSGL_V, "[x11] Unknown wm type...\n");
340 return wm;
343 static void init_atoms(void)
345 XA_INIT(_NET_SUPPORTED);
346 XA_INIT(_NET_WM_STATE);
347 XA_INIT(_NET_WM_STATE_FULLSCREEN);
348 XA_INIT(_NET_WM_STATE_ABOVE);
349 XA_INIT(_NET_WM_STATE_STAYS_ON_TOP);
350 XA_INIT(_NET_WM_STATE_BELOW);
351 XA_INIT(_NET_WM_PID);
352 XA_INIT(_WIN_PROTOCOLS);
353 XA_INIT(_WIN_LAYER);
354 XA_INIT(_WIN_HINTS);
355 XA_INIT(_BLACKBOX_PID);
358 int vo_init(void)
360 // int mScreen;
361 int depth, bpp;
362 unsigned int mask;
364 // char * DisplayName = ":0.0";
365 // Display * mDisplay;
366 XImage *mXImage = NULL;
368 // Window mRootWin;
369 XWindowAttributes attribs;
370 char *dispName;
372 if (vo_rootwin)
373 WinID = 0; // use root win
375 if (vo_depthonscreen)
377 saver_off(mDisplay);
378 return 1; // already called
381 XSetErrorHandler(x11_errorhandler);
383 #if 0
384 if (!mDisplayName)
385 if (!(mDisplayName = getenv("DISPLAY")))
386 mDisplayName = strdup(":0.0");
387 #else
388 dispName = XDisplayName(mDisplayName);
389 #endif
391 mp_msg(MSGT_VO, MSGL_V, "X11 opening display: %s\n", dispName);
393 mDisplay = XOpenDisplay(dispName);
394 if (!mDisplay)
396 mp_msg(MSGT_VO, MSGL_ERR,
397 "vo: couldn't open the X11 display (%s)!\n", dispName);
398 return 0;
400 mScreen = DefaultScreen(mDisplay); // Screen ID.
401 mRootWin = RootWindow(mDisplay, mScreen); // Root window ID.
403 init_atoms();
405 #ifdef HAVE_XINERAMA
406 if (XineramaIsActive(mDisplay))
408 XineramaScreenInfo *screens;
409 int num_screens;
411 screens = XineramaQueryScreens(mDisplay, &num_screens);
412 if (xinerama_screen >= num_screens)
413 xinerama_screen = 0;
414 if (!vo_screenwidth)
415 vo_screenwidth = screens[xinerama_screen].width;
416 if (!vo_screenheight)
417 vo_screenheight = screens[xinerama_screen].height;
418 xinerama_x = screens[xinerama_screen].x_org;
419 xinerama_y = screens[xinerama_screen].y_org;
421 XFree(screens);
422 } else
423 #endif
424 #ifdef HAVE_XF86VM
426 int clock;
428 XF86VidModeGetModeLine(mDisplay, mScreen, &clock, &modeline);
429 if (!vo_screenwidth)
430 vo_screenwidth = modeline.hdisplay;
431 if (!vo_screenheight)
432 vo_screenheight = modeline.vdisplay;
434 #endif
436 if (!vo_screenwidth)
437 vo_screenwidth = DisplayWidth(mDisplay, mScreen);
438 if (!vo_screenheight)
439 vo_screenheight = DisplayHeight(mDisplay, mScreen);
441 // get color depth (from root window, or the best visual):
442 XGetWindowAttributes(mDisplay, mRootWin, &attribs);
443 depth = attribs.depth;
445 if (depth != 15 && depth != 16 && depth != 24 && depth != 32)
447 Visual *visual;
449 depth = vo_find_depth_from_visuals(mDisplay, mScreen, &visual);
450 if (depth != -1)
451 mXImage = XCreateImage(mDisplay, visual, depth, ZPixmap,
452 0, NULL, 1, 1, 8, 1);
453 } else
454 mXImage =
455 XGetImage(mDisplay, mRootWin, 0, 0, 1, 1, AllPlanes, ZPixmap);
457 vo_depthonscreen = depth; // display depth on screen
459 // get bits/pixel from XImage structure:
460 if (mXImage == NULL)
462 mask = 0;
463 } else
466 * for the depth==24 case, the XImage structures might use
467 * 24 or 32 bits of data per pixel. The global variable
468 * vo_depthonscreen stores the amount of data per pixel in the
469 * XImage structure!
471 * Maybe we should rename vo_depthonscreen to (or add) vo_bpp?
473 bpp = mXImage->bits_per_pixel;
474 if ((vo_depthonscreen + 7) / 8 != (bpp + 7) / 8)
475 vo_depthonscreen = bpp; // by A'rpi
476 mask =
477 mXImage->red_mask | mXImage->green_mask | mXImage->blue_mask;
478 mp_msg(MSGT_VO, MSGL_V,
479 "vo: X11 color mask: %X (R:%lX G:%lX B:%lX)\n", mask,
480 mXImage->red_mask, mXImage->green_mask, mXImage->blue_mask);
481 XDestroyImage(mXImage);
483 if (((vo_depthonscreen + 7) / 8) == 2)
485 if (mask == 0x7FFF)
486 vo_depthonscreen = 15;
487 else if (mask == 0xFFFF)
488 vo_depthonscreen = 16;
490 // XCloseDisplay( mDisplay );
491 /* slightly improved local display detection AST */
492 if (strncmp(dispName, "unix:", 5) == 0)
493 dispName += 4;
494 else if (strncmp(dispName, "localhost:", 10) == 0)
495 dispName += 9;
496 if (*dispName == ':' && atoi(dispName + 1) < 10)
497 mLocalDisplay = 1;
498 else
499 mLocalDisplay = 0;
500 mp_msg(MSGT_VO, MSGL_INFO,
501 "vo: X11 running at %dx%d with depth %d and %d bpp (\"%s\" => %s display)\n",
502 vo_screenwidth, vo_screenheight, depth, vo_depthonscreen,
503 dispName, mLocalDisplay ? "local" : "remote");
505 vo_wm_type = vo_wm_detect();
507 vo_fs_type = vo_x11_get_fs_type(vo_wm_type);
509 fstype_dump(vo_fs_type);
511 saver_off(mDisplay);
512 return 1;
515 void vo_uninit(void)
517 if (!mDisplay)
519 mp_msg(MSGT_VO, MSGL_V,
520 "vo: x11 uninit called but X11 not inited..\n");
521 return;
523 // if( !vo_depthonscreen ) return;
524 mp_msg(MSGT_VO, MSGL_V, "vo: uninit ...\n");
525 XSetErrorHandler(NULL);
526 XCloseDisplay(mDisplay);
527 vo_depthonscreen = 0;
528 mDisplay = NULL;
531 #include "osdep/keycodes.h"
532 #include "wskeys.h"
534 extern void mplayer_put_key(int code);
536 #ifdef XF86XK_AudioPause
537 void vo_x11_putkey_ext(int keysym)
539 switch (keysym)
541 case XF86XK_AudioPause:
542 mplayer_put_key(KEY_XF86_PAUSE);
543 break;
544 case XF86XK_AudioStop:
545 mplayer_put_key(KEY_XF86_STOP);
546 break;
547 case XF86XK_AudioPrev:
548 mplayer_put_key(KEY_XF86_PREV);
549 break;
550 case XF86XK_AudioNext:
551 mplayer_put_key(KEY_XF86_NEXT);
552 break;
553 default:
554 break;
557 #endif
559 void vo_x11_putkey(int key)
561 switch (key)
563 case wsLeft:
564 mplayer_put_key(KEY_LEFT);
565 break;
566 case wsRight:
567 mplayer_put_key(KEY_RIGHT);
568 break;
569 case wsUp:
570 mplayer_put_key(KEY_UP);
571 break;
572 case wsDown:
573 mplayer_put_key(KEY_DOWN);
574 break;
575 case wsSpace:
576 mplayer_put_key(' ');
577 break;
578 case wsEscape:
579 mplayer_put_key(KEY_ESC);
580 break;
581 case wsEnter:
582 mplayer_put_key(KEY_ENTER);
583 break;
584 case wsBackSpace:
585 mplayer_put_key(KEY_BS);
586 break;
587 case wsDelete:
588 mplayer_put_key(KEY_DELETE);
589 break;
590 case wsInsert:
591 mplayer_put_key(KEY_INSERT);
592 break;
593 case wsHome:
594 mplayer_put_key(KEY_HOME);
595 break;
596 case wsEnd:
597 mplayer_put_key(KEY_END);
598 break;
599 case wsPageUp:
600 mplayer_put_key(KEY_PAGE_UP);
601 break;
602 case wsPageDown:
603 mplayer_put_key(KEY_PAGE_DOWN);
604 break;
605 case wsF1:
606 mplayer_put_key(KEY_F + 1);
607 break;
608 case wsF2:
609 mplayer_put_key(KEY_F + 2);
610 break;
611 case wsF3:
612 mplayer_put_key(KEY_F + 3);
613 break;
614 case wsF4:
615 mplayer_put_key(KEY_F + 4);
616 break;
617 case wsF5:
618 mplayer_put_key(KEY_F + 5);
619 break;
620 case wsF6:
621 mplayer_put_key(KEY_F + 6);
622 break;
623 case wsF7:
624 mplayer_put_key(KEY_F + 7);
625 break;
626 case wsF8:
627 mplayer_put_key(KEY_F + 8);
628 break;
629 case wsF9:
630 mplayer_put_key(KEY_F + 9);
631 break;
632 case wsF10:
633 mplayer_put_key(KEY_F + 10);
634 break;
635 case wsF11:
636 mplayer_put_key(KEY_F + 11);
637 break;
638 case wsF12:
639 mplayer_put_key(KEY_F + 12);
640 break;
641 case wsq:
642 case wsQ:
643 mplayer_put_key('q');
644 break;
645 case wsp:
646 case wsP:
647 mplayer_put_key('p');
648 break;
649 case wsMinus:
650 case wsGrayMinus:
651 mplayer_put_key('-');
652 break;
653 case wsPlus:
654 case wsGrayPlus:
655 mplayer_put_key('+');
656 break;
657 case wsGrayMul:
658 case wsMul:
659 mplayer_put_key('*');
660 break;
661 case wsGrayDiv:
662 case wsDiv:
663 mplayer_put_key('/');
664 break;
665 case wsLess:
666 mplayer_put_key('<');
667 break;
668 case wsMore:
669 mplayer_put_key('>');
670 break;
671 case wsGray0:
672 mplayer_put_key(KEY_KP0);
673 break;
674 case wsGrayEnd:
675 case wsGray1:
676 mplayer_put_key(KEY_KP1);
677 break;
678 case wsGrayDown:
679 case wsGray2:
680 mplayer_put_key(KEY_KP2);
681 break;
682 case wsGrayPgDn:
683 case wsGray3:
684 mplayer_put_key(KEY_KP3);
685 break;
686 case wsGrayLeft:
687 case wsGray4:
688 mplayer_put_key(KEY_KP4);
689 break;
690 case wsGray5Dup:
691 case wsGray5:
692 mplayer_put_key(KEY_KP5);
693 break;
694 case wsGrayRight:
695 case wsGray6:
696 mplayer_put_key(KEY_KP6);
697 break;
698 case wsGrayHome:
699 case wsGray7:
700 mplayer_put_key(KEY_KP7);
701 break;
702 case wsGrayUp:
703 case wsGray8:
704 mplayer_put_key(KEY_KP8);
705 break;
706 case wsGrayPgUp:
707 case wsGray9:
708 mplayer_put_key(KEY_KP9);
709 break;
710 case wsGrayDecimal:
711 mplayer_put_key(KEY_KPDEC);
712 break;
713 case wsGrayInsert:
714 mplayer_put_key(KEY_KPINS);
715 break;
716 case wsGrayDelete:
717 mplayer_put_key(KEY_KPDEL);
718 break;
719 case wsGrayEnter:
720 mplayer_put_key(KEY_KPENTER);
721 break;
722 case wsm:
723 case wsM:
724 mplayer_put_key('m');
725 break;
726 case wso:
727 case wsO:
728 mplayer_put_key('o');
729 break;
731 case wsGrave:
732 mplayer_put_key('`');
733 break;
734 case wsTilde:
735 mplayer_put_key('~');
736 break;
737 case wsExclSign:
738 mplayer_put_key('!');
739 break;
740 case wsAt:
741 mplayer_put_key('@');
742 break;
743 case wsHash:
744 mplayer_put_key('#');
745 break;
746 case wsDollar:
747 mplayer_put_key('$');
748 break;
749 case wsPercent:
750 mplayer_put_key('%');
751 break;
752 case wsCircumflex:
753 mplayer_put_key('^');
754 break;
755 case wsAmpersand:
756 mplayer_put_key('&');
757 break;
758 case wsobracket:
759 mplayer_put_key('(');
760 break;
761 case wscbracket:
762 mplayer_put_key(')');
763 break;
764 case wsUnder:
765 mplayer_put_key('_');
766 break;
767 case wsocbracket:
768 mplayer_put_key('{');
769 break;
770 case wsccbracket:
771 mplayer_put_key('}');
772 break;
773 case wsColon:
774 mplayer_put_key(':');
775 break;
776 case wsSemicolon:
777 mplayer_put_key(';');
778 break;
779 case wsDblQuote:
780 mplayer_put_key('\"');
781 break;
782 case wsAcute:
783 mplayer_put_key('\'');
784 break;
785 case wsComma:
786 mplayer_put_key(',');
787 break;
788 case wsPoint:
789 mplayer_put_key('.');
790 break;
791 case wsQuestSign:
792 mplayer_put_key('?');
793 break;
794 case wsBSlash:
795 mplayer_put_key('\\');
796 break;
797 case wsPipe:
798 mplayer_put_key('|');
799 break;
800 case wsEqual:
801 mplayer_put_key('=');
802 break;
803 case wsosbrackets:
804 mplayer_put_key('[');
805 break;
806 case wscsbrackets:
807 mplayer_put_key(']');
808 break;
811 default:
812 if ((key >= 'a' && key <= 'z') || (key >= 'A' && key <= 'Z') ||
813 (key >= '0' && key <= '9'))
814 mplayer_put_key(key);
820 // ----- Motif header: -------
822 #define MWM_HINTS_FUNCTIONS (1L << 0)
823 #define MWM_HINTS_DECORATIONS (1L << 1)
824 #define MWM_HINTS_INPUT_MODE (1L << 2)
825 #define MWM_HINTS_STATUS (1L << 3)
827 #define MWM_FUNC_ALL (1L << 0)
828 #define MWM_FUNC_RESIZE (1L << 1)
829 #define MWM_FUNC_MOVE (1L << 2)
830 #define MWM_FUNC_MINIMIZE (1L << 3)
831 #define MWM_FUNC_MAXIMIZE (1L << 4)
832 #define MWM_FUNC_CLOSE (1L << 5)
834 #define MWM_DECOR_ALL (1L << 0)
835 #define MWM_DECOR_BORDER (1L << 1)
836 #define MWM_DECOR_RESIZEH (1L << 2)
837 #define MWM_DECOR_TITLE (1L << 3)
838 #define MWM_DECOR_MENU (1L << 4)
839 #define MWM_DECOR_MINIMIZE (1L << 5)
840 #define MWM_DECOR_MAXIMIZE (1L << 6)
842 #define MWM_INPUT_MODELESS 0
843 #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1
844 #define MWM_INPUT_SYSTEM_MODAL 2
845 #define MWM_INPUT_FULL_APPLICATION_MODAL 3
846 #define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL
848 #define MWM_TEAROFF_WINDOW (1L<<0)
850 typedef struct
852 long flags;
853 long functions;
854 long decorations;
855 long input_mode;
856 long state;
857 } MotifWmHints;
859 extern int vo_depthonscreen;
860 extern int vo_screenwidth;
861 extern int vo_screenheight;
863 static MotifWmHints vo_MotifWmHints;
864 static Atom vo_MotifHints = None;
866 void vo_x11_decoration(Display * vo_Display, Window w, int d)
868 static unsigned int olddecor = MWM_DECOR_ALL;
869 static unsigned int oldfuncs =
870 MWM_FUNC_MOVE | MWM_FUNC_CLOSE | MWM_FUNC_MINIMIZE |
871 MWM_FUNC_MAXIMIZE | MWM_FUNC_RESIZE;
872 Atom mtype;
873 int mformat;
874 unsigned long mn, mb;
876 if (!WinID)
877 return;
879 if (vo_fsmode & 8)
881 XSetTransientForHint(vo_Display, w,
882 RootWindow(vo_Display, mScreen));
885 vo_MotifHints = XInternAtom(vo_Display, "_MOTIF_WM_HINTS", 0);
886 if (vo_MotifHints != None)
888 if (!d)
890 MotifWmHints *mhints = NULL;
892 XGetWindowProperty(vo_Display, w, vo_MotifHints, 0, 20, False,
893 vo_MotifHints, &mtype, &mformat, &mn,
894 &mb, (unsigned char **) &mhints);
895 if (mhints)
897 if (mhints->flags & MWM_HINTS_DECORATIONS)
898 olddecor = mhints->decorations;
899 if (mhints->flags & MWM_HINTS_FUNCTIONS)
900 oldfuncs = mhints->functions;
901 XFree(mhints);
905 memset(&vo_MotifWmHints, 0, sizeof(MotifWmHints));
906 vo_MotifWmHints.flags =
907 MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
908 if (d)
910 vo_MotifWmHints.functions = oldfuncs;
911 d = olddecor;
913 #if 0
914 vo_MotifWmHints.decorations =
915 d | ((vo_fsmode & 2) ? 0 : MWM_DECOR_MENU);
916 #else
917 vo_MotifWmHints.decorations =
918 d | ((vo_fsmode & 2) ? MWM_DECOR_MENU : 0);
919 #endif
920 XChangeProperty(vo_Display, w, vo_MotifHints, vo_MotifHints, 32,
921 PropModeReplace,
922 (unsigned char *) &vo_MotifWmHints,
923 (vo_fsmode & 4) ? 4 : 5);
927 void vo_x11_classhint(Display * display, Window window, char *name)
929 XClassHint wmClass;
930 pid_t pid = getpid();
932 wmClass.res_name = name;
933 wmClass.res_class = "MPlayer";
934 XSetClassHint(display, window, &wmClass);
935 XChangeProperty(display, window, XA_NET_WM_PID, XA_CARDINAL, 32,
936 PropModeReplace, (unsigned char *) &pid, 1);
939 Window vo_window = None;
940 GC vo_gc = NULL;
941 GC f_gc = NULL;
942 XSizeHints vo_hint;
944 #ifdef HAVE_NEW_GUI
945 void vo_setwindow(Window w, GC g)
947 vo_window = w;
948 vo_gc = g;
950 #endif
952 void vo_x11_uninit()
954 saver_on(mDisplay);
955 if (vo_window != None)
956 vo_showcursor(mDisplay, vo_window);
958 if (f_gc)
960 XFreeGC(mDisplay, f_gc);
961 f_gc = NULL;
963 #ifdef HAVE_NEW_GUI
964 /* destroy window only if it's not controlled by GUI */
965 if (!use_gui)
966 #endif
968 if (vo_gc)
970 XSetBackground(mDisplay, vo_gc, 0);
971 XFreeGC(mDisplay, vo_gc);
972 vo_gc = NULL;
974 if (vo_window != None)
976 XClearWindow(mDisplay, vo_window);
977 if (WinID < 0)
979 XEvent xev;
981 XUnmapWindow(mDisplay, vo_window);
982 XDestroyWindow(mDisplay, vo_window);
985 XNextEvent(mDisplay, &xev);
987 while (xev.type != DestroyNotify
988 || xev.xdestroywindow.event != vo_window);
990 vo_window = None;
992 vo_fs = 0;
993 vo_old_width = vo_old_height = 0;
997 int vo_mouse_timer_const = 30;
998 static int vo_mouse_counter = 30;
1000 int vo_x11_check_events(Display * mydisplay)
1002 int ret = 0;
1003 XEvent Event;
1004 char buf[100];
1005 KeySym keySym;
1006 static XComposeStatus stat;
1008 // unsigned long vo_KeyTable[512];
1010 if ((vo_mouse_autohide) && (--vo_mouse_counter == 0))
1011 vo_hidecursor(mydisplay, vo_window);
1013 while (XPending(mydisplay))
1015 XNextEvent(mydisplay, &Event);
1016 #ifdef HAVE_NEW_GUI
1017 if (use_gui)
1019 guiGetEvent(0, (char *) &Event);
1020 if (vo_window != Event.xany.window)
1021 continue;
1023 #endif
1024 // printf("\rEvent.type=%X \n",Event.type);
1025 switch (Event.type)
1027 case Expose:
1028 ret |= VO_EVENT_EXPOSE;
1029 break;
1030 case ConfigureNotify:
1031 // if (!vo_fs && (Event.xconfigure.width == vo_screenwidth || Event.xconfigure.height == vo_screenheight)) break;
1032 // if (vo_fs && Event.xconfigure.width != vo_screenwidth && Event.xconfigure.height != vo_screenheight) break;
1033 if (vo_window == None)
1034 break;
1035 vo_dwidth = Event.xconfigure.width;
1036 vo_dheight = Event.xconfigure.height;
1037 #if 0
1038 /* when resizing, x and y are zero :( */
1039 vo_dx = Event.xconfigure.x;
1040 vo_dy = Event.xconfigure.y;
1041 #else
1043 Window root;
1044 int foo;
1045 Window win;
1047 XGetGeometry(mydisplay, vo_window, &root, &foo, &foo,
1048 &foo /*width */ , &foo /*height */ , &foo,
1049 &foo);
1050 XTranslateCoordinates(mydisplay, vo_window, root, 0, 0,
1051 &vo_dx, &vo_dy, &win);
1053 #endif
1054 ret |= VO_EVENT_RESIZE;
1055 break;
1056 case KeyPress:
1058 int key;
1060 #ifdef HAVE_NEW_GUI
1061 if ( use_gui ) { break; }
1062 #endif
1064 XLookupString(&Event.xkey, buf, sizeof(buf), &keySym,
1065 &stat);
1066 #ifdef XF86XK_AudioPause
1067 vo_x11_putkey_ext(keySym);
1068 #endif
1069 key =
1070 ((keySym & 0xff00) !=
1071 0 ? ((keySym & 0x00ff) + 256) : (keySym));
1072 vo_x11_putkey(key);
1073 ret |= VO_EVENT_KEYPRESS;
1075 break;
1076 case MotionNotify:
1077 if (vo_mouse_autohide)
1079 vo_showcursor(mydisplay, vo_window);
1080 vo_mouse_counter = vo_mouse_timer_const;
1082 break;
1083 case ButtonPress:
1084 if (vo_mouse_autohide)
1086 vo_showcursor(mydisplay, vo_window);
1087 vo_mouse_counter = vo_mouse_timer_const;
1089 // Ignore mouse whell press event
1090 if (Event.xbutton.button > 3)
1092 mplayer_put_key(MOUSE_BTN0 + Event.xbutton.button - 1);
1093 break;
1095 #ifdef HAVE_NEW_GUI
1096 // Ignor mouse button 1 - 3 under gui
1097 if (use_gui && (Event.xbutton.button >= 1)
1098 && (Event.xbutton.button <= 3))
1099 break;
1100 #endif
1101 mplayer_put_key((MOUSE_BTN0 + Event.xbutton.button -
1102 1) | MP_KEY_DOWN);
1103 break;
1104 case ButtonRelease:
1105 if (vo_mouse_autohide)
1107 vo_showcursor(mydisplay, vo_window);
1108 vo_mouse_counter = vo_mouse_timer_const;
1110 #ifdef HAVE_NEW_GUI
1111 // Ignor mouse button 1 - 3 under gui
1112 if (use_gui && (Event.xbutton.button >= 1)
1113 && (Event.xbutton.button <= 3))
1114 break;
1115 #endif
1116 mplayer_put_key(MOUSE_BTN0 + Event.xbutton.button - 1);
1117 break;
1118 case PropertyNotify:
1120 char *name =
1121 XGetAtomName(mydisplay, Event.xproperty.atom);
1123 if (!name)
1124 break;
1126 // fprintf(stderr,"[ws] PropertyNotify ( 0x%x ) %s ( 0x%x )\n",vo_window,name,Event.xproperty.atom );
1128 XFree(name);
1130 break;
1131 case MapNotify:
1132 vo_hint.win_gravity = old_gravity;
1133 XSetWMNormalHints(mDisplay, vo_window, &vo_hint);
1134 vo_fs_flip = 0;
1135 break;
1138 return ret;
1142 * \brief sets the size and position of the non-fullscreen window.
1144 void vo_x11_nofs_sizepos(int x, int y, int width, int height)
1146 if (vo_fs) {
1147 vo_old_x = x;
1148 vo_old_y = y;
1149 vo_old_width = width;
1150 vo_old_height = height;
1152 else
1154 vo_dwidth = width;
1155 vo_dheight = height;
1156 XMoveResizeWindow(mDisplay, vo_window, x, y, width, height);
1160 void vo_x11_sizehint(int x, int y, int width, int height, int max)
1162 vo_hint.flags = PPosition | PSize | PWinGravity;
1163 if (vo_keepaspect)
1165 vo_hint.flags |= PAspect;
1166 vo_hint.min_aspect.x = width;
1167 vo_hint.min_aspect.y = height;
1168 vo_hint.max_aspect.x = width;
1169 vo_hint.max_aspect.y = height;
1172 vo_hint.x = x;
1173 vo_hint.y = y;
1174 vo_hint.width = width;
1175 vo_hint.height = height;
1176 if (max)
1178 vo_hint.max_width = width;
1179 vo_hint.max_height = height;
1180 vo_hint.flags |= PMaxSize;
1181 } else
1183 vo_hint.max_width = 0;
1184 vo_hint.max_height = 0;
1187 // set min height/width to 4 to avoid off by one errors
1188 // and because mga_vid requires a minial size of 4 pixel
1189 vo_hint.min_width = vo_hint.min_height = 4;
1190 vo_hint.flags |= PMinSize;
1192 vo_hint.win_gravity = StaticGravity;
1193 XSetWMNormalHints(mDisplay, vo_window, &vo_hint);
1196 static int vo_x11_get_gnome_layer(Display * mDisplay, Window win)
1198 Atom type;
1199 int format;
1200 unsigned long nitems;
1201 unsigned long bytesafter;
1202 unsigned short *args = NULL;
1204 if (XGetWindowProperty(mDisplay, win, XA_WIN_LAYER, 0, 16384,
1205 False, AnyPropertyType, &type, &format, &nitems,
1206 &bytesafter,
1207 (unsigned char **) &args) == Success
1208 && nitems > 0 && args)
1210 mp_msg(MSGT_VO, MSGL_V, "[x11] original window layer is %d.\n",
1211 *args);
1212 return *args;
1214 return WIN_LAYER_NORMAL;
1218 Window vo_x11_create_smooth_window(Display * mDisplay, Window mRoot,
1219 Visual * vis, int x, int y,
1220 unsigned int width, unsigned int height,
1221 int depth, Colormap col_map)
1223 unsigned long xswamask = CWBackingStore | CWBorderPixel;
1224 XSetWindowAttributes xswa;
1225 Window ret_win;
1227 if (col_map != CopyFromParent)
1229 xswa.colormap = col_map;
1230 xswamask |= CWColormap;
1232 xswa.background_pixel = 0;
1233 xswa.border_pixel = 0;
1234 xswa.backing_store = Always;
1235 xswa.bit_gravity = StaticGravity;
1237 ret_win =
1238 XCreateWindow(mDisplay, mRootWin, x, y, width, height, 0, depth,
1239 CopyFromParent, vis, xswamask, &xswa);
1240 if (!f_gc)
1241 f_gc = XCreateGC(mDisplay, ret_win, 0, 0);
1242 XSetForeground(mDisplay, f_gc, 0);
1244 return ret_win;
1248 void vo_x11_clearwindow_part(Display * mDisplay, Window vo_window,
1249 int img_width, int img_height, int use_fs)
1251 int u_dheight, u_dwidth, left_ov, left_ov2;
1253 if (!f_gc)
1254 return;
1256 u_dheight = use_fs ? vo_screenheight : vo_dheight;
1257 u_dwidth = use_fs ? vo_screenwidth : vo_dwidth;
1258 if ((u_dheight <= img_height) && (u_dwidth <= img_width))
1259 return;
1261 left_ov = (u_dheight - img_height) / 2;
1262 left_ov2 = (u_dwidth - img_width) / 2;
1264 XFillRectangle(mDisplay, vo_window, f_gc, 0, 0, u_dwidth, left_ov);
1265 XFillRectangle(mDisplay, vo_window, f_gc, 0, u_dheight - left_ov - 1,
1266 u_dwidth, left_ov + 1);
1268 if (u_dwidth > img_width)
1270 XFillRectangle(mDisplay, vo_window, f_gc, 0, left_ov, left_ov2,
1271 img_height);
1272 XFillRectangle(mDisplay, vo_window, f_gc, u_dwidth - left_ov2 - 1,
1273 left_ov, left_ov2, img_height);
1276 XFlush(mDisplay);
1279 void vo_x11_clearwindow(Display * mDisplay, Window vo_window)
1281 if (!f_gc)
1282 return;
1283 XFillRectangle(mDisplay, vo_window, f_gc, 0, 0, vo_screenwidth,
1284 vo_screenheight);
1286 XFlush(mDisplay);
1290 void vo_x11_setlayer(Display * mDisplay, Window vo_window, int layer)
1292 if (WinID >= 0)
1293 return;
1295 if (vo_fs_type & vo_wm_LAYER)
1297 XClientMessageEvent xev;
1299 if (!orig_layer)
1300 orig_layer = vo_x11_get_gnome_layer(mDisplay, vo_window);
1302 memset(&xev, 0, sizeof(xev));
1303 xev.type = ClientMessage;
1304 xev.display = mDisplay;
1305 xev.window = vo_window;
1306 xev.message_type = XA_WIN_LAYER;
1307 xev.format = 32;
1308 xev.data.l[0] = layer ? fs_layer : orig_layer; // if not fullscreen, stay on default layer
1309 xev.data.l[1] = CurrentTime;
1310 mp_msg(MSGT_VO, MSGL_V,
1311 "[x11] Layered style stay on top (layer %d).\n",
1312 xev.data.l[0]);
1313 XSendEvent(mDisplay, mRootWin, False, SubstructureNotifyMask,
1314 (XEvent *) & xev);
1315 } else if (vo_fs_type & vo_wm_NETWM)
1317 XClientMessageEvent xev;
1318 char *state;
1320 memset(&xev, 0, sizeof(xev));
1321 xev.type = ClientMessage;
1322 xev.message_type = XA_NET_WM_STATE;
1323 xev.display = mDisplay;
1324 xev.window = vo_window;
1325 xev.format = 32;
1326 xev.data.l[0] = layer;
1328 if (vo_fs_type & vo_wm_STAYS_ON_TOP)
1329 xev.data.l[1] = XA_NET_WM_STATE_STAYS_ON_TOP;
1330 else if (vo_fs_type & vo_wm_ABOVE)
1331 xev.data.l[1] = XA_NET_WM_STATE_ABOVE;
1332 else if (vo_fs_type & vo_wm_FULLSCREEN)
1333 xev.data.l[1] = XA_NET_WM_STATE_FULLSCREEN;
1334 else if (vo_fs_type & vo_wm_BELOW)
1335 // This is not fallback. We can safely assume that situation where
1336 // only NETWM_STATE_BELOW is supported and others not, doesn't exist.
1337 xev.data.l[1] = XA_NET_WM_STATE_BELOW;
1339 XSendEvent(mDisplay, mRootWin, False, SubstructureRedirectMask,
1340 (XEvent *) & xev);
1341 state = XGetAtomName(mDisplay, xev.data.l[1]);
1342 mp_msg(MSGT_VO, MSGL_V,
1343 "[x11] NET style stay on top (layer %d). Using state %s.\n",
1344 layer, state);
1345 XFree(state);
1349 static int vo_x11_get_fs_type(int supported)
1351 int i;
1352 int type = supported;
1354 if (vo_fstype_list)
1356 i = 0;
1357 for (i = 0; vo_fstype_list[i]; i++)
1359 int neg = 0;
1360 char *arg = vo_fstype_list[i];
1362 if (vo_fstype_list[i][0] == '-')
1364 neg = 1;
1365 arg = vo_fstype_list[i] + 1;
1368 if (!strncmp(arg, "layer", 5))
1370 if (!neg && (arg[5] == '='))
1372 char *endptr = NULL;
1373 int layer = strtol(vo_fstype_list[i] + 6, &endptr, 10);
1375 if (endptr && *endptr == '\0' && layer >= 0
1376 && layer <= 15)
1377 fs_layer = layer;
1379 if (neg)
1380 type &= ~vo_wm_LAYER;
1381 else
1382 type |= vo_wm_LAYER;
1383 } else if (!strcmp(arg, "above"))
1385 if (neg)
1386 type &= ~vo_wm_ABOVE;
1387 else
1388 type |= vo_wm_ABOVE;
1389 } else if (!strcmp(arg, "fullscreen"))
1391 if (neg)
1392 type &= ~vo_wm_FULLSCREEN;
1393 else
1394 type |= vo_wm_FULLSCREEN;
1395 } else if (!strcmp(arg, "stays_on_top"))
1397 if (neg)
1398 type &= ~vo_wm_STAYS_ON_TOP;
1399 else
1400 type |= vo_wm_STAYS_ON_TOP;
1401 } else if (!strcmp(arg, "below"))
1403 if (neg)
1404 type &= ~vo_wm_BELOW;
1405 else
1406 type |= vo_wm_BELOW;
1407 } else if (!strcmp(arg, "netwm"))
1409 if (neg)
1410 type &= ~vo_wm_NETWM;
1411 else
1412 type |= vo_wm_NETWM;
1413 } else if (!strcmp(arg, "none"))
1414 return 0;
1418 return type;
1421 void vo_x11_fullscreen(void)
1423 int x, y, w, h;
1425 if (WinID >= 0 || vo_fs_flip)
1426 return;
1428 if (vo_fs)
1430 // fs->win
1431 if ( ! (vo_fs_type & vo_wm_FULLSCREEN) ) // not needed with EWMH fs
1433 if (vo_dwidth != vo_screenwidth && vo_dheight != vo_screenheight)
1434 return;
1435 x = vo_old_x;
1436 y = vo_old_y;
1437 w = vo_old_width;
1438 h = vo_old_height;
1441 vo_x11_ewmh_fullscreen(_NET_WM_STATE_REMOVE); // removes fullscreen state if wm supports EWMH
1442 vo_fs = VO_FALSE;
1443 } else
1445 // win->fs
1446 vo_x11_ewmh_fullscreen(_NET_WM_STATE_ADD); // sends fullscreen state to be added if wm supports EWMH
1448 vo_fs = VO_TRUE;
1449 if ( ! (vo_fs_type & vo_wm_FULLSCREEN) ) // not needed with EWMH fs
1451 if (vo_old_width &&
1452 (vo_dwidth == vo_screenwidth && vo_dwidth != vo_old_width) &&
1453 (vo_dheight == vo_screenheight && vo_dheight != vo_old_height))
1454 return;
1455 vo_old_x = vo_dx;
1456 vo_old_y = vo_dy;
1457 vo_old_width = vo_dwidth;
1458 vo_old_height = vo_dheight;
1459 x = 0;
1460 y = 0;
1461 w = vo_screenwidth;
1462 h = vo_screenheight;
1466 long dummy;
1468 XGetWMNormalHints(mDisplay, vo_window, &vo_hint, &dummy);
1469 if (!(vo_hint.flags & PWinGravity))
1470 old_gravity = NorthWestGravity;
1471 else
1472 old_gravity = vo_hint.win_gravity;
1474 if (vo_wm_type == 0 && !(vo_fsmode & 16))
1476 XUnmapWindow(mDisplay, vo_window); // required for MWM
1477 XWithdrawWindow(mDisplay, vo_window, mScreen);
1478 vo_fs_flip = 1;
1481 if ( ! (vo_fs_type & vo_wm_FULLSCREEN) ) // not needed with EWMH fs
1483 vo_x11_decoration(mDisplay, vo_window, (vo_fs) ? 0 : 1);
1484 vo_x11_sizehint(x, y, w, h, 0);
1485 vo_x11_setlayer(mDisplay, vo_window, vo_fs);
1487 if ((!(vo_fs)) & vo_ontop)
1488 vo_x11_setlayer(mDisplay, vo_window, vo_ontop);
1490 XMoveResizeWindow(mDisplay, vo_window, x, y, w, h);
1492 #ifdef HAVE_XINERAMA
1493 vo_x11_xinerama_move(mDisplay, vo_window);
1494 #endif
1496 XMapRaised(mDisplay, vo_window);
1497 XRaiseWindow(mDisplay, vo_window);
1498 XFlush(mDisplay);
1501 void vo_x11_ontop(void)
1503 vo_ontop = (!(vo_ontop));
1505 vo_x11_setlayer(mDisplay, vo_window, vo_ontop);
1509 * XScreensaver stuff
1512 static int got_badwindow;
1513 static XErrorHandler old_handler;
1515 static int badwindow_handler(Display * dpy, XErrorEvent * error)
1517 if (error->error_code != BadWindow)
1518 return (*old_handler) (dpy, error);
1520 got_badwindow = True;
1521 return 0;
1524 static Window find_xscreensaver_window(Display * dpy)
1526 int i;
1527 Window root = RootWindowOfScreen(DefaultScreenOfDisplay(dpy));
1528 Window root2, parent, *kids;
1529 Window retval = 0;
1530 Atom xs_version;
1531 unsigned int nkids = 0;
1533 xs_version = XInternAtom(dpy, "_SCREENSAVER_VERSION", True);
1535 if (!(xs_version != None &&
1536 XQueryTree(dpy, root, &root2, &parent, &kids, &nkids) &&
1537 kids && nkids))
1538 return 0;
1540 old_handler = XSetErrorHandler(badwindow_handler);
1542 for (i = 0; i < nkids; i++)
1544 Atom type;
1545 int format;
1546 unsigned long nitems, bytesafter;
1547 char *v;
1548 int status;
1550 got_badwindow = False;
1551 status =
1552 XGetWindowProperty(dpy, kids[i], xs_version, 0, 200, False,
1553 XA_STRING, &type, &format, &nitems,
1554 &bytesafter, (unsigned char **) &v);
1555 XSync(dpy, False);
1556 if (got_badwindow)
1557 status = BadWindow;
1559 if (status == Success && type != None)
1561 retval = kids[i];
1562 break;
1565 XFree(kids);
1566 XSetErrorHandler(old_handler);
1568 return retval;
1571 static Window xs_windowid = 0;
1572 static Atom deactivate;
1573 static Atom screensaver;
1575 static unsigned int time_last;
1577 void xscreensaver_heartbeat(void)
1579 unsigned int time = GetTimerMS();
1580 XEvent ev;
1582 if (mDisplay && xs_windowid &&
1583 ((time - time_last) > 30000 || (time - time_last) < 0))
1585 time_last = time;
1587 ev.xany.type = ClientMessage;
1588 ev.xclient.display = mDisplay;
1589 ev.xclient.window = xs_windowid;
1590 ev.xclient.message_type = screensaver;
1591 ev.xclient.format = 32;
1592 memset(&ev.xclient.data, 0, sizeof(ev.xclient.data));
1593 ev.xclient.data.l[0] = (long) deactivate;
1595 mp_msg(MSGT_VO, MSGL_DBG2, "Pinging xscreensaver.\n");
1596 XSendEvent(mDisplay, xs_windowid, False, 0L, &ev);
1597 XSync(mDisplay, False);
1601 static void xscreensaver_disable(Display * dpy)
1603 mp_msg(MSGT_VO, MSGL_DBG2, "xscreensaver_disable()\n");
1605 xs_windowid = find_xscreensaver_window(dpy);
1606 if (!xs_windowid)
1608 mp_msg(MSGT_VO, MSGL_INFO,
1609 "xscreensaver_disable: Could not find xscreensaver window.\n");
1610 return;
1612 mp_msg(MSGT_VO, MSGL_INFO,
1613 "xscreensaver_disable: xscreensaver wid=%d.\n", xs_windowid);
1615 deactivate = XInternAtom(dpy, "DEACTIVATE", False);
1616 screensaver = XInternAtom(dpy, "SCREENSAVER", False);
1619 static void xscreensaver_enable(void)
1621 xs_windowid = 0;
1625 * End of XScreensaver stuff
1628 void saver_on(Display * mDisplay)
1631 #ifdef HAVE_XDPMS
1632 int nothing;
1634 if (dpms_disabled)
1636 if (DPMSQueryExtension(mDisplay, &nothing, &nothing))
1638 if (!DPMSEnable(mDisplay))
1639 { // restoring power saving settings
1640 mp_msg(MSGT_VO, MSGL_WARN, "DPMS not available?\n");
1641 } else
1643 // DPMS does not seem to be enabled unless we call DPMSInfo
1644 BOOL onoff;
1645 CARD16 state;
1647 DPMSForceLevel(mDisplay, DPMSModeOn);
1648 DPMSInfo(mDisplay, &state, &onoff);
1649 if (onoff)
1651 mp_msg(MSGT_VO, MSGL_V,
1652 "Successfully enabled DPMS\n");
1653 } else
1655 mp_msg(MSGT_VO, MSGL_WARN, "Could not enable DPMS\n");
1659 dpms_disabled = 0;
1661 #endif
1663 if (timeout_save)
1665 int dummy, interval, prefer_blank, allow_exp;
1667 XGetScreenSaver(mDisplay, &dummy, &interval, &prefer_blank,
1668 &allow_exp);
1669 XSetScreenSaver(mDisplay, timeout_save, interval, prefer_blank,
1670 allow_exp);
1671 XGetScreenSaver(mDisplay, &timeout_save, &interval, &prefer_blank,
1672 &allow_exp);
1673 timeout_save = 0;
1676 if (stop_xscreensaver)
1677 xscreensaver_enable();
1678 if (kdescreensaver_was_running && stop_xscreensaver)
1680 system
1681 ("dcop kdesktop KScreensaverIface enable true 2>/dev/null >/dev/null");
1682 kdescreensaver_was_running = 0;
1688 void saver_off(Display * mDisplay)
1691 int interval, prefer_blank, allow_exp;
1693 #ifdef HAVE_XDPMS
1694 int nothing;
1696 if (DPMSQueryExtension(mDisplay, &nothing, &nothing))
1698 BOOL onoff;
1699 CARD16 state;
1701 DPMSInfo(mDisplay, &state, &onoff);
1702 if (onoff)
1704 Status stat;
1706 mp_msg(MSGT_VO, MSGL_V, "Disabling DPMS\n");
1707 dpms_disabled = 1;
1708 stat = DPMSDisable(mDisplay); // monitor powersave off
1709 mp_msg(MSGT_VO, MSGL_V, "DPMSDisable stat: %d\n", stat);
1712 #endif
1713 if (!timeout_save)
1715 XGetScreenSaver(mDisplay, &timeout_save, &interval, &prefer_blank,
1716 &allow_exp);
1717 if (timeout_save)
1718 XSetScreenSaver(mDisplay, 0, interval, prefer_blank,
1719 allow_exp);
1721 // turning off screensaver
1722 if (stop_xscreensaver)
1723 xscreensaver_disable(mDisplay);
1724 if (stop_xscreensaver && !kdescreensaver_was_running)
1726 kdescreensaver_was_running =
1727 (system
1728 ("dcop kdesktop KScreensaverIface isEnabled 2>/dev/null | sed 's/1/true/g' | grep true 2>/dev/null >/dev/null")
1729 == 0);
1730 if (kdescreensaver_was_running)
1731 system
1732 ("dcop kdesktop KScreensaverIface enable false 2>/dev/null >/dev/null");
1736 static XErrorHandler old_handler = NULL;
1737 static int selectinput_err = 0;
1738 static int x11_selectinput_errorhandler(Display * display,
1739 XErrorEvent * event)
1741 if (event->error_code == BadAccess)
1743 selectinput_err = 1;
1744 mp_msg(MSGT_VO, MSGL_ERR,
1745 "X11 error: BadAccess during XSelectInput Call\n");
1746 mp_msg(MSGT_VO, MSGL_ERR,
1747 "X11 error: The 'ButtonPressMask' mask of specified window has probably already used by another appication (see man XSelectInput)\n");
1748 /* If you think mplayer should shutdown with this error, comments out following line */
1749 return 0;
1751 if (old_handler != NULL)
1752 old_handler(display, event);
1753 else
1754 x11_errorhandler(display, event);
1755 return 0;
1758 void vo_x11_selectinput_witherr(Display * display, Window w,
1759 long event_mask)
1761 XSync(display, False);
1762 old_handler = XSetErrorHandler(x11_selectinput_errorhandler);
1763 selectinput_err = 0;
1764 if (vo_nomouse_input)
1766 XSelectInput(display, w,
1767 event_mask &
1768 (~(ButtonPressMask | ButtonReleaseMask)));
1769 } else
1771 XSelectInput(display, w, event_mask);
1773 XSync(display, False);
1774 XSetErrorHandler(old_handler);
1775 if (selectinput_err)
1777 mp_msg(MSGT_VO, MSGL_ERR,
1778 "X11 error: MPlayer discards mouse control (reconfiguring)\n");
1779 XSelectInput(display, w,
1780 event_mask &
1782 (ButtonPressMask | ButtonReleaseMask |
1783 PointerMotionMask)));
1787 #ifdef HAVE_XINERAMA
1788 void vo_x11_xinerama_move(Display * dsp, Window w)
1790 if (XineramaIsActive(dsp) && !geometry_xy_changed)
1792 /* printf("XXXX Xinerama screen: x: %hd y: %hd\n",xinerama_x,xinerama_y); */
1793 XMoveWindow(dsp, w, xinerama_x, xinerama_y);
1796 #endif
1798 #ifdef HAVE_XF86VM
1799 void vo_vm_switch(uint32_t X, uint32_t Y, int *modeline_width,
1800 int *modeline_height)
1802 int vm_event, vm_error;
1803 int vm_ver, vm_rev;
1804 int i, j, have_vm = 0;
1806 int modecount;
1808 if (XF86VidModeQueryExtension(mDisplay, &vm_event, &vm_error))
1810 XF86VidModeQueryVersion(mDisplay, &vm_ver, &vm_rev);
1811 mp_msg(MSGT_VO, MSGL_V, "XF86VidMode Extension v%i.%i\n", vm_ver,
1812 vm_rev);
1813 have_vm = 1;
1814 } else
1815 mp_msg(MSGT_VO, MSGL_WARN,
1816 "XF86VidMode Extenstion not available.\n");
1818 if (have_vm)
1820 if (vidmodes == NULL)
1821 XF86VidModeGetAllModeLines(mDisplay, mScreen, &modecount,
1822 &vidmodes);
1823 j = 0;
1824 *modeline_width = vidmodes[0]->hdisplay;
1825 *modeline_height = vidmodes[0]->vdisplay;
1827 for (i = 1; i < modecount; i++)
1828 if ((vidmodes[i]->hdisplay >= X)
1829 && (vidmodes[i]->vdisplay >= Y))
1830 if ((vidmodes[i]->hdisplay <= *modeline_width)
1831 && (vidmodes[i]->vdisplay <= *modeline_height))
1833 *modeline_width = vidmodes[i]->hdisplay;
1834 *modeline_height = vidmodes[i]->vdisplay;
1835 j = i;
1838 mp_msg(MSGT_VO, MSGL_INFO,
1839 "XF86VM: Selected video mode %dx%d for image size %dx%d.\n",
1840 *modeline_width, *modeline_height, X, Y);
1841 XF86VidModeLockModeSwitch(mDisplay, mScreen, 0);
1842 XF86VidModeSwitchToMode(mDisplay, mScreen, vidmodes[j]);
1843 XF86VidModeSwitchToMode(mDisplay, mScreen, vidmodes[j]);
1844 X = (vo_screenwidth - *modeline_width) / 2;
1845 Y = (vo_screenheight - *modeline_height) / 2;
1846 XF86VidModeSetViewPort(mDisplay, mScreen, X, Y);
1850 void vo_vm_close(Display * dpy)
1852 #ifdef HAVE_NEW_GUI
1853 if (vidmodes != NULL && vo_window != None)
1854 #else
1855 if (vidmodes != NULL)
1856 #endif
1858 int i, modecount;
1859 int screen;
1861 screen = DefaultScreen(dpy);
1863 free(vidmodes);
1864 vidmodes = NULL;
1865 XF86VidModeGetAllModeLines(mDisplay, mScreen, &modecount,
1866 &vidmodes);
1867 for (i = 0; i < modecount; i++)
1868 if ((vidmodes[i]->hdisplay == vo_screenwidth)
1869 && (vidmodes[i]->vdisplay == vo_screenheight))
1871 mp_msg(MSGT_VO, MSGL_INFO,
1872 "Returning to original mode %dx%d\n",
1873 vo_screenwidth, vo_screenheight);
1874 break;
1877 XF86VidModeSwitchToMode(dpy, screen, vidmodes[i]);
1878 XF86VidModeSwitchToMode(dpy, screen, vidmodes[i]);
1879 free(vidmodes);
1880 vidmodes = NULL;
1883 #endif
1885 #endif /* X11_FULLSCREEN */
1889 * Scan the available visuals on this Display/Screen. Try to find
1890 * the 'best' available TrueColor visual that has a decent color
1891 * depth (at least 15bit). If there are multiple visuals with depth
1892 * >= 15bit, we prefer visuals with a smaller color depth.
1894 int vo_find_depth_from_visuals(Display * dpy, int screen,
1895 Visual ** visual_return)
1897 XVisualInfo visual_tmpl;
1898 XVisualInfo *visuals;
1899 int nvisuals, i;
1900 int bestvisual = -1;
1901 int bestvisual_depth = -1;
1903 visual_tmpl.screen = screen;
1904 visual_tmpl.class = TrueColor;
1905 visuals = XGetVisualInfo(dpy,
1906 VisualScreenMask | VisualClassMask,
1907 &visual_tmpl, &nvisuals);
1908 if (visuals != NULL)
1910 for (i = 0; i < nvisuals; i++)
1912 mp_msg(MSGT_VO, MSGL_V,
1913 "vo: X11 truecolor visual %#x, depth %d, R:%lX G:%lX B:%lX\n",
1914 visuals[i].visualid, visuals[i].depth,
1915 visuals[i].red_mask, visuals[i].green_mask,
1916 visuals[i].blue_mask);
1918 * save the visual index and it's depth, if this is the first
1919 * truecolor visul, or a visual that is 'preferred' over the
1920 * previous 'best' visual
1922 if (bestvisual_depth == -1
1923 || (visuals[i].depth >= 15
1924 && (visuals[i].depth < bestvisual_depth
1925 || bestvisual_depth < 15)))
1927 bestvisual = i;
1928 bestvisual_depth = visuals[i].depth;
1932 if (bestvisual != -1 && visual_return != NULL)
1933 *visual_return = visuals[bestvisual].visual;
1935 XFree(visuals);
1937 return bestvisual_depth;
1941 static Colormap cmap = None;
1942 static XColor cols[256];
1943 static int cm_size, red_mask, green_mask, blue_mask;
1946 Colormap vo_x11_create_colormap(XVisualInfo * vinfo)
1948 unsigned k, r, g, b, ru, gu, bu, m, rv, gv, bv, rvu, gvu, bvu;
1950 if (vinfo->class != DirectColor)
1951 return XCreateColormap(mDisplay, mRootWin, vinfo->visual,
1952 AllocNone);
1954 /* can this function get called twice or more? */
1955 if (cmap)
1956 return cmap;
1957 cm_size = vinfo->colormap_size;
1958 red_mask = vinfo->red_mask;
1959 green_mask = vinfo->green_mask;
1960 blue_mask = vinfo->blue_mask;
1961 ru = (red_mask & (red_mask - 1)) ^ red_mask;
1962 gu = (green_mask & (green_mask - 1)) ^ green_mask;
1963 bu = (blue_mask & (blue_mask - 1)) ^ blue_mask;
1964 rvu = 65536ull * ru / (red_mask + ru);
1965 gvu = 65536ull * gu / (green_mask + gu);
1966 bvu = 65536ull * bu / (blue_mask + bu);
1967 r = g = b = 0;
1968 rv = gv = bv = 0;
1969 m = DoRed | DoGreen | DoBlue;
1970 for (k = 0; k < cm_size; k++)
1972 int t;
1974 cols[k].pixel = r | g | b;
1975 cols[k].red = rv;
1976 cols[k].green = gv;
1977 cols[k].blue = bv;
1978 cols[k].flags = m;
1979 t = (r + ru) & red_mask;
1980 if (t < r)
1981 m &= ~DoRed;
1982 r = t;
1983 t = (g + gu) & green_mask;
1984 if (t < g)
1985 m &= ~DoGreen;
1986 g = t;
1987 t = (b + bu) & blue_mask;
1988 if (t < b)
1989 m &= ~DoBlue;
1990 b = t;
1991 rv += rvu;
1992 gv += gvu;
1993 bv += bvu;
1995 cmap = XCreateColormap(mDisplay, mRootWin, vinfo->visual, AllocAll);
1996 XStoreColors(mDisplay, cmap, cols, cm_size);
1997 return cmap;
2001 * Via colormaps/gamma ramps we can do gamma, brightness, contrast,
2002 * hue and red/green/blue intensity, but we cannot do saturation.
2003 * Currently only gamma, brightness and contrast are implemented.
2004 * Is there sufficient interest for hue and/or red/green/blue intensity?
2006 /* these values have range [-100,100] and are initially 0 */
2007 static int vo_gamma = 0;
2008 static int vo_brightness = 0;
2009 static int vo_contrast = 0;
2012 uint32_t vo_x11_set_equalizer(char *name, int value)
2014 float gamma, brightness, contrast;
2015 float rf, gf, bf;
2016 int k;
2019 * IMPLEMENTME: consider using XF86VidModeSetGammaRamp in the case
2020 * of TrueColor-ed window but be careful:
2021 * unlike the colormaps, which are private for the X client
2022 * who created them and thus automatically destroyed on client
2023 * disconnect, this gamma ramp is a system-wide (X-server-wide)
2024 * setting and _must_ be restored before the process exit.
2025 * Unforunately when the process crashes (or get killed
2026 * for some reason) it is impossible to restore the setting,
2027 * and such behaviour could be rather annoying for the users.
2029 if (cmap == None)
2030 return VO_NOTAVAIL;
2032 if (!strcasecmp(name, "brightness"))
2033 vo_brightness = value;
2034 else if (!strcasecmp(name, "contrast"))
2035 vo_contrast = value;
2036 else if (!strcasecmp(name, "gamma"))
2037 vo_gamma = value;
2038 else
2039 return VO_NOTIMPL;
2041 brightness = 0.01 * vo_brightness;
2042 contrast = tan(0.0095 * (vo_contrast + 100) * M_PI / 4);
2043 gamma = pow(2, -0.02 * vo_gamma);
2045 rf = (float) ((red_mask & (red_mask - 1)) ^ red_mask) / red_mask;
2046 gf = (float) ((green_mask & (green_mask - 1)) ^ green_mask) /
2047 green_mask;
2048 bf = (float) ((blue_mask & (blue_mask - 1)) ^ blue_mask) / blue_mask;
2050 /* now recalculate the colormap using the newly set value */
2051 for (k = 0; k < cm_size; k++)
2053 float s;
2055 s = pow(rf * k, gamma);
2056 s = (s - 0.5) * contrast + 0.5;
2057 s += brightness;
2058 if (s < 0)
2059 s = 0;
2060 if (s > 1)
2061 s = 1;
2062 cols[k].red = (unsigned short) (s * 65535);
2064 s = pow(gf * k, gamma);
2065 s = (s - 0.5) * contrast + 0.5;
2066 s += brightness;
2067 if (s < 0)
2068 s = 0;
2069 if (s > 1)
2070 s = 1;
2071 cols[k].green = (unsigned short) (s * 65535);
2073 s = pow(bf * k, gamma);
2074 s = (s - 0.5) * contrast + 0.5;
2075 s += brightness;
2076 if (s < 0)
2077 s = 0;
2078 if (s > 1)
2079 s = 1;
2080 cols[k].blue = (unsigned short) (s * 65535);
2083 XStoreColors(mDisplay, cmap, cols, cm_size);
2084 XFlush(mDisplay);
2085 return VO_TRUE;
2088 uint32_t vo_x11_get_equalizer(char *name, int *value)
2090 if (cmap == None)
2091 return VO_NOTAVAIL;
2092 if (!strcasecmp(name, "brightness"))
2093 *value = vo_brightness;
2094 else if (!strcasecmp(name, "contrast"))
2095 *value = vo_contrast;
2096 else if (!strcasecmp(name, "gamma"))
2097 *value = vo_gamma;
2098 else
2099 return VO_NOTIMPL;
2100 return VO_TRUE;
2103 #ifdef HAVE_XV
2104 int vo_xv_set_eq(uint32_t xv_port, char *name, int value)
2106 XvAttribute *attributes;
2107 int i, howmany, xv_atom;
2109 mp_dbg(MSGT_VO, MSGL_V, "xv_set_eq called! (%s, %d)\n", name, value);
2111 /* get available attributes */
2112 attributes = XvQueryPortAttributes(mDisplay, xv_port, &howmany);
2113 for (i = 0; i < howmany && attributes; i++)
2114 if (attributes[i].flags & XvSettable)
2116 xv_atom = XInternAtom(mDisplay, attributes[i].name, True);
2117 /* since we have SET_DEFAULTS first in our list, we can check if it's available
2118 then trigger it if it's ok so that the other values are at default upon query */
2119 if (xv_atom != None)
2121 int hue = 0, port_value, port_min, port_max;
2123 if (!strcmp(attributes[i].name, "XV_BRIGHTNESS") &&
2124 (!strcasecmp(name, "brightness")))
2125 port_value = value;
2126 else if (!strcmp(attributes[i].name, "XV_CONTRAST") &&
2127 (!strcasecmp(name, "contrast")))
2128 port_value = value;
2129 else if (!strcmp(attributes[i].name, "XV_SATURATION") &&
2130 (!strcasecmp(name, "saturation")))
2131 port_value = value;
2132 else if (!strcmp(attributes[i].name, "XV_HUE") &&
2133 (!strcasecmp(name, "hue")))
2135 port_value = value;
2136 hue = 1;
2137 } else
2138 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
2139 if (!strcmp(attributes[i].name, "XV_RED_INTENSITY") &&
2140 (!strcasecmp(name, "red_intensity")))
2141 port_value = value;
2142 else if (!strcmp(attributes[i].name, "XV_GREEN_INTENSITY")
2143 && (!strcasecmp(name, "green_intensity")))
2144 port_value = value;
2145 else if (!strcmp(attributes[i].name, "XV_BLUE_INTENSITY")
2146 && (!strcasecmp(name, "blue_intensity")))
2147 port_value = value;
2148 else
2149 continue;
2151 port_min = attributes[i].min_value;
2152 port_max = attributes[i].max_value;
2154 /* nvidia hue workaround */
2155 if (hue && port_min == 0 && port_max == 360)
2157 port_value =
2158 (port_value >=
2159 0) ? (port_value - 100) : (port_value + 100);
2161 // -100 -> min
2162 // 0 -> (max+min)/2
2163 // +100 -> max
2164 port_value =
2165 (port_value + 100) * (port_max - port_min) / 200 +
2166 port_min;
2167 XvSetPortAttribute(mDisplay, xv_port, xv_atom, port_value);
2168 return (VO_TRUE);
2171 return (VO_FALSE);
2174 int vo_xv_get_eq(uint32_t xv_port, char *name, int *value)
2177 XvAttribute *attributes;
2178 int i, howmany, xv_atom;
2180 /* get available attributes */
2181 attributes = XvQueryPortAttributes(mDisplay, xv_port, &howmany);
2182 for (i = 0; i < howmany && attributes; i++)
2183 if (attributes[i].flags & XvGettable)
2185 xv_atom = XInternAtom(mDisplay, attributes[i].name, True);
2186 /* since we have SET_DEFAULTS first in our list, we can check if it's available
2187 then trigger it if it's ok so that the other values are at default upon query */
2188 if (xv_atom != None)
2190 int val, port_value = 0, port_min, port_max;
2192 XvGetPortAttribute(mDisplay, xv_port, xv_atom,
2193 &port_value);
2195 port_min = attributes[i].min_value;
2196 port_max = attributes[i].max_value;
2197 val =
2198 (port_value - port_min) * 200 / (port_max - port_min) -
2199 100;
2201 if (!strcmp(attributes[i].name, "XV_BRIGHTNESS") &&
2202 (!strcasecmp(name, "brightness")))
2203 *value = val;
2204 else if (!strcmp(attributes[i].name, "XV_CONTRAST") &&
2205 (!strcasecmp(name, "contrast")))
2206 *value = val;
2207 else if (!strcmp(attributes[i].name, "XV_SATURATION") &&
2208 (!strcasecmp(name, "saturation")))
2209 *value = val;
2210 else if (!strcmp(attributes[i].name, "XV_HUE") &&
2211 (!strcasecmp(name, "hue")))
2213 /* nasty nvidia detect */
2214 if (port_min == 0 && port_max == 360)
2215 *value = (val >= 0) ? (val - 100) : (val + 100);
2216 else
2217 *value = val;
2218 } else
2219 /* Note: since 22.01.2002 GATOS supports these attrs for radeons (NK) */
2220 if (!strcmp(attributes[i].name, "XV_RED_INTENSITY") &&
2221 (!strcasecmp(name, "red_intensity")))
2222 *value = val;
2223 else if (!strcmp(attributes[i].name, "XV_GREEN_INTENSITY")
2224 && (!strcasecmp(name, "green_intensity")))
2225 *value = val;
2226 else if (!strcmp(attributes[i].name, "XV_BLUE_INTENSITY")
2227 && (!strcasecmp(name, "blue_intensity")))
2228 *value = val;
2229 else
2230 continue;
2232 mp_dbg(MSGT_VO, MSGL_V, "xv_get_eq called! (%s, %d)\n",
2233 name, *value);
2234 return (VO_TRUE);
2237 return (VO_FALSE);
2240 #endif