aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock1
-rw-r--r--Cargo.toml3
-rw-r--r--src/lib.rs3
-rw-r--r--src/window.rs52
4 files changed, 57 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock
index ead11c18..a38adc1e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -24,6 +24,7 @@ dependencies = [
"serde_yaml 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"vte 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "x11-dl 2.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"xdg 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
diff --git a/Cargo.toml b/Cargo.toml
index 6ea5935c..10e6fbd3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -35,6 +35,9 @@ unicode-width = "0.1.4"
clippy = { version = "0.0.104", optional = true }
+[target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os="dragonfly", target_os="openbsd"))'.dependencies]
+x11-dl = "2.12.0"
+
[features]
default = ["err-println"]
# Enabling this feature makes shaders automatically reload when changed
diff --git a/src/lib.rs b/src/lib.rs
index be4cae33..0a3366ce 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -27,6 +27,9 @@
#[macro_use] extern crate log;
#[macro_use] extern crate serde_derive;
+#[cfg(any(target_os = "linux", target_os = "freebsd", target_os="dragonfly", target_os="openbsd"))]
+extern crate x11_dl;
+
extern crate cgmath;
extern crate copypasta;
extern crate errno;
diff --git a/src/window.rs b/src/window.rs
index a69bd0ea..b821c77b 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -217,10 +217,14 @@ impl Window {
window.make_current()?;
}
- Ok(Window {
+ let window = Window {
glutin_window: window,
cursor_visible: true,
- })
+ };
+
+ window.run_os_extensions();
+
+ Ok(window)
}
/// Get some properties about the device
@@ -301,6 +305,50 @@ impl Window {
}
}
+pub trait OsExtensions {
+ fn run_os_extensions(&self) {}
+}
+
+#[cfg(not(any(target_os = "linux", target_os = "freebsd", target_os="dragonfly", target_os="openbsd")))]
+impl OsExtensions for Window { }
+
+#[cfg(any(target_os = "linux", target_os = "freebsd", target_os="dragonfly", target_os="openbsd"))]
+impl OsExtensions for Window {
+ fn run_os_extensions(&self) {
+ use ::glutin::os::unix::WindowExt;
+ use ::x11_dl::xlib::{self, XA_CARDINAL, PropModeReplace};
+ use ::std::ffi::{CStr};
+ use ::std::ptr;
+ use ::libc::getpid;
+
+ let xlib_display = self.glutin_window.get_xlib_display();
+ let xlib_window = self.glutin_window.get_xlib_window();
+
+ if let (Some(xlib_window), Some(xlib_display)) = (xlib_window, xlib_display) {
+ let xlib = xlib::Xlib::open().expect("get xlib");
+
+ // Set _NET_WM_PID to process pid
+ unsafe {
+ let _net_wm_pid = CStr::from_ptr(b"_NET_WM_PID\0".as_ptr() as *const _);
+ let atom = (xlib.XInternAtom)(xlib_display as *mut _, _net_wm_pid.as_ptr(), 0);
+ let pid = getpid();
+
+ (xlib.XChangeProperty)(xlib_display as _, xlib_window as _, atom,
+ XA_CARDINAL, 32, PropModeReplace, &pid as *const i32 as *const u8, 1);
+
+ }
+ // Although this call doesn't actually pass any data, it does cause
+ // WM_CLIENT_MACHINE to be set. WM_CLIENT_MACHINE MUST be set if _NET_WM_PID is set
+ // (which we do above).
+ unsafe {
+ (xlib.XSetWMProperties)(xlib_display as _, xlib_window as _, ptr::null_mut(),
+ ptr::null_mut(), ptr::null_mut(), 0, ptr::null_mut(), ptr::null_mut(),
+ ptr::null_mut());
+ }
+ }
+ }
+}
+
impl Proxy {
/// Wakes up the event loop of the window
///