aboutsummaryrefslogtreecommitdiff
path: root/niri-ipc/src/lib.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 /niri-ipc/src/lib.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 'niri-ipc/src/lib.rs')
-rw-r--r--niri-ipc/src/lib.rs45
1 files changed, 36 insertions, 9 deletions
diff --git a/niri-ipc/src/lib.rs b/niri-ipc/src/lib.rs
index beabfcbc..b0f124f9 100644
--- a/niri-ipc/src/lib.rs
+++ b/niri-ipc/src/lib.rs
@@ -146,11 +146,11 @@ pub enum Action {
FocusWorkspaceDown,
/// Focus the workspace above.
FocusWorkspaceUp,
- /// Focus a workspace by index.
+ /// Focus a workspace by reference (index or name).
FocusWorkspace {
- /// Index of the workspace to focus.
+ /// Reference (index or name) of the workspace to focus.
#[cfg_attr(feature = "clap", arg())]
- index: u8,
+ reference: WorkspaceReferenceArg,
},
/// Focus the previous workspace.
FocusWorkspacePrevious,
@@ -158,21 +158,21 @@ pub enum Action {
MoveWindowToWorkspaceDown,
/// Move the focused window to the workspace above.
MoveWindowToWorkspaceUp,
- /// Move the focused window to a workspace by index.
+ /// Move the focused window to a workspace by reference (index or name).
MoveWindowToWorkspace {
- /// Index of the target workspace.
+ /// Reference (index or name) of the workspace to move the window to.
#[cfg_attr(feature = "clap", arg())]
- index: u8,
+ reference: WorkspaceReferenceArg,
},
/// Move the focused column to the workspace below.
MoveColumnToWorkspaceDown,
/// Move the focused column to the workspace above.
MoveColumnToWorkspaceUp,
- /// Move the focused column to a workspace by index.
+ /// Move the focused column to a workspace by reference (index or name).
MoveColumnToWorkspace {
- /// Index of the target workspace.
+ /// Reference (index or name) of the workspace to move the column to.
#[cfg_attr(feature = "clap", arg())]
- index: u8,
+ reference: WorkspaceReferenceArg,
},
/// Move the focused workspace down.
MoveWorkspaceDown,
@@ -257,6 +257,15 @@ pub enum SizeChange {
AdjustProportion(f64),
}
+/// Workspace reference (index or name) to operate on.
+#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
+pub enum WorkspaceReferenceArg {
+ /// Index of the workspace.
+ Index(u8),
+ /// Name of the workspace.
+ Name(String),
+}
+
/// Layout to switch to.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
pub enum LayoutSwitchTarget {
@@ -475,6 +484,24 @@ pub enum OutputConfigChanged {
OutputWasMissing,
}
+impl FromStr for WorkspaceReferenceArg {
+ type Err = &'static str;
+
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ let reference = if let Ok(index) = s.parse::<i32>() {
+ if let Ok(idx) = u8::try_from(index) {
+ Self::Index(idx)
+ } else {
+ return Err("workspace indexes must be between 0 and 255");
+ }
+ } else {
+ Self::Name(s.to_string())
+ };
+
+ Ok(reference)
+ }
+}
+
impl FromStr for SizeChange {
type Err = &'static str;