Compare commits

...

4 commits

Author SHA1 Message Date
33deea91aa better mimick dwm on version, also tested 2024-01-31 16:26:46 -08:00
df25227db5 remove unused import 2024-01-31 16:26:24 -08:00
809fc3de61 x11rb wm? 2024-01-31 16:24:55 -08:00
dd1fbfe0de proper executable name 2024-01-31 16:13:49 -08:00
3 changed files with 27 additions and 99 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" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" 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]] [[package]]
name = "errno" name = "errno"
version = "0.3.8" version = "0.3.8"
@ -62,37 +52,12 @@ version = "0.4.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" 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]] [[package]]
name = "rswm" name = "rswm"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"as-raw-xcb-connection", "as-raw-xcb-connection",
"tiny-xlib",
"x11rb", "x11rb",
"x11rb-protocol", "x11rb-protocol",
] ]
@ -110,50 +75,6 @@ dependencies = [
"windows-sys", "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]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.52.0" 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 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
tiny-xlib = "0.2.2"
as-raw-xcb-connection = "1.0.1" as-raw-xcb-connection = "1.0.1"
x11rb = { version = "0.13.0", features = ["extra-traits", "allow-unsafe-code"] } x11rb = { version = "0.13.0", features = ["extra-traits", "allow-unsafe-code"] }
x11rb-protocol = { version = "0.13.0", features = ["std"] } x11rb-protocol = { version = "0.13.0", features = ["std"] }

View file

@ -1,41 +1,49 @@
use anyhow::{anyhow, Context}; use std::process::exit;
use as_raw_xcb_connection::AsRawXcbConnection; use anyhow::anyhow;
use tiny_xlib::Display;
use x11rb::xcb_ffi::XCBConnection;
fn xcb_connection_from_display(display: &Display) -> anyhow::Result<XCBConnection> { use x11rb::{
let xcb_conn = display.as_raw_xcb_connection(); 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 fn become_wm<C: Connection>(conn: &C, screen: &Screen) -> anyhow::Result<()> {
unsafe { let change = ChangeWindowAttributesAux::default()
XCBConnection::from_raw_xcb_connection(xcb_conn.cast(), false).map_err(|e| anyhow!(e)) .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<()> { fn main() -> anyhow::Result<()> {
let mut args = std::env::args().skip(1); let mut args = std::env::args().skip(1);
if let Some(arg) = args.next() { if let Some(arg) = args.next() {
if arg != "-v" { if arg != "-v" {
return Err(anyhow!("usage: rwm [-v]")); return Err(anyhow!("usage: rswm [-v]"));
} else { } else {
println!(env!("CARGO_PKG_VERSION")); // TODO: test this println!("rswm-{}", env!("CARGO_PKG_VERSION"));
return Ok(()); return Ok(());
} }
} }
// TODO: Investigate LC_CTYPE and Locale stuff from dwm // 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 // we can Arc conn if we want to start threading
let display = Display::new(None).context("Failed to open display")?; 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 become_wm(&conn, screen)?;
tiny_xlib::register_error_handler(Box::new(|_, error| {
println!("X11 error: {:?}", error);
false
}))?;
// TODO: Check if there are other wms running // TODO: Check if there are other wms running