mirror of
https://github.com/YaLTeR/niri.git
synced 2025-10-05 16:12:47 +02:00
layout: Move empty workspace handling to Monitor::new()
This commit is contained in:
@@ -654,9 +654,6 @@ impl<W: LayoutElement> Layout<W> {
|
||||
} => {
|
||||
let primary = &mut monitors[primary_idx];
|
||||
|
||||
let ws_id_to_activate = self.last_active_workspace_id.remove(&output.name());
|
||||
let mut active_workspace_idx = None;
|
||||
|
||||
let mut stopped_primary_ws_switch = false;
|
||||
|
||||
let mut workspaces = vec![];
|
||||
@@ -676,10 +673,6 @@ impl<W: LayoutElement> Layout<W> {
|
||||
// another monitor. However, we will add an empty workspace in the end
|
||||
// instead.
|
||||
if ws.has_windows_or_name() {
|
||||
if Some(ws.id()) == ws_id_to_activate {
|
||||
active_workspace_idx = Some(workspaces.len());
|
||||
}
|
||||
|
||||
workspaces.push(ws);
|
||||
}
|
||||
|
||||
@@ -717,33 +710,15 @@ impl<W: LayoutElement> Layout<W> {
|
||||
|
||||
workspaces.reverse();
|
||||
|
||||
if let Some(idx) = &mut active_workspace_idx {
|
||||
*idx = workspaces.len() - *idx - 1;
|
||||
}
|
||||
let mut active_workspace_idx = active_workspace_idx.unwrap_or(0);
|
||||
let ws_id_to_activate = self.last_active_workspace_id.remove(&output.name());
|
||||
|
||||
// Make sure there's always an empty workspace.
|
||||
workspaces.push(Workspace::new(
|
||||
output.clone(),
|
||||
let mut monitor = Monitor::new(
|
||||
output,
|
||||
workspaces,
|
||||
ws_id_to_activate,
|
||||
self.clock.clone(),
|
||||
self.options.clone(),
|
||||
));
|
||||
|
||||
if self.options.layout.empty_workspace_above_first && workspaces.len() > 1 {
|
||||
workspaces.insert(
|
||||
0,
|
||||
Workspace::new(output.clone(), self.clock.clone(), self.options.clone()),
|
||||
);
|
||||
active_workspace_idx += 1;
|
||||
}
|
||||
|
||||
for ws in &mut workspaces {
|
||||
ws.set_output(Some(output.clone()));
|
||||
}
|
||||
|
||||
let mut monitor =
|
||||
Monitor::new(output, workspaces, self.clock.clone(), self.options.clone());
|
||||
monitor.active_workspace_idx = active_workspace_idx;
|
||||
);
|
||||
monitor.overview_open = self.overview_open;
|
||||
monitor.set_overview_progress(self.overview_progress.as_ref());
|
||||
monitors.push(monitor);
|
||||
@@ -754,36 +729,16 @@ impl<W: LayoutElement> Layout<W> {
|
||||
active_monitor_idx,
|
||||
}
|
||||
}
|
||||
MonitorSet::NoOutputs { mut workspaces } => {
|
||||
// We know there are no empty workspaces there, so add one.
|
||||
workspaces.push(Workspace::new(
|
||||
output.clone(),
|
||||
self.clock.clone(),
|
||||
self.options.clone(),
|
||||
));
|
||||
|
||||
let mut active_workspace_idx = 0;
|
||||
if self.options.layout.empty_workspace_above_first && workspaces.len() > 1 {
|
||||
workspaces.insert(
|
||||
0,
|
||||
Workspace::new(output.clone(), self.clock.clone(), self.options.clone()),
|
||||
);
|
||||
active_workspace_idx += 1;
|
||||
}
|
||||
|
||||
MonitorSet::NoOutputs { workspaces } => {
|
||||
let ws_id_to_activate = self.last_active_workspace_id.remove(&output.name());
|
||||
|
||||
for (i, workspace) in workspaces.iter_mut().enumerate() {
|
||||
workspace.set_output(Some(output.clone()));
|
||||
|
||||
if Some(workspace.id()) == ws_id_to_activate {
|
||||
active_workspace_idx = i;
|
||||
}
|
||||
}
|
||||
|
||||
let mut monitor =
|
||||
Monitor::new(output, workspaces, self.clock.clone(), self.options.clone());
|
||||
monitor.active_workspace_idx = active_workspace_idx;
|
||||
let mut monitor = Monitor::new(
|
||||
output,
|
||||
workspaces,
|
||||
ws_id_to_activate,
|
||||
self.clock.clone(),
|
||||
self.options.clone(),
|
||||
);
|
||||
monitor.overview_open = self.overview_open;
|
||||
monitor.set_overview_progress(self.overview_progress.as_ref());
|
||||
|
||||
|
@@ -275,7 +275,8 @@ impl From<&super::OverviewProgress> for OverviewProgress {
|
||||
impl<W: LayoutElement> Monitor<W> {
|
||||
pub fn new(
|
||||
output: Output,
|
||||
workspaces: Vec<Workspace<W>>,
|
||||
mut workspaces: Vec<Workspace<W>>,
|
||||
ws_id_to_activate: Option<WorkspaceId>,
|
||||
clock: Clock,
|
||||
options: Rc<Options>,
|
||||
) -> Self {
|
||||
@@ -283,6 +284,28 @@ impl<W: LayoutElement> Monitor<W> {
|
||||
let view_size = output_size(&output);
|
||||
let working_area = compute_working_area(&output);
|
||||
|
||||
// Prepare the workspaces: set output, empty first, empty last.
|
||||
let mut active_workspace_idx = 0;
|
||||
|
||||
for (idx, ws) in workspaces.iter_mut().enumerate() {
|
||||
assert!(ws.has_windows_or_name());
|
||||
|
||||
ws.set_output(Some(output.clone()));
|
||||
|
||||
if ws_id_to_activate.is_some_and(|id| ws.id() == id) {
|
||||
active_workspace_idx = idx;
|
||||
}
|
||||
}
|
||||
|
||||
if options.layout.empty_workspace_above_first && !workspaces.is_empty() {
|
||||
let ws = Workspace::new(output.clone(), clock.clone(), options.clone());
|
||||
workspaces.insert(0, ws);
|
||||
active_workspace_idx += 1;
|
||||
}
|
||||
|
||||
let ws = Workspace::new(output.clone(), clock.clone(), options.clone());
|
||||
workspaces.push(ws);
|
||||
|
||||
Self {
|
||||
output_name: output.name(),
|
||||
output,
|
||||
@@ -290,7 +313,7 @@ impl<W: LayoutElement> Monitor<W> {
|
||||
view_size,
|
||||
working_area,
|
||||
workspaces,
|
||||
active_workspace_idx: 0,
|
||||
active_workspace_idx,
|
||||
previous_workspace_id: None,
|
||||
insert_hint: None,
|
||||
insert_hint_element: InsertHintElement::new(options.layout.insert_hint),
|
||||
|
Reference in New Issue
Block a user