Skip to content

Commit d7e114b

Browse files
committed
fix(awesomewm): make systray target configurable
1 parent e7cced4 commit d7e114b

File tree

3 files changed

+88
-13
lines changed

3 files changed

+88
-13
lines changed

roles/awesomewm/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,14 @@ M.screen_layouts = {
311311
["screen:2"] = "Fullscreen", -- Fallback if output names are unstable
312312
primary = "4K Workspace", -- Optional default for the primary screen
313313
}
314+
315+
M.systray_screen = "DP-1" -- Optional systray target; defaults to "primary"
314316
```
315317

316318
Notes:
317319
- Output-name keys are matched before `primary` and `screen:<index>`.
318320
- If no explicit mapping matches, Awesome falls back to resolution-based selection.
321+
- The systray target accepts the same output-name / `screen:<index>` style and falls back to the current primary screen if the configured target is unavailable.
319322
- `Hyper + p` and `Hyper + ;` now operate on the focused monitor only.
320323
- `Super + o` and `Super + Shift + o` move the focused client between monitors and re-snap it using the target monitor's active layout.
321324
- Use `xrandr --query` to find output names such as `DP-1`, `HDMI-1`, or `eDP-1`.

roles/awesomewm/files/config/cell-management/config.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ M.hyper = { 'Shift', 'Mod4', 'Mod1', 'Control' }
1818
-- }
1919
M.screen_layouts = {}
2020

21+
-- Optional systray target.
22+
-- Accepts "primary" (default), an XRandR output name like "DP-1",
23+
-- or "screen:<index>".
24+
M.systray_screen = "primary"
25+
2126
-- Virtual grid dimensions (resolution-independent)
2227
M.grid = {
2328
width = 80,

roles/awesomewm/files/config/wibar.lua

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
local awful = require("awful")
2+
local only_on_screen = require("awful.widget.only_on_screen")
23
local wibox = require("wibox")
34

45
local ai_usage_widget = require("ai-usage-widget")
6+
local user_config = require("cell-management.config")
7+
local screen_helpers = require("cell-management.helpers")
58
local clock = require("widgets.clock")
69
local controller = require("widgets.controller")
710
local dnd = require("widgets.dnd")
@@ -13,6 +16,62 @@ local system = require("widgets.system")
1316
local tasklist = require("widgets.tasklist")
1417

1518
local M = {}
19+
local systray = wibox.widget.systray()
20+
local systray_sections = setmetatable({}, { __mode = "k" })
21+
22+
local function configured_systray_target()
23+
return user_config.systray_screen or "primary"
24+
end
25+
26+
local function resolve_output_screen(output_name)
27+
for index = 1, screen.count() do
28+
local screen_obj = screen[index]
29+
for _, candidate in ipairs(screen_helpers.get_screen_output_names(screen_obj)) do
30+
if candidate == output_name then
31+
return screen_obj
32+
end
33+
end
34+
end
35+
36+
return nil
37+
end
38+
39+
local function resolve_systray_screen()
40+
local target = configured_systray_target()
41+
42+
if target == nil or target == "primary" then
43+
return "primary"
44+
end
45+
46+
if type(target) == "number" then
47+
return screen[target] or "primary"
48+
end
49+
50+
if type(target) == "string" then
51+
local screen_index = target:match("^screen:(%d+)$")
52+
if screen_index then
53+
return screen[tonumber(screen_index)] or "primary"
54+
end
55+
56+
return resolve_output_screen(target) or "primary"
57+
end
58+
59+
return "primary"
60+
end
61+
62+
local function sync_systray_target()
63+
local target_screen = resolve_systray_screen()
64+
local dpi_screen = target_screen == "primary" and awful.screen.primary or target_screen
65+
66+
systray:set_screen(target_screen)
67+
if dpi_screen then
68+
systray:set_base_size(shared.screen_dpi(16, dpi_screen))
69+
end
70+
71+
for systray_section in pairs(systray_sections) do
72+
systray_section:set_screen(target_screen)
73+
end
74+
end
1675

1776
function M.increase_volume(step)
1877
controller.increase_volume(step)
@@ -36,6 +95,19 @@ end
3695

3796
function M.create_wibar(screen_obj, tasklist_buttons, mainmenu)
3897
local screen_spacing = shared.screen_spacing(screen_obj)
98+
local systray_section = only_on_screen(
99+
wibox.widget {
100+
layout = wibox.layout.fixed.horizontal,
101+
shared.create_spacer(screen_spacing.section),
102+
{
103+
systray,
104+
valign = "center",
105+
widget = wibox.container.place,
106+
},
107+
shared.create_spacer(screen_spacing.section),
108+
},
109+
"primary"
110+
)
39111

40112
screen_obj.mypromptbox = awful.widget.prompt()
41113
screen_obj.mytasklist = tasklist.create(screen_obj, tasklist_buttons, shared)
@@ -51,12 +123,7 @@ function M.create_wibar(screen_obj, tasklist_buttons, mainmenu)
51123
}
52124

53125
controller.register(screen_obj, widgets.media.controls)
54-
55-
local systray = nil
56-
if screen_obj == awful.screen.primary then
57-
systray = wibox.widget.systray()
58-
systray:set_base_size(shared.screen_dpi(16, screen_obj))
59-
end
126+
systray_sections[systray_section] = true
60127

61128
screen_obj.mywibox = awful.wibar({
62129
position = "top",
@@ -103,13 +170,7 @@ function M.create_wibar(screen_obj, tasklist_buttons, mainmenu)
103170
widgets.media.volume,
104171
shared.create_spacer(screen_spacing.widget),
105172
widgets.ai,
106-
systray and shared.create_spacer(screen_spacing.section) or nil,
107-
systray and {
108-
systray,
109-
valign = "center",
110-
widget = wibox.container.place,
111-
} or nil,
112-
systray and shared.create_spacer(screen_spacing.section) or nil,
173+
systray_section,
113174
widgets.dnd,
114175
shared.create_spacer(screen_spacing.widget),
115176
widgets.clock,
@@ -119,6 +180,12 @@ function M.create_wibar(screen_obj, tasklist_buttons, mainmenu)
119180
},
120181
},
121182
}
183+
184+
sync_systray_target()
122185
end
123186

187+
screen.connect_signal("primary_changed", sync_systray_target)
188+
screen.connect_signal("list", sync_systray_target)
189+
screen.connect_signal("property::outputs", sync_systray_target)
190+
124191
return M

0 commit comments

Comments
 (0)