diff --git a/lib/wibox/widget/systray.lua b/lib/wibox/widget/systray.lua index e41e7b2c65..502a11ff77 100644 --- a/lib/wibox/widget/systray.lua +++ b/lib/wibox/widget/systray.lua @@ -67,6 +67,8 @@ function systray:draw(context, cr, width, height) local bg = beautiful.bg_systray or beautiful.bg_normal or "#000000" local spacing = beautiful.systray_icon_spacing or 0 + 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.") end @@ -93,10 +95,39 @@ 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 +-- 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) + 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. @@ -177,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