Skip to content

Commit 8834505

Browse files
committed
WIP Update smithay with layer shell updates
1 parent 7c9ab48 commit 8834505

File tree

4 files changed

+47
-40
lines changed

4 files changed

+47
-40
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,5 @@ cosmic-protocols = { git = "https://github.com/pop-os//cosmic-protocols", branch
147147
cosmic-client-toolkit = { git = "https://github.com/pop-os//cosmic-protocols", branch = "main" }
148148

149149
[patch.crates-io]
150-
smithay = { git = "https://github.com/smithay/smithay.git", rev = "eb45814" }
150+
# smithay = { git = "https://github.com/smithay/smithay.git", rev = "eb45814" }
151+
smithay = { git = "https://github.com/ids1024/smithay", branch = "layer-shell-arrange" }

src/shell/element/surface.rs

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ use smithay::{
4343
wayland::{
4444
compositor::{with_states, with_surface_tree_downward, SurfaceData, TraversalAction},
4545
seat::WaylandFocus,
46-
shell::xdg::{SurfaceCachedState, ToplevelSurface, XdgToplevelSurfaceData},
46+
shell::xdg::{
47+
SurfaceCachedState, ToplevelCachedState, ToplevelSurface, XdgToplevelSurfaceData,
48+
},
4749
},
4850
xwayland::{xwm::X11Relatable, X11Surface},
4951
};
@@ -216,7 +218,7 @@ impl CosmicSurface {
216218
pub fn is_activated(&self, pending: bool) -> bool {
217219
match self.0.underlying_surface() {
218220
WindowSurface::Wayland(toplevel) => with_toplevel_state(toplevel, pending, |state| {
219-
state.states.contains(ToplevelState::Activated)
221+
state.is_some_and(|state| state.states.contains(ToplevelState::Activated))
220222
}),
221223
WindowSurface::X11(surface) => surface.is_activated(),
222224
}
@@ -248,9 +250,11 @@ impl CosmicSurface {
248250
});
249251

250252
let xdg_state = with_toplevel_state(toplevel, pending, |state| {
251-
state
252-
.decoration_mode
253-
.map(|mode| mode == DecorationMode::ClientSide)
253+
state.and_then(|state| {
254+
state
255+
.decoration_mode
256+
.map(|mode| mode == DecorationMode::ClientSide)
257+
})
254258
});
255259

256260
kde_state.or(xdg_state).unwrap_or(true)
@@ -263,8 +267,9 @@ impl CosmicSurface {
263267
match self.0.underlying_surface() {
264268
WindowSurface::Wayland(toplevel) => {
265269
if enable {
266-
let previous_decoration_state =
267-
toplevel.current_state().decoration_mode.clone();
270+
let previous_decoration_state = toplevel.with_committed_state(|state| {
271+
state.map_or_else(Default::default, |state| state.decoration_mode.clone())
272+
});
268273
if PreferredDecorationMode::is_unset(&self.0) {
269274
PreferredDecorationMode::update(&self.0, previous_decoration_state);
270275
}
@@ -300,7 +305,7 @@ impl CosmicSurface {
300305
match self.0.underlying_surface() {
301306
WindowSurface::Wayland(toplevel) => {
302307
Some(with_toplevel_state(toplevel, pending, |state| {
303-
state.states.contains(ToplevelState::Resizing)
308+
state.is_some_and(|state| state.states.contains(ToplevelState::Resizing))
304309
}))
305310
}
306311
WindowSurface::X11(_surface) => None,
@@ -324,7 +329,7 @@ impl CosmicSurface {
324329
match self.0.underlying_surface() {
325330
WindowSurface::Wayland(toplevel) => {
326331
Some(with_toplevel_state(toplevel, pending, |state| {
327-
state.states.contains(ToplevelState::TiledLeft)
332+
state.is_some_and(|state| state.states.contains(ToplevelState::TiledLeft))
328333
}))
329334
}
330335
WindowSurface::X11(_surface) => None,
@@ -353,7 +358,7 @@ impl CosmicSurface {
353358
pub fn is_fullscreen(&self, pending: bool) -> bool {
354359
match self.0.underlying_surface() {
355360
WindowSurface::Wayland(toplevel) => with_toplevel_state(toplevel, pending, |state| {
356-
state.states.contains(ToplevelState::Fullscreen)
361+
state.is_some_and(|state| state.states.contains(ToplevelState::Fullscreen))
357362
}),
358363
WindowSurface::X11(surface) => surface.is_fullscreen(),
359364
}
@@ -377,7 +382,7 @@ impl CosmicSurface {
377382
pub fn is_maximized(&self, pending: bool) -> bool {
378383
match self.0.underlying_surface() {
379384
WindowSurface::Wayland(toplevel) => with_toplevel_state(toplevel, pending, |state| {
380-
state.states.contains(ToplevelState::Maximized)
385+
state.is_some_and(|state| state.states.contains(ToplevelState::Maximized))
381386
}),
382387
WindowSurface::X11(surface) => surface.is_maximized(),
383388
}
@@ -493,10 +498,9 @@ impl CosmicSurface {
493498
.lock()
494499
.unwrap();
495500
attrs
496-
.configure_serial
501+
.last_acked
497502
.as_ref()
498-
.map(|s| s >= serial)
499-
.unwrap_or(false)
503+
.is_some_and(|configure| configure.serial >= *serial)
500504
}),
501505
WindowSurface::X11(_surface) => true,
502506
}
@@ -505,17 +509,12 @@ impl CosmicSurface {
505509
pub fn serial_past(&self, serial: &Serial) -> bool {
506510
match self.0.underlying_surface() {
507511
WindowSurface::Wayland(toplevel) => with_states(toplevel.wl_surface(), |states| {
508-
let attrs = states
509-
.data_map
510-
.get::<XdgToplevelSurfaceData>()
511-
.unwrap()
512-
.lock()
513-
.unwrap();
514-
attrs
515-
.current_serial
512+
let mut guard = states.cached_state.get::<ToplevelCachedState>();
513+
guard
514+
.current()
515+
.last_acked
516516
.as_ref()
517-
.map(|s| s >= serial)
518-
.unwrap_or(false)
517+
.is_some_and(|configure| configure.serial >= *serial)
519518
}),
520519
WindowSurface::X11(_surface) => true,
521520
}
@@ -533,12 +532,18 @@ impl CosmicSurface {
533532
.unwrap();
534533

535534
let current_server = attributes.current_server_state();
536-
if attributes.current.size == current_server.size {
535+
let mut guard = states.cached_state.get::<ToplevelCachedState>();
536+
if guard
537+
.current()
538+
.last_acked
539+
.as_ref()
540+
.is_some_and(|configure| configure.state.size == current_server.size)
541+
{
537542
// The window had committed for our previous size change, so we can
538543
// change the size again.
539544
trace!(
540545
"current size matches server size: {:?}",
541-
attributes.current.size
546+
guard.current().last_acked.as_ref().unwrap().state.size
542547
);
543548
true
544549
} else {
@@ -931,15 +936,14 @@ where
931936
}
932937
}
933938

934-
fn with_toplevel_state<T, F: FnOnce(&smithay::wayland::shell::xdg::ToplevelState) -> T>(
939+
fn with_toplevel_state<T, F: FnOnce(Option<&smithay::wayland::shell::xdg::ToplevelState>) -> T>(
935940
toplevel: &ToplevelSurface,
936941
pending: bool,
937942
cb: F,
938943
) -> T {
939944
if pending {
940-
toplevel.with_pending_state(|pending| cb(pending))
945+
toplevel.with_pending_state(|pending| cb(Some(pending)))
941946
} else {
942-
let current = toplevel.current_state();
943-
cb(&current)
947+
toplevel.with_committed_state(|committed| cb(committed))
944948
}
945949
}

src/wayland/handlers/xdg_shell/popup.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use smithay::{
1515
wayland::{
1616
compositor::{get_role, with_states},
1717
seat::WaylandFocus,
18-
shell::xdg::{PopupSurface, ToplevelSurface, XdgPopupSurfaceData, XDG_POPUP_ROLE},
18+
shell::xdg::{
19+
PopupCachedState, PopupSurface, ToplevelSurface, XdgPopupSurfaceData, XDG_POPUP_ROLE,
20+
},
1921
},
2022
};
2123
use tracing::warn;
@@ -88,13 +90,13 @@ pub fn update_reactive_popups<'a>(
8890
match popup {
8991
PopupKind::Xdg(surface) => {
9092
let positioner = with_states(&surface.wl_surface(), |states| {
91-
let attributes = states
92-
.data_map
93-
.get::<XdgPopupSurfaceData>()
94-
.unwrap()
95-
.lock()
96-
.unwrap();
97-
attributes.current.positioner.clone()
93+
let mut guard = states.cached_state.get::<PopupCachedState>();
94+
guard
95+
.current()
96+
.last_acked
97+
.map_or_else(Default::default, |configure| {
98+
configure.state.positioner.clone()
99+
})
98100
});
99101
if positioner.reactive {
100102
let anchor_point = loc + positioner.get_anchor_point().as_global();

0 commit comments

Comments
 (0)