hterm: change mouse cursor style based on reporting mode
Some terminals (e.g. konsole & gnome-terminal) will change the mouse
cursor when the mouse reporting modes are enabled. This way the user
can see whether the terminal will respond to clicks or is dumb text.
Change-Id: Ie1c68d09a94bd58b3b143562d3112fee51c3ebaa
Reviewed-on: https://chromium-review.googlesource.com/517645
Reviewed-by: Brandon Gilmore <varz@google.com>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/hterm/js/hterm_scrollport.js b/hterm/js/hterm_scrollport.js
index c027102..094f3a3 100644
--- a/hterm/js/hterm_scrollport.js
+++ b/hterm/js/hterm_scrollport.js
@@ -298,7 +298,7 @@
'height: 100%;' +
'width: 100%;' +
'overflow: hidden;' +
- 'cursor: text;' +
+ 'cursor: var(--hterm-mouse-cursor-style);' +
'-webkit-user-select: none;' +
'-moz-user-select: none;');
diff --git a/hterm/js/hterm_terminal.js b/hterm/js/hterm_terminal.js
index 59839f7..05ace5c 100644
--- a/hterm/js/hterm_terminal.js
+++ b/hterm/js/hterm_terminal.js
@@ -834,6 +834,17 @@
};
/**
+ * Set the mouse cursor style based on the current terminal mode.
+ */
+hterm.Terminal.prototype.syncMouseStyle = function() {
+ this.document_.documentElement.style.setProperty(
+ '--hterm-mouse-cursor-style',
+ this.vt.mouseReport == this.vt.MOUSE_REPORT_DISABLED ?
+ 'var(--hterm-mouse-cursor-text)' :
+ 'var(--hterm-mouse-cursor-pointer)');
+};
+
+/**
* Return a copy of the current cursor position.
*
* @return {hterm.RowCol} The RowCol object representing the current position.
@@ -1363,6 +1374,9 @@
'}' +
':root {' +
' --hterm-blink-node-duration: 0.7s;' +
+ ' --hterm-mouse-cursor-text: text;' +
+ ' --hterm-mouse-cursor-pointer: default;' +
+ ' --hterm-mouse-cursor-style: var(--hterm-mouse-cursor-text);' +
'}' +
'@keyframes blink {' +
' from { opacity: 1.0; }' +
diff --git a/hterm/js/hterm_vt.js b/hterm/js/hterm_vt.js
index b8500c5..e80897c 100644
--- a/hterm/js/hterm_vt.js
+++ b/hterm/js/hterm_vt.js
@@ -736,11 +736,13 @@
case 1000: // Report on mouse clicks only.
this.mouseReport = (
state ? this.MOUSE_REPORT_CLICK : this.MOUSE_REPORT_DISABLED);
+ this.terminal.syncMouseStyle();
break;
case 1002: // Report on mouse clicks and drags
this.mouseReport = (
state ? this.MOUSE_REPORT_DRAG : this.MOUSE_REPORT_DISABLED);
+ this.terminal.syncMouseStyle();
break;
case 1010: // Scroll to bottom on tty output