-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmouse_driver_SGR.c
More file actions
95 lines (72 loc) · 2.21 KB
/
Copy pathmouse_driver_SGR.c
File metadata and controls
95 lines (72 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <string.h>
#include "vterm_private.h"
#include "mouse_driver.h"
#include "stringv.h"
/*
CSI < Ps ; Ps ; Ps M <- mouse button down or move event
CSI < Ps ; Ps ; Ps m <- mouse button release event
*/
ssize_t
mouse_driver_SGR(vterm_t *vterm, unsigned char *buf)
{
MEVENT mouse_event;
unsigned int button = 0;
int retval = 0;
int x, y;
if(vterm->pending_mouse != NULL)
memcpy(&mouse_event, vterm->pending_mouse, sizeof(MEVENT));
else
getmouse(&mouse_event);
x = mouse_event.x;
y = mouse_event.y;
if(vterm->window != NULL)
{
// see notes above on coordinate transformations
if(wmouse_trafo(vterm->window, &y, &x, FALSE) == FALSE)
{
return 0;
}
// ncurses top left is is 0,0 whereas for X10 it is 1,1
x++;
y++;
}
if(mouse_event.bstate & BUTTON_SHIFT) button |= 4;
if(mouse_event.bstate & BUTTON_CTRL) button |= 8;
if(mouse_event.bstate & BUTTON_ALT) button |= 16;
if(mouse_event.bstate & BUTTON1_PRESSED)
{
sprintf((char *)buf, "\033[<%d;%d;%dM", 0, x, y);
retval = strlen((char *)buf);
return retval;
}
if(mouse_event.bstate & BUTTON1_RELEASED)
{
sprintf((char *)buf, "\033[<%d;%d;%dm", 0, x, y);
retval = strlen((char *)buf);
return retval;
}
// only the newer ABI supports the wheel mouse properly
#if NCURSES_MOUSE_VERSION > 1
if(mouse_event.bstate & BUTTON4_PRESSED)
{
if(vterm->mouse_mode & VTERM_MOUSE_ALTSCROLL)
sprintf((char *)buf, "\033OA");
else
// SGR wheel-up is button 64 (+ modifier bits)
sprintf((char *)buf, "\033[<%d;%d;%dM", button + 64, x, y);
retval = strlen((char *)buf);
return retval;
}
if(mouse_event.bstate & BUTTON5_PRESSED)
{
if(vterm->mouse_mode & VTERM_MOUSE_ALTSCROLL)
sprintf((char *)buf, "\033OB");
else
// SGR wheel-down is button 65 (+ modifier bits)
sprintf((char *)buf, "\033[<%d;%d;%dM", button + 65, x, y);
retval = strlen((char *)buf);
return retval;
}
#endif
return 0;
}