style(touch): rustfmt the presenter finger dispatch + gesture engine
Wrap the long dispatch_finger call args, Abs struct literals, and Act::Button/ Scroll/MoveRel pushes per rustfmt (the CI fmt check on pf-presenter). No behavior change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -598,7 +598,15 @@ fn run_inner(mut opts: SessionOpts, mut mode: ModeCtl) -> Result<Option<Outcome>
|
|||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
if is_direct_touch(touch_id)
|
if is_direct_touch(touch_id)
|
||||||
&& dispatch_finger(FingerPhase::Down, &window, &mut stream, finger_id, x, y, timestamp)
|
&& dispatch_finger(
|
||||||
|
FingerPhase::Down,
|
||||||
|
&window,
|
||||||
|
&mut stream,
|
||||||
|
finger_id,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
timestamp,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
bump_stats_tier(&mut stats_verbosity, &mut stream, &presenter);
|
bump_stats_tier(&mut stats_verbosity, &mut stream, &presenter);
|
||||||
}
|
}
|
||||||
@@ -612,7 +620,15 @@ fn run_inner(mut opts: SessionOpts, mut mode: ModeCtl) -> Result<Option<Outcome>
|
|||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
if is_direct_touch(touch_id)
|
if is_direct_touch(touch_id)
|
||||||
&& dispatch_finger(FingerPhase::Move, &window, &mut stream, finger_id, x, y, timestamp)
|
&& dispatch_finger(
|
||||||
|
FingerPhase::Move,
|
||||||
|
&window,
|
||||||
|
&mut stream,
|
||||||
|
finger_id,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
timestamp,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
bump_stats_tier(&mut stats_verbosity, &mut stream, &presenter);
|
bump_stats_tier(&mut stats_verbosity, &mut stream, &presenter);
|
||||||
}
|
}
|
||||||
@@ -626,7 +642,15 @@ fn run_inner(mut opts: SessionOpts, mut mode: ModeCtl) -> Result<Option<Outcome>
|
|||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
if is_direct_touch(touch_id)
|
if is_direct_touch(touch_id)
|
||||||
&& dispatch_finger(FingerPhase::Up, &window, &mut stream, finger_id, x, y, timestamp)
|
&& dispatch_finger(
|
||||||
|
FingerPhase::Up,
|
||||||
|
&window,
|
||||||
|
&mut stream,
|
||||||
|
finger_id,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
timestamp,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
bump_stats_tier(&mut stats_verbosity, &mut stream, &presenter);
|
bump_stats_tier(&mut stats_verbosity, &mut stream, &presenter);
|
||||||
}
|
}
|
||||||
@@ -1374,15 +1398,32 @@ fn dispatch_finger(
|
|||||||
let abs = match st.last_video {
|
let abs = match st.last_video {
|
||||||
Some(video) => {
|
Some(video) => {
|
||||||
let (ax, ay, aw, ah) = finger_to_content((pw, ph), video, x, y);
|
let (ax, ay, aw, ah) = finger_to_content((pw, ph), video, x, y);
|
||||||
Abs { x: ax, y: ay, w: aw, h: ah }
|
Abs {
|
||||||
|
x: ax,
|
||||||
|
y: ay,
|
||||||
|
w: aw,
|
||||||
|
h: ah,
|
||||||
}
|
}
|
||||||
None if phase == FingerPhase::Up => Abs { x: 0, y: 0, w: 0, h: 0 },
|
}
|
||||||
|
None if phase == FingerPhase::Up => Abs {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
w: 0,
|
||||||
|
h: 0,
|
||||||
|
},
|
||||||
None => return false,
|
None => return false,
|
||||||
};
|
};
|
||||||
let Some(cap) = st.capture.as_mut() else {
|
let Some(cap) = st.capture.as_mut() else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
cap.dispatch_finger(phase, finger_id, wx, wy, abs, timestamp as f64 / 1_000_000.0)
|
cap.dispatch_finger(
|
||||||
|
phase,
|
||||||
|
finger_id,
|
||||||
|
wx,
|
||||||
|
wy,
|
||||||
|
abs,
|
||||||
|
timestamp as f64 / 1_000_000.0,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Advance the stats-overlay tier and re-render the OSD immediately from the last window
|
/// Advance the stats-overlay tier and re-render the OSD immediately from the last window
|
||||||
@@ -1759,7 +1800,10 @@ mod tests {
|
|||||||
// Video exactly fills the window (no letterbox): normalized finger → content
|
// Video exactly fills the window (no letterbox): normalized finger → content
|
||||||
// corners/center map straight through, and the surface size is the video size.
|
// corners/center map straight through, and the surface size is the video size.
|
||||||
let video = (1920, 1080);
|
let video = (1920, 1080);
|
||||||
assert_eq!(finger_to_content((1920, 1080), video, 0.0, 0.0), (0, 0, 1920, 1080));
|
assert_eq!(
|
||||||
|
finger_to_content((1920, 1080), video, 0.0, 0.0),
|
||||||
|
(0, 0, 1920, 1080)
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
finger_to_content((1920, 1080), video, 1.0, 1.0),
|
finger_to_content((1920, 1080), video, 1.0, 1.0),
|
||||||
(1920, 1080, 1920, 1080)
|
(1920, 1080, 1920, 1080)
|
||||||
@@ -1782,8 +1826,14 @@ mod tests {
|
|||||||
assert_eq!((w, h), (1280, 720));
|
assert_eq!((w, h), (1280, 720));
|
||||||
assert_eq!(cy, 360);
|
assert_eq!(cy, 360);
|
||||||
// y=0.01 → window pixel 8, above the 40px bar → clamps to content top (0).
|
// y=0.01 → window pixel 8, above the 40px bar → clamps to content top (0).
|
||||||
assert_eq!(finger_to_content(surface, video, 0.5, 0.01), (640, 0, 1280, 720));
|
assert_eq!(
|
||||||
|
finger_to_content(surface, video, 0.5, 0.01),
|
||||||
|
(640, 0, 1280, 720)
|
||||||
|
);
|
||||||
// Bottom-right corner of the video content.
|
// Bottom-right corner of the video content.
|
||||||
assert_eq!(finger_to_content(surface, video, 1.0, 1.0), (1280, 720, 1280, 720));
|
assert_eq!(
|
||||||
|
finger_to_content(surface, video, 1.0, 1.0),
|
||||||
|
(1280, 720, 1280, 720)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,7 +166,10 @@ impl Gestures {
|
|||||||
acts.push(Act::MoveAbs(abs)); // pointer: place the cursor before any press
|
acts.push(Act::MoveAbs(abs)); // pointer: place the cursor before any press
|
||||||
}
|
}
|
||||||
if self.drag_held {
|
if self.drag_held {
|
||||||
acts.push(Act::Button { gs: BTN_LEFT, down: true });
|
acts.push(Act::Button {
|
||||||
|
gs: BTN_LEFT,
|
||||||
|
down: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
self.track_id = Some(id);
|
self.track_id = Some(id);
|
||||||
self.prev = (wx, wy);
|
self.prev = (wx, wy);
|
||||||
@@ -208,17 +211,32 @@ impl Gestures {
|
|||||||
self.active = false;
|
self.active = false;
|
||||||
if self.drag_held {
|
if self.drag_held {
|
||||||
self.drag_held = false;
|
self.drag_held = false;
|
||||||
acts.push(Act::Button { gs: BTN_LEFT, down: false }); // end the held drag
|
acts.push(Act::Button {
|
||||||
|
gs: BTN_LEFT,
|
||||||
|
down: false,
|
||||||
|
}); // end the held drag
|
||||||
} else if !self.moved {
|
} else if !self.moved {
|
||||||
match self.max_fingers {
|
match self.max_fingers {
|
||||||
n if n >= 3 => acts.push(Act::CycleStats),
|
n if n >= 3 => acts.push(Act::CycleStats),
|
||||||
2 => {
|
2 => {
|
||||||
acts.push(Act::Button { gs: BTN_RIGHT, down: true });
|
acts.push(Act::Button {
|
||||||
acts.push(Act::Button { gs: BTN_RIGHT, down: false });
|
gs: BTN_RIGHT,
|
||||||
|
down: true,
|
||||||
|
});
|
||||||
|
acts.push(Act::Button {
|
||||||
|
gs: BTN_RIGHT,
|
||||||
|
down: false,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
acts.push(Act::Button { gs: BTN_LEFT, down: true });
|
acts.push(Act::Button {
|
||||||
acts.push(Act::Button { gs: BTN_LEFT, down: false });
|
gs: BTN_LEFT,
|
||||||
|
down: true,
|
||||||
|
});
|
||||||
|
acts.push(Act::Button {
|
||||||
|
gs: BTN_LEFT,
|
||||||
|
down: false,
|
||||||
|
});
|
||||||
self.last_tap_up = t; // arm tap-drag
|
self.last_tap_up = t; // arm tap-drag
|
||||||
self.last_tap_pt = self.start;
|
self.last_tap_pt = self.start;
|
||||||
}
|
}
|
||||||
@@ -261,12 +279,18 @@ impl Gestures {
|
|||||||
let notches_y = ((self.scroll_anchor.1 - cy) / SCROLL_DIV) as i32;
|
let notches_y = ((self.scroll_anchor.1 - cy) / SCROLL_DIV) as i32;
|
||||||
let notches_x = ((cx - self.scroll_anchor.0) / SCROLL_DIV) as i32;
|
let notches_x = ((cx - self.scroll_anchor.0) / SCROLL_DIV) as i32;
|
||||||
if notches_y != 0 {
|
if notches_y != 0 {
|
||||||
acts.push(Act::Scroll { axis: 0, delta: notches_y * 120 });
|
acts.push(Act::Scroll {
|
||||||
|
axis: 0,
|
||||||
|
delta: notches_y * 120,
|
||||||
|
});
|
||||||
self.scroll_anchor.1 = cy;
|
self.scroll_anchor.1 = cy;
|
||||||
self.moved = true;
|
self.moved = true;
|
||||||
}
|
}
|
||||||
if notches_x != 0 {
|
if notches_x != 0 {
|
||||||
acts.push(Act::Scroll { axis: 1, delta: notches_x * 120 });
|
acts.push(Act::Scroll {
|
||||||
|
axis: 1,
|
||||||
|
delta: notches_x * 120,
|
||||||
|
});
|
||||||
self.scroll_anchor.0 = cx;
|
self.scroll_anchor.0 = cx;
|
||||||
self.moved = true;
|
self.moved = true;
|
||||||
}
|
}
|
||||||
@@ -304,7 +328,10 @@ impl Gestures {
|
|||||||
let out_x = self.carry.0 as i32; // truncates toward zero → remainder kept with sign
|
let out_x = self.carry.0 as i32; // truncates toward zero → remainder kept with sign
|
||||||
let out_y = self.carry.1 as i32;
|
let out_y = self.carry.1 as i32;
|
||||||
if out_x != 0 || out_y != 0 {
|
if out_x != 0 || out_y != 0 {
|
||||||
acts.push(Act::MoveRel { dx: out_x, dy: out_y });
|
acts.push(Act::MoveRel {
|
||||||
|
dx: out_x,
|
||||||
|
dy: out_y,
|
||||||
|
});
|
||||||
self.carry.0 -= out_x as f32;
|
self.carry.0 -= out_x as f32;
|
||||||
self.carry.1 -= out_y as f32;
|
self.carry.1 -= out_y as f32;
|
||||||
}
|
}
|
||||||
@@ -316,10 +343,20 @@ impl Gestures {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
const ABS: Abs = Abs { x: 100, y: 200, w: 1280, h: 720 };
|
const ABS: Abs = Abs {
|
||||||
|
x: 100,
|
||||||
|
y: 200,
|
||||||
|
w: 1280,
|
||||||
|
h: 720,
|
||||||
|
};
|
||||||
|
|
||||||
fn abs_at(x: i32, y: i32) -> Abs {
|
fn abs_at(x: i32, y: i32) -> Abs {
|
||||||
Abs { x, y, w: 1280, h: 720 }
|
Abs {
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
w: 1280,
|
||||||
|
h: 720,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -331,8 +368,14 @@ mod tests {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
acts,
|
acts,
|
||||||
vec![
|
vec![
|
||||||
Act::Button { gs: BTN_LEFT, down: true },
|
Act::Button {
|
||||||
Act::Button { gs: BTN_LEFT, down: false },
|
gs: BTN_LEFT,
|
||||||
|
down: true
|
||||||
|
},
|
||||||
|
Act::Button {
|
||||||
|
gs: BTN_LEFT,
|
||||||
|
down: false
|
||||||
|
},
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -346,8 +389,14 @@ mod tests {
|
|||||||
acts,
|
acts,
|
||||||
vec![
|
vec![
|
||||||
Act::MoveAbs(abs_at(640, 360)),
|
Act::MoveAbs(abs_at(640, 360)),
|
||||||
Act::Button { gs: BTN_LEFT, down: true },
|
Act::Button {
|
||||||
Act::Button { gs: BTN_LEFT, down: false },
|
gs: BTN_LEFT,
|
||||||
|
down: true
|
||||||
|
},
|
||||||
|
Act::Button {
|
||||||
|
gs: BTN_LEFT,
|
||||||
|
down: false
|
||||||
|
},
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -362,8 +411,14 @@ mod tests {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
acts,
|
acts,
|
||||||
vec![
|
vec![
|
||||||
Act::Button { gs: BTN_RIGHT, down: true },
|
Act::Button {
|
||||||
Act::Button { gs: BTN_RIGHT, down: false },
|
gs: BTN_RIGHT,
|
||||||
|
down: true
|
||||||
|
},
|
||||||
|
Act::Button {
|
||||||
|
gs: BTN_RIGHT,
|
||||||
|
down: false
|
||||||
|
},
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -415,7 +470,9 @@ mod tests {
|
|||||||
let a2 = g.motion(2, 120.0, 160.0, ABS, 12.0);
|
let a2 = g.motion(2, 120.0, 160.0, ABS, 12.0);
|
||||||
let scrolls: Vec<_> = a1.into_iter().chain(a2).collect();
|
let scrolls: Vec<_> = a1.into_iter().chain(a2).collect();
|
||||||
assert!(
|
assert!(
|
||||||
scrolls.iter().any(|a| matches!(a, Act::Scroll { axis: 0, delta } if *delta > 0)),
|
scrolls
|
||||||
|
.iter()
|
||||||
|
.any(|a| matches!(a, Act::Scroll { axis: 0, delta } if *delta > 0)),
|
||||||
"expected an upward vertical scroll, got {scrolls:?}"
|
"expected an upward vertical scroll, got {scrolls:?}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -429,17 +486,35 @@ mod tests {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
click,
|
click,
|
||||||
vec![
|
vec![
|
||||||
Act::Button { gs: BTN_LEFT, down: true },
|
Act::Button {
|
||||||
Act::Button { gs: BTN_LEFT, down: false },
|
gs: BTN_LEFT,
|
||||||
|
down: true
|
||||||
|
},
|
||||||
|
Act::Button {
|
||||||
|
gs: BTN_LEFT,
|
||||||
|
down: false
|
||||||
|
},
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
// A new touch nearby within the window arms a held drag: button down on touch, and
|
// A new touch nearby within the window arms a held drag: button down on touch, and
|
||||||
// the whole gesture holds it until the lift.
|
// the whole gesture holds it until the lift.
|
||||||
let down2 = g.down(2, 52.0, 51.0, ABS, 120.0);
|
let down2 = g.down(2, 52.0, 51.0, ABS, 120.0);
|
||||||
assert_eq!(down2, vec![Act::Button { gs: BTN_LEFT, down: true }]);
|
assert_eq!(
|
||||||
|
down2,
|
||||||
|
vec![Act::Button {
|
||||||
|
gs: BTN_LEFT,
|
||||||
|
down: true
|
||||||
|
}]
|
||||||
|
);
|
||||||
let _ = g.motion(2, 90.0, 51.0, ABS, 140.0); // drag
|
let _ = g.motion(2, 90.0, 51.0, ABS, 140.0); // drag
|
||||||
let end = g.up(2, 160.0);
|
let end = g.up(2, 160.0);
|
||||||
assert_eq!(end, vec![Act::Button { gs: BTN_LEFT, down: false }]);
|
assert_eq!(
|
||||||
|
end,
|
||||||
|
vec![Act::Button {
|
||||||
|
gs: BTN_LEFT,
|
||||||
|
down: false
|
||||||
|
}]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -455,8 +530,14 @@ mod tests {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
acts,
|
acts,
|
||||||
vec![
|
vec![
|
||||||
Act::Button { gs: BTN_LEFT, down: true },
|
Act::Button {
|
||||||
Act::Button { gs: BTN_LEFT, down: false },
|
gs: BTN_LEFT,
|
||||||
|
down: true
|
||||||
|
},
|
||||||
|
Act::Button {
|
||||||
|
gs: BTN_LEFT,
|
||||||
|
down: false
|
||||||
|
},
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user