tiling: Better synchronize configures

This commit is contained in:
Victoria Brekenfeld 2023-07-05 23:48:10 +02:00
parent 5fc315c950
commit c145b3c35a
5 changed files with 54 additions and 39 deletions

View file

@ -12,6 +12,8 @@ use anyhow::{Context, Result};
use std::{ffi::OsString, os::unix::prelude::AsRawFd, sync::Arc}; use std::{ffi::OsString, os::unix::prelude::AsRawFd, sync::Arc};
use tracing::{error, info, warn}; use tracing::{error, info, warn};
use crate::wayland::handlers::compositor::client_compositor_state;
pub mod backend; pub mod backend;
pub mod config; pub mod config;
#[cfg(feature = "debug")] #[cfg(feature = "debug")]
@ -66,10 +68,13 @@ fn main() -> Result<()> {
} }
// trigger routines // trigger routines
data.state let clients = data.state.common.shell.update_animations();
.common {
.shell let dh = data.display.handle();
.update_animations(&data.state.common.event_loop_handle); for client in clients.values() {
client_compositor_state(&client).blocker_cleared(&mut data.state, &dh);
}
}
data.state.common.shell.refresh(); data.state.common.shell.refresh();
state::Common::refresh_focus(&mut data.state); state::Common::refresh_focus(&mut data.state);

View file

@ -1,8 +1,4 @@
use crate::{ use crate::shell::element::CosmicSurface;
shell::element::CosmicSurface, state::Data,
wayland::handlers::compositor::client_compositor_state,
};
use calloop::LoopHandle;
use smithay::{ use smithay::{
reexports::wayland_server::{backend::ClientId, Client, Resource}, reexports::wayland_server::{backend::ClientId, Client, Resource},
utils::Serial, utils::Serial,
@ -13,18 +9,25 @@ use smithay::{
}; };
use std::{ use std::{
collections::HashMap, collections::HashMap,
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
time::{Duration, Instant}, time::{Duration, Instant},
}; };
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct TilingBlocker { pub struct TilingBlocker {
pub necessary_acks: Vec<(CosmicSurface, Serial)>, pub necessary_acks: Vec<(CosmicSurface, Serial)>,
ready: Arc<AtomicBool>,
signaled: Arc<AtomicBool>,
start: Instant, start: Instant,
} }
impl Blocker for TilingBlocker { impl Blocker for TilingBlocker {
fn state(&self) -> BlockerState { fn state(&self) -> BlockerState {
if self.is_ready() { self.signaled.store(true, Ordering::SeqCst);
if self.ready.load(Ordering::SeqCst) {
BlockerState::Released BlockerState::Released
} else { } else {
BlockerState::Pending BlockerState::Pending
@ -36,30 +39,31 @@ impl TilingBlocker {
pub fn new(configures: impl IntoIterator<Item = (CosmicSurface, Serial)>) -> Self { pub fn new(configures: impl IntoIterator<Item = (CosmicSurface, Serial)>) -> Self {
TilingBlocker { TilingBlocker {
necessary_acks: configures.into_iter().collect(), necessary_acks: configures.into_iter().collect(),
ready: Arc::new(AtomicBool::new(false)),
signaled: Arc::new(AtomicBool::new(false)),
start: Instant::now(), start: Instant::now(),
} }
} }
pub fn is_ready(&self) -> bool { pub fn is_ready(&self) -> bool {
Instant::now().duration_since(self.start) >= Duration::from_millis(200) Instant::now().duration_since(self.start) >= Duration::from_millis(300)
|| self || self
.necessary_acks .necessary_acks
.iter() .iter()
.all(|(surf, serial)| surf.serial_acked(serial)) .all(|(surf, serial)| surf.serial_acked(serial))
} }
pub fn signal_ready(&self, handle: &LoopHandle<'static, Data>) { pub fn is_signaled(&self) -> bool {
let clients = self self.signaled.load(Ordering::SeqCst)
.necessary_acks }
#[must_use]
pub fn signal_ready(&self) -> HashMap<ClientId, Client> {
self.ready.swap(true, Ordering::SeqCst);
self.necessary_acks
.iter() .iter()
.flat_map(|(surface, _)| surface.wl_surface().and_then(|s| s.client())) .flat_map(|(surface, _)| surface.wl_surface().and_then(|s| s.client()))
.map(|client| (client.id(), client)) .map(|client| (client.id(), client))
.collect::<HashMap<ClientId, Client>>(); .collect::<HashMap<ClientId, Client>>()
handle.insert_idle(move |data| {
let dh = data.display.handle();
for client in clients.values() {
client_compositor_state(&client).blocker_cleared(&mut data.state, &dh);
}
});
} }
} }

View file

@ -22,7 +22,6 @@ use crate::{
}, },
}; };
use calloop::LoopHandle;
use cosmic_time::{Cubic, Ease, Tween}; use cosmic_time::{Cubic, Ease, Tween};
use id_tree::{InsertBehavior, MoveBehavior, Node, NodeId, NodeIdError, RemoveBehavior, Tree}; use id_tree::{InsertBehavior, MoveBehavior, Node, NodeId, NodeIdError, RemoveBehavior, Tree};
use smithay::{ use smithay::{
@ -36,6 +35,7 @@ use smithay::{
desktop::{layer_map_for_output, space::SpaceElement, PopupKind}, desktop::{layer_map_for_output, space::SpaceElement, PopupKind},
input::{pointer::GrabStartData as PointerGrabStartData, Seat}, input::{pointer::GrabStartData as PointerGrabStartData, Seat},
output::Output, output::Output,
reexports::wayland_server::Client,
utils::{IsAlive, Logical, Point, Rectangle, Scale}, utils::{IsAlive, Logical, Point, Rectangle, Scale},
wayland::{compositor::add_blocker, seat::WaylandFocus}, wayland::{compositor::add_blocker, seat::WaylandFocus},
}; };
@ -47,6 +47,7 @@ use std::{
time::{Duration, Instant}, time::{Duration, Instant},
}; };
use tracing::trace; use tracing::trace;
use wayland_backend::server::ClientId;
mod blocker; mod blocker;
mod grabs; mod grabs;
@ -1330,10 +1331,12 @@ impl TilingLayout {
.any(|queue| queue.animation_start.is_some()) .any(|queue| queue.animation_start.is_some())
} }
pub fn update_animation_state(&mut self, handle: &LoopHandle<'static, crate::state::Data>) { pub fn update_animation_state(&mut self) -> HashMap<ClientId, Client> {
let mut clients = HashMap::new();
for blocker in self.pending_blockers.drain(..) { for blocker in self.pending_blockers.drain(..) {
blocker.signal_ready(handle); clients.extend(blocker.signal_ready());
} }
for queue in self.queues.values_mut() { for queue in self.queues.values_mut() {
if let Some(start) = queue.animation_start { if let Some(start) = queue.animation_start {
let duration_since_start = Instant::now().duration_since(start); let duration_since_start = Instant::now().duration_since(start);
@ -1346,19 +1349,19 @@ impl TilingLayout {
continue; continue;
} }
} }
if let Some((_, blocker)) = queue.trees.get(1) { if let Some((_, _, blocker)) = queue.trees.get(1) {
if blocker if let Some(blocker) = blocker {
.as_ref() if blocker.is_ready() && blocker.is_signaled() {
.map(TilingBlocker::is_ready) clients.extend(blocker.signal_ready());
.unwrap_or(true) queue.animation_start = Some(Instant::now());
{
queue.animation_start = Some(Instant::now());
if let Some(blocker) = blocker.as_ref() {
blocker.signal_ready(handle)
} }
} else {
queue.animation_start = Some(Instant::now());
} }
} }
} }
clients
} }
pub fn resize_request( pub fn resize_request(

View file

@ -7,6 +7,7 @@ use std::{
time::Instant, time::Instant,
}; };
use tracing::warn; use tracing::warn;
use wayland_backend::server::ClientId;
use cosmic_protocols::workspace::v1::server::zcosmic_workspace_handle_v1::State as WState; use cosmic_protocols::workspace::v1::server::zcosmic_workspace_handle_v1::State as WState;
use smithay::{ use smithay::{
@ -18,7 +19,7 @@ use smithay::{
Seat, Seat,
}, },
output::Output, output::Output,
reexports::wayland_server::{protocol::wl_surface::WlSurface, DisplayHandle}, reexports::wayland_server::{protocol::wl_surface::WlSurface, Client, DisplayHandle},
utils::{Logical, Point, Rectangle, Serial, SERIAL_COUNTER}, utils::{Logical, Point, Rectangle, Serial, SERIAL_COUNTER},
wayland::{ wayland::{
compositor::with_states, compositor::with_states,
@ -1134,10 +1135,12 @@ impl Shell {
.any(|workspace| workspace.animations_going()) .any(|workspace| workspace.animations_going())
} }
pub fn update_animations(&mut self, handle: &LoopHandle<'static, crate::state::Data>) { pub fn update_animations(&mut self) -> HashMap<ClientId, Client> {
let mut clients = HashMap::new();
for workspace in self.workspaces.spaces_mut() { for workspace in self.workspaces.spaces_mut() {
workspace.update_animations(handle) clients.extend(workspace.update_animations());
} }
clients
} }
pub fn set_overview_mode(&mut self, enabled: Option<KeyModifiers>) { pub fn set_overview_mode(&mut self, enabled: Option<KeyModifiers>) {

View file

@ -38,7 +38,7 @@ use smithay::{
desktop::{layer_map_for_output, space::SpaceElement}, desktop::{layer_map_for_output, space::SpaceElement},
input::{pointer::GrabStartData as PointerGrabStartData, Seat}, input::{pointer::GrabStartData as PointerGrabStartData, Seat},
output::Output, output::Output,
reexports::wayland_server::protocol::wl_surface::WlSurface, reexports::wayland_server::{protocol::wl_surface::WlSurface, Client},
utils::{Buffer as BufferCoords, IsAlive, Logical, Physical, Point, Rectangle, Scale, Size}, utils::{Buffer as BufferCoords, IsAlive, Logical, Physical, Point, Rectangle, Scale, Size},
wayland::seat::WaylandFocus, wayland::seat::WaylandFocus,
xwayland::X11Surface, xwayland::X11Surface,
@ -103,8 +103,8 @@ impl Workspace {
self.tiling_layer.animations_going() self.tiling_layer.animations_going()
} }
pub fn update_animations(&mut self, handle: &LoopHandle<'static, crate::state::Data>) { pub fn update_animations(&mut self) -> HashMap<ClientId, Client> {
self.tiling_layer.update_animation_state(handle) self.tiling_layer.update_animation_state()
} }
pub fn commit(&mut self, surface: &WlSurface) { pub fn commit(&mut self, surface: &WlSurface) {