mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-11 13:51:01 -05:00
Find and set $WINDOWID to X11 window ID (#586)
This commit is contained in:
parent
0e4edc5420
commit
b9ec141c92
4 changed files with 27 additions and 2 deletions
|
@ -335,4 +335,8 @@ impl Display {
|
|||
api.clear();
|
||||
});
|
||||
}
|
||||
|
||||
pub fn get_window_id(&self) -> Option<usize> {
|
||||
self.window.get_window_id()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
//
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue