From 3cc27a4d767a87c617b5213810dfce254bac1131 Mon Sep 17 00:00:00 2001 From: Tuomas Siipola Date: Wed, 22 Feb 2017 22:46:08 +0200 Subject: [PATCH] Set cursor only when its visibility changes --- src/display.rs | 4 ++-- src/event.rs | 2 +- src/window.rs | 12 ++++++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/display.rs b/src/display.rs index bdb5274c..3d13f465 100644 --- a/src/display.rs +++ b/src/display.rs @@ -231,8 +231,8 @@ impl Display { self.tx.clone() } - pub fn window(&self) -> &Window { - &self.window + pub fn window(&mut self) -> &mut Window { + &mut self.window } /// Process pending resize events diff --git a/src/event.rs b/src/event.rs index d6b0796a..fd33bfb3 100644 --- a/src/event.rs +++ b/src/event.rs @@ -261,7 +261,7 @@ impl Processor { pub fn process_events<'a>( &mut self, term: &'a FairMutex, - window: &Window + window: &mut Window ) -> MutexGuard<'a, Term> { // Terminal is lazily initialized the first time an event is returned // from the blocking WaitEventsIterator. Otherwise, the pty reader would diff --git a/src/window.rs b/src/window.rs index b90c242d..fa751352 100644 --- a/src/window.rs +++ b/src/window.rs @@ -53,6 +53,7 @@ type Result = ::std::result::Result; /// Wraps the underlying windowing library to provide a stable API in Alacritty pub struct Window { glutin_window: glutin::Window, + cursor_visible: bool, } /// Threadsafe APIs for the window @@ -218,6 +219,7 @@ impl Window { Ok(Window { glutin_window: window, + cursor_visible: true, }) } @@ -290,10 +292,12 @@ impl Window { } /// Set cursor visible - #[inline] - pub fn set_cursor_visible(&self, show: bool) { - self.glutin_window.set_cursor(if show { glutin::MouseCursor::Default } - else { glutin::MouseCursor::NoneCursor }); + pub fn set_cursor_visible(&mut self, visible: bool) { + if visible != self.cursor_visible { + self.cursor_visible = visible; + self.glutin_window.set_cursor(if visible { glutin::MouseCursor::Default } + else { glutin::MouseCursor::NoneCursor }); + } } }