View: restore to previous output on reconnect

This commit is contained in:
Leon Henrik Plickat
2023-11-10 01:01:20 +01:00
committed by Isaac Freund
parent fecfa89a9a
commit 4e48d68485
3 changed files with 37 additions and 0 deletions

View File

@ -286,6 +286,15 @@ pub fn deactivateOutput(root: *Self, output: *Output) void {
if (view.inflight_transaction) {
view.commitTransaction();
}
// Store outputs connector name so that views can be moved back to
// reconnecting outputs. Skip if there is already a connector name
// stored to better handle the case of multiple outputs being
// removed sequentially.
if (view.output_before_evac == null) {
const name = mem.span(output.wlr_output.name);
view.output_before_evac = util.gpa.dupe(u8, name) catch null;
}
}
}
// Use the first output in the list as fallback. If the last real output
@ -386,6 +395,20 @@ pub fn activateOutput(root: *Self, output: *Output) void {
seat.focusOutput(output);
}
}
} else {
// Otherwise check if any views were previously evacuated from an output
// with the same (connector-)name and move them back.
var it = root.views.iterator(.forward);
while (it.next()) |view| {
const name = view.output_before_evac orelse continue;
if (mem.eql(u8, name, mem.span(output.wlr_output.name))) {
if (view.pending.output != output) {
view.setPendingOutput(output);
}
util.gpa.free(name);
view.output_before_evac = null;
}
}
}
assert(root.fallback_pending.focus_stack.empty());
assert(root.fallback_pending.wm_stack.empty());