I frequently lose track of which screen is currently focused (especially when there are no open clients). Therefore I want to write a widget which always shows which screen is focused.
My current code looks like this:
-- Focused screen widget
local focused_screen_widget = wibox.widget{
markup = "SCR: " .. tostring(awful.screen.focused().index),
align = 'center',
valign = 'center',
widget = wibox.widget.textbox
}
function update_focused_screen_widget()
focused_screen_widget.text = "SCR: " .. tostring(awful.screen.focused().index)
end
client.connect_signal("focus", update_focused_screen_widget)
client.connect_signal("unfocus", update_focused_screen_widget)
---- hook into awful.screen.focus()
original_screen_focus = awful.screen.focus
function awful.screen.focus(_screen)
original_screen_focus(_screen)
update_focused_screen_widget()
end
This is mostly working but when I have no open clients and move the mouse between screens, no update is triggered. I know the focus changed because new applications always start on the correct screen, but I can't find a way to update my widget on these changes. Can anyone help me with this?
Edit: I'm using awesome v4.2
Currently you cannot get events for when the mouse cursor moves to a different monitor. The reason is mostly technical (X11 doesn't give you an event for "the mouse moved to another monitor" unless you ask for "please send me an event for any mouse movement").
Thus, your only solution is a timer that updates your widget regularly, let's say once per second or every ten seconds or whatever number suits you.