Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

feat: add default window rules

Lars Berger13a0362ee09f
diff --git a/packages/wm/src/user_config.rs b/packages/wm/src/user_config.rs
index 720a2953..3b822f98 100644
--- a/packages/wm/src/user_config.rs
+++ b/packages/wm/src/user_config.rs
@@ -1,4 +1,4 @@
-use std::path::PathBuf;
+use std::{collections::HashMap, path::PathBuf};
use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};
@@ -89,6 +89,93 @@ impl UserConfig {
Ok(())
}
+ pub fn default_window_rules(&self) -> Vec<WindowRuleConfig> {
+ let mut window_rules = Vec::new();
+
+ let floating_defaults =
+ &self.value.window_behavior.state_defaults.floating;
+
+ // Default float rules.
+ window_rules.push(WindowRuleConfig {
+ commands: vec![InvokeCommand::SetFloating {
+ centered: Some(floating_defaults.centered),
+ shown_on_top: Some(floating_defaults.shown_on_top),
+ }],
+ match_window: vec![WindowMatchConfig {
+ window_class: Some(MatchType::Equals { equals:
+ // Windows 10 dialog shown when moving and deleting files.
+ "OperationStatusWindow".to_string(),
+ }),
+ ..WindowMatchConfig::default()
+ }],
+ on: vec![WindowRuleEvent::Manage],
+ run_once: true,
+ });
+
+ // Default ignore rules.
+ window_rules.push(WindowRuleConfig {
+ commands: vec![InvokeCommand::Ignore],
+ match_window: vec![
+ WindowMatchConfig {
+ window_process: Some(MatchType::Equals {
+ equals: "SearchApp".to_string(),
+ }),
+ ..WindowMatchConfig::default()
+ },
+ WindowMatchConfig {
+ window_process: Some(MatchType::Equals {
+ equals: "SearchHost".to_string(),
+ }),
+ ..WindowMatchConfig::default()
+ },
+ WindowMatchConfig {
+ window_process: Some(MatchType::Equals {
+ equals: "ShellExperienceHost".to_string(),
+ }),
+ ..WindowMatchConfig::default()
+ },
+ WindowMatchConfig {
+ window_process: Some(MatchType::Equals {
+ equals: "StartMenuExperienceHost".to_string(),
+ }),
+ ..WindowMatchConfig::default()
+ },
+ // TODO: Add snipping tool. Add lock app.
+ ],
+ on: vec![WindowRuleEvent::Manage],
+ run_once: true,
+ });
+
+ window_rules
+ }
+
+ fn window_rules_by_event(
+ &self,
+ ) -> HashMap<WindowRuleEvent, Vec<WindowRuleConfig>> {
+ let mut window_rules_by_event = HashMap::new();
+
+ let event_types = vec![
+ WindowRuleEvent::Focus,
+ WindowRuleEvent::Manage,
+ WindowRuleEvent::TitleChange,
+ ];
+
+ for event_type in event_types {
+ window_rules_by_event.insert(event_type, Vec::new());
+ }
+
+ for window_rule in &self.value.window_rules {
+ for event_type in &window_rule.on {
+ window_rules_by_event
+ .get_mut(event_type)
+ .unwrap()
+ .push(window_rule.clone());
+ }
+ }
+
+ window_rules_by_event
+ }
+
pub fn inactive_workspace_configs(
&self,
active_workspaces: &Vec<Workspace>,
@@ -312,48 +399,47 @@ pub struct BorderEffectConfig {
pub struct WindowRuleConfig {
pub commands: Vec<InvokeCommand>,
- #[serde(default)]
- pub match_type: MatchType,
-
#[serde(rename = "match")]
- pub match_window: WindowMatchType,
+ pub match_window: Vec<WindowMatchConfig>,
#[serde(default = "default_window_rule_on")]
- pub on: Vec<WindowMatchEvent>,
+ pub on: Vec<WindowRuleEvent>,
#[serde(default = "default_bool::<true>")]
pub run_once: bool,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
-#[serde(rename_all = "snake_case")]
-pub enum MatchType {
- All,
- #[default]
- Any,
-}
+#[serde(rename_all(serialize = "camelCase"))]
+pub struct WindowMatchConfig {
+ #[serde(default)]
+ pub window_process: Option<MatchType>,
-#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(tag = "prop", content = "matchBy")]
-pub enum WindowMatchType {
- WindowProcess(MatchBy),
- WindowClass(MatchBy),
- WindowTitle(MatchBy),
+ #[serde(default)]
+ pub window_class: Option<MatchType>,
+
+ #[serde(default)]
+ pub window_title: Option<MatchType>,
}
+/// Due to limitations in `serde_yaml`, we need to use an untagged enum
+/// instead of a regular enum.
#[derive(Clone, Debug, Deserialize, Serialize)]
-#[serde(tag = "type", content = "value")]
-pub enum MatchBy {
- Equals(String),
- Includes(String),
- Regex(String),
+#[serde(untagged)]
+pub enum MatchType {
+ Equals { equals: String },
+ Includes { includes: String },
+ Regex { regex: String },
}
-#[derive(Clone, Debug, Deserialize, Serialize)]
+#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
-pub enum WindowMatchEvent {
+pub enum WindowRuleEvent {
+ /// When a window receives native focus.
Focus,
+ /// When a window is initially managed.
Manage,
+ /// When the title of a window changes.
TitleChange,
}
@@ -383,6 +469,6 @@ const fn default_blue() -> Color {
}
/// Helper function for setting a default value for window rule events.
-fn default_window_rule_on() -> Vec<WindowMatchEvent> {
- vec![WindowMatchEvent::Manage, WindowMatchEvent::TitleChange]
+fn default_window_rule_on() -> Vec<WindowRuleEvent> {
+ vec![WindowRuleEvent::Manage, WindowRuleEvent::TitleChange]
}
diff --git a/resources/sample-config.yaml b/resources/sample-config.yaml
index fc0f7d7e..1bf2f0a3 100644
--- a/resources/sample-config.yaml
+++ b/resources/sample-config.yaml
@@ -77,34 +77,28 @@ workspaces:
- name: '9'
window_rules:
- # Task Manager requires admin privileges to manage and should be ignored
- # unless running the WM as admin.
- commands: ['ignore']
- match_type: 'any'
match:
+ # Task Manager requires admin privileges to manage and should be ignored
+ # unless running the WM as admin.
- window_process: { equals: 'Taskmgr' }
+
+ # Ignores the Snipping Tool's window.
- window_process: { equals: 'ScreenClippingHost' }
+ # Ignores picture-in-picture windows for browsers.
+ - window_title: { regex: '[Pp]icture.in.[Pp]icture' }
+ window_class: { regex: 'Chrome_WidgetWin_1|MozillaDialogClass' }
+
# Launches system dialogs as floating by default (e.g. File Explorer save
# and open dialog).
- commands: ['set-floating']
- match_type: 'any'
match:
- window_class: { equals: '#32770' }
- # Do not manage picture-in-picture windows for browsers. Note that the
- # default is for English; change `match_title` to the window's title if
- # you use another language.
- - commands: ['ignore']
- match_type: 'all'
- match:
- - window_title: { regex: '[Pp]icture.in.[Pp]icture' }
- - window_class: { regex: 'Chrome_WidgetWin_1|MozillaDialogClass' }
-
# Some applications (e.g. Steam) have borders that extend past the normal
# border size.
- commands: ['adjust-borders --right -7px --bottom -7px --left -7px']
- match_type: 'any'
match:
- window_process: { equals: 'steam' }