From eea76fc199f8c9022d77e9555dcbeff11aefeb7c Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 7 Oct 2016 18:11:03 -0700 Subject: [PATCH] Fixed bug 3063 - Wayland: SDL resizes EGL surface to 0x0. x414e54 Wayland will sometimes send empty resize events (0 width and 0 height) to the client. I have not worked out the exact conditions a client would receive these but I can assume it might be if the window is offscreen or not mapped yet. This causes issues with some SDL clients as they receive the 0x0 event and unexpected resize event or might not request to resize back to the correct size. As per the wl_shell Wayland spec configure events are only a suggestion and the client is free to ignore or pick a different size (this is how min/max and fixed aspect ratio is supped to be implemented). A patch is attached but is just the first iteration and I will fix any issues such as checking for FULLSCREEN/MAXIMIZED or RESIZABLE flags unless someone else fixes this first. I have update to take into account non resizable and fullscreen windows. Also adding in maximize/restore and title functions for Wayland. --- src/video/wayland/SDL_waylandvideo.c | 3 ++ src/video/wayland/SDL_waylandwindow.c | 58 +++++++++++++++++++++++++++ src/video/wayland/SDL_waylandwindow.h | 3 ++ 3 files changed, 64 insertions(+) diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c index 548704e2b6f3d..0660ae23a3e87 100644 --- a/src/video/wayland/SDL_waylandvideo.c +++ b/src/video/wayland/SDL_waylandvideo.c @@ -169,7 +169,10 @@ Wayland_CreateDevice(int devindex) device->CreateWindow = Wayland_CreateWindow; device->ShowWindow = Wayland_ShowWindow; device->SetWindowFullscreen = Wayland_SetWindowFullscreen; + device->MaximizeWindow = Wayland_MaximizeWindow; + device->RestoreWindow = Wayland_RestoreWindow; device->SetWindowSize = Wayland_SetWindowSize; + device->SetWindowTitle = Wayland_SetWindowTitle; device->DestroyWindow = Wayland_DestroyWindow; device->SetWindowHitTest = Wayland_SetWindowHitTest; diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c index 197600da78a72..85fca8de67f9a 100644 --- a/src/video/wayland/SDL_waylandwindow.c +++ b/src/video/wayland/SDL_waylandwindow.c @@ -47,6 +47,33 @@ handle_configure(void *data, struct wl_shell_surface *shell_surface, SDL_Window *window = wind->sdlwindow; struct wl_region *region; + /* wl_shell_surface spec states that this is a suggestion. + Ignore if less than or greater than max/min size. */ + + if (width == 0 || height == 0) { + return; + } + + if (!(window->flags & SDL_WINDOW_FULLSCREEN)) { + if ((window->flags & SDL_WINDOW_RESIZABLE)) { + if (window->max_w > 0) { + width = SDL_min(width, window->max_w); + } + width = SDL_max(width, window->min_w); + + if (window->max_h > 0) { + height = SDL_min(height, window->max_h); + } + height = SDL_max(height, window->min_h); + } else { + return; + } + } + + if (width == window->w && height == window->h) { + return; + } + window->w = width; window->h = height; WAYLAND_wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0); @@ -146,6 +173,26 @@ Wayland_SetWindowFullscreen(_THIS, SDL_Window * window, WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); } +void +Wayland_RestoreWindow(_THIS, SDL_Window * window) +{ + SDL_WindowData *wind = window->driverdata; + + wl_shell_surface_set_toplevel(wind->shell_surface); + + WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); +} + +void +Wayland_MaximizeWindow(_THIS, SDL_Window * window) +{ + SDL_WindowData *wind = window->driverdata; + + wl_shell_surface_set_maximized(wind->shell_surface, NULL); + + WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); +} + int Wayland_CreateWindow(_THIS, SDL_Window *window) { SDL_WindowData *data; @@ -239,6 +286,17 @@ void Wayland_SetWindowSize(_THIS, SDL_Window * window) wl_region_destroy(region); } +void Wayland_SetWindowTitle(_THIS, SDL_Window * window) +{ + SDL_WindowData *wind = window->driverdata; + + if (window->title != NULL) { + wl_shell_surface_set_title(wind->shell_surface, window->title); + } + + WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display ); +} + void Wayland_DestroyWindow(_THIS, SDL_Window *window) { SDL_VideoData *data = _this->driverdata; diff --git a/src/video/wayland/SDL_waylandwindow.h b/src/video/wayland/SDL_waylandwindow.h index d031002a1248d..319a573dc8a74 100644 --- a/src/video/wayland/SDL_waylandwindow.h +++ b/src/video/wayland/SDL_waylandwindow.h @@ -50,8 +50,11 @@ extern void Wayland_ShowWindow(_THIS, SDL_Window *window); extern void Wayland_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * _display, SDL_bool fullscreen); +extern void Wayland_MaximizeWindow(_THIS, SDL_Window * window); +extern void Wayland_RestoreWindow(_THIS, SDL_Window * window); extern int Wayland_CreateWindow(_THIS, SDL_Window *window); extern void Wayland_SetWindowSize(_THIS, SDL_Window * window); +extern void Wayland_SetWindowTitle(_THIS, SDL_Window * window); extern void Wayland_DestroyWindow(_THIS, SDL_Window *window); extern SDL_bool