*work in progress*
[winnie] / src / mouse.cc
1 #include <errno.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5
6 #include <fcntl.h>
7 #include <sys/ioctl.h>
8 #include <termios.h>
9 #include <unistd.h>
10
11 #include "mouse.h"
12 #include "geom.h"
13
14 static int dev_fd = -1; // file descriptor for /dev/psaux
15 static Rect bounds;
16 static int pointer_x, pointer_y;
17
18 bool init_mouse()
19 {
20         if((dev_fd = open("/dev/psaux", O_NONBLOCK)) == -1) {
21                 fprintf(stderr, "Cannot open /dev/psaux : %s\n", strerror(errno));
22                 return false;
23         }
24
25         return true;
26 }
27
28 void destroy_mouse()
29 {
30         close(dev_fd);
31 }
32
33 void set_mouse_bounds(const Rect &rect)
34 {
35         bounds = rect;
36 }
37
38 int get_mouse_fd()
39 {
40         return dev_fd;
41 }
42
43 void process_mouse_event()
44 {
45         /* TODO:
46          * - read all pending events from mouse fd (use O_NONBLOCK so that
47          *   read will return -1 when there are no more events instead of blocking).
48          * - process each event and update the pointer and button state
49          * - send each pointer move and button press/release to the tompost window
50          *   with the pointer on it.
51          */
52 }
53
54 void get_pointer_pos(int *x, int *y)
55 {
56         *x = pointer_x;
57         *y = pointer_y;
58 }
59
60 int get_button_state(int bn)
61 {
62         // TODO
63         return 0;
64 }