Skip to content

Commit 75661c6

Browse files
committed
tiling: Refactor blocker code
1 parent 560d234 commit 75661c6

File tree

2 files changed

+25
-41
lines changed

2 files changed

+25
-41
lines changed

src/shell/layout/tiling/blocker.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,18 @@ use smithay::{
99
};
1010
use std::{
1111
collections::HashMap,
12-
sync::{
13-
atomic::{AtomicBool, Ordering},
14-
Arc,
15-
},
1612
time::{Duration, Instant},
1713
};
1814

1915
#[derive(Debug, Clone)]
2016
pub struct TilingBlocker {
2117
pub necessary_acks: Vec<(CosmicSurface, Serial)>,
22-
ready: Arc<AtomicBool>,
23-
signaled: Arc<AtomicBool>,
2418
start: Instant,
2519
}
2620

2721
impl Blocker for TilingBlocker {
2822
fn state(&self) -> BlockerState {
29-
self.signaled.store(true, Ordering::SeqCst);
30-
if self.ready.load(Ordering::SeqCst) {
23+
if self.is_ready() {
3124
BlockerState::Released
3225
} else {
3326
BlockerState::Pending
@@ -39,8 +32,6 @@ impl TilingBlocker {
3932
pub fn new(configures: impl IntoIterator<Item = (CosmicSurface, Serial)>) -> Self {
4033
TilingBlocker {
4134
necessary_acks: configures.into_iter().collect(),
42-
ready: Arc::new(AtomicBool::new(false)),
43-
signaled: Arc::new(AtomicBool::new(false)),
4435
start: Instant::now(),
4536
}
4637
}
@@ -53,14 +44,15 @@ impl TilingBlocker {
5344
.all(|(surf, serial)| !surf.alive() || surf.serial_acked(serial))
5445
}
5546

56-
pub fn is_signaled(&self) -> bool {
57-
self.signaled.load(Ordering::SeqCst)
58-
|| !self.necessary_acks.iter().any(|(surf, _)| surf.alive())
47+
pub fn is_processed(&self) -> bool {
48+
Instant::now().duration_since(self.start) >= Duration::from_millis(500)
49+
|| self
50+
.necessary_acks
51+
.iter()
52+
.all(|(surf, serial)| !surf.alive() || surf.serial_past(serial))
5953
}
6054

61-
#[must_use]
62-
pub fn signal_ready(&self) -> HashMap<ClientId, Client> {
63-
self.ready.swap(true, Ordering::SeqCst);
55+
pub fn clients(&self) -> HashMap<ClientId, Client> {
6456
self.necessary_acks
6557
.iter()
6658
.flat_map(|(surface, _)| surface.wl_surface().and_then(|s| s.client()))

src/shell/layout/tiling/mod.rs

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ impl TreeQueue {
130130
pub struct TilingLayout {
131131
output: Output,
132132
queue: TreeQueue,
133-
pending_blockers: Vec<TilingBlocker>,
134133
placeholder_id: Id,
135134
swapping_stack_surface_id: Id,
136135
last_overview_hover: Option<(Option<Instant>, TargetZone)>,
@@ -353,7 +352,6 @@ impl TilingLayout {
353352
animation_start: None,
354353
},
355354
output: output.clone(),
356-
pending_blockers: Vec::new(),
357355
placeholder_id: Id::new(),
358356
swapping_stack_surface_id: Id::new(),
359357
last_overview_hover: None,
@@ -2345,8 +2343,20 @@ impl TilingLayout {
23452343

23462344
pub fn update_animation_state(&mut self) -> HashMap<ClientId, Client> {
23472345
let mut clients = HashMap::new();
2348-
for blocker in self.pending_blockers.drain(..) {
2349-
clients.extend(blocker.signal_ready());
2346+
let mut ready_trees = 0;
2347+
for (_, _, blocker) in self.queue.trees.iter().skip(1) {
2348+
if let Some(blocker) = blocker.as_ref() {
2349+
if blocker.is_processed() {
2350+
ready_trees += 1;
2351+
}
2352+
if blocker.is_ready() {
2353+
clients.extend(blocker.clients());
2354+
continue;
2355+
}
2356+
break;
2357+
} else {
2358+
ready_trees += 1;
2359+
}
23502360
}
23512361

23522362
if let Some(start) = self.queue.animation_start {
@@ -2361,6 +2371,7 @@ impl TilingLayout {
23612371
{
23622372
let _ = self.queue.animation_start.take();
23632373
let _ = self.queue.trees.pop_front();
2374+
ready_trees -= 1;
23642375
let front = self.queue.trees.front_mut().unwrap();
23652376
if let Some(root_id) = front.0.root_node_id() {
23662377
for node in front
@@ -2383,28 +2394,12 @@ impl TilingLayout {
23832394
}
23842395
}
23852396

2386-
let ready_trees = self
2387-
.queue
2388-
.trees
2389-
.iter()
2390-
.skip(1)
2391-
.take_while(|(_, _, blocker)| {
2392-
blocker
2393-
.as_ref()
2394-
.map(|blocker| blocker.is_ready() && blocker.is_signaled())
2395-
.unwrap_or(true)
2396-
})
2397-
.count();
2398-
23992397
// merge
24002398
let other_duration = if ready_trees > 1 {
24012399
self.queue
24022400
.trees
24032401
.drain(1..ready_trees)
2404-
.fold(None, |res, (_, duration, blocker)| {
2405-
if let Some(blocker) = blocker {
2406-
clients.extend(blocker.signal_ready());
2407-
}
2402+
.fold(None, |res, (_, duration, _)| {
24082403
Some(
24092404
res.map(|old_duration: Duration| old_duration.max(duration))
24102405
.unwrap_or(duration),
@@ -2416,13 +2411,10 @@ impl TilingLayout {
24162411

24172412
// start
24182413
if ready_trees > 0 {
2419-
let (_, duration, blocker) = self.queue.trees.get_mut(1).unwrap();
2414+
let (_, duration, _) = self.queue.trees.get_mut(1).unwrap();
24202415
*duration = other_duration
24212416
.map(|other| other.max(*duration))
24222417
.unwrap_or(*duration);
2423-
if let Some(blocker) = blocker {
2424-
clients.extend(blocker.signal_ready());
2425-
}
24262418
self.queue.animation_start = Some(Instant::now());
24272419
}
24282420

0 commit comments

Comments
 (0)