Added SDL_WINDOWEVENT_TAKE_FOCUS.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 05 Jan 2016 02:27:50 -0500
changeset 100294c992fd19316
parent 10028 da668b612d10
child 10030 061b1b467bd3
Added SDL_WINDOWEVENT_TAKE_FOCUS.

This is for corner cases where a multi-window app is activated and wants to
make a decision about where focus should go.

This patch came from Unreal Engine 4's fork of SDL, compliments of Epic Games.
include/SDL_video.h
src/video/x11/SDL_x11events.c
src/video/x11/SDL_x11video.c
src/video/x11/SDL_x11video.h
src/video/x11/SDL_x11window.c
     1.1 --- a/include/SDL_video.h	Tue Apr 21 10:10:59 2015 -0400
     1.2 +++ b/include/SDL_video.h	Tue Jan 05 02:27:50 2016 -0500
     1.3 @@ -161,7 +161,8 @@
     1.4      SDL_WINDOWEVENT_FOCUS_GAINED,   /**< Window has gained keyboard focus */
     1.5      SDL_WINDOWEVENT_FOCUS_LOST,     /**< Window has lost keyboard focus */
     1.6      SDL_WINDOWEVENT_CLOSE,          /**< The window manager requests that the window be closed */
     1.7 -    SDL_WINDOWEVENT_HIT_TEST        /** Window had a hit test that wasn't SDL_HITTEST_NORMAL. */
     1.8 +    SDL_WINDOWEVENT_TAKE_FOCUS,     /**< Window is being offered a focus (should SetWindowInputFocus() on itself or a subwindow, or ignore) */
     1.9 +    SDL_WINDOWEVENT_HIT_TEST        /**< Window had a hit test that wasn't SDL_HITTEST_NORMAL. */
    1.10  } SDL_WindowEventID;
    1.11  
    1.12  /**
     2.1 --- a/src/video/x11/SDL_x11events.c	Tue Apr 21 10:10:59 2015 -0400
     2.2 +++ b/src/video/x11/SDL_x11events.c	Tue Jan 05 02:27:50 2016 -0500
     2.3 @@ -979,6 +979,16 @@
     2.4                  SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
     2.5                  break;
     2.6              }
     2.7 +            else if ((xevent.xclient.message_type == videodata->WM_PROTOCOLS) &&
     2.8 +                (xevent.xclient.format == 32) &&
     2.9 +                (xevent.xclient.data.l[0] == videodata->WM_TAKE_FOCUS)) {
    2.10 +
    2.11 +#ifdef DEBUG_XEVENTS
    2.12 +                printf("window %p: WM_TAKE_FOCUS\n", data);
    2.13 +#endif
    2.14 +                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_TAKE_FOCUS, 0, 0);
    2.15 +                break;
    2.16 +            }
    2.17          }
    2.18          break;
    2.19  
     3.1 --- a/src/video/x11/SDL_x11video.c	Tue Apr 21 10:10:59 2015 -0400
     3.2 +++ b/src/video/x11/SDL_x11video.c	Tue Jan 05 02:27:50 2016 -0500
     3.3 @@ -395,6 +395,7 @@
     3.4  #define GET_ATOM(X) data->X = X11_XInternAtom(data->display, #X, False)
     3.5      GET_ATOM(WM_PROTOCOLS);
     3.6      GET_ATOM(WM_DELETE_WINDOW);
     3.7 +    GET_ATOM(WM_TAKE_FOCUS);
     3.8      GET_ATOM(_NET_WM_STATE);
     3.9      GET_ATOM(_NET_WM_STATE_HIDDEN);
    3.10      GET_ATOM(_NET_WM_STATE_FOCUSED);
     4.1 --- a/src/video/x11/SDL_x11video.h	Tue Apr 21 10:10:59 2015 -0400
     4.2 +++ b/src/video/x11/SDL_x11video.h	Tue Jan 05 02:27:50 2016 -0500
     4.3 @@ -89,6 +89,7 @@
     4.4      /* Useful atoms */
     4.5      Atom WM_PROTOCOLS;
     4.6      Atom WM_DELETE_WINDOW;
     4.7 +    Atom WM_TAKE_FOCUS;
     4.8      Atom _NET_WM_STATE;
     4.9      Atom _NET_WM_STATE_HIDDEN;
    4.10      Atom _NET_WM_STATE_FOCUSED;
     5.1 --- a/src/video/x11/SDL_x11window.c	Tue Apr 21 10:10:59 2015 -0400
     5.2 +++ b/src/video/x11/SDL_x11window.c	Tue Jan 05 02:27:50 2016 -0500
     5.3 @@ -574,18 +574,17 @@
     5.4                      (unsigned char *)&compositor, 1);
     5.5  
     5.6      {
     5.7 -        Atom protocols[2];
     5.8 +        Atom protocols[3];
     5.9          int proto_count = 0;
    5.10          const char *ping_hint;
    5.11  
    5.12 -        protocols[proto_count] = data->WM_DELETE_WINDOW; /* Allow window to be deleted by the WM */
    5.13 -        proto_count++;
    5.14 -        
    5.15 +        protocols[proto_count++] = data->WM_DELETE_WINDOW; /* Allow window to be deleted by the WM */
    5.16 +        protocols[proto_count++] = data->WM_TAKE_FOCUS; /* Since we will want to set input focus explicitly */
    5.17 +
    5.18          ping_hint = SDL_GetHint(SDL_HINT_VIDEO_X11_NET_WM_PING);
    5.19          /* Default to using ping if there is no hint */
    5.20          if (!ping_hint || SDL_atoi(ping_hint)) {
    5.21 -            protocols[proto_count] = data->_NET_WM_PING; /* Respond so WM knows we're alive */
    5.22 -            proto_count++;
    5.23 +            protocols[proto_count++] = data->_NET_WM_PING; /* Respond so WM knows we're alive */
    5.24          }
    5.25  
    5.26          SDL_assert(proto_count <= sizeof(protocols) / sizeof(protocols[0]));