Home | History | Annotate | Download | only in x11
      1 /*
      2     SDL - Simple DirectMedia Layer
      3     Copyright (C) 1997-2012 Sam Lantinga
      4 
      5     This library is free software; you can redistribute it and/or
      6     modify it under the terms of the GNU Lesser General Public
      7     License as published by the Free Software Foundation; either
      8     version 2.1 of the License, or (at your option) any later version.
      9 
     10     This library is distributed in the hope that it will be useful,
     11     but WITHOUT ANY WARRANTY; without even the implied warranty of
     12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13     Lesser General Public License for more details.
     14 
     15     You should have received a copy of the GNU Lesser General Public
     16     License along with this library; if not, write to the Free Software
     17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     18 
     19     Sam Lantinga
     20     slouken (at) libsdl.org
     21 */
     22 #include "SDL_config.h"
     23 
     24 #ifndef _SDL_x11video_h
     25 #define _SDL_x11video_h
     26 
     27 #include <X11/Xlib.h>
     28 #include <X11/Xutil.h>
     29 #include <X11/Xatom.h>
     30 
     31 #include "SDL_mouse.h"
     32 #include "../SDL_sysvideo.h"
     33 
     34 #if SDL_VIDEO_DRIVER_X11_DGAMOUSE
     35 #include "../Xext/extensions/xf86dga.h"
     36 #endif
     37 #if SDL_VIDEO_DRIVER_X11_XINERAMA
     38 #include "../Xext/extensions/Xinerama.h"
     39 #endif
     40 #if SDL_VIDEO_DRIVER_X11_XRANDR
     41 #include <X11/extensions/Xrandr.h>
     42 #endif
     43 #if SDL_VIDEO_DRIVER_X11_VIDMODE
     44 #include "../Xext/extensions/xf86vmode.h"
     45 #endif
     46 #if SDL_VIDEO_DRIVER_X11_XME
     47 #include "../Xext/extensions/xme.h"
     48 #endif
     49 
     50 #include "SDL_x11dyn.h"
     51 
     52 /* Hidden "this" pointer for the video functions */
     53 #define _THIS	SDL_VideoDevice *this
     54 
     55 /* Private display data */
     56 struct SDL_PrivateVideoData {
     57     int local_X11;		/* Flag: true if local display */
     58     Display *X11_Display;	/* Used for events and window management */
     59     Display *GFX_Display;	/* Used for graphics and colormap stuff */
     60     Visual *SDL_Visual;		/* The visual used by our window */
     61     Window WMwindow;		/* Input window, managed by window manager */
     62     Window FSwindow;		/* Fullscreen window, completely unmanaged */
     63     Window SDL_Window;		/* Shared by both displays (no X security?) */
     64     Atom WM_DELETE_WINDOW;	/* "close-window" protocol atom */
     65     WMcursor *BlankCursor;	/* The invisible cursor */
     66     XIM X11_IM;		/* Used to communicate with the input method (IM) server */
     67     XIC X11_IC;		/* Used for retaining the state, properties, and semantics of communication with                                                  the input method (IM) server */
     68 
     69     char *SDL_windowid;		/* Flag: true if we have been passed a window */
     70 
     71     /* Direct Graphics Access extension information */
     72     int using_dga;
     73 
     74 #ifndef NO_SHARED_MEMORY
     75     /* MIT shared memory extension information */
     76     int use_mitshm;
     77     XShmSegmentInfo shminfo;
     78 #endif
     79 
     80     /* The variables used for displaying graphics */
     81     XImage *Ximage;		/* The X image for our window */
     82     GC	gc;			/* The graphic context for drawing */
     83 
     84     /* The current width and height of the fullscreen mode */
     85     int window_w;
     86     int window_h;
     87 
     88     /* Support for internal mouse warping */
     89     struct {
     90         int x;
     91         int y;
     92     } mouse_last;
     93     struct {
     94         int numerator;
     95         int denominator;
     96         int threshold;
     97     } mouse_accel;
     98     int mouse_relative;
     99 
    100     /* The current list of available video modes */
    101     SDL_Rect **modelist;
    102 
    103     /* available visuals of interest to us, sorted deepest first */
    104     struct {
    105 	Visual *visual;
    106 	int depth;		/* number of significant bits/pixel */
    107 	int bpp;		/* pixel quantum in bits */
    108     } visuals[2*5];		/* at most 2 entries for 8, 15, 16, 24, 32 */
    109     int nvisuals;
    110 
    111     Visual *vis;		/* current visual in use */
    112     int depth;			/* current visual depth (not bpp) */
    113 
    114     /* Variables used by the X11 video mode code */
    115 #if SDL_VIDEO_DRIVER_X11_XINERAMA
    116     SDL_NAME(XineramaScreenInfo) xinerama_info;
    117 #endif
    118 #if SDL_VIDEO_DRIVER_X11_XRANDR
    119     XRRScreenConfiguration* screen_config;
    120     int saved_size_id;
    121     Rotation saved_rotation;
    122 #endif
    123 #if SDL_VIDEO_DRIVER_X11_VIDMODE
    124     SDL_NAME(XF86VidModeModeInfo) saved_mode;
    125     struct {
    126         int x, y;
    127     } saved_view;
    128 #endif
    129 #if SDL_VIDEO_DRIVER_X11_XME /* XiG XME fullscreen */
    130     XiGMiscResolutionInfo saved_res;
    131 #endif
    132 
    133     int use_xinerama;
    134     int use_xrandr;
    135     int use_vidmode;
    136     int use_xme;
    137     int currently_fullscreen;
    138 
    139     /* Automatic mode switching support (entering/leaving fullscreen) */
    140     Uint32 switch_waiting;
    141     Uint32 switch_time;
    142 
    143     /* Prevent too many XSync() calls */
    144     int blit_queued;
    145 
    146     /* Colormap handling */
    147     Colormap DisplayColormap;	/* The default display colormap */
    148     Colormap XColorMap;		/* The current window colormap */
    149     int *XPixels;		/* pixels value allocation counts */
    150     float gamma_saved[3];	/* Saved gamma values for VidMode gamma */
    151     int gamma_changed;		/* flag: has VidMode gamma been modified? */
    152 
    153     short *iconcolors;		/* List of colors used by the icon */
    154 
    155     /* Screensaver settings */
    156     int allow_screensaver;
    157 };
    158 
    159 extern int X11_wmXAdjust;
    160 extern int X11_wmYAdjust;
    161 
    162 /* Old variable names */
    163 #define local_X11		(this->hidden->local_X11)
    164 #define SDL_Display		(this->hidden->X11_Display)
    165 #define GFX_Display		(this->hidden->GFX_Display)
    166 #define SDL_Screen		DefaultScreen(this->hidden->X11_Display)
    167 #define SDL_Visual		(this->hidden->vis)
    168 #define SDL_Root		RootWindow(SDL_Display, SDL_Screen)
    169 #define WMwindow		(this->hidden->WMwindow)
    170 #define FSwindow		(this->hidden->FSwindow)
    171 #define SDL_Window		(this->hidden->SDL_Window)
    172 #define WM_DELETE_WINDOW	(this->hidden->WM_DELETE_WINDOW)
    173 #define SDL_BlankCursor		(this->hidden->BlankCursor)
    174 #define SDL_IM			(this->hidden->X11_IM)
    175 #define SDL_IC			(this->hidden->X11_IC)
    176 #define SDL_windowid		(this->hidden->SDL_windowid)
    177 #define using_dga		(this->hidden->using_dga)
    178 #define use_mitshm		(this->hidden->use_mitshm)
    179 #define shminfo			(this->hidden->shminfo)
    180 #define SDL_Ximage		(this->hidden->Ximage)
    181 #define SDL_GC			(this->hidden->gc)
    182 #define window_w		(this->hidden->window_w)
    183 #define window_h		(this->hidden->window_h)
    184 #define mouse_last		(this->hidden->mouse_last)
    185 #define mouse_accel		(this->hidden->mouse_accel)
    186 #define mouse_relative		(this->hidden->mouse_relative)
    187 #define SDL_modelist		(this->hidden->modelist)
    188 #define xinerama_info		(this->hidden->xinerama_info)
    189 #define saved_mode		(this->hidden->saved_mode)
    190 #define saved_view		(this->hidden->saved_view)
    191 #define saved_res		(this->hidden->saved_res)
    192 #define screen_config		(this->hidden->screen_config)
    193 #define saved_size_id		(this->hidden->saved_size_id)
    194 #define saved_rotation		(this->hidden->saved_rotation)
    195 #define use_xinerama		(this->hidden->use_xinerama)
    196 #define use_vidmode		(this->hidden->use_vidmode)
    197 #define use_xrandr		(this->hidden->use_xrandr)
    198 #define use_xme			(this->hidden->use_xme)
    199 #define currently_fullscreen	(this->hidden->currently_fullscreen)
    200 #define switch_waiting		(this->hidden->switch_waiting)
    201 #define switch_time		(this->hidden->switch_time)
    202 #define blit_queued		(this->hidden->blit_queued)
    203 #define SDL_DisplayColormap	(this->hidden->DisplayColormap)
    204 #define SDL_PrivateColormap	(this->hidden->PrivateColormap)
    205 #define SDL_XColorMap		(this->hidden->XColorMap)
    206 #define SDL_XPixels		(this->hidden->XPixels)
    207 #define gamma_saved		(this->hidden->gamma_saved)
    208 #define gamma_changed		(this->hidden->gamma_changed)
    209 #define SDL_iconcolors		(this->hidden->iconcolors)
    210 #define allow_screensaver	(this->hidden->allow_screensaver)
    211 
    212 /* Some versions of XFree86 have bugs - detect if this is one of them */
    213 #define BUGGY_XFREE86(condition, buggy_version) \
    214 ((SDL_strcmp(ServerVendor(SDL_Display), "The XFree86 Project, Inc") == 0) && \
    215  (VendorRelease(SDL_Display) condition buggy_version))
    216 
    217 #endif /* _SDL_x11video_h */
    218