Split get resize data from update

This commit is contained in:
Ivan Molodetskikh
2024-05-11 08:26:49 +04:00
parent 9dfa121b8e
commit 34bcc6ea93
4 changed files with 34 additions and 19 deletions
+3 -1
View File
@@ -244,7 +244,9 @@ impl LayoutElement for TestWindow {
fn cancel_interactive_resize(&mut self) {} fn cancel_interactive_resize(&mut self) {}
fn interactive_resize_data(&mut self, _serial: Serial) -> Option<InteractiveResizeData> { fn update_interactive_resize(&mut self, _serial: Serial) {}
fn interactive_resize_data(&self) -> Option<InteractiveResizeData> {
None None
} }
} }
+5 -2
View File
@@ -176,7 +176,8 @@ pub trait LayoutElement {
fn set_interactive_resize(&mut self, data: Option<InteractiveResizeData>); fn set_interactive_resize(&mut self, data: Option<InteractiveResizeData>);
fn cancel_interactive_resize(&mut self); fn cancel_interactive_resize(&mut self);
fn interactive_resize_data(&mut self, serial: Serial) -> Option<InteractiveResizeData>; fn update_interactive_resize(&mut self, serial: Serial);
fn interactive_resize_data(&self) -> Option<InteractiveResizeData>;
} }
#[derive(Debug)] #[derive(Debug)]
@@ -2209,7 +2210,9 @@ mod tests {
fn cancel_interactive_resize(&mut self) {} fn cancel_interactive_resize(&mut self) {}
fn interactive_resize_data(&mut self, _serial: Serial) -> Option<InteractiveResizeData> { fn update_interactive_resize(&mut self, _serial: Serial) {}
fn interactive_resize_data(&self) -> Option<InteractiveResizeData> {
None None
} }
} }
+6 -4
View File
@@ -1189,13 +1189,15 @@ impl<W: LayoutElement> Workspace<W> {
let tile = &mut col.tiles[tile_idx]; let tile = &mut col.tiles[tile_idx];
let window = tile.window_mut(); let window = tile.window_mut();
let resize = serial.and_then(|serial| window.interactive_resize_data(serial)); let resize = window.interactive_resize_data();
if let Some(serial) = serial {
window.update_interactive_resize(serial);
}
// If this was the last resize commit, this function will now return None. This way we // If this was the last resize commit, this function will now return None. This way we
// can animate the window into view after the last resize commit. // can animate the window into view after the last resize commit.
let resize_still_ongoing = serial let resize_still_ongoing = window.interactive_resize_data().is_some();
.and_then(|serial| window.interactive_resize_data(serial))
.is_some();
if let Some(resize) = resize { if let Some(resize) = resize {
// If this is an interactive resize commit of an active window, then we need to // If this is an interactive resize commit of an active window, then we need to
+17 -9
View File
@@ -77,6 +77,16 @@ enum InteractiveResize {
}, },
} }
impl InteractiveResize {
fn data(&self) -> InteractiveResizeData {
match self {
InteractiveResize::Ongoing(data) => *data,
InteractiveResize::WaitingForLastConfigure(data) => *data,
InteractiveResize::WaitingForLastCommit { data, .. } => *data,
}
}
}
impl Mapped { impl Mapped {
pub fn new(window: Window, rules: ResolvedWindowRules, hook: HookId) -> Self { pub fn new(window: Window, rules: ResolvedWindowRules, hook: HookId) -> Self {
Self { Self {
@@ -520,19 +530,17 @@ impl LayoutElement for Mapped {
self.interactive_resize = None; self.interactive_resize = None;
} }
fn interactive_resize_data(&mut self, commit_serial: Serial) -> Option<InteractiveResizeData> { fn update_interactive_resize(&mut self, commit_serial: Serial) {
let resize = self.interactive_resize.as_ref()?; if let Some(InteractiveResize::WaitingForLastCommit { serial, .. }) =
match resize { &self.interactive_resize
InteractiveResize::Ongoing(data) | InteractiveResize::WaitingForLastConfigure(data) => { {
Some(*data)
}
InteractiveResize::WaitingForLastCommit { data, serial } => {
let rv = Some(*data);
if commit_serial.is_no_older_than(serial) { if commit_serial.is_no_older_than(serial) {
self.interactive_resize = None; self.interactive_resize = None;
} }
rv
} }
} }
fn interactive_resize_data(&self) -> Option<InteractiveResizeData> {
Some(self.interactive_resize.as_ref()?.data())
} }
} }