summaryrefslogtreecommitdiff
path: root/src/window.rs
diff options
context:
space:
mode:
authorDustin <dustin1114@gmail.com>2017-12-24 15:15:42 -0500
committerJoe Wilm <jwilm@users.noreply.github.com>2017-12-24 12:15:42 -0800
commitcaddac918e21a2b881a929eb371acf9f4d82cd0c (patch)
tree934f3ef81485d2b0a6dac6afd24011a6e10e5bf3 /src/window.rs
parented91eb365e8e24b0ef64351235ab3f8022a8e7b3 (diff)
downloadalacritty-caddac918e21a2b881a929eb371acf9f4d82cd0c.tar.gz
alacritty-caddac918e21a2b881a929eb371acf9f4d82cd0c.zip
Change mouse cursor on terminal mode change (#865)
Some terminals have functionality around changing the type of mouse cursor dynamically (arrow and text) based on which mode(s) the VTE is in. For example, gnome-terminal changes the cursor from text (default) to an arrow when opening programs that track mouse events (e.g. vim, emacs, tmux, htop, etc.). The programs all allow using the mouse interactively under some circumstances (like executing `set mouse=a` in vim). The programs that use an interactive mouse set the terminal mode to different values. Though they're not entirely the same terminal mode across programs, an emulator like vte (the library gnome-terminal implements), changes the mouse cursor if the mouse mode is one of the following: - 1000: Mouse Click Tracking - 1001: Mouse Highlight Tracking - 1002: Mouse Cell Motion Tracking - 1003: Mouse All Motion Tracking - 1004: Mouse Focus Tracking See https://github.com/GNOME/vte/blob/6acfa59dfcceef65c1f7e3570db37ab245f049c4/src/vteseq.cc#L708 for more information. This commit adds functionality that changes the winit/glutin `MouseCursor` when a mouse-listening mode of 1000-1004 is set. It behaves similarly to when the window title changes.
Diffstat (limited to 'src/window.rs')
-rw-r--r--src/window.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/window.rs b/src/window.rs
index e42151fd..aec4b76d 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -16,9 +16,12 @@ use std::fmt::{self, Display};
use std::ops::Deref;
use gl;
-use glutin::{self, EventsLoop, WindowBuilder, Event, MouseCursor, CursorState, ControlFlow, ContextBuilder};
+use glutin::{self, ContextBuilder, ControlFlow, CursorState, Event, EventsLoop,
+ MouseCursor as GlutinMouseCursor, WindowBuilder};
use glutin::GlContext;
+use MouseCursor;
+
use config::WindowConfig;
/// Window errors
@@ -200,7 +203,7 @@ impl Window {
let window = ::glutin::GlWindow::new(window, context, &event_loop)?;
// Text cursor
- window.set_cursor(MouseCursor::Text);
+ window.set_cursor(GlutinMouseCursor::Text);
// Set OpenGL symbol loader
gl::load_with(|symbol| window.get_proc_address(symbol) as *const _);
@@ -284,6 +287,14 @@ impl Window {
self.window.set_title(title);
}
+ #[inline]
+ pub fn set_mouse_cursor(&self, cursor: MouseCursor) {
+ self.window.set_cursor(match cursor {
+ MouseCursor::Arrow => GlutinMouseCursor::Arrow,
+ MouseCursor::Text => GlutinMouseCursor::Text,
+ });
+ }
+
/// Set cursor visible
pub fn set_cursor_visible(&mut self, visible: bool) {
if visible != self.cursor_visible {