diff --git a/komorebi-client/src/lib.rs b/komorebi-client/src/lib.rs index 746464c3..2041b538 100644 --- a/komorebi-client/src/lib.rs +++ b/komorebi-client/src/lib.rs @@ -12,6 +12,8 @@ pub use komorebi::core::MonocleFocusBehaviour; pub use komorebi::core::MoveBehaviour; pub use komorebi::core::OperationBehaviour; pub use komorebi::core::OperationDirection; +pub use komorebi::core::PanDirection; +pub use komorebi::core::PanGesture; pub use komorebi::core::Rect; pub use komorebi::core::Sizing; pub use komorebi::core::SocketMessage; diff --git a/komorebi/src/core/mod.rs b/komorebi/src/core/mod.rs index 471c13a6..ebbd2384 100644 --- a/komorebi/src/core/mod.rs +++ b/komorebi/src/core/mod.rs @@ -28,6 +28,8 @@ pub use komorebi_layouts::MAX_RATIO; pub use komorebi_layouts::MAX_RATIOS; pub use komorebi_layouts::MIN_RATIO; pub use komorebi_layouts::OperationDirection; +pub use komorebi_layouts::PanDirection; +pub use komorebi_layouts::PanGesture; pub use komorebi_layouts::Rect; pub use komorebi_layouts::ScrollingLayoutOptions; pub use komorebi_layouts::Sizing; @@ -336,6 +338,8 @@ pub enum SocketMessage { ScrollingLayoutFullWidth, CenterFocus, Expand, + Pan(PanDirection), + PanGesture(PanGesture), Consume(OperationDirection), Expel, ToggleColumnStack, @@ -501,6 +505,7 @@ mod tests { SocketMessage::ScrollingLayoutFullWidth, SocketMessage::CenterFocus, SocketMessage::Expand, + SocketMessage::Pan(PanDirection::Left), SocketMessage::Consume(OperationDirection::Left), SocketMessage::Expel, SocketMessage::ToggleColumnStack, diff --git a/komorebi/src/lib.rs b/komorebi/src/lib.rs index 0f13217f..9e929682 100644 --- a/komorebi/src/lib.rs +++ b/komorebi/src/lib.rs @@ -65,6 +65,7 @@ pub mod macos_api; pub mod monitor; pub mod monitor_reconciliator; pub mod notification_center_listener; +pub mod pan; pub mod process_command; pub mod process_event; pub mod reaper; diff --git a/komorebi/src/pan.rs b/komorebi/src/pan.rs new file mode 100644 index 00000000..858ab601 --- /dev/null +++ b/komorebi/src/pan.rs @@ -0,0 +1,508 @@ +//! Moving the strip of the Scrolling layout across the screen without changing which window has +//! focus: by a step, and with the fingers on a touchpad. +//! +//! A gesture is a begin, any number of moves, and an end, or a cancel. The strip follows the +//! fingers for as long as they are down, and the workspace is laid out a step at a time as the +//! windows of a drag are, and when the fingers lift it comes to rest with a column against an +//! edge of the screen. Where the strip rests is laid out the way every layout is, so that with +//! animations on the windows glide there from where the fingers left them. + +use crate::core::PanDirection; +use crate::core::PanGesture; +use crate::window::Snapping; +use crate::window::steps_begin; +use crate::window::steps_end; +use crate::window_manager::WindowManager; +use crate::workspace::Workspace; +use color_eyre::eyre; +use komorebi_layouts::scrolling::model::ScrollingSpace; +use komorebi_layouts::scrolling::model::SwipeTracker; +use std::time::Instant; + +/// How far the fingers go across a touchpad, in centimetres, to move the strip as far as the +/// width of the screen +const CM_PER_SCREEN: f64 = 10.0; + +/// A gesture that is going on +#[derive(Debug)] +pub struct Pan { + monitor_idx: usize, + workspace_idx: usize, + /// What the strip was before the gesture, for putting it back if it is given up + saved: ScrollingSpace, + /// How fast the fingers are going + tracker: SwipeTracker, + /// When it began, and the time of the touchpad at the first move, for the log + began: Instant, + first_t: Option, +} + +/// How far the strip is moved on a screen that is `screen_width` pixels wide by fingers that +/// move `cm` centimetres, in pixels, to the right if it is positive +fn distance_on_screen(cm: f64, screen_width: i32) -> f64 { + cm * f64::from(screen_width) / CM_PER_SCREEN +} + +impl WindowManager { + /// Move the view of the focused workspace one step, a column, to the left or the right, and + /// let it come to rest with a column against an edge of the screen. Focus goes to the nearest + /// column in view if the focused one is not. Nothing happens in a layout that is not Scrolling. + #[tracing::instrument(skip(self))] + pub fn pan(&mut self, direction: PanDirection) -> eyre::Result<()> { + let workspace = self.focused_workspace_mut()?; + + if workspace.begin_scrolling_pan().is_none() { + return Ok(()); + } + + let step = workspace + .scrolling_pan_step() + .and_then(|step| u32::try_from(step).ok()) + .unwrap_or_default(); + + workspace.pan_scrolling(direction.strip_offset(step)); + let focus_moved = workspace.end_scrolling_pan(0.0); + + self.update_focused_workspace(focus_moved, focus_moved) + } + + /// What the fingers of a gesture do + pub fn pan_gesture(&mut self, gesture: PanGesture) -> eyre::Result<()> { + match gesture { + PanGesture::Begin => self.pan_begin(), + PanGesture::Move { dx, t, .. } => self.pan_move(dx, t), + PanGesture::End => self.pan_end(), + PanGesture::Cancel => self.pan_cancel(), + } + } + + /// Whether the workspace that a gesture is about is the one that is on show + fn pan_is_on_show(&self, pan: &Pan) -> bool { + self.focused_monitor_idx() == pan.monitor_idx + && self + .focused_workspace_idx() + .is_ok_and(|idx| idx == pan.workspace_idx) + } + + /// The workspace that a gesture is about, which is not the one that is on show if the fingers + /// have been on the touchpad while it was changed + fn pan_workspace_mut(&mut self, pan: &Pan) -> Option<&mut Workspace> { + self.monitors_mut() + .get_mut(pan.monitor_idx)? + .workspaces_mut() + .get_mut(pan.workspace_idx) + } + + fn pan_begin(&mut self) -> eyre::Result<()> { + // a gesture that was not finished is given up, as a new one begins + self.pan_cancel()?; + + let monitor_idx = self.focused_monitor_idx(); + let workspace_idx = self.focused_workspace_idx()?; + + let Some(saved) = self.focused_workspace_mut()?.begin_scrolling_pan() else { + return Ok(()); + }; + + steps_begin(); + + self.pan = Some(Pan { + monitor_idx, + workspace_idx, + saved, + tracker: SwipeTracker::new(), + began: Instant::now(), + first_t: None, + }); + + Ok(()) + } + + fn pan_move(&mut self, dx_cm: f64, t_ms: f64) -> eyre::Result<()> { + let Some(pan) = &self.pan else { + return Ok(()); + }; + + // the workspace that the fingers are on is not the one that is on show any more + if !self.pan_is_on_show(pan) { + return self.pan_cancel(); + } + + let workspace = self.focused_workspace_mut()?; + let Some(width) = workspace.scrolling_view_width() else { + return Ok(()); + }; + + let dx = distance_on_screen(dx_cm, width); + workspace.pan_scrolling(dx); + + if let Some(pan) = self.pan.as_mut() { + pan.tracker.push(t_ms / 1000.0, dx); + + // how far behind the fingers a move is handled is how far the wall clock has got + // ahead of the touchpad's since the first + let first = *pan.first_t.get_or_insert(t_ms); + let fingers = t_ms - first; + let wall = pan.began.elapsed().as_secs_f64() * 1000.0; + tracing::trace!( + "pan: move of {dx:.1} px at {fingers:.0} ms of the fingers, handled at {wall:.0} ms ({:+.0} ms)", + wall - fingers + ); + } + + // the workspace is laid out a step at a time, straight into place + let _snapping = Snapping::pan(); + self.update_focused_workspace(false, false) + } + + fn pan_end(&mut self) -> eyre::Result<()> { + let Some(pan) = self.pan.take() else { + return Ok(()); + }; + + steps_end(); + + let velocity = pan.tracker.velocity(); + let on_show = self.pan_is_on_show(&pan); + let Some(workspace) = self.pan_workspace_mut(&pan) else { + return Ok(()); + }; + + // a workspace that was changed in the middle of the gesture is let come to rest all the + // same, and laid out when it is shown, from where it rests + let focus_moved = workspace.end_scrolling_pan(velocity); + + if !on_show { + return Ok(()); + } + + // what is laid out here is not a step: with animations on the windows glide to where the + // strip rests from where the fingers left them, and without they go straight there + self.update_focused_workspace(focus_moved, focus_moved) + } + + fn pan_cancel(&mut self) -> eyre::Result<()> { + let Some(pan) = self.pan.take() else { + return Ok(()); + }; + + steps_end(); + + let on_show = self.pan_is_on_show(&pan); + let Some(workspace) = self.pan_workspace_mut(&pan) else { + return Ok(()); + }; + + workspace.cancel_scrolling_pan(pan.saved); + + if !on_show { + return Ok(()); + } + + self.update_focused_workspace(false, false) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::WindowManagerEvent; + use crate::container::Container; + use crate::core::DefaultLayout; + use crate::core::Layout; + use crate::core::Rect; + use crate::core::SocketMessage; + use crate::monitor; + use crossbeam_channel::Receiver; + use crossbeam_channel::Sender; + use crossbeam_channel::bounded; + use objc2_core_foundation::CFRunLoop; + use std::path::PathBuf; + use uuid::Uuid; + + /// The socket of a window manager that a test made, which is not left behind + struct Socket(PathBuf); + + impl Drop for Socket { + fn drop(&mut self) { + let _ = std::fs::remove_file(&self.0); + } + } + + const AREA: Rect = Rect { + left: 0, + top: 0, + right: 1200, + bottom: 800, + }; + + /// A window manager with two workspaces on a monitor, the first with a strip of six + /// containers that have no windows, so that nothing is laid out on a screen + fn window_manager() -> (WindowManager, Socket) { + let (_sender, receiver): (Sender, Receiver) = + bounded(1); + let path = PathBuf::from(format!("komorebi-test-{}.sock", Uuid::new_v4())); + let socket = Socket(path.clone()); + + let mut wm = WindowManager::new(&CFRunLoop::main().unwrap(), receiver, Some(path)).unwrap(); + wm.monitors_mut().push_back(monitor::new( + 0, + AREA, + AREA, + "TestMonitor".to_string(), + "TestDeviceID".to_string(), + )); + + let monitor = wm.focused_monitor_mut().unwrap(); + monitor.focus_workspace(1).unwrap(); + monitor.focus_workspace(0).unwrap(); + + let workspace = wm.focused_workspace_mut().unwrap(); + workspace.layout = Layout::Default(DefaultLayout::Scrolling); + for _ in 0..6 { + workspace.add_container_to_back(Container::default()); + } + workspace.focus_container(0); + workspace.layout_scrolling(&AREA, 0); + + (wm, socket) + } + + fn strip_of(wm: &mut WindowManager, workspace_idx: usize) -> Vec { + wm.monitors_mut()[0].workspaces_mut()[workspace_idx] + .layout_scrolling(&AREA, 0) + .iter() + .map(|placement| placement.rect.left) + .collect() + } + + #[test] + fn fingers_on_a_layout_that_is_not_scrolling_move_nothing() { + let (mut wm, _socket) = window_manager(); + wm.focused_workspace_mut().unwrap().layout = Layout::Default(DefaultLayout::BSP); + + for gesture in [ + PanGesture::Begin, + PanGesture::Move { + dx: 1.0, + dy: 0.0, + t: 100.0, + }, + PanGesture::End, + PanGesture::Cancel, + ] { + wm.pan_gesture(gesture).unwrap(); + assert!(wm.pan.is_none(), "{gesture:?}"); + } + + wm.pan(PanDirection::Left).unwrap(); + wm.pan(PanDirection::Right).unwrap(); + } + + #[test] + fn fingers_that_land_on_a_strip_are_a_gesture_until_they_lift() { + let (mut wm, _socket) = window_manager(); + + wm.pan_gesture(PanGesture::Begin).unwrap(); + assert!(wm.pan.is_some()); + + // and it is not about moves that come with no fingers down + wm.pan_gesture(PanGesture::Cancel).unwrap(); + assert!(wm.pan.is_none()); + wm.pan_gesture(PanGesture::Cancel).unwrap(); + wm.pan_gesture(PanGesture::End).unwrap(); + } + + #[test] + fn a_gesture_that_is_given_up_after_the_workspace_changed_puts_its_strip_back() { + let (mut wm, _socket) = window_manager(); + let before = strip_of(&mut wm, 0); + + wm.pan_gesture(PanGesture::Begin).unwrap(); + wm.monitors_mut()[0].workspaces_mut()[0].pan_scrolling(-500.0); + assert_ne!(strip_of(&mut wm, 0), before, "the fingers moved the strip"); + + // the workspace that is on show is another by the time that they give up + wm.focused_monitor_mut() + .unwrap() + .focus_workspace(1) + .unwrap(); + wm.pan_gesture(PanGesture::Cancel).unwrap(); + + assert!(wm.pan.is_none()); + assert_eq!(strip_of(&mut wm, 0), before); + } + + #[test] + fn a_gesture_that_ends_after_the_workspace_changed_lets_its_strip_come_to_rest() { + let (mut wm, _socket) = window_manager(); + + wm.pan_gesture(PanGesture::Begin).unwrap(); + // 150 pixels short of a column, which is not where a strip rests + wm.monitors_mut()[0].workspaces_mut()[0].pan_scrolling(-250.0); + wm.focused_monitor_mut() + .unwrap() + .focus_workspace(1) + .unwrap(); + wm.pan_gesture(PanGesture::End).unwrap(); + + assert!(wm.pan.is_none()); + let rested = strip_of(&mut wm, 0); + assert!( + rested.iter().any(|left| *left == 0 || *left + 400 == 1200), + "a column is against an edge: {rested:?}" + ); + } + + #[test] + fn a_gesture_that_begins_gives_up_the_one_that_was_not_finished() { + let (mut wm, _socket) = window_manager(); + let before = strip_of(&mut wm, 0); + + wm.pan_gesture(PanGesture::Begin).unwrap(); + wm.monitors_mut()[0].workspaces_mut()[0].pan_scrolling(-500.0); + + // the fingers land again on a workspace that has no strip to move + wm.focused_monitor_mut() + .unwrap() + .focus_workspace(1) + .unwrap(); + wm.pan_gesture(PanGesture::Begin).unwrap(); + + assert!( + wm.pan.is_none(), + "there is no strip on the workspace on show" + ); + assert_eq!(strip_of(&mut wm, 0), before, "and the first is given up"); + } + + #[test] + fn fingers_that_go_across_a_touchpad_move_the_strip_across_the_screen() { + assert!((distance_on_screen(10.0, 5000) - 5000.0).abs() < 1e-9); + assert!((distance_on_screen(1.0, 5000) - 500.0).abs() < 1e-9); + assert!((distance_on_screen(-0.5, 1200) + 60.0).abs() < 1e-9); + assert!(distance_on_screen(0.0, 1200).abs() < f64::EPSILON); + } + + /// The moves of a swipe of about two seconds at about 125 times a second, with a time that + /// is a millisecond or two out for each, as a touchpad gives them, the fingers going at + /// `lift` centimetres a second for the last 200 milliseconds and at `earlier` before that + /// (eased in from rest). Each is how far they went since the one before, and when. + fn swipe(earlier: f64, lift: f64) -> Vec<(f64, f64)> { + let mut moves = Vec::new(); + let mut t = 118_000.0; + + for step in 1..=250 { + let jitter = f64::from((step * 37) % 7 - 3) * 0.5; + let next = 118_000.0 + f64::from(step) * 8.0 + jitter; + let dt = (next - t) / 1000.0; + + let elapsed = f64::from(step) * 8.0; + let speed = if elapsed > 1800.0 { + lift + } else { + earlier * (elapsed / 1800.0) + }; + + moves.push((speed * dt, next)); + t = next; + } + + moves + } + + /// How fast the strip is going when the fingers lift, in centimetres of the fingers a + /// second, for these moves on a screen that is 5000 pixels wide + fn lift_speed(moves: &[(f64, f64)]) -> f64 { + let mut tracker = SwipeTracker::new(); + + for (cm, t) in moves { + tracker.push(t / 1000.0, distance_on_screen(*cm, 5000)); + } + + // a centimetre of the fingers is 500 pixels on that screen + tracker.velocity() / 500.0 + } + + #[test] + fn the_speed_that_the_fingers_lift_at_is_what_the_strip_is_let_go_at() { + // fast, with the time of every move a little out + let speed = lift_speed(&swipe(8.0, 16.0)); + assert!((speed - 16.0).abs() < 0.8, "16 cm/s, got {speed:.2}"); + + // a flick + let speed = lift_speed(&swipe(20.0, 33.0)); + assert!((speed - 33.0).abs() < 1.7, "33 cm/s, got {speed:.2}"); + + // one that eased to a stop and lifts almost still + let speed = lift_speed(&swipe(8.0, 0.2)); + assert!(speed < 0.5, "almost still, got {speed:.2}"); + } + + /// The moves of what a gesture stream writes for a swipe, which is what komorebic tells + /// komorebi of them: how far the fingers went, in centimetres, and when + fn moves_of(transcript: &str) -> Vec<(f64, f64)> { + let field = |line: &str, key: &str| -> Option { + line.split_whitespace() + .find_map(|word| word.strip_prefix(key)?.strip_prefix('=')) + .and_then(|value| value.parse().ok()) + }; + + transcript + .lines() + .filter(|line| line.starts_with("move ")) + .filter_map(|line| Some((field(line, "dx")?, field(line, "t")?))) + .collect() + } + + #[test] + fn the_swipes_of_a_stream_lift_at_the_speed_that_they_were_made_to() { + let long = lift_speed(&moves_of(include_str!( + "../../komorebic/fixtures/pan3-long.transcript.txt" + ))); + let flick = lift_speed(&moves_of(include_str!( + "../../komorebic/fixtures/pan3-flick.transcript.txt" + ))); + let slow = lift_speed(&moves_of(include_str!( + "../../komorebic/fixtures/pan3-slow.transcript.txt" + ))); + + // 0.128 cm every 8 ms, and 0.267 every 8 + assert!((long - 16.0).abs() < 0.8, "16 cm/s, got {long:.2}"); + assert!((flick - 33.0).abs() < 1.7, "33 cm/s, got {flick:.2}"); + // slowing from 1.9 cm/s to 0.75 over the last 150 ms, which is what the speed is the + // average of: a nudge, and not a throw + assert!(slow > 1.0 && slow < 2.5, "about 1.6 cm/s, got {slow:.2}"); + assert!(flick > long && long > 5.0 * slow); + } + + #[test] + fn what_has_hardly_moved_is_not_going_anywhere() { + assert!(lift_speed(&[]).abs() < f64::EPSILON); + assert!(lift_speed(&[(1.0, 100.0)]).abs() < f64::EPSILON); + // two moves at the same time have no speed + assert!(lift_speed(&[(1.0, 100.0), (1.0, 100.0)]).abs() < f64::EPSILON); + } + + #[test] + fn a_gesture_goes_over_the_socket_as_it_is() { + for gesture in [ + PanGesture::Begin, + PanGesture::Move { + dx: 0.42, + dy: -0.03, + t: 118_345.0, + }, + PanGesture::End, + PanGesture::Cancel, + ] { + let message = SocketMessage::PanGesture(gesture); + let json = serde_json::to_string(&message).unwrap(); + let SocketMessage::PanGesture(back) = serde_json::from_str(&json).unwrap() else { + panic!("not a gesture: {json}"); + }; + + assert_eq!(back, gesture, "{json}"); + } + } +} diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 3583a604..3f972345 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -1508,6 +1508,8 @@ impl WindowManager { self.focused_workspace_mut()?.expand_scrolling_column(); self.update_focused_workspace(false, false)?; } + SocketMessage::Pan(direction) => self.pan(direction)?, + SocketMessage::PanGesture(gesture) => self.pan_gesture(gesture)?, SocketMessage::Consume(direction) => { self.focused_workspace_mut()?.consume_scrolling(direction); self.update_focused_workspace(false, false)?; diff --git a/komorebi/src/scrolling.rs b/komorebi/src/scrolling.rs index 5f5b3719..a11ae9c3 100644 --- a/komorebi/src/scrolling.rs +++ b/komorebi/src/scrolling.rs @@ -28,7 +28,9 @@ use crate::workspace::clamp_to_work_area; use color_eyre::eyre; use komorebi_layouts::scrolling; use komorebi_layouts::scrolling::ScrollingPlacement; +use komorebi_layouts::scrolling::model::ColumnWidth; use komorebi_layouts::scrolling::model::Options; +use komorebi_layouts::scrolling::model::ScrollingSpace; use komorebi_layouts::scrolling::model::Viewport; use komorebi_layouts::scrolling::model::Visibility; use komorebi_layouts::scrolling::note_departure; @@ -686,6 +688,82 @@ impl Workspace { } } + /// Start moving the strip across the screen by hand, and give back the strip as it is, for + /// putting it back if the pan is given up. Only the Scrolling layout has a strip to move, and + /// not before a layout has made it. + pub(crate) fn begin_scrolling_pan(&mut self) -> Option> { + if !self.is_scrolling() || self.scrolling.is_none() { + return None; + } + + self.sync_scrolling_containers(); + + let space = self.scrolling.as_mut()?; + let saved = space.clone(); + space.begin_pan(); + + Some(saved) + } + + /// Move the strip by `dx` pixels on the screen, to the right if it is positive. Nothing else + /// changes: not which container has focus, nor the width of any. + pub(crate) fn pan_scrolling(&mut self, dx: f64) { + if let Some(space) = self.scrolling.as_mut() { + space.pan_by(dx); + } + } + + /// Let go of the strip, going at `velocity` pixels a second on the screen, to the right if it + /// is positive, and let it come to rest, which is with a column against an edge of the screen. + /// Focus goes to the nearest column that is fully in view if the focused one is not, and + /// this tells whether it moved. + pub(crate) fn end_scrolling_pan(&mut self, velocity: f64) -> bool { + let Some(space) = self.scrolling.as_mut() else { + return false; + }; + + if space.pan_end(velocity).is_none() { + return false; + } + + let focused = space.active_tile_index(); + let before = self.focused_container_idx(); + + match focused { + Some(idx) if idx != before => { + self.focus_container(idx); + true + } + _ => false, + } + } + + /// Give up a pan: the strip is put back to what it was when it began. + pub(crate) fn cancel_scrolling_pan(&mut self, saved: ScrollingSpace) { + if self.scrolling.is_some() { + self.scrolling = Some(saved); + } + } + + /// How wide the screen is that the strip is moved across, in pixels. + pub(crate) fn scrolling_view_width(&self) -> Option { + self.scrolling.as_ref().map(|space| space.viewport().width) + } + + /// How far one step of a pan goes, if nothing says: a column of the width that a new one is + /// given. + pub(crate) fn scrolling_pan_step(&self) -> Option { + let space = self.scrolling.as_ref()?; + let viewport = f64::from(space.viewport().width); + + let step = match space.options().default_width { + ColumnWidth::Proportion(share) => viewport * share, + ColumnWidth::Fixed(width) => f64::from(width), + }; + + Some(step.round() as i32) + } + /// Centre the focused column on the screen, this once. pub(crate) fn center_scrolling_column(&mut self) { if self.focused_scrolling_column().is_some() @@ -1985,4 +2063,89 @@ mod tests { assert!(workspace.scrolling.is_none()); } + + #[test] + fn panning_moves_the_strip_and_leaves_focus_where_it_is_until_it_is_let_go() { + let mut workspace = workspace(3, 6); + workspace.layout_scrolling(&AREA, 0); + workspace.focus_container(0); + let before = workspace.layout_scrolling(&AREA, 0); + + assert!(workspace.begin_scrolling_pan().is_some()); + workspace.pan_scrolling(-300.0); + let panned = workspace.layout_scrolling(&AREA, 0); + + assert_eq!( + panned[1].rect.left, + before[1].rect.left - 300, + "the strip moved" + ); + assert_eq!(workspace.focused_container_idx(), 0, "and focus did not"); + } + + #[test] + fn a_strip_that_is_let_go_comes_to_rest_and_focus_goes_to_a_column_in_view() { + let mut workspace = workspace(3, 6); + workspace.layout_scrolling(&AREA, 0); + workspace.focus_container(0); + + assert!(workspace.begin_scrolling_pan().is_some()); + // three columns to the left of the screen, which is where the first three are + workspace.pan_scrolling(-1200.0); + assert!(workspace.end_scrolling_pan(0.0), "focus moved"); + + let rested = workspace.layout_scrolling(&AREA, 0); + let focused = workspace.focused_container_idx(); + + assert!(focused >= 3, "to a column that is in view, not {focused}"); + assert_eq!(rested[focused].visibility, Visibility::Visible); + } + + #[test] + fn there_is_no_strip_to_pan_in_another_layout_or_before_there_is_one() { + let mut workspace = workspace(3, 6); + assert!(workspace.begin_scrolling_pan().is_none(), "no layout yet"); + assert!(!workspace.end_scrolling_pan(0.0)); + + workspace.layout_scrolling(&AREA, 0); + workspace.layout = Layout::Default(DefaultLayout::BSP); + assert!(workspace.begin_scrolling_pan().is_none()); + } + + #[test] + fn a_step_of_a_pan_is_a_column_of_the_width_that_a_new_one_has() { + let mut workspace = workspace(3, 6); + assert_eq!(workspace.scrolling_pan_step(), None, "no layout yet"); + + workspace.layout_scrolling(&AREA, 0); + assert_eq!(workspace.scrolling_pan_step(), Some(400)); + + workspace.set_scrolling_columns(4); + workspace.layout_scrolling(&AREA, 0); + assert_eq!(workspace.scrolling_pan_step(), Some(300)); + } + + #[test] + fn a_pan_that_is_given_up_puts_the_strip_back() { + let mut workspace = workspace(3, 6); + workspace.layout_scrolling(&AREA, 0); + workspace.focus_container(1); + let before = workspace.layout_scrolling(&AREA, 0); + + let saved = workspace.begin_scrolling_pan().expect("a strip to pan"); + workspace.pan_scrolling(-500.0); + workspace.cancel_scrolling_pan(saved); + + assert_eq!(workspace.layout_scrolling(&AREA, 0), before); + assert_eq!(workspace.focused_container_idx(), 1); + } + + #[test] + fn the_strip_is_moved_across_a_screen_as_wide_as_the_work_area() { + let mut workspace = workspace(3, 6); + assert_eq!(workspace.scrolling_view_width(), None, "no layout yet"); + + workspace.layout_scrolling(&AREA, 0); + assert_eq!(workspace.scrolling_view_width(), Some(1200)); + } } diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index a16fdbc3..206145d1 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -1219,6 +1219,7 @@ impl StaticConfig { pending_move_op: Arc::new(None), pending_resize_op: Arc::new(None), live_resize: None, + pan: None, already_moved_window_handles: Default::default(), known_window_ids: HashMap::new(), }; diff --git a/komorebi/src/window.rs b/komorebi/src/window.rs index d1229cac..eaafbcfe 100644 --- a/komorebi/src/window.rs +++ b/komorebi/src/window.rs @@ -211,6 +211,14 @@ impl Snapping { Self } + /// For a step of a pan of the strip of the Scrolling layout, in which no window is being + /// dragged, and so every one of them is laid out, straight into place, and left alone only + /// if it is where it was sent last. + pub fn pan() -> Self { + // nought is the id of no window + Self::step(0) + } + /// For the end of a drag that was followed: the windows are a few pixels from where the end of /// the drag puts them, which is not worth animating, and every one of them is sent there. pub fn end() -> Self { @@ -238,6 +246,17 @@ pub fn live_resize_begins(window_id: u32) { DRAG.begin(window_id); } +/// A run of steps that is not the drag of a window begins, as the fingers of a pan land: where +/// windows were sent by the last is not where they are by now. +pub fn steps_begin() { + SENT.lock().clear(); +} + +/// The run of steps is over, and the layout that follows it sends every window where it goes. +pub fn steps_end() { + SENT.lock().clear(); +} + /// The drag is over. pub fn live_resize_ends() { DRAG.end(); diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 187bc35d..d2ffda0d 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -39,6 +39,7 @@ use crate::current_space_id; use crate::lockable_sequence::Lockable; use crate::macos_api::MacosApi; use crate::monitor::Monitor; +use crate::pan::Pan; use crate::ring::Ring; use crate::skylight::BatchedUpdates; use crate::static_config::StaticConfig; @@ -137,6 +138,8 @@ pub struct WindowManager { pub pending_resize_op: Arc)>>, /// The workspace as it was when an edge that the windows next to it follow was taken hold of pub live_resize: Option, + /// The fingers of a gesture that pans the strip of the Scrolling layout, while they are down + pub(crate) pan: Option, pub already_moved_window_handles: Arc>>, /// Maps each known window id to the (monitor, workspace) index pair managing it pub known_window_ids: HashMap, @@ -222,6 +225,7 @@ impl WindowManager { pending_move_op: Arc::new(None), pending_resize_op: Arc::new(None), live_resize: None, + pan: None, already_moved_window_handles: Default::default(), known_window_ids: Default::default(), }) diff --git a/komorebic/fixtures/gesture-stream.transcript.txt b/komorebic/fixtures/gesture-stream.transcript.txt new file mode 100644 index 00000000..faf68116 --- /dev/null +++ b/komorebic/fixtures/gesture-stream.transcript.txt @@ -0,0 +1,5 @@ +begin fingers=3 x=4.000 y=2.000 w=10.500 h=7.200 t=118337 +move dx=0.420 dy=-0.030 x=4.420 y=1.970 t=118345 +move dx=0.510 dy=-0.020 x=4.930 y=1.950 t=118353 +move dx=0.470 dy=0.000 x=5.400 y=1.950 t=118361 +end x=5.400 y=1.950 t=118369 diff --git a/komorebic/fixtures/pan3-flick.transcript.txt b/komorebic/fixtures/pan3-flick.transcript.txt new file mode 100644 index 00000000..906d331a --- /dev/null +++ b/komorebic/fixtures/pan3-flick.transcript.txt @@ -0,0 +1,18 @@ +begin fingers=3 x=5.000 y=3.000 w=11.700 h=7.500 t=100048 +move dx=0.267 dy=0.000 x=5.267 y=3.000 t=100088 +move dx=0.267 dy=0.000 x=5.533 y=3.000 t=100096 +move dx=0.267 dy=0.000 x=5.800 y=3.000 t=100104 +move dx=0.267 dy=0.000 x=6.067 y=3.000 t=100112 +move dx=0.267 dy=0.000 x=6.333 y=3.000 t=100120 +move dx=0.267 dy=0.000 x=6.600 y=3.000 t=100128 +swipe swipe3right +move dx=0.267 dy=0.000 x=6.867 y=3.000 t=100136 +move dx=0.267 dy=0.000 x=7.133 y=3.000 t=100144 +move dx=0.267 dy=0.000 x=7.400 y=3.000 t=100152 +move dx=0.267 dy=0.000 x=7.667 y=3.000 t=100160 +move dx=0.267 dy=0.000 x=7.933 y=3.000 t=100168 +move dx=0.267 dy=0.000 x=8.200 y=3.000 t=100176 +move dx=0.267 dy=0.000 x=8.467 y=3.000 t=100184 +move dx=0.267 dy=0.000 x=8.733 y=3.000 t=100192 +move dx=0.267 dy=0.000 x=9.000 y=3.000 t=100200 +end x=9.000 y=3.000 t=100208 diff --git a/komorebic/fixtures/pan3-long.transcript.txt b/komorebic/fixtures/pan3-long.transcript.txt new file mode 100644 index 00000000..eb2a7b0c --- /dev/null +++ b/komorebic/fixtures/pan3-long.transcript.txt @@ -0,0 +1,218 @@ +begin fingers=3 x=5.000 y=3.000 w=11.700 h=7.500 t=100048 +move dx=0.007 dy=0.000 x=5.015 y=3.001 t=100110 +move dx=0.008 dy=0.000 x=5.023 y=3.001 t=100119 +move dx=0.010 dy=0.001 x=5.033 y=3.002 t=100129 +move dx=0.012 dy=0.001 x=5.045 y=3.003 t=100136 +move dx=0.014 dy=0.001 x=5.059 y=3.004 t=100142 +move dx=0.015 dy=0.001 x=5.074 y=3.004 t=100153 +move dx=0.017 dy=0.001 x=5.091 y=3.005 t=100160 +move dx=0.018 dy=0.001 x=5.109 y=3.007 t=100168 +move dx=0.020 dy=0.001 x=5.129 y=3.008 t=100174 +move dx=0.022 dy=0.001 x=5.151 y=3.009 t=100184 +move dx=0.023 dy=0.001 x=5.174 y=3.010 t=100193 +move dx=0.025 dy=0.001 x=5.199 y=3.012 t=100199 +move dx=0.026 dy=0.002 x=5.225 y=3.013 t=100207 +move dx=0.027 dy=0.002 x=5.252 y=3.015 t=100217 +move dx=0.029 dy=0.002 x=5.281 y=3.017 t=100223 +move dx=0.030 dy=0.002 x=5.311 y=3.019 t=100231 +move dx=0.032 dy=0.002 x=5.343 y=3.021 t=100240 +move dx=0.033 dy=0.002 x=5.376 y=3.023 t=100248 +move dx=0.034 dy=0.002 x=5.410 y=3.025 t=100256 +move dx=0.035 dy=0.002 x=5.446 y=3.027 t=100262 +move dx=0.037 dy=0.002 x=5.482 y=3.029 t=100272 +move dx=0.038 dy=0.002 x=5.520 y=3.031 t=100281 +move dx=0.039 dy=0.002 x=5.559 y=3.034 t=100287 +move dx=0.040 dy=0.002 x=5.599 y=3.036 t=100294 +move dx=0.041 dy=0.002 x=5.640 y=3.038 t=100303 +move dx=0.042 dy=0.003 x=5.682 y=3.041 t=100312 +move dx=0.043 dy=0.003 x=5.726 y=3.044 t=100318 +move dx=0.044 dy=0.003 x=5.770 y=3.046 t=100327 +move dx=0.045 dy=0.003 x=5.815 y=3.049 t=100334 +move dx=0.046 dy=0.003 x=5.861 y=3.052 t=100342 +move dx=0.047 dy=0.003 x=5.909 y=3.055 t=100351 +move dx=0.048 dy=0.003 x=5.956 y=3.057 t=100360 +move dx=0.049 dy=0.003 x=6.005 y=3.060 t=100369 +move dx=0.050 dy=0.003 x=6.055 y=3.063 t=100375 +move dx=0.050 dy=0.003 x=6.105 y=3.066 t=100383 +move dx=0.051 dy=0.003 x=6.156 y=3.069 t=100390 +move dx=0.052 dy=0.003 x=6.208 y=3.072 t=100400 +move dx=0.053 dy=0.003 x=6.261 y=3.076 t=100406 +move dx=0.053 dy=0.003 x=6.314 y=3.079 t=100414 +move dx=0.054 dy=0.003 x=6.368 y=3.082 t=100423 +move dx=0.054 dy=0.003 x=6.422 y=3.085 t=100431 +move dx=0.055 dy=0.003 x=6.477 y=3.089 t=100439 +move dx=0.056 dy=0.003 x=6.533 y=3.092 t=100448 +swipe swipe3right +move dx=0.056 dy=0.003 x=6.589 y=3.095 t=100454 +move dx=0.057 dy=0.003 x=6.646 y=3.099 t=100464 +move dx=0.057 dy=0.003 x=6.703 y=3.102 t=100472 +move dx=0.057 dy=0.003 x=6.760 y=3.106 t=100481 +move dx=0.058 dy=0.003 x=6.818 y=3.109 t=100487 +move dx=0.058 dy=0.003 x=6.876 y=3.113 t=100497 +move dx=0.058 dy=0.004 x=6.934 y=3.116 t=100504 +move dx=0.059 dy=0.004 x=6.993 y=3.120 t=100511 +move dx=0.059 dy=0.004 x=7.052 y=3.123 t=100520 +move dx=0.059 dy=0.004 x=7.111 y=3.127 t=100527 +move dx=0.059 dy=0.004 x=7.171 y=3.130 t=100535 +move dx=0.060 dy=0.004 x=7.230 y=3.134 t=100543 +move dx=0.060 dy=0.004 x=7.290 y=3.137 t=100552 +move dx=0.060 dy=0.004 x=7.350 y=3.141 t=100561 +move dx=0.060 dy=0.004 x=7.410 y=3.145 t=100567 +move dx=0.060 dy=0.004 x=7.470 y=3.148 t=100576 +move dx=0.060 dy=0.004 x=7.530 y=3.152 t=100584 +move dx=0.060 dy=0.004 x=7.590 y=3.155 t=100591 +move dx=0.060 dy=0.004 x=7.650 y=3.159 t=100600 +move dx=0.060 dy=0.004 x=7.710 y=3.163 t=100609 +move dx=0.060 dy=0.004 x=7.770 y=3.166 t=100615 +move dx=0.060 dy=0.004 x=7.829 y=3.170 t=100624 +move dx=0.059 dy=0.004 x=7.889 y=3.173 t=100632 +move dx=0.059 dy=0.004 x=7.948 y=3.177 t=100640 +move dx=0.059 dy=0.004 x=8.007 y=3.180 t=100648 +move dx=0.059 dy=0.004 x=8.066 y=3.184 t=100654 +move dx=0.058 dy=0.004 x=8.124 y=3.187 t=100664 +move dx=0.058 dy=0.003 x=8.182 y=3.191 t=100672 +move dx=0.058 dy=0.003 x=8.240 y=3.194 t=100680 +move dx=0.057 dy=0.003 x=8.297 y=3.198 t=100688 +move dx=0.057 dy=0.003 x=8.354 y=3.201 t=100694 +move dx=0.057 dy=0.003 x=8.411 y=3.205 t=100703 +move dx=0.056 dy=0.003 x=8.467 y=3.208 t=100712 +move dx=0.056 dy=0.003 x=8.523 y=3.211 t=100718 +move dx=0.055 dy=0.003 x=8.578 y=3.215 t=100728 +move dx=0.054 dy=0.003 x=8.632 y=3.218 t=100735 +move dx=0.054 dy=0.003 x=8.686 y=3.221 t=100744 +move dx=0.053 dy=0.003 x=8.739 y=3.224 t=100752 +move dx=0.053 dy=0.003 x=8.792 y=3.228 t=100760 +move dx=0.052 dy=0.003 x=8.844 y=3.231 t=100769 +move dx=0.051 dy=0.003 x=8.895 y=3.234 t=100774 +move dx=0.050 dy=0.003 x=8.945 y=3.237 t=100785 +move dx=0.050 dy=0.003 x=8.995 y=3.240 t=100792 +move dx=0.049 dy=0.003 x=9.044 y=3.243 t=100799 +move dx=0.048 dy=0.003 x=9.091 y=3.245 t=100809 +move dx=0.047 dy=0.003 x=9.139 y=3.248 t=100815 +move dx=0.046 dy=0.003 x=9.185 y=3.251 t=100824 +move dx=0.045 dy=0.003 x=9.230 y=3.254 t=100832 +move dx=0.044 dy=0.003 x=9.274 y=3.256 t=100839 +move dx=0.043 dy=0.003 x=9.318 y=3.259 t=100846 +move dx=0.042 dy=0.003 x=9.360 y=3.262 t=100856 +move dx=0.041 dy=0.002 x=9.401 y=3.264 t=100863 +move dx=0.040 dy=0.002 x=9.441 y=3.266 t=100873 +move dx=0.039 dy=0.002 x=9.480 y=3.269 t=100880 +move dx=0.038 dy=0.002 x=9.518 y=3.271 t=100887 +move dx=0.037 dy=0.002 x=9.554 y=3.273 t=100897 +move dx=0.035 dy=0.002 x=9.590 y=3.275 t=100904 +move dx=0.034 dy=0.002 x=9.624 y=3.277 t=100912 +move dx=0.033 dy=0.002 x=9.657 y=3.279 t=100918 +move dx=0.032 dy=0.002 x=9.689 y=3.281 t=100929 +move dx=0.030 dy=0.002 x=9.719 y=3.283 t=100935 +move dx=0.029 dy=0.002 x=9.748 y=3.285 t=100944 +move dx=0.027 dy=0.002 x=9.775 y=3.287 t=100952 +move dx=0.026 dy=0.002 x=9.801 y=3.288 t=100959 +move dx=0.025 dy=0.001 x=9.826 y=3.290 t=100968 +move dx=0.023 dy=0.001 x=9.849 y=3.291 t=100974 +move dx=0.022 dy=0.001 x=9.871 y=3.292 t=100983 +move dx=0.020 dy=0.001 x=9.891 y=3.293 t=100991 +move dx=0.018 dy=0.001 x=9.909 y=3.295 t=101001 +move dx=0.017 dy=0.001 x=9.926 y=3.296 t=101008 +move dx=0.015 dy=0.001 x=9.941 y=3.296 t=101016 +move dx=0.014 dy=0.001 x=9.955 y=3.297 t=101023 +move dx=0.012 dy=0.001 x=9.967 y=3.298 t=101033 +move dx=0.010 dy=0.001 x=9.977 y=3.299 t=101039 +move dx=0.008 dy=0.000 x=9.985 y=3.299 t=101048 +move dx=0.007 dy=0.000 x=9.991 y=3.299 t=101056 +move dx=-0.005 dy=-0.001 x=9.991 y=3.299 t=101105 +move dx=-0.007 dy=-0.001 x=9.984 y=3.298 t=101110 +move dx=-0.009 dy=-0.001 x=9.975 y=3.297 t=101121 +move dx=-0.011 dy=-0.001 x=9.964 y=3.296 t=101126 +move dx=-0.013 dy=-0.001 x=9.951 y=3.295 t=101135 +move dx=-0.014 dy=-0.001 x=9.937 y=3.294 t=101143 +move dx=-0.016 dy=-0.002 x=9.921 y=3.292 t=101151 +move dx=-0.018 dy=-0.002 x=9.903 y=3.290 t=101159 +move dx=-0.019 dy=-0.002 x=9.884 y=3.288 t=101168 +move dx=-0.021 dy=-0.002 x=9.863 y=3.286 t=101177 +move dx=-0.022 dy=-0.002 x=9.841 y=3.284 t=101182 +move dx=-0.024 dy=-0.002 x=9.817 y=3.282 t=101192 +move dx=-0.025 dy=-0.002 x=9.792 y=3.279 t=101198 +move dx=-0.026 dy=-0.003 x=9.766 y=3.277 t=101208 +move dx=-0.027 dy=-0.003 x=9.738 y=3.274 t=101216 +move dx=-0.029 dy=-0.003 x=9.710 y=3.271 t=101222 +move dx=-0.030 dy=-0.003 x=9.680 y=3.268 t=101231 +move dx=-0.031 dy=-0.003 x=9.649 y=3.265 t=101240 +move dx=-0.032 dy=-0.003 x=9.617 y=3.262 t=101247 +move dx=-0.033 dy=-0.003 x=9.585 y=3.258 t=101254 +move dx=-0.034 dy=-0.003 x=9.551 y=3.255 t=101265 +move dx=-0.034 dy=-0.003 x=9.517 y=3.252 t=101273 +move dx=-0.035 dy=-0.004 x=9.481 y=3.248 t=101280 +move dx=-0.036 dy=-0.004 x=9.446 y=3.245 t=101287 +move dx=-0.037 dy=-0.004 x=9.409 y=3.241 t=101295 +move dx=-0.037 dy=-0.004 x=9.372 y=3.237 t=101304 +move dx=-0.038 dy=-0.004 x=9.334 y=3.233 t=101313 +move dx=-0.038 dy=-0.004 x=9.296 y=3.230 t=101319 +move dx=-0.039 dy=-0.004 x=9.257 y=3.226 t=101328 +move dx=-0.039 dy=-0.004 x=9.218 y=3.222 t=101335 +move dx=-0.039 dy=-0.004 x=9.179 y=3.218 t=101342 +move dx=-0.040 dy=-0.004 x=9.140 y=3.214 t=101353 +move dx=-0.040 dy=-0.004 x=9.100 y=3.210 t=101359 +move dx=-0.040 dy=-0.004 x=9.060 y=3.206 t=101367 +move dx=-0.040 dy=-0.004 x=9.020 y=3.202 t=101375 +move dx=-0.040 dy=-0.004 x=8.980 y=3.198 t=101384 +move dx=-0.040 dy=-0.004 x=8.940 y=3.194 t=101390 +move dx=-0.040 dy=-0.004 x=8.900 y=3.190 t=101399 +move dx=-0.040 dy=-0.004 x=8.860 y=3.186 t=101408 +move dx=-0.040 dy=-0.004 x=8.821 y=3.182 t=101417 +move dx=-0.039 dy=-0.004 x=8.782 y=3.178 t=101425 +move dx=-0.039 dy=-0.004 x=8.743 y=3.174 t=101430 +move dx=-0.039 dy=-0.004 x=8.704 y=3.170 t=101441 +move dx=-0.038 dy=-0.004 x=8.666 y=3.167 t=101448 +move dx=-0.038 dy=-0.004 x=8.628 y=3.163 t=101457 +move dx=-0.037 dy=-0.004 x=8.591 y=3.159 t=101465 +move dx=-0.037 dy=-0.004 x=8.554 y=3.155 t=101470 +move dx=-0.036 dy=-0.004 x=8.519 y=3.152 t=101479 +move dx=-0.035 dy=-0.004 x=8.483 y=3.148 t=101488 +move dx=-0.034 dy=-0.003 x=8.449 y=3.145 t=101495 +move dx=-0.034 dy=-0.003 x=8.415 y=3.142 t=101505 +move dx=-0.033 dy=-0.003 x=8.383 y=3.138 t=101511 +move dx=-0.032 dy=-0.003 x=8.351 y=3.135 t=101520 +move dx=-0.031 dy=-0.003 x=8.320 y=3.132 t=101526 +move dx=-0.030 dy=-0.003 x=8.290 y=3.129 t=101537 +move dx=-0.029 dy=-0.003 x=8.262 y=3.126 t=101545 +move dx=-0.027 dy=-0.003 x=8.234 y=3.123 t=101553 +move dx=-0.026 dy=-0.003 x=8.208 y=3.121 t=101559 +move dx=-0.025 dy=-0.002 x=8.183 y=3.118 t=101567 +move dx=-0.024 dy=-0.002 x=8.159 y=3.116 t=101577 +move dx=-0.022 dy=-0.002 x=8.137 y=3.114 t=101584 +move dx=-0.021 dy=-0.002 x=8.116 y=3.112 t=101591 +move dx=-0.019 dy=-0.002 x=8.097 y=3.110 t=101600 +move dx=-0.018 dy=-0.002 x=8.079 y=3.108 t=101606 +move dx=-0.016 dy=-0.002 x=8.063 y=3.106 t=101615 +move dx=-0.014 dy=-0.001 x=8.049 y=3.105 t=101624 +move dx=-0.013 dy=-0.001 x=8.036 y=3.104 t=101633 +move dx=-0.011 dy=-0.001 x=8.025 y=3.103 t=101640 +move dx=-0.009 dy=-0.001 x=8.016 y=3.102 t=101647 +move dx=-0.007 dy=-0.001 x=8.009 y=3.101 t=101656 +move dx=-0.005 dy=-0.001 x=8.004 y=3.100 t=101663 +move dx=0.128 dy=0.000 x=8.128 y=3.100 t=101688 +move dx=0.128 dy=0.000 x=8.256 y=3.100 t=101696 +move dx=0.128 dy=0.000 x=8.384 y=3.100 t=101705 +move dx=0.128 dy=0.000 x=8.512 y=3.100 t=101713 +move dx=0.128 dy=0.000 x=8.640 y=3.100 t=101721 +move dx=0.128 dy=0.000 x=8.768 y=3.100 t=101728 +move dx=0.128 dy=0.000 x=8.896 y=3.100 t=101735 +move dx=0.128 dy=0.000 x=9.024 y=3.100 t=101743 +move dx=0.128 dy=0.000 x=9.152 y=3.100 t=101751 +move dx=0.128 dy=0.000 x=9.280 y=3.100 t=101759 +move dx=0.128 dy=0.000 x=9.408 y=3.100 t=101769 +move dx=0.128 dy=0.000 x=9.536 y=3.100 t=101774 +move dx=0.128 dy=0.000 x=9.664 y=3.100 t=101783 +move dx=0.128 dy=0.000 x=9.792 y=3.100 t=101792 +move dx=0.128 dy=0.000 x=9.920 y=3.100 t=101800 +move dx=0.128 dy=0.000 x=10.048 y=3.100 t=101809 +move dx=0.128 dy=0.000 x=10.176 y=3.100 t=101814 +move dx=0.128 dy=0.000 x=10.304 y=3.100 t=101822 +move dx=0.128 dy=0.000 x=10.432 y=3.100 t=101831 +move dx=0.128 dy=0.000 x=10.560 y=3.100 t=101841 +move dx=0.128 dy=0.000 x=10.688 y=3.100 t=101847 +move dx=0.128 dy=0.000 x=10.816 y=3.100 t=101856 +move dx=0.128 dy=0.000 x=10.944 y=3.100 t=101864 +move dx=0.128 dy=0.000 x=11.072 y=3.100 t=101872 +move dx=0.128 dy=0.000 x=11.200 y=3.100 t=101880 +end x=11.200 y=3.100 t=101888 diff --git a/komorebic/fixtures/pan3-slow.transcript.txt b/komorebic/fixtures/pan3-slow.transcript.txt new file mode 100644 index 00000000..490b91e5 --- /dev/null +++ b/komorebic/fixtures/pan3-slow.transcript.txt @@ -0,0 +1,67 @@ +begin fingers=3 x=5.000 y=3.000 w=11.700 h=7.500 t=100048 +move dx=0.006 dy=0.001 x=5.020 y=3.002 t=100128 +move dx=0.007 dy=0.001 x=5.027 y=3.002 t=100136 +move dx=0.008 dy=0.001 x=5.035 y=3.003 t=100144 +move dx=0.009 dy=0.001 x=5.044 y=3.004 t=100152 +move dx=0.010 dy=0.001 x=5.053 y=3.005 t=100160 +move dx=0.011 dy=0.001 x=5.064 y=3.006 t=100168 +move dx=0.011 dy=0.001 x=5.075 y=3.007 t=100176 +move dx=0.012 dy=0.001 x=5.088 y=3.008 t=100184 +move dx=0.013 dy=0.001 x=5.101 y=3.009 t=100192 +move dx=0.014 dy=0.001 x=5.114 y=3.010 t=100200 +move dx=0.014 dy=0.001 x=5.129 y=3.012 t=100208 +move dx=0.015 dy=0.001 x=5.144 y=3.013 t=100216 +move dx=0.016 dy=0.001 x=5.160 y=3.015 t=100224 +move dx=0.016 dy=0.001 x=5.176 y=3.016 t=100232 +move dx=0.017 dy=0.002 x=5.193 y=3.018 t=100240 +move dx=0.017 dy=0.002 x=5.210 y=3.019 t=100248 +move dx=0.018 dy=0.002 x=5.228 y=3.021 t=100256 +move dx=0.018 dy=0.002 x=5.247 y=3.022 t=100264 +move dx=0.019 dy=0.002 x=5.266 y=3.024 t=100272 +move dx=0.019 dy=0.002 x=5.285 y=3.026 t=100280 +move dx=0.020 dy=0.002 x=5.305 y=3.028 t=100288 +move dx=0.020 dy=0.002 x=5.325 y=3.030 t=100296 +move dx=0.020 dy=0.002 x=5.345 y=3.031 t=100304 +move dx=0.021 dy=0.002 x=5.366 y=3.033 t=100312 +move dx=0.021 dy=0.002 x=5.387 y=3.035 t=100320 +move dx=0.021 dy=0.002 x=5.408 y=3.037 t=100328 +move dx=0.021 dy=0.002 x=5.430 y=3.039 t=100336 +move dx=0.022 dy=0.002 x=5.451 y=3.041 t=100344 +move dx=0.022 dy=0.002 x=5.473 y=3.043 t=100352 +move dx=0.022 dy=0.002 x=5.495 y=3.045 t=100360 +move dx=0.022 dy=0.002 x=5.517 y=3.047 t=100368 +move dx=0.022 dy=0.002 x=5.539 y=3.049 t=100376 +move dx=0.022 dy=0.002 x=5.561 y=3.051 t=100384 +move dx=0.022 dy=0.002 x=5.583 y=3.053 t=100392 +move dx=0.022 dy=0.002 x=5.605 y=3.055 t=100400 +move dx=0.022 dy=0.002 x=5.627 y=3.057 t=100408 +move dx=0.022 dy=0.002 x=5.649 y=3.059 t=100416 +move dx=0.022 dy=0.002 x=5.670 y=3.061 t=100424 +move dx=0.021 dy=0.002 x=5.692 y=3.063 t=100432 +move dx=0.021 dy=0.002 x=5.713 y=3.065 t=100440 +move dx=0.021 dy=0.002 x=5.734 y=3.067 t=100448 +move dx=0.021 dy=0.002 x=5.755 y=3.069 t=100456 +move dx=0.020 dy=0.002 x=5.775 y=3.070 t=100464 +move dx=0.020 dy=0.002 x=5.795 y=3.072 t=100472 +move dx=0.020 dy=0.002 x=5.815 y=3.074 t=100480 +move dx=0.019 dy=0.002 x=5.834 y=3.076 t=100488 +move dx=0.019 dy=0.002 x=5.853 y=3.078 t=100496 +move dx=0.018 dy=0.002 x=5.872 y=3.079 t=100504 +move dx=0.018 dy=0.002 x=5.890 y=3.081 t=100512 +move dx=0.017 dy=0.002 x=5.907 y=3.082 t=100520 +move dx=0.017 dy=0.002 x=5.924 y=3.084 t=100528 +move dx=0.016 dy=0.001 x=5.940 y=3.085 t=100536 +move dx=0.016 dy=0.001 x=5.956 y=3.087 t=100544 +move dx=0.015 dy=0.001 x=5.971 y=3.088 t=100552 +move dx=0.014 dy=0.001 x=5.986 y=3.090 t=100560 +move dx=0.014 dy=0.001 x=5.999 y=3.091 t=100568 +move dx=0.013 dy=0.001 x=6.012 y=3.092 t=100576 +move dx=0.012 dy=0.001 x=6.025 y=3.093 t=100584 +move dx=0.011 dy=0.001 x=6.036 y=3.094 t=100592 +move dx=0.011 dy=0.001 x=6.047 y=3.095 t=100600 +move dx=0.010 dy=0.001 x=6.056 y=3.096 t=100608 +move dx=0.009 dy=0.001 x=6.065 y=3.097 t=100616 +move dx=0.008 dy=0.001 x=6.073 y=3.098 t=100624 +move dx=0.007 dy=0.001 x=6.080 y=3.098 t=100632 +move dx=0.006 dy=0.001 x=6.086 y=3.099 t=100640 +end x=6.100 y=3.100 t=100688 diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 613abc66..af3f8e5c 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -13,6 +13,7 @@ use komorebi_client::DefaultLayout; use komorebi_client::MoveBehaviour; use komorebi_client::OperationBehaviour; use komorebi_client::OperationDirection; +use komorebi_client::PanDirection; use komorebi_client::PathExt; use komorebi_client::Rect; use komorebi_client::Sizing; @@ -629,6 +630,13 @@ struct ScrollingLayoutColumns { count: NonZeroUsize, } +#[derive(Parser)] +struct Pan { + /// The way that the view goes + #[clap(value_enum)] + direction: PanDirection, +} + #[derive(Parser)] struct LayoutRatios { /// Column width ratios (space-separated values between 0.1 and 0.9) @@ -1017,6 +1025,14 @@ enum SubCommand { /// becomes a column with a window in each slot, in the order of its tabs. Only the Scrolling /// layout has columns of several windows, so this does nothing in the other layouts. ToggleColumnStack, + /// Move the view of the Scrolling layout a column to the left or the right + /// + /// The strip of columns moves by the width of a new column and comes to rest with a column + /// against an edge of the screen. Focus stays on the column that has it if that is still fully + /// in view, and otherwise goes to the nearest column that is. Only the Scrolling layout has a + /// strip to move, so this does nothing in the other layouts. + #[clap(arg_required_else_help = true)] + Pan(Pan), /// Set the layout column and row ratios for the focused workspace LayoutRatios(LayoutRatios), // /// Load a custom layout from file for the focused workspace @@ -2417,6 +2433,9 @@ exit 1 SubCommand::ToggleColumnStack => { send_message(&SocketMessage::ToggleColumnStack)?; } + SubCommand::Pan(args) => { + send_message(&SocketMessage::Pan(args.direction))?; + } SubCommand::LayoutRatios(args) => { if args.columns.is_none() && args.rows.is_none() { println!(