Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 13 Sep 2012 15:24:04 -0400
changeset 6423339c0ccf6250
parent 6422 fd0ac1b56115
child 6424 bfaafcf78560
Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
src/video/x11/SDL_x11sym.h
src/video/x11/SDL_x11window.c
     1.1 --- a/src/video/x11/SDL_x11sym.h	Thu Sep 13 01:43:53 2012 -0400
     1.2 +++ b/src/video/x11/SDL_x11sym.h	Thu Sep 13 15:24:04 2012 -0400
     1.3 @@ -89,6 +89,7 @@
     1.4  SDL_X11_SYM(Status,XSendEvent,(Display* a,Window b,Bool c,long d,XEvent* e),(a,b,c,d,e),return)
     1.5  SDL_X11_SYM(XErrorHandler,XSetErrorHandler,(XErrorHandler a),(a),return)
     1.6  SDL_X11_SYM(XIOErrorHandler,XSetIOErrorHandler,(XIOErrorHandler a),(a),return)
     1.7 +SDL_X11_SYM(int,XSetInputFocus,(Display *a,Window b,int c,Time d),(a,b,c,d),return)
     1.8  SDL_X11_SYM(int,XSetSelectionOwner,(Display* a,Atom b,Window c,Time d),(a,b,c,d),return)
     1.9  SDL_X11_SYM(int,XSetTransientForHint,(Display* a,Window b,Window c),(a,b,c),return)
    1.10  SDL_X11_SYM(void,XSetTextProperty,(Display* a,Window b,XTextProperty* c,Atom d),(a,b,c,d),)
     2.1 --- a/src/video/x11/SDL_x11window.c	Thu Sep 13 01:43:53 2012 -0400
     2.2 +++ b/src/video/x11/SDL_x11window.c	Thu Sep 13 15:24:04 2012 -0400
     2.3 @@ -734,6 +734,8 @@
     2.4  void
     2.5  X11_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
     2.6  {
     2.7 +    const SDL_bool focused = ((window->flags & SDL_WINDOW_INPUT_FOCUS) != 0);
     2.8 +    const SDL_bool visible = ((window->flags & SDL_WINDOW_HIDDEN) == 0);
     2.9      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    2.10      SDL_DisplayData *displaydata =
    2.11          (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
    2.12 @@ -741,13 +743,25 @@
    2.13      XEvent event;
    2.14  
    2.15      SetWindowBordered(display, displaydata->screen, data->xwindow, bordered);
    2.16 +    XFlush(display);
    2.17      XIfEvent(display, &event, &isConfigureNotify, (XPointer)&data->xwindow);
    2.18  
    2.19 +    if (visible) {
    2.20 +        XWindowAttributes attr;
    2.21 +        do {
    2.22 +            XSync(display, False);
    2.23 +            XGetWindowAttributes(display, data->xwindow, &attr);
    2.24 +        } while (attr.map_state != IsViewable);
    2.25 +
    2.26 +        if (focused) {
    2.27 +            XSetInputFocus(display, data->xwindow, RevertToParent, CurrentTime);
    2.28 +        }
    2.29 +    }
    2.30 +
    2.31      /* make sure these don't make it to the real event queue if they fired here. */
    2.32 -    while (XCheckIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow)) {}
    2.33 -    while (XCheckIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow)) {}
    2.34 -
    2.35 -    XFlush(display);
    2.36 +    XSync(display, False);
    2.37 +    XCheckIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);
    2.38 +    XCheckIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
    2.39  }
    2.40  
    2.41  void