mirror of
https://github.com/YaLTeR/niri.git
synced 2025-10-06 00:23:14 +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 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 stopped_primary_ws_switch = false;
|
||||||
|
|
||||||
let mut workspaces = vec![];
|
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
|
// another monitor. However, we will add an empty workspace in the end
|
||||||
// instead.
|
// instead.
|
||||||
if ws.has_windows_or_name() {
|
if ws.has_windows_or_name() {
|
||||||
if Some(ws.id()) == ws_id_to_activate {
|
|
||||||
active_workspace_idx = Some(workspaces.len());
|
|
||||||
}
|
|
||||||
|
|
||||||
workspaces.push(ws);
|
workspaces.push(ws);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -717,33 +710,15 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
|
|
||||||
workspaces.reverse();
|
workspaces.reverse();
|
||||||
|
|
||||||
if let Some(idx) = &mut active_workspace_idx {
|
let ws_id_to_activate = self.last_active_workspace_id.remove(&output.name());
|
||||||
*idx = workspaces.len() - *idx - 1;
|
|
||||||
}
|
|
||||||
let mut active_workspace_idx = active_workspace_idx.unwrap_or(0);
|
|
||||||
|
|
||||||
// Make sure there's always an empty workspace.
|
let mut monitor = Monitor::new(
|
||||||
workspaces.push(Workspace::new(
|
output,
|
||||||
output.clone(),
|
workspaces,
|
||||||
|
ws_id_to_activate,
|
||||||
self.clock.clone(),
|
self.clock.clone(),
|
||||||
self.options.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.overview_open = self.overview_open;
|
||||||
monitor.set_overview_progress(self.overview_progress.as_ref());
|
monitor.set_overview_progress(self.overview_progress.as_ref());
|
||||||
monitors.push(monitor);
|
monitors.push(monitor);
|
||||||
@@ -754,36 +729,16 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
active_monitor_idx,
|
active_monitor_idx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MonitorSet::NoOutputs { mut workspaces } => {
|
MonitorSet::NoOutputs { 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
let ws_id_to_activate = self.last_active_workspace_id.remove(&output.name());
|
let ws_id_to_activate = self.last_active_workspace_id.remove(&output.name());
|
||||||
|
|
||||||
for (i, workspace) in workspaces.iter_mut().enumerate() {
|
let mut monitor = Monitor::new(
|
||||||
workspace.set_output(Some(output.clone()));
|
output,
|
||||||
|
workspaces,
|
||||||
if Some(workspace.id()) == ws_id_to_activate {
|
ws_id_to_activate,
|
||||||
active_workspace_idx = i;
|
self.clock.clone(),
|
||||||
}
|
self.options.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.overview_open = self.overview_open;
|
||||||
monitor.set_overview_progress(self.overview_progress.as_ref());
|
monitor.set_overview_progress(self.overview_progress.as_ref());
|
||||||
|
|
||||||
|
@@ -275,7 +275,8 @@ impl From<&super::OverviewProgress> for OverviewProgress {
|
|||||||
impl<W: LayoutElement> Monitor<W> {
|
impl<W: LayoutElement> Monitor<W> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
output: Output,
|
output: Output,
|
||||||
workspaces: Vec<Workspace<W>>,
|
mut workspaces: Vec<Workspace<W>>,
|
||||||
|
ws_id_to_activate: Option<WorkspaceId>,
|
||||||
clock: Clock,
|
clock: Clock,
|
||||||
options: Rc<Options>,
|
options: Rc<Options>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@@ -283,6 +284,28 @@ impl<W: LayoutElement> Monitor<W> {
|
|||||||
let view_size = output_size(&output);
|
let view_size = output_size(&output);
|
||||||
let working_area = compute_working_area(&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 {
|
Self {
|
||||||
output_name: output.name(),
|
output_name: output.name(),
|
||||||
output,
|
output,
|
||||||
@@ -290,7 +313,7 @@ impl<W: LayoutElement> Monitor<W> {
|
|||||||
view_size,
|
view_size,
|
||||||
working_area,
|
working_area,
|
||||||
workspaces,
|
workspaces,
|
||||||
active_workspace_idx: 0,
|
active_workspace_idx,
|
||||||
previous_workspace_id: None,
|
previous_workspace_id: None,
|
||||||
insert_hint: None,
|
insert_hint: None,
|
||||||
insert_hint_element: InsertHintElement::new(options.layout.insert_hint),
|
insert_hint_element: InsertHintElement::new(options.layout.insert_hint),
|
||||||
|
Reference in New Issue
Block a user