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

Fix overlap #1026

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
13 changes: 13 additions & 0 deletions src/wayland/handlers/overlap_notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ impl OverlapNotifyHandler for State {
let shell = self.common.shell.read().unwrap();
shell.outputs().cloned().collect::<Vec<_>>().into_iter()
}

fn active_workspaces(
&self,
) -> impl Iterator<Item = crate::wayland::protocols::workspace::WorkspaceHandle> {
let shell = self.common.shell.read().unwrap();
shell
.workspaces
.sets
.iter()
.map(|(_, set)| set.workspaces[set.active].handle)
.collect::<Vec<_>>()
.into_iter()
}
}

delegate_overlap_notify!(State);
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
32 changes: 28 additions & 4 deletions src/wayland/protocols/overlap_notify.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: GPL-3.0-only

use std::{collections::HashMap, sync::Mutex};
use std::{
collections::{HashMap, HashSet},
sync::Mutex,
};

use cosmic_protocols::{
overlap_notify::v1::server::{
Expand Down Expand Up @@ -32,8 +35,11 @@ use wayland_backend::server::{GlobalId, ObjectId};

use crate::utils::prelude::{RectExt, RectGlobalExt, RectLocalExt};

use super::toplevel_info::{
ToplevelHandleState, ToplevelInfoGlobalData, ToplevelInfoHandler, ToplevelState, Window,
use super::{
toplevel_info::{
ToplevelHandleState, ToplevelInfoGlobalData, ToplevelInfoHandler, ToplevelState, Window,
},
workspace::WorkspaceHandle,
};

#[derive(Debug)]
Expand Down Expand Up @@ -82,8 +88,10 @@ impl OverlapNotifyState {
+ 'static,
W: Window + 'static,
{
let active_workspaces: Vec<_> = state.active_workspaces().collect();
for output in state.outputs() {
let map = layer_map_for_output(&output);

for layer_surface in map.layers() {
if let Some(data) = layer_surface
.user_data()
Expand All @@ -100,7 +108,22 @@ impl OverlapNotifyState {
.as_local()
.to_global(&output);

for window in state.toplevel_info_state().registered_toplevels() {
for window in
state
.toplevel_info_state()
.registered_toplevels()
.filter(|w| {
let state = w
.user_data()
.get::<ToplevelState>()
.unwrap()
.lock()
.unwrap();
active_workspaces.iter().any(|active_workspace| {
state.in_workspace(&active_workspace)
})
})
{
if let Some(window_geo) = window.global_geometry() {
if let Some(intersection) = layer_geo.intersection(window_geo) {
// relative to layer location
Expand Down Expand Up @@ -146,6 +169,7 @@ pub trait OverlapNotifyHandler: ToplevelInfoHandler {
fn overlap_notify_state(&mut self) -> &mut OverlapNotifyState;
fn layer_surface_from_resource(&self, resource: ZwlrLayerSurfaceV1) -> Option<LayerSurface>;
fn outputs(&self) -> impl Iterator<Item = Output>;
fn active_workspaces(&self) -> impl Iterator<Item = (WorkspaceHandle)>;
}

pub struct OverlapNotifyGlobalData {
Expand Down
4 changes: 4 additions & 0 deletions src/wayland/protocols/toplevel_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ impl ToplevelStateInner {
pub fn foreign_handle(&self) -> Option<&ForeignToplevelHandle> {
self.foreign_handle.as_ref()
}

pub fn in_workspace(&self, handle: &WorkspaceHandle) -> bool {
self.workspaces.contains(handle)
}
}

pub struct ToplevelHandleStateInner<W: Window> {
Expand Down
Loading