From ed816fa7ad0b44a4ca8167bfb4b50a7e080d8a75 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Tue, 25 Dec 2018 19:23:03 +0530 Subject: [PATCH] Initial commit --- .gitignore | 2 ++ Cargo.lock | 30 ++++++++++++++++++++++++++++++ Cargo.toml | 10 ++++++++++ build.rs | 4 ++++ src/main.rs | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 build.rs create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53eaa21 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +**/*.rs.bk diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..01b2bf5 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,30 @@ +[[package]] +name = "libc" +version = "0.2.45" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "pkg-config" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rwmstatus" +version = "0.1.0" +dependencies = [ + "x11 2.18.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "x11" +version = "2.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[metadata] +"checksum libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "2d2857ec59fadc0773853c664d2d18e7198e83883e7060b63c924cb077bd5c74" +"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c" +"checksum x11 2.18.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39697e3123f715483d311b5826e254b6f3cfebdd83cf7ef3358f579c3d68e235" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..abfe8ef --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "rwmstatus" +version = "0.1.0" +authors = ["Wojciech Kozlowski "] + +links = "X11" +build = "build.rs" + +[dependencies] +x11 = "2" \ No newline at end of file diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..8a05a8f --- /dev/null +++ b/build.rs @@ -0,0 +1,4 @@ +fn main() { + println!("cargo:rustc-link-lib=X11"); + println!("cargo:rustc-link-search=native=/usr/X11R6/lib"); +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..ff08d52 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,35 @@ +extern crate x11; + +use x11::xlib::Display; +use x11::xlib::{XDefaultRootWindow, XOpenDisplay, XStoreName, XSync}; + +use std::ptr; +use std::process; +use std::thread; +use std::time; + +use std::ffi::CString; + +fn main() { + let display: *mut Display; + + unsafe { + display = XOpenDisplay(ptr::null()); + } + + if display == ptr::null_mut() { + eprintln!("rwmstatus: cannot open display."); + process::exit(1); + } + + loop { + let status = CString::new("Hello!").expect("CString::new failed when setting status."); + + unsafe { + XStoreName(display, XDefaultRootWindow(display), status.as_ptr()); + XSync(display, false as i32); + } + + thread::sleep(time::Duration::from_secs(1)); + } +}