initial x11 support

This commit is contained in:
Ferdinand Schober
2023-02-12 22:15:19 +01:00
parent b20100b28e
commit 20cf6d450a
6 changed files with 60 additions and 0 deletions

11
Cargo.lock generated
View File

@@ -245,6 +245,7 @@ dependencies = [
"wayland-protocols-misc",
"wayland-protocols-wlr",
"winapi",
"x11",
]
[[package]]
@@ -968,3 +969,13 @@ checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69"
dependencies = [
"winapi",
]
[[package]]
name = "x11"
version = "2.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "502da5464ccd04011667b11c435cb992822c2c0dbde1770c988480d312a0db2e"
dependencies = [
"libc",
"pkg-config",
]

View File

@@ -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-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"] }
x11 = { version = "2.21.0", features = ["xlib", "xtest"] }
[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.9", features = ["winuser"] }

View File

@@ -1,2 +1,3 @@
pub mod windows;
pub mod wayland;
pub mod x11;

2
src/backend/x11.rs Normal file
View File

@@ -0,0 +1,2 @@
pub mod consumer;
pub mod producer;

View 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!(),
}
}
}

View File