[vte/vte-next] Add urxvt extended mouse tracking mode support



commit fa0b91a03291f7b989f759b8ed4cdfbc1b12e3f9
Author: Egmont Koblinger <egmont gmail com>
Date:   Wed Nov 9 22:47:37 2011 +0100

    Add urxvt extended mouse tracking mode support
    
    https://bugzilla.gnome.org/show_bug.cgi?id=662423

 src/vte-private.h |    3 ++
 src/vte.c         |   65 ++++++++++++++++++++++++++++++++++++----------------
 src/vteseq.c      |    5 ++++
 3 files changed, 53 insertions(+), 20 deletions(-)
---
diff --git a/src/vte-private.h b/src/vte-private.h
index dd5e41d..6d8dd3e 100644
--- a/src/vte-private.h
+++ b/src/vte-private.h
@@ -288,6 +288,9 @@ struct _VteBufferPrivate {
         /* Cursor */
         gboolean cursor_visible;
 
+        /* Mouse tracking */
+        gboolean mouse_urxvt_extension;
+
         /* FIXMEchpe: this is duplicated wiht VteBufferPrivate; keep just one
          * and update the other! (Not sure if this belongs in the view or the
          * buffer, although it _is_ set from vteseq.c.)
diff --git a/src/vte.c b/src/vte.c
index 92a6670..7dfc565 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -5505,11 +5505,12 @@ vte_view_get_mouse_tracking_info (VteView   *terminal,
 				      long           col,
 				      long           row,
 				      unsigned char *pb,
-				      unsigned char *px,
-				      unsigned char *py)
+                                       long          *px,
+				      long          *py)
 {
         VteBuffer *buffer;
-	unsigned char cb = 0, cx = 0, cy = 0;
+	unsigned char cb = 0;
+        long cx, cy;
 
         buffer = terminal->pvt->buffer;
 
@@ -5547,17 +5548,36 @@ vte_view_get_mouse_tracking_info (VteView   *terminal,
 		cb |= 16;
 	}
 
-	/* Encode the cursor coordinates. */
-	cx = 32 + CLAMP(1 + col,
-			1, buffer->pvt->column_count);
-	cy = 32 + CLAMP(1 + row,
-			1, buffer->pvt->row_count);;
+       /* Cursor coordinates */
+       cx = CLAMP(1 + col, 1, buffer->pvt->column_count);
+       cy = CLAMP(1 + row, 1, buffer->pvt->row_count);
 
 	*pb = cb;
 	*px = cx;
 	*py = cy;
 }
 
+static void
+vte_buffer_feed_mouse_event(VteBuffer *buffer,
+                            int        cb,
+                            long       cx,
+                            long       cy)
+{
+        char buf[LINE_MAX];
+        gint len = 0;
+
+        if (buffer->pvt->mouse_urxvt_extension) {
+                /* urxvt's extended mode (1015) */
+                len = g_snprintf(buf, sizeof(buf), _VTE_CAP_CSI "%d;%ld;%ldM", cb, cx, cy);
+        } else if (cx <= 231 && cy <= 231) {
+                /* legacy mode */
+                len = g_snprintf(buf, sizeof(buf), _VTE_CAP_CSI "M%c%c%c", cb, 32 + (guchar)cx, 32 + (guchar)cy);
+        }
+
+        /* Send event direct to the child, this is binary not text data */
+        vte_buffer_feed_child_binary(buffer, buf, len);
+}
+
 /*
  * vte_view_send_mouse_button_internal:
  * @terminal:
@@ -5571,11 +5591,15 @@ vte_view_send_mouse_button_internal(VteView *terminal,
 					long         x,
 					long         y)
 {
-	unsigned char cb, cx, cy;
-	char buf[LINE_MAX];
-	gint len;
+        VteBuffer *buffer;
+	unsigned char cb;
+        long cx, cy;
         long col, row;
 
+        buffer = terminal->pvt->buffer;
+        if (buffer == NULL)
+                return;
+
         if (!_vte_view_xy_to_grid(terminal, x, y, &col, &row))
                 return;
 
@@ -5583,9 +5607,7 @@ vte_view_send_mouse_button_internal(VteView *terminal,
 					      button, col, row,
 					      &cb, &cx, &cy);
 
-	/* Send event direct to the child, this is binary not text data */
-	len = g_snprintf(buf, sizeof(buf), _VTE_CAP_CSI "M%c%c%c", cb, cx, cy);
-	vte_buffer_feed_child_binary(terminal->pvt->buffer, buf, len);
+        vte_buffer_feed_mouse_event(buffer, cb, cx, cy);
 }
 
 /* Send a mouse button click/release notification. */
@@ -5621,11 +5643,15 @@ vte_view_maybe_send_mouse_button(VteView *terminal,
 static void
 vte_view_maybe_send_mouse_drag(VteView *terminal, GdkEventMotion *event)
 {
-	unsigned char cb, cx, cy;
-	char buf[LINE_MAX];
-	gint len;
+        VteBuffer *buffer;
+	unsigned char cb;
+        long cx, cy;
         long col, row;
 
+        buffer = terminal->pvt->buffer;
+        if (buffer == NULL)
+                return;
+
         (void) _vte_view_xy_to_grid(terminal, event->x, event->y, &col, &row);
 
 	/* First determine if we even want to send notification. */
@@ -5656,9 +5682,7 @@ vte_view_maybe_send_mouse_drag(VteView *terminal, GdkEventMotion *event)
 					      &cb, &cx, &cy);
 	cb += 32; /* for movement */
 
-	/* Send event direct to the child, this is binary not text data */
-	len = g_snprintf(buf, sizeof(buf), _VTE_CAP_CSI "M%c%c%c", cb, cx, cy);
-	vte_buffer_feed_child_binary(terminal->pvt->buffer, buf, len);
+        vte_buffer_feed_mouse_event(buffer, cb, cx, cy);
 }
 
 /* Clear all match hilites. */
@@ -12165,6 +12189,7 @@ vte_buffer_reset(VteBuffer *buffer,
 	}
 	/* Reset mouse motion events. */
         terminal->pvt->mouse_tracking_mode = MOUSE_TRACKING_NONE;
+        pvt->mouse_urxvt_extension = FALSE;
         terminal->pvt->mouse_last_button = 0;
         terminal->pvt->mouse_last_x = 0;
         terminal->pvt->mouse_last_y = 0;
diff --git a/src/vteseq.c b/src/vteseq.c
index 14b8c9a..d0e4cbd 100644
--- a/src/vteseq.c
+++ b/src/vteseq.c
@@ -614,6 +614,11 @@ vte_sequence_handler_decset_internal(VteBuffer *buffer,
 		{1010, NULL, NULL, NULL, NULL, NULL, NULL, NULL,},
 		/* 1011/rxvt: disallowed, scroll-on-keypress is set by user. */
 		{1011, NULL, NULL, NULL, NULL, NULL, NULL, NULL,},
+                /* 1015/urxvt: Extended mouse coordinates. */
+                {1015, &buffer->pvt->mouse_urxvt_extension, NULL, NULL,
+                 GINT_TO_POINTER(FALSE),
+                 GINT_TO_POINTER(TRUE),
+                 NULL, NULL,},
 		/* 1035: disallowed, don't know what to do with it. */
 		{1035, NULL, NULL, NULL, NULL, NULL, NULL, NULL,},
 		/* 1036: Meta-sends-escape. */



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