[vte/vte-0-34] emulation: Support xterm extended mouse tracking mode



commit e75d806d8a79d7b7e28d982da05e066c3681ea32
Author: Christian Persch <chpe gnome org>
Date:   Tue Aug 21 00:42:14 2012 +0200

    emulation: Support xterm extended mouse tracking mode
    
    https://bugzilla.gnome.org/show_bug.cgi?id=681329

 src/vte-private.h |    1 +
 src/vte.c         |   90 +++++++++++++++++++++++++++-------------------------
 src/vteseq.c      |    7 ++++
 3 files changed, 55 insertions(+), 43 deletions(-)
---
diff --git a/src/vte-private.h b/src/vte-private.h
index 2e1f9cc..0946cf9 100644
--- a/src/vte-private.h
+++ b/src/vte-private.h
@@ -305,6 +305,7 @@ struct _VteTerminalPrivate {
 	long mouse_last_x, mouse_last_y;
 	gboolean mouse_autohide;
 	guint mouse_autoscroll_tag;
+	gboolean mouse_xterm_extension;
 
 	/* State variables for handling match checks. */
 	char *match_contents;
diff --git a/src/vte.c b/src/vte.c
index 35fa597..276615d 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -5833,21 +5833,20 @@ vte_terminal_paste_cb(GtkClipboard *clipboard, const gchar *text, gpointer data)
 }
 
 static void
-vte_terminal_get_mouse_tracking_info (VteTerminal   *terminal,
-				      int            button,
-				      long           col,
-				      long           row,
-				      unsigned char *pb,
-				      unsigned char *px,
-				      unsigned char *py)
-{
-	unsigned char cb = 0, cx = 0, cy = 0;
+vte_terminal_feed_mouse_event(VteTerminal *terminal,
+			      int          button,
+			      gboolean     is_drag,
+			      gboolean     is_release,
+			      long         col,
+			      long         row)
+{
+	unsigned char cb = 0;
+	long cx, cy;
+	char buf[LINE_MAX];
+	gint len = 0;
 
 	/* Encode the button information in cb. */
 	switch (button) {
-	case 0:			/* Release/no buttons. */
-		cb = 3;
-		break;
 	case 1:			/* Left. */
 		cb = 0;
 		break;
@@ -5864,7 +5863,12 @@ vte_terminal_get_mouse_tracking_info (VteTerminal   *terminal,
 		cb = 65;	/* Scroll down. */
 		break;
 	}
-	cb += 32; /* 32 for normal */
+
+	/* With the exception of the 1006 mode, button release is also encoded here. */
+	/* Note that if multiple extensions are enabled, the 1006 is used, so it's okay to check for only that. */
+	if (is_release && !terminal->pvt->mouse_xterm_extension) {
+		cb = 3;
+	}
 
 	/* Encode the modifiers. */
 	if (terminal->pvt->modifiers & GDK_SHIFT_MASK) {
@@ -5877,38 +5881,43 @@ vte_terminal_get_mouse_tracking_info (VteTerminal   *terminal,
 		cb |= 16;
 	}
 
-	/* Encode the cursor coordinates. */
-	cx = 32 + CLAMP(1 + col,
-			1, terminal->column_count);
-	cy = 32 + CLAMP(1 + row,
-			1, terminal->row_count);;
+	/* Encode a drag event. */
+	if (is_drag) {
+		cb |= 32;
+	}
+
+	/* Clamp the cursor coordinates. Make them 1-based. */
+	cx = CLAMP(1 + col,
+		   1, terminal->column_count);
+	cy = CLAMP(1 + row,
+		   1, terminal->row_count);
+
+	/* Check the extensions in decreasing order of preference. Encoding the release event above assumes that 1006 comes first. */
+	if (terminal->pvt->mouse_xterm_extension) {
+		/* xterm's extended mode (1006) */
+		len = g_snprintf(buf, sizeof(buf), _VTE_CAP_CSI "<%d;%ld;%ld%c", cb, cx, cy, is_release ? 'm' : 'M');
+	} else if (cx <= 231 && cy <= 231) {
+		/* legacy mode */
+		len = g_snprintf(buf, sizeof(buf), _VTE_CAP_CSI "M%c%c%c", 32 + cb, 32 + (guchar)cx, 32 + (guchar)cy);
+	}
 
-	*pb = cb;
-	*px = cx;
-	*py = cy;
+	/* Send event direct to the child, this is binary not text data */
+	vte_terminal_feed_child_binary(terminal, buf, len);
 }
 
 static void
 vte_terminal_send_mouse_button_internal(VteTerminal *terminal,
 					int          button,
+					gboolean     is_release,
 					long         x,
 					long         y)
 {
-	unsigned char cb, cx, cy;
-	char buf[LINE_MAX];
-	gint len;
 	int width = terminal->char_width;
 	int height = terminal->char_height;
 	long col = (x - terminal->pvt->inner_border.left) / width;
 	long row = (y - terminal->pvt->inner_border.top) / height;
 
-	vte_terminal_get_mouse_tracking_info (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_terminal_feed_child_binary(terminal, buf, len);
+	vte_terminal_feed_mouse_event(terminal, button, FALSE /* not drag */, is_release, col, row);
 }
 
 /* Send a mouse button click/release notification. */
@@ -5936,7 +5945,8 @@ vte_terminal_maybe_send_mouse_button(VteTerminal *terminal,
 	}
 
 	vte_terminal_send_mouse_button_internal(terminal,
-					        (event->type == GDK_BUTTON_PRESS) ? event->button : 0,
+						event->button,
+						event->type == GDK_BUTTON_RELEASE,
 						event->x, event->y);
 }
 
@@ -5944,9 +5954,6 @@ vte_terminal_maybe_send_mouse_button(VteTerminal *terminal,
 static void
 vte_terminal_maybe_send_mouse_drag(VteTerminal *terminal, GdkEventMotion *event)
 {
-	unsigned char cb, cx, cy;
-	char buf[LINE_MAX];
-	gint len;
 	int width = terminal->char_width;
 	int height = terminal->char_height;
 	long col = ((long) event->x - terminal->pvt->inner_border.left) / width;
@@ -5975,14 +5982,9 @@ vte_terminal_maybe_send_mouse_drag(VteTerminal *terminal, GdkEventMotion *event)
 		break;
 	}
 
-	vte_terminal_get_mouse_tracking_info (terminal,
-					      terminal->pvt->mouse_last_button, col, row,
-					      &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_terminal_feed_child_binary(terminal, buf, len);
+	vte_terminal_feed_mouse_event(terminal, terminal->pvt->mouse_last_button,
+				      TRUE /* drag */, FALSE /* not release */,
+				      col, row);
 }
 
 /* Clear all match hilites. */
@@ -11408,6 +11410,7 @@ vte_terminal_scroll(GtkWidget *widget, GdkEventScroll *event)
 			/* Encode the parameters and send them to the app. */
 			vte_terminal_send_mouse_button_internal(terminal,
 								button,
+								FALSE /* not release */,
 								event->x,
 								event->y);
 		}
@@ -14194,6 +14197,7 @@ vte_terminal_reset(VteTerminal *terminal,
 	pvt->mouse_last_button = 0;
 	pvt->mouse_last_x = 0;
 	pvt->mouse_last_y = 0;
+	pvt->mouse_xterm_extension = FALSE;
 	/* Clear modifiers. */
 	pvt->modifiers = 0;
 	/* Cause everything to be redrawn (or cleared). */
diff --git a/src/vteseq.c b/src/vteseq.c
index 07b1524..adc65a3 100644
--- a/src/vteseq.c
+++ b/src/vteseq.c
@@ -685,10 +685,17 @@ vte_sequence_handler_decset_internal(VteTerminal *terminal,
 		 GINT_TO_POINTER(0),
 		 GINT_TO_POINTER(MOUSE_TRACKING_ALL_MOTION_TRACKING),
 		 NULL, NULL,},
+		/* 1006: Extended mouse coordinates. */
+		{1006, &terminal->pvt->mouse_xterm_extension, NULL, NULL,
+		 GINT_TO_POINTER(FALSE),
+		 GINT_TO_POINTER(TRUE),
+		 NULL, NULL,},
 		/* 1010/rxvt: disallowed, scroll-on-output is set by user. */
 		{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. Not supported. */
+		{1015,  NULL, NULL, NULL, NULL, NULL, 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]