Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/video/x11/SDL_x11events.c
Original file line number Diff line number Diff line change
Expand Up @@ -2085,6 +2085,36 @@ static void X11_DispatchEvent(SDL_VideoDevice *_this, XEvent *xevent)
if (changed & SDL_WINDOW_OCCLUDED) {
SDL_SendWindowEvent(data->window, (flags & SDL_WINDOW_OCCLUDED) ? SDL_EVENT_WINDOW_OCCLUDED : SDL_EVENT_WINDOW_EXPOSED, 0, 0);
}
} else if (xevent->xproperty.atom == videodata->atoms.WM_STATE) {
/* Support for ICCCM-compliant window managers (like i3) that change
WM_STATE to WithdrawnState without sending UnmapNotify or updating
_NET_WM_STATE when moving windows to invisible workspaces. */
Atom type;
int format;
unsigned long nitems, bytes_after;
unsigned char *prop_data = NULL;

if (X11_XGetWindowProperty(display, data->xwindow, videodata->atoms.WM_STATE,
0L, 2L, False, videodata->atoms.WM_STATE,
&type, &format, &nitems, &bytes_after, &prop_data) == Success) {
if (nitems > 0) {
// WM_STATE: 0=Withdrawn, 1=Normal, 3=Iconic
Uint32 state = *(Uint32 *)prop_data;

if (state == 0 || state == 3) { // Withdrawn or Iconic
if (!(data->window->flags & SDL_WINDOW_MINIMIZED)) {
SDL_SendWindowEvent(data->window, SDL_EVENT_WINDOW_MINIMIZED, 0, 0);
SDL_SendWindowEvent(data->window, SDL_EVENT_WINDOW_OCCLUDED, 0, 0);
}
} else if (state == 1) { // NormalState
if (data->window->flags & SDL_WINDOW_MINIMIZED) {
SDL_SendWindowEvent(data->window, SDL_EVENT_WINDOW_RESTORED, 0, 0);
SDL_SendWindowEvent(data->window, SDL_EVENT_WINDOW_EXPOSED, 0, 0);
}
}
}
X11_XFree(prop_data);
}
} else if (xevent->xproperty.atom == videodata->atoms.XKLAVIER_STATE) {
/* Hack for Ubuntu 12.04 (etc) that doesn't send MappingNotify
events when the keyboard layout changes (for example,
Expand Down
1 change: 1 addition & 0 deletions src/video/x11/SDL_x11video.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ static bool X11_VideoInit(SDL_VideoDevice *_this)
GET_ATOM(WM_TAKE_FOCUS);
GET_ATOM(WM_NAME);
GET_ATOM(WM_TRANSIENT_FOR);
GET_ATOM(WM_STATE);
GET_ATOM(_NET_WM_STATE);
GET_ATOM(_NET_WM_STATE_HIDDEN);
GET_ATOM(_NET_WM_STATE_FOCUSED);
Expand Down
1 change: 1 addition & 0 deletions src/video/x11/SDL_x11video.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct SDL_VideoData
Atom WM_TAKE_FOCUS;
Atom WM_NAME;
Atom WM_TRANSIENT_FOR;
Atom WM_STATE;
Atom _NET_WM_STATE;
Atom _NET_WM_STATE_HIDDEN;
Atom _NET_WM_STATE_FOCUSED;
Expand Down
Loading