x11rb wm?

main
Zynh0722 2024-01-31 16:24:55 -08:00
parent dd1fbfe0de
commit 809fc3de61
3 changed files with 25 additions and 97 deletions

79
Cargo.lock generated
View File

@ -20,16 +20,6 @@ version = "2.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf"
[[package]]
name = "ctor"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30d2b3721e861707777e3195b0158f950ae6dc4a27e4d02ff9f67e3eb3de199e"
dependencies = [
"quote",
"syn",
]
[[package]]
name = "errno"
version = "0.3.8"
@ -62,37 +52,12 @@ version = "0.4.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c"
[[package]]
name = "pin-project-lite"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58"
[[package]]
name = "proc-macro2"
version = "1.0.78"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rswm"
version = "0.1.0"
dependencies = [
"anyhow",
"as-raw-xcb-connection",
"tiny-xlib",
"x11rb",
"x11rb-protocol",
]
@ -110,50 +75,6 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "syn"
version = "2.0.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "tiny-xlib"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4098d49269baa034a8d1eae9bd63e9fa532148d772121dace3bcd6a6c98eb6d"
dependencies = [
"as-raw-xcb-connection",
"ctor",
"tracing",
]
[[package]]
name = "tracing"
version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
dependencies = [
"pin-project-lite",
"tracing-core",
]
[[package]]
name = "tracing-core"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "windows-sys"
version = "0.52.0"

View File

@ -6,7 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tiny-xlib = "0.2.2"
as-raw-xcb-connection = "1.0.1"
x11rb = { version = "0.13.0", features = ["extra-traits", "allow-unsafe-code"] }
x11rb-protocol = { version = "0.13.0", features = ["std"] }

View File

@ -1,18 +1,30 @@
use anyhow::{anyhow, Context};
use std::{io::ErrorKind, process::exit};
use as_raw_xcb_connection::AsRawXcbConnection;
use tiny_xlib::Display;
use x11rb::xcb_ffi::XCBConnection;
use anyhow::anyhow;
fn xcb_connection_from_display(display: &Display) -> anyhow::Result<XCBConnection> {
let xcb_conn = display.as_raw_xcb_connection();
use x11rb::{
connect, connection::Connection, protocol::xproto::ConnectionExt, xcb_ffi::ReplyError,
};
use x11rb_protocol::protocol::xproto::{ChangeWindowAttributesAux, EventMask, Screen};
// Safety: taking a pointer straight from the safe tiny_x11 to the safe x11rb
unsafe {
XCBConnection::from_raw_xcb_connection(xcb_conn.cast(), false).map_err(|e| anyhow!(e))
fn become_wm<C: Connection>(conn: &C, screen: &Screen) -> anyhow::Result<()> {
let change = ChangeWindowAttributesAux::default()
.event_mask(EventMask::SUBSTRUCTURE_REDIRECT | EventMask::SUBSTRUCTURE_NOTIFY);
let res = conn.change_window_attributes(screen.root, &change)?.check();
if let Err(ReplyError::X11Error(ref error)) = res {
use x11rb_protocol::protocol::ErrorKind;
if error.error_kind == ErrorKind::Access {
eprintln!("rswm: another window manager is already running");
exit(1);
}
}
res.map_err(|e| anyhow!(e))
}
fn main() -> anyhow::Result<()> {
let mut args = std::env::args().skip(1);
if let Some(arg) = args.next() {
@ -26,16 +38,12 @@ fn main() -> anyhow::Result<()> {
// TODO: Investigate LC_CTYPE and Locale stuff from dwm
// Here we open a display and get an x11rb connection, we could also just use xcb I think
let display = Display::new(None).context("Failed to open display")?;
// we can Arc conn if we want to start threading
let (conn, screen_num) = connect(None)?;
let _conn = xcb_connection_from_display(&display)?;
let screen = &conn.setup().roots[screen_num];
// Registering a baby error handler for now
tiny_xlib::register_error_handler(Box::new(|_, error| {
println!("X11 error: {:?}", error);
false
}))?;
become_wm(&conn, screen)?;
// TODO: Check if there are other wms running