]> git.mdlowis.com Git - proto/labwc.git/commitdiff
ssd: add titleLayout setting
authorTobias Bengfort <tobias.bengfort@posteo.de>
Sat, 17 Aug 2024 12:45:25 +0000 (14:45 +0200)
committerTobias Bengfort <tobias.bengfort@posteo.de>
Tue, 20 Aug 2024 21:04:10 +0000 (23:04 +0200)
docs/labwc-config.5.scd
docs/rc.xml.all
include/config/rcxml.h
src/config/rcxml.c

index bd03fd6bf4f447724f4c615a914c7a02febd8b66..4345794f66a3bb3ab72eacb818722c68bae97393 100644 (file)
@@ -432,6 +432,18 @@ extending outward from the snapped edge.
 *<theme><name>*
        The name of the Openbox theme to use. It is not set by default.
 
+*<theme><titleLayout>*
+       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
+
 *<theme><cornerRadius>*
        The radius of server side decoration top corners. Default is 8.
 
index f71014a67a68fc948e7361f2085cbf4fc58e3a34..a1d030b579321ebc3f68764e052c5d2a3b331282 100644 (file)
@@ -28,6 +28,7 @@
   <!-- <font><theme> can be defined without an attribute to set all places -->
   <theme>
     <name></name>
+    <titleLayout>WLIMC</titleLayout>
     <cornerRadius>8</cornerRadius>
     <keepBorder>yes</keepBorder>
     <dropShadows>no</dropShadows>
index 2b5da58867760d1433c99e995f13ecc949029532..436876686a2a4297ed671a6bbede9d67a8d1c863 100644 (file)
@@ -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;
index da0bbde3e795ad963e1d272ae7b90aa00f71a531..c67a49e9041c516937b4ef5baf5541d481493370 100644 (file)
@@ -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);