Awesome: Center the window title

Created on 9 Nov 2019  Â·  5Comments  Â·  Source: awesomeWM/awesome

Output of awesome --version:

awesome v4.3 (Too long)
 • Compiled against Lua 5.3.5 (running with Lua 5.3)
 • D-Bus support: ✔
 • execinfo support: ✔
 • xcb-randr version: 1.6
 • LGI version: 0.9.2

How to reproduce the issue:

The issue is present with the default config and theme.

Actual result:

Window titles are offset from the center of the window. Instead they are centered on the space between the window icon on the left and the window buttons on the right. By default there are 5 buttons and only one icon, so the window title is to the left of center.

image

Expected result:

The window title should be centered on the window.

question

Most helpful comment

Does this patch do what you want?
foo

diff --git a/awesomerc.lua b/awesomerc.lua
index 948407220..a2c053d1d 100644
--- a/awesomerc.lua
+++ b/awesomerc.lua
@@ -532,6 +532,16 @@ client.connect_signal("request::titlebars", function(c)
         end)
     )

+    local right_fixed = wibox.layout.fixed.horizontal()
+    right_fixed:add(awful.titlebar.widget.floatingbutton (c))
+    right_fixed:add(awful.titlebar.widget.maximizedbutton(c))
+    right_fixed:add(awful.titlebar.widget.stickybutton   (c))
+    right_fixed:add(awful.titlebar.widget.ontopbutton    (c))
+    right_fixed:add(awful.titlebar.widget.closebutton    (c))
+
+    local right = wibox.layout.align.horizontal()
+    right:set_right(right_fixed)
+
     awful.titlebar(c) : setup {
         { -- Left
             awful.titlebar.widget.iconwidget(c),
@@ -546,14 +556,8 @@ client.connect_signal("request::titlebars", function(c)
             buttons = buttons,
             layout  = wibox.layout.flex.horizontal
         },
-        { -- Right
-            awful.titlebar.widget.floatingbutton (c),
-            awful.titlebar.widget.maximizedbutton(c),
-            awful.titlebar.widget.stickybutton   (c),
-            awful.titlebar.widget.ontopbutton    (c),
-            awful.titlebar.widget.closebutton    (c),
-            layout = wibox.layout.fixed.horizontal()
-        },
+        right,
+        expand = "outside",
         layout = wibox.layout.align.horizontal
     }
 end)

@Elv13 How do I do this "properly"? I gave up on the declarative layout here, because I was getting an unhelpful "argument is not a widget" error.

Question: Any ideas how to make this simpler? Without the extra align layout, expand = "outside" causes the buttons on the right to be left-aligned in the available space, which means they appear right next to the window title.

All 5 comments

Does this patch do what you want?
foo

diff --git a/awesomerc.lua b/awesomerc.lua
index 948407220..a2c053d1d 100644
--- a/awesomerc.lua
+++ b/awesomerc.lua
@@ -532,6 +532,16 @@ client.connect_signal("request::titlebars", function(c)
         end)
     )

+    local right_fixed = wibox.layout.fixed.horizontal()
+    right_fixed:add(awful.titlebar.widget.floatingbutton (c))
+    right_fixed:add(awful.titlebar.widget.maximizedbutton(c))
+    right_fixed:add(awful.titlebar.widget.stickybutton   (c))
+    right_fixed:add(awful.titlebar.widget.ontopbutton    (c))
+    right_fixed:add(awful.titlebar.widget.closebutton    (c))
+
+    local right = wibox.layout.align.horizontal()
+    right:set_right(right_fixed)
+
     awful.titlebar(c) : setup {
         { -- Left
             awful.titlebar.widget.iconwidget(c),
@@ -546,14 +556,8 @@ client.connect_signal("request::titlebars", function(c)
             buttons = buttons,
             layout  = wibox.layout.flex.horizontal
         },
-        { -- Right
-            awful.titlebar.widget.floatingbutton (c),
-            awful.titlebar.widget.maximizedbutton(c),
-            awful.titlebar.widget.stickybutton   (c),
-            awful.titlebar.widget.ontopbutton    (c),
-            awful.titlebar.widget.closebutton    (c),
-            layout = wibox.layout.fixed.horizontal()
-        },
+        right,
+        expand = "outside",
         layout = wibox.layout.align.horizontal
     }
 end)

@Elv13 How do I do this "properly"? I gave up on the declarative layout here, because I was getting an unhelpful "argument is not a widget" error.

Question: Any ideas how to make this simpler? Without the extra align layout, expand = "outside" causes the buttons on the right to be left-aligned in the available space, which means they appear right next to the window title.

Any clue about how to get titles left aligned with left-margin?

{
    align = 'left',
    -- titlebar text doesn't show at all
    widget = wibox.container.margin(awful.titlebar.widget.titlewidget(c), dpi(5)),
},

Edit: don't nest the titlewidget like in the default layout and it will work.

@Elv13 How do I do this "properly"? I gave up on the declarative layout here, because I was getting an unhelpful "argument is not a widget" error.

It seems strange to me that we have a layout = wibox.layout.fixed.horizontal() in the declarative layout definition here... Shouldn't it be layout = wibox.layout.fixed.horizontal (without the ())? We should give a layout constructor callback not an instance.

@@ -546,14 +556,8 @@ client.connect_signal("request::titlebars", function(c)
             buttons = buttons,
             layout  = wibox.layout.flex.horizontal
         },
-        { -- Right
-            awful.titlebar.widget.floatingbutton (c),
-            awful.titlebar.widget.maximizedbutton(c),
-            awful.titlebar.widget.stickybutton   (c),
-            awful.titlebar.widget.ontopbutton    (c),
-            awful.titlebar.widget.closebutton    (c),
-            layout = wibox.layout.fixed.horizontal()
-        },
+        right,
+        expand = "outside",
         layout = wibox.layout.align.horizontal
     }
 end)

It seems strange to me that we have a layout = wibox.layout.fixed.horizontal() in the declarative layout definition here... Shouldn't it be layout = wibox.layout.fixed.horizontal (without the ())? We should give a layout constructor callback not an instance.

Umm, probably, but it doesn't actually change anything in this case. If it was a template it would cause bugs, but not here. Anyhow, the part 5 of the API standardization will "fix that" since it standardize the constructor and you can use wibox.layout.align.horizontal { my_widget { }, ... expand="outside"}. This way the layout= and widget= are only required in templates, where the "no instances allowed" can be enforced.

Resolving since this is a question and it has been answered.

Was this page helpful?
0 / 5 - 0 ratings