78 lines
2.9 KiB
Rust
78 lines
2.9 KiB
Rust
//! Outil de test : pilote un pointeur virtuel (protocole wlr-virtual-pointer).
|
|
//!
|
|
//! Usage : vptr LARGEUR HAUTEUR [move X Y | down N | up N | sleep MS]...
|
|
//! où N est 1 (gauche) ou 3 (droit). Sert à tester l'overlay dans un Sway sans écran.
|
|
|
|
use std::time::{Duration, Instant};
|
|
|
|
use wayland_client::globals::{GlobalListContents, registry_queue_init};
|
|
use wayland_client::protocol::wl_pointer::ButtonState;
|
|
use wayland_client::protocol::wl_registry;
|
|
use wayland_client::{Connection, Dispatch, QueueHandle, delegate_noop};
|
|
use wayland_protocols_wlr::virtual_pointer::v1::client::zwlr_virtual_pointer_manager_v1::ZwlrVirtualPointerManagerV1;
|
|
use wayland_protocols_wlr::virtual_pointer::v1::client::zwlr_virtual_pointer_v1::ZwlrVirtualPointerV1;
|
|
|
|
struct State;
|
|
|
|
impl Dispatch<wl_registry::WlRegistry, GlobalListContents> for State {
|
|
fn event(
|
|
_: &mut Self,
|
|
_: &wl_registry::WlRegistry,
|
|
_: wl_registry::Event,
|
|
_: &GlobalListContents,
|
|
_: &Connection,
|
|
_: &QueueHandle<Self>,
|
|
) {
|
|
}
|
|
}
|
|
|
|
delegate_noop!(State: ZwlrVirtualPointerManagerV1);
|
|
delegate_noop!(State: ZwlrVirtualPointerV1);
|
|
|
|
fn main() {
|
|
let args: Vec<String> = std::env::args().skip(1).collect();
|
|
let num = |i: usize| -> u32 { args[i].parse().expect("nombre attendu") };
|
|
let (width, height) = (num(0), num(1));
|
|
|
|
let conn = Connection::connect_to_env().expect("connexion Wayland");
|
|
let (globals, mut queue) = registry_queue_init::<State>(&conn).expect("registre");
|
|
let qh = queue.handle();
|
|
let manager: ZwlrVirtualPointerManagerV1 = globals.bind(&qh, 1..=1, ()).expect("wlr-virtual-pointer absent");
|
|
let pointer = manager.create_virtual_pointer(None, &qh, ());
|
|
queue.roundtrip(&mut State).unwrap();
|
|
// Laisse aux clients le temps de voir apparaître le pointeur.
|
|
std::thread::sleep(Duration::from_millis(300));
|
|
|
|
let start = Instant::now();
|
|
let now = || start.elapsed().as_millis() as u32;
|
|
let button = |n: u32| if n == 3 { 0x111 } else { 0x110 };
|
|
let mut i = 2;
|
|
while i < args.len() {
|
|
match args[i].as_str() {
|
|
"move" => {
|
|
pointer.motion_absolute(now(), num(i + 1), num(i + 2), width, height);
|
|
i += 3;
|
|
}
|
|
"down" => {
|
|
pointer.button(now(), button(num(i + 1)), ButtonState::Pressed);
|
|
i += 2;
|
|
}
|
|
"up" => {
|
|
pointer.button(now(), button(num(i + 1)), ButtonState::Released);
|
|
i += 2;
|
|
}
|
|
"sleep" => {
|
|
std::thread::sleep(Duration::from_millis(num(i + 1) as u64));
|
|
i += 2;
|
|
continue;
|
|
}
|
|
other => panic!("commande inconnue : {other}"),
|
|
}
|
|
pointer.frame();
|
|
queue.roundtrip(&mut State).unwrap();
|
|
std::thread::sleep(Duration::from_millis(40));
|
|
}
|
|
pointer.destroy();
|
|
queue.roundtrip(&mut State).unwrap();
|
|
}
|