2022-03-24 20:32:31 +01:00
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
2022-07-04 15:28:03 +02:00
|
|
|
|
|
2022-07-04 16:00:29 +02:00
|
|
|
|
use crate::{input::ActiveOutput, state::State};
|
2022-07-06 23:36:25 +02:00
|
|
|
|
use regex::RegexSet;
|
2022-03-24 20:32:31 +01:00
|
|
|
|
use smithay::{
|
|
|
|
|
|
desktop::{Space, Window},
|
2022-08-31 13:01:23 +02:00
|
|
|
|
input::Seat,
|
2022-03-24 20:32:31 +01:00
|
|
|
|
wayland::{
|
2022-08-31 13:01:23 +02:00
|
|
|
|
compositor::with_states, output::Output, shell::xdg::XdgToplevelSurfaceRoleAttributes,
|
2022-03-24 20:32:31 +01:00
|
|
|
|
},
|
|
|
|
|
|
};
|
2022-03-30 16:27:39 +02:00
|
|
|
|
use std::sync::Mutex;
|
2022-03-24 20:32:31 +01:00
|
|
|
|
|
|
|
|
|
|
pub mod floating;
|
|
|
|
|
|
pub mod tiling;
|
|
|
|
|
|
|
2022-03-29 14:41:09 +02:00
|
|
|
|
#[derive(Debug, serde::Deserialize, Clone, Copy, PartialEq, Eq, Hash)]
|
|
|
|
|
|
pub enum Orientation {
|
|
|
|
|
|
Horizontal,
|
|
|
|
|
|
Vertical,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-06 23:36:25 +02:00
|
|
|
|
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"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.*$",
|
|
|
|
|
|
]).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"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".*",
|
|
|
|
|
|
]).unwrap();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-04 15:28:03 +02:00
|
|
|
|
pub fn should_be_floating(window: &Window) -> bool {
|
|
|
|
|
|
let surface = window.toplevel().wl_surface();
|
|
|
|
|
|
with_states(surface, |states| {
|
|
|
|
|
|
let attrs = states
|
|
|
|
|
|
.data_map
|
|
|
|
|
|
.get::<Mutex<XdgToplevelSurfaceRoleAttributes>>()
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
.lock()
|
|
|
|
|
|
.unwrap();
|
2022-03-24 20:32:31 +01:00
|
|
|
|
|
2022-07-04 15:28:03 +02:00
|
|
|
|
// simple heuristic taken from
|
|
|
|
|
|
// sway/desktop/xdg_shell.c:188 @ 0ee54a52
|
|
|
|
|
|
if attrs.parent.is_some()
|
2022-07-04 16:00:29 +02:00
|
|
|
|
|| (attrs.min_size.w != 0 && attrs.min_size.h != 0 && attrs.min_size == attrs.max_size)
|
2022-07-04 15:28:03 +02:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2022-03-30 16:27:39 +02:00
|
|
|
|
|
2022-07-04 15:28:03 +02:00
|
|
|
|
// else take a look at our exceptions
|
2022-07-06 23:36:25 +02:00
|
|
|
|
let appid_matches = EXCEPTIONS_APPID.matches(attrs.app_id.as_deref().unwrap_or(""));
|
|
|
|
|
|
let title_matches = EXCEPTIONS_TITLE.matches(attrs.app_id.as_deref().unwrap_or(""));
|
|
|
|
|
|
for idx in appid_matches.into_iter() {
|
|
|
|
|
|
if title_matches.matched(idx) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2022-07-04 15:28:03 +02:00
|
|
|
|
}
|
2022-07-06 23:36:25 +02:00
|
|
|
|
|
|
|
|
|
|
false
|
2022-07-04 15:28:03 +02:00
|
|
|
|
})
|
2022-03-24 20:32:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-04 15:28:03 +02:00
|
|
|
|
fn output_from_seat(seat: Option<&Seat<State>>, space: &Space) -> Option<Output> {
|
2022-03-31 13:44:16 +02:00
|
|
|
|
seat.and_then(|seat| {
|
|
|
|
|
|
seat.user_data()
|
|
|
|
|
|
.get::<ActiveOutput>()
|
|
|
|
|
|
.map(|active| active.0.borrow().clone())
|
|
|
|
|
|
.or_else(|| {
|
|
|
|
|
|
seat.get_pointer()
|
|
|
|
|
|
.map(|ptr| space.output_under(ptr.current_location()).next().unwrap())
|
|
|
|
|
|
.cloned()
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
2022-04-05 16:35:58 +02:00
|
|
|
|
.or_else(|| space.outputs().next().cloned())
|
2022-03-24 20:32:31 +01:00
|
|
|
|
}
|