aboutsummaryrefslogtreecommitdiffstats
path: root/libterminput_parse_csi_m_mouse_tracking__.c
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2025-02-19 19:53:53 +0100
committerMattias Andrée <m@maandree.se>2025-02-19 19:55:30 +0100
commita40d93ab5a064f8f2f9696acd1b57ef3603cd2fe (patch)
tree288671ad6f1b0d8c57a00b18b04f21b827eab24d /libterminput_parse_csi_m_mouse_tracking__.c
parentminor readability improvement (diff)
downloadlibterminput-a40d93ab5a064f8f2f9696acd1b57ef3603cd2fe.tar.gz
libterminput-a40d93ab5a064f8f2f9696acd1b57ef3603cd2fe.tar.bz2
libterminput-a40d93ab5a064f8f2f9696acd1b57ef3603cd2fe.tar.xz
misc cleanup, fixes, and clarifications, and escape sequence
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to '')
-rw-r--r--libterminput_parse_csi_m_mouse_tracking__.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/libterminput_parse_csi_m_mouse_tracking__.c b/libterminput_parse_csi_m_mouse_tracking__.c
new file mode 100644
index 0000000..f943c04
--- /dev/null
+++ b/libterminput_parse_csi_m_mouse_tracking__.c
@@ -0,0 +1,54 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+void
+libterminput_parse_csi_m_mouse_tracking__(union libterminput_input *input, struct libterminput_state *ctx,
+ unsigned long long int *nums, size_t nnums)
+{
+ unsigned long long int numsbuf[3];
+ size_t pos;
+
+ if (nnums >= 3U) {
+ /* Parsing for \e[?1000;1015h output */
+ nums[0] -= 32ULL;
+
+ } else if (!nnums && (ctx->flags & LIBTERMINPUT_DECSET_1005)) {
+ /* Parsing for semi-legacy \e[?1000;1005h output */
+ ctx->mouse_tracking = 0;
+ nums = numsbuf;
+ pos = ctx->stored_tail;
+ if ((nums[0] = libterminput_utf8_decode__(ctx->stored, &ctx->stored_tail)) < 32 ||
+ (nums[1] = libterminput_utf8_decode__(ctx->stored, &ctx->stored_tail)) < 32 ||
+ (nums[2] = libterminput_utf8_decode__(ctx->stored, &ctx->stored_tail)) < 32) {
+ ctx->stored_tail = pos;
+ input->keypress.key = LIBTERMINPUT_MACRO;
+ return;
+ }
+ nums[0] = nums[0] - 32ULL;
+ nums[1] = nums[1] - 32ULL;
+ nums[2] = nums[2] - 32ULL;
+ if (ctx->stored_head == ctx->stored_tail)
+ ctx->stored_head = ctx->stored_tail = 0;
+
+ } else if (!nnums) {
+ /* Parsing output for legacy mouse tracking output */
+ ctx->mouse_tracking = 0;
+ nums = numsbuf;
+ nums[0] = (unsigned long long int)(unsigned char)ctx->stored[ctx->stored_tail++];
+ nums[1] = (unsigned long long int)(unsigned char)ctx->stored[ctx->stored_tail++];
+ nums[2] = (unsigned long long int)(unsigned char)ctx->stored[ctx->stored_tail++];
+ nums[0] = (nums[0] - 32ULL) & 255ULL;
+ nums[1] = (nums[1] - 32ULL) & 255ULL;
+ nums[2] = (nums[2] - 32ULL) & 255ULL;
+ if (ctx->stored_head == ctx->stored_tail)
+ ctx->stored_head = ctx->stored_tail = 0;
+
+ } else {
+ input->type = LIBTERMINPUT_NONE;
+ return;
+ }
+
+ input->mouseevent.event = LIBTERMINPUT_PRESS;
+ libterminput_parse_decimal_mouse_tracking__(input, nums);
+}