diff --git a/Cargo.lock b/Cargo.lock index 54827da..bd7adc8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,6 +23,7 @@ name = "cursor-mover-app" version = "0.1.0" dependencies = [ "wayland-client", + "wayland-protocols-wlr", ] [[package]] @@ -154,6 +155,31 @@ dependencies = [ "wayland-scanner", ] +[[package]] +name = "wayland-protocols" +version = "0.32.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baeda9ffbcfc8cd6ddaade385eaf2393bd2115a69523c735f12242353c3df4f3" +dependencies = [ + "bitflags", + "wayland-backend", + "wayland-client", + "wayland-scanner", +] + +[[package]] +name = "wayland-protocols-wlr" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9597cdf02cf0c34cd5823786dce6b5ae8598f05c2daf5621b6e178d4f7345f3" +dependencies = [ + "bitflags", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-scanner", +] + [[package]] name = "wayland-scanner" version = "0.31.8" diff --git a/crates/cursor-mover-app/Cargo.toml b/crates/cursor-mover-app/Cargo.toml index 584947a..9ce41ff 100644 --- a/crates/cursor-mover-app/Cargo.toml +++ b/crates/cursor-mover-app/Cargo.toml @@ -11,6 +11,7 @@ readme = "README.md" [dependencies] wayland-client = "0.31.12" +wayland-protocols-wlr = { version = "0.3.10", features = ["client"] } [lints] workspace = true diff --git a/crates/cursor-mover-app/src/main.rs b/crates/cursor-mover-app/src/main.rs index e7a11a9..93d2387 100644 --- a/crates/cursor-mover-app/src/main.rs +++ b/crates/cursor-mover-app/src/main.rs @@ -1,3 +1,99 @@ -fn main() { - println!("Hello, world!"); +use wayland_client::{Connection, Dispatch, Proxy, QueueHandle, protocol::wl_registry}; +use wayland_protocols_wlr::virtual_pointer::v1::client::{ + zwlr_virtual_pointer_manager_v1::ZwlrVirtualPointerManagerV1, + zwlr_virtual_pointer_v1::ZwlrVirtualPointerV1, +}; + +#[derive(Default)] +struct AppData { + virtual_pointer: Option, +} + +impl Dispatch for AppData { + fn event( + state: &mut Self, + proxy: &ZwlrVirtualPointerV1, + event: ::Event, + data: &(), + conn: &Connection, + qhandle: &QueueHandle, + ) { + println!("VPointerData"); + } +} + +impl Dispatch for AppData { + fn event( + state: &mut Self, + proxy: &ZwlrVirtualPointerManagerV1, + event: ::Event, + data: &(), + conn: &Connection, + qhandle: &QueueHandle, + ) { + println!("ZwlrEvent") + } +} + +impl Dispatch for AppData { + fn event( + app_data: &mut Self, + registry: &wl_registry::WlRegistry, + event: wl_registry::Event, + _: &(), + _: &Connection, + queue_handle: &QueueHandle, + ) { + // When receiving events from the wl_registry, we are only interested in the + // `global` event, which signals a new available global. + // When receiving this event, we just print its characteristics in this example. + if let wl_registry::Event::Global { + name, + interface, + version, + } = event + { + //println!("[{name}] {interface} (v{version})"); + + if interface.as_str() == "zwlr_virtual_pointer_manager_v1" { + app_data.virtual_pointer.get_or_insert_with(|| { + let manager = registry.bind::( + name, + version, + queue_handle, + (), + ); + + let pointer = manager.create_virtual_pointer(None, queue_handle, ()); + + println!("Virtual pointer manager created"); + pointer + }); + } + } + } +} + +fn main() { + let connection = Connection::connect_to_env().unwrap(); + let display = connection.display(); + + let mut event_queue = connection.new_event_queue(); + let queue_handle = event_queue.handle(); + let _registry = display.get_registry(&queue_handle, ()); + println!("Advertized globals:"); + + let mut appdata = AppData::default(); + event_queue.roundtrip(&mut appdata).unwrap(); + + loop { + let dispatched = event_queue.dispatch_pending(&mut appdata).unwrap(); + if dispatched == 0 { + event_queue.flush().unwrap(); + } + + if let Some(pointer) = &appdata.virtual_pointer { + println!("Moving pointer?") + } + } }