diff options
author | Christian Duerr <contact@christianduerr.com> | 2021-10-23 07:16:47 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-23 07:16:47 +0000 |
commit | 1df7dc5171abfe1eab3e95be964f61c5876198f1 (patch) | |
tree | 315ceaa093b86b8e875512825302f38e32f697a4 /alacritty/src/input.rs | |
parent | d8a98f88295e59d6518ae780a9857c033a83161c (diff) | |
download | r-alacritty-1df7dc5171abfe1eab3e95be964f61c5876198f1.tar.gz r-alacritty-1df7dc5171abfe1eab3e95be964f61c5876198f1.tar.bz2 r-alacritty-1df7dc5171abfe1eab3e95be964f61c5876198f1.zip |
Add multi-window support
Previously Alacritty would always initialize only a single terminal
emulator window feeding into the winit event loop, however some
platforms like macOS expect all windows to be spawned by the same
process and this "daemon-mode" can also come with the advantage of
increased memory efficiency.
The event loop has been restructured to handle all window-specific
events only by the event processing context with the associated window
id. This makes it possible to add new terminal windows at any time using
the WindowContext::new function call.
Some preliminary tests have shown that for empty terminals, this reduces
the cost of additional terminal emulators from ~100M to ~6M. However at
this point the robustness of the daemon against issues with individual
terminals has not been refined, making the reliability of this system
questionable.
New windows can be created either by using the new `CreateNewWindow`
action, or with the `alacritty msg create-window` subcommand. The
subcommand sends a message to an IPC socket which Alacritty listens on,
its location can be found in the `ALACRITTY_SOCKET` environment
variable.
Fixes #607.
Diffstat (limited to 'alacritty/src/input.rs')
-rw-r--r-- | alacritty/src/input.rs | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/alacritty/src/input.rs b/alacritty/src/input.rs index 98a1b723..ca5742ee 100644 --- a/alacritty/src/input.rs +++ b/alacritty/src/input.rs @@ -34,9 +34,9 @@ use crate::daemon::start_daemon; use crate::display::hint::HintMatch; use crate::display::window::Window; use crate::display::Display; -use crate::event::{ClickState, Event, Mouse, TYPING_SEARCH_DELAY}; +use crate::event::{ClickState, Event, EventType, Mouse, TYPING_SEARCH_DELAY}; use crate::message_bar::{self, Message}; -use crate::scheduler::{Scheduler, TimerId}; +use crate::scheduler::{Scheduler, TimerId, Topic}; /// Font size change interval. pub const FONT_SIZE_STEP: f32 = 0.5; @@ -80,6 +80,7 @@ pub trait ActionContext<T: EventListener> { fn terminal(&self) -> &Term<T>; fn terminal_mut(&mut self) -> &mut Term<T>; fn spawn_new_instance(&mut self) {} + fn create_new_window(&mut self) {} fn change_font_size(&mut self, _delta: f32) {} fn reset_font_size(&mut self) {} fn pop_message(&mut self) {} @@ -319,6 +320,7 @@ impl<T: EventListener> Execute<T> for Action { Action::ClearHistory => ctx.terminal_mut().clear_screen(ClearMode::Saved), Action::ClearLogNotice => ctx.pop_message(), Action::SpawnNewInstance => ctx.spawn_new_instance(), + Action::CreateNewWindow => ctx.create_new_window(), Action::ReceiveChar | Action::None => (), } } @@ -594,7 +596,8 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> { } self.ctx.display().highlighted_hint = hint; - self.ctx.scheduler_mut().unschedule(TimerId::SelectionScrolling); + let timer_id = TimerId::new(Topic::SelectionScrolling, self.ctx.window().id()); + self.ctx.scheduler_mut().unschedule(timer_id); // Copy selection on release, to prevent flooding the display server. self.ctx.copy_selection(ClipboardType::Selection); @@ -731,8 +734,10 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> { // Reset search delay when the user is still typing. if self.ctx.search_active() { - if let Some(timer) = self.ctx.scheduler_mut().get_mut(TimerId::DelayedSearch) { - timer.deadline = Instant::now() + TYPING_SEARCH_DELAY; + let timer_id = TimerId::new(Topic::DelayedSearch, self.ctx.window().id()); + let scheduler = self.ctx.scheduler_mut(); + if let Some(timer) = scheduler.unschedule(timer_id) { + scheduler.schedule(timer.event, TYPING_SEARCH_DELAY, false, timer.id); } } @@ -911,6 +916,7 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> { fn update_selection_scrolling(&mut self, mouse_y: i32) { let dpr = self.ctx.window().dpr; let size = self.ctx.size_info(); + let window_id = self.ctx.window().id(); let scheduler = self.ctx.scheduler_mut(); // Scale constants by DPI. @@ -928,26 +934,18 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> { } else if mouse_y >= start_bottom { start_bottom - mouse_y - step } else { - scheduler.unschedule(TimerId::SelectionScrolling); + scheduler.unschedule(TimerId::new(Topic::SelectionScrolling, window_id)); return; }; // Scale number of lines scrolled based on distance to boundary. let delta = delta as i32 / step as i32; - let event = Event::Scroll(Scroll::Delta(delta)); + let event = Event::new(EventType::Scroll(Scroll::Delta(delta)), Some(window_id)); // Schedule event. - match scheduler.get_mut(TimerId::SelectionScrolling) { - Some(timer) => timer.event = event.into(), - None => { - scheduler.schedule( - event.into(), - SELECTION_SCROLLING_INTERVAL, - true, - TimerId::SelectionScrolling, - ); - }, - } + let timer_id = TimerId::new(Topic::SelectionScrolling, window_id); + scheduler.unschedule(timer_id); + scheduler.schedule(event, SELECTION_SCROLLING_INTERVAL, true, timer_id); } } @@ -1106,7 +1104,7 @@ mod tests { ..Mouse::default() }; - let mut message_buffer = MessageBuffer::new(); + let mut message_buffer = MessageBuffer::default(); let context = ActionContext { terminal: &mut terminal, |