aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorns <portification@gmail.com>2017-05-28 05:08:28 +0200
committerJoe Wilm <jwilm@users.noreply.github.com>2017-05-27 20:08:28 -0700
commitb9ec141c927b333bfea5d8a285deedd164181dd8 (patch)
tree4e585aee9265f8da68d039ab33d396882455be3d
parent0e4edc5420ee7e1d240980686ff0244d2627993d (diff)
downloadalacritty-b9ec141c927b333bfea5d8a285deedd164181dd8.tar.gz
alacritty-b9ec141c927b333bfea5d8a285deedd164181dd8.zip
Find and set $WINDOWID to X11 window ID (#586)
-rw-r--r--src/display.rs4
-rw-r--r--src/main.rs5
-rw-r--r--src/tty.rs5
-rw-r--r--src/window.rs15
4 files changed, 27 insertions, 2 deletions
diff --git a/src/display.rs b/src/display.rs
index 20c2ce37..d8c10d18 100644
--- a/src/display.rs
+++ b/src/display.rs
@@ -335,4 +335,8 @@ impl Display {
api.clear();
});
}
+
+ pub fn get_window_id(&self) -> Option<usize> {
+ self.window.get_window_id()
+ }
}
diff --git a/src/main.rs b/src/main.rs
index 7c377f2b..b7db4dec 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -98,12 +98,15 @@ fn run(mut config: Config, options: cli::Options) -> Result<(), Box<Error>> {
let terminal = Term::new(&config, display.size().to_owned());
let terminal = Arc::new(FairMutex::new(terminal));
+ // Find the window ID for setting $WINDOWID
+ let window_id = display.get_window_id();
+
// Create the pty
//
// The pty forks a process to run the shell on the slave side of the
// pseudoterminal. A file descriptor for the master side is retained for
// reading/writing to the shell.
- let mut pty = tty::new(&config, &options, display.size());
+ let mut pty = tty::new(&config, &options, display.size(), window_id);
// Create the pseudoterminal I/O loop
//
diff --git a/src/tty.rs b/src/tty.rs
index bd291b16..4f0aa1cf 100644
--- a/src/tty.rs
+++ b/src/tty.rs
@@ -174,7 +174,7 @@ fn get_pw_entry(buf: &mut [i8; 1024]) -> Passwd {
}
/// Create a new tty and return a handle to interact with it.
-pub fn new<T: ToWinsize>(config: &Config, options: &Options, size: T) -> Pty {
+pub fn new<T: ToWinsize>(config: &Config, options: &Options, size: T, window_id: Option<usize>) -> Pty {
let win = size.to_winsize();
let mut buf = [0; 1024];
let pw = get_pw_entry(&mut buf);
@@ -206,6 +206,9 @@ pub fn new<T: ToWinsize>(config: &Config, options: &Options, size: T) -> Pty {
builder.env("SHELL", shell.program());
builder.env("HOME", pw.dir);
builder.env("TERM", "xterm-256color"); // default term until we can supply our own
+ if let Some(window_id) = window_id {
+ builder.env("WINDOWID", format!("{}", window_id));
+ }
for (key, value) in config.env().iter() {
builder.env(key, value);
}
diff --git a/src/window.rs b/src/window.rs
index 00f60c38..d0a51e6b 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -303,6 +303,21 @@ impl Window {
else { glutin::CursorState::Hide }).unwrap();
}
}
+
+ #[cfg(not(target_os = "macos"))]
+ pub fn get_window_id(&self) -> Option<usize> {
+ use glutin::os::unix::WindowExt;
+
+ match self.glutin_window.get_xlib_window() {
+ Some(xlib_window) => Some(xlib_window as usize),
+ None => None
+ }
+ }
+
+ #[cfg(target_os = "macos")]
+ pub fn get_window_id(&self) -> Option<usize> {
+ None
+ }
}
pub trait OsExtensions {