From fa432e771a80ad61880df0e2ac880693e91f26a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fekete=2C=20Zolt=C3=A1n?= Date: Mon, 2 Oct 2023 08:24:35 +0200 Subject: [PATCH 1/5] Center systray vertically If the user sets the systay size with systray:set_base_size(...), then this change centers the systray vertically. --- lib/wibox/widget/systray.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/wibox/widget/systray.lua b/lib/wibox/widget/systray.lua index e41e7b2c65..ddda155ed0 100644 --- a/lib/wibox/widget/systray.lua +++ b/lib/wibox/widget/systray.lua @@ -66,6 +66,7 @@ function systray:draw(context, cr, width, height) local cols = math.ceil(num_entries / rows) local bg = beautiful.bg_systray or beautiful.bg_normal or "#000000" local spacing = beautiful.systray_icon_spacing or 0 + local y_offset = ((height - base_size) / 2) - 1 if context and not context.wibox then error("The systray widget can only be placed inside a wibox.") @@ -93,7 +94,7 @@ function systray:draw(context, cr, width, height) -- Solving the "width" formula above for "base" (with width=in_dir): base = (in_dir + spacing) / cols - spacing end - capi.awesome.systray(context.wibox.drawin, math.ceil(x), math.ceil(y), + capi.awesome.systray(context.wibox.drawin, math.ceil(x), math.ceil(y + y_offset), base, is_rotated, bg, reverse, spacing, rows) end From 9301c491d2e6ddbd8668f7e474ebbbfd73357827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fekete=2C=20Zolt=C3=A1n?= Date: Tue, 3 Oct 2023 07:14:30 +0200 Subject: [PATCH 2/5] Fixed error when base_size is not set --- lib/wibox/widget/systray.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/wibox/widget/systray.lua b/lib/wibox/widget/systray.lua index ddda155ed0..717f9dbb3a 100644 --- a/lib/wibox/widget/systray.lua +++ b/lib/wibox/widget/systray.lua @@ -66,7 +66,10 @@ function systray:draw(context, cr, width, height) local cols = math.ceil(num_entries / rows) local bg = beautiful.bg_systray or beautiful.bg_normal or "#000000" local spacing = beautiful.systray_icon_spacing or 0 - local y_offset = ((height - base_size) / 2) - 1 + local y_offset = 0 + if base_size then + y_offset = ((height - base_size) / 2) - 1 + end if context and not context.wibox then error("The systray widget can only be placed inside a wibox.") From a554498155863f72d0f9cd30981a01cfe71230e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fekete=2C=20Zolt=C3=A1n?= Date: Mon, 13 Nov 2023 07:31:19 +0100 Subject: [PATCH 3/5] Update lib/wibox/widget/systray.lua Removed trailing whitespace. Co-authored-by: Aire-One --- lib/wibox/widget/systray.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wibox/widget/systray.lua b/lib/wibox/widget/systray.lua index 717f9dbb3a..2306d6d52d 100644 --- a/lib/wibox/widget/systray.lua +++ b/lib/wibox/widget/systray.lua @@ -66,7 +66,7 @@ function systray:draw(context, cr, width, height) local cols = math.ceil(num_entries / rows) local bg = beautiful.bg_systray or beautiful.bg_normal or "#000000" local spacing = beautiful.systray_icon_spacing or 0 - local y_offset = 0 + local y_offset = 0 if base_size then y_offset = ((height - base_size) / 2) - 1 end From ead4fc3e6d9a31332fc241dc1f933a48faff8801 Mon Sep 17 00:00:00 2001 From: Zoltan Fekete Date: Sun, 4 Feb 2024 10:49:23 +0100 Subject: [PATCH 4/5] Applied common API to determine vertical alignment. --- lib/wibox/widget/systray.lua | 56 +++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/lib/wibox/widget/systray.lua b/lib/wibox/widget/systray.lua index 2306d6d52d..5a9d928512 100644 --- a/lib/wibox/widget/systray.lua +++ b/lib/wibox/widget/systray.lua @@ -66,10 +66,8 @@ function systray:draw(context, cr, width, height) local cols = math.ceil(num_entries / rows) local bg = beautiful.bg_systray or beautiful.bg_normal or "#000000" local spacing = beautiful.systray_icon_spacing or 0 - local y_offset = 0 - if base_size then - y_offset = ((height - base_size) / 2) - 1 - end + + local y_offset = instance:_get_top_offset(height) if context and not context.wibox then error("The systray widget can only be placed inside a wibox.") @@ -101,6 +99,35 @@ function systray:draw(context, cr, width, height) base, is_rotated, bg, reverse, spacing, rows) end +-- Private API. Does not appear in LDoc. This function is called +-- some time to vertically align the systray according to the arguments. +function systray:_get_top_offset(height, valign) + if not base_size then + return 0 + end + + local valign = self._private.valign + + if not valign then + return 0 + end + + if valign == "top" then + return 0 + end + + if valign == "center" then + return math.floor((height - base_size) / 2) + end + + if valign == "bottom" then + return (height - base_size) + end + + return 0 + +end + -- Private API. Does not appear in LDoc on purpose. This function is called -- some time after the systray is removed from some drawable. It's purpose is to -- really remove the systray. @@ -181,6 +208,27 @@ function systray:set_horizontal(horiz) end end +--- The vertical alignment. +-- +--@DOC_wibox_widget_systray_valign_EXAMPLE@ +-- +-- @property valign +-- @tparam[opt="center"] string valign +-- @propertyvalue "top" +-- @propertyvalue "center" +-- @propertyvalue "bottom" +-- @propemits true false + +function systray:set_valign(value) + if value ~= "center" and value ~= "top" and value ~= "bottom" then + return + end + + self._private.valign = value +-- self:emit_signal("widget::layout_changed") + self:emit_signal("property::valign", value) +end + --- Should the systray icons be displayed in reverse order? -- -- @property reverse From 5017acaf9d246aa038139b459548cf9a23d84523 Mon Sep 17 00:00:00 2001 From: Fekete Zoltan Date: Sat, 24 Feb 2024 16:02:53 +0100 Subject: [PATCH 5/5] Removed unused variable. Removed unnecessary whitespces. --- lib/wibox/widget/systray.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/wibox/widget/systray.lua b/lib/wibox/widget/systray.lua index 5a9d928512..502a11ff77 100644 --- a/lib/wibox/widget/systray.lua +++ b/lib/wibox/widget/systray.lua @@ -100,8 +100,8 @@ function systray:draw(context, cr, width, height) end -- Private API. Does not appear in LDoc. This function is called --- some time to vertically align the systray according to the arguments. -function systray:_get_top_offset(height, valign) +-- some time to vertically align the systray according to the arguments. +function systray:_get_top_offset(height) if not base_size then return 0 end @@ -111,11 +111,11 @@ function systray:_get_top_offset(height, valign) if not valign then return 0 end - + if valign == "top" then return 0 end - + if valign == "center" then return math.floor((height - base_size) / 2) end