mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-29 08:00:55 +03:00
initial x11 support
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
pub mod windows;
|
||||
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