]> git.mdlowis.com Git - proto/labwc.git/commitdiff
menu: add title theme options (#2097)
authordroc12345 <80716141+droc12345@users.noreply.github.com>
Wed, 21 Aug 2024 17:27:07 +0000 (12:27 -0500)
committerGitHub <noreply@github.com>
Wed, 21 Aug 2024 17:27:07 +0000 (18:27 +0100)
Add theme options `menu.title.text.color` and `menu.title.text.justify`.

Add font place MenuHeader: `<font place="MenuHeader">`

Add `Oblique` font style

```
<theme>
  <font>
    <slant>Oblique</slant>
  </font>
</theme>
```

12 files changed:
docs/labwc-config.5.scd
docs/labwc-theme.5.scd
docs/menu.xml
docs/rc.xml.all
docs/themerc
include/common/font.h
include/config/rcxml.h
include/theme.h
src/common/font.c
src/config/rcxml.c
src/menu/menu.c
src/theme.c

index bd03fd6bf4f447724f4c615a914c7a02febd8b66..4c961115990975a8957b7285c70ea7872223c280 100644 (file)
@@ -448,6 +448,7 @@ extending outward from the snapped edge.
        - ActiveWindow - titlebar of active window
        - InactiveWindow - titlebar of all windows that aren't focused by the
          cursor
+       - MenuHeader - menu title
        - MenuItem - menu item (currently only root menu)
        - OnScreenDisplay - items in the on screen display
        If no place attribute is provided, the setting will be applied to all
@@ -460,7 +461,7 @@ extending outward from the snapped edge.
        Font size in pixels. Default is 10.
 
 *<theme><font place=""><slant>*
-       Font slant (normal or italic). Default is normal.
+       Font slant (normal, oblique or italic). Default is normal.
 
 *<theme><font place=""><weight>*
        Font weight (normal or bold). Default is normal.
index 29a832f5881b34f58bbbeb82ec168c905aeac58e..9f8310affba6f99c3da787bbd363ae6abb38db6a 100644 (file)
@@ -67,6 +67,10 @@ labwc-config(5).
        Vertical padding of menu text entries in pixels.
        Default is 4.
 
+*menu.title.text.justify*
+       Specifies how menu titles are aligned in the titlebar.
+       Type justification. Default Center.
+
 *menu.overlap.x*
        Horizontal overlap in pixels between submenus and their parents. A
        positive value move submenus over the top of their parents, whereas a
@@ -178,6 +182,9 @@ elements are not listed here, but are supported.
        Menu title color. Default #589bda.
        Note: A menu title is a separator with a label.
 
+*menu.title.text.color*
+       Text color of separator label.  Default #ffffff.
+
 *osd.bg.color*
        Background color of on-screen-display. Inherits
        *window.active.title.bg.color* if not set.
index a23f1b915e8e1ef768947499019562c3fb64367d..f150b258a6b84ef264c89d5dedb31a823e765d09 100644 (file)
 </menu>
 
 <menu id="some-custom-menu">
+  <!--
+    Creates menu title.
+    To create an empty header with no text,
+    set label=" ", not label=""
+  -->
+  <separator label="custom menu" />
   <item label="Reconfigure">
     <action name="Reconfigure" />
   </item>
index f71014a67a68fc948e7361f2085cbf4fc58e3a34..d1fc811baab3cee6fd12ef7ce06ea3d7b7238420 100644 (file)
       <slant>normal</slant>
       <weight>normal</weight>
     </font>
+    <font place="MenuHeader">
+      <name>sans</name>
+      <size>10</size>
+      <slant>normal</slant>
+      <weight>normal</weight>
+    </font>
     <font place="MenuItem">
       <name>sans</name>
       <size>10</size>
index e54dfb96f03c7fd27951a4414486977c1ec8eb23..66e1d09c59f285969fdcd4823749fe4fe139d510 100644 (file)
@@ -63,6 +63,8 @@ menu.separator.padding.width: 6
 menu.separator.padding.height: 3
 menu.separator.color: #888888
 menu.title.bg.color: #589bda
+menu.title.text.color: #ffffff
+menu.title.text.justify: Center
 
 # on screen display (window-cycle dialog)
 osd.bg.color: #e1dedb
index ddca15aaf96d2096c6118ab2f82ab339577a11b7..7684f7e244f553fa780d85d61ed68f58ed5f8e4d 100644 (file)
@@ -6,7 +6,8 @@ struct lab_data_buffer;
 
 enum font_slant {
        FONT_SLANT_NORMAL = 0,
-       FONT_SLANT_ITALIC
+       FONT_SLANT_ITALIC,
+       FONT_SLANT_OBLIQUE
 };
 
 enum font_weight {
index 2b5da58867760d1433c99e995f13ecc949029532..e981cb3669495aee0b12d672c167ad5dea3d3539 100644 (file)
@@ -80,6 +80,7 @@ struct rcxml {
        bool shadows_enabled;
        struct font font_activewindow;
        struct font font_inactivewindow;
+       struct font font_menuheader;
        struct font font_menuitem;
        struct font font_osd;
 
index 4ad3855cd71fe672ffead5f7ea9030c341267689..f0c3b757847b635f11a6fb587b8fa300b542e598 100644 (file)
@@ -44,6 +44,7 @@ struct theme {
        float window_active_label_text_color[4];
        float window_inactive_label_text_color[4];
        enum lab_justification window_label_text_justify;
+       enum lab_justification menu_title_text_justify;
 
        /* button width */
        int window_button_width;
@@ -78,6 +79,8 @@ struct theme {
 
        float menu_title_bg_color[4];
 
+       float menu_title_text_color[4];
+
        int osd_border_width;
 
        float osd_bg_color[4];
index 6e12e78012f70dfe845e4987a6afb9fa9cd23b52..e917dec9803a393d100261fee42024effc739a93 100644 (file)
@@ -20,6 +20,9 @@ font_to_pango_desc(struct font *font)
        if (font->slant == FONT_SLANT_ITALIC) {
                pango_font_description_set_style(desc, PANGO_STYLE_ITALIC);
        }
+       if (font->slant == FONT_SLANT_OBLIQUE) {
+               pango_font_description_set_style(desc, PANGO_STYLE_OBLIQUE);
+       }
        if (font->weight == FONT_WEIGHT_BOLD) {
                pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD);
        }
index da0bbde3e795ad963e1d272ae7b90aa00f71a531..38e5490f51a84080756cfee2aa4e9ed0fd728a27 100644 (file)
@@ -69,6 +69,7 @@ enum font_place {
        FONT_PLACE_UNKNOWN,
        FONT_PLACE_ACTIVEWINDOW,
        FONT_PLACE_INACTIVEWINDOW,
+       FONT_PLACE_MENUHEADER,
        FONT_PLACE_MENUITEM,
        FONT_PLACE_OSD,
        /* TODO: Add all places based on Openbox's rc.xml */
@@ -691,8 +692,13 @@ set_font_attr(struct font *font, const char *nodename, const char *content)
        } else if (!strcmp(nodename, "size")) {
                font->size = atoi(content);
        } else if (!strcmp(nodename, "slant")) {
-               font->slant = !strcasecmp(content, "italic") ?
-                       FONT_SLANT_ITALIC : FONT_SLANT_NORMAL;
+               if (!strcasecmp(content, "italic")) {
+                       font->slant = FONT_SLANT_ITALIC;
+               } else if (!strcasecmp(content, "oblique")) {
+                       font->slant = FONT_SLANT_OBLIQUE;
+               } else {
+                       font->slant = FONT_SLANT_NORMAL;
+               }
        } else if (!strcmp(nodename, "weight")) {
                font->weight = !strcasecmp(content, "bold") ?
                        FONT_WEIGHT_BOLD : FONT_WEIGHT_NORMAL;
@@ -715,6 +721,7 @@ fill_font(char *nodename, char *content, enum font_place place)
                 */
                set_font_attr(&rc.font_activewindow, nodename, content);
                set_font_attr(&rc.font_inactivewindow, nodename, content);
+               set_font_attr(&rc.font_menuheader, nodename, content);
                set_font_attr(&rc.font_menuitem, nodename, content);
                set_font_attr(&rc.font_osd, nodename, content);
                break;
@@ -724,6 +731,9 @@ fill_font(char *nodename, char *content, enum font_place place)
        case FONT_PLACE_INACTIVEWINDOW:
                set_font_attr(&rc.font_inactivewindow, nodename, content);
                break;
+       case FONT_PLACE_MENUHEADER:
+               set_font_attr(&rc.font_menuheader, nodename, content);
+               break;
        case FONT_PLACE_MENUITEM:
                set_font_attr(&rc.font_menuitem, nodename, content);
                break;
@@ -748,6 +758,8 @@ enum_font_place(const char *place)
                return FONT_PLACE_ACTIVEWINDOW;
        } else if (!strcasecmp(place, "InactiveWindow")) {
                return FONT_PLACE_INACTIVEWINDOW;
+       } else if (!strcasecmp(place, "MenuHeader")) {
+               return FONT_PLACE_MENUHEADER;
        } else if (!strcasecmp(place, "MenuItem")) {
                return FONT_PLACE_MENUITEM;
        } else if (!strcasecmp(place, "OnScreenDisplay")
@@ -1265,6 +1277,7 @@ rcxml_init(void)
 
        init_font_defaults(&rc.font_activewindow);
        init_font_defaults(&rc.font_inactivewindow);
+       init_font_defaults(&rc.font_menuheader);
        init_font_defaults(&rc.font_menuitem);
        init_font_defaults(&rc.font_osd);
 
@@ -1510,6 +1523,9 @@ post_processing(void)
        if (!rc.font_inactivewindow.name) {
                rc.font_inactivewindow.name = xstrdup("sans");
        }
+       if (!rc.font_menuheader.name) {
+               rc.font_menuheader.name = xstrdup("sans");
+       }
        if (!rc.font_menuitem.name) {
                rc.font_menuitem.name = xstrdup("sans");
        }
@@ -1715,6 +1731,7 @@ rcxml_finish(void)
 {
        zfree(rc.font_activewindow.name);
        zfree(rc.font_inactivewindow.name);
+       zfree(rc.font_menuheader.name);
        zfree(rc.font_menuitem.name);
        zfree(rc.font_osd.name);
        zfree(rc.theme_name);
index 1abef56acc0dbdb537080f6cbf4810e54fa86b52..f8653d648923267090c585efd1ef2517f30eb5dd 100644 (file)
@@ -141,6 +141,19 @@ menu_update_width(struct menu *menu)
                        wlr_scene_rect_set_size(
                                wlr_scene_rect_from_node(item->normal.text),
                                width, theme->menu_separator_line_thickness);
+               } else if (item->type == LAB_MENU_TITLE) {
+                       if (item->native_width > max_width) {
+                               scaled_font_buffer_set_max_width(item->normal.buffer,
+                                       max_width);
+                       }
+                       if (theme->menu_title_text_justify == LAB_JUSTIFY_CENTER) {
+                               int x, y;
+                               x = (max_width - theme->menu_item_padding_x -
+                                               item->native_width) / 2;
+                               x = x < 0 ? 0 : x;
+                               y = (theme->menu_item_height - item->normal.buffer->height) / 2;
+                               wlr_scene_node_set_position(item->normal.text, x, y);
+                       }
                }
 
                if (item->selectable) {
@@ -295,7 +308,7 @@ separator_create(struct menu *menu, const char *label)
 
        if (menuitem->type == LAB_MENU_TITLE) {
                menuitem->height = theme->menu_item_height;
-               menuitem->native_width = font_width(&rc.font_menuitem, label);
+               menuitem->native_width = font_width(&rc.font_menuheader, label);
        } else if (menuitem->type == LAB_MENU_SEPARATOR_LINE) {
                menuitem->height = theme->menu_separator_line_thickness +
                                2 * theme->menu_separator_padding_height;
@@ -312,6 +325,8 @@ separator_create(struct menu *menu, const char *label)
        /* Item background nodes */
        float *bg_color = menuitem->type == LAB_MENU_TITLE
                ? theme->menu_title_bg_color : theme->menu_items_bg_color;
+       float *text_color = menuitem->type == LAB_MENU_TITLE
+               ? theme->menu_title_text_color : theme->menu_items_text_color;
        menuitem->normal.background = &wlr_scene_rect_create(
                menuitem->normal.tree,
                menu->size.width, menuitem->height, bg_color)->node;
@@ -328,8 +343,8 @@ separator_create(struct menu *menu, const char *label)
                menuitem->normal.text = &menuitem->normal.buffer->scene_buffer->node;
                /* Font buffer */
                scaled_font_buffer_update(menuitem->normal.buffer, label,
-                       menuitem->native_width, &rc.font_menuitem,
-                       theme->menu_items_text_color, bg_color, /* arrow */ NULL);
+                       menuitem->native_width, &rc.font_menuheader,
+                       text_color, bg_color, /* arrow */ NULL);
                /* Center font nodes */
                int x, y;
                x = theme->menu_item_padding_x;
index a22d09361608d0862b1f05d25557e27d52aa48bc..ee104268b66cede12a2f67e4eb4b102ffa740996 100644 (file)
@@ -487,6 +487,7 @@ theme_builtin(struct theme *theme, struct server *server)
        parse_hexstr("#000000", theme->window_active_label_text_color);
        parse_hexstr("#000000", theme->window_inactive_label_text_color);
        theme->window_label_text_justify = parse_justification("Center");
+       theme->menu_title_text_justify = parse_justification("Center");
 
        theme->window_button_width = 26;
 
@@ -530,6 +531,8 @@ theme_builtin(struct theme *theme, struct server *server)
 
        parse_hexstr("#589bda", theme->menu_title_bg_color);
 
+       parse_hexstr("#ffffff", theme->menu_title_text_color);
+
        theme->osd_window_switcher_width = 600;
        theme->osd_window_switcher_width_is_percent = false;
        theme->osd_window_switcher_padding = 4;
@@ -606,6 +609,9 @@ entry(struct theme *theme, const char *key, const char *value)
        if (match_glob(key, "menu.items.padding.y")) {
                theme->menu_item_padding_y = atoi(value);
        }
+       if (match_glob(key, "menu.title.text.justify")) {
+               theme->menu_title_text_justify = parse_justification(value);
+       }
        if (match_glob(key, "menu.overlap.x")) {
                theme->menu_overlap_x = atoi(value);
        }
@@ -772,6 +778,10 @@ entry(struct theme *theme, const char *key, const char *value)
                parse_hexstr(value, theme->menu_title_bg_color);
        }
 
+       if (match_glob(key, "menu.title.text.color")) {
+               parse_hexstr(value, theme->menu_title_text_color);
+       }
+
        if (match_glob(key, "osd.bg.color")) {
                parse_hexstr(value, theme->osd_bg_color);
        }