diff options
author | Christian Duerr <contact@christianduerr.com> | 2019-10-05 02:29:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-05 02:29:26 +0200 |
commit | 729eef0c933831bccfeac6a355bdb410787fbe5f (patch) | |
tree | 35cdf2e6427ad18bc53efbab4cab34a0af2054d7 /alacritty_terminal/src/tty | |
parent | b0c6fdff763f7271506d26d7e768e6377fdc691b (diff) | |
download | alacritty-729eef0c933831bccfeac6a355bdb410787fbe5f.tar.gz alacritty-729eef0c933831bccfeac6a355bdb410787fbe5f.zip |
Update to winit/glutin EventLoop 2.0
This takes the latest glutin master to port Alacritty to the EventLoop
2.0 rework.
This changes a big part of the event loop handling by pushing the event
loop in a separate thread from the renderer and running both in
parallel.
Fixes #2796.
Fixes #2694.
Fixes #2643.
Fixes #2625.
Fixes #2618.
Fixes #2601.
Fixes #2564.
Fixes #2456.
Fixes #2438.
Fixes #2334.
Fixes #2254.
Fixes #2217.
Fixes #1789.
Fixes #1750.
Fixes #1125.
Diffstat (limited to 'alacritty_terminal/src/tty')
-rw-r--r-- | alacritty_terminal/src/tty/mod.rs | 2 | ||||
-rw-r--r-- | alacritty_terminal/src/tty/unix.rs | 38 | ||||
-rw-r--r-- | alacritty_terminal/src/tty/windows/conpty.rs | 9 | ||||
-rw-r--r-- | alacritty_terminal/src/tty/windows/mod.rs | 5 | ||||
-rw-r--r-- | alacritty_terminal/src/tty/windows/winpty.rs | 8 |
5 files changed, 31 insertions, 31 deletions
diff --git a/alacritty_terminal/src/tty/mod.rs b/alacritty_terminal/src/tty/mod.rs index 16ae96ce..7150a42d 100644 --- a/alacritty_terminal/src/tty/mod.rs +++ b/alacritty_terminal/src/tty/mod.rs @@ -77,7 +77,7 @@ pub trait EventedPty: EventedReadWrite { } // Setup environment variables -pub fn setup_env(config: &Config) { +pub fn setup_env<C>(config: &Config<C>) { // Default to 'alacritty' terminfo if it is available, otherwise // default to 'xterm-256color'. May be overridden by user's config // below. diff --git a/alacritty_terminal/src/tty/unix.rs b/alacritty_terminal/src/tty/unix.rs index 77b5db43..a2a277a6 100644 --- a/alacritty_terminal/src/tty/unix.rs +++ b/alacritty_terminal/src/tty/unix.rs @@ -15,12 +15,13 @@ //! tty related functionality use crate::config::{Config, Shell}; -use crate::display::OnResize; +use crate::event::OnResize; use crate::term::SizeInfo; use crate::tty::{ChildEvent, EventedPty, EventedReadWrite}; use mio; use libc::{self, c_int, pid_t, winsize, TIOCSCTTY}; +use log::error; use nix::pty::openpty; use signal_hook::{self as sighook, iterator::Signals}; @@ -42,6 +43,13 @@ use std::sync::atomic::{AtomicUsize, Ordering}; /// Necessary to put this in static storage for `sigchld` to have access static PID: AtomicUsize = AtomicUsize::new(0); +macro_rules! die { + ($($arg:tt)*) => {{ + error!($($arg)*); + ::std::process::exit(1); + }} +} + pub fn child_pid() -> pid_t { PID.load(Ordering::Relaxed) as pid_t } @@ -133,24 +141,8 @@ pub struct Pty { signals_token: mio::Token, } -impl Pty { - /// Resize the pty - /// - /// Tells the kernel that the window size changed with the new pixel - /// dimensions and line/column counts. - pub fn resize<T: ToWinsize>(&self, size: &T) { - let win = size.to_winsize(); - - let res = unsafe { libc::ioctl(self.fd.as_raw_fd(), libc::TIOCSWINSZ, &win as *const _) }; - - if res < 0 { - die!("ioctl TIOCSWINSZ failed: {}", io::Error::last_os_error()); - } - } -} - /// Create a new tty and return a handle to interact with it. -pub fn new<T: ToWinsize>(config: &Config, size: &T, window_id: Option<usize>) -> Pty { +pub fn new<C>(config: &Config<C>, size: &SizeInfo, window_id: Option<usize>) -> Pty { let win_size = size.to_winsize(); let mut buf = [0; 1024]; let pw = get_pw_entry(&mut buf); @@ -241,12 +233,10 @@ pub fn new<T: ToWinsize>(config: &Config, size: &T, window_id: Option<usize>) -> signals, signals_token: mio::Token::from(0), }; - pty.resize(size); + pty.fd.as_raw_fd().on_resize(size); pty }, - Err(err) => { - die!("Failed to spawn command: {}", err); - }, + Err(err) => die!("Failed to spawn command: {}", err), } } @@ -365,6 +355,10 @@ impl<'a> ToWinsize for &'a SizeInfo { } impl OnResize for i32 { + /// Resize the pty + /// + /// Tells the kernel that the window size changed with the new pixel + /// dimensions and line/column counts. fn on_resize(&mut self, size: &SizeInfo) { let win = size.to_winsize(); diff --git a/alacritty_terminal/src/tty/windows/conpty.rs b/alacritty_terminal/src/tty/windows/conpty.rs index bd602c35..fe49b4dc 100644 --- a/alacritty_terminal/src/tty/windows/conpty.rs +++ b/alacritty_terminal/src/tty/windows/conpty.rs @@ -22,6 +22,7 @@ use std::ptr; use std::sync::Arc; use dunce::canonicalize; +use log::info; use mio_anonymous_pipes::{EventedAnonRead, EventedAnonWrite}; use miow; use widestring::U16CString; @@ -38,7 +39,7 @@ use winapi::um::winbase::{EXTENDED_STARTUPINFO_PRESENT, STARTF_USESTDHANDLES, ST use winapi::um::wincontypes::{COORD, HPCON}; use crate::config::{Config, Shell}; -use crate::display::OnResize; +use crate::event::OnResize; use crate::term::SizeInfo; /// Dynamically-loaded Pseudoconsole API from kernel32.dll @@ -98,7 +99,11 @@ impl Drop for Conpty { unsafe impl Send for Conpty {} unsafe impl Sync for Conpty {} -pub fn new<'a>(config: &Config, size: &SizeInfo, _window_id: Option<usize>) -> Option<Pty<'a>> { +pub fn new<'a, C>( + config: &Config<C>, + size: &SizeInfo, + _window_id: Option<usize>, +) -> Option<Pty<'a>> { if !config.enable_experimental_conpty_backend { return None; } diff --git a/alacritty_terminal/src/tty/windows/mod.rs b/alacritty_terminal/src/tty/windows/mod.rs index 7537d331..922dde26 100644 --- a/alacritty_terminal/src/tty/windows/mod.rs +++ b/alacritty_terminal/src/tty/windows/mod.rs @@ -20,12 +20,13 @@ use mio::{self, Evented, Poll, PollOpt, Ready, Token}; use mio_anonymous_pipes::{EventedAnonRead, EventedAnonWrite}; use mio_named_pipes::NamedPipe; +use log::info; use winapi::shared::winerror::WAIT_TIMEOUT; use winapi::um::synchapi::WaitForSingleObject; use winapi::um::winbase::WAIT_OBJECT_0; use crate::config::Config; -use crate::display::OnResize; +use crate::event::OnResize; use crate::term::SizeInfo; use crate::tty::{EventedPty, EventedReadWrite}; @@ -83,7 +84,7 @@ impl<'a> Pty<'a> { } } -pub fn new<'a>(config: &Config, size: &SizeInfo, window_id: Option<usize>) -> Pty<'a> { +pub fn new<'a, C>(config: &Config<C>, size: &SizeInfo, window_id: Option<usize>) -> Pty<'a> { if let Some(pty) = conpty::new(config, size, window_id) { info!("Using Conpty agent"); IS_CONPTY.store(true, Ordering::Relaxed); diff --git a/alacritty_terminal/src/tty/windows/winpty.rs b/alacritty_terminal/src/tty/windows/winpty.rs index 8795ca6d..db397ad9 100644 --- a/alacritty_terminal/src/tty/windows/winpty.rs +++ b/alacritty_terminal/src/tty/windows/winpty.rs @@ -22,13 +22,13 @@ use std::sync::Arc; use std::u16; use dunce::canonicalize; +use log::info; use mio_named_pipes::NamedPipe; use winapi::um::winbase::FILE_FLAG_OVERLAPPED; -use winpty::Config as WinptyConfig; -use winpty::{ConfigFlags, MouseMode, SpawnConfig, SpawnFlags, Winpty}; +use winpty::{Config as WinptyConfig, ConfigFlags, MouseMode, SpawnConfig, SpawnFlags, Winpty}; use crate::config::{Config, Shell}; -use crate::display::OnResize; +use crate::event::OnResize; use crate::term::SizeInfo; // We store a raw pointer because we need mutable access to call @@ -75,7 +75,7 @@ impl<'a> Drop for Agent<'a> { /// This is a placeholder value until we see how often long responses happen const AGENT_TIMEOUT: u32 = 10000; -pub fn new<'a>(config: &Config, size: &SizeInfo, _window_id: Option<usize>) -> Pty<'a> { +pub fn new<'a, C>(config: &Config<C>, size: &SizeInfo, _window_id: Option<usize>) -> Pty<'a> { // Create config let mut wconfig = WinptyConfig::new(ConfigFlags::empty()).unwrap(); |