Repository navigation
Focus lost when turning monitor off and on again #15554
|
I'm on 0.56 and when turning my (only) monitor off and on again, which I do regularily when i'm afk so my OLED doesn't get burnin I experience a loss of window focus, workspace focus and special workspace focus. When turning the monitor off hyprland switches to a virtual Fallback devices and when switching it on again it doesn't recover the previous state. Thanks to lua I was able to create following workaround: -- Workaround for for restoring focus on toggling monitor on/off
local function restore_focus(target_workspace, target_window)
-- cycle workspace
for _, workspace in ipairs(hl.get_workspaces()) do
if workspace.id ~= target_workspace.id
and not workspace.name:match("^special:") then
hl.dispatch(hl.dsp.focus({ workspace = workspace }))
break
end
end
-- focus last workspace again
hl.dispatch(hl.dsp.focus({ workspace = target_workspace }))
-- focus last window
if target_window then
hl.dispatch(hl.dsp.focus({ window = target_window }))
end
end
hl.on("monitor.added", function(monitor)
if monitor.name == "FALLBACK" or not hl.get_monitor("FALLBACK") then
return
end
-- Capture before FALLBACK migration destroys the history.
local target_workspace = hl.get_last_workspace()
local target_window = hl.get_last_window()
hl.timer(function()
restore_focus(target_workspace, target_window)
end, {
timeout = 500,
type = "oneshot",
})
end)This script is reading the previous context and restores it by focussing the last window and focussing the last workspace. To focus the last workspace another workspace had to be focussed as hyprland still had the old workspace saved as focussed, but hasn't focussed it and won't if the same workspace is given. You have to cycle it to another workspace once. When reading the hyprland socket the communication looks like this: % ncat -U "$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" | grep --line-buffered -E '^(monitor(add|remov)|focusedmon|activewindow|activespecial)'
monitorremoved>>DP-1
monitorremovedv2>>1,DP-1,Dell Inc. AW3225QF 11F1YZ3
focusedmon>>FALLBACK,4
focusedmonv2>>FALLBACK,4
monitoradded>>FALLBACK
monitoraddedv2>>0,FALLBACK,
activewindow>>,
activewindowv2>>
monitoradded>>DP-1
monitoraddedv2>>1,DP-1,Dell Inc. AW3225QF 11F1YZ3
focusedmon>>DP-1,2
focusedmonv2>>DP-1,2
monitorremoved>>FALLBACK
monitorremovedv2>>0,FALLBACK,
monitorremoved>>FALLBACK
monitorremovedv2>>0,FALLBACK,with the fix it looks like this % ncat -U "$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" | grep --line-buffered -E '^(monitor(add|remov)|focusedmon|activewindow|activespecial)'
monitorremoved>>DP-1
monitorremovedv2>>1,DP-1,Dell Inc. AW3225QF 11F1YZ3
focusedmon>>FALLBACK,4
focusedmonv2>>FALLBACK,4
monitoradded>>FALLBACK
monitoraddedv2>>0,FALLBACK,
activewindow>>,
activewindowv2>>
monitoradded>>DP-1
monitoraddedv2>>1,DP-1,Dell Inc. AW3225QF 11F1YZ3
focusedmon>>DP-1,2
focusedmonv2>>DP-1,2
monitorremoved>>FALLBACK
monitorremovedv2>>0,FALLBACK,
monitorremoved>>FALLBACK
monitorremovedv2>>0,FALLBACK,
activewindow>>Alacritty,Alacritty
activewindowv2>>55d2c95e9e80
activespecial>>special:terminal,DP-1
activespecialv2>>-97,special:terminal,DP-1
activewindow>>Alacritty,Alacritty
activewindowv2>>55d2c95e9e80I wanted to file this as a bug since it's pretty annoying as I otherwise have to toggle workspace by keyboard and window by mouse and it destroys the workspace visualisation I did within my Shell (Aylurs AGS). |
Replies: 1 comment 2 replies
|
Hey, man! You are probably busy with a lot of other stuff, but could you please take a short look at this or point me to whom I need to talk about this. Since I have a workaround I am good, but I consider the reported behaviour as a bug. Hyprland should not change the the state (in this case focussed windows) the user left the system in just because a monitor was turned off. If you are fine with the current behaviour we can close this and I'll just stay with my workaround. Otherwise this could be made into a bug to be worked on. |
I don't think we enforce focus on monitor addition to not disrupt current state. With lua I think the workaround is totally reasonable