fix: schedule pending resizes with bounded deadlines (#42)
Co-authored-by: Samuel Onoja <[email protected]>
This commit is contained in:
1 parent
216289d66c
commit
e980bb2e43
5 files changed
+268
-14
No files matched your search
@@ -257,7 +257,7 @@ impl ClientGeometry {
|
||||
}
|
||||
|
||||
self.last_configured_size = Some(size);
|
||||
self.waiting_since = Some(now);
|
||||
self.waiting_since.get_or_insert(now);
|
||||
true
|
||||
}
|
||||
|
||||
@@ -276,6 +276,11 @@ impl ClientGeometry {
|
||||
self.waiting_since.is_some()
|
||||
}
|
||||
|
||||
/// The hard bound for the current uninterrupted client-buffer wait.
|
||||
pub fn commit_deadline(&self) -> Option<Duration> {
|
||||
self.waiting_since.map(|started| started + CLIENT_COMMIT_TIMEOUT)
|
||||
}
|
||||
|
||||
pub fn timed_out(&self, now: Duration) -> bool {
|
||||
self.waiting_since
|
||||
.is_some_and(|started| now.saturating_sub(started) >= CLIENT_COMMIT_TIMEOUT)
|
||||
@@ -545,6 +550,29 @@ fn finite_or(value: f64, fallback: f64) -> f64 {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn replacing_size_requests_does_not_extend_a_stalled_client_wait() {
|
||||
let mut client = ClientGeometry::default();
|
||||
for width in 1..=50 {
|
||||
assert!(client.request_size(
|
||||
ClientSize { width, height: 100 },
|
||||
Duration::from_millis((width as u64 - 1) * 10)
|
||||
));
|
||||
}
|
||||
assert_eq!(client.commit_deadline(), Some(Duration::from_millis(500)));
|
||||
assert!(!client.commit(ClientSize { width: 49, height: 100 }));
|
||||
assert!(client.expire_wait(Duration::from_millis(499)).is_none());
|
||||
assert_eq!(
|
||||
client.expire_wait(Duration::from_millis(500)),
|
||||
Some(ClientSize { width: 50, height: 100 })
|
||||
);
|
||||
assert_eq!(client.commit_deadline(), None);
|
||||
assert!(client.request_size(ClientSize { width: 51, height: 100 }, Duration::from_millis(600)));
|
||||
assert_eq!(client.commit_deadline(), Some(Duration::from_millis(1100)));
|
||||
assert!(client.commit(ClientSize { width: 51, height: 100 }));
|
||||
assert_eq!(client.commit_deadline(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returning_fullscreen_window_does_not_resume_hidden_zoom() {
|
||||
let normal = Rect::new(100.0, 50.0, 900.0, 700.0);
|
||||
|
||||
Reference in new issue
Block a user