From ea95963726e8dce30a510c0bafae52f74503ce9b Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 5 Mar 2016 16:17:35 +0100 Subject: [PATCH 1/4] systray: Turn this into a singleton There's no point in having multiple instances of this, because there are no per-instance settings and the systray can only be visible in a single place at a time anyway. Signed-off-by: Uli Schlachter --- lib/wibox/widget/systray.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/wibox/widget/systray.lua b/lib/wibox/widget/systray.lua index 262c274e..5625f64a 100644 --- a/lib/wibox/widget/systray.lua +++ b/lib/wibox/widget/systray.lua @@ -90,8 +90,12 @@ local function new(revers) return ret end +local instance function systray.mt:__call(...) - return new(...) + if not instance then + instance = new(...) + end + return instance end return setmetatable(systray, systray.mt) From 1e5dd0c7825620a5595577469684a63f77844bfb Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 5 Mar 2016 16:39:25 +0100 Subject: [PATCH 2/4] systray: Add API documentation Signed-off-by: Uli Schlachter --- docs/config.ld | 1 - lib/wibox/widget/systray.lua | 38 ++++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/docs/config.ld b/docs/config.ld index ce738c8e..994a6473 100644 --- a/docs/config.ld +++ b/docs/config.ld @@ -63,7 +63,6 @@ file = { '../lib/gears/init.lua', '../lib/wibox/layout/init.lua', '../lib/wibox/widget/init.lua', - '../lib/wibox/widget/systray.lua', -- Ignore some parts of the widget library '../lib/awful/widget/init.lua', diff --git a/lib/wibox/widget/systray.lua b/lib/wibox/widget/systray.lua index 5625f64a..d8c92d48 100644 --- a/lib/wibox/widget/systray.lua +++ b/lib/wibox/widget/systray.lua @@ -14,6 +14,7 @@ local abs = math.abs local systray = { mt = {} } +local instance = nil local horizontal = true local base_size = nil local reverse = false @@ -69,14 +70,40 @@ function systray:fit(_, width, height) return base, base * num_entries - spacing end +-- Check if the function was called like :foo() or .foo() and do the right thing +local function get_args(self, ...) + if self == instance then + return ... + end + return self, ... +end + +--- Set the size of a single icon. +-- If this is set to nil, then the size is picked dynamically based on the +-- available space. Otherwise, any single icon has a size of `size`x`size`. +-- @tparam integer|nil size The base size +function systray:set_base_size(size) + base_size = get_args(self, size) +end + +--- Decide between horizontal or vertical display. +-- @tparam boolean horiz Use horizontal mode? +function systray:set_horizontal(horiz) + horizontal = get_args(self, horiz) +end + +--- Should the systray icons be displayed in reverse order? +-- @tparam boolean rev Display in reverse order +function systray:set_reverse(rev) + reverse = get_args(self, rev) +end + local function new(revers) local ret = wbase.make_widget() - ret.fit = systray.fit - ret.draw = systray.draw - ret.set_base_size = function(_, size) base_size = size end - ret.set_horizontal = function(_, horiz) horizontal = horiz end - ret.set_reverse = function(arg) reverse = arg end + for k, v in pairs(systray) do + ret[k] = v + end if revers then ret:set_reverse(true) @@ -90,7 +117,6 @@ local function new(revers) return ret end -local instance function systray.mt:__call(...) if not instance then instance = new(...) From a1b20ef6bb1b648f6559d01c998370c0b8f87827 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 5 Mar 2016 16:49:49 +0100 Subject: [PATCH 3/4] 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 --- awesomerc.lua | 2 +- lib/wibox/widget/systray.lua | 37 ++++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/awesomerc.lua b/awesomerc.lua index 5b8f6460..d56ec785 100755 --- a/awesomerc.lua +++ b/awesomerc.lua @@ -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], }, diff --git a/lib/wibox/widget/systray.lua b/lib/wibox/widget/systray.lua index d8c92d48..d0e164e9 100644 --- a/lib/wibox/widget/systray.lua +++ b/lib/wibox/widget/systray.lua @@ -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 From 2e2e3f07e26cd14041eea0070d3d14645b83811e Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 5 Mar 2016 16:53:38 +0100 Subject: [PATCH 4/4] systray: Emit layout_changed / redraw_needed where needed Signed-off-by: Uli Schlachter --- lib/wibox/widget/systray.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/wibox/widget/systray.lua b/lib/wibox/widget/systray.lua index d0e164e9..9a513204 100644 --- a/lib/wibox/widget/systray.lua +++ b/lib/wibox/widget/systray.lua @@ -103,18 +103,27 @@ end -- @tparam integer|nil size The base size function systray:set_base_size(size) base_size = get_args(self, size) + if instance then + instance:emit_signal("widget::layout_changed") + end end --- Decide between horizontal or vertical display. -- @tparam boolean horiz Use horizontal mode? function systray:set_horizontal(horiz) horizontal = get_args(self, horiz) + if instance then + instance:emit_signal("widget::layout_changed") + end end --- Should the systray icons be displayed in reverse order? -- @tparam boolean rev Display in reverse order function systray:set_reverse(rev) reverse = get_args(self, rev) + if instance then + instance:emit_signal("widget::redraw_needed") + end end --- Set the screen that the systray should be displayed on. @@ -124,6 +133,9 @@ end -- @tparam screen|"primary" s The screen to display on. function systray:set_screen(s) display_on_screen = get_args(self, s) + if instance then + instance:emit_signal("widget::layout_changed") + end end local function new(revers)