summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2021-05-09 20:44:14 +0000
committerChristian Duerr <contact@christianduerr.com>2021-05-09 21:08:18 +0000
commit2cf3d9eb39865e47ce30ae1592a1796473e6a11a (patch)
tree0fdeaeef16ddc6189bfda9f4c6c3737864a9e9df
parent605ddd9898f36b4993a3dbacc15382455dd82448 (diff)
downloadalacritty-2cf3d9eb39865e47ce30ae1592a1796473e6a11a.tar.gz
alacritty-2cf3d9eb39865e47ce30ae1592a1796473e6a11a.zip
Fix unnecessary redraws due to hint highlighting
When the mouse cursor is moved by at least one cell, an update to the highlighted hints is triggered automatically. Previously this would always update the hints and redraw Alacritty regardless of the actualy change to the hint highlighting. By checking if the hint highlighting has actually changed, pointless redraws can be prevented. This is especially helpful since mouse motions often generate a lot of hint re-computations.
-rw-r--r--alacritty/src/display/hint.rs2
-rw-r--r--alacritty/src/display/mod.rs20
-rw-r--r--alacritty/src/event.rs3
3 files changed, 16 insertions, 9 deletions
diff --git a/alacritty/src/display/hint.rs b/alacritty/src/display/hint.rs
index 5e770bcf..6d61b094 100644
--- a/alacritty/src/display/hint.rs
+++ b/alacritty/src/display/hint.rs
@@ -165,7 +165,7 @@ impl HintState {
}
/// Hint match which was selected by the user.
-#[derive(Debug, Clone)]
+#[derive(PartialEq, Debug, Clone)]
pub struct HintMatch {
/// Action for handling the text.
pub action: HintAction,
diff --git a/alacritty/src/display/mod.rs b/alacritty/src/display/mod.rs
index 810d20f3..0947ab7e 100644
--- a/alacritty/src/display/mod.rs
+++ b/alacritty/src/display/mod.rs
@@ -657,26 +657,31 @@ impl Display {
}
/// Update the mouse/vi mode cursor hint highlighting.
+ ///
+ /// This will return whether the highlighted hints changed.
pub fn update_highlighted_hints<T>(
&mut self,
term: &Term<T>,
config: &Config,
mouse: &Mouse,
modifiers: ModifiersState,
- ) {
+ ) -> bool {
// Update vi mode cursor hint.
- if term.mode().contains(TermMode::VI) {
+ let vi_highlighted_hint = if term.mode().contains(TermMode::VI) {
let mods = ModifiersState::all();
let point = term.vi_mode_cursor.point;
- self.vi_highlighted_hint = hint::highlighted_at(&term, config, point, mods);
+ hint::highlighted_at(&term, config, point, mods)
} else {
- self.vi_highlighted_hint = None;
- }
+ None
+ };
+ let mut dirty = vi_highlighted_hint != self.vi_highlighted_hint;
+ self.vi_highlighted_hint = vi_highlighted_hint;
// Abort if mouse highlighting conditions are not met.
if !mouse.inside_text_area || !term.selection.as_ref().map_or(true, Selection::is_empty) {
+ dirty |= self.highlighted_hint.is_some();
self.highlighted_hint = None;
- return;
+ return dirty;
}
// Find highlighted hint at mouse position.
@@ -694,7 +699,10 @@ impl Display {
}
}
+ dirty |= self.highlighted_hint != highlighted_hint;
self.highlighted_hint = highlighted_hint;
+
+ dirty
}
/// Format search regex to account for the cursor and fullwidth characters.
diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs
index a895514f..64283eb7 100644
--- a/alacritty/src/event.rs
+++ b/alacritty/src/event.rs
@@ -1114,14 +1114,13 @@ impl<N: Notify + OnResize> Processor<N> {
}
if self.dirty || self.mouse.hint_highlight_dirty {
- self.display.update_highlighted_hints(
+ self.dirty |= self.display.update_highlighted_hints(
&terminal,
&self.config,
&self.mouse,
self.modifiers,
);
self.mouse.hint_highlight_dirty = false;
- self.dirty = true;
}
if self.dirty {