diff options
author | Elaina Martineau <elainamartineau@gmail.com> | 2019-07-08 12:13:55 -0600 |
---|---|---|
committer | Christian Duerr <chrisduerr@users.noreply.github.com> | 2019-07-08 18:13:55 +0000 |
commit | 84aca672964e29b5b4503b7da7bc34fc395f08ab (patch) | |
tree | 01c6d670624809ad7e7b560c0beb76f8f77f5bd0 /alacritty_terminal/src/input.rs | |
parent | 7331e89122c464e7b1a73b2e7b20399f832a5913 (diff) | |
download | r-alacritty-84aca672964e29b5b4503b7da7bc34fc395f08ab.tar.gz r-alacritty-84aca672964e29b5b4503b7da7bc34fc395f08ab.tar.bz2 r-alacritty-84aca672964e29b5b4503b7da7bc34fc395f08ab.zip |
Change mouse cursor when hovering over the message bar
Diffstat (limited to 'alacritty_terminal/src/input.rs')
-rw-r--r-- | alacritty_terminal/src/input.rs | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/alacritty_terminal/src/input.rs b/alacritty_terminal/src/input.rs index b4ea5910..697c439f 100644 --- a/alacritty_terminal/src/input.rs +++ b/alacritty_terminal/src/input.rs @@ -412,11 +412,19 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { let cell_changed = prev_line != self.ctx.mouse().line || prev_col != self.ctx.mouse().column; - let mouse_moved = cell_changed || prev_side != cell_side; + + // If the mouse hasn't changed cells, do nothing + if cell_changed || prev_side != cell_side { + return; + } // Only report motions when cell changed and mouse is not over the message bar - if self.message_at_point(Some(point)).is_some() || !mouse_moved { + if let Some(message) = self.message_at_point(Some(point)) { + self.update_message_cursor(point, message); + return; + } else { + self.ctx.terminal_mut().reset_mouse_cursor(); } // Don't launch URLs if mouse has moved @@ -910,6 +918,15 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { has_binding } + /// Set the cursor depending on where the mouse is on the message bar + fn update_message_cursor(&mut self, point: Point, message: Message) { + if self.message_close_at_point(point, message) { + self.ctx.terminal_mut().set_mouse_cursor(MouseCursor::Hand); + } else { + self.ctx.terminal_mut().set_mouse_cursor(MouseCursor::Default); + } + } + /// Return the message bar's message if there is some at the specified point fn message_at_point(&mut self, point: Option<Point>) -> Option<Message> { if let (Some(point), Some(message)) = @@ -924,16 +941,25 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> { None } + /// Whether the point is over the message bar's close button + fn message_close_at_point(&self, point: Point, message: Message) -> bool { + let size = self.ctx.size_info(); + point.col + message_bar::CLOSE_BUTTON_TEXT.len() >= size.cols() + && point.line == size.lines() - message.text(&size).len() + } + /// Handle clicks on the message bar. fn on_message_bar_click(&mut self, button_state: ElementState, point: Point, message: Message) { match button_state { ElementState::Released => self.copy_selection(), ElementState::Pressed => { - let size = self.ctx.size_info(); - if point.col + message_bar::CLOSE_BUTTON_TEXT.len() >= size.cols() - && point.line == size.lines() - message.text(&size).len() - { + if self.message_close_at_point(point, message) { self.ctx.terminal_mut().message_buffer_mut().pop(); + if let Some(message) = self.message_at_point(Some(point)) { + self.update_message_cursor(point, message); + } else { + self.ctx.terminal_mut().reset_mouse_cursor(); + } } self.ctx.clear_selection(); |