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

Commit

Permalink
Simplified the NetWM code a little bit, and it now operates on X11 Wi…
Browse files Browse the repository at this point in the history
…ndow
  • Loading branch information
slouken committed Sep 28, 2012
1 parent 07d3606 commit cdacf56
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/video/x11/SDL_x11events.c
Expand Up @@ -485,7 +485,7 @@ X11_DispatchEvent(_THIS)
without ever mapping / unmapping them, so we handle that here,
because they use the NETWM protocol to notify us of changes.
*/
Uint32 flags = X11_GetNetWMState(_this, data->window);
Uint32 flags = X11_GetNetWMState(_this, xevent.xproperty.window);
if ((flags^data->window->flags) & SDL_WINDOW_HIDDEN) {
if (flags & SDL_WINDOW_HIDDEN) {
X11_DispatchUnmapNotify(data);
Expand Down
56 changes: 19 additions & 37 deletions src/video/x11/SDL_x11window.c
Expand Up @@ -114,15 +114,18 @@ X11_IsActionAllowed(SDL_Window *window, Atom action)
return ret;
}

int
X11_GetWMStateProperty(_THIS, Uint32 flags, Atom atoms[5])
void
X11_SetNetWMState(_THIS, Window xwindow, Uint32 flags)
{
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
Display *display = videodata->display;
Atom _NET_WM_STATE = videodata->_NET_WM_STATE;
/*Atom _NET_WM_STATE_HIDDEN = videodata->_NET_WM_STATE_HIDDEN;*/
Atom _NET_WM_STATE_FOCUSED = videodata->_NET_WM_STATE_FOCUSED;
Atom _NET_WM_STATE_MAXIMIZED_VERT = videodata->_NET_WM_STATE_MAXIMIZED_VERT;
Atom _NET_WM_STATE_MAXIMIZED_HORZ = videodata->_NET_WM_STATE_MAXIMIZED_HORZ;
Atom _NET_WM_STATE_FULLSCREEN = videodata->_NET_WM_STATE_FULLSCREEN;
Atom atoms[5];
int count = 0;

/* The window manager sets this property, we shouldn't set it.
Expand All @@ -143,14 +146,19 @@ X11_GetWMStateProperty(_THIS, Uint32 flags, Atom atoms[5])
if (flags & SDL_WINDOW_FULLSCREEN) {
atoms[count++] = _NET_WM_STATE_FULLSCREEN;
}
return count;
if (count > 0) {
XChangeProperty(display, xwindow, _NET_WM_STATE, XA_ATOM, 32,
PropModeReplace, (unsigned char *)atoms, count);
} else {
XDeleteProperty(display, xwindow, _NET_WM_STATE);
}
}

Uint32
X11_GetNetWMState(_THIS, SDL_Window * window)
X11_GetNetWMState(_THIS, Window xwindow)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
Display *display = videodata->display;
Atom _NET_WM_STATE = videodata->_NET_WM_STATE;
Atom _NET_WM_STATE_HIDDEN = videodata->_NET_WM_STATE_HIDDEN;
Atom _NET_WM_STATE_FOCUSED = videodata->_NET_WM_STATE_FOCUSED;
Expand All @@ -164,7 +172,7 @@ X11_GetNetWMState(_THIS, SDL_Window * window)
long maxLength = 1024;
Uint32 flags = 0;

if (XGetWindowProperty(videodata->display, data->xwindow, _NET_WM_STATE,
if (XGetWindowProperty(display, xwindow, _NET_WM_STATE,
0l, maxLength, False, XA_ATOM, &actualType,
&actualFormat, &numItems, &bytesAfter,
&propertyValue) == Success) {
Expand Down Expand Up @@ -214,8 +222,6 @@ SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created)
SDL_OutOfMemory();
return -1;
}
window->driverdata = data;

data->window = window;
data->xwindow = w;
#ifdef X_HAVE_UTF8_STRING
Expand Down Expand Up @@ -269,7 +275,7 @@ SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created)
data->colormap = attrib.colormap;
}

window->flags |= X11_GetNetWMState(_this, window);
window->flags |= X11_GetNetWMState(_this, w);

{
Window FocalWindow;
Expand All @@ -290,6 +296,7 @@ SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created)
}

/* All done! */
window->driverdata = data;
return 0;
}

Expand Down Expand Up @@ -342,8 +349,6 @@ X11_CreateWindow(_THIS, SDL_Window * window)
Atom _NET_WM_WINDOW_TYPE;
Atom _NET_WM_WINDOW_TYPE_NORMAL;
Atom _NET_WM_PID;
int wmstate_count;
Atom wmstate_atoms[5];
Uint32 fevent = 0;

#if SDL_VIDEO_OPENGL_GLX || SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
Expand Down Expand Up @@ -528,14 +533,7 @@ X11_CreateWindow(_THIS, SDL_Window * window)
}

/* Set the window manager state */
wmstate_count = X11_GetWMStateProperty(_this, window->flags, wmstate_atoms);
if (wmstate_count > 0) {
XChangeProperty(display, w, data->_NET_WM_STATE, XA_ATOM, 32,
PropModeReplace,
(unsigned char *)wmstate_atoms, wmstate_count);
} else {
XDeleteProperty(display, w, data->_NET_WM_STATE);
}
X11_SetNetWMState(_this, w, window->flags);

/* Let the window manager know we're a "normal" window */
_NET_WM_WINDOW_TYPE = XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
Expand Down Expand Up @@ -875,23 +873,15 @@ SetWindowMaximized(_THIS, SDL_Window * window, SDL_bool maximized)
XSendEvent(display, RootWindow(display, displaydata->screen), 0,
SubstructureNotifyMask | SubstructureRedirectMask, &e);
} else {
int count;
Uint32 flags;
Atom atoms[5];

flags = window->flags;
if (maximized) {
flags |= SDL_WINDOW_MAXIMIZED;
} else {
flags &= ~SDL_WINDOW_MAXIMIZED;
}
count = X11_GetWMStateProperty(_this, flags, atoms);
if (count > 0) {
XChangeProperty(display, data->xwindow, _NET_WM_STATE, XA_ATOM, 32,
PropModeReplace, (unsigned char *)atoms, count);
} else {
XDeleteProperty(display, data->xwindow, _NET_WM_STATE);
}
X11_SetNetWMState(_this, data->xwindow, flags);
}
XFlush(display);
}
Expand Down Expand Up @@ -970,23 +960,15 @@ X11_SetWindowFullscreenViaWM(_THIS, SDL_Window * window, SDL_VideoDisplay * _dis
XSendEvent(display, RootWindow(display, displaydata->screen), 0,
SubstructureNotifyMask | SubstructureRedirectMask, &e);
} else {
int count;
Uint32 flags;
Atom atoms[5];

flags = window->flags;
if (fullscreen) {
flags |= SDL_WINDOW_FULLSCREEN;
} else {
flags &= ~SDL_WINDOW_FULLSCREEN;
}
count = X11_GetWMStateProperty(_this, flags, atoms);
if (count > 0) {
XChangeProperty(display, data->xwindow, _NET_WM_STATE, XA_ATOM, 32,
PropModeReplace, (unsigned char *)atoms, count);
} else {
XDeleteProperty(display, data->xwindow, _NET_WM_STATE);
}
X11_SetNetWMState(_this, data->xwindow, flags);
}
XFlush(display);
}
Expand Down
4 changes: 2 additions & 2 deletions src/video/x11/SDL_x11window.h
Expand Up @@ -42,8 +42,8 @@ typedef struct
struct SDL_VideoData *videodata;
} SDL_WindowData;

extern int X11_GetWMStateProperty(_THIS, Uint32 flags, Atom atoms[5]);
extern Uint32 X11_GetNetWMState(_THIS, SDL_Window * window);
extern void X11_SetNetWMState(_THIS, Window xwindow, Uint32 flags);
extern Uint32 X11_GetNetWMState(_THIS, Window xwindow);

extern int X11_CreateWindow(_THIS, SDL_Window * window);
extern int X11_CreateWindowFrom(_THIS, SDL_Window * window, const void *data);
Expand Down

0 comments on commit cdacf56

Please sign in to comment.