1 /* BSD mouse system-specific routines. */
7 #include "osdep/system.h"
10 #ifdef HAVE_SYS_CONSIO_H
11 #include <sys/consio.h>
14 #include <machine/console.h>
15 #endif /* HAVE_SYS_CONSIO_H */
16 #endif /* CONFIG_SYSMOUSE */
20 #include "main/select.h"
21 #include "osdep/osdep.h"
22 #include "osdep/signals.h"
23 #include "terminal/event.h"
24 #include "terminal/mouse.h"
27 #if defined(CONFIG_SYSMOUSE) && defined(CONFIG_MOUSE)
29 struct sysmouse_spec
{
33 void (*fn
)(void *, unsigned char *, int);
37 sysmouse_handler(void *data
)
39 static struct interlink_event_mouse prev_mouse
;
40 static int prev_buttons
;
41 struct sysmouse_spec
*sp
= data
;
42 void *itrm
= sp
->itrm
;
43 int fd
= get_output_handle();
47 struct interlink_event_mouse mouse
;
48 struct interlink_event ev
;
50 mi
.operation
= MOUSE_GETINFO
;
51 if (ioctl(fd
, CONS_MOUSECTL
, &mi
) == -1) return;
52 mouse
.x
= int_max(mi
.u
.data
.x
/ sp
->cwidth
, 0);
53 mouse
.y
= int_max(mi
.u
.data
.y
/ sp
->cheight
, 0);
55 /* for cosmetic bug in syscons.c on FreeBSD 3.3/3.4 */
56 #ifdef HAVE_MACHINE_CONSOLE_H
57 mi
.operation
= MOUSE_HIDE
;
58 ioctl(fd
, CONS_MOUSECTL
, &mi
);
59 mi
.operation
= MOUSE_SHOW
;
60 ioctl(fd
, CONS_MOUSECTL
, &mi
);
62 buttons
= mi
.u
.data
.buttons
& 7;
63 change
= (mouse
.x
!= prev_mouse
.x
|| mouse
.y
!= prev_mouse
.y
);
68 switch (prev_buttons
) {
70 extended_button
= mi
.u
.data
.buttons
& 24;
71 if (!extended_button
) return;
72 if (extended_button
& 8) mouse
.button
= B_WHEEL_UP
;
73 else mouse
.button
= B_WHEEL_DOWN
;
79 mouse
.button
= B_LEFT
| B_UP
;
83 mouse
.button
= B_MIDDLE
| B_UP
;
86 mouse
.button
= B_RIGHT
| B_UP
;
94 switch (prev_buttons
) {
99 mouse
.button
= B_LEFT
| B_DOWN
;
106 mouse
.button
= B_LEFT
| B_DRAG
;
107 else mouse
.button
= B_LEFT
| B_DOWN
;
113 switch (prev_buttons
) {
118 mouse
.button
= B_LEFT
| B_UP
;
122 mouse
.button
= B_MIDDLE
| B_DOWN
;
127 mouse
.button
= B_MIDDLE
| B_DRAG
;
128 else mouse
.button
= B_MIDDLE
| B_DOWN
;
133 switch (prev_buttons
) {
138 mouse
.button
= B_LEFT
| B_UP
;
142 mouse
.button
= B_MIDDLE
| B_UP
;
145 mouse
.button
= B_RIGHT
| B_DOWN
;
149 mouse
.button
= B_RIGHT
| B_DRAG
;
150 else mouse
.button
= B_RIGHT
| B_DOWN
;
156 prev_buttons
= buttons
;
157 set_mouse_interlink_event(&ev
, mouse
.x
, mouse
.y
, mouse
.button
);
158 sp
->fn(itrm
, (unsigned char *)&ev
, sizeof(ev
));
162 sysmouse_signal_handler(void *data
)
164 register_bottom_half(sysmouse_handler
, data
);
168 handle_mouse(int cons
, void (*fn
)(void *, unsigned char *, int),
171 static struct sysmouse_spec mouse_spec
;
174 int fd
= get_output_handle();
176 if (is_xterm()) return NULL
;
177 mouse_spec
.itrm
= data
;
180 if (ioctl(fd
, FBIO_GETMODE
, &vi
.vi_mode
) != -1 &&
181 ioctl(fd
, FBIO_MODEINFO
, &vi
) != -1) {
182 mouse_spec
.cwidth
= vi
.vi_cwidth
;
183 mouse_spec
.cheight
= vi
.vi_cheight
;
188 install_signal_handler(SIGUSR2
, NULL
, NULL
, 0);
189 mi
.operation
= MOUSE_MODE
;
191 mi
.u
.mode
.signal
= SIGUSR2
;
192 if (ioctl(fd
, CONS_MOUSECTL
, &mi
) != -1) {
193 install_signal_handler(SIGUSR2
,
194 (void (*)(void *))sysmouse_signal_handler
, &mouse_spec
, 0);
195 mi
.operation
= MOUSE_SHOW
;
196 ioctl(fd
, CONS_MOUSECTL
, &mi
);
204 unhandle_mouse(void *data
)
208 int fd
= get_output_handle();
210 mi
.operation
= MOUSE_MODE
;
212 mi
.u
.mode
.signal
= 0;
213 install_signal_handler(SIGUSR2
, NULL
, NULL
, 0);
214 ioctl(fd
, CONS_MOUSECTL
, &mi
);
219 suspend_mouse(void *data
)
221 unhandle_mouse(data
);
225 resume_mouse(void *data
)
229 int fd
= get_output_handle();
231 mi
.operation
= MOUSE_MODE
;
233 mi
.u
.mode
.signal
= SIGUSR2
;;
234 install_signal_handler(SIGUSR2
,
235 (void (*)(void *))sysmouse_signal_handler
, data
, 0);
236 ioctl(fd
, CONS_MOUSECTL
, &mi
);