File mc-xmouse-supp.diff of Package mc46

--- src/mouse.h.orig	2022-05-19 15:28:09.663253795 +0300
+++ src/mouse.h	2022-05-19 15:28:17.795253595 +0300
@@ -69,6 +69,9 @@
 /* String indicating that a mouse event has occured, usually "\E[M" */
 extern const char *xmouse_seq;
 
+/* String indicating that an SGR extended mouse event has occurred, namely "\E[<" */
+extern const char *xmouse_extended_seq;
+
 void init_mouse (void);
 void enable_mouse (void);
 void disable_mouse (void);
--- src/mouse.c.orig	2022-05-19 15:25:36.007257562 +0300
+++ src/mouse.c	2022-05-19 15:42:56.123232063 +0300
@@ -33,6 +33,7 @@
 
 int mouse_enabled = 0;
 const char *xmouse_seq;
+const char *xmouse_extended_seq;
 
 #ifdef HAVE_LIBGPM
 void show_mouse_pointer (int x, int y)
@@ -54,6 +55,7 @@
     case MOUSE_XTERM_NORMAL_TRACKING:
     case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
 	define_sequence (MCKEY_MOUSE, xmouse_seq, MCKEY_NOACTION);
+	define_sequence (MCKEY_EXTENDED_MOUSE, xmouse_extended_seq, MCKEY_NOACTION);
 	break;
     default:
 	break;
@@ -95,6 +97,9 @@
 	/* enable mouse tracking */
 	printf(ESC_STR "[?1000h");
 
+	/* enable SGR extended mouse reporting */
+	printf(ESC_STR "[?1006h");
+
 	fflush (stdout);
 	mouse_enabled = 1; 
 	break;
@@ -105,6 +110,9 @@
 	/* enable mouse tracking */
 	printf(ESC_STR "[?1002h");
 
+	/* enable SGR extended mouse reporting */
+	printf(ESC_STR "[?1006h");
+
 	fflush (stdout);
 	mouse_enabled = 1; 
 	break;
@@ -128,6 +136,9 @@
 	break;
 #endif
     case MOUSE_XTERM_NORMAL_TRACKING:
+	/* disable SGR extended mouse reporting */
+	printf (ESC_STR "[?1006l");
+
 	/* disable mouse tracking */
 	printf(ESC_STR "[?1000l");
 
@@ -137,6 +148,9 @@
 	fflush (stdout);
 	break;
     case MOUSE_XTERM_BUTTON_EVENT_TRACKING:
+	/* disable SGR extended mouse reporting */
+	printf(ESC_STR "[?1006l");
+
 	/* disable mouse tracking */
 	printf(ESC_STR "[?1002l");
 
--- src/key.h.orig	2022-05-19 15:24:03.367259833 +0300
+++ src/key.h	2022-05-19 15:24:22.131259373 +0300
@@ -56,6 +56,9 @@
 /* Return code for the mouse sequence */
 #define MCKEY_MOUSE     -2
 
+/* Return code for the extended mouse sequence */
+#define MCKEY_EXTENDED_MOUSE     -3
+
 int define_sequence (int code, const char *seq, int action);
 
 /* internally used in key.c, defined in keyxtra.c */
--- src/main.c.orig	2022-05-19 15:57:10.439211120 +0300
+++ src/main.c	2022-05-19 15:57:42.703210329 +0300
@@ -1445,6 +1445,10 @@
 	    }
 	}
     }
+
+    /* No termcap for SGR extended mouse (yet), hardcode it for now */
+    if (xmouse_seq != NULL)
+        xmouse_extended_seq = ESC_STR "[<";
 }
 
 static void
--- src/key.c.orig	2022-05-19 15:59:35.663207559 +0300
+++ src/key.c	2022-05-19 16:22:42.907173551 +0300
@@ -503,7 +503,7 @@
 
 
 static void
-xmouse_get_event (Gpm_Event *ev)
+xmouse_get_event (Gpm_Event *ev, gboolean extended)
 {
     int btn;
     static struct timeval tv1 = { 0, 0 }; /* Force first click as single */
@@ -513,9 +513,43 @@
 
     /* Decode Xterm mouse information to a GPM style event */
 
-    /* Variable btn has following meaning: */
-    /* 0 = btn1 dn, 1 = btn2 dn, 2 = btn3 dn, 3 = btn up */
-    btn = getch () - 32;
+    if (!extended) {
+	/* Variable btn has following meaning: */
+	/* 0 = btn1 dn, 1 = btn2 dn, 2 = btn3 dn, 3 = btn up */
+	btn = getch () - 32;
+	/* Coordinates are 33-based */
+	/* Transform them to 1-based */
+	ev->x = getch () - 32;
+	ev->y = getch () - 32;
+    } else {
+        /* SGR 1006 extension (e.g. "\e[<0;12;300M"):
+           - Numbers are encoded in decimal to make it ASCII-safe
+             and to overcome the limit of 223 columns/rows.
+           - Mouse release is encoded by trailing 'm' rather than 'M'
+             so that the released button can be reported.
+           - Numbers are no longer offset by 32. */
+        char c;
+        btn = ev->x = ev->y = 0;
+        ev->type = 0;  /* In case we return on an invalid sequence */
+        while ((c = getch()) != ';') {
+            if (c < '0' || c > '9') return;
+            btn = 10 * btn + (c - '0');
+        }
+        while ((c = getch()) != ';') {
+            if (c < '0' || c > '9') return;
+            ev->x = 10 * ev->x + (c - '0');
+        }
+        while ((c = getch()) != 'M' && c != 'm') {
+            if (c < '0' || c > '9') return;
+            ev->y = 10 * ev->y + (c - '0');
+        }
+        /* Legacy mouse protocol doesn't tell which button was released,
+           conveniently all of mc's widgets are written not to rely on this
+           information. With the SGR extension the released button becomes
+           known, but for the sake of simplicity we just ignore it. */
+        if (c == 'm') btn = 3;
+    }
+
 
     /* There seems to be no way of knowing which button was released */
     /* So we assume all the buttons were released */
@@ -571,10 +605,6 @@
 	}
 	last_btn = ev->buttons;
     }
-    /* Coordinates are 33-based */
-    /* Transform them to 1-based */
-    ev->x = getch () - 32;
-    ev->y = getch () - 32;
 }
 
 static key_def *create_sequence (const char *seq, int code, int action)
@@ -1144,9 +1174,9 @@
 #ifdef KEY_MOUSE
 	|| c == KEY_MOUSE
 #endif				/* KEY_MOUSE */
-	) {
+	|| c == MCKEY_EXTENDED_MOUSE) {
 	/* Mouse event */
-	xmouse_get_event (event);
+	xmouse_get_event (event, c == MCKEY_EXTENDED_MOUSE);
 	if (event->type)
 	    return EV_MOUSE;
 	else
openSUSE Build Service is sponsored by