diff --git a/CHANGELOG.md b/CHANGELOG.md index 32c678b0..15164698 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Resizing of windows without decorations - On Wayland, key repetition works again - On macOS, Alacritty will now use the integrated GPU again when available +- On Linux, the `WINIT_HIDPI_FACTOR` environment variable can be set from the config now ## Version 0.2.1 diff --git a/src/main.rs b/src/main.rs index e72df15d..11adb396 100644 --- a/src/main.rs +++ b/src/main.rs @@ -116,6 +116,9 @@ fn run(mut config: Config, options: &cli::Options) -> Result<(), Box> { info!("Configuration loaded from {}", config_path.display()); }; + // Set environment variables + tty::setup_env(&config); + // Create a display. // // The display manages a window and can draw the terminal diff --git a/src/tty/mod.rs b/src/tty/mod.rs index 5657b0fd..faed276d 100644 --- a/src/tty/mod.rs +++ b/src/tty/mod.rs @@ -13,9 +13,12 @@ // limitations under the License. // //! tty related functionality - use mio; -use std::io; +use std::{env, io}; + +use terminfo::Database; + +use config::Config; #[cfg(not(windows))] mod unix; @@ -34,7 +37,13 @@ pub trait EventedReadWrite { type Reader: io::Read; type Writer: io::Write; - fn register(&mut self, &mio::Poll, &mut Iterator, mio::Ready, mio::PollOpt) -> io::Result<()>; + fn register( + &mut self, + &mio::Poll, + &mut Iterator, + mio::Ready, + mio::PollOpt, + ) -> io::Result<()>; fn reregister(&mut self, &mio::Poll, mio::Ready, mio::PollOpt) -> io::Result<()>; fn deregister(&mut self, &mio::Poll) -> io::Result<()>; @@ -43,3 +52,26 @@ pub trait EventedReadWrite { fn writer(&mut self) -> &mut Self::Writer; fn write_token(&self) -> mio::Token; } + +// Setup environment variables +pub fn setup_env(config: &Config) { + // Default to 'alacritty' terminfo if it is available, otherwise + // default to 'xterm-256color'. May be overridden by user's config + // below. + env::set_var( + "TERM", + if Database::from_name("alacritty").is_ok() { + "alacritty" + } else { + "xterm-256color" + }, + ); + + // Advertise 24-bit color support + env::set_var("COLORTERM", "truecolor"); + + // Set env vars from config + for (key, value) in config.env().iter() { + env::set_var(key, value); + } +} diff --git a/src/tty/unix.rs b/src/tty/unix.rs index 08a2c4f3..d6ab6a46 100644 --- a/src/tty/unix.rs +++ b/src/tty/unix.rs @@ -23,7 +23,6 @@ use cli::Options; use mio; use libc::{self, c_int, pid_t, winsize, SIGCHLD, TIOCSCTTY, WNOHANG}; -use terminfo::Database; use std::os::unix::io::{FromRawFd, RawFd}; use std::fs::File; @@ -241,29 +240,15 @@ pub fn new( builder.stderr(unsafe { Stdio::from_raw_fd(slave) }); builder.stdout(unsafe { Stdio::from_raw_fd(slave) }); - // Setup environment + // Setup shell environment builder.env("LOGNAME", pw.name); builder.env("USER", pw.name); builder.env("SHELL", shell.program()); builder.env("HOME", pw.dir); - // TERM; default to 'alacritty' if it is available, otherwise - // default to 'xterm-256color'. May be overridden by user's config - // below. - let term = if Database::from_name("alacritty").is_ok() { - "alacritty" - } else { - "xterm-256color" - }; - builder.env("TERM", term); - - builder.env("COLORTERM", "truecolor"); // advertise 24-bit support if let Some(window_id) = window_id { builder.env("WINDOWID", format!("{}", window_id)); } - for (key, value) in config.env().iter() { - builder.env(key, value); - } builder.before_exec(move || { // Create a new process group