cosmic-comp/src/shell/layout/mod.rs
Yureka 9b78a2d780 refactor(shell/element): refactor how decorations height is accessed
This fixes several things:
- The xwayland code previously incorrectly used the SSD_HEIGHT (for Windows) even when the X11 surface was in a stack
- The SSD_HEIGHT was defined in surface.rs, even though rendering serverside decorations is done in the window/stack

Rename (min|max)_size to (min|max)_size_without_ssd in CosmicSurface and make it act accordingly
Add a new (min|max)_size() in CosmicWindow and CosmicStack, which takes the surface's (min|max)_size and adds the decorations.
Change all callers to use (min|max)_size() from the window or stack respectively, except is_dialog() where it does not matter.
2024-12-28 15:32:03 +01:00

103 lines
2.9 KiB
Rust

// SPDX-License-Identifier: GPL-3.0-only
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;
pub fn is_dialog(window: &CosmicSurface) -> bool {
// Check "window type"
match window.0.underlying_surface() {
WindowSurface::Wayland(toplevel) => {
if with_states(toplevel.wl_surface(), |states| {
let attrs = states
.data_map
.get::<XdgToplevelSurfaceData>()
.unwrap()
.lock()
.unwrap();
attrs.parent.is_some()
}) {
return true;
}
}
WindowSurface::X11(surface) => {
if surface.is_override_redirect()
|| surface.is_popup()
|| !matches!(
surface.window_type(),
None | Some(WmWindowType::Normal) | Some(WmWindowType::Utility)
)
{
return true;
}
}
};
// Check if sizing suggest dialog
let max_size = window.max_size_without_ssd();
let min_size = window.min_size_without_ssd();
if min_size.is_some() && min_size == max_size {
return true;
}
false
}
#[derive(Debug, Clone, Default)]
pub struct TilingExceptions {
app_ids: RegexSet,
titles: RegexSet,
}
impl TilingExceptions {
pub fn new<'a, I>(exceptions_config: I) -> Self
where
I: Iterator<Item = &'a ApplicationException>,
{
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(),
}
}
}
pub fn has_floating_exception(exceptions: &TilingExceptions, window: &CosmicSurface) -> bool {
// else take a look at our exceptions
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;
}
}
false
}