From 03e1b906abc6b29bb4b76b6e0429b8da9e2e2c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 11 May 2021 17:58:40 +0200 Subject: [PATCH] meson: add xdg-activation-v1.xml conditionally MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only enable XDG activation when compiling against wayland-protocols 1.21. Older versions don’t have this protocol. When available, define HAVE_XDG_ACTIVATION. Make all usages of xdg_activation_v1 and xdg_activation_token_v1 conditional. --- meson.build | 9 +++++++-- wayland.c | 16 ++++++++++++++++ wayland.h | 9 ++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index b78079c3..0c48929a 100644 --- a/meson.build +++ b/meson.build @@ -88,16 +88,21 @@ wscanner_prog = find_program( wl_proto_headers = [] wl_proto_src = [] -foreach prot : [ +wl_proto_xml = [ wayland_protocols_datadir + '/stable/xdg-shell/xdg-shell.xml', wayland_protocols_datadir + '/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml', wayland_protocols_datadir + '/unstable/xdg-output/xdg-output-unstable-v1.xml', wayland_protocols_datadir + '/unstable/primary-selection/primary-selection-unstable-v1.xml', wayland_protocols_datadir + '/stable/presentation-time/presentation-time.xml', wayland_protocols_datadir + '/unstable/text-input/text-input-unstable-v3.xml', - wayland_protocols_datadir + '/staging/xdg-activation/xdg-activation-v1.xml', ] +if wayland_protocols.version().version_compare('>=1.21') + add_project_arguments('-DHAVE_XDG_ACTIVATION', language: 'c') + wl_proto_xml += [wayland_protocols_datadir + '/staging/xdg-activation/xdg-activation-v1.xml'] +endif + +foreach prot : wl_proto_xml wl_proto_headers += custom_target( prot.underscorify() + '-client-header', output: '@BASENAME@.h', diff --git a/wayland.c b/wayland.c index 35ed35dd..cbceb576 100644 --- a/wayland.c +++ b/wayland.c @@ -985,6 +985,7 @@ 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)) @@ -993,6 +994,7 @@ handle_global(void *data, struct wl_registry *registry, 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) { @@ -1192,7 +1194,11 @@ 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"); @@ -1286,8 +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) @@ -1465,8 +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) @@ -1588,6 +1598,7 @@ 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) @@ -1607,10 +1618,12 @@ activation_token_done(void *data, struct xdg_activation_token_v1 *xdg_token, 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) @@ -1632,6 +1645,9 @@ wayl_win_set_urgent(struct wl_window *win) xdg_activation_token_v1_commit(token); win->xdg_activation_token = token; return true; +#else + return false; +#endif } bool diff --git a/wayland.h b/wayland.h index dd6637cd..4ec09544 100644 --- a/wayland.h +++ b/wayland.h @@ -12,11 +12,14 @@ #include #include #include -#include #include #include #include +#if defined(HAVE_XDG_ACTIVATION) + #include +#endif + #include #include "fdm.h" @@ -383,7 +386,9 @@ struct wl_window { struct wl_surface *surface; struct xdg_surface *xdg_surface; struct xdg_toplevel *xdg_toplevel; +#if defined(HAVE_XDG_ACTIVATION) struct xdg_activation_token_v1 *xdg_activation_token; +#endif struct zxdg_toplevel_decoration_v1 *xdg_toplevel_decoration; @@ -451,7 +456,9 @@ struct wayland { struct wl_data_device_manager *data_device_manager; struct zwp_primary_selection_device_manager_v1 *primary_selection_device_manager; +#if defined(HAVE_XDG_ACTIVATION) struct xdg_activation_v1 *xdg_activation; +#endif struct wp_presentation *presentation; uint32_t presentation_clock_id;