Systray: Add settings for which screen to display on
This makes it possible to have the systray only visible on the primary screen, which is the new default value. This also makes it possible to configure directly on which screen the systray should be visible. This breaks the API in the sense that people who use "the old method" to configure the systray's screen possibly don't have a systray. Fixes: https://github.com/awesomeWM/awesome/issues/724 Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
1e5dd0c782
commit
a1b20ef6bb
|
@ -208,7 +208,7 @@ for s = 1, screen.count() do
|
|||
{ -- Right widgets
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
mykeyboardlayout,
|
||||
s == 1 and wibox.widget.systray(),
|
||||
wibox.widget.systray(),
|
||||
mytextclock,
|
||||
mylayoutbox[s],
|
||||
},
|
||||
|
|
|
@ -7,7 +7,10 @@
|
|||
|
||||
local wbase = require("wibox.widget.base")
|
||||
local beautiful = require("beautiful")
|
||||
local capi = { awesome = awesome }
|
||||
local capi = {
|
||||
awesome = awesome,
|
||||
screen = screen
|
||||
}
|
||||
local setmetatable = setmetatable
|
||||
local error = error
|
||||
local abs = math.abs
|
||||
|
@ -18,8 +21,20 @@ local instance = nil
|
|||
local horizontal = true
|
||||
local base_size = nil
|
||||
local reverse = false
|
||||
local display_on_screen = "primary"
|
||||
|
||||
local function should_display_on(s)
|
||||
if display_on_screen == "primary" then
|
||||
return s == capi.screen.primary
|
||||
end
|
||||
return s == display_on_screen
|
||||
end
|
||||
|
||||
function systray:draw(context, cr, width, height)
|
||||
if not should_display_on(context.screen) then
|
||||
return
|
||||
end
|
||||
|
||||
local x, y, _, _ = wbase.rect_to_device_geometry(cr, 0, 0, width, height)
|
||||
local num_entries = capi.awesome.systray()
|
||||
local bg = beautiful.bg_systray or beautiful.bg_normal or "#000000"
|
||||
|
@ -49,7 +64,11 @@ function systray:draw(context, cr, width, height)
|
|||
base, is_rotated, bg, reverse, spacing)
|
||||
end
|
||||
|
||||
function systray:fit(_, width, height)
|
||||
function systray:fit(context, width, height)
|
||||
if not should_display_on(context.screen) then
|
||||
return 0, 0
|
||||
end
|
||||
|
||||
local num_entries = capi.awesome.systray()
|
||||
local base = base_size
|
||||
local spacing = beautiful.systray_icon_spacing or 0
|
||||
|
@ -98,6 +117,15 @@ function systray:set_reverse(rev)
|
|||
reverse = get_args(self, rev)
|
||||
end
|
||||
|
||||
--- Set the screen that the systray should be displayed on.
|
||||
-- This can either be a screen, in which case the systray will be displayed on
|
||||
-- exactly that screen, or the string `"primary"`, in which case it will be
|
||||
-- visible on the primary screen. The default value is "primary".
|
||||
-- @tparam screen|"primary" s The screen to display on.
|
||||
function systray:set_screen(s)
|
||||
display_on_screen = get_args(self, s)
|
||||
end
|
||||
|
||||
local function new(revers)
|
||||
local ret = wbase.make_widget()
|
||||
|
||||
|
@ -113,6 +141,11 @@ local function new(revers)
|
|||
ret:emit_signal("widget::layout_changed")
|
||||
ret:emit_signal("widget::redraw_needed")
|
||||
end)
|
||||
capi.screen.connect_signal("primary_changed", function()
|
||||
if display_on_screen == "primary" then
|
||||
ret:emit_signal("widget::layout_changed")
|
||||
end
|
||||
end)
|
||||
|
||||
return ret
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue