aboutsummaryrefslogtreecommitdiff
path: root/src/niri.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/niri.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/niri.rs')
-rw-r--r--src/niri.rs50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/niri.rs b/src/niri.rs
index a8d906c1..f054250c 100644
--- a/src/niri.rs
+++ b/src/niri.rs
@@ -11,7 +11,7 @@ use std::{env, mem, thread};
use _server_decoration::server::org_kde_kwin_server_decoration_manager::Mode as KdeDecorationsMode;
use anyhow::{ensure, Context};
use calloop::futures::Scheduler;
-use niri_config::{Config, Key, Modifiers, PreviewRender, TrackLayout};
+use niri_config::{Config, Key, Modifiers, PreviewRender, TrackLayout, WorkspaceReference};
use smithay::backend::allocator::Fourcc;
use smithay::backend::renderer::damage::OutputDamageTracker;
use smithay::backend::renderer::element::memory::MemoryRenderBufferRenderElement;
@@ -857,8 +857,24 @@ impl State {
self.niri.config_error_notification.hide();
+ // Find & orphan removed named workspaces.
+ let mut removed_workspaces: Vec<String> = vec![];
+ for ws in &self.niri.config.borrow().workspaces {
+ if !config.workspaces.iter().any(|w| w.name == ws.name) {
+ removed_workspaces.push(ws.name.0.clone());
+ }
+ }
+ for name in removed_workspaces {
+ self.niri.layout.unname_workspace(&name);
+ }
+
self.niri.layout.update_config(&config);
+ // Create new named workspaces.
+ for ws_config in &config.workspaces {
+ self.niri.layout.ensure_named_workspace(ws_config);
+ }
+
let slowdown = if config.animations.off {
0.
} else {
@@ -2097,6 +2113,38 @@ impl Niri {
.cloned()
}
+ pub fn output_by_name(&self, name: &str) -> Option<Output> {
+ self.global_space
+ .outputs()
+ .find(|output| output.name().eq_ignore_ascii_case(name))
+ .cloned()
+ }
+
+ pub fn find_output_and_workspace_index(
+ &self,
+ workspace_reference: WorkspaceReference,
+ ) -> Option<(Option<Output>, usize)> {
+ let workspace_name = match workspace_reference {
+ WorkspaceReference::Index(index) => {
+ return Some((None, index.saturating_sub(1) as usize));
+ }
+ WorkspaceReference::Name(name) => name,
+ };
+
+ let (target_workspace_index, target_workspace) =
+ self.layout.find_workspace_by_name(&workspace_name)?;
+
+ // FIXME: when we do fixes for no connected outputs, this will need fixing too.
+ let active_workspace = self.layout.active_workspace()?;
+
+ if target_workspace.current_output() == active_workspace.current_output() {
+ return Some((None, target_workspace_index));
+ }
+ let target_output = target_workspace.current_output()?;
+
+ Some((Some(target_output.clone()), target_workspace_index))
+ }
+
pub fn output_down(&self) -> Option<Output> {
let active = self.layout.active_output()?;
let active_geo = self.global_space.output_geometry(active).unwrap();