From 7e334bfe69cad3131da7e901ab9a36bb318a3a6a Mon Sep 17 00:00:00 2001 From: VallierDev <24893073+VallierDev@users.noreply.github.com> Date: Wed, 14 Oct 2026 23:59:19 +0800 Subject: [PATCH] Separate portal input audit budgets and count native GTK button delivery --- src/input.rs | 13 ++++++--- src/webrtc.rs | 10 +++++++ tests/fixtures/clipboard-official.py | 40 ++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 tests/fixtures/clipboard-official.py diff --git a/src/input.rs b/src/input.rs index 5e4cfce..dc6ab0a 100644 --- a/src/input.rs +++ b/src/input.rs @@ -33,11 +33,11 @@ struct PendingPointer { unsafe fn x11_pointer_state(_: *mut libc::c_int,_:*mut libc::c_int,_:*mut libc::c_uint)->libc::c_int {-1} #[derive(Default)] struct HeldInput { buttons: std::collections::BTreeSet, keys: std::collections::BTreeSet } -pub struct InputInjector { portal_failures: std::sync::atomic::AtomicUsize, portal_outcomes: std::sync::atomic::AtomicUsize, portal:std::sync::Mutex>>, backend: crate::desktop_backend::DesktopBackend, pending: std::sync::Mutex, held: std::sync::Mutex } +pub struct InputInjector { portal_failures: std::sync::atomic::AtomicUsize, portal_outcomes: [std::sync::atomic::AtomicUsize; 3], portal:std::sync::Mutex>>, backend: crate::desktop_backend::DesktopBackend, pending: std::sync::Mutex, held: std::sync::Mutex } impl InputInjector { pub fn new() -> Self { - Self { portal_failures: std::sync::atomic::AtomicUsize::new(0), portal_outcomes: std::sync::atomic::AtomicUsize::new(0), portal:std::sync::Mutex::new(None), backend:crate::desktop_backend::detect().unwrap_or(crate::desktop_backend::DesktopBackend::X11), pending: std::sync::Mutex::new(PendingPointer::default()), held:std::sync::Mutex::new(HeldInput::default()) } + Self { portal_failures: std::sync::atomic::AtomicUsize::new(0), portal_outcomes: std::array::from_fn(|_| std::sync::atomic::AtomicUsize::new(0)), portal:std::sync::Mutex::new(None), backend:crate::desktop_backend::detect().unwrap_or(crate::desktop_backend::DesktopBackend::X11), pending: std::sync::Mutex::new(PendingPointer::default()), held:std::sync::Mutex::new(HeldInput::default()) } } pub fn bind_portal(&self,session:Option>) { @@ -95,6 +95,12 @@ impl InputInjector { } pub fn wire_mouse_button(&self, button: i32, is_press: bool) { if let Some(mapped) = crate::input_mapping::mouse_button_to_x11(button) { self.mouse_button(mapped,is_press); } + else { + static UNKNOWN: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); + if UNKNOWN.fetch_add(1, std::sync::atomic::Ordering::Relaxed) < 16 { + log::warn!("Unsupported desktop wire mouse button: {}", button); + } + } } pub fn mouse_button(&self, button: i32, is_press: bool) { self.flush_pointer(); @@ -136,7 +142,8 @@ impl InputInjector { // and D-Bus errors. Never include keys, coordinates, text or portal tokens. fn portal_result(&self, operation: &str, result: Result<(), String>) -> i32 { use std::sync::atomic::Ordering::Relaxed; - if self.portal_outcomes.fetch_add(1, Relaxed) < 16 { + let slot = match operation { "motion" => 0, "button" => 1, _ => 2 }; + if self.portal_outcomes[slot].fetch_add(1, Relaxed) < 16 { log::info!("Portal input outcome: operation={} success={}", operation, result.is_ok()); } match result { diff --git a/src/webrtc.rs b/src/webrtc.rs index fd2c711..35ca76c 100644 --- a/src/webrtc.rs +++ b/src/webrtc.rs @@ -714,6 +714,16 @@ impl WebRtcSession { match crate::control_protocol::decode_control(&msg.data) { Ok(crate::control_protocol::ControlMessage::Input(event)) => { use crate::control_protocol::ControlInput; + // Separate receipt budgets keep motion floods from hiding clicks. + static RECEIPTS: [std::sync::atomic::AtomicUsize; 3] = [const { std::sync::atomic::AtomicUsize::new(0) }; 3]; + let (slot, kind) = match &event { + ControlInput::MouseButton {..} | ControlInput::MouseClick {..} => (0, "button"), + ControlInput::Keyboard {..} | ControlInput::KeyboardClick {..} => (1, "keyboard"), + _ => (2, "motion"), + }; + if RECEIPTS[slot].fetch_add(1, std::sync::atomic::Ordering::Relaxed) < 16 { + log::info!("CONTROL input received: kind={}", kind); + } match &event { ControlInput::MouseAbsolute {x,y} => input_worker.mouse_absolute_normalized(*x,*y,input_size), ControlInput::MouseRelative {dx,dy} => input_worker.mouse_relative(*dx,*dy), diff --git a/tests/fixtures/clipboard-official.py b/tests/fixtures/clipboard-official.py new file mode 100644 index 0000000..016c4bf --- /dev/null +++ b/tests/fixtures/clipboard-official.py @@ -0,0 +1,40 @@ +"""Official viewer clipboard fixture; only synthetic-marker match booleans are recorded.""" +import gi,json +from pathlib import Path +gi.require_version('Gtk','4.0'); gi.require_version('Gdk','4.0') +from gi.repository import Gtk,Gdk,GLib +assert Path('/proc/sys/kernel/hostname').read_text().strip()=='uu-hyprland-test' +state={'native_wayland':False,'mac_to_vm':False,'reverse_owned':False,'button_presses':0,'button_releases':0,'check_activations':0,'copy_activations':0,'window_active':False} +report=Path('/tmp/uuremote-clipboard-official.json') +app=Gtk.Application(application_id='dev.uuremote.ClipboardOfficial') +def activate(app): + window=Gtk.ApplicationWindow(application=app,title='UU clipboard official acceptance') + box=Gtk.Box(orientation=Gtk.Orientation.VERTICAL,spacing=24) + box.set_halign(Gtk.Align.CENTER);box.set_valign(Gtk.Align.CENTER) + label=Gtk.Label(label='UU Portal clipboard acceptance') + check=Gtk.Button(label='Check Mac β†’ VM') + copy=Gtk.Button(label='Copy VM β†’ Mac') + box.append(label);box.append(check);box.append(copy);window.set_child(box) + clipboard=window.get_clipboard() + def read(*_): + state['check_activations']+=1 + def done(source,result): + try: state['mac_to_vm']=source.read_text_finish(result)=='UU-Mac-to-VM δΈ­ζ–‡πŸ™‚' + except GLib.Error: state['mac_to_vm']=False + label.set_label('Mac β†’ VM: '+('PASS' if state['mac_to_vm'] else 'not matched')) + clipboard.read_text_async(None,done) + def write(*_): + state['copy_activations']+=1 + clipboard.set('UU-VM-to-Mac δΈ­ζ–‡πŸš€');state['reverse_owned']=True + label.set_label('VM marker copied') + check.connect('clicked',read);copy.connect('clicked',write) + window.connect('notify::is-active',lambda *_:state.update(window_active=window.is_active())) + gesture=Gtk.GestureClick();gesture.set_propagation_phase(Gtk.PropagationPhase.CAPTURE) + gesture.connect('pressed',lambda *_:state.update(button_presses=state['button_presses']+1)) + gesture.connect('released',lambda *_:state.update(button_releases=state['button_releases']+1)) + window.add_controller(gesture) + window.present();window.fullscreen() + state['native_wayland']='wayland' in type(Gdk.Display.get_default()).__name__.lower() + def record(): report.write_text(json.dumps(state));return True + GLib.timeout_add(200,record) +app.connect('activate',activate);app.run([])