Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move tiling exceptions to configuration file #726

Merged
merged 7 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.CosmicSettings.WindowRules/v1/tiling_exception_defaults"

all: extract-vendor
cargo build $(ARGS)
Expand All @@ -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"
Expand Down
49 changes: 49 additions & 0 deletions data/tiling-exceptions.ron
Original file line number Diff line number Diff line change
@@ -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: [".*"]),

]
42 changes: 41 additions & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use crate::{
},
};
use cosmic_config::{ConfigGet, CosmicConfigEntry};
use cosmic_settings_config::{shortcuts, Shortcuts};
use cosmic_settings_config::window_rules::ApplicationException;
use cosmic_settings_config::{shortcuts, window_rules, Shortcuts};
use serde::{Deserialize, Serialize};
use smithay::wayland::xdg_activation::XdgActivationState;
pub use smithay::{
Expand Down Expand Up @@ -47,11 +48,14 @@ 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,
/// Key bindings from `com.system76.CosmicSettings.Shortcuts`
pub shortcuts: Shortcuts,
// Tiling exceptions from `com.system76.CosmicSettings.WindowRules`
pub tiling_exceptions: Vec<ApplicationException>,
/// System actions from `com.system76.CosmicSettings.Shortcuts`
pub system_actions: BTreeMap<shortcuts::action::System, String>,
}
Expand Down Expand Up @@ -243,13 +247,49 @@ impl Config {
),
};

let window_rules_context =
window_rules::context().expect("Failed to load window rules config");
let tiling_exceptions = window_rules::tiling_exceptions(&window_rules_context);

match cosmic_config::calloop::ConfigWatchSource::new(&window_rules_context) {
Ok(source) => {
if let Err(err) = loop_handle.insert_source(source, |(config, keys), (), state| {
for key in keys {
match key.as_str() {
"tiling_exception_defaults" | "tiling_exception_custom" => {
let new_exceptions = window_rules::tiling_exceptions(&config);
state.common.config.tiling_exceptions = new_exceptions;
state
.common
.shell
.write()
.unwrap()
.update_tiling_exceptions(&state.common.config.tiling_exceptions);
}
_ => (),
}
}
}) {
warn!(
?err,
"Failed to watch com.system76.CosmicSettings.WindowRules config"
);
}
}
Err(err) => warn!(
?err,
"failed to create config watch source for com.system76.CosmicSettings.WindowRules"
),
};

Config {
dynamic_conf: Self::load_dynamic(xdg.as_ref()),
cosmic_conf: cosmic_comp_config,
cosmic_helper: config,
settings_context,
shortcuts,
system_actions,
tiling_exceptions,
}
}

Expand Down
116 changes: 38 additions & 78 deletions src/shell/layout/mod.rs
Original file line number Diff line number Diff line change
@@ -1,91 +1,19 @@
// SPDX-License-Identifier: GPL-3.0-only

use cosmic_settings_config::shortcuts::action::Orientation;
use regex::RegexSet;
use cosmic_settings_config::{shortcuts::action::Orientation, window_rules::ApplicationException};
use regex::{Regex, RegexSet};
use smithay::{
desktop::WindowSurface,
wayland::{compositor::with_states, shell::xdg::XdgToplevelSurfaceData},
xwayland::xwm::WmWindowType,
};
use tracing::warn;

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() {
Expand Down Expand Up @@ -126,10 +54,42 @@ pub fn is_dialog(window: &CosmicSurface) -> bool {
false
}

pub fn has_floating_exception(window: &CosmicSurface) -> bool {
#[derive(Debug, Clone, Default)]
pub struct TilingExceptions {
app_ids: RegexSet,
titles: RegexSet,
}

impl TilingExceptions {
pub fn new(exceptions_config: &Vec<ApplicationException>) -> Self {
Tebro marked this conversation as resolved.
Show resolved Hide resolved
let mut app_ids = Vec::new();
let mut titles = Vec::new();

for exception in exceptions_config {
if let Err(e) = Regex::new(&exception.appid) {
warn!("Invalid regex for appid: {}, {}", exception.appid, e);
continue;
}
if let Err(e) = Regex::new(&exception.title) {
warn!("Invalid regex for title: {}, {}", exception.appid, e);
continue;
}

app_ids.push(exception.appid.clone());
titles.push(exception.title.clone());
}

Self {
app_ids: RegexSet::new(app_ids).unwrap(),
titles: RegexSet::new(titles).unwrap(),
Tebro marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

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;
Expand Down
13 changes: 11 additions & 2 deletions src/shell/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use calloop::LoopHandle;
use grabs::SeatMoveGrabState;
use indexmap::IndexMap;
use layout::TilingExceptions;
use std::{
collections::HashMap,
sync::atomic::Ordering,
Expand All @@ -15,7 +16,7 @@ use cosmic_comp_config::{
use cosmic_protocols::workspace::v1::server::zcosmic_workspace_handle_v1::{
State as WState, TilingState,
};
use cosmic_settings_config::shortcuts;
use cosmic_settings_config::{shortcuts, window_rules::ApplicationException};
use cosmic_settings_config::shortcuts::action::{Direction, FocusDirection, ResizeDirection};
use keyframe::{ease, functions::EaseInOutCubic};
use smithay::{
Expand Down Expand Up @@ -250,6 +251,7 @@ pub struct Shell {
Output,
)>,
resize_indicator: Option<ResizeIndicator>,
tiling_exceptions: TilingExceptions,

#[cfg(feature = "debug")]
pub debug_active: bool,
Expand Down Expand Up @@ -1218,6 +1220,8 @@ impl Shell {
pub fn new(config: &Config) -> Self {
let theme = cosmic::theme::system_preference();

let tiling_exceptions = layout::TilingExceptions::new(&config.tiling_exceptions);
Tebro marked this conversation as resolved.
Show resolved Hide resolved

Shell {
workspaces: Workspaces::new(config, theme.clone()),
seats: Seats::new(),
Expand All @@ -1235,6 +1239,7 @@ impl Shell {
resize_mode: ResizeMode::None,
resize_state: None,
resize_indicator: None,
tiling_exceptions,

#[cfg(feature = "debug")]
debug_active: false,
Expand Down Expand Up @@ -1934,7 +1939,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 {
Expand Down Expand Up @@ -3365,6 +3370,10 @@ impl Shell {
&self.theme
}

pub fn update_tiling_exceptions(&mut self, exceptions: &Vec<ApplicationException>) {
Tebro marked this conversation as resolved.
Show resolved Hide resolved
self.tiling_exceptions = layout::TilingExceptions::new(exceptions);
}

pub fn take_presentation_feedback(
&self,
output: &Output,
Expand Down
Loading