#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <inttypes.h>
#include "config.h"
#include "mp_msg.h"
#include "x11_common.h"
#ifdef X11_FULLSCREEN
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <signal.h>
#include "video_out.h"
#include "help_mp.h"
#include <X11/Xmd.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#ifdef HAVE_XDPMS
#include <X11/extensions/dpms.h>
#endif
#ifdef HAVE_XINERAMA
#include <X11/extensions/Xinerama.h>
#endif
#ifdef HAVE_XF86VM
#include <X11/extensions/xf86vmode.h>
#include <X11/XF86keysym.h>
#endif
#ifdef HAVE_XV
#include <X11/extensions/Xv.h>
#include <X11/extensions/Xvlib.h>
#endif
#include "../input/input.h"
#include "../input/mouse.h"
#ifdef HAVE_NEW_GUI
#include "../Gui/interface.h"
#include "../mplayer.h"
#endif
#define WIN_LAYER_ONBOTTOM 2
#define WIN_LAYER_NORMAL 4
#define WIN_LAYER_ONTOP 6
#define WIN_LAYER_ABOVE_DOCK 10
int fs_layer=WIN_LAYER_ABOVE_DOCK;
static int orig_layer=0;
int stop_xscreensaver=0;
static int dpms_disabled=0;
static int timeout_save=0;
static int kdescreensaver_was_running=0;
char* mDisplayName=NULL;
Display* mDisplay=NULL;
Window mRootWin;
int mScreen;
int mLocalDisplay;
/* output window id */
int WinID=-1;
int vo_mouse_autohide = 0;
int vo_wm_type = 0;
static int vo_fs_type = 0;
char** vo_fstype_list;
/* if equal to 1 means that WM is a metacity (broken as hell) */
int metacity_hack = 0;
static Atom XA_NET_SUPPORTED;
static Atom XA_NET_WM_STATE;
static Atom XA_NET_WM_STATE_FULLSCREEN;
static Atom XA_NET_WM_STATE_ABOVE;
static Atom XA_NET_WM_STATE_STAYS_ON_TOP;
static Atom XA_NET_WM_STATE_BELOW;
static Atom XA_NET_WM_PID;
static Atom XA_WIN_PROTOCOLS;
static Atom XA_WIN_LAYER;
static Atom XA_WIN_HINTS;
static Atom XA_BLACKBOX_PID;
#define XA_INIT(x) XA##x = XInternAtom(mDisplay, #x, False)
static int vo_old_x = 0;
static int vo_old_y = 0;
static int vo_old_width = 0;
static int vo_old_height = 0;
int vo_x11_keepaspect = 1;
#ifdef HAVE_XINERAMA
int xinerama_screen = 0;
int xinerama_x = 0;
int xinerama_y = 0;
#endif
#ifdef HAVE_XF86VM
XF86VidModeModeInfo **vidmodes=NULL;
XF86VidModeModeLine modeline;
#endif
static int vo_x11_get_fs_type(int supported);
void vo_hidecursor ( Display *disp , Window win )
{
Cursor no_ptr;
Pixmap bm_no;
XColor black,dummy;
Colormap colormap;
static unsigned char bm_no_data[] = { 0,0,0,0, 0,0,0,0 };
if(WinID==0) return; // do not hide, if we're playing at rootwin
colormap = DefaultColormap(disp,DefaultScreen(disp));
XAllocNamedColor(disp,colormap,"black",&black,&dummy);
bm_no = XCreateBitmapFromData(disp, win, bm_no_data, 8,8);
no_ptr=XCreatePixmapCursor(disp, bm_no, bm_no,&black, &black,0, 0);
XDefineCursor(disp,win,no_ptr);
XFreeCursor( disp,no_ptr );
if (bm_no != None)
XFreePixmap(disp, bm_no);
}
void vo_showcursor( Display *disp, Window win )
{
if ( WinID==0 ) return;
XDefineCursor( disp,win,0 );
}
static int x11_errorhandler(Display *display, XErrorEvent *event)
{
#define MSGLEN 60
char msg[MSGLEN];
XGetErrorText(display, event->error_code, (char *)&msg, MSGLEN);
mp_msg(MSGT_VO,MSGL_ERR,"X11 error: %s\n", msg);
mp_msg(MSGT_VO,MSGL_V,"Type: %x, display: %x, resourceid: %x, serial: %x\n",
event->type, event->display, event->resourceid, event->serial);
mp_msg(MSGT_VO,MSGL_V,"Error code: %x, request code: %x, minor code: %x\n",
event->error_code, event->request_code, event->minor_code);
abort();
//exit_player("X11 error");
#undef MSGLEN
}
void fstype_help(void)
{
mp_msg(MSGT_VO, MSGL_INFO, MSGTR_AvailableFsType);
mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "none", "don't set fullscreen window layer");
mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "layer", "use _WIN_LAYER hint with default layer");
mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "layer=<0..15>", "use _WIN_LAYER hint with a given layer number");
mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "netwm", "force NETWM style");
mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "above", "use _NETWM_STATE_ABOVE hint if available");
mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "below", "use _NETWM_STATE_BELOW hint if available");
mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "fullscreen", "use _NETWM_STATE_FULLSCREEN hint if availale");
mp_msg(MSGT_VO, MSGL_INFO, " %-15s %s\n", "stays_on_top", "use _NETWM_STATE_STAYS_ON_TOP hint if available");
mp_msg(MSGT_VO
|