//! Hyprland/wlroots native backend. No XWayland fallback and no input logging. #[cfg(all(target_os="linux", feature="wayland"))] extern "C" { fn uu_wl_init(out_w: *mut i32, out_h: *mut i32) -> i32; fn uu_wl_capture(buffer: *mut u8, length: usize) -> i32; fn uu_wl_move(x: i32, y: i32, relative: i32) -> i32; fn uu_wl_button(button: i32, pressed: i32) -> i32; fn uu_wl_key(symbol: u64, pressed: i32) -> i32; fn uu_wl_wake() -> i32; } pub fn init() -> Result<(u32,u32),String> { #[cfg(all(target_os="linux", feature="wayland"))] { let (mut w,mut h)=(0,0); let result=unsafe { uu_wl_init(&mut w,&mut h) }; if result != 0 || w <= 0 || h <= 0 { return Err(format!("Wayland initialization failed ({result}); requires screencopy, virtual keyboard and virtual pointer. Check UU_WAYLAND_OUTPUT and session environment.")); } return Ok((w as u32,h as u32)); } #[cfg(not(all(target_os="linux", feature="wayland")))] Err("Wayland backend requires Linux and a build with --features wayland".into()) } pub fn capture(buffer:&mut [u8]) -> Result<(),String> { #[cfg(all(target_os="linux", feature="wayland"))] { let result=unsafe { uu_wl_capture(buffer.as_mut_ptr(),buffer.len()) }; if result==0 { return Ok(()) } return Err(format!("Wayland capture failed ({result})")); } #[cfg(not(all(target_os="linux", feature="wayland")))] { let _=buffer; Err("Wayland capture unavailable".into()) } } pub fn wake()->Result<(),String> { #[cfg(all(target_os="linux", feature="wayland"))] { let result=unsafe { uu_wl_wake() }; if result==0 { return Ok(()); } return Err("Wayland output power control unavailable".into()); } #[cfg(not(all(target_os="linux", feature="wayland")))] Err("Wayland output power control unavailable".into()) } pub fn move_pointer(x:i32,y:i32,relative:bool)->i32 { #[cfg(all(target_os="linux", feature="wayland"))] { return unsafe { uu_wl_move(x,y,i32::from(relative)) }; } #[cfg(not(all(target_os="linux", feature="wayland")))] { let _=(x,y,relative); -1 } } pub fn button(button:i32,pressed:bool)->i32 { #[cfg(all(target_os="linux", feature="wayland"))] { return unsafe { uu_wl_button(button,i32::from(pressed)) }; } #[cfg(not(all(target_os="linux", feature="wayland")))] { let _=(button,pressed); -1 } } pub fn key(symbol:u64,pressed:bool)->i32 { #[cfg(all(target_os="linux", feature="wayland"))] { return unsafe { uu_wl_key(symbol,i32::from(pressed)) }; } #[cfg(not(all(target_os="linux", feature="wayland")))] { let _=(symbol,pressed); -1 } } /// A separate process owns capture; encoder cancellation closes its pipe. pub fn capture_stdout() -> Result<(),String> { use std::io::Write; let (w,h)=init()?; let mut frame=vec![0u8;(w as usize)*(h as usize)*4]; let mut stdout=std::io::stdout().lock(); let interval=std::time::Duration::from_nanos(1_000_000_000/crate::video::FPS); loop { let start=std::time::Instant::now(); capture(&mut frame)?; stdout.write_all(&frame).map_err(|e|format!("Capture pipe: {e}"))?; if let Some(left)=interval.checked_sub(start.elapsed()) { std::thread::sleep(left); } } } /// Use only in an isolated acceptance desktop; emits fixed test events, no logs. pub fn input_probe()->Result<(),String> { let (w,h)=init()?; wake()?; if move_pointer((w/4) as i32,(h/4) as i32,false)!=0 { return Err("Pointer probe failed".into()); } std::thread::sleep(std::time::Duration::from_millis(50)); if move_pointer((w/2) as i32,(h/2) as i32,false)!=0 { return Err("Pointer probe failed".into()); } std::thread::sleep(std::time::Duration::from_millis(100)); if button(1,true)!=0 || button(1,false)!=0 { return Err("Button probe failed".into()); } std::thread::sleep(std::time::Duration::from_millis(100)); if move_pointer(32,0,true)!=0 { return Err("Relative pointer probe failed".into()); } std::thread::sleep(std::time::Duration::from_millis(100)); for symbol in b"uuwayland" { if key(u64::from(*symbol),true)!=0 || key(u64::from(*symbol),false)!=0 { return Err("Keyboard probe failed".into()); } } std::thread::sleep(std::time::Duration::from_millis(250)); println!("Wayland test events sent; verify the native GTK acceptance report."); Ok(()) }