mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-12-01 04:34:11 +01:00
komorebic pan --stream reads the gestures of fingers on a touchpad from standard input, as whkd writes them for a swipe of three or four fingers (docs/gesture-stream.md in its repository): a line for each begin, move, end and cancel, with the distances in centimetres, and any field or message that it does not know ignored. The row follows the fingers while they are down, and when they lift it comes to rest with a column against an edge of the screen, going at the speed that the times of the moves say that the fingers were. Focus goes to the nearest column in view if the focused one is not. A gesture that is given up, or that is not finished when the stream stops, puts the row back to what it was. komorebic works out nothing but what it is asked to: --sensitivity multiplies the distances, --reversed flips the way that the row goes, and --paging takes a step for every two centimetres that the fingers go, as komorebic pan does, and not move the row with them. Moves that wait while one is told are added up, as whkd says that they may be. A gesture is told to komorebi on one connection, which it handles in order, as messages that are sent on a connection each are not. With ghost movement the pictures that cover the windows near the screen are taken when the fingers go down, a move of the fingers sets them where the row puts the windows and does nothing else, and when the fingers lift they glide to where it comes to rest, over the time that an animation takes, and the windows are shown. Without it the workspace is laid out a step at a time, as it is for a drag. Ten centimetres of the fingers move the row the width of the screen. The golden transcript of whkd and the swipes of its demo are fixtures of the tests that read the stream.
68 lines
2.2 KiB
Rust
68 lines
2.2 KiB
Rust
use clap::ValueEnum;
|
|
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
use strum::Display;
|
|
use strum::EnumString;
|
|
|
|
/// Which way the view goes when the strip of the Scrolling layout is panned: to the left is to
|
|
/// see what is to the left of the screen, which is to move the strip to the right
|
|
#[derive(
|
|
Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Display, EnumString, ValueEnum,
|
|
)]
|
|
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
|
pub enum PanDirection {
|
|
Left,
|
|
Right,
|
|
}
|
|
|
|
impl PanDirection {
|
|
/// How far the strip is moved on the screen to pan `distance` pixels this way, in pixels,
|
|
/// to the right if it is positive
|
|
#[must_use]
|
|
pub fn strip_offset(self, distance: u32) -> f64 {
|
|
match self {
|
|
Self::Left => f64::from(distance),
|
|
Self::Right => -f64::from(distance),
|
|
}
|
|
}
|
|
}
|
|
|
|
/// What the fingers of a gesture that pans the strip do, as far as the strip is concerned
|
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
|
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
|
pub enum PanGesture {
|
|
/// The fingers have landed
|
|
Begin,
|
|
/// The fingers moved by `dx` and `dy` centimetres on the touchpad since the last time, to
|
|
/// the right and down if they are positive, at `t` milliseconds on a clock that only the
|
|
/// differences between the times of a gesture mean anything on
|
|
Move { dx: f64, dy: f64, t: f64 },
|
|
/// The fingers lifted
|
|
End,
|
|
/// The gesture was given up: the strip goes back to where it was
|
|
Cancel,
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use std::str::FromStr;
|
|
|
|
#[test]
|
|
fn the_strip_goes_the_other_way_to_the_view() {
|
|
assert!((PanDirection::Left.strip_offset(400) - 400.0).abs() < f64::EPSILON);
|
|
assert!((PanDirection::Right.strip_offset(400) + 400.0).abs() < f64::EPSILON);
|
|
assert!(PanDirection::Left.strip_offset(0).abs() < f64::EPSILON);
|
|
}
|
|
|
|
#[test]
|
|
fn directions_have_the_names_that_the_others_have() {
|
|
assert_eq!(
|
|
<PanDirection as FromStr>::from_str("Left").unwrap(),
|
|
PanDirection::Left
|
|
);
|
|
assert_eq!(PanDirection::Right.to_string(), "Right");
|
|
assert!(<PanDirection as FromStr>::from_str("Up").is_err());
|
|
}
|
|
}
|