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 { + 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> { 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(config: &Config, options: &Options, size: T) -> Pty { +pub fn new(config: &Config, options: &Options, size: T, window_id: Option) -> 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(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 { + 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 { + None + } } pub trait OsExtensions {