2020-05-05 22:50:23 +00:00
|
|
|
//! Process window events.
|
2020-06-06 18:49:14 +00:00
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
use std::borrow::Cow;
|
2020-07-09 21:45:22 +00:00
|
|
|
use std::cmp::{max, min};
|
2019-10-05 00:29:26 +00:00
|
|
|
use std::env;
|
2020-07-10 19:32:44 +00:00
|
|
|
use std::fmt::Debug;
|
2020-11-07 04:48:48 +00:00
|
|
|
#[cfg(not(any(target_os = "macos", windows)))]
|
2019-10-05 00:29:26 +00:00
|
|
|
use std::fs;
|
|
|
|
use std::fs::File;
|
|
|
|
use std::io::Write;
|
2020-01-10 01:51:37 +00:00
|
|
|
use std::mem;
|
2020-11-13 05:40:09 +00:00
|
|
|
use std::ops::RangeInclusive;
|
2020-04-09 01:02:10 +00:00
|
|
|
use std::path::PathBuf;
|
2020-05-03 23:29:11 +00:00
|
|
|
#[cfg(not(any(target_os = "macos", windows)))]
|
|
|
|
use std::sync::atomic::Ordering;
|
2019-10-05 00:29:26 +00:00
|
|
|
use std::sync::Arc;
|
2020-07-09 21:45:22 +00:00
|
|
|
use std::time::{Duration, Instant};
|
2019-10-05 00:29:26 +00:00
|
|
|
|
|
|
|
use glutin::dpi::PhysicalSize;
|
2020-06-23 09:57:15 +00:00
|
|
|
use glutin::event::{ElementState, Event as GlutinEvent, ModifiersState, MouseButton, WindowEvent};
|
2020-02-07 13:44:11 +00:00
|
|
|
use glutin::event_loop::{ControlFlow, EventLoop, EventLoopProxy, EventLoopWindowTarget};
|
2019-10-05 00:29:26 +00:00
|
|
|
use glutin::platform::desktop::EventLoopExtDesktop;
|
2020-10-12 09:22:36 +00:00
|
|
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
2020-04-09 01:02:10 +00:00
|
|
|
use glutin::platform::unix::EventLoopWindowTargetExtUnix;
|
2020-07-10 19:32:44 +00:00
|
|
|
use log::info;
|
2019-10-05 00:29:26 +00:00
|
|
|
use serde_json as json;
|
|
|
|
|
2020-05-17 21:14:13 +00:00
|
|
|
#[cfg(target_os = "macos")]
|
2020-07-18 01:27:41 +00:00
|
|
|
use crossfont::set_font_smoothing;
|
|
|
|
use crossfont::{self, Size};
|
2019-10-05 00:29:26 +00:00
|
|
|
|
|
|
|
use alacritty_terminal::config::LOG_TARGET_CONFIG;
|
2020-07-09 21:45:22 +00:00
|
|
|
use alacritty_terminal::event::{Event as TerminalEvent, EventListener, Notify, OnResize};
|
|
|
|
use alacritty_terminal::grid::{Dimensions, Scroll};
|
2020-07-15 21:27:32 +00:00
|
|
|
use alacritty_terminal::index::{Boundary, Column, Direction, Line, Point, Side};
|
2020-03-18 02:35:08 +00:00
|
|
|
use alacritty_terminal::selection::{Selection, SelectionType};
|
2019-10-05 00:29:26 +00:00
|
|
|
use alacritty_terminal::sync::FairMutex;
|
2020-06-06 21:33:20 +00:00
|
|
|
use alacritty_terminal::term::{ClipboardType, SizeInfo, Term, TermMode};
|
2019-11-16 21:11:56 +00:00
|
|
|
#[cfg(not(windows))]
|
2019-10-05 00:29:26 +00:00
|
|
|
use alacritty_terminal::tty;
|
|
|
|
|
2020-08-22 20:55:27 +00:00
|
|
|
use crate::cli::Options as CLIOptions;
|
2020-06-06 21:33:20 +00:00
|
|
|
use crate::clipboard::Clipboard;
|
2019-10-05 00:29:26 +00:00
|
|
|
use crate::config;
|
|
|
|
use crate::config::Config;
|
2020-07-10 19:32:44 +00:00
|
|
|
use crate::daemon::start_daemon;
|
2020-07-09 21:45:22 +00:00
|
|
|
use crate::display::{Display, DisplayUpdate};
|
2019-11-11 21:05:24 +00:00
|
|
|
use crate::input::{self, ActionContext as _, FONT_SIZE_STEP};
|
2020-11-07 04:48:48 +00:00
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
use crate::macos;
|
2020-07-11 17:03:09 +00:00
|
|
|
use crate::message_bar::{Message, MessageBuffer};
|
2020-07-09 21:45:22 +00:00
|
|
|
use crate::scheduler::{Scheduler, TimerId};
|
2020-03-18 02:35:08 +00:00
|
|
|
use crate::url::{Url, Urls};
|
2019-10-05 00:29:26 +00:00
|
|
|
use crate::window::Window;
|
|
|
|
|
2020-07-09 21:45:22 +00:00
|
|
|
/// Duration after the last user input until an unlimited search is performed.
|
|
|
|
pub const TYPING_SEARCH_DELAY: Duration = Duration::from_millis(500);
|
|
|
|
|
|
|
|
/// Maximum number of lines for the blocking search while still typing the search regex.
|
|
|
|
const MAX_SEARCH_WHILE_TYPING: Option<usize> = Some(1000);
|
|
|
|
|
2020-06-18 01:02:56 +00:00
|
|
|
/// Events dispatched through the UI event loop.
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub enum Event {
|
|
|
|
TerminalEvent(TerminalEvent),
|
|
|
|
DPRChanged(f64, (u32, u32)),
|
|
|
|
Scroll(Scroll),
|
|
|
|
ConfigReload(PathBuf),
|
|
|
|
Message(Message),
|
2020-07-09 21:45:22 +00:00
|
|
|
SearchNext,
|
2020-06-18 01:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Event> for GlutinEvent<'_, Event> {
|
|
|
|
fn from(event: Event) -> Self {
|
|
|
|
GlutinEvent::UserEvent(event)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<TerminalEvent> for Event {
|
|
|
|
fn from(event: TerminalEvent) -> Self {
|
|
|
|
Event::TerminalEvent(event)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-09 21:45:22 +00:00
|
|
|
/// Regex search state.
|
|
|
|
pub struct SearchState {
|
|
|
|
/// Search string regex.
|
|
|
|
regex: Option<String>,
|
|
|
|
|
|
|
|
/// Search direction.
|
|
|
|
direction: Direction,
|
|
|
|
|
|
|
|
/// Change in display offset since the beginning of the search.
|
|
|
|
display_offset_delta: isize,
|
|
|
|
|
2020-07-15 21:27:32 +00:00
|
|
|
/// Search origin in viewport coordinates relative to original display offset.
|
|
|
|
origin: Point,
|
2020-11-13 05:40:09 +00:00
|
|
|
|
|
|
|
/// Focused match during active search.
|
|
|
|
focused_match: Option<RangeInclusive<Point<usize>>>,
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
|
2020-07-09 21:45:22 +00:00
|
|
|
impl SearchState {
|
|
|
|
fn new() -> Self {
|
|
|
|
Self::default()
|
|
|
|
}
|
2020-07-17 01:26:53 +00:00
|
|
|
|
|
|
|
/// Search regex text if a search is active.
|
|
|
|
pub fn regex(&self) -> Option<&String> {
|
|
|
|
self.regex.as_ref()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Direction of the search from the search origin.
|
|
|
|
pub fn direction(&self) -> Direction {
|
|
|
|
self.direction
|
|
|
|
}
|
2020-11-13 05:40:09 +00:00
|
|
|
|
|
|
|
/// Focused match during vi-less search.
|
|
|
|
pub fn focused_match(&self) -> Option<&RangeInclusive<Point<usize>>> {
|
|
|
|
self.focused_match.as_ref()
|
|
|
|
}
|
2020-07-09 21:45:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for SearchState {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
direction: Direction::Right,
|
|
|
|
display_offset_delta: 0,
|
2020-07-15 21:27:32 +00:00
|
|
|
origin: Point::default(),
|
2020-11-13 05:40:09 +00:00
|
|
|
focused_match: None,
|
2020-07-09 21:45:22 +00:00
|
|
|
regex: None,
|
|
|
|
}
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct ActionContext<'a, N, T> {
|
|
|
|
pub notifier: &'a mut N,
|
|
|
|
pub terminal: &'a mut Term<T>,
|
2020-06-06 21:33:20 +00:00
|
|
|
pub clipboard: &'a mut Clipboard,
|
2019-10-05 00:29:26 +00:00
|
|
|
pub size_info: &'a mut SizeInfo,
|
|
|
|
pub mouse: &'a mut Mouse,
|
|
|
|
pub received_count: &'a mut usize,
|
|
|
|
pub suppress_chars: &'a mut bool,
|
2019-11-11 21:05:24 +00:00
|
|
|
pub modifiers: &'a mut ModifiersState,
|
2019-10-05 00:29:26 +00:00
|
|
|
pub window: &'a mut Window,
|
|
|
|
pub message_buffer: &'a mut MessageBuffer,
|
2019-11-03 19:02:26 +00:00
|
|
|
pub display_update_pending: &'a mut DisplayUpdate,
|
|
|
|
pub config: &'a mut Config,
|
2020-02-07 13:44:11 +00:00
|
|
|
pub event_loop: &'a EventLoopWindowTarget<Event>,
|
2020-03-18 02:35:08 +00:00
|
|
|
pub urls: &'a Urls,
|
2020-06-18 01:02:56 +00:00
|
|
|
pub scheduler: &'a mut Scheduler,
|
2020-07-09 21:45:22 +00:00
|
|
|
pub search_state: &'a mut SearchState,
|
2020-08-22 20:55:27 +00:00
|
|
|
cli_options: &'a CLIOptions,
|
2019-11-03 19:02:26 +00:00
|
|
|
font_size: &'a mut Size,
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionContext<'a, N, T> {
|
|
|
|
fn write_to_pty<B: Into<Cow<'static, [u8]>>>(&mut self, val: B) {
|
|
|
|
self.notifier.notify(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn size_info(&self) -> SizeInfo {
|
|
|
|
*self.size_info
|
|
|
|
}
|
|
|
|
|
|
|
|
fn scroll(&mut self, scroll: Scroll) {
|
2020-07-15 21:27:32 +00:00
|
|
|
let old_offset = self.terminal.grid().display_offset() as isize;
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
self.terminal.scroll_display(scroll);
|
|
|
|
|
2020-07-15 21:27:32 +00:00
|
|
|
// Keep track of manual display offset changes during search.
|
|
|
|
if self.search_active() {
|
|
|
|
let display_offset = self.terminal.grid().display_offset();
|
|
|
|
self.search_state.display_offset_delta += old_offset - display_offset as isize;
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Update selection.
|
2020-03-18 02:35:08 +00:00
|
|
|
if self.terminal.mode().contains(TermMode::VI)
|
2020-05-30 20:45:44 +00:00
|
|
|
&& self.terminal.selection.as_ref().map(|s| s.is_empty()) != Some(true)
|
2020-03-18 02:35:08 +00:00
|
|
|
{
|
|
|
|
self.update_selection(self.terminal.vi_mode_cursor.point, Side::Right);
|
2020-07-27 19:05:25 +00:00
|
|
|
} else if self.mouse().left_button_state == ElementState::Pressed
|
|
|
|
|| self.mouse().right_button_state == ElementState::Pressed
|
|
|
|
{
|
2020-08-14 07:26:42 +00:00
|
|
|
let point = self.size_info().pixels_to_coords(self.mouse().x, self.mouse().y);
|
2019-10-05 00:29:26 +00:00
|
|
|
let cell_side = self.mouse().cell_side;
|
|
|
|
self.update_selection(Point { line: point.line, col: point.col }, cell_side);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn copy_selection(&mut self, ty: ClipboardType) {
|
|
|
|
if let Some(selected) = self.terminal.selection_to_string() {
|
|
|
|
if !selected.is_empty() {
|
2020-06-06 21:33:20 +00:00
|
|
|
self.clipboard.store(ty, selected);
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn selection_is_empty(&self) -> bool {
|
2020-05-30 20:45:44 +00:00
|
|
|
self.terminal.selection.as_ref().map(Selection::is_empty).unwrap_or(true)
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn clear_selection(&mut self) {
|
2020-05-30 20:45:44 +00:00
|
|
|
self.terminal.selection = None;
|
2019-10-05 00:29:26 +00:00
|
|
|
self.terminal.dirty = true;
|
|
|
|
}
|
|
|
|
|
2020-08-14 07:26:42 +00:00
|
|
|
fn update_selection(&mut self, mut point: Point, side: Side) {
|
|
|
|
let mut selection = match self.terminal.selection.take() {
|
|
|
|
Some(selection) => selection,
|
|
|
|
None => return,
|
|
|
|
};
|
2019-10-05 00:29:26 +00:00
|
|
|
|
2020-08-14 07:26:42 +00:00
|
|
|
// Treat motion over message bar like motion over the last line.
|
|
|
|
point.line = min(point.line, self.terminal.screen_lines() - 1);
|
2019-10-05 00:29:26 +00:00
|
|
|
|
2020-08-14 07:26:42 +00:00
|
|
|
// Update selection.
|
|
|
|
let absolute_point = self.terminal.visible_to_buffer(point);
|
|
|
|
selection.update(absolute_point, side);
|
2019-10-05 00:29:26 +00:00
|
|
|
|
2020-08-14 07:26:42 +00:00
|
|
|
// Move vi cursor and expand selection.
|
2020-11-13 05:40:09 +00:00
|
|
|
if self.terminal.mode().contains(TermMode::VI) && !self.search_active() {
|
2020-08-14 07:26:42 +00:00
|
|
|
self.terminal.vi_mode_cursor.point = point;
|
|
|
|
selection.include_all();
|
2020-03-18 02:35:08 +00:00
|
|
|
}
|
2020-08-14 07:26:42 +00:00
|
|
|
|
|
|
|
self.terminal.selection = Some(selection);
|
|
|
|
self.terminal.dirty = true;
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 02:35:08 +00:00
|
|
|
fn start_selection(&mut self, ty: SelectionType, point: Point, side: Side) {
|
2019-10-05 00:29:26 +00:00
|
|
|
let point = self.terminal.visible_to_buffer(point);
|
2020-05-30 20:45:44 +00:00
|
|
|
self.terminal.selection = Some(Selection::new(ty, point, side));
|
2019-10-05 00:29:26 +00:00
|
|
|
self.terminal.dirty = true;
|
|
|
|
}
|
|
|
|
|
2020-03-18 02:35:08 +00:00
|
|
|
fn toggle_selection(&mut self, ty: SelectionType, point: Point, side: Side) {
|
2020-05-30 20:45:44 +00:00
|
|
|
match &mut self.terminal.selection {
|
2020-03-18 02:35:08 +00:00
|
|
|
Some(selection) if selection.ty == ty && !selection.is_empty() => {
|
|
|
|
self.clear_selection();
|
|
|
|
},
|
|
|
|
Some(selection) if !selection.is_empty() => {
|
|
|
|
selection.ty = ty;
|
|
|
|
self.terminal.dirty = true;
|
|
|
|
},
|
|
|
|
_ => self.start_selection(ty, point, side),
|
|
|
|
}
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn mouse_coords(&self) -> Option<Point> {
|
|
|
|
let x = self.mouse.x as usize;
|
|
|
|
let y = self.mouse.y as usize;
|
|
|
|
|
2019-11-03 20:59:28 +00:00
|
|
|
if self.size_info.contains_point(x, y) {
|
2019-10-05 00:29:26 +00:00
|
|
|
Some(self.size_info.pixels_to_coords(x, y))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-18 02:35:08 +00:00
|
|
|
#[inline]
|
|
|
|
fn mouse_mode(&self) -> bool {
|
|
|
|
self.terminal.mode().intersects(TermMode::MOUSE_MODE)
|
|
|
|
&& !self.terminal.mode().contains(TermMode::VI)
|
|
|
|
}
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
#[inline]
|
|
|
|
fn mouse_mut(&mut self) -> &mut Mouse {
|
|
|
|
self.mouse
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn mouse(&self) -> &Mouse {
|
|
|
|
self.mouse
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn received_count(&mut self) -> &mut usize {
|
|
|
|
&mut self.received_count
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn suppress_chars(&mut self) -> &mut bool {
|
|
|
|
&mut self.suppress_chars
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2019-11-11 21:05:24 +00:00
|
|
|
fn modifiers(&mut self) -> &mut ModifiersState {
|
2019-10-05 00:29:26 +00:00
|
|
|
&mut self.modifiers
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn window(&self) -> &Window {
|
|
|
|
self.window
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn window_mut(&mut self) -> &mut Window {
|
|
|
|
self.window
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn terminal(&self) -> &Term<T> {
|
|
|
|
self.terminal
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn terminal_mut(&mut self) -> &mut Term<T> {
|
|
|
|
self.terminal
|
|
|
|
}
|
|
|
|
|
|
|
|
fn spawn_new_instance(&mut self) {
|
2020-09-06 15:38:49 +00:00
|
|
|
let mut env_args = env::args();
|
|
|
|
let alacritty = env_args.next().unwrap();
|
2019-10-05 00:29:26 +00:00
|
|
|
|
|
|
|
#[cfg(unix)]
|
2020-09-06 15:38:49 +00:00
|
|
|
let mut args = {
|
2020-08-06 00:42:49 +00:00
|
|
|
// Use working directory of controlling process, or fallback to initial shell.
|
|
|
|
let mut pid = unsafe { libc::tcgetpgrp(tty::master_fd()) };
|
|
|
|
if pid < 0 {
|
|
|
|
pid = tty::child_pid();
|
|
|
|
}
|
|
|
|
|
2020-11-07 04:48:48 +00:00
|
|
|
#[cfg(not(any(target_os = "macos", target_os = "freebsd")))]
|
2020-08-06 00:42:49 +00:00
|
|
|
let link_path = format!("/proc/{}/cwd", pid);
|
2019-10-05 00:29:26 +00:00
|
|
|
#[cfg(target_os = "freebsd")]
|
2020-08-06 00:42:49 +00:00
|
|
|
let link_path = format!("/compat/linux/proc/{}/cwd", pid);
|
2020-11-07 04:48:48 +00:00
|
|
|
#[cfg(not(target_os = "macos"))]
|
|
|
|
let cwd = fs::read_link(link_path);
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
let cwd = macos::proc::cwd(pid);
|
2020-08-06 00:42:49 +00:00
|
|
|
|
2020-09-06 15:38:49 +00:00
|
|
|
// Add the current working directory as parameter.
|
2020-11-07 04:48:48 +00:00
|
|
|
cwd.map(|path| vec!["--working-directory".into(), path]).unwrap_or_default()
|
2019-10-05 00:29:26 +00:00
|
|
|
};
|
2020-09-06 15:38:49 +00:00
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
#[cfg(not(unix))]
|
2020-09-06 15:38:49 +00:00
|
|
|
let mut args: Vec<PathBuf> = Vec::new();
|
|
|
|
|
|
|
|
let working_directory_set = !args.is_empty();
|
|
|
|
|
|
|
|
// Reuse the arguments passed to Alacritty for the new instance.
|
|
|
|
while let Some(arg) = env_args.next() {
|
|
|
|
// Drop working directory from existing parameters.
|
|
|
|
if working_directory_set && arg == "--working-directory" {
|
|
|
|
let _ = env_args.next();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
args.push(arg.into());
|
|
|
|
}
|
2019-10-05 00:29:26 +00:00
|
|
|
|
2020-07-10 19:32:44 +00:00
|
|
|
start_daemon(&alacritty, &args);
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 01:02:56 +00:00
|
|
|
/// Spawn URL launcher when clicking on URLs.
|
|
|
|
fn launch_url(&self, url: Url) {
|
|
|
|
if self.mouse.block_url_launcher {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(ref launcher) = self.config.ui_config.mouse.url.launcher {
|
|
|
|
let mut args = launcher.args().to_vec();
|
|
|
|
let start = self.terminal.visible_to_buffer(url.start());
|
|
|
|
let end = self.terminal.visible_to_buffer(url.end());
|
|
|
|
args.push(self.terminal.bounds_to_string(start, end));
|
|
|
|
|
2020-07-10 19:32:44 +00:00
|
|
|
start_daemon(launcher.program(), &args);
|
2020-06-18 01:02:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
fn change_font_size(&mut self, delta: f32) {
|
2019-11-03 19:02:26 +00:00
|
|
|
*self.font_size = max(*self.font_size + delta, Size::new(FONT_SIZE_STEP));
|
2020-07-11 17:03:09 +00:00
|
|
|
let font = self.config.ui_config.font.clone().with_size(*self.font_size);
|
2020-07-09 21:45:22 +00:00
|
|
|
self.display_update_pending.set_font(font);
|
2019-10-05 00:29:26 +00:00
|
|
|
self.terminal.dirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn reset_font_size(&mut self) {
|
2020-07-11 17:03:09 +00:00
|
|
|
*self.font_size = self.config.ui_config.font.size;
|
|
|
|
self.display_update_pending.set_font(self.config.ui_config.font.clone());
|
2019-10-05 00:29:26 +00:00
|
|
|
self.terminal.dirty = true;
|
|
|
|
}
|
|
|
|
|
2020-07-09 21:45:22 +00:00
|
|
|
#[inline]
|
2019-10-05 00:29:26 +00:00
|
|
|
fn pop_message(&mut self) {
|
2020-07-09 21:45:22 +00:00
|
|
|
if !self.message_buffer.is_empty() {
|
|
|
|
self.display_update_pending.dirty = true;
|
|
|
|
self.message_buffer.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn start_search(&mut self, direction: Direction) {
|
|
|
|
let num_lines = self.terminal.screen_lines();
|
|
|
|
let num_cols = self.terminal.cols();
|
|
|
|
|
2020-11-13 05:40:09 +00:00
|
|
|
self.search_state.focused_match = None;
|
2020-07-09 21:45:22 +00:00
|
|
|
self.search_state.regex = Some(String::new());
|
|
|
|
self.search_state.direction = direction;
|
|
|
|
|
2020-07-15 21:27:32 +00:00
|
|
|
// Store original search position as origin and reset location.
|
|
|
|
self.search_state.display_offset_delta = 0;
|
|
|
|
self.search_state.origin = if self.terminal.mode().contains(TermMode::VI) {
|
2020-07-09 21:45:22 +00:00
|
|
|
self.terminal.vi_mode_cursor.point
|
|
|
|
} else {
|
|
|
|
match direction {
|
|
|
|
Direction::Right => Point::new(Line(0), Column(0)),
|
|
|
|
Direction::Left => Point::new(num_lines - 2, num_cols - 1),
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
self.display_update_pending.dirty = true;
|
|
|
|
self.terminal.dirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn confirm_search(&mut self) {
|
|
|
|
// Force unlimited search if the previous one was interrupted.
|
|
|
|
if self.scheduler.scheduled(TimerId::DelayedSearch) {
|
|
|
|
self.goto_match(None);
|
|
|
|
}
|
|
|
|
|
2020-09-27 22:36:08 +00:00
|
|
|
self.exit_search();
|
2020-07-09 21:45:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn cancel_search(&mut self) {
|
|
|
|
self.terminal.cancel_search();
|
|
|
|
|
2020-07-25 14:05:11 +00:00
|
|
|
if self.terminal.mode().contains(TermMode::VI) {
|
2020-11-13 05:40:09 +00:00
|
|
|
// Recover pre-search state in vi mode.
|
2020-07-25 14:05:11 +00:00
|
|
|
self.search_reset_state();
|
2020-11-13 05:40:09 +00:00
|
|
|
} else if let Some(focused_match) = &self.search_state.focused_match {
|
|
|
|
// Create a selection for the focused match.
|
|
|
|
let start = self.terminal.grid().clamp_buffer_to_visible(*focused_match.start());
|
|
|
|
let end = self.terminal.grid().clamp_buffer_to_visible(*focused_match.end());
|
|
|
|
self.start_selection(SelectionType::Simple, start, Side::Left);
|
|
|
|
self.update_selection(end, Side::Right);
|
2020-07-25 14:05:11 +00:00
|
|
|
}
|
2020-07-09 21:45:22 +00:00
|
|
|
|
2020-09-27 22:36:08 +00:00
|
|
|
self.exit_search();
|
2020-07-09 21:45:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn push_search(&mut self, c: char) {
|
2020-07-10 21:00:33 +00:00
|
|
|
if let Some(regex) = self.search_state.regex.as_mut() {
|
2020-07-17 00:30:34 +00:00
|
|
|
if !self.terminal.mode().contains(TermMode::VI) {
|
2020-11-13 05:40:09 +00:00
|
|
|
// Clear selection so we do not obstruct any matches.
|
2020-07-17 00:30:34 +00:00
|
|
|
self.terminal.selection = None;
|
|
|
|
}
|
|
|
|
|
2020-07-10 21:00:33 +00:00
|
|
|
regex.push(c);
|
|
|
|
self.update_search();
|
2020-07-09 21:45:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn pop_search(&mut self) {
|
2020-07-10 21:00:33 +00:00
|
|
|
if let Some(regex) = self.search_state.regex.as_mut() {
|
|
|
|
regex.pop();
|
|
|
|
self.update_search();
|
2020-07-09 21:45:22 +00:00
|
|
|
}
|
2020-07-10 21:00:33 +00:00
|
|
|
}
|
2020-07-09 21:45:22 +00:00
|
|
|
|
2020-07-10 21:00:33 +00:00
|
|
|
#[inline]
|
|
|
|
fn pop_word_search(&mut self) {
|
|
|
|
if let Some(regex) = self.search_state.regex.as_mut() {
|
|
|
|
*regex = regex.trim_end().to_owned();
|
|
|
|
regex.truncate(regex.rfind(' ').map(|i| i + 1).unwrap_or(0));
|
|
|
|
self.update_search();
|
2020-07-09 21:45:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-15 21:27:32 +00:00
|
|
|
#[inline]
|
|
|
|
fn advance_search_origin(&mut self, direction: Direction) {
|
|
|
|
let origin = self.absolute_origin();
|
|
|
|
self.terminal.scroll_to_point(origin);
|
|
|
|
|
|
|
|
// Move the search origin right in front of the next match in the specified direction.
|
|
|
|
if let Some(regex_match) = self.terminal.search_next(origin, direction, Side::Left, None) {
|
|
|
|
let origin = match direction {
|
|
|
|
Direction::Right => *regex_match.end(),
|
|
|
|
Direction::Left => {
|
|
|
|
regex_match.start().sub_absolute(self.terminal, Boundary::Wrap, 1)
|
|
|
|
},
|
|
|
|
};
|
|
|
|
self.terminal.scroll_to_point(origin);
|
|
|
|
|
|
|
|
let origin_relative = self.terminal.grid().clamp_buffer_to_visible(origin);
|
|
|
|
self.search_state.origin = origin_relative;
|
|
|
|
self.search_state.display_offset_delta = 0;
|
|
|
|
|
|
|
|
self.update_search();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-09 21:45:22 +00:00
|
|
|
#[inline]
|
|
|
|
fn search_direction(&self) -> Direction {
|
|
|
|
self.search_state.direction
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn search_active(&self) -> bool {
|
|
|
|
self.search_state.regex.is_some()
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn message(&self) -> Option<&Message> {
|
|
|
|
self.message_buffer.message()
|
|
|
|
}
|
2019-11-03 19:02:26 +00:00
|
|
|
|
|
|
|
fn config(&self) -> &Config {
|
|
|
|
self.config
|
|
|
|
}
|
2020-02-07 13:44:11 +00:00
|
|
|
|
|
|
|
fn event_loop(&self) -> &EventLoopWindowTarget<Event> {
|
|
|
|
self.event_loop
|
|
|
|
}
|
2020-03-18 02:35:08 +00:00
|
|
|
|
|
|
|
fn urls(&self) -> &Urls {
|
|
|
|
self.urls
|
|
|
|
}
|
|
|
|
|
2020-06-18 01:02:56 +00:00
|
|
|
fn clipboard_mut(&mut self) -> &mut Clipboard {
|
2020-06-06 21:33:20 +00:00
|
|
|
self.clipboard
|
|
|
|
}
|
|
|
|
|
2020-06-18 01:02:56 +00:00
|
|
|
fn scheduler_mut(&mut self) -> &mut Scheduler {
|
|
|
|
self.scheduler
|
2020-03-18 02:35:08 +00:00
|
|
|
}
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
|
2020-07-09 21:45:22 +00:00
|
|
|
impl<'a, N: Notify + 'a, T: EventListener> ActionContext<'a, N, T> {
|
2020-07-10 21:00:33 +00:00
|
|
|
fn update_search(&mut self) {
|
|
|
|
let regex = match self.search_state.regex.as_mut() {
|
|
|
|
Some(regex) => regex,
|
|
|
|
None => return,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Hide cursor while typing into the search bar.
|
|
|
|
if self.config.ui_config.mouse.hide_when_typing {
|
|
|
|
self.window.set_mouse_visible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if regex.is_empty() {
|
|
|
|
// Stop search if there's nothing to search for.
|
|
|
|
self.search_reset_state();
|
|
|
|
self.terminal.cancel_search();
|
2020-07-25 14:05:11 +00:00
|
|
|
|
|
|
|
if !self.terminal.mode().contains(TermMode::VI) {
|
2020-11-13 05:40:09 +00:00
|
|
|
// Restart search without vi mode to clear the search origin.
|
2020-07-25 14:05:11 +00:00
|
|
|
self.start_search(self.search_state.direction);
|
|
|
|
}
|
2020-07-10 21:00:33 +00:00
|
|
|
} else {
|
|
|
|
// Create terminal search from the new regex string.
|
|
|
|
self.terminal.start_search(®ex);
|
|
|
|
|
|
|
|
// Update search highlighting.
|
|
|
|
self.goto_match(MAX_SEARCH_WHILE_TYPING);
|
|
|
|
}
|
|
|
|
|
|
|
|
self.terminal.dirty = true;
|
|
|
|
}
|
|
|
|
|
2020-07-09 21:45:22 +00:00
|
|
|
/// Reset terminal to the state before search was started.
|
|
|
|
fn search_reset_state(&mut self) {
|
|
|
|
// Reset display offset.
|
|
|
|
self.terminal.scroll_display(Scroll::Delta(self.search_state.display_offset_delta));
|
|
|
|
self.search_state.display_offset_delta = 0;
|
|
|
|
|
2020-11-13 05:40:09 +00:00
|
|
|
// Clear focused match.
|
|
|
|
self.search_state.focused_match = None;
|
|
|
|
|
2020-07-09 21:45:22 +00:00
|
|
|
// Reset vi mode cursor.
|
2020-07-15 21:27:32 +00:00
|
|
|
let mut origin = self.search_state.origin;
|
|
|
|
origin.line = min(origin.line, self.terminal.screen_lines() - 1);
|
|
|
|
origin.col = min(origin.col, self.terminal.cols() - 1);
|
|
|
|
self.terminal.vi_mode_cursor.point = origin;
|
2020-07-09 21:45:22 +00:00
|
|
|
|
|
|
|
// Unschedule pending timers.
|
|
|
|
self.scheduler.unschedule(TimerId::DelayedSearch);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Jump to the first regex match from the search origin.
|
|
|
|
fn goto_match(&mut self, mut limit: Option<usize>) {
|
|
|
|
let regex = match self.search_state.regex.take() {
|
|
|
|
Some(regex) => regex,
|
|
|
|
None => return,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Limit search only when enough lines are available to run into the limit.
|
|
|
|
limit = limit.filter(|&limit| limit <= self.terminal.total_lines());
|
|
|
|
|
|
|
|
// Jump to the next match.
|
|
|
|
let direction = self.search_state.direction;
|
2020-07-15 21:27:32 +00:00
|
|
|
match self.terminal.search_next(self.absolute_origin(), direction, Side::Left, limit) {
|
2020-07-09 21:45:22 +00:00
|
|
|
Some(regex_match) => {
|
|
|
|
let old_offset = self.terminal.grid().display_offset() as isize;
|
|
|
|
|
2020-07-15 21:27:32 +00:00
|
|
|
if self.terminal.mode().contains(TermMode::VI) {
|
|
|
|
// Move vi cursor to the start of the match.
|
|
|
|
self.terminal.vi_goto_point(*regex_match.start());
|
|
|
|
} else {
|
|
|
|
// Select the match when vi mode is not active.
|
|
|
|
self.terminal.scroll_to_point(*regex_match.start());
|
|
|
|
}
|
2020-07-09 21:45:22 +00:00
|
|
|
|
2020-11-13 05:40:09 +00:00
|
|
|
// Update the focused match.
|
|
|
|
self.search_state.focused_match = Some(regex_match);
|
|
|
|
|
2020-07-09 21:45:22 +00:00
|
|
|
// Store number of lines the viewport had to be moved.
|
|
|
|
let display_offset = self.terminal.grid().display_offset();
|
|
|
|
self.search_state.display_offset_delta += old_offset - display_offset as isize;
|
|
|
|
|
|
|
|
// Since we found a result, we require no delayed re-search.
|
|
|
|
self.scheduler.unschedule(TimerId::DelayedSearch);
|
|
|
|
},
|
|
|
|
// Reset viewport only when we know there is no match, to prevent unnecessary jumping.
|
|
|
|
None if limit.is_none() => self.search_reset_state(),
|
|
|
|
None => {
|
|
|
|
// Schedule delayed search if we ran into our search limit.
|
|
|
|
if !self.scheduler.scheduled(TimerId::DelayedSearch) {
|
|
|
|
self.scheduler.schedule(
|
|
|
|
Event::SearchNext.into(),
|
|
|
|
TYPING_SEARCH_DELAY,
|
|
|
|
false,
|
|
|
|
TimerId::DelayedSearch,
|
|
|
|
);
|
|
|
|
}
|
2020-11-13 05:40:09 +00:00
|
|
|
|
|
|
|
// Clear focused match.
|
|
|
|
self.search_state.focused_match = None;
|
2020-07-09 21:45:22 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
self.search_state.regex = Some(regex);
|
|
|
|
}
|
2020-07-15 21:27:32 +00:00
|
|
|
|
2020-11-13 05:40:09 +00:00
|
|
|
/// Cleanup the search state.
|
2020-09-27 22:36:08 +00:00
|
|
|
fn exit_search(&mut self) {
|
|
|
|
// Move vi cursor down if resize will pull content from history.
|
|
|
|
if self.terminal.history_size() != 0
|
|
|
|
&& self.terminal.grid().display_offset() == 0
|
|
|
|
&& self.terminal.screen_lines() > self.terminal.vi_mode_cursor.point.line + 1
|
|
|
|
{
|
|
|
|
self.terminal.vi_mode_cursor.point.line += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.display_update_pending.dirty = true;
|
|
|
|
self.search_state.regex = None;
|
|
|
|
self.terminal.dirty = true;
|
2020-11-13 05:40:09 +00:00
|
|
|
|
|
|
|
// Clear focused match.
|
|
|
|
self.search_state.focused_match = None;
|
2020-09-27 22:36:08 +00:00
|
|
|
}
|
|
|
|
|
2020-07-15 21:27:32 +00:00
|
|
|
/// Get the absolute position of the search origin.
|
|
|
|
///
|
|
|
|
/// This takes the relative motion of the viewport since the start of the search into account.
|
|
|
|
/// So while the absolute point of the origin might have changed since new content was printed,
|
|
|
|
/// this will still return the correct absolute position.
|
|
|
|
fn absolute_origin(&self) -> Point<usize> {
|
|
|
|
let mut relative_origin = self.search_state.origin;
|
|
|
|
relative_origin.line = min(relative_origin.line, self.terminal.screen_lines() - 1);
|
2020-07-17 21:12:11 +00:00
|
|
|
relative_origin.col = min(relative_origin.col, self.terminal.cols() - 1);
|
2020-07-15 21:27:32 +00:00
|
|
|
let mut origin = self.terminal.visible_to_buffer(relative_origin);
|
|
|
|
origin.line = (origin.line as isize + self.search_state.display_offset_delta) as usize;
|
|
|
|
origin
|
|
|
|
}
|
2020-07-09 21:45:22 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 18:23:50 +00:00
|
|
|
#[derive(Debug, Eq, PartialEq)]
|
2019-10-05 00:29:26 +00:00
|
|
|
pub enum ClickState {
|
|
|
|
None,
|
|
|
|
Click,
|
|
|
|
DoubleClick,
|
|
|
|
TripleClick,
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// State of the mouse.
|
2020-03-18 02:35:08 +00:00
|
|
|
#[derive(Debug)]
|
2019-10-05 00:29:26 +00:00
|
|
|
pub struct Mouse {
|
|
|
|
pub x: usize,
|
|
|
|
pub y: usize,
|
|
|
|
pub left_button_state: ElementState,
|
|
|
|
pub middle_button_state: ElementState,
|
|
|
|
pub right_button_state: ElementState,
|
|
|
|
pub last_click_timestamp: Instant,
|
2020-06-23 09:57:15 +00:00
|
|
|
pub last_click_button: MouseButton,
|
2019-10-05 00:29:26 +00:00
|
|
|
pub click_state: ClickState,
|
2020-03-02 05:32:18 +00:00
|
|
|
pub scroll_px: f64,
|
2019-10-05 00:29:26 +00:00
|
|
|
pub line: Line,
|
|
|
|
pub column: Column,
|
|
|
|
pub cell_side: Side,
|
|
|
|
pub lines_scrolled: f32,
|
|
|
|
pub block_url_launcher: bool,
|
2020-08-14 07:26:42 +00:00
|
|
|
pub inside_text_area: bool,
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Mouse {
|
|
|
|
fn default() -> Mouse {
|
|
|
|
Mouse {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
last_click_timestamp: Instant::now(),
|
2020-06-23 09:57:15 +00:00
|
|
|
last_click_button: MouseButton::Left,
|
2019-10-05 00:29:26 +00:00
|
|
|
left_button_state: ElementState::Released,
|
|
|
|
middle_button_state: ElementState::Released,
|
|
|
|
right_button_state: ElementState::Released,
|
|
|
|
click_state: ClickState::None,
|
2020-03-02 05:32:18 +00:00
|
|
|
scroll_px: 0.,
|
2019-10-05 00:29:26 +00:00
|
|
|
line: Line(0),
|
|
|
|
column: Column(0),
|
|
|
|
cell_side: Side::Left,
|
2020-03-02 05:32:18 +00:00
|
|
|
lines_scrolled: 0.,
|
2019-10-05 00:29:26 +00:00
|
|
|
block_url_launcher: false,
|
2020-08-14 07:26:42 +00:00
|
|
|
inside_text_area: false,
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// The event processor.
|
2019-10-05 00:29:26 +00:00
|
|
|
///
|
|
|
|
/// Stores some state from received events and dispatches actions when they are
|
|
|
|
/// triggered.
|
|
|
|
pub struct Processor<N> {
|
|
|
|
notifier: N,
|
|
|
|
mouse: Mouse,
|
|
|
|
received_count: usize,
|
|
|
|
suppress_chars: bool,
|
2020-06-06 21:33:20 +00:00
|
|
|
clipboard: Clipboard,
|
2019-11-11 21:05:24 +00:00
|
|
|
modifiers: ModifiersState,
|
2019-10-05 00:29:26 +00:00
|
|
|
config: Config,
|
|
|
|
message_buffer: MessageBuffer,
|
|
|
|
display: Display,
|
2019-11-03 19:02:26 +00:00
|
|
|
font_size: Size,
|
2020-06-18 01:02:56 +00:00
|
|
|
event_queue: Vec<GlutinEvent<'static, Event>>,
|
2020-07-09 21:45:22 +00:00
|
|
|
search_state: SearchState,
|
2020-08-22 20:55:27 +00:00
|
|
|
cli_options: CLIOptions,
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
|
2019-12-14 21:32:24 +00:00
|
|
|
impl<N: Notify + OnResize> Processor<N> {
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Create a new event processor.
|
2019-10-05 00:29:26 +00:00
|
|
|
///
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Takes a writer which is expected to be hooked up to the write end of a PTY.
|
2019-10-05 00:29:26 +00:00
|
|
|
pub fn new(
|
|
|
|
notifier: N,
|
|
|
|
message_buffer: MessageBuffer,
|
|
|
|
config: Config,
|
|
|
|
display: Display,
|
2020-08-22 20:55:27 +00:00
|
|
|
cli_options: CLIOptions,
|
2019-10-05 00:29:26 +00:00
|
|
|
) -> Processor<N> {
|
2020-06-06 21:33:20 +00:00
|
|
|
#[cfg(not(any(target_os = "macos", windows)))]
|
|
|
|
let clipboard = Clipboard::new(display.window.wayland_display());
|
|
|
|
#[cfg(any(target_os = "macos", windows))]
|
|
|
|
let clipboard = Clipboard::new();
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
Processor {
|
|
|
|
notifier,
|
|
|
|
mouse: Default::default(),
|
|
|
|
received_count: 0,
|
|
|
|
suppress_chars: false,
|
|
|
|
modifiers: Default::default(),
|
2020-07-11 17:03:09 +00:00
|
|
|
font_size: config.ui_config.font.size,
|
2019-10-05 00:29:26 +00:00
|
|
|
config,
|
|
|
|
message_buffer,
|
|
|
|
display,
|
2020-05-03 23:29:11 +00:00
|
|
|
event_queue: Vec::new(),
|
2020-06-06 21:33:20 +00:00
|
|
|
clipboard,
|
2020-07-09 21:45:22 +00:00
|
|
|
search_state: SearchState::new(),
|
2020-08-22 20:55:27 +00:00
|
|
|
cli_options,
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-03 23:29:11 +00:00
|
|
|
/// Return `true` if `event_queue` is empty, `false` otherwise.
|
|
|
|
#[inline]
|
2020-10-12 09:22:36 +00:00
|
|
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
2020-05-03 23:29:11 +00:00
|
|
|
fn event_queue_empty(&mut self) -> bool {
|
|
|
|
let wayland_event_queue = match self.display.wayland_event_queue.as_mut() {
|
|
|
|
Some(wayland_event_queue) => wayland_event_queue,
|
|
|
|
// Since frame callbacks do not exist on X11, just check for event queue.
|
|
|
|
None => return self.event_queue.is_empty(),
|
|
|
|
};
|
|
|
|
|
|
|
|
// Check for pending frame callbacks on Wayland.
|
|
|
|
let events_dispatched = wayland_event_queue
|
|
|
|
.dispatch_pending(&mut (), |_, _, _| {})
|
|
|
|
.expect("failed to dispatch event queue");
|
|
|
|
|
|
|
|
self.event_queue.is_empty() && events_dispatched == 0
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return `true` if `event_queue` is empty, `false` otherwise.
|
|
|
|
#[inline]
|
2020-10-12 22:13:38 +00:00
|
|
|
#[cfg(any(not(feature = "wayland"), target_os = "macos", windows))]
|
2020-05-03 23:29:11 +00:00
|
|
|
fn event_queue_empty(&mut self) -> bool {
|
|
|
|
self.event_queue.is_empty()
|
|
|
|
}
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
/// Run the event loop.
|
|
|
|
pub fn run<T>(&mut self, terminal: Arc<FairMutex<Term<T>>>, mut event_loop: EventLoop<Event>)
|
|
|
|
where
|
|
|
|
T: EventListener,
|
|
|
|
{
|
2020-06-18 01:02:56 +00:00
|
|
|
let mut scheduler = Scheduler::new();
|
|
|
|
|
2020-02-07 13:44:11 +00:00
|
|
|
event_loop.run_return(|event, event_loop, control_flow| {
|
2020-07-11 17:03:09 +00:00
|
|
|
if self.config.ui_config.debug.print_events {
|
2019-10-05 00:29:26 +00:00
|
|
|
info!("glutin event: {:?}", event);
|
|
|
|
}
|
|
|
|
|
2020-05-03 23:29:11 +00:00
|
|
|
// Ignore all events we do not care about.
|
2020-01-10 01:51:37 +00:00
|
|
|
if Self::skip_event(&event) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
match event {
|
2020-05-03 23:29:11 +00:00
|
|
|
// Check for shutdown.
|
2020-06-18 01:02:56 +00:00
|
|
|
GlutinEvent::UserEvent(Event::TerminalEvent(TerminalEvent::Exit)) => {
|
2019-10-05 00:29:26 +00:00
|
|
|
*control_flow = ControlFlow::Exit;
|
|
|
|
return;
|
|
|
|
},
|
2020-05-03 23:29:11 +00:00
|
|
|
// Process events.
|
2020-01-05 01:00:50 +00:00
|
|
|
GlutinEvent::RedrawEventsCleared => {
|
2020-06-18 01:02:56 +00:00
|
|
|
*control_flow = match scheduler.update(&mut self.event_queue) {
|
|
|
|
Some(instant) => ControlFlow::WaitUntil(instant),
|
|
|
|
None => ControlFlow::Wait,
|
|
|
|
};
|
2019-10-05 00:29:26 +00:00
|
|
|
|
2020-05-03 23:29:11 +00:00
|
|
|
if self.event_queue_empty() {
|
2019-10-05 00:29:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
},
|
2020-05-03 23:29:11 +00:00
|
|
|
// Remap DPR change event to remove lifetime.
|
2020-01-10 01:51:37 +00:00
|
|
|
GlutinEvent::WindowEvent {
|
|
|
|
event: WindowEvent::ScaleFactorChanged { scale_factor, new_inner_size },
|
|
|
|
..
|
|
|
|
} => {
|
2019-10-05 00:29:26 +00:00
|
|
|
*control_flow = ControlFlow::Poll;
|
2020-01-10 01:51:37 +00:00
|
|
|
let size = (new_inner_size.width, new_inner_size.height);
|
2020-06-18 01:02:56 +00:00
|
|
|
self.event_queue.push(Event::DPRChanged(scale_factor, size).into());
|
2020-01-10 01:51:37 +00:00
|
|
|
return;
|
|
|
|
},
|
|
|
|
// Transmute to extend lifetime, which exists only for `ScaleFactorChanged` event.
|
|
|
|
// Since we remap that event to remove the lifetime, this is safe.
|
|
|
|
event => unsafe {
|
|
|
|
*control_flow = ControlFlow::Poll;
|
2020-05-03 23:29:11 +00:00
|
|
|
self.event_queue.push(mem::transmute(event));
|
2019-10-05 00:29:26 +00:00
|
|
|
return;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut terminal = terminal.lock();
|
|
|
|
|
2019-11-03 19:02:26 +00:00
|
|
|
let mut display_update_pending = DisplayUpdate::default();
|
2020-07-09 21:45:22 +00:00
|
|
|
let old_is_searching = self.search_state.regex.is_some();
|
2019-10-05 00:29:26 +00:00
|
|
|
|
|
|
|
let context = ActionContext {
|
|
|
|
terminal: &mut terminal,
|
|
|
|
notifier: &mut self.notifier,
|
|
|
|
mouse: &mut self.mouse,
|
2020-06-06 21:33:20 +00:00
|
|
|
clipboard: &mut self.clipboard,
|
2019-10-05 00:29:26 +00:00
|
|
|
size_info: &mut self.display.size_info,
|
|
|
|
received_count: &mut self.received_count,
|
|
|
|
suppress_chars: &mut self.suppress_chars,
|
|
|
|
modifiers: &mut self.modifiers,
|
|
|
|
message_buffer: &mut self.message_buffer,
|
2019-11-03 19:02:26 +00:00
|
|
|
display_update_pending: &mut display_update_pending,
|
2019-10-05 00:29:26 +00:00
|
|
|
window: &mut self.display.window,
|
2019-11-03 19:02:26 +00:00
|
|
|
font_size: &mut self.font_size,
|
|
|
|
config: &mut self.config,
|
2020-03-18 02:35:08 +00:00
|
|
|
urls: &self.display.urls,
|
2020-06-18 01:02:56 +00:00
|
|
|
scheduler: &mut scheduler,
|
2020-07-09 21:45:22 +00:00
|
|
|
search_state: &mut self.search_state,
|
2020-08-22 20:55:27 +00:00
|
|
|
cli_options: &self.cli_options,
|
2020-02-07 13:44:11 +00:00
|
|
|
event_loop,
|
2019-10-05 00:29:26 +00:00
|
|
|
};
|
2020-03-18 02:35:08 +00:00
|
|
|
let mut processor = input::Processor::new(context, &self.display.highlighted_url);
|
2019-10-05 00:29:26 +00:00
|
|
|
|
2020-05-03 23:29:11 +00:00
|
|
|
for event in self.event_queue.drain(..) {
|
2019-10-05 00:29:26 +00:00
|
|
|
Processor::handle_event(event, &mut processor);
|
|
|
|
}
|
|
|
|
|
2020-05-03 23:29:11 +00:00
|
|
|
// Process DisplayUpdate events.
|
2020-07-09 21:45:22 +00:00
|
|
|
if display_update_pending.dirty {
|
|
|
|
self.submit_display_update(&mut terminal, old_is_searching, display_update_pending);
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
|
2020-07-28 10:00:55 +00:00
|
|
|
// Skip rendering on Wayland until we get frame event from compositor.
|
2020-05-03 23:29:11 +00:00
|
|
|
#[cfg(not(any(target_os = "macos", windows)))]
|
2020-10-12 09:22:36 +00:00
|
|
|
if !self.display.is_x11 && !self.display.window.should_draw.load(Ordering::Relaxed) {
|
2020-07-28 10:00:55 +00:00
|
|
|
return;
|
2020-05-03 23:29:11 +00:00
|
|
|
}
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
if terminal.dirty {
|
2019-10-24 22:26:33 +00:00
|
|
|
terminal.dirty = false;
|
|
|
|
|
2020-05-03 23:29:11 +00:00
|
|
|
// Request immediate re-draw if visual bell animation is not finished yet.
|
2019-10-24 22:26:33 +00:00
|
|
|
if !terminal.visual_bell.completed() {
|
2020-06-18 01:02:56 +00:00
|
|
|
let event: Event = TerminalEvent::Wakeup.into();
|
|
|
|
self.event_queue.push(event.into());
|
2020-10-30 06:22:13 +00:00
|
|
|
|
|
|
|
*control_flow = ControlFlow::Poll;
|
2019-10-24 22:26:33 +00:00
|
|
|
}
|
2019-10-05 00:29:26 +00:00
|
|
|
|
2020-05-03 23:29:11 +00:00
|
|
|
// Redraw screen.
|
2019-11-03 20:59:28 +00:00
|
|
|
self.display.draw(
|
|
|
|
terminal,
|
|
|
|
&self.message_buffer,
|
|
|
|
&self.config,
|
|
|
|
&self.mouse,
|
2019-11-11 21:05:24 +00:00
|
|
|
self.modifiers,
|
2020-07-17 01:26:53 +00:00
|
|
|
&self.search_state,
|
2019-11-03 20:59:28 +00:00
|
|
|
);
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Write ref tests to disk.
|
2020-07-11 17:03:09 +00:00
|
|
|
if self.config.ui_config.debug.ref_test {
|
2020-07-09 21:45:22 +00:00
|
|
|
self.write_ref_test_results(&terminal.lock());
|
|
|
|
}
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Handle events from glutin.
|
2019-10-05 00:29:26 +00:00
|
|
|
///
|
2019-10-24 22:26:33 +00:00
|
|
|
/// Doesn't take self mutably due to borrow checking.
|
2019-10-05 00:29:26 +00:00
|
|
|
fn handle_event<T>(
|
2020-10-29 04:17:33 +00:00
|
|
|
event: GlutinEvent<'_, Event>,
|
|
|
|
processor: &mut input::Processor<'_, T, ActionContext<'_, N, T>>,
|
2019-10-05 00:29:26 +00:00
|
|
|
) where
|
|
|
|
T: EventListener,
|
|
|
|
{
|
|
|
|
match event {
|
|
|
|
GlutinEvent::UserEvent(event) => match event {
|
2020-01-10 01:51:37 +00:00
|
|
|
Event::DPRChanged(scale_factor, (width, height)) => {
|
|
|
|
let display_update_pending = &mut processor.ctx.display_update_pending;
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Push current font to update its DPR.
|
2020-07-11 17:03:09 +00:00
|
|
|
let font = processor.ctx.config.ui_config.font.clone();
|
2020-07-09 21:45:22 +00:00
|
|
|
display_update_pending.set_font(font.with_size(*processor.ctx.font_size));
|
2020-01-10 01:51:37 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Resize to event's dimensions, since no resize event is emitted on Wayland.
|
2020-07-09 21:45:22 +00:00
|
|
|
display_update_pending.set_dimensions(PhysicalSize::new(width, height));
|
2020-01-10 01:51:37 +00:00
|
|
|
|
2020-09-27 22:36:08 +00:00
|
|
|
processor.ctx.window.dpr = scale_factor;
|
2020-01-10 01:51:37 +00:00
|
|
|
processor.ctx.terminal.dirty = true;
|
|
|
|
},
|
2019-10-05 00:29:26 +00:00
|
|
|
Event::Message(message) => {
|
|
|
|
processor.ctx.message_buffer.push(message);
|
2020-07-09 21:45:22 +00:00
|
|
|
processor.ctx.display_update_pending.dirty = true;
|
2019-10-05 00:29:26 +00:00
|
|
|
processor.ctx.terminal.dirty = true;
|
|
|
|
},
|
2020-07-09 21:45:22 +00:00
|
|
|
Event::SearchNext => processor.ctx.goto_match(None),
|
2020-06-18 01:02:56 +00:00
|
|
|
Event::ConfigReload(path) => Self::reload_config(&path, processor),
|
|
|
|
Event::Scroll(scroll) => processor.ctx.scroll(scroll),
|
|
|
|
Event::TerminalEvent(event) => match event {
|
2020-07-11 17:03:09 +00:00
|
|
|
TerminalEvent::Title(title) => {
|
|
|
|
let ui_config = &processor.ctx.config.ui_config;
|
|
|
|
if ui_config.dynamic_title() {
|
|
|
|
processor.ctx.window.set_title(&title);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
TerminalEvent::ResetTitle => {
|
|
|
|
let ui_config = &processor.ctx.config.ui_config;
|
|
|
|
if ui_config.dynamic_title() {
|
|
|
|
processor.ctx.window.set_title(&ui_config.window.title);
|
|
|
|
}
|
|
|
|
},
|
2020-06-18 01:02:56 +00:00
|
|
|
TerminalEvent::Wakeup => processor.ctx.terminal.dirty = true,
|
2020-07-10 19:32:44 +00:00
|
|
|
TerminalEvent::Bell => {
|
|
|
|
let bell_command = processor.ctx.config.bell().command.as_ref();
|
|
|
|
let _ = bell_command.map(|cmd| start_daemon(cmd.program(), cmd.args()));
|
2020-10-10 21:24:40 +00:00
|
|
|
if processor.ctx.terminal.mode().contains(TermMode::URGENCY_HINTS) {
|
|
|
|
processor.ctx.window.set_urgent(!processor.ctx.terminal.is_focused);
|
|
|
|
}
|
2020-06-18 01:02:56 +00:00
|
|
|
},
|
|
|
|
TerminalEvent::ClipboardStore(clipboard_type, content) => {
|
|
|
|
processor.ctx.clipboard.store(clipboard_type, content);
|
|
|
|
},
|
|
|
|
TerminalEvent::ClipboardLoad(clipboard_type, format) => {
|
|
|
|
let text = format(processor.ctx.clipboard.load(clipboard_type).as_str());
|
|
|
|
processor.ctx.write_to_pty(text.into_bytes());
|
|
|
|
},
|
|
|
|
TerminalEvent::MouseCursorDirty => processor.reset_mouse_cursor(),
|
|
|
|
TerminalEvent::Exit => (),
|
2020-06-06 21:33:20 +00:00
|
|
|
},
|
2019-10-05 00:29:26 +00:00
|
|
|
},
|
2020-01-05 01:00:50 +00:00
|
|
|
GlutinEvent::RedrawRequested(_) => processor.ctx.terminal.dirty = true,
|
2019-10-05 00:29:26 +00:00
|
|
|
GlutinEvent::WindowEvent { event, window_id, .. } => {
|
|
|
|
match event {
|
2020-03-07 22:17:38 +00:00
|
|
|
WindowEvent::CloseRequested => processor.ctx.terminal.exit(),
|
|
|
|
WindowEvent::Resized(size) => {
|
2020-07-28 10:00:55 +00:00
|
|
|
// Minimizing the window sends a Resize event with zero width and
|
|
|
|
// height. But there's no need to ever actually resize to this.
|
|
|
|
// Both WinPTY & ConPTY have issues when resizing down to zero size
|
|
|
|
// and back.
|
2019-12-09 17:26:31 +00:00
|
|
|
#[cfg(windows)]
|
2020-07-28 10:00:55 +00:00
|
|
|
if size.width == 0 && size.height == 0 {
|
|
|
|
return;
|
2019-12-09 17:26:31 +00:00
|
|
|
}
|
|
|
|
|
2020-07-09 21:45:22 +00:00
|
|
|
processor.ctx.display_update_pending.set_dimensions(size);
|
2019-10-05 00:29:26 +00:00
|
|
|
processor.ctx.terminal.dirty = true;
|
|
|
|
},
|
2020-03-07 22:17:38 +00:00
|
|
|
WindowEvent::KeyboardInput { input, is_synthetic: false, .. } => {
|
2019-11-11 21:05:24 +00:00
|
|
|
processor.key_input(input);
|
2019-10-05 00:29:26 +00:00
|
|
|
},
|
2020-03-07 22:17:38 +00:00
|
|
|
WindowEvent::ReceivedCharacter(c) => processor.received_char(c),
|
|
|
|
WindowEvent::MouseInput { state, button, .. } => {
|
2020-02-27 23:42:39 +00:00
|
|
|
processor.ctx.window.set_mouse_visible(true);
|
|
|
|
processor.mouse_input(state, button);
|
|
|
|
processor.ctx.terminal.dirty = true;
|
2019-10-05 00:29:26 +00:00
|
|
|
},
|
2020-03-11 22:31:59 +00:00
|
|
|
WindowEvent::ModifiersChanged(modifiers) => {
|
|
|
|
processor.modifiers_input(modifiers)
|
|
|
|
},
|
2020-03-07 22:17:38 +00:00
|
|
|
WindowEvent::CursorMoved { position, .. } => {
|
2019-10-05 00:29:26 +00:00
|
|
|
processor.ctx.window.set_mouse_visible(true);
|
2020-06-18 01:02:56 +00:00
|
|
|
processor.mouse_moved(position);
|
2019-10-05 00:29:26 +00:00
|
|
|
},
|
2020-03-07 22:17:38 +00:00
|
|
|
WindowEvent::MouseWheel { delta, phase, .. } => {
|
2019-10-05 00:29:26 +00:00
|
|
|
processor.ctx.window.set_mouse_visible(true);
|
2020-01-05 01:00:50 +00:00
|
|
|
processor.mouse_wheel_input(delta, phase);
|
2019-10-05 00:29:26 +00:00
|
|
|
},
|
2020-03-07 22:17:38 +00:00
|
|
|
WindowEvent::Focused(is_focused) => {
|
2019-10-05 00:29:26 +00:00
|
|
|
if window_id == processor.ctx.window.window_id() {
|
|
|
|
processor.ctx.terminal.is_focused = is_focused;
|
|
|
|
processor.ctx.terminal.dirty = true;
|
|
|
|
|
|
|
|
if is_focused {
|
|
|
|
processor.ctx.window.set_urgent(false);
|
|
|
|
} else {
|
|
|
|
processor.ctx.window.set_mouse_visible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
processor.on_focus_change(is_focused);
|
|
|
|
}
|
|
|
|
},
|
2020-03-07 22:17:38 +00:00
|
|
|
WindowEvent::DroppedFile(path) => {
|
2019-10-05 00:29:26 +00:00
|
|
|
let path: String = path.to_string_lossy().into();
|
2020-06-03 00:01:26 +00:00
|
|
|
processor.ctx.write_to_pty((path + " ").into_bytes());
|
2019-10-05 00:29:26 +00:00
|
|
|
},
|
2020-03-07 22:17:38 +00:00
|
|
|
WindowEvent::CursorLeft { .. } => {
|
2020-08-14 07:26:42 +00:00
|
|
|
processor.ctx.mouse.inside_text_area = false;
|
2019-11-03 20:59:28 +00:00
|
|
|
|
|
|
|
if processor.highlighted_url.is_some() {
|
|
|
|
processor.ctx.terminal.dirty = true;
|
|
|
|
}
|
|
|
|
},
|
2020-03-07 22:17:38 +00:00
|
|
|
WindowEvent::KeyboardInput { is_synthetic: true, .. }
|
|
|
|
| WindowEvent::TouchpadPressure { .. }
|
|
|
|
| WindowEvent::ScaleFactorChanged { .. }
|
|
|
|
| WindowEvent::CursorEntered { .. }
|
|
|
|
| WindowEvent::AxisMotion { .. }
|
|
|
|
| WindowEvent::HoveredFileCancelled
|
|
|
|
| WindowEvent::Destroyed
|
|
|
|
| WindowEvent::ThemeChanged(_)
|
|
|
|
| WindowEvent::HoveredFile(_)
|
|
|
|
| WindowEvent::Touch(_)
|
|
|
|
| WindowEvent::Moved(_) => (),
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
},
|
2019-11-11 21:05:24 +00:00
|
|
|
GlutinEvent::Suspended { .. }
|
2019-10-05 00:29:26 +00:00
|
|
|
| GlutinEvent::NewEvents { .. }
|
2020-03-11 22:31:59 +00:00
|
|
|
| GlutinEvent::DeviceEvent { .. }
|
2020-01-05 01:00:50 +00:00
|
|
|
| GlutinEvent::MainEventsCleared
|
|
|
|
| GlutinEvent::RedrawEventsCleared
|
2019-10-05 00:29:26 +00:00
|
|
|
| GlutinEvent::Resumed
|
|
|
|
| GlutinEvent::LoopDestroyed => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Check if an event is irrelevant and can be skipped.
|
2020-10-29 04:17:33 +00:00
|
|
|
fn skip_event(event: &GlutinEvent<'_, Event>) -> bool {
|
2019-10-05 00:29:26 +00:00
|
|
|
match event {
|
2020-08-06 01:09:46 +00:00
|
|
|
GlutinEvent::WindowEvent { event, .. } => matches!(
|
|
|
|
event,
|
2020-03-07 22:17:38 +00:00
|
|
|
WindowEvent::KeyboardInput { is_synthetic: true, .. }
|
2020-08-06 01:09:46 +00:00
|
|
|
| WindowEvent::TouchpadPressure { .. }
|
|
|
|
| WindowEvent::CursorEntered { .. }
|
|
|
|
| WindowEvent::AxisMotion { .. }
|
|
|
|
| WindowEvent::HoveredFileCancelled
|
|
|
|
| WindowEvent::Destroyed
|
|
|
|
| WindowEvent::HoveredFile(_)
|
|
|
|
| WindowEvent::Touch(_)
|
|
|
|
| WindowEvent::Moved(_)
|
|
|
|
),
|
2019-11-11 21:05:24 +00:00
|
|
|
GlutinEvent::Suspended { .. }
|
2019-10-05 00:29:26 +00:00
|
|
|
| GlutinEvent::NewEvents { .. }
|
2020-01-05 01:00:50 +00:00
|
|
|
| GlutinEvent::MainEventsCleared
|
2019-10-05 00:29:26 +00:00
|
|
|
| GlutinEvent::LoopDestroyed => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-29 04:17:33 +00:00
|
|
|
fn reload_config<T>(
|
|
|
|
path: &PathBuf,
|
|
|
|
processor: &mut input::Processor<'_, T, ActionContext<'_, N, T>>,
|
|
|
|
) where
|
2020-04-09 01:02:10 +00:00
|
|
|
T: EventListener,
|
|
|
|
{
|
2020-07-09 21:45:22 +00:00
|
|
|
if !processor.ctx.message_buffer.is_empty() {
|
|
|
|
processor.ctx.message_buffer.remove_target(LOG_TARGET_CONFIG);
|
|
|
|
processor.ctx.display_update_pending.dirty = true;
|
|
|
|
}
|
2020-04-09 01:02:10 +00:00
|
|
|
|
2020-08-22 20:55:27 +00:00
|
|
|
let config = match config::reload(&path, &processor.ctx.cli_options) {
|
2020-04-09 01:02:10 +00:00
|
|
|
Ok(config) => config,
|
|
|
|
Err(_) => return,
|
|
|
|
};
|
|
|
|
|
|
|
|
processor.ctx.terminal.update_config(&config);
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Reload cursor if we've changed its thickness.
|
2020-04-15 03:50:34 +00:00
|
|
|
if (processor.ctx.config.cursor.thickness() - config.cursor.thickness()).abs()
|
|
|
|
> std::f64::EPSILON
|
|
|
|
{
|
2020-07-09 21:45:22 +00:00
|
|
|
processor.ctx.display_update_pending.set_cursor_dirty();
|
2020-04-15 03:50:34 +00:00
|
|
|
}
|
|
|
|
|
2020-07-11 17:03:09 +00:00
|
|
|
if processor.ctx.config.ui_config.font != config.ui_config.font {
|
2020-05-05 22:50:23 +00:00
|
|
|
// Do not update font size if it has been changed at runtime.
|
2020-07-11 17:03:09 +00:00
|
|
|
if *processor.ctx.font_size == processor.ctx.config.ui_config.font.size {
|
|
|
|
*processor.ctx.font_size = config.ui_config.font.size;
|
2020-04-09 01:02:10 +00:00
|
|
|
}
|
|
|
|
|
2020-07-11 17:03:09 +00:00
|
|
|
let font = config.ui_config.font.clone().with_size(*processor.ctx.font_size);
|
2020-07-09 21:45:22 +00:00
|
|
|
processor.ctx.display_update_pending.set_font(font);
|
2020-04-09 01:02:10 +00:00
|
|
|
}
|
|
|
|
|
2020-07-15 19:59:32 +00:00
|
|
|
// Update display if padding options were changed.
|
|
|
|
let window_config = &processor.ctx.config.ui_config.window;
|
2020-09-27 22:36:08 +00:00
|
|
|
if window_config.padding(1.) != config.ui_config.window.padding(1.)
|
2020-07-15 19:59:32 +00:00
|
|
|
|| window_config.dynamic_padding != config.ui_config.window.dynamic_padding
|
|
|
|
{
|
|
|
|
processor.ctx.display_update_pending.dirty = true;
|
|
|
|
}
|
|
|
|
|
2020-07-11 17:03:09 +00:00
|
|
|
// Live title reload.
|
|
|
|
if !config.ui_config.dynamic_title()
|
|
|
|
|| processor.ctx.config.ui_config.window.title != config.ui_config.window.title
|
|
|
|
{
|
|
|
|
processor.ctx.window.set_title(&config.ui_config.window.title);
|
|
|
|
}
|
|
|
|
|
2020-10-12 09:22:36 +00:00
|
|
|
#[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))]
|
2020-07-28 10:00:55 +00:00
|
|
|
if processor.ctx.event_loop.is_wayland() {
|
|
|
|
processor.ctx.window.set_wayland_theme(&config.colors);
|
2020-04-09 01:02:10 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 21:14:13 +00:00
|
|
|
// Set subpixel anti-aliasing.
|
|
|
|
#[cfg(target_os = "macos")]
|
2020-07-11 17:03:09 +00:00
|
|
|
set_font_smoothing(config.ui_config.font.use_thin_strokes());
|
2020-05-17 21:14:13 +00:00
|
|
|
|
2020-04-09 01:02:10 +00:00
|
|
|
*processor.ctx.config = config;
|
|
|
|
|
|
|
|
processor.ctx.terminal.dirty = true;
|
|
|
|
}
|
|
|
|
|
2020-07-09 21:45:22 +00:00
|
|
|
/// Submit the pending changes to the `Display`.
|
|
|
|
fn submit_display_update<T>(
|
|
|
|
&mut self,
|
|
|
|
terminal: &mut Term<T>,
|
|
|
|
old_is_searching: bool,
|
|
|
|
display_update_pending: DisplayUpdate,
|
|
|
|
) where
|
|
|
|
T: EventListener,
|
|
|
|
{
|
|
|
|
// Compute cursor positions before resize.
|
|
|
|
let num_lines = terminal.screen_lines();
|
|
|
|
let cursor_at_bottom = terminal.grid().cursor.point.line + 1 == num_lines;
|
2020-07-15 21:27:32 +00:00
|
|
|
let origin_at_bottom = if terminal.mode().contains(TermMode::VI) {
|
|
|
|
terminal.vi_mode_cursor.point.line == num_lines - 1
|
|
|
|
} else {
|
|
|
|
self.search_state.direction == Direction::Left
|
|
|
|
};
|
2020-07-09 21:45:22 +00:00
|
|
|
|
|
|
|
self.display.handle_update(
|
|
|
|
terminal,
|
|
|
|
&mut self.notifier,
|
|
|
|
&self.message_buffer,
|
|
|
|
self.search_state.regex.is_some(),
|
|
|
|
&self.config,
|
|
|
|
display_update_pending,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Scroll to make sure search origin is visible and content moves as little as possible.
|
|
|
|
if !old_is_searching && self.search_state.regex.is_some() {
|
|
|
|
let display_offset = terminal.grid().display_offset();
|
|
|
|
if display_offset == 0 && cursor_at_bottom && !origin_at_bottom {
|
|
|
|
terminal.scroll_display(Scroll::Delta(1));
|
|
|
|
} else if display_offset != 0 && origin_at_bottom {
|
|
|
|
terminal.scroll_display(Scroll::Delta(-1));
|
|
|
|
}
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
2020-07-09 21:45:22 +00:00
|
|
|
}
|
2019-10-05 00:29:26 +00:00
|
|
|
|
2020-07-09 21:45:22 +00:00
|
|
|
/// Write the ref test results to the disk.
|
|
|
|
fn write_ref_test_results<T>(&self, terminal: &Term<T>) {
|
2020-05-05 22:50:23 +00:00
|
|
|
// Dump grid state.
|
2019-10-05 00:29:26 +00:00
|
|
|
let mut grid = terminal.grid().clone();
|
2020-11-05 04:45:14 +00:00
|
|
|
grid.initialize_all();
|
2019-10-05 00:29:26 +00:00
|
|
|
grid.truncate();
|
|
|
|
|
|
|
|
let serialized_grid = json::to_string(&grid).expect("serialize grid");
|
|
|
|
|
|
|
|
let serialized_size = json::to_string(&self.display.size_info).expect("serialize size");
|
|
|
|
|
|
|
|
let serialized_config = format!("{{\"history_size\":{}}}", grid.history_size());
|
|
|
|
|
|
|
|
File::create("./grid.json")
|
|
|
|
.and_then(|mut f| f.write_all(serialized_grid.as_bytes()))
|
|
|
|
.expect("write grid.json");
|
|
|
|
|
|
|
|
File::create("./size.json")
|
|
|
|
.and_then(|mut f| f.write_all(serialized_size.as_bytes()))
|
|
|
|
.expect("write size.json");
|
|
|
|
|
|
|
|
File::create("./config.json")
|
|
|
|
.and_then(|mut f| f.write_all(serialized_config.as_bytes()))
|
|
|
|
.expect("write config.json");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct EventProxy(EventLoopProxy<Event>);
|
|
|
|
|
|
|
|
impl EventProxy {
|
|
|
|
pub fn new(proxy: EventLoopProxy<Event>) -> Self {
|
|
|
|
EventProxy(proxy)
|
|
|
|
}
|
2020-06-18 01:02:56 +00:00
|
|
|
|
|
|
|
/// Send an event to the event loop.
|
|
|
|
pub fn send_event(&self, event: Event) {
|
|
|
|
let _ = self.0.send_event(event);
|
|
|
|
}
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl EventListener for EventProxy {
|
2020-06-18 01:02:56 +00:00
|
|
|
fn send_event(&self, event: TerminalEvent) {
|
|
|
|
let _ = self.0.send_event(Event::TerminalEvent(event));
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
}
|