From 28a1c67dd5ecc917ebd69c0552a1ed99165c310f Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 8 Sep 2024 11:18:30 +0200 Subject: wayland: bind the xdg-toplevel-icon manager global --- wayland.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'wayland.c') diff --git a/wayland.c b/wayland.c index 3f65901b..1e98560a 100644 --- a/wayland.c +++ b/wayland.c @@ -1363,6 +1363,17 @@ handle_global(void *data, struct wl_registry *registry, &wp_single_pixel_buffer_manager_v1_interface, required); } +#if defined(HAVE_XDG_TOPLEVEL_ICON) + else if (streq(interface, xdg_toplevel_icon_v1_interface.name)) { + const uint32_t required = 1; + if (!verify_iface_version(interface, version, required)) + return; + + wayl->toplevel_icon_manager = wl_registry_bind( + wayl->registry, name, &xdg_toplevel_icon_v1_interface, required); + } +#endif + #if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED else if (streq(interface, zwp_text_input_manager_v3_interface.name)) { const uint32_t required = 1; @@ -1679,6 +1690,10 @@ wayl_destroy(struct wayland *wayl) zwp_text_input_manager_v3_destroy(wayl->text_input_manager); #endif +#if defined(HAVE_XDG_TOPLEVEL_ICON) + if (wayl->toplevel_icon_manager != NULL) + xdg_toplevel_icon_manager_v1_destroy(wayl->toplevel_icon_manager); +#endif if (wayl->single_pixel_manager != NULL) wp_single_pixel_buffer_manager_v1_destroy(wayl->single_pixel_manager); if (wayl->fractional_scale_manager != NULL) -- cgit v1.3 From 0cb07027f2f1e5035cc009140084128d35995c54 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 8 Sep 2024 13:15:21 +0200 Subject: wayland: set toplevel icon If the xdg-toplevel-icon-v1 protocol is available, and we have the corresponding manager global, set the toplevel icon to "foot". Note: we do *not* provide any pixel data. This is by design; we want to keep things simple. To be able to provide pixel data, we would have to either: * embed the raw pixel data in the foot binary * link against either libpng or/and e.g. nanosvg, locate, at run-time, the paths to our own icons, and load them at run-time. * link against either libpng or/and e.g. nanosvg, and, at run-time, do a full icon lookup. This would also require us to add a config option for which icon theme to use. Of the two, I would prefer the first option. But, let's skip this completely for now. By providing the icon as a name, the compositor will have to lookup the icon itself. Compositors supporting icons is likely to already support this. So what do we gain by implementing this protocol? Compositors no longer has to parse .desktop files and map our app-id to find the icon to use. There's one question remaining. With this patch, the icon name is hardcoded to "foot", just like our .desktop files. But, perhaps we should use the app-id instead? And if so, should we also change the icon when the app-id changes? My gut feeling is, yes, we should use the app-id instead, and yes, we should update the icon when the app-id is changed at run-time. --- wayland.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'wayland.c') diff --git a/wayland.c b/wayland.c index 1e98560a..30ee86c6 100644 --- a/wayland.c +++ b/wayland.c @@ -1811,6 +1811,17 @@ wayl_win_init(struct terminal *term, const char *token) xdg_toplevel_set_app_id(win->xdg_toplevel, conf->app_id); +#if defined(HAVE_XDG_TOPLEVEL_ICON) + if (wayl->toplevel_icon_manager != NULL) { + struct xdg_toplevel_icon_v1 *icon = + xdg_toplevel_icon_manager_v1_create_icon(wayl->toplevel_icon_manager); + xdg_toplevel_icon_v1_set_name(icon, "foot"); + xdg_toplevel_icon_manager_v1_set_icon( + wayl->toplevel_icon_manager, win->xdg_toplevel, icon); + xdg_toplevel_icon_v1_destroy(icon); + } +#endif + if (conf->csd.preferred == CONF_CSD_PREFER_NONE) { /* User specifically do *not* want decorations */ win->csd_mode = CSD_NO; -- cgit v1.3 From b34137dde3bd40b5a116b4d8f86196027fc11d3f Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 8 Sep 2024 18:25:07 +0200 Subject: toplevel-icon: set to app-id, instead of hardcoding to "foot" And, special case "footclient", and map it to "foot". --- render.c | 27 ++++++++++++++++++++++++--- wayland.c | 6 +++++- 2 files changed, 29 insertions(+), 4 deletions(-) (limited to 'wayland.c') diff --git a/render.c b/render.c index 00ea3445..93bad7fe 100644 --- a/render.c +++ b/render.c @@ -4944,10 +4944,31 @@ render_refresh_app_id(struct terminal *term) }; timerfd_settime(term->render.app_id.timer_fd, 0, &timeout, NULL); - } else { - term->render.app_id.last_update = now; - xdg_toplevel_set_app_id(term->window->xdg_toplevel, term->app_id ? term->app_id : term->conf->app_id); + return; } + + const char *app_id = + term->app_id != NULL ? term->app_id : term->conf->app_id; + + xdg_toplevel_set_app_id(term->window->xdg_toplevel, app_id); + +#if defined(HAVE_XDG_TOPLEVEL_ICON) + if (term->wl->toplevel_icon_manager != NULL) { + struct xdg_toplevel_icon_v1 *icon = + xdg_toplevel_icon_manager_v1_create_icon( + term->wl->toplevel_icon_manager); + + xdg_toplevel_icon_v1_set_name( + icon, streq(app_id, "footclient") ? "foot" : app_id); + + xdg_toplevel_icon_manager_v1_set_icon( + term->wl->toplevel_icon_manager, term->window->xdg_toplevel, icon); + + xdg_toplevel_icon_v1_destroy(icon); + } +#endif + + term->render.app_id.last_update = now; } void diff --git a/wayland.c b/wayland.c index 30ee86c6..fd228312 100644 --- a/wayland.c +++ b/wayland.c @@ -1813,9 +1813,13 @@ wayl_win_init(struct terminal *term, const char *token) #if defined(HAVE_XDG_TOPLEVEL_ICON) if (wayl->toplevel_icon_manager != NULL) { + const char *app_id = + term->app_id != NULL ? term->app_id : term->conf->app_id; + struct xdg_toplevel_icon_v1 *icon = xdg_toplevel_icon_manager_v1_create_icon(wayl->toplevel_icon_manager); - xdg_toplevel_icon_v1_set_name(icon, "foot"); + xdg_toplevel_icon_v1_set_name(icon, streq( + app_id, "footclient") ? "foot" : app_id); xdg_toplevel_icon_manager_v1_set_icon( wayl->toplevel_icon_manager, win->xdg_toplevel, icon); xdg_toplevel_icon_v1_destroy(icon); -- cgit v1.3 From c6208a98c80f4b945608b4ce1bd6f35fab5b56d8 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 13 Sep 2024 08:45:54 +0200 Subject: main: include toplevel-icon support in --version output --- foot-features.h | 9 +++++++++ main.c | 3 ++- wayland.c | 20 +++++++++++++------- 3 files changed, 24 insertions(+), 8 deletions(-) (limited to 'wayland.c') diff --git a/foot-features.h b/foot-features.h index ad447767..674c1056 100644 --- a/foot-features.h +++ b/foot-features.h @@ -37,3 +37,12 @@ static inline bool feature_graphemes(void) return false; #endif } + +static inline bool feature_xdg_toplevel_icon(void) +{ +#if defined(HAVE_XDG_TOPLEVEL_ICON) + return true; +#else + return false; +#endif +} diff --git a/main.c b/main.c index 15741012..973cbae4 100644 --- a/main.c +++ b/main.c @@ -51,11 +51,12 @@ version_and_features(void) { static char buf[256]; snprintf(buf, sizeof(buf), - "version: %s %cpgo %cime %cgraphemes %cassertions", + "version: %s %cpgo %cime %cgraphemes %ctoplevel-icon %cassertions", FOOT_VERSION, feature_pgo() ? '+' : '-', feature_ime() ? '+' : '-', feature_graphemes() ? '+' : '-', + feature_xdg_toplevel_icon() ? '+' : '-', feature_assertions() ? '+' : '-'); return buf; } diff --git a/wayland.c b/wayland.c index fd228312..9c184adc 100644 --- a/wayland.c +++ b/wayland.c @@ -1592,27 +1592,33 @@ wayl_init(struct fdm *fdm, struct key_binding_manager *key_binding_manager, goto out; } + if (presentation_timings && wayl->presentation == NULL) { + LOG_ERR("compositor does not implement the presentation time interface"); + goto out; + } + if (wayl->primary_selection_device_manager == NULL) - LOG_WARN("no primary selection available"); + LOG_WARN("compositor does not implement the primary selection interface"); if (wayl->xdg_activation == NULL) { LOG_WARN( - "no XDG activation support; " + "compositor does not implement XDG activation, " "bell.urgent will fall back to coloring the window margins red"); } if (wayl->fractional_scale_manager == NULL || wayl->viewporter == NULL) - LOG_WARN("fractional scaling not available"); + LOG_WARN("compositor does not implement fractional scaling"); if (wayl->cursor_shape_manager == NULL) { - LOG_WARN("no server-side cursors available, " + LOG_WARN("compositor does not implement server-side cursors, " "falling back to client-side cursors"); } - if (presentation_timings && wayl->presentation == NULL) { - LOG_ERR("presentation time interface not implemented by compositor"); - goto out; +#if defined(HAVE_XDG_TOPLEVEL_ICON) + if (wayl->toplevel_icon_manager == NULL) { + LOG_WARN("compositor does not implement the XDG toplevel icon protocol"); } +#endif #if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED if (wayl->text_input_manager == NULL) { -- cgit v1.3