shell: Allow querying current vs pending state

This commit is contained in:
Victoria Brekenfeld 2023-06-09 16:26:13 +02:00
parent 8f20cf5ece
commit be1b4ceb10
8 changed files with 111 additions and 69 deletions

View file

@ -247,14 +247,14 @@ impl CosmicMapped {
}
}
pub fn is_resizing(&self) -> Option<bool> {
pub fn is_resizing(&self, pending: bool) -> Option<bool> {
let window = match &self.element {
CosmicMappedInternal::Stack(s) => s.active(),
CosmicMappedInternal::Window(w) => w.surface(),
_ => unreachable!(),
};
window.is_resizing()
window.is_resizing(pending)
}
pub fn set_tiled(&self, tiled: bool) {
@ -268,14 +268,14 @@ impl CosmicMapped {
}
}
pub fn is_tiled(&self) -> Option<bool> {
pub fn is_tiled(&self, pending: bool) -> Option<bool> {
let window = match &self.element {
CosmicMappedInternal::Stack(s) => s.active(),
CosmicMappedInternal::Window(w) => w.surface(),
_ => unreachable!(),
};
window.is_tiled()
window.is_tiled(pending)
}
pub fn set_fullscreen(&self, fullscreen: bool) {
@ -290,14 +290,14 @@ impl CosmicMapped {
}
}
pub fn is_fullscreen(&self) -> bool {
pub fn is_fullscreen(&self, pending: bool) -> bool {
let window = match &self.element {
CosmicMappedInternal::Stack(s) => s.active(),
CosmicMappedInternal::Window(w) => w.surface(),
_ => unreachable!(),
};
window.is_fullscreen()
window.is_fullscreen(pending)
}
pub fn set_maximized(&self, maximized: bool) {
@ -312,14 +312,14 @@ impl CosmicMapped {
}
}
pub fn is_maximized(&self) -> bool {
pub fn is_maximized(&self, pending: bool) -> bool {
let window = match &self.element {
CosmicMappedInternal::Stack(s) => s.active(),
CosmicMappedInternal::Window(w) => w.surface(),
_ => unreachable!(),
};
window.is_maximized()
window.is_maximized(pending)
}
pub fn set_activated(&self, activated: bool) {
@ -334,14 +334,14 @@ impl CosmicMapped {
}
}
pub fn is_activated(&self) -> bool {
pub fn is_activated(&self, pending: bool) -> bool {
let window = match &self.element {
CosmicMappedInternal::Stack(s) => s.active(),
CosmicMappedInternal::Window(w) => w.surface(),
_ => unreachable!(),
};
window.is_activated()
window.is_activated(pending)
}
pub fn set_geometry(&self, geo: Rectangle<i32, Logical>) {

View file

@ -129,13 +129,21 @@ impl CosmicSurface {
}
}
pub fn is_activated(&self) -> bool {
pub fn is_activated(&self, pending: bool) -> bool {
match self {
CosmicSurface::Wayland(window) => window
.toplevel()
.current_state()
.states
.contains(ToplevelState::Activated),
CosmicSurface::Wayland(window) => {
if pending {
window.toplevel().with_pending_state(|pending| {
pending.states.contains(ToplevelState::Activated)
})
} else {
window
.toplevel()
.current_state()
.states
.contains(ToplevelState::Activated)
}
}
CosmicSurface::X11(surface) => surface.is_activated(),
_ => unreachable!(),
}
@ -157,29 +165,46 @@ impl CosmicSurface {
}
}
pub fn is_decorated(&self) -> bool {
pub fn is_decorated(&self, pending: bool) -> bool {
match self {
CosmicSurface::Wayland(window) => window
.toplevel()
.current_state()
.decoration_mode
.map(|mode| mode == DecorationMode::ClientSide)
.unwrap_or(true),
CosmicSurface::Wayland(window) => {
if pending {
window.toplevel().with_pending_state(|pending| {
pending
.decoration_mode
.map(|mode| mode == DecorationMode::ClientSide)
.unwrap_or(true)
})
} else {
window
.toplevel()
.current_state()
.decoration_mode
.map(|mode| mode == DecorationMode::ClientSide)
.unwrap_or(true)
}
}
CosmicSurface::X11(surface) => surface.is_decorated(),
_ => unreachable!(),
}
}
pub fn is_resizing(&self) -> Option<bool> {
pub fn is_resizing(&self, pending: bool) -> Option<bool> {
match self {
CosmicSurface::Wayland(window) => {
let xdg = window.toplevel();
Some(
xdg.current_state().states.contains(ToplevelState::Resizing)
|| xdg.with_pending_state(|states| {
states.states.contains(ToplevelState::Resizing)
}),
)
if pending {
Some(window.toplevel().with_pending_state(|pending| {
pending.states.contains(ToplevelState::Resizing)
}))
} else {
Some(
window
.toplevel()
.current_state()
.states
.contains(ToplevelState::Resizing),
)
}
}
_ => None,
}
@ -198,15 +223,23 @@ impl CosmicSurface {
}
}
pub fn is_tiled(&self) -> Option<bool> {
pub fn is_tiled(&self, pending: bool) -> Option<bool> {
match self {
CosmicSurface::Wayland(window) => Some(
window
.toplevel()
.current_state()
.states
.contains(ToplevelState::TiledLeft),
),
CosmicSurface::Wayland(window) => {
if pending {
Some(window.toplevel().with_pending_state(|pending| {
pending.states.contains(ToplevelState::TiledLeft)
}))
} else {
Some(
window
.toplevel()
.current_state()
.states
.contains(ToplevelState::TiledLeft),
)
}
}
_ => None,
}
}
@ -230,16 +263,20 @@ impl CosmicSurface {
}
}
pub fn is_fullscreen(&self) -> bool {
pub fn is_fullscreen(&self, pending: bool) -> bool {
match self {
CosmicSurface::Wayland(window) => {
let xdg = window.toplevel();
xdg.current_state()
.states
.contains(ToplevelState::Fullscreen)
|| xdg.with_pending_state(|state| {
state.states.contains(ToplevelState::Fullscreen)
if pending {
window.toplevel().with_pending_state(|pending| {
pending.states.contains(ToplevelState::Fullscreen)
})
} else {
window
.toplevel()
.current_state()
.states
.contains(ToplevelState::Fullscreen)
}
}
CosmicSurface::X11(surface) => surface.is_fullscreen(),
_ => unreachable!(),
@ -262,15 +299,20 @@ impl CosmicSurface {
}
}
pub fn is_maximized(&self) -> bool {
pub fn is_maximized(&self, pending: bool) -> bool {
match self {
CosmicSurface::Wayland(window) => {
let xdg = window.toplevel();
xdg.current_state()
.states
.contains(ToplevelState::Maximized)
|| xdg
.with_pending_state(|state| state.states.contains(ToplevelState::Maximized))
if pending {
window.toplevel().with_pending_state(|pending| {
pending.states.contains(ToplevelState::Maximized)
})
} else {
window
.toplevel()
.current_state()
.states
.contains(ToplevelState::Maximized)
}
}
CosmicSurface::X11(surface) => surface.is_maximized(),
_ => unreachable!(),
@ -311,7 +353,7 @@ impl CosmicSurface {
_ => unreachable!(),
}
.map(|size| {
if self.is_decorated() {
if self.is_decorated(false) {
size + (0, SSD_HEIGHT).into()
} else {
size
@ -337,7 +379,7 @@ impl CosmicSurface {
_ => unreachable!(),
}
.map(|size| {
if self.is_decorated() {
if self.is_decorated(false) {
size + (0, SSD_HEIGHT).into()
} else {
size

View file

@ -107,7 +107,7 @@ impl CosmicWindowInternal {
}
pub fn has_ssd(&self) -> bool {
!self.window.is_decorated()
!self.window.is_decorated(false)
}
}
@ -259,7 +259,7 @@ impl Program for CosmicWindowInternal {
}
fn background_color(&self) -> Color {
if self.window.is_activated() {
if self.window.is_activated(false) {
Color {
r: 0.1176,
g: 0.1176,
@ -281,7 +281,7 @@ impl Program for CosmicWindowInternal {
pixels: &mut tiny_skia::PixmapMut<'_>,
damage: &[Rectangle<i32, BufferCoords>],
) {
if !self.window.is_activated() {
if !self.window.is_activated(false) {
let mask = self.mask.lock().unwrap();
let mut paint = tiny_skia::Paint::default();
paint.set_color_rgba8(0, 0, 0, 102);