wayland: Implement RaiseWindow with xdg-activation

This commit is contained in:
Ethan Lee
2021-06-02 11:41:44 -04:00
committed by Sam Lantinga
parent f498c281e1
commit 151f953815
5 changed files with 252 additions and 0 deletions

View File

@@ -51,6 +51,7 @@
#include "xdg-decoration-unstable-v1-client-protocol.h"
#include "keyboard-shortcuts-inhibit-unstable-v1-client-protocol.h"
#include "idle-inhibit-unstable-v1-client-protocol.h"
#include "xdg-activation-v1-client-protocol.h"
#define WAYLANDVID_DRIVER_NAME "wayland"
@@ -199,6 +200,7 @@ Wayland_CreateDevice(int devindex)
device->CreateSDLWindow = Wayland_CreateWindow;
device->ShowWindow = Wayland_ShowWindow;
device->HideWindow = Wayland_HideWindow;
device->RaiseWindow = Wayland_RaiseWindow;
device->SetWindowFullscreen = Wayland_SetWindowFullscreen;
device->MaximizeWindow = Wayland_MaximizeWindow;
device->MinimizeWindow = Wayland_MinimizeWindow;
@@ -463,6 +465,8 @@ display_handle_global(void *data, struct wl_registry *registry, uint32_t id,
d->key_inhibitor_manager = wl_registry_bind(d->registry, id, &zwp_keyboard_shortcuts_inhibit_manager_v1_interface, 1);
} else if (strcmp(interface, "zwp_idle_inhibit_manager_v1") == 0) {
d->idle_inhibit_manager = wl_registry_bind(d->registry, id, &zwp_idle_inhibit_manager_v1_interface, 1);
} else if (strcmp(interface, "xdg_activation_v1") == 0) {
d->activation_manager = wl_registry_bind(d->registry, id, &xdg_activation_v1_interface, 1);
} else if (strcmp(interface, "wl_data_device_manager") == 0) {
Wayland_add_data_device_manager(d, id, version);
} else if (strcmp(interface, "zxdg_decoration_manager_v1") == 0) {
@@ -583,6 +587,9 @@ Wayland_VideoQuit(_THIS)
Wayland_display_destroy_pointer_constraints(data);
Wayland_display_destroy_relative_pointer_manager(data);
if (data->activation_manager)
xdg_activation_v1_destroy(data->activation_manager);
if (data->idle_inhibit_manager)
zwp_idle_inhibit_manager_v1_destroy(data->idle_inhibit_manager);

View File

@@ -69,6 +69,7 @@ typedef struct {
struct zxdg_decoration_manager_v1 *decoration_manager;
struct zwp_keyboard_shortcuts_inhibit_manager_v1 *key_inhibitor_manager;
struct zwp_idle_inhibit_manager_v1 *idle_inhibit_manager;
struct xdg_activation_v1 *activation_manager;
EGLDisplay edpy;
EGLContext context;

View File

@@ -37,6 +37,7 @@
#include "xdg-shell-unstable-v6-client-protocol.h"
#include "xdg-decoration-unstable-v1-client-protocol.h"
#include "idle-inhibit-unstable-v1-client-protocol.h"
#include "xdg-activation-v1-client-protocol.h"
static float get_window_scale_factor(SDL_Window *window) {
return ((SDL_WindowData*)window->driverdata)->scale_factor;
@@ -812,6 +813,57 @@ void Wayland_HideWindow(_THIS, SDL_Window *window)
}
}
static void
handle_xdg_activation_done(void *data,
struct xdg_activation_token_v1 *xdg_activation_token_v1,
const char *token)
{
SDL_WindowData *window = data;
if (xdg_activation_token_v1 == window->activation_token) {
xdg_activation_v1_activate(window->waylandData->activation_manager,
token,
window->surface);
xdg_activation_token_v1_destroy(window->activation_token);
window->activation_token = NULL;
}
}
static const struct xdg_activation_token_v1_listener activation_listener_xdg = {
handle_xdg_activation_done
};
void Wayland_RaiseWindow(_THIS, SDL_Window *window)
{
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 */
xdg_activation_token_v1_destroy(wind->activation_token);
}
wind->activation_token = xdg_activation_v1_get_activation_token(data->activation_manager);
xdg_activation_token_v1_add_listener(wind->activation_token,
&activation_listener_xdg,
wind);
/* Note that we are not setting the app_id or serial here.
*
* 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);
xdg_activation_token_v1_commit(wind->activation_token);
}
}
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
static void SDLCALL
QtExtendedSurface_OnHintChanged(void *userdata, const char *name,
@@ -1277,6 +1329,10 @@ void Wayland_DestroyWindow(_THIS, SDL_Window *window)
zwp_idle_inhibitor_v1_destroy(wind->idle_inhibitor);
}
if (wind->activation_token) {
xdg_activation_token_v1_destroy(wind->activation_token);
}
SDL_free(wind->outputs);
if (wind->frame_callback) {

View File

@@ -67,6 +67,7 @@ typedef struct {
struct zxdg_toplevel_decoration_v1 *server_decoration;
struct zwp_keyboard_shortcuts_inhibitor_v1 *key_inhibitor;
struct zwp_idle_inhibitor_v1 *idle_inhibitor;
struct xdg_activation_token_v1 *activation_token;
SDL_atomic_t swap_interval_ready;
@@ -89,6 +90,7 @@ typedef struct {
extern void Wayland_ShowWindow(_THIS, SDL_Window *window);
extern void Wayland_HideWindow(_THIS, SDL_Window *window);
extern void Wayland_RaiseWindow(_THIS, SDL_Window *window);
extern void Wayland_SetWindowFullscreen(_THIS, SDL_Window * window,
SDL_VideoDisplay * _display,
SDL_bool fullscreen);