From e8947b8742c3d37cc1c2bd72eee6973e49d42faf Mon Sep 17 00:00:00 2001 From: Richard Weber Date: Wed, 14 Aug 2024 21:56:20 +0300 Subject: [PATCH] Move tiling exceptions to configuration file --- Makefile | 2 + cosmic-comp-config/src/lib.rs | 8 +++ data/tiling-exceptions.ron | 49 ++++++++++++++++ src/config/mod.rs | 1 + src/shell/layout/mod.rs | 106 ++++++++++------------------------ src/shell/mod.rs | 5 +- 6 files changed, 94 insertions(+), 77 deletions(-) create mode 100644 data/tiling-exceptions.ron diff --git a/Makefile b/Makefile index 00a4713f..48d6c778 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,7 @@ endif TARGET_BIN="$(DESTDIR)$(bindir)/$(BINARY)" KEYBINDINGS_CONF="$(DESTDIR)$(sharedir)/cosmic/com.system76.CosmicSettings.Shortcuts/v1/defaults" +TILING_EXCEPTIONS_CONF="$(DESTDIR)$(sharedir)/cosmic/com.system76.CosmicComp/v1/tiling_exceptions" all: extract-vendor cargo build $(ARGS) @@ -49,6 +50,7 @@ endif install: install -Dm0755 "$(CARGO_TARGET_DIR)/$(TARGET)/$(BINARY)" "$(TARGET_BIN)" install -Dm0644 "data/keybindings.ron" "$(KEYBINDINGS_CONF)" + install -Dm0644 "data/tiling-exceptions.ron" "$(TILING_EXCEPTIONS_CONF)" install-bare-session: install install -Dm0644 "data/cosmic.desktop" "$(DESTDIR)$(sharedir)/wayland-sessions/cosmic.desktop" diff --git a/cosmic-comp-config/src/lib.rs b/cosmic-comp-config/src/lib.rs index 5a656e52..85e34ce4 100644 --- a/cosmic-comp-config/src/lib.rs +++ b/cosmic-comp-config/src/lib.rs @@ -15,6 +15,7 @@ pub struct CosmicCompConfig { pub input_touchpad: input::InputConfig, pub input_devices: HashMap, pub xkb_config: XkbConfig, + pub tiling_exceptions: Vec, /// Autotiling enabled pub autotile: bool, /// Determines the behavior of the autotile variable @@ -33,6 +34,12 @@ pub struct CosmicCompConfig { pub descale_xwayland: bool, } +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] +pub struct ApplicationExceptions { + pub appid: String, + pub titles: Vec, +} + impl Default for CosmicCompConfig { fn default() -> Self { Self { @@ -53,6 +60,7 @@ impl Default for CosmicCompConfig { }, input_devices: Default::default(), xkb_config: Default::default(), + tiling_exceptions: Default::default(), autotile: Default::default(), autotile_behavior: Default::default(), active_hint: true, diff --git a/data/tiling-exceptions.ron b/data/tiling-exceptions.ron new file mode 100644 index 00000000..97605849 --- /dev/null +++ b/data/tiling-exceptions.ron @@ -0,0 +1,49 @@ +[ + // Any appid title only matching + ( + appid: ".*", + titles: [ + "Discord Updater", + ] + ), + // Empty appid title only matches + ( + appid: "", + titles: [ + "Steam", + "wl-clipboard", + ] + ), + + + // Appid matches + (appid: "Authy Desktop", titles: [".*"]), + (appid: "Com.github.amezin.ddterm", titles: [".*"]), + (appid: "Com.github.donadigo.eddy", titles: [".*"]), + (appid: "Enpass", titles: ["Enpass Assistant"]), + (appid: "Gjs", titles: ["Settings"]), + (appid: "Gnome-initial-setup", titles: [".*"]), + (appid: "Gnome-terminal", titles: ["Preferences - General"]), + (appid: "Guake", titles: [".*"]), + (appid: "Io.elementary.sideload", titles: [".*"]), + (appid: "KotatogramDesktop", titles: ["Media viewer"]), + (appid: "Mozilla VPN", titles: [".*"]), + (appid: "update-manager", titles: ["Software Updater"]), + (appid: "Solaar", titles: [".*"]), + (appid: "Steam", titles: ["^.*?(Guard|Login).*"]), + (appid: "TelegramDesktop", titles: ["Media viewer"]), + (appid: "Zotero", titles: ["Quick Format Citation"]), + (appid: "gjs", titles: [".*"]), + (appid: "gnome-screenshot", titles: [".*"]), + (appid: "ibus-.*", titles: [".*"]), + (appid: "jetbrains-toolbox", titles: [".*"]), + (appid: "jetbrains-webstorm", titles: ["Customize WebStorm", "License Activation", "Welcome to WebStorm"]), + (appid: "krunner", titles: [".*"]), + (appid: "pritunl", titles: [".*"]), + (appid: "re.sonny.Junction", titles: [".*"]), + (appid: "system76-driver", titles: [".*"]), + (appid: "tilda", titles: [".*"]), + (appid: "zoom", titles: [".*"]), + (appid: "^.*?action=join.*$", titles: [".*"]), + +] diff --git a/src/config/mod.rs b/src/config/mod.rs index 7ac15044..b2218a95 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -47,6 +47,7 @@ use cosmic_comp_config::{ pub struct Config { pub dynamic_conf: DynamicConfig, pub cosmic_helper: cosmic_config::Config, + /// cosmic-config comp configuration for `com.system76.CosmicComp` pub cosmic_conf: CosmicCompConfig, /// cosmic-config context for `com.system76.CosmicSettings.Shortcuts` pub settings_context: cosmic_config::Config, diff --git a/src/shell/layout/mod.rs b/src/shell/layout/mod.rs index 17039710..5bfc6c1e 100644 --- a/src/shell/layout/mod.rs +++ b/src/shell/layout/mod.rs @@ -8,84 +8,13 @@ use smithay::{ xwayland::xwm::WmWindowType, }; +use crate::config::Config; + use super::CosmicSurface; pub mod floating; pub mod tiling; -lazy_static::lazy_static! { - static ref EXCEPTIONS_APPID: RegexSet = RegexSet::new(&[ - r"Authy Desktop", - r"Com.github.amezin.ddterm", - r"Com.github.donadigo.eddy", - r".*", - r"Enpass", - r"Gjs", - r"Gnome-initial-setup", - r"Gnome-terminal", - r"Guake", - r"Io.elementary.sideload", - r"KotatogramDesktop", - r"Mozilla VPN", - r"update-manager", - r"Solaar", - r"Steam", - r"", - r"TelegramDesktop", - r"Zotero", - r"gjs", - r"gnome-screenshot", - r"ibus-.*", - r"jetbrains-toolbox", - r"jetbrains-webstorm", - r"jetbrains-webstorm", - r"jetbrains-webstorm", - r"krunner", - r"pritunl", - r"re.sonny.Junction", - r"system76-driver", - r"tilda", - r"zoom", - r"^.*?action=join.*$", - r"", - ]).unwrap(); - static ref EXCEPTIONS_TITLE: RegexSet = RegexSet::new(&[ - r".*", - r".*", - r".*", - r"Discord Updater", - r"Enpass Assistant", - r"Settings", - r".*", - r"Preferences – General", - r".*", - r".*", - r"Media viewer", - r".*", - r"Software Updater", - r".*", - r"^.*?(Guard|Login).*", - r"Steam", - r"Media viewer", - r"Quick Format Citation", - r".*", - r".*", - r".*", - r".*", - r"Customize WebStorm", - r"License Activation", - r"Welcome to WebStorm", - r".*", - r".*", - r".*", - r".*", - r".*", - r".*", - r".*", - r"wl-clipboard", - ]).unwrap(); -} - pub fn is_dialog(window: &CosmicSurface) -> bool { // Check "window type" match window.0.underlying_surface() { @@ -126,10 +55,35 @@ pub fn is_dialog(window: &CosmicSurface) -> bool { false } -pub fn has_floating_exception(window: &CosmicSurface) -> bool { +#[derive(Debug, Clone)] +pub struct TilingExceptions { + app_ids: RegexSet, + titles: RegexSet, +} + +impl TilingExceptions { + pub fn new(config: &Config) -> Self { + let mut app_ids = Vec::new(); + let mut titles = Vec::new(); + + for app in &config.cosmic_conf.tiling_exceptions { + for title in &app.titles { + app_ids.push(app.appid.clone()); + titles.push(title.clone()); + } + } + + Self { + app_ids: RegexSet::new(app_ids).unwrap(), + titles: RegexSet::new(titles).unwrap(), + } + } +} + +pub fn has_floating_exception(exceptions: &TilingExceptions, window: &CosmicSurface) -> bool { // else take a look at our exceptions - let appid_matches = EXCEPTIONS_APPID.matches(&window.app_id()); - let title_matches = EXCEPTIONS_TITLE.matches(&window.title()); + let appid_matches = exceptions.app_ids.matches(&window.app_id()); + let title_matches = exceptions.titles.matches(&window.title()); for idx in appid_matches.into_iter() { if title_matches.matched(idx) { return true; diff --git a/src/shell/mod.rs b/src/shell/mod.rs index b48b248a..122cbe92 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -1,6 +1,7 @@ use calloop::LoopHandle; use grabs::SeatMoveGrabState; use indexmap::IndexMap; +use layout::TilingExceptions; use std::{ collections::HashMap, sync::atomic::Ordering, @@ -257,6 +258,7 @@ pub struct Shell { Output, )>, resize_indicator: Option, + tiling_exceptions: TilingExceptions, #[cfg(feature = "debug")] pub debug_active: bool, @@ -1250,6 +1252,7 @@ impl Shell { resize_mode: ResizeMode::None, resize_state: None, resize_indicator: None, + tiling_exceptions: layout::TilingExceptions::new(config), #[cfg(feature = "debug")] debug_active: false, @@ -2093,7 +2096,7 @@ impl Shell { && (workspace_output != seat.active_output() || active_handle != workspace.handle); let workspace_handle = workspace.handle; let is_dialog = layout::is_dialog(&window); - let floating_exception = layout::has_floating_exception(&window); + let floating_exception = layout::has_floating_exception(&self.tiling_exceptions, &window); let maybe_focused = workspace.focus_stack.get(&seat).iter().next().cloned(); if let Some(focused) = maybe_focused {