Skip to content

Commit

Permalink
#7 intermediate triggers for pinch gestures
Browse files Browse the repository at this point in the history
raise event on pinch update
configuration of triggers
  - trigger when scale threshold is reached
cleanup some mut pointer usage
ignore local history
  • Loading branch information
Alsan authored and pguedes committed Nov 23, 2020
1 parent 98e38fd commit 0856718
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 137 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
gesticle.iml
/target/
**/*.rs.bk
.history/
project.code-workspace
3 changes: 3 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[gesture.trigger]
pinch.in.scale = 0.2
pinch.out.scale = -0.5

[swipe.up]
3 = "ctrl+t"
Expand Down
53 changes: 33 additions & 20 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,46 @@ impl LibinputInterface for LibInputFile {
}
}

pub struct GestureSource {
pinch_in_scale_trigger: f64,
pinch_out_scale_trigger: f64,
}

impl GestureSource {

pub fn new(pinch_in_scale_trigger: f64, pinch_out_scale_trigger: f64) -> GestureSource {
GestureSource {
pinch_in_scale_trigger,
pinch_out_scale_trigger
}
}

pub fn listen<G>(gesture_action: G)
where G: Fn(GestureType) {
pub fn listen(&self) -> mpsc::Receiver<GestureType> {
let (tx, rx) = mpsc::channel();

let (tx, rx) = mpsc::channel();
let pinch_in_trigger = self.pinch_in_scale_trigger;
let pinch_out_trigger = self.pinch_out_scale_trigger;

thread::spawn(move || {
thread::spawn(move || {

let io = LibInputFile { };
let ctx = Context::new().expect("could not create udev context...");
let mut libinput = Libinput::new_from_udev(io, &ctx);
let io = LibInputFile { };
let ctx = Context::new().expect("could not create udev context...");
let mut libinput = Libinput::new_from_udev(io, &ctx);

libinput.udev_assign_seat("seat0").unwrap();
let publish = |t: GestureType| tx.send(t).unwrap();
let mut listener = Listener::new(&publish);
libinput.udev_assign_seat("seat0").unwrap();
let publish = |t: GestureType| tx.send(t).unwrap();
let mut listener =
Listener::new(pinch_in_trigger, pinch_out_trigger, &publish);

loop {
libinput.dispatch().unwrap();
while let Some(event) = libinput.next() {
listener = listener.event(event);
loop {
libinput.dispatch().unwrap();
while let Some(event) = libinput.next() {
listener.event(event);
}
sleep(Duration::from_millis(10));
}
sleep(Duration::from_millis(10));
}
});
});

for gesture in rx {
debug!("triggered gesture: {:?}", gesture);
gesture_action(gesture);
return rx
}
}
Loading

0 comments on commit 0856718

Please sign in to comment.