ssd: support window icons

The default `titleLayout` is updated to `icon:iconify,max,close` which
replaces the window menu button with the window icon.

When the icon file is not found or could not be loaded, the window menu
icon as before is shown.

The icon theme can be selected with `<theme><icon>`.

This commit adds libsfdo as an optional dependency. `-Dicon=disabled` can
be passsed to `meson setup` command in order to disable window icon, in
which case the window icon is always replaced with a window menu button.
This commit is contained in:
tokyo4j 2024-09-06 17:00:40 +09:00 committed by Hiroaki Yamamoto
parent b9414d8b8d
commit a745f91169
32 changed files with 452 additions and 142 deletions

View file

@ -1,9 +0,0 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LABWC_BUTTON_PNG_H
#define LABWC_BUTTON_PNG_H
struct lab_data_buffer;
void button_png_load(const char *button_name, struct lab_data_buffer **buffer);
#endif /* LABWC_BUTTON_PNG_H */

View file

@ -1,10 +0,0 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LABWC_BUTTON_SVG_H
#define LABWC_BUTTON_SVG_H
struct lab_data_buffer;
void button_svg_load(const char *button_name, struct lab_data_buffer **buffer,
int size);
#endif /* LABWC_BUTTON_SVG_H */

View file

@ -1,22 +0,0 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LABWC_BUTTON_XBM_H
#define LABWC_BUTTON_XBM_H
struct lab_data_buffer;
/**
* button_xbm_from_bitmap() - create button from monochrome bitmap
* @bitmap: bitmap data array in hexadecimal xbm format
* @buffer: cairo-surface-buffer to create
* @rgba: color
*
* Example bitmap: char button[6] = { 0x3f, 0x3f, 0x21, 0x21, 0x21, 0x3f };
*/
void button_xbm_from_bitmap(const char *bitmap, struct lab_data_buffer **buffer,
float *rgba);
/* button_xbm_load - Convert xbm file to buffer with cairo surface */
void button_xbm_load(const char *button_name, struct lab_data_buffer **buffer,
float *rgba);
#endif /* LABWC_BUTTON_XBM_H */

View file

@ -1,17 +0,0 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LABWC_BUTTON_COMMON_H
#define LABWC_BUTTON_COMMON_H
#include <stddef.h>
/**
* button_filename() - Get full filename for button.
* @name: The name of the button (for example 'iconify.xbm').
* @buf: Buffer to fill with the full filename
* @len: Length of buffer
*
* Example return value: /usr/share/themes/Numix/openbox-3/iconify.xbm
*/
void button_filename(const char *name, char *buf, size_t len);
#endif /* LABWC_BUTTON_COMMON_H */

View file

@ -376,6 +376,32 @@ static struct mouse_combos {
.name = "atCursor",
.value = "no",
},
}, {
.context = "Icon",
.button = "Left",
.event = "Click",
.action = "ShowMenu",
.attributes[0] = {
.name = "menu",
.value = "client-menu",
},
.attributes[1] = {
.name = "atCursor",
.value = "no",
},
}, {
.context = "Icon",
.button = "Right",
.event = "Click",
.action = "ShowMenu",
.attributes[0] = {
.name = "menu",
.value = "client-menu",
},
.attributes[1] = {
.name = "atCursor",
.value = "no",
},
}, {
.context = "Root",
.button = "Left",

View file

@ -81,6 +81,7 @@ struct rcxml {
/* theme */
char *theme_name;
char *icon_theme_name;
struct wl_list title_buttons_left;
struct wl_list title_buttons_right;
int corner_radius;

12
include/icon-loader.h Normal file
View file

@ -0,0 +1,12 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LABWC_ICON_LOADER_H
#define LABWC_ICON_LOADER_H
struct server;
void icon_loader_init(struct server *server);
void icon_loader_finish(struct server *server);
struct lab_data_buffer *icon_loader_lookup(struct server *server,
const char *app_id, int size, int scale);
#endif /* LABWC_ICON_LOADER_H */

9
include/img/img-png.h Normal file
View file

@ -0,0 +1,9 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LABWC_IMG_PNG_H
#define LABWC_IMG_PNG_H
struct lab_data_buffer;
void img_png_load(const char *filename, struct lab_data_buffer **buffer);
#endif /* LABWC_IMG_PNG_H */

10
include/img/img-svg.h Normal file
View file

@ -0,0 +1,10 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LABWC_IMG_SVG_H
#define LABWC_IMG_SVG_H
struct lab_data_buffer;
void img_svg_load(const char *filename, struct lab_data_buffer **buffer,
int size);
#endif /* LABWC_IMG_SVG_H */

22
include/img/img-xbm.h Normal file
View file

@ -0,0 +1,22 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LABWC_IMG_XBM_H
#define LABWC_IMG_XBM_H
struct lab_data_buffer;
/**
* img_xbm_from_bitmap() - create button from monochrome bitmap
* @bitmap: bitmap data array in hexadecimal xbm format
* @buffer: cairo-surface-buffer to create
* @rgba: color
*
* Example bitmap: char button[6] = { 0x3f, 0x3f, 0x21, 0x21, 0x21, 0x3f };
*/
void img_xbm_from_bitmap(const char *bitmap, struct lab_data_buffer **buffer,
float *rgba);
/* img_xbm_load - Convert xbm file to buffer with cairo surface */
void img_xbm_load(const char *filename, struct lab_data_buffer **buffer,
float *rgba);
#endif /* LABWC_IMG_XBM_H */

View file

@ -365,6 +365,8 @@ struct server {
struct menu *menu_current;
struct wl_list menus;
struct icon_loader *icon_loader;
pid_t primary_client_pid;
};

View file

@ -73,6 +73,8 @@ struct ssd {
struct ssd_state_title_width active;
struct ssd_state_title_width inactive;
} title;
char *app_id;
} state;
/* An invisible area around the view which allows resizing */
@ -145,6 +147,8 @@ struct ssd_part *add_scene_button(
void add_toggled_icon(struct ssd_button *button, struct wl_list *part_list,
enum ssd_part_type type, struct wlr_buffer *icon_buffer,
struct wlr_buffer *hover_buffer);
void update_window_icon_buffer(struct wlr_scene_node *button_node,
struct wlr_buffer *buffer);
/* SSD internal helpers */
struct ssd_part *ssd_get_part(

View file

@ -24,6 +24,7 @@ enum ssd_part_type {
LAB_SSD_BUTTON_CLOSE,
LAB_SSD_BUTTON_MAXIMIZE,
LAB_SSD_BUTTON_ICONIFY,
LAB_SSD_BUTTON_WINDOW_ICON,
LAB_SSD_BUTTON_WINDOW_MENU,
LAB_SSD_BUTTON_SHADE,
LAB_SSD_BUTTON_OMNIPRESENT,
@ -87,6 +88,7 @@ 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);