From 9a252249c98f62a50782ca77e8c9eab1f32435b0 Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Sat, 17 Aug 2024 14:45:25 +0200 Subject: [PATCH] ssd: add titleLayout setting --- docs/labwc-config.5.scd | 12 +++++++ docs/rc.xml.all | 1 + include/config/rcxml.h | 10 ++++++ src/config/rcxml.c | 73 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+) diff --git a/docs/labwc-config.5.scd b/docs/labwc-config.5.scd index bd03fd6b..4345794f 100644 --- a/docs/labwc-config.5.scd +++ b/docs/labwc-config.5.scd @@ -432,6 +432,18 @@ extending outward from the snapped edge. ** The name of the Openbox theme to use. It is not set by default. +** + Selection and order of buttons in a window's titlebar. + The following letters can be used, each only once: + - L: window label (aka. title) + - |: empty space (can be used instead of a title) + - W: window menu + - I: iconify + - M: maximize + - C: close + + Example: WLIMC + ** The radius of server side decoration top corners. Default is 8. diff --git a/docs/rc.xml.all b/docs/rc.xml.all index f71014a6..a1d030b5 100644 --- a/docs/rc.xml.all +++ b/docs/rc.xml.all @@ -28,6 +28,7 @@ + WLIMC 8 yes no diff --git a/include/config/rcxml.h b/include/config/rcxml.h index 2b5da588..43687668 100644 --- a/include/config/rcxml.h +++ b/include/config/rcxml.h @@ -14,6 +14,7 @@ #include "config/tablet-tool.h" #include "config/libinput.h" #include "resize-indicator.h" +#include "ssd.h" #include "theme.h" enum view_placement_policy { @@ -45,6 +46,11 @@ enum tiling_events_mode { (LAB_TILING_EVENTS_REGION | LAB_TILING_EVENTS_EDGE), }; +struct title_button { + enum ssd_part_type type; + struct wl_list link; +}; + struct usable_area_override { struct border margin; char *output; @@ -75,7 +81,11 @@ struct rcxml { /* theme */ char *theme_name; + struct wl_list title_buttons_left; + struct wl_list title_buttons_right; int corner_radius; + bool show_title; + bool title_layout_loaded; bool ssd_keep_border; bool shadows_enabled; struct font font_activewindow; diff --git a/src/config/rcxml.c b/src/config/rcxml.c index da0bbde3..c67a49e9 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -116,6 +116,59 @@ parse_window_type(const char *type) } } +static void +fill_title_layout(char *nodename, char *content) +{ + char *c, *c2; + enum ssd_part_type type; + struct title_button *item; + struct wl_list *list = &rc.title_buttons_left; + + for (c = content; *c != '\0'; c++) { + for (c2 = content; c2 < c; c2++) { + if (*c2 == *c) { + break; + } + } + if (c2 != c) { + continue; + } + + switch (*c) { + /* case 'N': icon */ + case 'L': + list = &rc.title_buttons_right; + rc.show_title = true; + continue; + case '|': + list = &rc.title_buttons_right; + continue; + case 'W': + type = LAB_SSD_BUTTON_WINDOW_MENU; + break; + case 'I': + type = LAB_SSD_BUTTON_ICONIFY; + break; + case 'M': + type = LAB_SSD_BUTTON_MAXIMIZE; + break; + case 'C': + type = LAB_SSD_BUTTON_CLOSE; + break; + /* case 'S': shade */ + /* case 'D': omnipresent */ + default: + continue; + } + + item = znew(*item); + item->type = type; + wl_list_append(list, &item->link); + } + + rc.title_layout_loaded = true; +} + static void fill_usable_area_override(char *nodename, char *content) { @@ -916,6 +969,8 @@ entry(xmlNode *node, char *nodename, char *content) rc.placement_cascade_offset_y = atoi(content); } else if (!strcmp(nodename, "name.theme")) { rc.theme_name = xstrdup(content); + } else if (!strcmp(nodename, "titlelayout.theme")) { + fill_title_layout(nodename, content); } else if (!strcmp(nodename, "cornerradius.theme")) { rc.corner_radius = atoi(content); } else if (!strcasecmp(nodename, "keepBorder.theme")) { @@ -1236,6 +1291,8 @@ rcxml_init(void) static bool has_run; if (!has_run) { + wl_list_init(&rc.title_buttons_left); + wl_list_init(&rc.title_buttons_right); wl_list_init(&rc.usable_area_overrides); wl_list_init(&rc.keybinds); wl_list_init(&rc.mousebinds); @@ -1253,6 +1310,8 @@ rcxml_init(void) rc.placement_cascade_offset_y = 0; rc.xdg_shell_server_side_deco = true; + rc.show_title = false; + rc.title_layout_loaded = false; rc.ssd_keep_border = true; rc.corner_radius = 8; rc.shadows_enabled = false; @@ -1494,6 +1553,10 @@ post_processing(void) load_default_mouse_bindings(); } + if (!rc.title_layout_loaded) { + fill_title_layout("titlelayout.theme", "WLIMC"); + } + /* * Replace all earlier bindings by later ones * and clear the ones with an empty action list. @@ -1720,6 +1783,16 @@ rcxml_finish(void) zfree(rc.theme_name); zfree(rc.workspace_config.prefix); + struct title_button *p, *p_tmp; + wl_list_for_each_safe(p, p_tmp, &rc.title_buttons_left, link) { + wl_list_remove(&p->link); + zfree(p); + } + wl_list_for_each_safe(p, p_tmp, &rc.title_buttons_right, link) { + wl_list_remove(&p->link); + zfree(p); + } + struct usable_area_override *area, *area_tmp; wl_list_for_each_safe(area, area_tmp, &rc.usable_area_overrides, link) { wl_list_remove(&area->link); -- 2.52.0