mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-20 06:23:19 +03:00
initial x11 support
This commit is contained in:
11
Cargo.lock
generated
11
Cargo.lock
generated
@@ -245,6 +245,7 @@ dependencies = [
|
|||||||
"wayland-protocols-misc",
|
"wayland-protocols-misc",
|
||||||
"wayland-protocols-wlr",
|
"wayland-protocols-wlr",
|
||||||
"winapi",
|
"winapi",
|
||||||
|
"x11",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -968,3 +969,13 @@ checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "x11"
|
||||||
|
version = "2.21.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "502da5464ccd04011667b11c435cb992822c2c0dbde1770c988480d312a0db2e"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"pkg-config",
|
||||||
|
]
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ wayland-client = { git="https://github.com/Smithay/wayland-rs.git" }
|
|||||||
wayland-protocols = { git="https://github.com/Smithay/wayland-rs.git", features=["client", "staging", "unstable"] }
|
wayland-protocols = { git="https://github.com/Smithay/wayland-rs.git", features=["client", "staging", "unstable"] }
|
||||||
wayland-protocols-wlr = { git="https://github.com/Smithay/wayland-rs.git", features=["client", "server"] }
|
wayland-protocols-wlr = { git="https://github.com/Smithay/wayland-rs.git", features=["client", "server"] }
|
||||||
wayland-protocols-misc = { git="https://github.com/Smithay/wayland-rs.git", features=["client", "server"] }
|
wayland-protocols-misc = { git="https://github.com/Smithay/wayland-rs.git", features=["client", "server"] }
|
||||||
|
x11 = { version = "2.21.0", features = ["xlib", "xtest"] }
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
winapi = { version = "0.3.9", features = ["winuser"] }
|
winapi = { version = "0.3.9", features = ["winuser"] }
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
pub mod windows;
|
pub mod windows;
|
||||||
pub mod wayland;
|
pub mod wayland;
|
||||||
|
pub mod x11;
|
||||||
|
|||||||
2
src/backend/x11.rs
Normal file
2
src/backend/x11.rs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
pub mod consumer;
|
||||||
|
pub mod producer;
|
||||||
45
src/backend/x11/consumer.rs
Normal file
45
src/backend/x11/consumer.rs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#![cfg(unix)]
|
||||||
|
use std::{sync::mpsc::Receiver, ptr};
|
||||||
|
use x11::{xtest, xlib};
|
||||||
|
|
||||||
|
use crate::{client::{ClientHandle, Client}, event::Event};
|
||||||
|
|
||||||
|
fn open_display() -> Option<*mut xlib::Display> {
|
||||||
|
unsafe {
|
||||||
|
match xlib::XOpenDisplay(ptr::null()) {
|
||||||
|
d if d == ptr::null::<xlib::Display>() as *mut xlib::Display => None,
|
||||||
|
display => Some(display),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn relative_motion(display: *mut xlib::Display, dx: i32, dy: i32) {
|
||||||
|
unsafe {
|
||||||
|
xtest::XTestFakeRelativeMotionEvent(display, dx, dy, 0, 0);
|
||||||
|
xlib::XFlush(display);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run(event_rx: Receiver<(Event, ClientHandle)>, _clients: Vec<Client>) {
|
||||||
|
let display = match open_display() {
|
||||||
|
None => panic!("could not open display!"),
|
||||||
|
Some(display) => display,
|
||||||
|
};
|
||||||
|
|
||||||
|
loop {
|
||||||
|
match event_rx.recv().expect("event receiver unavailable").0 {
|
||||||
|
Event::Pointer(pointer_event) => {
|
||||||
|
match pointer_event {
|
||||||
|
crate::event::PointerEvent::Motion { time: _, relative_x, relative_y } => {
|
||||||
|
relative_motion(display, relative_x as i32, relative_y as i32);
|
||||||
|
},
|
||||||
|
crate::event::PointerEvent::Button { .. } => todo!(),
|
||||||
|
crate::event::PointerEvent::Axis { .. } => todo!(),
|
||||||
|
crate::event::PointerEvent::Frame { } => todo!(),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Event::Keyboard(_) => todo!(),
|
||||||
|
Event::Release() => todo!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
0
src/backend/x11/producer.rs
Normal file
0
src/backend/x11/producer.rs
Normal file
Reference in New Issue
Block a user