Skip to content

Commit

Permalink
shell: Fix windows global geometry to include ssd
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed Dec 5, 2024
1 parent e3b41c5 commit fcd5378
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/shell/element/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl CosmicStack {
if let Some(mut geo) = p.geometry.lock().unwrap().clone() {
geo.loc.y += TAB_HEIGHT;
geo.size.h -= TAB_HEIGHT;
window.set_geometry(geo);
window.set_geometry(geo, TAB_HEIGHT as u32);
}
window.send_configure();
if let Some(idx) = idx {
Expand Down Expand Up @@ -490,7 +490,7 @@ impl CosmicStack {

let win_geo = Rectangle::from_loc_and_size(loc, size);
for window in p.windows.lock().unwrap().iter() {
window.set_geometry(win_geo);
window.set_geometry(win_geo, TAB_HEIGHT as u32);
}

*p.geometry.lock().unwrap() = Some(geo);
Expand Down
22 changes: 19 additions & 3 deletions src/shell/element/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct Minimized(AtomicBool);
struct Sticky(AtomicBool);

#[derive(Default)]
pub struct GlobalGeometry(pub Mutex<Option<Rectangle<i32, Global>>>);
struct GlobalGeometry(Mutex<Option<Rectangle<i32, Global>>>);

pub const SSD_HEIGHT: i32 = 36;
pub const RESIZE_BORDER: i32 = 10;
Expand Down Expand Up @@ -139,14 +139,30 @@ impl CosmicSurface {
}
}

pub fn set_geometry(&self, geo: Rectangle<i32, Global>) {
pub fn global_geometry(&self) -> Option<Rectangle<i32, Global>> {
*self
.0
.user_data()
.get_or_insert_threadsafe(GlobalGeometry::default)
.0
.lock()
.unwrap() = Some(geo);
.unwrap()
}

pub fn set_geometry(&self, geo: Rectangle<i32, Global>, ssd_height: u32) {
{
let mut geo = geo;
geo.size.h += ssd_height as i32;
geo.loc.y -= ssd_height as i32;

*self
.0
.user_data()
.get_or_insert_threadsafe(GlobalGeometry::default)
.0
.lock()
.unwrap() = Some(geo);
}
match self.0.underlying_surface() {
WindowSurface::Wayland(toplevel) => {
toplevel.with_pending_state(|state| state.size = Some(geo.size.as_logical()))
Expand Down
13 changes: 4 additions & 9 deletions src/shell/element/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,11 @@ impl CosmicWindow {

pub fn set_geometry(&self, geo: Rectangle<i32, Global>) {
self.0.with_program(|p| {
let loc = (
geo.loc.x,
geo.loc.y + if p.has_ssd(true) { SSD_HEIGHT } else { 0 },
);
let size = (
geo.size.w,
std::cmp::max(geo.size.h - if p.has_ssd(true) { SSD_HEIGHT } else { 0 }, 0),
);
let ssd_height = if p.has_ssd(true) { SSD_HEIGHT } else { 0 };
let loc = (geo.loc.x, geo.loc.y + ssd_height);
let size = (geo.size.w, std::cmp::max(geo.size.h - ssd_height, 0));
p.window
.set_geometry(Rectangle::from_loc_and_size(loc, size));
.set_geometry(Rectangle::from_loc_and_size(loc, size), ssd_height as u32);
});
}

Expand Down
8 changes: 4 additions & 4 deletions src/shell/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ impl Workspace {
} else {
None
};
fullscreen.surface.set_geometry(geo);
fullscreen.surface.set_geometry(geo, 0);
fullscreen.surface.send_configure();
}

Expand Down Expand Up @@ -835,7 +835,7 @@ impl Workspace {

window.set_fullscreen(true);
let geo = self.output.geometry();
let original_geometry = window.geometry().as_global();
let original_geometry = window.global_geometry().unwrap_or_default();
let signal = if let Some(surface) = window.wl_surface() {
let signal = Arc::new(AtomicBool::new(false));
add_blocker(
Expand All @@ -848,7 +848,7 @@ impl Workspace {
} else {
None
};
window.set_geometry(geo);
window.set_geometry(geo, 0);
window.send_configure();

self.fullscreen = Some(FullscreenSurface {
Expand Down Expand Up @@ -878,7 +878,7 @@ impl Workspace {
.filter(|f| &f.surface == window && f.ended_at.is_none())
{
window.set_fullscreen(false);
window.set_geometry(f.original_geometry);
window.set_geometry(f.original_geometry, 0);

self.floating_layer.refresh();
self.tiling_layer.recalculate();
Expand Down
10 changes: 2 additions & 8 deletions src/wayland/handlers/toplevel_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use smithay::utils::{user_data::UserDataMap, Rectangle};

use crate::{
shell::{element::surface::GlobalGeometry, CosmicSurface},
shell::CosmicSurface,
state::State,
utils::prelude::Global,
wayland::protocols::toplevel_info::{
Expand Down Expand Up @@ -52,13 +52,7 @@ impl Window for CosmicSurface {
}

fn global_geometry(&self) -> Option<Rectangle<i32, Global>> {
self.user_data()
.get_or_insert(GlobalGeometry::default)
.0
.lock()
.unwrap()
.clone()
.filter(|_| !self.is_minimized())
CosmicSurface::global_geometry(self)
}

fn user_data(&self) -> &UserDataMap {
Expand Down

0 comments on commit fcd5378

Please sign in to comment.