aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2025-08-27 11:14:52 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2025-08-27 11:16:36 +0300
commit82697773f8e5507dc3982645f805a011996f7cb4 (patch)
tree12575f531ae173207ce78335bb1546ef77948dc2
parentf64cb6c03e1bc69422edbf7731d0031ffd4f6771 (diff)
downloadniri-82697773f8e5507dc3982645f805a011996f7cb4.tar.gz
niri-82697773f8e5507dc3982645f805a011996f7cb4.tar.bz2
niri-82697773f8e5507dc3982645f805a011996f7cb4.zip
config: Move workspace into its own module
-rw-r--r--niri-config/src/lib.rs2
-rw-r--r--niri-config/src/misc.rs64
-rw-r--r--niri-config/src/workspace.rs63
-rw-r--r--src/layout/tests.rs4
4 files changed, 67 insertions, 66 deletions
diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs
index 3210697d..636b4c82 100644
--- a/niri-config/src/lib.rs
+++ b/niri-config/src/lib.rs
@@ -20,6 +20,7 @@ pub mod misc;
pub mod output;
pub mod utils;
pub mod window_rule;
+pub mod workspace;
pub use crate::animations::{
Animation, AnimationCurve, AnimationKind, Animations, EasingParams, SpringParams,
@@ -35,6 +36,7 @@ pub use crate::misc::*;
pub use crate::output::{Output, OutputName, Outputs, Position, Vrr};
pub use crate::utils::FloatOrInt;
pub use crate::window_rule::{FloatingPosition, RelativeTo, WindowRule};
+pub use crate::workspace::Workspace;
#[derive(knuffel::Decode, Debug, PartialEq)]
pub struct Config {
diff --git a/niri-config/src/misc.rs b/niri-config/src/misc.rs
index 444fe772..781f51c0 100644
--- a/niri-config/src/misc.rs
+++ b/niri-config/src/misc.rs
@@ -1,5 +1,3 @@
-use knuffel::errors::DecodeError;
-
use crate::appearance::{Color, WorkspaceShadow, DEFAULT_BACKDROP_COLOR};
use crate::FloatOrInt;
@@ -105,65 +103,3 @@ impl Default for XwaylandSatellite {
}
}
}
-
-#[derive(knuffel::Decode, Debug, Clone, PartialEq, Eq)]
-pub struct Workspace {
- #[knuffel(argument)]
- pub name: WorkspaceName,
- #[knuffel(child, unwrap(argument))]
- pub open_on_output: Option<String>,
-}
-
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub struct WorkspaceName(pub String);
-
-impl<S: knuffel::traits::ErrorSpan> knuffel::DecodeScalar<S> for WorkspaceName {
- fn type_check(
- type_name: &Option<knuffel::span::Spanned<knuffel::ast::TypeName, S>>,
- ctx: &mut knuffel::decode::Context<S>,
- ) {
- if let Some(type_name) = &type_name {
- ctx.emit_error(DecodeError::unexpected(
- type_name,
- "type name",
- "no type name expected for this node",
- ));
- }
- }
-
- fn raw_decode(
- val: &knuffel::span::Spanned<knuffel::ast::Literal, S>,
- ctx: &mut knuffel::decode::Context<S>,
- ) -> Result<WorkspaceName, DecodeError<S>> {
- #[derive(Debug)]
- struct WorkspaceNameSet(Vec<String>);
- match &**val {
- knuffel::ast::Literal::String(ref s) => {
- let mut name_set: Vec<String> = match ctx.get::<WorkspaceNameSet>() {
- Some(h) => h.0.clone(),
- None => Vec::new(),
- };
-
- if name_set.iter().any(|name| name.eq_ignore_ascii_case(s)) {
- ctx.emit_error(DecodeError::unexpected(
- val,
- "named workspace",
- format!("duplicate named workspace: {s}"),
- ));
- return Ok(Self(String::new()));
- }
-
- name_set.push(s.to_string());
- ctx.set(WorkspaceNameSet(name_set));
- Ok(Self(s.clone().into()))
- }
- _ => {
- ctx.emit_error(DecodeError::unsupported(
- val,
- "workspace names must be strings",
- ));
- Ok(Self(String::new()))
- }
- }
- }
-}
diff --git a/niri-config/src/workspace.rs b/niri-config/src/workspace.rs
new file mode 100644
index 00000000..e502bdb7
--- /dev/null
+++ b/niri-config/src/workspace.rs
@@ -0,0 +1,63 @@
+use knuffel::errors::DecodeError;
+
+#[derive(knuffel::Decode, Debug, Clone, PartialEq, Eq)]
+pub struct Workspace {
+ #[knuffel(argument)]
+ pub name: WorkspaceName,
+ #[knuffel(child, unwrap(argument))]
+ pub open_on_output: Option<String>,
+}
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct WorkspaceName(pub String);
+
+impl<S: knuffel::traits::ErrorSpan> knuffel::DecodeScalar<S> for WorkspaceName {
+ fn type_check(
+ type_name: &Option<knuffel::span::Spanned<knuffel::ast::TypeName, S>>,
+ ctx: &mut knuffel::decode::Context<S>,
+ ) {
+ if let Some(type_name) = &type_name {
+ ctx.emit_error(DecodeError::unexpected(
+ type_name,
+ "type name",
+ "no type name expected for this node",
+ ));
+ }
+ }
+
+ fn raw_decode(
+ val: &knuffel::span::Spanned<knuffel::ast::Literal, S>,
+ ctx: &mut knuffel::decode::Context<S>,
+ ) -> Result<WorkspaceName, DecodeError<S>> {
+ #[derive(Debug)]
+ struct WorkspaceNameSet(Vec<String>);
+ match &**val {
+ knuffel::ast::Literal::String(ref s) => {
+ let mut name_set: Vec<String> = match ctx.get::<WorkspaceNameSet>() {
+ Some(h) => h.0.clone(),
+ None => Vec::new(),
+ };
+
+ if name_set.iter().any(|name| name.eq_ignore_ascii_case(s)) {
+ ctx.emit_error(DecodeError::unexpected(
+ val,
+ "named workspace",
+ format!("duplicate named workspace: {s}"),
+ ));
+ return Ok(Self(String::new()));
+ }
+
+ name_set.push(s.to_string());
+ ctx.set(WorkspaceNameSet(name_set));
+ Ok(Self(s.clone().into()))
+ }
+ _ => {
+ ctx.emit_error(DecodeError::unsupported(
+ val,
+ "workspace names must be strings",
+ ));
+ Ok(Self(String::new()))
+ }
+ }
+ }
+}
diff --git a/src/layout/tests.rs b/src/layout/tests.rs
index ab2f1f66..04381079 100644
--- a/src/layout/tests.rs
+++ b/src/layout/tests.rs
@@ -1,8 +1,8 @@
use std::cell::{Cell, OnceCell, RefCell};
+use niri_config::workspace::WorkspaceName;
use niri_config::{
- FloatOrInt, OutputName, TabIndicatorLength, TabIndicatorPosition, WorkspaceName,
- WorkspaceReference,
+ FloatOrInt, OutputName, TabIndicatorLength, TabIndicatorPosition, WorkspaceReference,
};
use proptest::prelude::*;
use proptest_derive::Arbitrary;