texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[5696] mouse scroll-wheel support


From: Gavin D. Smith
Subject: [5696] mouse scroll-wheel support
Date: Wed, 02 Jul 2014 13:42:54 +0000

Revision: 5696
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5696
Author:   gavin
Date:     2014-07-02 13:42:52 +0000 (Wed, 02 Jul 2014)
Log Message:
-----------
mouse scroll-wheel support

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/info/infomap.h
    trunk/info/session.c
    trunk/info/terminal.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2014-07-01 17:27:38 UTC (rev 5695)
+++ trunk/ChangeLog     2014-07-02 13:42:52 UTC (rev 5696)
@@ -1,3 +1,22 @@
+2014-07-02  Gavin Smith  <address@hidden>
+
+       * info/terminal.c (term_Km): New variable.
+       (terminal_begin_using_terminal, terminal_end_using_terminal): Enter
+       and leave mouse tracking mode.
+       (add_seq_to_byte_map, initialize_byte_map): Function
+       split out.
+       (initialize_byte_map): Bind term_Km sequence to KEY_MOUSE.
+       * info/infomap (KEY_MOUSE): New symbol.
+       (KEYMAP_META_BASE, KEYMAP_SIZE): Updated.
+
+       * info/session.c (mouse_reporting_on, mouse_reporting_off)
+       (mouse_event_handler): New functions.
+       (mouse_cb, mouse_cx, mouse_cy): New variables.
+       (get_input_key): Set them if mouse event occurred.
+       (get_input_key_internal): Initialize variable properly.
+       (info_read_and_dispatch): Call mouse_event_handler if mouse event
+       received.
+
 2014-07-01  Gavin Smith  <address@hidden>
 
        * info/session.c (get_input_key): Try to ignore sequences in the input

Modified: trunk/info/infomap.h
===================================================================
--- trunk/info/infomap.h        2014-07-01 17:27:38 UTC (rev 5695)
+++ trunk/info/infomap.h        2014-07-02 13:42:52 UTC (rev 5696)
@@ -89,14 +89,15 @@
 #define KEY_CTL_RIGHT_ARROW    267
 #define KEY_CTL_DELETE         268
 #define KEY_BACK_TAB           269
+#define KEY_MOUSE               270
 
 /* Add this to get the offset of the key binding with the meta key. */
-#define KEYMAP_META_BASE 270
+#define KEYMAP_META_BASE 271
 
 /* Number of entries in a Keymap: 256 entries for plain byte values plus
    mappings for special keys.  The bindings for the key chords with meta
    follow. */
-#define KEYMAP_SIZE (270 * 2)
+#define KEYMAP_SIZE (KEYMAP_META_BASE * 2)
 
 #define KEYMAP_META(k) ((k) < KEYMAP_META_BASE ? (k) + KEYMAP_META_BASE : (k))
 

Modified: trunk/info/session.c
===================================================================
--- trunk/info/session.c        2014-07-01 17:27:38 UTC (rev 5695)
+++ trunk/info/session.c        2014-07-02 13:42:52 UTC (rev 5696)
@@ -40,6 +40,7 @@
 static void info_handle_pointer (char *label, WINDOW *window);
 static void display_info_keyseq (int expecting_future_input);
 char *node_printed_rep (NODE *node);
+static int get_byte_from_input_buffer (unsigned char *key);
 
 static REFERENCE *select_menu_digit (WINDOW *window, unsigned char key);
 static void gc_file_buffers_and_nodes (void);
@@ -51,6 +52,7 @@
 /* **************************************************************** */
 
 static void info_read_and_dispatch (void);
+static void mouse_event_handler (void);
 
 /* The place that we are reading input from. */
 static FILE *info_input_stream = NULL;
@@ -163,6 +165,9 @@
   close_dribble_file ();
 }
 
+void mouse_reporting_on (void);
+void mouse_reporting_off (void);
+
 static void
 info_read_and_dispatch (void)
 {
@@ -177,16 +182,20 @@
       info_initialize_numeric_arg ();
 
       initialize_keyseq ();
+      mouse_reporting_on ();
       key = get_input_key ();
+      mouse_reporting_off ();
       if (key == -1)
         continue;
 
       window_clear_echo_area ();
-
       info_error_was_printed = 0;
 
-      /* Do the selected command. */
-      info_dispatch_on_key (key, info_keymap);
+      if (key == KEY_MOUSE)
+        mouse_event_handler ();
+      else
+        /* Do the selected command. */
+        info_dispatch_on_key (key, info_keymap);
     }
 }
 
@@ -464,6 +473,42 @@
 
 static int get_input_key_internal (void);
 
+/* Whether to process or skip mouse events in the input stream. */
+static int mouse_reporting = 0;
+unsigned char mouse_cb, mouse_cx, mouse_cy;
+
+/* Handle mouse event given that mouse_cb, mouse_cx and mouse_cy contain the
+   data from the event.  See the "XTerm Control Sequences" document for their
+   meanings. */
+static void
+mouse_event_handler (void)
+{
+  if (mouse_cb & 0x40)
+    {
+      switch (mouse_cb & 0x03)
+        {
+        case 0: /* Mouse button 4 (scroll up). */
+          info_up_line (active_window, 3, KEY_MOUSE);
+          break;
+        case 1: /* Mouse button 5 (scroll down). */
+          info_down_line (active_window, 3, KEY_MOUSE);
+          break;
+        }
+    }
+}
+
+void
+mouse_reporting_on (void)
+{
+  mouse_reporting = 1;
+}
+
+void
+mouse_reporting_off (void)
+{
+  mouse_reporting = 0;
+}
+
 /* Return number representing a key that has been pressed, which is an index
    into info_keymap and echo_area_keymap. */
 int
@@ -472,7 +517,19 @@
   int ret = -1;
 
   while (ret == -1)
-    ret = get_input_key_internal ();
+    {
+      ret = get_input_key_internal ();
+
+      if (ret == KEY_MOUSE)
+        {
+          get_byte_from_input_buffer (&mouse_cb);
+          get_byte_from_input_buffer (&mouse_cx);
+          get_byte_from_input_buffer (&mouse_cy);
+
+          if (!mouse_reporting)
+            ret = -1;
+        }
+    }
   return ret;
 }
 
@@ -483,7 +540,7 @@
 {
   BYTEMAP_ENTRY *b;
   unsigned char c;
-  int esc_seen;
+  int esc_seen = 0;
   int pop_start;
   unsigned char first;
   fill_input_buffer (1);

Modified: trunk/info/terminal.c
===================================================================
--- trunk/info/terminal.c       2014-07-01 17:27:38 UTC (rev 5695)
+++ trunk/info/terminal.c       2014-07-02 13:42:52 UTC (rev 5696)
@@ -110,6 +110,9 @@
 /* The string to turn off inverse mode, if this term has one. */
 static char *term_invend;
 
+/* String introducing a mouse event. */
+static char *term_Km;
+
 /* Although I can't find any documentation that says this is supposed to
    return its argument, all the code I've looked at (termutils, less)
    does so, so fine.  */
@@ -133,6 +136,13 @@
 {
   RETSIGTYPE (*sigsave) (int signum);
 
+  /* Turn on mouse reporting.  This is "normal tracking mode" supported by
+     xterm.  The presence of the Km capability may not be a reliable way to
+     tell whether this mode exists, but sending the following sequence is
+     probably harmless if it doesn't.  */
+  if (term_Km)
+    send_to_terminal ("\033[?1000h");
+
   if (term_keypad_on)
       send_to_terminal (term_keypad_on);
   
@@ -164,6 +174,10 @@
 {
   RETSIGTYPE (*sigsave) (int signum);
 
+  /* Turn off mouse reporting ("normal tracking mode"). */
+  if (term_Km)
+    send_to_terminal ("\033[?1000l");
+
   if (term_keypad_off)
       send_to_terminal (term_keypad_off);
   
@@ -504,6 +518,30 @@
    keys. */
 BYTEMAP_ENTRY *byte_seq_to_key;
 
+static void
+add_seq_to_byte_map (int key_id, unsigned char *seq)
+{
+  BYTEMAP_ENTRY *b = byte_seq_to_key;
+
+  unsigned char *c = seq;
+  for (; *c; c++)
+    {
+      if (c[1] == '\0') /* Last character. */
+        {
+          b[*c].type = BYTEMAP_KEY;
+          b[*c].key = key_id;
+        }
+      else
+        {
+          b[*c].type = BYTEMAP_MAP;
+          b[*c].key = 0;
+          if (!b[*c].next)
+            b[*c].next = xzalloc (256 * sizeof (BYTEMAP_ENTRY));
+          b = b[*c].next;
+        }
+    }
+}
+
 /* Initialize byte map read in get_input_key. */
 static void
 initialize_byte_map (void)
@@ -554,30 +592,15 @@
   /* For each special key, record its byte sequence. */
   for (i = 0; i < sizeof (keys) / sizeof (*keys); i++)
     {
-      unsigned char *c;
-      BYTEMAP_ENTRY *b = byte_seq_to_key;
-
       if (!*keys[i].byte_seq)
         continue; /* No byte sequence known for this key. */
-      c = *keys[i].byte_seq;
-      for (; *c; c++)
-        {
-          if (c[1] == '\0') /* Last character. */
-            {
-              b[*c].type = BYTEMAP_KEY;
-              b[*c].key = keys[i].key_id;
-            }
-          else
-            {
-              b[*c].type = BYTEMAP_MAP;
-              b[*c].key = 0;
-              if (!b[*c].next)
-                b[*c].next = xzalloc (256 * sizeof (BYTEMAP_ENTRY));
-              b = b[*c].next;
-            }
-        }
+
+      add_seq_to_byte_map (keys[i].key_id, *keys[i].byte_seq);
     }
 
+  if (term_Km)
+    add_seq_to_byte_map (KEY_MOUSE, term_Km);
+
   /* Special case for ESC: Can introduce special key sequences, represent the
      Meta key being pressed, or be a key on its own. */
   byte_seq_to_key['\033'].type = BYTEMAP_ESC;
@@ -723,6 +746,9 @@
 
   term_bt = tgetstr ("bt", &buffer);
 
+  /* String introducing a mosue event. */
+  term_Km = tgetstr ("Km", &buffer);
+
   initialize_byte_map ();
 
   /* If this terminal is not cursor addressable, then it is really dumb. */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]