diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2021-05-14 12:23:19 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2021-05-14 12:23:19 +0000 |
| commit | 92e517ae34243d9c294e966221f5a4589684a9b5 (patch) | |
| tree | 2fb1774c2e62ada3c387b71e577bcee3c0960d63 /wayland.c | |
| parent | Merge branch 'vt-anywhere-cleanup' (diff) | |
| parent | changeloge: xdg-activation support (diff) | |
Merge branch 'xdg-activation'
Closes #487
Diffstat (limited to 'wayland.c')
| -rw-r--r-- | wayland.c | 87 |
1 files changed, 82 insertions, 5 deletions
@@ -12,13 +12,9 @@ #include <wayland-client.h> #include <wayland-cursor.h> -#include <xdg-shell.h> #include <xkbcommon/xkbcommon-compose.h> #include <tllist.h> -#include <xdg-output-unstable-v1.h> -#include <xdg-decoration-unstable-v1.h> -#include <text-input-unstable-v3.h> #define LOG_MODULE "wayland" #define LOG_ENABLE_DBG 0 @@ -630,7 +626,7 @@ xdg_toplevel_close(void *data, struct xdg_toplevel *xdg_toplevel) static const struct xdg_toplevel_listener xdg_toplevel_listener = { .configure = &xdg_toplevel_configure, - .close = &xdg_toplevel_close, + /*.close = */&xdg_toplevel_close, /* epoll-shim defines a macro ‘close’... */ }; static void @@ -989,6 +985,17 @@ handle_global(void *data, struct wl_registry *registry, } } +#if defined(HAVE_XDG_ACTIVATION) + else if (strcmp(interface, xdg_activation_v1_interface.name) == 0) { + const uint32_t required = 1; + if (!verify_iface_version(interface, version, required)) + return; + + wayl->xdg_activation = wl_registry_bind( + wayl->registry, name, &xdg_activation_v1_interface, required); + } +#endif + #if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED else if (strcmp(interface, zwp_text_input_manager_v3_interface.name) == 0) { const uint32_t required = 1; @@ -1187,6 +1194,16 @@ wayl_init(const struct config *conf, struct fdm *fdm) if (wayl->primary_selection_device_manager == NULL) LOG_WARN("no primary selection available"); +#if defined(HAVE_XDG_ACTIVATION) + if (wayl->xdg_activation == NULL && conf->bell.urgent) { +#else + if (conf->bell.urgent) { +#endif + LOG_WARN( + "no XDG activation support; " + "bell.urgent will fall back to coloring the window margins red"); + } + if (conf->presentation_timings && wayl->presentation == NULL) { LOG_ERR("presentation time interface not implemented by compositor"); goto out; @@ -1275,6 +1292,10 @@ wayl_destroy(struct wayland *wayl) zwp_text_input_manager_v3_destroy(wayl->text_input_manager); #endif +#if defined(HAVE_XDG_ACTIVATION) + if (wayl->xdg_activation != NULL) + xdg_activation_v1_destroy(wayl->xdg_activation); +#endif if (wayl->xdg_output_manager != NULL) zxdg_output_manager_v1_destroy(wayl->xdg_output_manager); if (wayl->shell != NULL) @@ -1452,6 +1473,10 @@ wayl_win_destroy(struct wl_window *win) wayl_win_subsurface_destroy(&win->scrollback_indicator); wayl_win_subsurface_destroy(&win->render_timer); +#if defined(HAVE_XDG_ACTIVATION) + if (win->xdg_activation_token != NULL) + xdg_activation_token_v1_destroy(win->xdg_activation_token); +#endif if (win->frame_callback != NULL) wl_callback_destroy(win->frame_callback); if (win->xdg_toplevel_decoration != NULL) @@ -1573,6 +1598,58 @@ wayl_roundtrip(struct wayland *wayl) wayl_flush(wayl); } +#if defined(HAVE_XDG_ACTIVATION) +static void +activation_token_done(void *data, struct xdg_activation_token_v1 *xdg_token, + const char *token) +{ + struct wl_window *win = data; + struct wayland *wayl = win->term->wl; + + LOG_DBG("activation token: %s", token); + + xdg_activation_v1_activate(wayl->xdg_activation, token, win->surface); + + xassert(win->xdg_activation_token == xdg_token); + xdg_activation_token_v1_destroy(xdg_token); + win->xdg_activation_token = NULL; +} + +static const struct xdg_activation_token_v1_listener activation_token_listener = { + .done = &activation_token_done, +}; +#endif /* HAVE_XDG_ACTIVATION */ + +bool +wayl_win_set_urgent(struct wl_window *win) +{ +#if defined(HAVE_XDG_ACTIVATION) + struct wayland *wayl = win->term->wl; + + if (wayl->xdg_activation == NULL) + return false; + + if (win->xdg_activation_token != NULL) + return true; + + struct xdg_activation_token_v1 *token = + xdg_activation_v1_get_activation_token(wayl->xdg_activation); + + if (token == NULL) { + LOG_ERR("failed to retrieve XDG activation token"); + return false; + } + + xdg_activation_token_v1_add_listener(token, &activation_token_listener, win); + xdg_activation_token_v1_set_surface(token, win->surface); + xdg_activation_token_v1_commit(token); + win->xdg_activation_token = token; + return true; +#else + return false; +#endif +} + bool wayl_win_subsurface_new_with_custom_parent( struct wl_window *win, struct wl_surface *parent, |
