aboutsummaryrefslogtreecommitdiff
path: root/src/layout/workspace.rs
diff options
context:
space:
mode:
authorGergely Nagy <niri@gergo.csillger.hu>2024-05-11 22:40:30 +0200
committerIvan Molodetskikh <yalterz@gmail.com>2024-05-16 01:24:34 -0700
commiteb9bbe3352820754a4ee3c19f15cff690d1c193d (patch)
tree65264aa9d03cc1ed63b4a540d0bca438ba75624b /src/layout/workspace.rs
parent229ca905071d837dbe6cfd9383e51cbb3c4634d7 (diff)
downloadniri-eb9bbe3352820754a4ee3c19f15cff690d1c193d.tar.gz
niri-eb9bbe3352820754a4ee3c19f15cff690d1c193d.tar.bz2
niri-eb9bbe3352820754a4ee3c19f15cff690d1c193d.zip
Implement named workspaces
This is an implementation of named, pre-declared workspaces. With this implementation, workspaces can be declared in the configuration file by name: ``` workspace "name" { open-on-output "winit" } ``` The `open-on-output` property is optional, and can be skipped, in which case the workspace will open on the primary output. All actions that were able to target a workspace by index can now target them by either an index, or a name. In case of the command line, where we do not have types available, this means that workspace names that also pass as `u8` cannot be switched to by name, only by index. Unlike dynamic workspaces, named workspaces do not close when they are empty, they remain static. Like dynamic workspaces, named workspaces are bound to a particular output. Switching to a named workspace, or moving a window or column to one will also switch to, or move the thing in question to the output of the workspace. When reloading the configuration, newly added named workspaces will be created, and removed ones will lose their name. If any such orphaned workspace was empty, they will be removed. If they weren't, they'll remain as a dynamic workspace, without a name. Re-declaring a workspace with the same name later will create a new one. Additionally, this also implements a `open-on-workspace "<name>"` window rule. Matching windows will open on the given workspace (or the current one, if the named workspace does not exist). Signed-off-by: Gergely Nagy <niri@gergo.csillger.hu>
Diffstat (limited to 'src/layout/workspace.rs')
-rw-r--r--src/layout/workspace.rs48
1 files changed, 44 insertions, 4 deletions
diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs
index 4a6ad91c..827228c6 100644
--- a/src/layout/workspace.rs
+++ b/src/layout/workspace.rs
@@ -3,7 +3,7 @@ use std::iter::{self, zip};
use std::rc::Rc;
use std::time::Duration;
-use niri_config::{CenterFocusedColumn, PresetWidth, Struts};
+use niri_config::{CenterFocusedColumn, PresetWidth, Struts, Workspace as WorkspaceConfig};
use niri_ipc::SizeChange;
use smithay::backend::renderer::gles::GlesRenderer;
use smithay::desktop::{layer_map_for_output, Window};
@@ -94,6 +94,9 @@ pub struct Workspace<W: LayoutElement> {
/// Configurable properties of the layout.
pub options: Rc<Options>,
+ /// Optional name of this workspace.
+ pub name: Option<String>,
+
/// Unique ID of this workspace.
id: WorkspaceId,
}
@@ -313,9 +316,23 @@ impl TileData {
impl<W: LayoutElement> Workspace<W> {
pub fn new(output: Output, options: Rc<Options>) -> Self {
+ Self::new_with_config(output, None, options)
+ }
+
+ pub fn new_with_config(
+ output: Output,
+ config: Option<WorkspaceConfig>,
+ options: Rc<Options>,
+ ) -> Self {
+ let original_output = config
+ .as_ref()
+ .and_then(|c| c.open_on_output.clone())
+ .map(OutputId)
+ .unwrap_or(OutputId::new(&output));
+
let working_area = compute_working_area(&output, options.struts);
Self {
- original_output: OutputId::new(&output),
+ original_output,
view_size: output_size(&output),
working_area,
output: Some(output),
@@ -329,14 +346,24 @@ impl<W: LayoutElement> Workspace<W> {
view_offset_before_fullscreen: None,
closing_windows: vec![],
options,
+ name: config.map(|c| c.name.0),
id: WorkspaceId::next(),
}
}
- pub fn new_no_outputs(options: Rc<Options>) -> Self {
+ pub fn new_with_config_no_outputs(
+ config: Option<WorkspaceConfig>,
+ options: Rc<Options>,
+ ) -> Self {
+ let original_output = OutputId(
+ config
+ .clone()
+ .and_then(|c| c.open_on_output)
+ .unwrap_or_default(),
+ );
Self {
output: None,
- original_output: OutputId(String::new()),
+ original_output,
view_size: Size::from((1280, 720)),
working_area: Rectangle::from_loc_and_size((0, 0), (1280, 720)),
columns: vec![],
@@ -349,14 +376,23 @@ impl<W: LayoutElement> Workspace<W> {
view_offset_before_fullscreen: None,
closing_windows: vec![],
options,
+ name: config.map(|c| c.name.0),
id: WorkspaceId::next(),
}
}
+ pub fn new_no_outputs(options: Rc<Options>) -> Self {
+ Self::new_with_config_no_outputs(None, options)
+ }
+
pub fn id(&self) -> WorkspaceId {
self.id
}
+ pub fn unname(&mut self) {
+ self.name = None;
+ }
+
pub fn advance_animations(&mut self, current_time: Duration) {
if let Some(ViewOffsetAdjustment::Animation(anim)) = &mut self.view_offset_adj {
anim.set_current_time(current_time);
@@ -435,6 +471,10 @@ impl<W: LayoutElement> Workspace<W> {
.map(Tile::window_mut)
}
+ pub fn current_output(&self) -> Option<&Output> {
+ self.output.as_ref()
+ }
+
pub fn set_output(&mut self, output: Option<Output>) {
if self.output == output {
return;