Compare commits

...

2 Commits

Author SHA1 Message Date
Alex Kotov ff9dabe3cd
Merge Rust creates 2022-09-09 18:11:21 +04:00
Alex Kotov 2fbe9f00d0
Use X11 FFI in Rust 2022-09-09 18:08:31 +04:00
8 changed files with 43 additions and 45 deletions

1
.gitignore vendored
View File

@ -10,5 +10,4 @@
# Rust
/Cargo.lock
/rust-polytreewm/Cargo.lock
/rust-winproto/Cargo.lock
/target/

View File

@ -1,5 +1,4 @@
[workspace]
members = [
"rust-polytreewm",
"rust-winproto",
]

View File

@ -19,10 +19,6 @@ RUST_SRC = \
rust-polytreewm/src/*.rs \
rust-polytreewm/src/**/*.rs
RUST_WINPROTO_SRC = \
rust-winproto/Cargo.toml \
rust-winproto/src/*.rs
RUST_APIS = src/constraints.h src/geom.h src/helpers.h src/settings.h
MODULES_SRC = \
@ -67,10 +63,10 @@ ALL_EXE = polytreewm $(TEST_EXE)
# Executables #
###############
polytreewm: src/main.o $(MODULES_OBJ) target/debug/libpolytreewm.a target/debug/libwinproto.a
polytreewm: src/main.o $(MODULES_OBJ) target/debug/libpolytreewm.a
$(CC) -o $@ $^ $(LDFLAGS)
%.test: %.o tests/main.o $(MODULES_OBJ) target/debug/libpolytreewm.a target/debug/libwinproto.a
%.test: %.o tests/main.o $(MODULES_OBJ) target/debug/libpolytreewm.a
$(CC) -o $@ $^ $(LDFLAGS)
################
@ -85,9 +81,6 @@ dwm.o: $(DWM_SRC) $(DWM_HDR)
target/debug/libpolytreewm.a: $(RUST_SRC)
$(CARGO) build
target/debug/libwinproto.a: $(RUST_WINPROTO_SRC)
$(CARGO) build
#########
# Tasks #
#########

View File

@ -20,3 +20,4 @@ crate-type = ["staticlib"]
ctor = "0.1.23"
env_logger = "0.9.0"
log = "0.4.17"
x11 = "2.20.0"

View File

@ -1,8 +1,10 @@
mod api;
mod constraints;
mod xbase;
pub mod geom;
pub mod settings;
pub mod unit;
pub use settings::Settings;
pub use xbase::Xbase;

View File

@ -0,0 +1,38 @@
use std::os::raw::*;
use std::ptr::null;
use x11::xlib::{self, Display};
pub struct Xbase {
program_title: String,
x_display: *mut Display,
x_screen: c_int,
x_root: c_ulong,
}
impl Xbase {
pub fn new(
program_title: String,
) -> Result<Self, Box<dyn std::error::Error>> {
unsafe {
if xlib::XSupportsLocale() == 0 {
return Err("no locale support in X".into());
}
let x_display = xlib::XOpenDisplay(null());
if x_display.is_null() {
return Err("cannot open X display".into());
}
let x_screen = xlib::XDefaultScreen(x_display);
let x_root = xlib::XRootWindow(x_display, x_screen);
Ok(Self {
program_title,
x_display,
x_screen,
x_root,
})
}
}
}

View File

@ -1,12 +0,0 @@
[package]
name = "winproto"
version = "0.0.0"
edition = "2021"
publish = false
[lib]
name = "winproto"
crate-type = ["staticlib"]
[dependencies]
x11rb = "0.10.1"

View File

@ -1,22 +0,0 @@
use x11rb::atom_manager;
atom_manager! {
pub AtomCollection: AtomCollectionCookie {
WM_PROTOCOLS,
WM_DELETE_WINDOW,
WM_STATE,
WM_TAKE_FOCUS,
_NET_ACTIVE_WINDOW,
_NET_SUPPORTED,
_NET_WM_NAME,
_NET_WM_STATE,
_NET_SUPPORTING_WM_CHECK,
_NET_WM_STATE_FULLSCREEN,
_NET_WM_WINDOW_TYPE,
_NET_WM_WINDOW_TYPE_DIALOG,
_NET_CLIENT_LIST,
UTF8_STRING,
}
}