Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Lots of prep for the "real" way to support fullscreen mode on modern …
Browse files Browse the repository at this point in the history
…window managers.

Unfortunately, this doesn't work.  I also noticed that maximizing doesn't work as well.  Also xprop hangs when trying to list properties of SDL windows.... ???
  • Loading branch information
slouken committed Jul 14, 2010
1 parent 1cc0dad commit 5a4df8f
Show file tree
Hide file tree
Showing 7 changed files with 242 additions and 70 deletions.
62 changes: 56 additions & 6 deletions src/video/x11/SDL_x11events.c
Expand Up @@ -34,18 +34,19 @@
#include "SDL_timer.h"
#include "SDL_syswm.h"

/*#define DEBUG_XEVENTS*/
#define DEBUG_XEVENTS

static void
X11_DispatchEvent(_THIS)
{
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
Display *display = videodata->display;
SDL_WindowData *data;
XEvent xevent;
int i;

SDL_zero(xevent); /* valgrind fix. --ryan. */
XNextEvent(videodata->display, &xevent);
XNextEvent(display, &xevent);

/* filter events catchs XIM events and sends them to the correct
handler */
Expand Down Expand Up @@ -80,6 +81,7 @@ X11_DispatchEvent(_THIS)
if (!data) {
return;
}

#if 0
printf("type = %d display = %d window = %d\n",
xevent.type, xevent.xany.display, xevent.xany.window);
Expand Down Expand Up @@ -182,9 +184,8 @@ X11_DispatchEvent(_THIS)
#if 0
if (videodata->key_layout[keycode] == SDLK_UNKNOWN) {
int min_keycode, max_keycode;
XDisplayKeycodes(videodata->display, &min_keycode,
&max_keycode);
keysym = XKeycodeToKeysym(videodata->display, keycode, 0);
XDisplayKeycodes(display, &min_keycode, &max_keycode);
keysym = XKeycodeToKeysym(display, keycode, 0);
fprintf(stderr,
"The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <sdl@libsdl.org> X11 KeyCode %d (%d), X11 KeySym 0x%X (%s).\n",
keycode, keycode - min_keycode, keysym,
Expand Down Expand Up @@ -289,9 +290,58 @@ X11_DispatchEvent(_THIS)
}
break;

case PropertyNotify:{
#ifdef DEBUG_XEVENTS
char *name = XGetAtomName(display, xevent.xproperty.atom);
printf("PropertyNotify (atom = %s)\n", name ? name : "NULL");
if (name) {
XFree(name);
}
#endif
if (xevent.xproperty.atom == videodata->_NET_WM_STATE) {
unsigned char *propdata;
int status, real_format;
Atom real_type;
unsigned long items_read, items_left, i;

#ifdef DEBUG_XEVENTS
printf("_NET_WM_STATE: {");
#endif
status = XGetWindowProperty(display, data->xwindow, videodata->_NET_WM_STATE, 0L, 8192L, False, XA_ATOM, &real_type, &real_format, &items_read, &items_left, &propdata);
if (status == Success) {
Atom *atoms = (Atom *)propdata;
for (i = 0; i < items_read; i++) {
if (atoms[i] == videodata->_NET_WM_STATE_HIDDEN) {
#ifdef DEBUG_XEVENTS
printf(" _NET_WM_STATE_HIDDEN");
#endif
}
if (atoms[i] == videodata->_NET_WM_STATE_MAXIMIZED_HORZ) {
#ifdef DEBUG_XEVENTS
printf(" _NET_WM_STATE_MAXIMIZED_HORZ");
#endif
}
if (atoms[i] == videodata->_NET_WM_STATE_MAXIMIZED_VERT) {
#ifdef DEBUG_XEVENTS
printf(" _NET_WM_STATE_MAXIMIZED_VERT");
#endif
}
if (atoms[i] == videodata->_NET_WM_STATE_FULLSCREEN) {
#ifdef DEBUG_XEVENTS
printf(" _NET_WM_STATE_FULLSCREEN");
#endif
}
}
}
#ifdef DEBUG_XEVENTS
printf(" }\n");
#endif
}
}
break;

/* Copy the selection from XA_CUT_BUFFER0 to the requested property */
case SelectionRequest: {
Display *display = videodata->display;
XSelectionRequestEvent *req;
XEvent sevent;
int seln_format;
Expand Down
5 changes: 4 additions & 1 deletion src/video/x11/SDL_x11modes.c
Expand Up @@ -23,7 +23,7 @@

#include "SDL_x11video.h"

//#define X11MODES_DEBUG
#define X11MODES_DEBUG
#undef SDL_VIDEO_DRIVER_X11_XINERAMA
#undef SDL_VIDEO_DRIVER_X11_XRANDR
#undef SDL_VIDEO_DRIVER_X11_VIDMODE
Expand Down Expand Up @@ -253,6 +253,7 @@ CheckVidMode(Display * display, int *major, int *minor)
return SDL_TRUE;
}

static
Bool SDL_NAME(XF86VidModeGetModeInfo) (Display * dpy, int scr,
SDL_NAME(XF86VidModeModeInfo) * info)
{
Expand Down Expand Up @@ -296,6 +297,7 @@ save_mode(Display * display, SDL_DisplayData * data)
&data->saved_view.y);
}

/*
static void
restore_mode(Display * display, SDL_DisplayData * data)
{
Expand All @@ -313,6 +315,7 @@ restore_mode(Display * display, SDL_DisplayData * data)
data->saved_view.y);
}
}
*/
#endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */

void
Expand Down
2 changes: 2 additions & 0 deletions src/video/x11/SDL_x11sym.h
Expand Up @@ -67,12 +67,14 @@ SDL_X11_SYM(int,XFreeCursor,(Display* a,Cursor b),(a,b),return)
SDL_X11_SYM(int,XFreeGC,(Display* a,GC b),(a,b),return)
SDL_X11_SYM(int,XFreeModifiermap,(XModifierKeymap* a),(a),return)
SDL_X11_SYM(int,XFreePixmap,(Display* a,Pixmap b),(a,b),return)
SDL_X11_SYM(char*,XGetAtomName,(Display *a,Atom b),(a,b),return)
SDL_X11_SYM(int,XGetErrorDatabaseText,(Display* a,_Xconst char* b,_Xconst char* c,_Xconst char* d,char* e,int f),(a,b,c,d,e,f),return)
SDL_X11_SYM(XImage*,XGetImage,(Display* a,Drawable b,int c,int d,unsigned int e,unsigned int f,unsigned long g, int h),(a,b,c,d,e,f,g,h),return)
SDL_X11_SYM(XModifierKeymap*,XGetModifierMapping,(Display* a),(a),return)
SDL_X11_SYM(int,XGetPointerControl,(Display* a,int* b,int* c,int* d),(a,b,c,d),return)
SDL_X11_SYM(int,XGetRGBColormaps,(Display* a,Window b,XStandardColormap **c,int *d,Atom e),(a,b,c,d,e),return)
SDL_X11_SYM(Window,XGetSelectionOwner,(Display* a,Atom b),(a,b),return)
SDL_X11_SYM(Status,XGetTextProperty,(Display *a,Window b,XTextProperty *c,Atom d),(a,b,c,d),return)
SDL_X11_SYM(XVisualInfo*,XGetVisualInfo,(Display* a,long b,XVisualInfo* c,int* d),(a,b,c,d),return)
SDL_X11_SYM(Status,XGetWindowAttributes,(Display* a,Window b,XWindowAttributes* c),(a,b,c),return)
SDL_X11_SYM(int,XGetWindowProperty,(Display* a,Window b,Atom c,long d,long e,Bool f,Atom g,Atom* h,int* i,unsigned long* j,unsigned long *k,unsigned char **l),(a,b,c,d,e,f,g,h,i,j,k,l),return)
Expand Down
53 changes: 51 additions & 2 deletions src/video/x11/SDL_x11video.c
Expand Up @@ -242,6 +242,43 @@ VideoBootStrap X11_bootstrap = {
};


static void
X11_CheckWindowManager(_THIS)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
Display *display = data->display;
Atom _NET_SUPPORTING_WM_CHECK;
int status, real_format;
Atom real_type;
unsigned long items_read, items_left;
unsigned char *propdata;
Window wm_window = 0;
#ifdef DEBUG_WINDOW_MANAGER
char *wm_name;
#endif

_NET_SUPPORTING_WM_CHECK = XInternAtom(display, "_NET_SUPPORTING_WM_CHECK", False);
status = XGetWindowProperty(display, DefaultRootWindow(display), _NET_SUPPORTING_WM_CHECK, 0L, 1L, False, XA_WINDOW, &real_type, &real_format, &items_read, &items_left, &propdata);
if (status == Success && items_read) {
wm_window = ((Window*)propdata)[0];
}
XFree(propdata);

if (!wm_window) {
#ifdef DEBUG_WINDOW_MANAGER
printf("Couldn't get _NET_SUPPORTING_WM_CHECK property\n");
#endif
return;
}
data->net_wm = SDL_TRUE;

#ifdef DEBUG_WINDOW_MANAGER
wm_name = X11_GetWindowTitle(_this, wm_window);
printf("Window manager: %s\n", wm_name);
SDL_free(wm_name);
#endif
}

int
X11_VideoInit(_THIS)
{
Expand All @@ -259,8 +296,20 @@ X11_VideoInit(_THIS)
#endif

/* Look up some useful Atoms */
data->WM_DELETE_WINDOW =
XInternAtom(data->display, "WM_DELETE_WINDOW", False);
#define GET_ATOM(X) data->X = XInternAtom(data->display, #X, False)
GET_ATOM(WM_DELETE_WINDOW);
GET_ATOM(_NET_WM_STATE);
GET_ATOM(_NET_WM_STATE_HIDDEN);
GET_ATOM(_NET_WM_STATE_MAXIMIZED_VERT);
GET_ATOM(_NET_WM_STATE_MAXIMIZED_HORZ);
GET_ATOM(_NET_WM_STATE_FULLSCREEN);
GET_ATOM(_NET_WM_NAME);
GET_ATOM(_NET_WM_ICON_NAME);
GET_ATOM(_NET_WM_ICON);
GET_ATOM(UTF8_STRING);

/* Detect the window manager */
X11_CheckWindowManager(_this);

if (X11_InitModes(_this) < 0) {
return -1;
Expand Down
15 changes: 15 additions & 0 deletions src/video/x11/SDL_x11video.h
Expand Up @@ -68,7 +68,22 @@ typedef struct SDL_VideoData
int numwindows;
SDL_WindowData **windowlist;
int windowlistlength;

/* This is true for ICCCM2.0-compliant window managers */
SDL_bool net_wm;

/* Useful atoms */
Atom WM_DELETE_WINDOW;
Atom _NET_WM_STATE;
Atom _NET_WM_STATE_HIDDEN;
Atom _NET_WM_STATE_MAXIMIZED_VERT;
Atom _NET_WM_STATE_MAXIMIZED_HORZ;
Atom _NET_WM_STATE_FULLSCREEN;
Atom _NET_WM_NAME;
Atom _NET_WM_ICON_NAME;
Atom _NET_WM_ICON;
Atom UTF8_STRING;

SDL_scancode key_layout[256];
SDL_bool selection_waiting;
} SDL_VideoData;
Expand Down

0 comments on commit 5a4df8f

Please sign in to comment.