Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions default/hypr/monitor-workspaces.lua
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,17 @@ end
-- over there.
local function reclaim(monitor, id)
local workspace = hl.get_workspace(id)
if not workspace or not workspace.monitor or workspace.monitor.name == monitor.name then
if not workspace or (workspace.monitor and workspace.monitor.name == monitor.name) then
return
end

local away = workspace.monitor
hl.dispatch(hl.dsp.workspace.move({ workspace = tostring(id), monitor = monitor.name }))

local monitors = connected()
settle(away, monitors, assign(monitors))
if away then
local monitors = connected()
settle(away, monitors, assign(monitors))
end
end

-- Renumber a workspace into a block, keeping its slot when that one is free and
Expand Down
25 changes: 24 additions & 1 deletion test/shell.d/hyprland-monitor-workspaces-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ local function create(id, monitor)
end

local function activate(workspace)
monitor_named(workspace.monitor).active = workspace.id
local monitor = monitor_named(workspace.monitor)
assert(monitor, "Workspace has no monitor")
monitor.active = workspace.id
end

local function windows_on(id)
Expand Down Expand Up @@ -374,6 +376,27 @@ check(shows("eDP-1") >= 1 and shows("eDP-1") <= 10, "the laptop falls back to on
' || fail "a workspace an unplug left elsewhere comes home on its key"
pass "a workspace an unplug left elsewhere comes home on its key"

run_lua reclaim_monitorless '
plug("DP-1", 0, "Dell", 1)
world.focused = "DP-1"
local m = load_module()
world.handlers["hyprland.start"]()
window("0xa", 2)
world.workspaces[#world.workspaces].monitor = nil

hl.dispatch(m.focus(2))
check(shows("DP-1") == 2 and on(2) == "DP-1", "Super + 2 brings a monitorless workspace home")
check(world.windows["0xa"].workspace == 2, "the orphaned window keeps its workspace")

window("0xb", 3)
world.workspaces[#world.workspaces].monitor = nil
world.active_window = "0xa"
hl.dispatch(m.move_window(3))
check(shows("DP-1") == 3 and on(3) == "DP-1", "moving a window reclaims a monitorless destination")
check(world.windows["0xa"].workspace == 3 and world.windows["0xb"].workspace == 3, "both windows stay reachable")
' || fail "workspace actions reclaim a workspace left without a monitor"
pass "workspace actions reclaim a workspace left without a monitor"

# --- Monitors coming and going -------------------------------------------------

run_lua hotplug '
Expand Down