Commit03a247acRecorded5 Dec 2026Repositorysigil-ui

Submit Wayland activation tokens for existing toplevels

Changed
 native/wayland.c                                   |  16 ++++++
 native/wayland/protocols/xdg-activation-v1.xml     | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 native/wayland/xdg-activation-v1-client-protocol.h | 415 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 native/wayland/xdg-activation-v1-protocol.c        |  84 +++++++++++++++++++++++++++++
 native/window-wayland-services.inc                 |  23 ++++++++
 scripts/test-wayland-dual-link.sgl                 |  13 +++--
 src/sigil/ui/wayland.sgl                           |   9 +++-
 test/wayland/standalone-protocols.h                |   1 +
 8 files changed, 755 insertions(+), 6 deletions(-)
Diff
native/wayland.cmodified
@@ -70,6 +70,8 @@
70
#define SIGIL_UI_EXTERNAL_WAYLAND_PROTOCOLS 1
71
#pragma GCC visibility push(hidden)
72
#include "wayland-client.h"
+73
/* The hidden activation interface must resolve to sigil-window's table at link time. */
+74
#include "xdg-activation-v1-client-protocol.h"
75
#include "xdg-shell-client-protocol.h"
76
#include "xdg-decoration-unstable-v1-client-protocol.h"
77
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
@@ -313,6 +315,8 @@ typedef struct Wl {
315
ClipboardWrite writes[CLIPBOARD_WRITES];
316
struct wl_display *display;
317
struct wl_registry *registry;
+318
struct xdg_activation_v1 *activation;
+319
uint32_t activation_global;
320
uint32_t exporter_global;
321
struct wl_proxy *exporter, *exported;
322
char *export_handle;
@@ -1213,6 +1217,10 @@ static void global(void *data, struct wl_registry *r, uint32_t id, const char *i
1217
w->compositor = wl_registry_bind(r, id, &wl_compositor_interface, min_u(version, 6));
1218
else if (!strcmp(iface, wl_subcompositor_interface.name) && !w->subcompositor)
1219
w->subcompositor = wl_registry_bind(r, id, &wl_subcompositor_interface, 1);
+1220
else if (!strcmp(iface, xdg_activation_v1_interface.name) && !w->activation) {
+1221
w->activation = wl_registry_bind(r, id, &xdg_activation_v1_interface, 1);
+1222
w->activation_global = id;
+1223
}
1224
else if (!strcmp(iface, exporter_interface.name) && !w->exporter_global)
1225
w->exporter_global = id;
1226
else if (!strcmp(iface, presentation_interface.name) && !w->presentation_global)
@@ -1259,6 +1267,11 @@ static void global(void *data, struct wl_registry *r, uint32_t id, const char *i
1267
static void global_remove(void *data, struct wl_registry *r, uint32_t id)
1268
{
1269
Wl *w = data;
+1270
if (w->activation && id == w->activation_global) {
+1271
xdg_activation_v1_destroy(w->activation);
+1272
w->activation = NULL;
+1273
w->activation_global = 0;
+1274
}
1275
if (id == w->exporter_global) {
1276
export_close(w);
1277
w->exporter_global = 0;
@@ -1368,6 +1381,8 @@ static void wl_teardown(Wl *w)
1381
if (zwlr_layer_shell_v1_get_version(w->layer_shell) >= 3) zwlr_layer_shell_v1_destroy(w->layer_shell);
1382
else wl_proxy_destroy((struct wl_proxy *)w->layer_shell);
1383
}
+1384
if (w->activation) xdg_activation_v1_destroy(w->activation);
+1385
w->activation = NULL;
1386
if (w->wm_base) xdg_wm_base_destroy(w->wm_base);
1387
if (w->decoration_manager) zxdg_decoration_manager_v1_destroy(w->decoration_manager);
1388
if (w->seat) wl_seat_destroy(w->seat);
@@ -2561,6 +2576,7 @@ void sigil__register_sigil_ui_wayland(SigilVM *vm)
2576
REGISTER_AND_EXPORT("%wl-alpha!", native_wl_alpha, SIGIL_ARITY_EXACT(2), "Set an overlay alpha mask");
2577
REGISTER_AND_EXPORT("%wl-keymap", native_wl_keymap, SIGIL_ARITY_EXACT(1), "Compositor keymap text");
2578
REGISTER_AND_EXPORT("%wl-title!", native_wl_title, SIGIL_ARITY_EXACT(2), "Update a toplevel title without presenting");
+2579
REGISTER_AND_EXPORT("%wl-activate!", native_wl_activate, SIGIL_ARITY_EXACT(2), "Submit a toplevel activation token");
2580
REGISTER_AND_EXPORT("%wl-fullscreen?", native_wl_fullscreen_state, SIGIL_ARITY_EXACT(1), "Configured xdg-toplevel fullscreen state");
2581
REGISTER_AND_EXPORT("%wl-fullscreen!", native_wl_fullscreen, SIGIL_ARITY_EXACT(2), "Request an asynchronous fullscreen transition");
2582
REGISTER_AND_EXPORT("%wl-clipboard-set!", native_wl_clipboard_set, SIGIL_ARITY_EXACT(2), "Own the text clipboard");
native/wayland/protocols/xdg-activation-v1.xmladded
@@ -0,0 +1,200 @@
+1
<?xml version="1.0" encoding="UTF-8"?>
+2
<protocol name="xdg_activation_v1">
+3
+4
<copyright>
+5
Copyright © 2020 Aleix Pol Gonzalez &lt;aleixpol@kde.org&gt;
+6
Copyright © 2020 Carlos Garnacho &lt;carlosg@gnome.org&gt;
+7
+8
Permission is hereby granted, free of charge, to any person obtaining a
+9
copy of this software and associated documentation files (the "Software"),
+10
to deal in the Software without restriction, including without limitation
+11
the rights to use, copy, modify, merge, publish, distribute, sublicense,
+12
and/or sell copies of the Software, and to permit persons to whom the
+13
Software is furnished to do so, subject to the following conditions:
+14
+15
The above copyright notice and this permission notice (including the next
+16
paragraph) shall be included in all copies or substantial portions of the
+17
Software.
+18
+19
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+20
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+21
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+22
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+23
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+24
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+25
DEALINGS IN THE SOFTWARE.
+26
</copyright>
+27
+28
<description summary="Protocol for requesting activation of surfaces">
+29
The way for a client to pass focus to another toplevel is as follows.
+30
+31
The client that intends to activate another toplevel uses the
+32
xdg_activation_v1.get_activation_token request to get an activation token.
+33
This token is then forwarded to the client, which is supposed to activate
+34
one of its surfaces, through a separate band of communication.
+35
+36
One established way of doing this is through the XDG_ACTIVATION_TOKEN
+37
environment variable of a newly launched child process. The child process
+38
should unset the environment variable again right after reading it out in
+39
order to avoid propagating it to other child processes.
+40
+41
Another established way exists for Applications implementing the D-Bus
+42
interface org.freedesktop.Application, which should get their token under
+43
activation-token on their platform_data.
+44
+45
In general activation tokens may be transferred across clients through
+46
means not described in this protocol.
+47
+48
The client to be activated will then pass the token
+49
it received to the xdg_activation_v1.activate request. The compositor can
+50
then use this token to decide how to react to the activation request.
+51
+52
The token the activating client gets may be ineffective either already at
+53
the time it receives it, for example if it was not focused, for focus
+54
stealing prevention. The activating client will have no way to discover
+55
the validity of the token, and may still forward it to the to be activated
+56
client.
+57
+58
The created activation token may optionally get information attached to it
+59
that can be used by the compositor to identify the application that we
+60
intend to activate. This can for example be used to display a visual hint
+61
about what application is being started.
+62
+63
Warning! The protocol described in this file is currently in the testing
+64
phase. Backward compatible changes may be added together with the
+65
corresponding interface version bump. Backward incompatible changes can
+66
only be done by creating a new major version of the extension.
+67
</description>
+68
+69
<interface name="xdg_activation_v1" version="1">
+70
<description summary="interface for activating surfaces">
+71
A global interface used for informing the compositor about applications
+72
being activated or started, or for applications to request to be
+73
activated.
+74
</description>
+75
+76
<request name="destroy" type="destructor">
+77
<description summary="destroy the xdg_activation object">
+78
Notify the compositor that the xdg_activation object will no longer be
+79
used.
+80
+81
The child objects created via this interface are unaffected and should
+82
be destroyed separately.
+83
</description>
+84
</request>
+85
+86
<request name="get_activation_token">
+87
<description summary="requests a token">
+88
Creates an xdg_activation_token_v1 object that will provide
+89
the initiating client with a unique token for this activation. This
+90
token should be offered to the clients to be activated.
+91
</description>
+92
+93
<arg name="id" type="new_id" interface="xdg_activation_token_v1"/>
+94
</request>
+95
+96
<request name="activate">
+97
<description summary="notify new interaction being available">
+98
Requests surface activation. It's up to the compositor to display
+99
this information as desired, for example by placing the surface above
+100
the rest.
+101
+102
The compositor may know who requested this by checking the activation
+103
token and might decide not to follow through with the activation if it's
+104
considered unwanted.
+105
+106
Compositors can ignore unknown activation tokens when an invalid
+107
token is passed.
+108
</description>
+109
<arg name="token" type="string" summary="the activation token of the initiating client"/>
+110
<arg name="surface" type="object" interface="wl_surface"
+111
summary="the wl_surface to activate"/>
+112
</request>
+113
</interface>
+114
+115
<interface name="xdg_activation_token_v1" version="1">
+116
<description summary="an exported activation handle">
+117
An object for setting up a token and receiving a token handle that can
+118
be passed as an activation token to another client.
+119
+120
The object is created using the xdg_activation_v1.get_activation_token
+121
request. This object should then be populated with the app_id, surface
+122
and serial information and committed. The compositor shall then issue a
+123
done event with the token. In case the request's parameters are invalid,
+124
the compositor will provide an invalid token.
+125
</description>
+126
+127
<enum name="error">
+128
<entry name="already_used" value="0"
+129
summary="The token has already been used previously"/>
+130
</enum>
+131
+132
<request name="set_serial">
+133
<description summary="specifies the seat and serial of the activating event">
+134
Provides information about the seat and serial event that requested the
+135
token.
+136
+137
The serial can come from an input or focus event. For instance, if a
+138
click triggers the launch of a third-party client, the launcher client
+139
should send a set_serial request with the serial and seat from the
+140
wl_pointer.button event.
+141
+142
Some compositors might refuse to activate toplevels when the token
+143
doesn't have a valid and recent enough event serial.
+144
+145
Must be sent before commit. This information is optional.
+146
</description>
+147
<arg name="serial" type="uint"
+148
summary="the serial of the event that triggered the activation"/>
+149
<arg name="seat" type="object" interface="wl_seat"
+150
summary="the wl_seat of the event"/>
+151
</request>
+152
+153
<request name="set_app_id">
+154
<description summary="specifies the application being activated">
+155
The requesting client can specify an app_id to associate the token
+156
being created with it.
+157
+158
Must be sent before commit. This information is optional.
+159
</description>
+160
<arg name="app_id" type="string"
+161
summary="the application id of the client being activated."/>
+162
</request>
+163
+164
<request name="set_surface">
+165
<description summary="specifies the surface requesting activation">
+166
This request sets the surface requesting the activation. Note, this is
+167
different from the surface that will be activated.
+168
+169
Some compositors might refuse to activate toplevels when the token
+170
doesn't have a requesting surface.
+171
+172
Must be sent before commit. This information is optional.
+173
</description>
+174
<arg name="surface" type="object" interface="wl_surface"
+175
summary="the requesting surface"/>
+176
</request>
+177
+178
<request name="commit">
+179
<description summary="issues the token request">
+180
Requests an activation token based on the different parameters that
+181
have been offered through set_serial, set_surface and set_app_id.
+182
</description>
+183
</request>
+184
+185
<event name="done">
+186
<description summary="the exported activation token">
+187
The 'done' event contains the unique token of this activation request
+188
and notifies that the provider is done.
+189
</description>
+190
<arg name="token" type="string" summary="the exported activation token"/>
+191
</event>
+192
+193
<request name="destroy" type="destructor">
+194
<description summary="destroy the xdg_activation_token_v1 object">
+195
Notify the compositor that the xdg_activation_token_v1 object will no
+196
longer be used. The received token stays valid.
+197
</description>
+198
</request>
+199
</interface>
+200
</protocol>
native/wayland/xdg-activation-v1-client-protocol.hadded
@@ -0,0 +1,415 @@
+1
/* Generated by wayland-scanner 1.24.0 */
+2
+3
#ifndef XDG_ACTIVATION_V1_CLIENT_PROTOCOL_H
+4
#define XDG_ACTIVATION_V1_CLIENT_PROTOCOL_H
+5
+6
#include <stdint.h>
+7
#include <stddef.h>
+8
#include "wayland-client.h"
+9
+10
#ifdef __cplusplus
+11
extern "C" {
+12
#endif
+13
+14
/**
+15
* @page page_xdg_activation_v1 The xdg_activation_v1 protocol
+16
* Protocol for requesting activation of surfaces
+17
*
+18
* @section page_desc_xdg_activation_v1 Description
+19
*
+20
* The way for a client to pass focus to another toplevel is as follows.
+21
*
+22
* The client that intends to activate another toplevel uses the
+23
* xdg_activation_v1.get_activation_token request to get an activation token.
+24
* This token is then forwarded to the client, which is supposed to activate
+25
* one of its surfaces, through a separate band of communication.
+26
*
+27
* One established way of doing this is through the XDG_ACTIVATION_TOKEN
+28
* environment variable of a newly launched child process. The child process
+29
* should unset the environment variable again right after reading it out in
+30
* order to avoid propagating it to other child processes.
+31
*
+32
* Another established way exists for Applications implementing the D-Bus
+33
* interface org.freedesktop.Application, which should get their token under
+34
* activation-token on their platform_data.
+35
*
+36
* In general activation tokens may be transferred across clients through
+37
* means not described in this protocol.
+38
*
+39
* The client to be activated will then pass the token
+40
* it received to the xdg_activation_v1.activate request. The compositor can
+41
* then use this token to decide how to react to the activation request.
+42
*
+43
* The token the activating client gets may be ineffective either already at
+44
* the time it receives it, for example if it was not focused, for focus
+45
* stealing prevention. The activating client will have no way to discover
+46
* the validity of the token, and may still forward it to the to be activated
+47
* client.
+48
*
+49
* The created activation token may optionally get information attached to it
+50
* that can be used by the compositor to identify the application that we
+51
* intend to activate. This can for example be used to display a visual hint
+52
* about what application is being started.
+53
*
+54
* Warning! The protocol described in this file is currently in the testing
+55
* phase. Backward compatible changes may be added together with the
+56
* corresponding interface version bump. Backward incompatible changes can
+57
* only be done by creating a new major version of the extension.
+58
*
+59
* @section page_ifaces_xdg_activation_v1 Interfaces
+60
* - @subpage page_iface_xdg_activation_v1 - interface for activating surfaces
+61
* - @subpage page_iface_xdg_activation_token_v1 - an exported activation handle
+62
* @section page_copyright_xdg_activation_v1 Copyright
+63
* <pre>
+64
*
+65
* Copyright © 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
+66
* Copyright © 2020 Carlos Garnacho <carlosg@gnome.org>
+67
*
+68
* Permission is hereby granted, free of charge, to any person obtaining a
+69
* copy of this software and associated documentation files (the "Software"),
+70
* to deal in the Software without restriction, including without limitation
+71
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+72
* and/or sell copies of the Software, and to permit persons to whom the
+73
* Software is furnished to do so, subject to the following conditions:
+74
*
+75
* The above copyright notice and this permission notice (including the next
+76
* paragraph) shall be included in all copies or substantial portions of the
+77
* Software.
+78
*
+79
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+80
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+81
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+82
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+83
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+84
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+85
* DEALINGS IN THE SOFTWARE.
+86
* </pre>
+87
*/
+88
struct wl_seat;
+89
struct wl_surface;
+90
struct xdg_activation_token_v1;
+91
struct xdg_activation_v1;
+92
+93
#ifndef XDG_ACTIVATION_V1_INTERFACE
+94
#define XDG_ACTIVATION_V1_INTERFACE
+95
/**
+96
* @page page_iface_xdg_activation_v1 xdg_activation_v1
+97
* @section page_iface_xdg_activation_v1_desc Description
+98
*
+99
* A global interface used for informing the compositor about applications
+100
* being activated or started, or for applications to request to be
+101
* activated.
+102
* @section page_iface_xdg_activation_v1_api API
+103
* See @ref iface_xdg_activation_v1.
+104
*/
+105
/**
+106
* @defgroup iface_xdg_activation_v1 The xdg_activation_v1 interface
+107
*
+108
* A global interface used for informing the compositor about applications
+109
* being activated or started, or for applications to request to be
+110
* activated.
+111
*/
+112
extern const struct wl_interface xdg_activation_v1_interface;
+113
#endif
+114
#ifndef XDG_ACTIVATION_TOKEN_V1_INTERFACE
+115
#define XDG_ACTIVATION_TOKEN_V1_INTERFACE
+116
/**
+117
* @page page_iface_xdg_activation_token_v1 xdg_activation_token_v1
+118
* @section page_iface_xdg_activation_token_v1_desc Description
+119
*
+120
* An object for setting up a token and receiving a token handle that can
+121
* be passed as an activation token to another client.
+122
*
+123
* The object is created using the xdg_activation_v1.get_activation_token
+124
* request. This object should then be populated with the app_id, surface
+125
* and serial information and committed. The compositor shall then issue a
+126
* done event with the token. In case the request's parameters are invalid,
+127
* the compositor will provide an invalid token.
+128
* @section page_iface_xdg_activation_token_v1_api API
+129
* See @ref iface_xdg_activation_token_v1.
+130
*/
+131
/**
+132
* @defgroup iface_xdg_activation_token_v1 The xdg_activation_token_v1 interface
+133
*
+134
* An object for setting up a token and receiving a token handle that can
+135
* be passed as an activation token to another client.
+136
*
+137
* The object is created using the xdg_activation_v1.get_activation_token
+138
* request. This object should then be populated with the app_id, surface
+139
* and serial information and committed. The compositor shall then issue a
+140
* done event with the token. In case the request's parameters are invalid,
+141
* the compositor will provide an invalid token.
+142
*/
+143
extern const struct wl_interface xdg_activation_token_v1_interface;
+144
#endif
+145
+146
#define XDG_ACTIVATION_V1_DESTROY 0
+147
#define XDG_ACTIVATION_V1_GET_ACTIVATION_TOKEN 1
+148
#define XDG_ACTIVATION_V1_ACTIVATE 2
+149
+150
+151
/**
+152
* @ingroup iface_xdg_activation_v1
+153
*/
+154
#define XDG_ACTIVATION_V1_DESTROY_SINCE_VERSION 1
+155
/**
+156
* @ingroup iface_xdg_activation_v1
+157
*/
+158
#define XDG_ACTIVATION_V1_GET_ACTIVATION_TOKEN_SINCE_VERSION 1
+159
/**
+160
* @ingroup iface_xdg_activation_v1
+161
*/
+162
#define XDG_ACTIVATION_V1_ACTIVATE_SINCE_VERSION 1
+163
+164
/** @ingroup iface_xdg_activation_v1 */
+165
static inline void
+166
xdg_activation_v1_set_user_data(struct xdg_activation_v1 *xdg_activation_v1, void *user_data)
+167
{
+168
wl_proxy_set_user_data((struct wl_proxy *) xdg_activation_v1, user_data);
+169
}
+170
+171
/** @ingroup iface_xdg_activation_v1 */
+172
static inline void *
+173
xdg_activation_v1_get_user_data(struct xdg_activation_v1 *xdg_activation_v1)
+174
{
+175
return wl_proxy_get_user_data((struct wl_proxy *) xdg_activation_v1);
+176
}
+177
+178
static inline uint32_t
+179
xdg_activation_v1_get_version(struct xdg_activation_v1 *xdg_activation_v1)
+180
{
+181
return wl_proxy_get_version((struct wl_proxy *) xdg_activation_v1);
+182
}
+183
+184
/**
+185
* @ingroup iface_xdg_activation_v1
+186
*
+187
* Notify the compositor that the xdg_activation object will no longer be
+188
* used.
+189
*
+190
* The child objects created via this interface are unaffected and should
+191
* be destroyed separately.
+192
*/
+193
static inline void
+194
xdg_activation_v1_destroy(struct xdg_activation_v1 *xdg_activation_v1)
+195
{
+196
wl_proxy_marshal_flags((struct wl_proxy *) xdg_activation_v1,
+197
XDG_ACTIVATION_V1_DESTROY, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_activation_v1), WL_MARSHAL_FLAG_DESTROY);
+198
}
+199
+200
/**
+201
* @ingroup iface_xdg_activation_v1
+202
*
+203
* Creates an xdg_activation_token_v1 object that will provide
+204
* the initiating client with a unique token for this activation. This
+205
* token should be offered to the clients to be activated.
+206
*/
+207
static inline struct xdg_activation_token_v1 *
+208
xdg_activation_v1_get_activation_token(struct xdg_activation_v1 *xdg_activation_v1)
+209
{
+210
struct wl_proxy *id;
+211
+212
id = wl_proxy_marshal_flags((struct wl_proxy *) xdg_activation_v1,
+213
XDG_ACTIVATION_V1_GET_ACTIVATION_TOKEN, &xdg_activation_token_v1_interface, wl_proxy_get_version((struct wl_proxy *) xdg_activation_v1), 0, NULL);
+214
+215
return (struct xdg_activation_token_v1 *) id;
+216
}
+217
+218
/**
+219
* @ingroup iface_xdg_activation_v1
+220
*
+221
* Requests surface activation. It's up to the compositor to display
+222
* this information as desired, for example by placing the surface above
+223
* the rest.
+224
*
+225
* The compositor may know who requested this by checking the activation
+226
* token and might decide not to follow through with the activation if it's
+227
* considered unwanted.
+228
*
+229
* Compositors can ignore unknown activation tokens when an invalid
+230
* token is passed.
+231
*/
+232
static inline void
+233
xdg_activation_v1_activate(struct xdg_activation_v1 *xdg_activation_v1, const char *token, struct wl_surface *surface)
+234
{
+235
wl_proxy_marshal_flags((struct wl_proxy *) xdg_activation_v1,
+236
XDG_ACTIVATION_V1_ACTIVATE, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_activation_v1), 0, token, surface);
+237
}
+238
+239
#ifndef XDG_ACTIVATION_TOKEN_V1_ERROR_ENUM
+240
#define XDG_ACTIVATION_TOKEN_V1_ERROR_ENUM
+241
enum xdg_activation_token_v1_error {
+242
/**
+243
* The token has already been used previously
+244
*/
+245
XDG_ACTIVATION_TOKEN_V1_ERROR_ALREADY_USED = 0,
+246
};
+247
#endif /* XDG_ACTIVATION_TOKEN_V1_ERROR_ENUM */
+248
+249
/**
+250
* @ingroup iface_xdg_activation_token_v1
+251
* @struct xdg_activation_token_v1_listener
+252
*/
+253
struct xdg_activation_token_v1_listener {
+254
/**
+255
* the exported activation token
+256
*
+257
* The 'done' event contains the unique token of this activation
+258
* request and notifies that the provider is done.
+259
* @param token the exported activation token
+260
*/
+261
void (*done)(void *data,
+262
struct xdg_activation_token_v1 *xdg_activation_token_v1,
+263
const char *token);
+264
};
+265
+266
/**
+267
* @ingroup iface_xdg_activation_token_v1
+268
*/
+269
static inline int
+270
xdg_activation_token_v1_add_listener(struct xdg_activation_token_v1 *xdg_activation_token_v1,
+271
const struct xdg_activation_token_v1_listener *listener, void *data)
+272
{
+273
return wl_proxy_add_listener((struct wl_proxy *) xdg_activation_token_v1,
+274
(void (**)(void)) listener, data);
+275
}
+276
+277
#define XDG_ACTIVATION_TOKEN_V1_SET_SERIAL 0
+278
#define XDG_ACTIVATION_TOKEN_V1_SET_APP_ID 1
+279
#define XDG_ACTIVATION_TOKEN_V1_SET_SURFACE 2
+280
#define XDG_ACTIVATION_TOKEN_V1_COMMIT 3
+281
#define XDG_ACTIVATION_TOKEN_V1_DESTROY 4
+282
+283
/**
+284
* @ingroup iface_xdg_activation_token_v1
+285
*/
+286
#define XDG_ACTIVATION_TOKEN_V1_DONE_SINCE_VERSION 1
+287
+288
/**
+289
* @ingroup iface_xdg_activation_token_v1
+290
*/
+291
#define XDG_ACTIVATION_TOKEN_V1_SET_SERIAL_SINCE_VERSION 1
+292
/**
+293
* @ingroup iface_xdg_activation_token_v1
+294
*/
+295
#define XDG_ACTIVATION_TOKEN_V1_SET_APP_ID_SINCE_VERSION 1
+296
/**
+297
* @ingroup iface_xdg_activation_token_v1
+298
*/
+299
#define XDG_ACTIVATION_TOKEN_V1_SET_SURFACE_SINCE_VERSION 1
+300
/**
+301
* @ingroup iface_xdg_activation_token_v1
+302
*/
+303
#define XDG_ACTIVATION_TOKEN_V1_COMMIT_SINCE_VERSION 1
+304
/**
+305
* @ingroup iface_xdg_activation_token_v1
+306
*/
+307
#define XDG_ACTIVATION_TOKEN_V1_DESTROY_SINCE_VERSION 1
+308
+309
/** @ingroup iface_xdg_activation_token_v1 */
+310
static inline void
+311
xdg_activation_token_v1_set_user_data(struct xdg_activation_token_v1 *xdg_activation_token_v1, void *user_data)
+312
{
+313
wl_proxy_set_user_data((struct wl_proxy *) xdg_activation_token_v1, user_data);
+314
}
+315
+316
/** @ingroup iface_xdg_activation_token_v1 */
+317
static inline void *
+318
xdg_activation_token_v1_get_user_data(struct xdg_activation_token_v1 *xdg_activation_token_v1)
+319
{
+320
return wl_proxy_get_user_data((struct wl_proxy *) xdg_activation_token_v1);
+321
}
+322
+323
static inline uint32_t
+324
xdg_activation_token_v1_get_version(struct xdg_activation_token_v1 *xdg_activation_token_v1)
+325
{
+326
return wl_proxy_get_version((struct wl_proxy *) xdg_activation_token_v1);
+327
}
+328
+329
/**
+330
* @ingroup iface_xdg_activation_token_v1
+331
*
+332
* Provides information about the seat and serial event that requested the
+333
* token.
+334
*
+335
* The serial can come from an input or focus event. For instance, if a
+336
* click triggers the launch of a third-party client, the launcher client
+337
* should send a set_serial request with the serial and seat from the
+338
* wl_pointer.button event.
+339
*
+340
* Some compositors might refuse to activate toplevels when the token
+341
* doesn't have a valid and recent enough event serial.
+342
*
+343
* Must be sent before commit. This information is optional.
+344
*/
+345
static inline void
+346
xdg_activation_token_v1_set_serial(struct xdg_activation_token_v1 *xdg_activation_token_v1, uint32_t serial, struct wl_seat *seat)
+347
{
+348
wl_proxy_marshal_flags((struct wl_proxy *) xdg_activation_token_v1,
+349
XDG_ACTIVATION_TOKEN_V1_SET_SERIAL, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_activation_token_v1), 0, serial, seat);
+350
}
+351
+352
/**
+353
* @ingroup iface_xdg_activation_token_v1
+354
*
+355
* The requesting client can specify an app_id to associate the token
+356
* being created with it.
+357
*
+358
* Must be sent before commit. This information is optional.
+359
*/
+360
static inline void
+361
xdg_activation_token_v1_set_app_id(struct xdg_activation_token_v1 *xdg_activation_token_v1, const char *app_id)
+362
{
+363
wl_proxy_marshal_flags((struct wl_proxy *) xdg_activation_token_v1,
+364
XDG_ACTIVATION_TOKEN_V1_SET_APP_ID, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_activation_token_v1), 0, app_id);
+365
}
+366
+367
/**
+368
* @ingroup iface_xdg_activation_token_v1
+369
*
+370
* This request sets the surface requesting the activation. Note, this is
+371
* different from the surface that will be activated.
+372
*
+373
* Some compositors might refuse to activate toplevels when the token
+374
* doesn't have a requesting surface.
+375
*
+376
* Must be sent before commit. This information is optional.
+377
*/
+378
static inline void
+379
xdg_activation_token_v1_set_surface(struct xdg_activation_token_v1 *xdg_activation_token_v1, struct wl_surface *surface)
+380
{
+381
wl_proxy_marshal_flags((struct wl_proxy *) xdg_activation_token_v1,
+382
XDG_ACTIVATION_TOKEN_V1_SET_SURFACE, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_activation_token_v1), 0, surface);
+383
}
+384
+385
/**
+386
* @ingroup iface_xdg_activation_token_v1
+387
*
+388
* Requests an activation token based on the different parameters that
+389
* have been offered through set_serial, set_surface and set_app_id.
+390
*/
+391
static inline void
+392
xdg_activation_token_v1_commit(struct xdg_activation_token_v1 *xdg_activation_token_v1)
+393
{
+394
wl_proxy_marshal_flags((struct wl_proxy *) xdg_activation_token_v1,
+395
XDG_ACTIVATION_TOKEN_V1_COMMIT, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_activation_token_v1), 0);
+396
}
+397
+398
/**
+399
* @ingroup iface_xdg_activation_token_v1
+400
*
+401
* Notify the compositor that the xdg_activation_token_v1 object will no
+402
* longer be used. The received token stays valid.
+403
*/
+404
static inline void
+405
xdg_activation_token_v1_destroy(struct xdg_activation_token_v1 *xdg_activation_token_v1)
+406
{
+407
wl_proxy_marshal_flags((struct wl_proxy *) xdg_activation_token_v1,
+408
XDG_ACTIVATION_TOKEN_V1_DESTROY, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_activation_token_v1), WL_MARSHAL_FLAG_DESTROY);
+409
}
+410
+411
#ifdef __cplusplus
+412
}
+413
#endif
+414
+415
#endif
native/wayland/xdg-activation-v1-protocol.cadded
@@ -0,0 +1,84 @@
+1
/* Generated by wayland-scanner 1.24.0 */
+2
+3
/*
+4
* Copyright © 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
+5
* Copyright © 2020 Carlos Garnacho <carlosg@gnome.org>
+6
*
+7
* Permission is hereby granted, free of charge, to any person obtaining a
+8
* copy of this software and associated documentation files (the "Software"),
+9
* to deal in the Software without restriction, including without limitation
+10
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+11
* and/or sell copies of the Software, and to permit persons to whom the
+12
* Software is furnished to do so, subject to the following conditions:
+13
*
+14
* The above copyright notice and this permission notice (including the next
+15
* paragraph) shall be included in all copies or substantial portions of the
+16
* Software.
+17
*
+18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+19
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+20
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+21
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+22
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+23
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+24
* DEALINGS IN THE SOFTWARE.
+25
*/
+26
+27
#include <stdbool.h>
+28
#include <stdlib.h>
+29
#include <stdint.h>
+30
#include "wayland-util.h"
+31
+32
#ifndef __has_attribute
+33
# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
+34
#endif
+35
+36
#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4)
+37
#define WL_PRIVATE __attribute__ ((visibility("hidden")))
+38
#else
+39
#define WL_PRIVATE
+40
#endif
+41
+42
extern const struct wl_interface wl_seat_interface;
+43
extern const struct wl_interface wl_surface_interface;
+44
extern const struct wl_interface xdg_activation_token_v1_interface;
+45
+46
static const struct wl_interface *xdg_activation_v1_types[] = {
+47
NULL,
+48
&xdg_activation_token_v1_interface,
+49
NULL,
+50
&wl_surface_interface,
+51
NULL,
+52
&wl_seat_interface,
+53
&wl_surface_interface,
+54
};
+55
+56
static const struct wl_message xdg_activation_v1_requests[] = {
+57
{ "destroy", "", xdg_activation_v1_types + 0 },
+58
{ "get_activation_token", "n", xdg_activation_v1_types + 1 },
+59
{ "activate", "so", xdg_activation_v1_types + 2 },
+60
};
+61
+62
WL_PRIVATE const struct wl_interface xdg_activation_v1_interface = {
+63
"xdg_activation_v1", 1,
+64
3, xdg_activation_v1_requests,
+65
0, NULL,
+66
};
+67
+68
static const struct wl_message xdg_activation_token_v1_requests[] = {
+69
{ "set_serial", "uo", xdg_activation_v1_types + 4 },
+70
{ "set_app_id", "s", xdg_activation_v1_types + 0 },
+71
{ "set_surface", "o", xdg_activation_v1_types + 6 },
+72
{ "commit", "", xdg_activation_v1_types + 0 },
+73
{ "destroy", "", xdg_activation_v1_types + 0 },
+74
};
+75
+76
static const struct wl_message xdg_activation_token_v1_events[] = {
+77
{ "done", "s", xdg_activation_v1_types + 0 },
+78
};
+79
+80
WL_PRIVATE const struct wl_interface xdg_activation_token_v1_interface = {
+81
"xdg_activation_token_v1", 1,
+82
5, xdg_activation_token_v1_requests,
+83
1, xdg_activation_token_v1_events,
+84
};
native/window-wayland-services.incmodified
@@ -228,6 +228,29 @@ static int window_service_live(Wl *w)
228
return w && w->display && !w->dead && !w->closed && !w->closing;
229
}
230
+231
static Value native_wl_activate(SigilVM *vm, int argc, Value *args)
+232
{
+233
Wl *w = window_service_handle(vm, args[0]);
+234
if (sigil_is_false(args[1])) return SIGIL_FALSE;
+235
if (!sigil_is_string(args[1])) {
+236
sigil__vm_error(vm, SIGIL_ERR_TYPE, "wayland-activate!: expected a token string or false");
+237
return DONE;
+238
}
+239
+240
size_t length = ((SigilString *)sigil_as_ptr(args[1]))->byte_length;
+241
const char *token = sigil_string_bytes(args[1]);
+242
if (!length || length > 1024 || memchr(token, 0, length)) return SIGIL_FALSE;
+243
if (!window_service_live(w) || w->parent || !w->toplevel || !w->surface || !w->activation ||
+244
w->connection_depth) return SIGIL_FALSE;
+245
+246
xdg_activation_v1_activate(w->activation, token, w->surface);
+247
if (wl_display_flush(w->display) < 0 && errno != EAGAIN) {
+248
fail(w, "the compositor connection failed");
+249
return SIGIL_FALSE;
+250
}
+251
return SIGIL_TRUE;
+252
}
+253
254
static void window_service_fullscreen_event(Wl *w, int type)
255
{
256
Event *event = push(w, type);
scripts/test-wayland-dual-link.sglmodified
@@ -6,23 +6,26 @@
6
(define fixture (path root "test/link-check"))
7
(define cli (arg 1 default: (executable-path)))
8
−9
(define (global-definitions archive)
+9
(define (global-symbols archive selection)
10
(map (lambda (line) (car (split line " ")))
11
(filter (lambda (line) (and (not (equal? line "")) (not (ends-with? line ":"))))
−12
(lines nm -P -g --defined-only ,archive timeout: 30))))
+12
(lines nm -P -g ,selection ,archive timeout: 30))))
13
14
($ ,cli deps install cwd: ,fixture timeout: 180)
15
(each config '("gcc" "dev")
16
($ ,cli build --config ,config cwd: ,fixture timeout: 300)
17
(define build (path fixture "build" config))
−18
(define ui (global-definitions (path build "native/libsigil-ui.a")))
−19
(define window (global-definitions (path build "native/libsigil-window.a")))
+18
(define ui-archive (path build "native/libsigil-ui.a"))
+19
(define ui (global-symbols ui-archive "--defined-only"))
+20
(define window (global-symbols (path build "native/libsigil-window.a") "--defined-only"))
21
(define collisions (filter (lambda (name) (member name window)) ui))
22
(unless (null? collisions)
23
(error "Wayland libraries define duplicate globals" config collisions))
24
(unless (and (member "sui_wayland_acquire" ui)
25
(member "sigil_window_wayland_acquire" window)
−25
(member "wl_display_interface" window))
+26
(member "wl_display_interface" window)
+27
(member "xdg_activation_v1_interface" window)
+28
(member "xdg_activation_v1_interface" (global-symbols ui-archive "--undefined-only")))
29
(error "Expected both Wayland bridges and sigil-window protocol tables" config))
30
($ ,(path build "bin/sigil-ui-link-check") timeout: 30)
31
(println "PASS: ~a linked both Wayland archives with unique globals" config))
src/sigil/ui/wayland.sglmodified
@@ -75,7 +75,7 @@
75
open-wayland-subsurface wayland-set-alpha! wayland-keymap wayland-native-handle
76
wayland-cursor-configure! wayland-set-cursor! wayland-set-cursor-image! wayland-cursor-backend
77
wayland-clipboard-set! wayland-clipboard-read
−78
wayland-set-title! wayland-decoration-mode
+78
wayland-set-title! wayland-decoration-mode wayland-activate!
79
wayland-set-fullscreen! wayland-surface-fullscreen?
80
wayland-window-set-title! wayland-window-clipboard-read wayland-window-clipboard-set!
81
wayland-window-fullscreen? wayland-window-set-fullscreen! wayland-window-fullscreen-status
@@ -112,6 +112,7 @@
112
(define-native (%wl-cursor-image! s pixels width height stride x y scale)
113
(: any? any? any? any? any? any? any? any? -> any?))
114
(define-native (%wl-title! s title) (: any? any? -> any?))
+115
(define-native (%wl-activate! s token) (: any? any? -> any?))
116
(define-native (%wl-fullscreen! s fullscreen?) (: any? any? -> any?))
117
(define-native (%wl-fullscreen? s) (: any? -> any?))
118
(define-native (%wl-clipboard-set! s text) (: any? any? -> any?))
@@ -179,6 +180,12 @@
180
(define (wayland-set-title! surface title)
181
(%wl-title! (wayland-surface-handle surface) title))
182
+183
;;; Submit a compositor-issued token on this toplevel's connection.
+184
;;; Tokens may contain up to 1024 bytes and may not contain NUL.
+185
;;; Return true if submitted. The compositor decides whether to focus the window.
+186
(define (wayland-activate! surface token)
+187
(%wl-activate! (wayland-surface-handle surface) token))
+188
189
;; Portable host services keep legacy Wayland behavior above unchanged.
190
(define (wayland-window-set-title! surface title)
191
(%window-title! (wayland-surface-handle surface) title))
test/wayland/standalone-protocols.hmodified
@@ -4,6 +4,7 @@
4
#ifdef SIGIL_UI_EXTERNAL_WAYLAND_PROTOCOLS
5
#pragma GCC visibility push(hidden)
6
#include "wayland-protocol.c"
+7
#include "xdg-activation-v1-protocol.c"
8
#include "xdg-shell-protocol.c"
9
#include "xdg-decoration-unstable-v1-protocol.c"
10
#include "wlr-layer-shell-unstable-v1-protocol.c"