shithub: orca

Download patch

ref: 7bd17f61f98baa021c9c9596dabd356c0a5395ce
parent: bda14805d755dff131f72099222ee88984658f92
author: cancel <cancel@cancel.fm>
date: Mon Dec 10 20:23:00 EST 2018

Add smarter mouse tracking enable/disable

--- a/tui_main.c
+++ b/tui_main.c
@@ -1003,11 +1003,22 @@
 
 void app_mouse_event(App_state* a, Usz y, Usz x, mmask_t mouse_bstate) {
   if (mouse_bstate & BUTTON1_RELEASED) {
-    app_jump_cursor_to(a, y, x);
+    // hard-disables tracking, but also disables further mouse stuff.
+    // mousemask() with our original parameters seems to work to get into the
+    // state we want, though.
+    //
+    // printf("\033[?1003l\n");
+    mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL);
     a->is_mouse_down = false;
   } else if (mouse_bstate & BUTTON1_PRESSED) {
     app_jump_cursor_to(a, y, x);
     a->is_mouse_down = true;
+    // some sequence to hopefully make terminal start reporting all further
+    // mouse movement events. 'REPORT_MOUSE_POSITION' alone in the mousemask
+    // doesn't seem to work, at least not for xterm. we need to set it only
+    // only when needed, otherwise some terminals will send movement updates
+    // when we don't want them.
+    printf("\033[?1003h\n");
   } else if (a->is_mouse_down) {
     app_jump_cursor_to(a, y, x);
   }
@@ -1313,11 +1324,6 @@
 
   mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL);
   if (has_mouse()) {
-    // some sequence to hopefully make terminal report mouse movement events.
-    // 'REPORT_MOUSE_POSITION' alone in the mousemask doesn't seem to work, at
-    // least not for xterm.
-    printf("\033[?1003h\n");
-    // use printf("\033[?1003l\n"); to disable
     // no waiting for distinguishing click from press
     mouseinterval(0);
   }