Support xdg-toplevel-icon protocol

This patch also changes the semantics of scaled_icon_buffer: rather than
calling scaled_icon_buffer_set_app_id() every time an app_id is set, we
can now call scaled_icon_buffer_set_view() just once so that multiple
scaled_icon_buffers bound to a window are automatically updated when an
app_id is set or new icon is set via xdg-toplevel-icon-v1.
This commit is contained in:
tokyo4j 2025-05-30 20:58:48 +09:00 committed by Hiroaki Yamamoto
parent 649773b4f8
commit fb077c0095
12 changed files with 247 additions and 57 deletions

View file

@ -3,6 +3,7 @@
#define LABWC_SCALED_ICON_BUFFER_H
#include <stdbool.h>
#include <wayland-server-core.h>
struct wlr_scene_tree;
struct wlr_scene_node;
@ -12,8 +13,18 @@ struct scaled_icon_buffer {
struct scaled_scene_buffer *scaled_buffer;
struct wlr_scene_buffer *scene_buffer;
struct server *server;
char *app_id;
/* for window icon */
struct view *view;
char *view_app_id;
char *view_icon_name;
struct wl_array view_icon_buffers;
struct {
struct wl_listener set_icon;
struct wl_listener destroy;
} on_view;
/* for general icon (e.g. in menus) */
char *icon_name;
int width;
int height;
};
@ -28,8 +39,8 @@ struct scaled_icon_buffer *scaled_icon_buffer_create(
struct wlr_scene_tree *parent, struct server *server,
int width, int height);
void scaled_icon_buffer_set_app_id(struct scaled_icon_buffer *self,
const char *app_id);
void scaled_icon_buffer_set_view(struct scaled_icon_buffer *self,
struct view *view);
void scaled_icon_buffer_set_icon_name(struct scaled_icon_buffer *self,
const char *icon_name);

View file

@ -264,6 +264,9 @@ struct server {
struct wl_listener xdg_activation_request;
struct wl_listener xdg_activation_new_token;
struct wlr_xdg_toplevel_icon_manager_v1 *xdg_toplevel_icon_manager;
struct wl_listener xdg_toplevel_icon_set_icon;
struct wl_list views;
struct wl_list unmanaged_surfaces;

View file

@ -94,7 +94,6 @@ void ssd_update_title(struct ssd *ssd);
void ssd_update_geometry(struct ssd *ssd);
void ssd_destroy(struct ssd *ssd);
void ssd_set_titlebar(struct ssd *ssd, bool enabled);
void ssd_update_window_icon(struct ssd *ssd);
void ssd_enable_keybind_inhibit_indicator(struct ssd *ssd, bool enable);
void ssd_enable_shade(struct ssd *ssd, bool enable);

View file

@ -281,6 +281,12 @@ struct view {
struct foreign_toplevel *foreign_toplevel;
/* used by scaled_icon_buffer */
struct {
char *name;
struct wl_array buffers; /* struct lab_data_buffer * */
} icon;
struct {
struct wl_signal new_app_id;
struct wl_signal new_title;
@ -289,6 +295,11 @@ struct view {
struct wl_signal minimized;
struct wl_signal fullscreened;
struct wl_signal activated; /* bool *activated */
/*
* This is emitted when app_id, or icon set via xdg_toplevel_icon
* is updated. This is listened by scaled_icon_buffer.
*/
struct wl_signal set_icon;
struct wl_signal destroy;
} events;
};
@ -614,6 +625,10 @@ int view_get_min_width(void);
void view_set_shade(struct view *view, bool shaded);
/* Icon buffers set with this function are dropped later */
void view_set_icon(struct view *view, const char *icon_name,
struct wl_array *buffers);
struct view_size_hints view_get_size_hints(struct view *view);
void view_adjust_size(struct view *view, int *w, int *h);