mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-23 02:05:33 +07:00
config: Move workspace into its own module
This commit is contained in:
@@ -20,6 +20,7 @@ pub mod misc;
|
|||||||
pub mod output;
|
pub mod output;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
pub mod window_rule;
|
pub mod window_rule;
|
||||||
|
pub mod workspace;
|
||||||
|
|
||||||
pub use crate::animations::{
|
pub use crate::animations::{
|
||||||
Animation, AnimationCurve, AnimationKind, Animations, EasingParams, SpringParams,
|
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::output::{Output, OutputName, Outputs, Position, Vrr};
|
||||||
pub use crate::utils::FloatOrInt;
|
pub use crate::utils::FloatOrInt;
|
||||||
pub use crate::window_rule::{FloatingPosition, RelativeTo, WindowRule};
|
pub use crate::window_rule::{FloatingPosition, RelativeTo, WindowRule};
|
||||||
|
pub use crate::workspace::Workspace;
|
||||||
|
|
||||||
#[derive(knuffel::Decode, Debug, PartialEq)]
|
#[derive(knuffel::Decode, Debug, PartialEq)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
use knuffel::errors::DecodeError;
|
|
||||||
|
|
||||||
use crate::appearance::{Color, WorkspaceShadow, DEFAULT_BACKDROP_COLOR};
|
use crate::appearance::{Color, WorkspaceShadow, DEFAULT_BACKDROP_COLOR};
|
||||||
use crate::FloatOrInt;
|
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()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
use std::cell::{Cell, OnceCell, RefCell};
|
use std::cell::{Cell, OnceCell, RefCell};
|
||||||
|
|
||||||
|
use niri_config::workspace::WorkspaceName;
|
||||||
use niri_config::{
|
use niri_config::{
|
||||||
FloatOrInt, OutputName, TabIndicatorLength, TabIndicatorPosition, WorkspaceName,
|
FloatOrInt, OutputName, TabIndicatorLength, TabIndicatorPosition, WorkspaceReference,
|
||||||
WorkspaceReference,
|
|
||||||
};
|
};
|
||||||
use proptest::prelude::*;
|
use proptest::prelude::*;
|
||||||
use proptest_derive::Arbitrary;
|
use proptest_derive::Arbitrary;
|
||||||
|
|||||||
Reference in New Issue
Block a user