| 1 | /* |
| 2 | Simple DirectMedia Layer |
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> |
| 4 | |
| 5 | This software is provided 'as-is', without any express or implied |
| 6 | warranty. In no event will the authors be held liable for any damages |
| 7 | arising from the use of this software. |
| 8 | |
| 9 | Permission is granted to anyone to use this software for any purpose, |
| 10 | including commercial applications, and to alter it and redistribute it |
| 11 | freely, subject to the following restrictions: |
| 12 | |
| 13 | 1. The origin of this software must not be misrepresented; you must not |
| 14 | claim that you wrote the original software. If you use this software |
| 15 | in a product, an acknowledgment in the product documentation would be |
| 16 | appreciated but is not required. |
| 17 | 2. Altered source versions must be plainly marked as such, and must not be |
| 18 | misrepresented as being the original software. |
| 19 | 3. This notice may not be removed or altered from any source distribution. |
| 20 | */ |
| 21 | |
| 22 | #include "SDL_internal.h" |
| 23 | |
| 24 | #ifndef SDL_waylandwindow_h_ |
| 25 | #define SDL_waylandwindow_h_ |
| 26 | |
| 27 | #include "../SDL_sysvideo.h" |
| 28 | #include "../../events/SDL_touch_c.h" |
| 29 | |
| 30 | #include "SDL_waylandvideo.h" |
| 31 | #include "SDL_waylandshmbuffer.h" |
| 32 | |
| 33 | struct SDL_WaylandInput; |
| 34 | |
| 35 | struct SDL_WindowData |
| 36 | { |
| 37 | SDL_Window *sdlwindow; |
| 38 | SDL_VideoData *waylandData; |
| 39 | struct wl_surface *surface; |
| 40 | struct wl_callback *gles_swap_frame_callback; |
| 41 | struct wl_event_queue *gles_swap_frame_event_queue; |
| 42 | struct wl_surface *gles_swap_frame_surface_wrapper; |
| 43 | struct wl_callback *surface_frame_callback; |
| 44 | |
| 45 | union |
| 46 | { |
| 47 | #ifdef HAVE_LIBDECOR_H |
| 48 | struct |
| 49 | { |
| 50 | struct libdecor_frame *frame; |
| 51 | bool initial_configure_seen; |
| 52 | } libdecor; |
| 53 | #endif |
| 54 | struct |
| 55 | { |
| 56 | struct xdg_surface *surface; |
| 57 | union |
| 58 | { |
| 59 | struct |
| 60 | { |
| 61 | struct xdg_toplevel *xdg_toplevel; |
| 62 | } toplevel; |
| 63 | struct |
| 64 | { |
| 65 | struct *; |
| 66 | struct xdg_positioner *xdg_positioner; |
| 67 | } ; |
| 68 | }; |
| 69 | bool initial_configure_seen; |
| 70 | } xdg; |
| 71 | } shell_surface; |
| 72 | enum |
| 73 | { |
| 74 | WAYLAND_SHELL_SURFACE_TYPE_UNKNOWN = 0, |
| 75 | WAYLAND_SHELL_SURFACE_TYPE_XDG_TOPLEVEL, |
| 76 | WAYLAND_SHELL_SURFACE_TYPE_XDG_POPUP, |
| 77 | WAYLAND_SHELL_SURFACE_TYPE_LIBDECOR, |
| 78 | WAYLAND_SHELL_SURFACE_TYPE_CUSTOM |
| 79 | } shell_surface_type; |
| 80 | enum |
| 81 | { |
| 82 | WAYLAND_SHELL_SURFACE_STATUS_HIDDEN = 0, |
| 83 | WAYLAND_SHELL_SURFACE_STATUS_WAITING_FOR_CONFIGURE, |
| 84 | WAYLAND_SHELL_SURFACE_STATUS_WAITING_FOR_FRAME, |
| 85 | WAYLAND_SHELL_SURFACE_STATUS_SHOW_PENDING, |
| 86 | WAYLAND_SHELL_SURFACE_STATUS_SHOWN |
| 87 | } shell_surface_status; |
| 88 | enum |
| 89 | { |
| 90 | WAYLAND_WM_CAPS_WINDOW_MENU = 0x01, |
| 91 | WAYLAND_WM_CAPS_MAXIMIZE = 0x02, |
| 92 | WAYLAND_WM_CAPS_FULLSCREEN = 0x04, |
| 93 | WAYLAND_WM_CAPS_MINIMIZE = 0x08, |
| 94 | |
| 95 | WAYLAND_WM_CAPS_ALL = WAYLAND_WM_CAPS_WINDOW_MENU | |
| 96 | WAYLAND_WM_CAPS_MAXIMIZE | |
| 97 | WAYLAND_WM_CAPS_FULLSCREEN | |
| 98 | WAYLAND_WM_CAPS_MINIMIZE |
| 99 | } wm_caps; |
| 100 | |
| 101 | struct wl_egl_window *egl_window; |
| 102 | struct SDL_WaylandInput *keyboard_device; |
| 103 | #ifdef SDL_VIDEO_OPENGL_EGL |
| 104 | EGLSurface egl_surface; |
| 105 | #endif |
| 106 | struct zwp_locked_pointer_v1 *locked_pointer; |
| 107 | struct zwp_confined_pointer_v1 *confined_pointer; |
| 108 | struct zxdg_toplevel_decoration_v1 *server_decoration; |
| 109 | struct zwp_keyboard_shortcuts_inhibitor_v1 *key_inhibitor; |
| 110 | struct zwp_idle_inhibitor_v1 *idle_inhibitor; |
| 111 | struct xdg_activation_token_v1 *activation_token; |
| 112 | struct wp_viewport *viewport; |
| 113 | struct wp_fractional_scale_v1 *fractional_scale; |
| 114 | struct zxdg_exported_v2 *exported; |
| 115 | struct xdg_dialog_v1 *xdg_dialog_v1; |
| 116 | struct wp_alpha_modifier_surface_v1 *wp_alpha_modifier_surface_v1; |
| 117 | struct xdg_toplevel_icon_v1 *xdg_toplevel_icon_v1; |
| 118 | struct frog_color_managed_surface *frog_color_managed_surface; |
| 119 | struct wp_color_management_surface_feedback_v1 *wp_color_management_surface_feedback; |
| 120 | |
| 121 | struct Wayland_ColorInfoState *color_info_state; |
| 122 | |
| 123 | SDL_AtomicInt swap_interval_ready; |
| 124 | |
| 125 | SDL_DisplayData **outputs; |
| 126 | int num_outputs; |
| 127 | |
| 128 | SDL_Window *keyboard_focus; |
| 129 | |
| 130 | char *app_id; |
| 131 | double scale_factor; |
| 132 | |
| 133 | struct Wayland_SHMBuffer *icon_buffers; |
| 134 | int icon_buffer_count; |
| 135 | |
| 136 | struct |
| 137 | { |
| 138 | double x; |
| 139 | double y; |
| 140 | } pointer_scale; |
| 141 | |
| 142 | // The in-flight window size request. |
| 143 | struct |
| 144 | { |
| 145 | // The requested logical window size. |
| 146 | int logical_width; |
| 147 | int logical_height; |
| 148 | |
| 149 | // The size of the window in pixels, when using screen space scaling. |
| 150 | int pixel_width; |
| 151 | int pixel_height; |
| 152 | } requested; |
| 153 | |
| 154 | // The current size of the window and drawable backing store. |
| 155 | struct |
| 156 | { |
| 157 | // The size of the underlying window. |
| 158 | int logical_width; |
| 159 | int logical_height; |
| 160 | |
| 161 | // The size of the window backbuffer in pixels. |
| 162 | int pixel_width; |
| 163 | int pixel_height; |
| 164 | } current; |
| 165 | |
| 166 | // The last compositor requested parameters; used for deduplication of window geometry configuration. |
| 167 | struct |
| 168 | { |
| 169 | int width; |
| 170 | int height; |
| 171 | } last_configure; |
| 172 | |
| 173 | // System enforced window size limits. |
| 174 | struct |
| 175 | { |
| 176 | // Minimum allowed logical window size. |
| 177 | int min_width; |
| 178 | int min_height; |
| 179 | } system_limits; |
| 180 | |
| 181 | struct |
| 182 | { |
| 183 | int width; |
| 184 | int height; |
| 185 | } toplevel_bounds; |
| 186 | |
| 187 | SDL_DisplayID last_displayID; |
| 188 | int fullscreen_deadline_count; |
| 189 | int maximized_restored_deadline_count; |
| 190 | Uint64 last_focus_event_time_ns; |
| 191 | int icc_fd; |
| 192 | Uint32 icc_size; |
| 193 | bool floating; |
| 194 | bool suspended; |
| 195 | bool resizing; |
| 196 | bool active; |
| 197 | bool drop_interactive_resizes; |
| 198 | bool is_fullscreen; |
| 199 | bool fullscreen_exclusive; |
| 200 | bool drop_fullscreen_requests; |
| 201 | bool fullscreen_was_positioned; |
| 202 | bool show_hide_sync_required; |
| 203 | bool scale_to_display; |
| 204 | bool reparenting_required; |
| 205 | bool double_buffer; |
| 206 | |
| 207 | SDL_HitTestResult hit_test_result; |
| 208 | |
| 209 | struct wl_list external_window_list_link; |
| 210 | }; |
| 211 | |
| 212 | extern void Wayland_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window); |
| 213 | extern void Wayland_HideWindow(SDL_VideoDevice *_this, SDL_Window *window); |
| 214 | extern void Wayland_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window); |
| 215 | extern SDL_FullscreenResult Wayland_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *_display, SDL_FullscreenOp fullscreen); |
| 216 | extern void Wayland_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window *window); |
| 217 | extern void Wayland_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window); |
| 218 | extern bool Wayland_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window); |
| 219 | extern bool Wayland_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); |
| 220 | extern bool Wayland_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); |
| 221 | extern void Wayland_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window); |
| 222 | extern void Wayland_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window *window, bool bordered); |
| 223 | extern void Wayland_SetWindowResizable(SDL_VideoDevice *_this, SDL_Window *window, bool resizable); |
| 224 | extern bool Wayland_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); |
| 225 | extern bool Wayland_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); |
| 226 | extern void Wayland_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); |
| 227 | extern void Wayland_SetWindowMinimumSize(SDL_VideoDevice *_this, SDL_Window *window); |
| 228 | extern void Wayland_SetWindowMaximumSize(SDL_VideoDevice *_this, SDL_Window *window); |
| 229 | extern void Wayland_GetWindowSizeInPixels(SDL_VideoDevice *_this, SDL_Window *window, int *w, int *h); |
| 230 | extern SDL_DisplayID Wayland_GetDisplayForWindow(SDL_VideoDevice *_this, SDL_Window *window); |
| 231 | extern bool Wayland_SetWindowParent(SDL_VideoDevice *_this, SDL_Window *window, SDL_Window *parent_window); |
| 232 | extern bool Wayland_SetWindowModal(SDL_VideoDevice *_this, SDL_Window *window, bool modal); |
| 233 | extern bool Wayland_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity); |
| 234 | extern void Wayland_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); |
| 235 | extern void Wayland_ShowWindowSystemMenu(SDL_Window *window, int x, int y); |
| 236 | extern void Wayland_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window); |
| 237 | extern bool Wayland_SuspendScreenSaver(SDL_VideoDevice *_this); |
| 238 | extern bool Wayland_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon); |
| 239 | extern float Wayland_GetWindowContentScale(SDL_VideoDevice *_this, SDL_Window *window); |
| 240 | extern void *Wayland_GetWindowICCProfile(SDL_VideoDevice *_this, SDL_Window *window, size_t *size); |
| 241 | |
| 242 | extern bool Wayland_SetWindowHitTest(SDL_Window *window, bool enabled); |
| 243 | extern bool Wayland_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation); |
| 244 | extern bool Wayland_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window); |
| 245 | |
| 246 | extern void Wayland_RemoveOutputFromWindow(SDL_WindowData *window, SDL_DisplayData *display_data); |
| 247 | |
| 248 | #endif // SDL_waylandwindow_h_ |
| 249 | |