mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-23 02:05:33 +07:00
config: Add RegexEq util type instead of manual PartialEq
This commit is contained in:
+8
-18
@@ -12,7 +12,6 @@ use knuffel::errors::DecodeError;
|
||||
use knuffel::Decode as _;
|
||||
use miette::{miette, Context, IntoDiagnostic, NarratableReportHandler};
|
||||
use niri_ipc::{ConfiguredMode, LayoutSwitchTarget, SizeChange, Transform, WorkspaceReferenceArg};
|
||||
use regex::Regex;
|
||||
use smithay::backend::renderer::Color32F;
|
||||
use smithay::input::keyboard::keysyms::KEY_NoSymbol;
|
||||
use smithay::input::keyboard::xkb::{keysym_from_name, KEYSYM_CASE_INSENSITIVE};
|
||||
@@ -21,6 +20,9 @@ use smithay::reexports::input;
|
||||
|
||||
pub const DEFAULT_BACKGROUND_COLOR: Color = Color::from_array_unpremul([0.2, 0.2, 0.2, 1.]);
|
||||
|
||||
mod utils;
|
||||
pub use utils::RegexEq;
|
||||
|
||||
#[derive(knuffel::Decode, Debug, PartialEq)]
|
||||
pub struct Config {
|
||||
#[knuffel(child, default)]
|
||||
@@ -1002,13 +1004,12 @@ pub struct WindowRule {
|
||||
pub variable_refresh_rate: Option<bool>,
|
||||
}
|
||||
|
||||
// Remember to update the PartialEq impl when adding fields!
|
||||
#[derive(knuffel::Decode, Debug, Default, Clone)]
|
||||
#[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)]
|
||||
pub struct Match {
|
||||
#[knuffel(property, str)]
|
||||
pub app_id: Option<Regex>,
|
||||
pub app_id: Option<RegexEq>,
|
||||
#[knuffel(property, str)]
|
||||
pub title: Option<Regex>,
|
||||
pub title: Option<RegexEq>,
|
||||
#[knuffel(property)]
|
||||
pub is_active: Option<bool>,
|
||||
#[knuffel(property)]
|
||||
@@ -1019,17 +1020,6 @@ pub struct Match {
|
||||
pub at_startup: Option<bool>,
|
||||
}
|
||||
|
||||
impl PartialEq for Match {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.is_active == other.is_active
|
||||
&& self.is_focused == other.is_focused
|
||||
&& self.is_active_in_column == other.is_active_in_column
|
||||
&& self.at_startup == other.at_startup
|
||||
&& self.app_id.as_ref().map(Regex::as_str) == other.app_id.as_ref().map(Regex::as_str)
|
||||
&& self.title.as_ref().map(Regex::as_str) == other.title.as_ref().map(Regex::as_str)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq)]
|
||||
pub struct CornerRadius {
|
||||
pub top_left: f32,
|
||||
@@ -3361,7 +3351,7 @@ mod tests {
|
||||
]),
|
||||
window_rules: vec![WindowRule {
|
||||
matches: vec![Match {
|
||||
app_id: Some(Regex::new(".*alacritty").unwrap()),
|
||||
app_id: Some(RegexEq::from_str(".*alacritty").unwrap()),
|
||||
title: None,
|
||||
is_active: None,
|
||||
is_focused: None,
|
||||
@@ -3371,7 +3361,7 @@ mod tests {
|
||||
excludes: vec![
|
||||
Match {
|
||||
app_id: None,
|
||||
title: Some(Regex::new("~").unwrap()),
|
||||
title: Some(RegexEq::from_str("~").unwrap()),
|
||||
is_active: None,
|
||||
is_focused: None,
|
||||
is_active_in_column: None,
|
||||
|
||||
Reference in New Issue
Block a user