]> git.mdlowis.com Git - proto/labwc.git/commitdiff
font: remove 4px padding on the right
authortokyo4j <hrak1529@gmail.com>
Sun, 21 Sep 2025 11:40:49 +0000 (20:40 +0900)
committerJohan Malm <johanmalm@users.noreply.github.com>
Mon, 22 Sep 2025 17:23:33 +0000 (18:23 +0100)
Added `menu.items.padding.x` padding between item text and arrow instead.

Replaced `if (!string)` with `if (string_null_or_empty(string))` in
`font_extents()` just as a minor optimization.

src/common/font.c
src/menu/menu.c
src/ssd/resize-indicator.c

index 81784ea88e214735587ae089e727d8df964d8be3..b307729c465a2212788b059c782d88fe53c2b273 100644 (file)
@@ -22,7 +22,7 @@ static PangoRectangle
 font_extents(struct font *font, const char *string)
 {
        PangoRectangle rect = { 0 };
-       if (!string) {
+       if (string_null_or_empty(string)) {
                return rect;
        }
        cairo_surface_t *surface;
@@ -43,10 +43,6 @@ font_extents(struct font *font, const char *string)
        pango_layout_get_extents(layout, NULL, &rect);
        pango_extents_to_pixels(&rect, NULL);
 
-       /* we put a 2 px edge on each side - because Openbox does it :) */
-       /* TODO: remove the 4 pixel addition and always do the padding by the caller */
-       rect.width += 4;
-
        cairo_destroy(c);
        cairo_surface_destroy(surface);
        pango_font_description_free(desc);
index e7a7b90c2fe2fa868f235e7d7e83d912ec817089..455035ec80b3daada42e08890b205ecee3cd1d2e 100644 (file)
@@ -135,6 +135,7 @@ item_create(struct menu *menu, const char *text, const char *icon_name, bool sho
        assert(menu);
        assert(text);
 
+       struct theme *theme = menu->server->theme;
        struct menuitem *menuitem = znew(*menuitem);
        menuitem->parent = menu;
        menuitem->selectable = true;
@@ -151,7 +152,8 @@ item_create(struct menu *menu, const char *text, const char *icon_name, bool sho
 
        menuitem->native_width = font_width(&rc.font_menuitem, text);
        if (menuitem->arrow) {
-               menuitem->native_width += font_width(&rc.font_menuitem, menuitem->arrow);
+               menuitem->native_width += font_width(&rc.font_menuitem, menuitem->arrow)
+                                       + theme->menu_items_padding_x;
        }
 
        wl_list_append(&menu->menuitems, &menuitem->link);
@@ -177,7 +179,7 @@ item_create_scene_for_state(struct menuitem *item, float *text_color,
 
        int bg_width = menu->size.width - 2 * theme->menu_border_width;
        int arrow_width = item->arrow ?
-               font_width(&rc.font_menuitem, item->arrow) : 0;
+               font_width(&rc.font_menuitem, item->arrow) + theme->menu_items_padding_x : 0;
        int label_max_width = bg_width - 2 * theme->menu_items_padding_x
                - arrow_width - icon_width;
 
@@ -227,7 +229,7 @@ item_create_scene_for_state(struct menuitem *item, float *text_color,
        scaled_font_buffer_update(arrow_buffer, item->arrow, -1,
                &rc.font_menuitem, text_color, bg_color);
        /* Vertically center and right-align arrow */
-       x += label_max_width;
+       x += label_max_width + theme->menu_items_padding_x;
        y = (theme->menu_item_height - label_buffer->height) / 2;
        wlr_scene_node_set_position(&arrow_buffer->scene_buffer->node, x, y);
 
index 6c22e656ee749953645789b92561581602994508..3a635edcf59ef43826f85ddedb791c0c6333e83e 100644 (file)
@@ -193,9 +193,6 @@ resize_indicator_update(struct view *view)
        /* Let the indicator change width as required by the content */
        int width = font_width(&rc.font_osd, text);
 
-       /* font_extents() adds 4 pixels to the calculated width */
-       width -= 4;
-
        resize_indicator_set_size(indicator, width);
 
        /* Center the indicator in the window */