@@ -223,12 +223,12 @@ struct AudioSourceConfig {
223223enum Message {
224224 Portal ( Box < Result < portal:: PortalStream , portal:: PortalError > > ) ,
225225 Stream ( StreamEvent ) ,
226- /// A left mouse-button edge observed on evdev, carrying the event time in
227- /// milliseconds so the emitted click sample is stamped when it happened
228- /// rather than at the next throttled sample. See [`input`] for why this is
226+ /// A left mouse-button edge observed on evdev, carrying its device path
227+ /// and time in milliseconds so the emitted click sample is stamped when
228+ /// it happened rather than at the next throttled sample. See [`input`] for why this is
229229 /// the only way to see a button on Wayland, and for its permission and
230230 /// privacy model.
231- PointerButton ( u64 , bool ) ,
231+ PointerButton ( PathBuf , u64 , bool ) ,
232232 /// A pointer reader thread stopped on a device error (typically an unplug);
233233 /// the string is the OS error. Surfaced as a warning so click capture going
234234 /// quiet mid-recording is not silent.
@@ -672,6 +672,7 @@ fn run<W: Write>(
672672 // picker has been answered.
673673 let mut armed = false ;
674674 let mut cursor: Option < CursorState > = None ;
675+ let mut held_pointer_devices = HashSet :: new ( ) ;
675676 let mut known_assets: HashSet < String > = HashSet :: new ( ) ;
676677 let mut pending_asset: Option < CursorAsset > = None ;
677678 // Wall-clock ms at which the pw_stream last reached `streaming` (mutter began
@@ -785,8 +786,9 @@ fn run<W: Write>(
785786 // began (see `streaming_since`): a press while the picker is still up —
786787 // the click on its "Share" button — is older, so it is dropped even if
787788 // its message is delivered after the stream-state one.
788- Ok ( Message :: PointerButton ( press_ms, down) ) => {
789- if streaming_since. is_some_and ( |since| press_ms >= since) {
789+ Ok ( Message :: PointerButton ( device, press_ms, down) ) => {
790+ let edge = pointer_button_edge ( & mut held_pointer_devices, device, down) ;
791+ if streaming_since. is_some_and ( |since| press_ms >= since) && edge. is_some ( ) {
790792 emit_sample ( emitter, & cursor, content_rect ( & capture, size) , & mut pending_asset, Some ( ( press_ms, down) ) ) ;
791793 }
792794 }
@@ -1525,6 +1527,37 @@ fn content_rect(capture: &Option<Capture>, size: Option<(i32, i32)>) -> Option<s
15251527 }
15261528}
15271529
1530+ fn pointer_button_edge ( held : & mut HashSet < PathBuf > , device : PathBuf , down : bool ) -> Option < bool > {
1531+ if down {
1532+ held. insert ( device) ;
1533+ Some ( true )
1534+ } else if held. remove ( & device) && held. is_empty ( ) {
1535+ Some ( false )
1536+ } else {
1537+ None
1538+ }
1539+ }
1540+
1541+ #[ cfg( test) ]
1542+ mod pointer_button_tests {
1543+ use super :: * ;
1544+
1545+ #[ test]
1546+ fn one_device_release_does_not_end_another_devices_hold ( ) {
1547+ let mut held = HashSet :: new ( ) ;
1548+ let mouse = PathBuf :: from ( "/dev/input/mouse" ) ;
1549+ let touchpad = PathBuf :: from ( "/dev/input/touchpad" ) ;
1550+ assert_eq ! ( pointer_button_edge( & mut held, mouse. clone( ) , true ) , Some ( true ) ) ;
1551+ assert_eq ! (
1552+ pointer_button_edge( & mut held, touchpad. clone( ) , true ) ,
1553+ Some ( true )
1554+ ) ;
1555+ assert_eq ! ( pointer_button_edge( & mut held, mouse. clone( ) , false ) , None ) ;
1556+ assert_eq ! ( pointer_button_edge( & mut held, touchpad, false ) , Some ( false ) ) ;
1557+ assert_eq ! ( pointer_button_edge( & mut held, mouse, false ) , None ) ;
1558+ }
1559+ }
1560+
15281561/// Emits one cursor sample, positioned inside `content`.
15291562///
15301563/// `content` is the sub-rectangle of the stream the recording actually shows —
0 commit comments