Compare commits
No commits in common. "33deea91aac009ae5e4a52d7dbb3058884d7a5a8" and "a4331e93a3eaf54cda5888d67d63b6ae4695b8db" have entirely different histories.
33deea91aa
...
a4331e93a3
3 changed files with 99 additions and 27 deletions
79
Cargo.lock
generated
79
Cargo.lock
generated
|
@ -20,6 +20,16 @@ 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"
|
||||
|
@ -52,12 +62,37 @@ 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",
|
||||
]
|
||||
|
@ -75,6 +110,50 @@ 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"
|
||||
|
|
|
@ -6,6 +6,7 @@ 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"] }
|
||||
|
|
46
src/main.rs
46
src/main.rs
|
@ -1,49 +1,41 @@
|
|||
use std::process::exit;
|
||||
use anyhow::{anyhow, Context};
|
||||
|
||||
use anyhow::anyhow;
|
||||
use as_raw_xcb_connection::AsRawXcbConnection;
|
||||
use tiny_xlib::Display;
|
||||
use x11rb::xcb_ffi::XCBConnection;
|
||||
|
||||
use x11rb::{
|
||||
connect, connection::Connection, protocol::xproto::ConnectionExt, xcb_ffi::ReplyError,
|
||||
};
|
||||
use x11rb_protocol::protocol::xproto::{ChangeWindowAttributesAux, EventMask, Screen};
|
||||
fn xcb_connection_from_display(display: &Display) -> anyhow::Result<XCBConnection> {
|
||||
let xcb_conn = display.as_raw_xcb_connection();
|
||||
|
||||
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);
|
||||
}
|
||||
// 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))
|
||||
}
|
||||
|
||||
res.map_err(|e| anyhow!(e))
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let mut args = std::env::args().skip(1);
|
||||
if let Some(arg) = args.next() {
|
||||
if arg != "-v" {
|
||||
return Err(anyhow!("usage: rswm [-v]"));
|
||||
return Err(anyhow!("usage: rwm [-v]"));
|
||||
} else {
|
||||
println!("rswm-{}", env!("CARGO_PKG_VERSION"));
|
||||
println!(env!("CARGO_PKG_VERSION")); // TODO: test this
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Investigate LC_CTYPE and Locale stuff from dwm
|
||||
|
||||
// we can Arc conn if we want to start threading
|
||||
let (conn, screen_num) = connect(None)?;
|
||||
// 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")?;
|
||||
|
||||
let screen = &conn.setup().roots[screen_num];
|
||||
let _conn = xcb_connection_from_display(&display)?;
|
||||
|
||||
become_wm(&conn, screen)?;
|
||||
// Registering a baby error handler for now
|
||||
tiny_xlib::register_error_handler(Box::new(|_, error| {
|
||||
println!("X11 error: {:?}", error);
|
||||
false
|
||||
}))?;
|
||||
|
||||
// TODO: Check if there are other wms running
|
||||
|
||||
|
|
Loading…
Reference in a new issue