aboutsummaryrefslogtreecommitdiff
path: root/src/input
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/input
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/input')
-rw-r--r--src/input/mod.rs77
1 files changed, 54 insertions, 23 deletions
diff --git a/src/input/mod.rs b/src/input/mod.rs
index 8206890c..1984b23c 100644
--- a/src/input/mod.rs
+++ b/src/input/mod.rs
@@ -587,12 +587,22 @@ impl State {
// FIXME: granular
self.niri.queue_redraw_all();
}
- Action::MoveWindowToWorkspace(idx) => {
- let idx = idx.saturating_sub(1) as usize;
- self.niri.layout.move_to_workspace(idx);
- self.maybe_warp_cursor_to_focus();
- // FIXME: granular
- self.niri.queue_redraw_all();
+ Action::MoveWindowToWorkspace(reference) => {
+ if let Some((output, index)) = self.niri.find_output_and_workspace_index(reference)
+ {
+ if let Some(output) = output {
+ self.niri.layout.move_to_workspace_on_output(&output, index);
+ if !self.maybe_warp_cursor_to_focus_centered() {
+ self.move_cursor_to_output(&output);
+ }
+ } else {
+ self.niri.layout.move_to_workspace(index);
+ self.maybe_warp_cursor_to_focus();
+ }
+
+ // FIXME: granular
+ self.niri.queue_redraw_all();
+ }
}
Action::MoveColumnToWorkspaceDown => {
self.niri.layout.move_column_to_workspace_down();
@@ -606,12 +616,24 @@ impl State {
// FIXME: granular
self.niri.queue_redraw_all();
}
- Action::MoveColumnToWorkspace(idx) => {
- let idx = idx.saturating_sub(1) as usize;
- self.niri.layout.move_column_to_workspace(idx);
- self.maybe_warp_cursor_to_focus();
- // FIXME: granular
- self.niri.queue_redraw_all();
+ Action::MoveColumnToWorkspace(reference) => {
+ if let Some((output, index)) = self.niri.find_output_and_workspace_index(reference)
+ {
+ if let Some(output) = output {
+ self.niri
+ .layout
+ .move_column_to_workspace_on_output(&output, index);
+ if !self.maybe_warp_cursor_to_focus_centered() {
+ self.move_cursor_to_output(&output);
+ }
+ } else {
+ self.niri.layout.move_column_to_workspace(index);
+ self.maybe_warp_cursor_to_focus();
+ }
+
+ // FIXME: granular
+ self.niri.queue_redraw_all();
+ }
}
Action::FocusWorkspaceDown => {
self.niri.layout.switch_workspace_down();
@@ -625,19 +647,28 @@ impl State {
// FIXME: granular
self.niri.queue_redraw_all();
}
- Action::FocusWorkspace(idx) => {
- let idx = idx.saturating_sub(1) as usize;
+ Action::FocusWorkspace(reference) => {
+ if let Some((output, index)) = self.niri.find_output_and_workspace_index(reference)
+ {
+ if let Some(output) = output {
+ self.niri.layout.focus_output(&output);
+ self.niri.layout.switch_workspace(index);
+ if !self.maybe_warp_cursor_to_focus_centered() {
+ self.move_cursor_to_output(&output);
+ }
+ } else {
+ let config = &self.niri.config;
+ if config.borrow().input.workspace_auto_back_and_forth {
+ self.niri.layout.switch_workspace_auto_back_and_forth(index);
+ } else {
+ self.niri.layout.switch_workspace(index);
+ }
+ self.maybe_warp_cursor_to_focus();
+ }
- let config = &self.niri.config;
- if config.borrow().input.workspace_auto_back_and_forth {
- self.niri.layout.switch_workspace_auto_back_and_forth(idx);
- } else {
- self.niri.layout.switch_workspace(idx);
+ // FIXME: granular
+ self.niri.queue_redraw_all();
}
-
- self.maybe_warp_cursor_to_focus();
- // FIXME: granular
- self.niri.queue_redraw_all();
}
Action::FocusWorkspacePrevious => {
self.niri.layout.switch_workspace_previous();