mirror of
https://github.com/YaLTeR/niri.git
synced 2025-10-05 16:12:47 +02:00
layout: Extract Monitor::append_workspaces()
This commit is contained in:
@@ -769,7 +769,7 @@ impl<W: LayoutElement> Layout<W> {
|
||||
monitor.workspaces[monitor.active_workspace_idx].id(),
|
||||
);
|
||||
|
||||
let mut workspaces = monitor.into_workspaces();
|
||||
let workspaces = monitor.into_workspaces();
|
||||
|
||||
if monitors.is_empty() {
|
||||
// Removed the last monitor.
|
||||
@@ -788,43 +788,7 @@ impl<W: LayoutElement> Layout<W> {
|
||||
}
|
||||
|
||||
let primary = &mut monitors[primary_idx];
|
||||
for ws in &mut workspaces {
|
||||
ws.set_output(Some(primary.output.clone()));
|
||||
}
|
||||
|
||||
let mut stopped_primary_ws_switch = false;
|
||||
if !workspaces.is_empty() && primary.workspace_switch.is_some() {
|
||||
// FIXME: if we're adding workspaces to currently invisible positions
|
||||
// (outside the workspace switch), we don't need to cancel it.
|
||||
primary.workspace_switch = None;
|
||||
stopped_primary_ws_switch = true;
|
||||
}
|
||||
|
||||
let empty_was_focused =
|
||||
primary.active_workspace_idx == primary.workspaces.len() - 1;
|
||||
|
||||
// Push the workspaces from the removed monitor in the end, right before the
|
||||
// last, empty, workspace.
|
||||
let empty = primary.workspaces.remove(primary.workspaces.len() - 1);
|
||||
primary.workspaces.extend(workspaces);
|
||||
primary.workspaces.push(empty);
|
||||
|
||||
// If empty_workspace_above_first is set and the first workspace is now no
|
||||
// longer empty, add a new empty workspace on top.
|
||||
if primary.options.layout.empty_workspace_above_first
|
||||
&& primary.workspaces[0].has_windows_or_name()
|
||||
{
|
||||
primary.add_workspace_top();
|
||||
}
|
||||
|
||||
// If the empty workspace was focused on the primary monitor, keep it focused.
|
||||
if empty_was_focused {
|
||||
primary.active_workspace_idx = primary.workspaces.len() - 1;
|
||||
}
|
||||
|
||||
if stopped_primary_ws_switch {
|
||||
primary.clean_up_workspaces();
|
||||
}
|
||||
primary.append_workspaces(workspaces);
|
||||
|
||||
MonitorSet::Normal {
|
||||
monitors,
|
||||
|
@@ -690,6 +690,42 @@ impl<W: LayoutElement> Monitor<W> {
|
||||
self.clean_up_workspaces();
|
||||
}
|
||||
|
||||
pub fn append_workspaces(&mut self, mut workspaces: Vec<Workspace<W>>) {
|
||||
if workspaces.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
for ws in &mut workspaces {
|
||||
ws.set_output(Some(self.output.clone()));
|
||||
}
|
||||
|
||||
let empty_was_focused = self.active_workspace_idx == self.workspaces.len() - 1;
|
||||
|
||||
// Push the workspaces from the removed monitor in the end, right before the
|
||||
// last, empty, workspace.
|
||||
let empty = self.workspaces.remove(self.workspaces.len() - 1);
|
||||
self.workspaces.extend(workspaces);
|
||||
self.workspaces.push(empty);
|
||||
|
||||
// If empty_workspace_above_first is set and the first workspace is now no longer empty,
|
||||
// add a new empty workspace on top.
|
||||
if self.options.layout.empty_workspace_above_first
|
||||
&& self.workspaces[0].has_windows_or_name()
|
||||
{
|
||||
self.add_workspace_top();
|
||||
}
|
||||
|
||||
// If the empty workspace was focused on the primary monitor, keep it focused.
|
||||
if empty_was_focused {
|
||||
self.active_workspace_idx = self.workspaces.len() - 1;
|
||||
}
|
||||
|
||||
// FIXME: if we're adding workspaces to currently invisible positions
|
||||
// (outside the workspace switch), we don't need to cancel it.
|
||||
self.workspace_switch = None;
|
||||
self.clean_up_workspaces();
|
||||
}
|
||||
|
||||
pub fn move_down_or_to_workspace_down(&mut self) {
|
||||
if !self.active_workspace().move_down() {
|
||||
self.move_to_workspace_down(true);
|
||||
|
Reference in New Issue
Block a user