Connect to wayland socket

This commit is contained in:
2025-03-24 10:11:57 -07:00
parent a5c757169f
commit 6a0b47c57e
2 changed files with 32 additions and 2 deletions

7
Cargo.lock generated Normal file
View File

@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "ChloroStart-rs"
version = "0.1.0"

View File

@@ -1,3 +1,26 @@
fn main() {
println!("Hello, world!");
use std::{env, error::Error, os::unix::net::UnixStream};
fn wl_connect() -> Result<UnixStream, Box<dyn Error>> {
let wl_sock_path: String = format!(
"{}/{}",
env::var("XDG_RUNTIME_DIR")?,
env::var("WAYLAND_DISPLAY")?
);
let sock = UnixStream::connect(wl_sock_path)?;
Ok(sock)
}
fn main() ->Result<(), Box<dyn Error>> {
let mut wl_sock = match wl_connect() {
Ok(res) => res,
Err(err) => {
eprintln!("wl_connect failed: {}", err);
return Err(err);
}
};
Ok(())
}