src/video/wayland/SDL_waylandwindow.c
changeset 10614 63c2c6c8762c
parent 10492 786e10ab72d8
child 10737 3406a0f8b041
     1.1 --- a/src/video/wayland/SDL_waylandwindow.c	Tue Nov 15 01:14:30 2016 -0800
     1.2 +++ b/src/video/wayland/SDL_waylandwindow.c	Sun Nov 13 10:39:04 2016 +0100
     1.3 @@ -31,6 +31,7 @@
     1.4  #include "SDL_waylandvideo.h"
     1.5  #include "SDL_waylandtouch.h"
     1.6  #include "SDL_waylanddyn.h"
     1.7 +#include "SDL_hints.h"
     1.8  
     1.9  static void
    1.10  handle_ping(void *data, struct wl_shell_surface *shell_surface,
    1.11 @@ -157,6 +158,71 @@
    1.12      WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
    1.13  }
    1.14  
    1.15 +#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
    1.16 +static void QtExtendedSurface_OnHintChanged(void *userdata, const char *name,
    1.17 +        const char *oldValue, const char *newValue)
    1.18 +{
    1.19 +    struct qt_extended_surface *qt_extended_surface = userdata;
    1.20 +
    1.21 +    if (name == NULL) {
    1.22 +        return;
    1.23 +    }
    1.24 +
    1.25 +    if (strcmp(name, SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION) == 0) {
    1.26 +        int32_t orientation = QT_EXTENDED_SURFACE_ORIENTATION_PRIMARYORIENTATION;
    1.27 +
    1.28 +        if (newValue != NULL) {
    1.29 +            if (strcmp(newValue, "portrait") == 0) {
    1.30 +                orientation = QT_EXTENDED_SURFACE_ORIENTATION_PORTRAITORIENTATION;
    1.31 +            } else if (strcmp(newValue, "landscape") == 0) {
    1.32 +                orientation = QT_EXTENDED_SURFACE_ORIENTATION_LANDSCAPEORIENTATION;
    1.33 +            } else if (strcmp(newValue, "inverted-portrait") == 0) {
    1.34 +                orientation = QT_EXTENDED_SURFACE_ORIENTATION_INVERTEDPORTRAITORIENTATION;
    1.35 +            } else if (strcmp(newValue, "inverted-landscape") == 0) {
    1.36 +                orientation = QT_EXTENDED_SURFACE_ORIENTATION_INVERTEDLANDSCAPEORIENTATION;
    1.37 +            }
    1.38 +        }
    1.39 +
    1.40 +        qt_extended_surface_set_content_orientation(qt_extended_surface, orientation);
    1.41 +    } else if (strcmp(name, SDL_HINT_QTWAYLAND_WINDOW_FLAGS) == 0) {
    1.42 +        uint32_t flags = 0;
    1.43 +
    1.44 +        if (newValue != NULL) {
    1.45 +            char *tmp = strdup(newValue);
    1.46 +            char *saveptr = NULL;
    1.47 +
    1.48 +            char *flag = strtok_r(tmp, " ", &saveptr);
    1.49 +            while (flag) {
    1.50 +                if (strcmp(flag, "OverridesSystemGestures") == 0) {
    1.51 +                    flags |= QT_EXTENDED_SURFACE_WINDOWFLAG_OVERRIDESSYSTEMGESTURES;
    1.52 +                } else if (strcmp(flag, "StaysOnTop") == 0) {
    1.53 +                    flags |= QT_EXTENDED_SURFACE_WINDOWFLAG_STAYSONTOP;
    1.54 +                } else if (strcmp(flag, "BypassWindowManager") == 0) {
    1.55 +                    // See https://github.com/qtproject/qtwayland/commit/fb4267103d
    1.56 +                    flags |= 4 /* QT_EXTENDED_SURFACE_WINDOWFLAG_BYPASSWINDOWMANAGER */;
    1.57 +                }
    1.58 +
    1.59 +                flag = strtok_r(NULL, " ", &saveptr);
    1.60 +            }
    1.61 +
    1.62 +            free(tmp);
    1.63 +        }
    1.64 +
    1.65 +        qt_extended_surface_set_window_flags(qt_extended_surface, flags);
    1.66 +    }
    1.67 +}
    1.68 +
    1.69 +static void QtExtendedSurface_Subscribe(struct qt_extended_surface *surface, const char *name)
    1.70 +{
    1.71 +    SDL_AddHintCallback(name, QtExtendedSurface_OnHintChanged, surface);
    1.72 +}
    1.73 +
    1.74 +static void QtExtendedSurface_Unsubscribe(struct qt_extended_surface *surface, const char *name)
    1.75 +{
    1.76 +    SDL_DelHintCallback(name, QtExtendedSurface_OnHintChanged, surface);
    1.77 +}
    1.78 +#endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
    1.79 +
    1.80  void
    1.81  Wayland_SetWindowFullscreen(_THIS, SDL_Window * window,
    1.82                              SDL_VideoDisplay * _display, SDL_bool fullscreen)
    1.83 @@ -227,10 +293,13 @@
    1.84      data->shell_surface = wl_shell_get_shell_surface(c->shell,
    1.85                                                       data->surface);
    1.86      wl_shell_surface_set_class (data->shell_surface, c->classname);
    1.87 -#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH    
    1.88 +#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
    1.89      if (c->surface_extension) {
    1.90          data->extended_surface = qt_surface_extension_get_extended_surface(
    1.91                  c->surface_extension, data->surface);
    1.92 +
    1.93 +        QtExtendedSurface_Subscribe(data->extended_surface, SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION);
    1.94 +        QtExtendedSurface_Subscribe(data->extended_surface, SDL_HINT_QTWAYLAND_WINDOW_FLAGS);
    1.95      }
    1.96  #endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
    1.97  
    1.98 @@ -310,8 +379,11 @@
    1.99              wl_shell_surface_destroy(wind->shell_surface);
   1.100  
   1.101  #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
   1.102 -        if (wind->extended_surface)
   1.103 +        if (wind->extended_surface) {
   1.104 +            QtExtendedSurface_Unsubscribe(wind->extended_surface, SDL_HINT_QTWAYLAND_CONTENT_ORIENTATION);
   1.105 +            QtExtendedSurface_Unsubscribe(wind->extended_surface, SDL_HINT_QTWAYLAND_WINDOW_FLAGS);
   1.106              qt_extended_surface_destroy(wind->extended_surface);
   1.107 +        }
   1.108  #endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */
   1.109          wl_surface_destroy(wind->surface);
   1.110