From 87e5b1aa25ea61937fa5f79668d2a46e88707c5e Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Thu, 18 Jun 2020 01:02:56 +0000 Subject: Add automatic scrolling during selection This adds a new `Scheduler` which allows for staging events to be processed at a later time. If there is a selection active and the mouse is above or below the window, the viewport will now scroll torwards the direction of the mouse. The amount of lines scrolled depends on the distance of the mouse to the boundaries used for selection scrolling. To make it possible to scroll while in fullscreen, the selection scrolling area includes the padding of the window and is at least 5 pixels high in case there is not enough padding present. --- alacritty_terminal/src/event.rs | 8 -------- alacritty_terminal/src/grid/mod.rs | 2 +- alacritty_terminal/src/term/mod.rs | 15 +++++++++++++-- alacritty_terminal/src/util.rs | 22 +++------------------- 4 files changed, 17 insertions(+), 30 deletions(-) (limited to 'alacritty_terminal/src') diff --git a/alacritty_terminal/src/event.rs b/alacritty_terminal/src/event.rs index 20b105cd..296e3bb0 100644 --- a/alacritty_terminal/src/event.rs +++ b/alacritty_terminal/src/event.rs @@ -1,17 +1,12 @@ use std::borrow::Cow; use std::fmt::{self, Debug, Formatter}; -use std::path::PathBuf; use std::sync::Arc; -use crate::message_bar::Message; use crate::term::{ClipboardType, SizeInfo}; #[derive(Clone)] pub enum Event { - DPRChanged(f64, (u32, u32)), - ConfigReload(PathBuf), MouseCursorDirty, - Message(Message), Title(String), ClipboardStore(ClipboardType, String), ClipboardLoad(ClipboardType, Arc String + Sync + Send + 'static>), @@ -23,10 +18,7 @@ pub enum Event { impl Debug for Event { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { - Event::DPRChanged(scale, size) => write!(f, "DPRChanged({}, {:?})", scale, size), - Event::ConfigReload(path) => write!(f, "ConfigReload({:?})", path), Event::MouseCursorDirty => write!(f, "MouseCursorDirty"), - Event::Message(msg) => write!(f, "Message({:?})", msg), Event::Title(title) => write!(f, "Title({})", title), Event::ClipboardStore(ty, text) => write!(f, "ClipboardStore({:?}, {})", ty, text), Event::ClipboardLoad(ty, _) => write!(f, "ClipboardLoad({:?})", ty), diff --git a/alacritty_terminal/src/grid/mod.rs b/alacritty_terminal/src/grid/mod.rs index 0c338fba..d5932639 100644 --- a/alacritty_terminal/src/grid/mod.rs +++ b/alacritty_terminal/src/grid/mod.rs @@ -148,7 +148,7 @@ pub struct Grid { max_scroll_limit: usize, } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub enum Scroll { Lines(isize), PageUp, diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs index 6aac05d9..33d2e14e 100644 --- a/alacritty_terminal/src/term/mod.rs +++ b/alacritty_terminal/src/term/mod.rs @@ -691,13 +691,24 @@ impl SizeInfo { Column(((self.width - 2. * self.padding_x) / self.cell_width) as usize) } + #[inline] + pub fn padding_right(&self) -> usize { + (self.padding_x + (self.width - 2. * self.padding_x) % self.cell_width) as usize + } + + #[inline] + pub fn padding_bottom(&self) -> usize { + (self.padding_y + (self.height - 2. * self.padding_y) % self.cell_height) as usize + } + /// Check if coordinates are inside the terminal grid. /// /// The padding is not counted as part of the grid. + #[inline] pub fn contains_point(&self, x: usize, y: usize) -> bool { - x < (self.width - self.padding_x) as usize + x < (self.width as usize - self.padding_right()) && x >= self.padding_x as usize - && y < (self.height - self.padding_y) as usize + && y < (self.height as usize - self.padding_bottom()) && y >= self.padding_y as usize } diff --git a/alacritty_terminal/src/util.rs b/alacritty_terminal/src/util.rs index fde06966..f996359a 100644 --- a/alacritty_terminal/src/util.rs +++ b/alacritty_terminal/src/util.rs @@ -1,6 +1,6 @@ use std::ffi::OsStr; +use std::io; use std::process::{Command, Stdio}; -use std::{cmp, io}; #[cfg(not(windows))] use std::os::unix::process::CommandExt; @@ -13,22 +13,18 @@ use winapi::um::winbase::{CREATE_NEW_PROCESS_GROUP, CREATE_NO_WINDOW}; /// Threading utilities. pub mod thread { /// Like `thread::spawn`, but with a `name` argument. - pub fn spawn_named(name: S, f: F) -> ::std::thread::JoinHandle + pub fn spawn_named(name: S, f: F) -> std::thread::JoinHandle where F: FnOnce() -> T + Send + 'static, T: Send + 'static, S: Into, { - ::std::thread::Builder::new().name(name.into()).spawn(f).expect("thread spawn works") + std::thread::Builder::new().name(name.into()).spawn(f).expect("thread spawn works") } pub use std::thread::*; } -pub fn limit(value: T, min: T, max: T) -> T { - cmp::min(cmp::max(value, min), max) -} - #[cfg(not(windows))] pub fn start_daemon(program: &str, args: I) -> io::Result<()> where @@ -79,15 +75,3 @@ where .spawn() .map(|_| ()) } - -#[cfg(test)] -mod tests { - use super::limit; - - #[test] - fn limit_works() { - assert_eq!(10, limit(10, 0, 100)); - assert_eq!(10, limit(5, 10, 100)); - assert_eq!(100, limit(1000, 10, 100)); - } -} -- cgit