Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Center systray vertically #3860

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion lib/wibox/widget/systray.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
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
Expand All @@ -93,10 +95,39 @@
-- 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

Check warning on line 116 in lib/wibox/widget/systray.lua

View check run for this annotation

Codecov / codecov/patch

lib/wibox/widget/systray.lua#L115-L116

Added lines #L115 - L116 were not covered by tests
end

if valign == "center" then
return math.floor((height - base_size) / 2)

Check warning on line 120 in lib/wibox/widget/systray.lua

View check run for this annotation

Codecov / codecov/patch

lib/wibox/widget/systray.lua#L119-L120

Added lines #L119 - L120 were not covered by tests
end

if valign == "bottom" then
return (height - base_size)

Check warning on line 124 in lib/wibox/widget/systray.lua

View check run for this annotation

Codecov / codecov/patch

lib/wibox/widget/systray.lua#L123-L124

Added lines #L123 - L124 were not covered by tests
end

return 0

Check warning on line 127 in lib/wibox/widget/systray.lua

View check run for this annotation

Codecov / codecov/patch

lib/wibox/widget/systray.lua#L127

Added line #L127 was not covered by tests

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.
Expand Down Expand Up @@ -177,6 +208,27 @@
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

Check warning on line 224 in lib/wibox/widget/systray.lua

View check run for this annotation

Codecov / codecov/patch

lib/wibox/widget/systray.lua#L223-L224

Added lines #L223 - L224 were not covered by tests
end

self._private.valign = value

Check warning on line 227 in lib/wibox/widget/systray.lua

View check run for this annotation

Codecov / codecov/patch

lib/wibox/widget/systray.lua#L227

Added line #L227 was not covered by tests
-- self:emit_signal("widget::layout_changed")
self:emit_signal("property::valign", value)

Check warning on line 229 in lib/wibox/widget/systray.lua

View check run for this annotation

Codecov / codecov/patch

lib/wibox/widget/systray.lua#L229

Added line #L229 was not covered by tests
end

--- Should the systray icons be displayed in reverse order?
--
-- @property reverse
Expand Down
Loading