mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-18 13:55:23 -05:00
Set env variables before window start
The environment variables specified in the configuration file are now all set before the window is created. As a result, this makes it possible to add the `WINIT_HIDPI_FACTOR` env variable directly to the Alacritty configuration. This fixes https://github.com/jwilm/alacritty/issues/1768.
This commit is contained in:
parent
021b424858
commit
dba3cccf69
4 changed files with 40 additions and 19 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -116,6 +116,9 @@ fn run(mut config: Config, options: &cli::Options) -> Result<(), Box<Error>> {
|
|||
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
|
||||
|
|
|
@ -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<Item = &usize>, mio::Ready, mio::PollOpt) -> io::Result<()>;
|
||||
fn register(
|
||||
&mut self,
|
||||
&mio::Poll,
|
||||
&mut Iterator<Item = &usize>,
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<T: ToWinsize>(
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue