aboutsummaryrefslogtreecommitdiff
path: root/terminal.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-07-05 13:13:06 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-07-05 13:13:06 +0000
commit1610828b8cefaee2588552578ba0eccf354e3c29 (patch)
tree05580c03cd7bfdf3bb685a454d5eb029e5414ee8 /terminal.c
parentvt: add support for \E[?1000h - report mouse button events (diff)
vt: add support for mouse motion reports
Diffstat (limited to 'terminal.c')
-rw-r--r--terminal.c92
1 files changed, 72 insertions, 20 deletions
diff --git a/terminal.c b/terminal.c
index 37cb9bbd..7639da2d 100644
--- a/terminal.c
+++ b/terminal.c
@@ -423,35 +423,36 @@ encode_xbutton(int xbutton)
}
static void
-report_mouse_click(struct terminal *term, int button, int row, int col,
- bool release, bool shift, bool alt, bool ctrl)
+report_mouse_click(struct terminal *term, int encoded_button, int row, int col,
+ bool release)
+{
+ char response[16];
+ snprintf(response, sizeof(response), "\033[M%c%c%c",
+ 32 + encoded_button, 32 + col + 1, 32 + row + 1);
+ write(term->ptmx, response, strlen(response));
+}
+
+static void
+report_mouse_motion(struct terminal *term, int encoded_button, int row, int col)
+{
+ report_mouse_click(term, encoded_button, row, col, false);
+}
+
+void
+term_mouse_down(struct terminal *term, int button, int row, int col,
+ bool shift, bool alt, bool ctrl)
{
/* Map libevent button event code to X button number */
int xbutton = linux_mouse_button_to_x(button);
if (xbutton == -1)
return;
- if (release && (xbutton == 4 || xbutton == 5)) {
- /* No button release events for scroll buttons */
- return;
- }
-
- int encoded = release ? 3 : encode_xbutton(xbutton);
+ int encoded = encode_xbutton(xbutton);
if (encoded == -1)
return;
encoded += (shift ? 4 : 0) + (alt ? 8 : 0) + (ctrl ? 16 : 0);
- char response[16];
- snprintf(response, sizeof(response), "\033[M%c%c%c",
- 32 + encoded, 32 + col + 1, 32 + row + 1);
- write(term->ptmx, response, strlen(response));
-}
-
-void
-term_mouse_down(struct terminal *term, int button, int row, int col,
- bool shift, bool alt, bool ctrl)
-{
switch (term->mouse_tracking) {
case MOUSE_NONE:
break;
@@ -460,7 +461,7 @@ term_mouse_down(struct terminal *term, int button, int row, int col,
case MOUSE_CLICK:
case MOUSE_DRAG:
case MOUSE_MOTION:
- report_mouse_click(term, button, row, col, false, shift, alt, ctrl);
+ report_mouse_click(term, encoded, row, col, false);
break;
}
}
@@ -469,6 +470,19 @@ void
term_mouse_up(struct terminal *term, int button, int row, int col,
bool shift, bool alt, bool ctrl)
{
+ /* Map libevent button event code to X button number */
+ int xbutton = linux_mouse_button_to_x(button);
+ if (xbutton == -1)
+ return;
+
+ if (xbutton == 4 || xbutton == 5) {
+ /* No release events for scroll buttons */
+ return;
+ }
+
+ int encoded = 3;
+ encoded += (shift ? 4 : 0) + (alt ? 8 : 0) + (ctrl ? 16 : 0);
+
switch (term->mouse_tracking) {
case MOUSE_NONE:
break;
@@ -477,7 +491,45 @@ term_mouse_up(struct terminal *term, int button, int row, int col,
case MOUSE_CLICK:
case MOUSE_DRAG:
case MOUSE_MOTION:
- report_mouse_click(term, button, row, col, true, shift, alt, ctrl);
+ report_mouse_click(term, encoded, row, col, true);
+ break;
+ }
+}
+
+void
+term_mouse_motion(struct terminal *term, int button, int row, int col,
+ bool shift, bool alt, bool ctrl)
+{
+ int encoded = 0;
+
+ if (button != 0) {
+ /* Map libevent button event code to X button number */
+ int xbutton = linux_mouse_button_to_x(button);
+ if (xbutton == -1)
+ return;
+
+ encoded = encode_xbutton(xbutton);
+ if (encoded == -1)
+ return;
+ } else
+ encoded = 3; /* "released" */
+
+ encoded += 32; /* Motion event */
+ encoded += (shift ? 4 : 0) + (alt ? 8 : 0) + (ctrl ? 16 : 0);
+
+ switch (term->mouse_tracking) {
+ case MOUSE_NONE:
+ case MOUSE_X10:
+ case MOUSE_CLICK:
+ return;
+
+ case MOUSE_DRAG:
+ if (button == 0)
+ return;
+ /* FALLTHROUGH */
+
+ case MOUSE_MOTION:
+ report_mouse_motion(term, encoded, row, col);
break;
}
}