wayland: Implement FlashWindow
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c
index bae83ac..7503d81 100644
--- a/src/video/wayland/SDL_waylandvideo.c
+++ b/src/video/wayland/SDL_waylandvideo.c
@@ -216,6 +216,7 @@ Wayland_CreateDevice(int devindex)
device->SetWindowTitle = Wayland_SetWindowTitle;
device->DestroyWindow = Wayland_DestroyWindow;
device->SetWindowHitTest = Wayland_SetWindowHitTest;
+ device->FlashWindow = Wayland_FlashWindow;
device->SetClipboardText = Wayland_SetClipboardText;
device->GetClipboardText = Wayland_GetClipboardText;
diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c
index 1c69d54..35ee3a2 100644
--- a/src/video/wayland/SDL_waylandwindow.c
+++ b/src/video/wayland/SDL_waylandwindow.c
@@ -848,11 +848,31 @@ static const struct xdg_activation_token_v1_listener activation_listener_xdg = {
handle_xdg_activation_done
};
-void Wayland_RaiseWindow(_THIS, SDL_Window *window)
+/* The xdg-activation protocol considers "activation" to be one of two things:
+ *
+ * 1: Raising a window to the top and flashing the titlebar
+ * 2: Flashing the titlebar while keeping the window where it is
+ *
+ * As you might expect from Wayland, the general policy is to go with #2 unless
+ * the client can prove to the compositor beyond a reasonable doubt that raising
+ * the window will not be malicuous behavior.
+ *
+ * For SDL this means RaiseWindow and FlashWindow both use the same protocol,
+ * but in different ways: RaiseWindow will provide as _much_ information as
+ * possible while FlashWindow will provide as _little_ information as possible,
+ * to nudge the compositor into doing what we want.
+ *
+ * This isn't _strictly_ what the protocol says will happen, but this is what
+ * current implementations are doing (as of writing, YMMV in the far distant
+ * future).
+ *
+ * -flibit
+ */
+static void
+Wayland_activate_window(SDL_VideoData *data, SDL_WindowData *wind,
+ struct wl_surface *surface,
+ uint32_t serial, struct wl_seat *seat)
{
- SDL_VideoData *data = _this->driverdata;
- SDL_WindowData *wind = window->driverdata;
-
if (data->activation_manager) {
if (wind->activation_token != NULL) {
/* We're about to overwrite this with a new request */
@@ -869,17 +889,47 @@ void Wayland_RaiseWindow(_THIS, SDL_Window *window)
* Hypothetically we could set the app_id from data->classname, but
* that part of the API is for _external_ programs, not ourselves.
*
- * As for a serial, this Raise event is arbitrary and doesn't come from
- * an event, so it's actually very likely that this token will be
- * ignored! TODO: Maybe add support for Raise via serial?
- *
* -flibit
*/
- xdg_activation_token_v1_set_surface(wind->activation_token, wind->surface);
+ if (surface != NULL) {
+ xdg_activation_token_v1_set_surface(wind->activation_token, surface);
+ }
+ if (seat != NULL) {
+ xdg_activation_token_v1_set_serial(wind->activation_token, serial, seat);
+ }
xdg_activation_token_v1_commit(wind->activation_token);
}
}
+void
+Wayland_RaiseWindow(_THIS, SDL_Window *window)
+{
+ SDL_WindowData *wind = window->driverdata;
+
+ /* FIXME: This Raise event is arbitrary and doesn't come from an event, so
+ * it's actually very likely that this token will be ignored! Maybe add
+ * support for passing serials (and the associated seat) so this can have
+ * a better chance of actually raising the window.
+ * -flibit
+ */
+ Wayland_activate_window(_this->driverdata,
+ wind,
+ wind->surface,
+ 0,
+ NULL);
+}
+
+int
+Wayland_FlashWindow(_THIS, SDL_Window *window, Uint32 flash_count)
+{
+ Wayland_activate_window(_this->driverdata,
+ window->driverdata,
+ NULL,
+ 0,
+ NULL);
+ return 0;
+}
+
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
static void SDLCALL
QtExtendedSurface_OnHintChanged(void *userdata, const char *name,
diff --git a/src/video/wayland/SDL_waylandwindow.h b/src/video/wayland/SDL_waylandwindow.h
index 49b3ee4..320fd3e 100644
--- a/src/video/wayland/SDL_waylandwindow.h
+++ b/src/video/wayland/SDL_waylandwindow.h
@@ -113,6 +113,7 @@ extern void Wayland_SuspendScreenSaver(_THIS);
extern SDL_bool
Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info);
extern int Wayland_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);
+extern int Wayland_FlashWindow(_THIS, SDL_Window * window, Uint32 flash_count);
extern void Wayland_HandlePendingResize(SDL_Window *window);