-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmouse_driver_X10.c
More file actions
88 lines (67 loc) · 1.82 KB
/
Copy pathmouse_driver_X10.c
File metadata and controls
88 lines (67 loc) · 1.82 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
#include <string.h>
#include "vterm_private.h"
#include "mouse_driver.h"
#include "stringv.h"
ssize_t
mouse_driver_vt200(vterm_t *vterm, unsigned char *buf)
{
MEVENT mouse_event;
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)
{
/*
get mouse returns screen relative coords and we need to transform
those into window relative coords. wmouse_trafo() does exactly
that and returns false if the conversion is not possilbe--for
exmpale if the coord are out of bounds.
*/
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 & BUTTON1_PRESSED)
{
sprintf((char *)buf, "\033[M%c%c%c",
32 + 0x0,
32 + x,
32 + y);
retval = strlen((char *)buf);
return retval;
}
if(mouse_event.bstate & BUTTON1_RELEASED)
{
sprintf((char *)buf, "\033[M%c%c%c",
32 + 0x3,
32 + x,
32 + y);
retval = strlen((char *)buf);
return retval;
}
// only the newer ABI supports the wheel mous properly
#if NCURSES_MOUSE_VERSION > 1
if(mouse_event.bstate & BUTTON4_PRESSED)
{
sprintf((char *)buf, "\033OA");
retval = strlen((char *)buf);
return retval;
}
if(mouse_event.bstate & BUTTON5_PRESSED)
{
sprintf((char *)buf, "\033OB");
retval = strlen((char *)buf);
return retval;
}
#endif
return 0;
}