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

Commit

Permalink
Make the X11 SetBordered event tapdancing more robust, restore focus,…
Browse files Browse the repository at this point in the history
… etc.
  • Loading branch information
icculus committed Sep 13, 2012
1 parent dc38242 commit 756088c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/video/x11/SDL_x11sym.h
Expand Up @@ -89,6 +89,7 @@ SDL_X11_SYM(int,XSelectInput,(Display* a,Window b,long c),(a,b,c),return)
SDL_X11_SYM(Status,XSendEvent,(Display* a,Window b,Bool c,long d,XEvent* e),(a,b,c,d,e),return)
SDL_X11_SYM(XErrorHandler,XSetErrorHandler,(XErrorHandler a),(a),return)
SDL_X11_SYM(XIOErrorHandler,XSetIOErrorHandler,(XIOErrorHandler a),(a),return)
SDL_X11_SYM(int,XSetInputFocus,(Display *a,Window b,int c,Time d),(a,b,c,d),return)
SDL_X11_SYM(int,XSetSelectionOwner,(Display* a,Atom b,Window c,Time d),(a,b,c,d),return)
SDL_X11_SYM(int,XSetTransientForHint,(Display* a,Window b,Window c),(a,b,c),return)
SDL_X11_SYM(void,XSetTextProperty,(Display* a,Window b,XTextProperty* c,Atom d),(a,b,c,d),)
Expand Down
22 changes: 18 additions & 4 deletions src/video/x11/SDL_x11window.c
Expand Up @@ -734,20 +734,34 @@ static Bool isConfigureNotify(Display *dpy, XEvent *ev, XPointer win)
void
X11_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
{
const SDL_bool focused = ((window->flags & SDL_WINDOW_INPUT_FOCUS) != 0);
const SDL_bool visible = ((window->flags & SDL_WINDOW_HIDDEN) == 0);
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
SDL_DisplayData *displaydata =
(SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
Display *display = data->videodata->display;
XEvent event;

SetWindowBordered(display, displaydata->screen, data->xwindow, bordered);
XFlush(display);
XIfEvent(display, &event, &isConfigureNotify, (XPointer)&data->xwindow);

/* make sure these don't make it to the real event queue if they fired here. */
while (XCheckIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow)) {}
while (XCheckIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow)) {}
if (visible) {
XWindowAttributes attr;
do {
XSync(display, False);
XGetWindowAttributes(display, data->xwindow, &attr);
} while (attr.map_state != IsViewable);

XFlush(display);
if (focused) {
XSetInputFocus(display, data->xwindow, RevertToParent, CurrentTime);
}
}

/* make sure these don't make it to the real event queue if they fired here. */
XSync(display, False);
XCheckIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);
XCheckIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
}

void
Expand Down

0 comments on commit 756088c

Please sign in to comment.