*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         dev_fd = -1;
32 }
33
34 void set_mouse_bounds(const Rect &rect)
35 {
36         bounds = rect;
37 }
38
39 int get_mouse_fd()
40 {
41         return dev_fd;
42 }
43
44 void process_mouse_event()
45 {
46         /* TODO:
47          * - read all pending events from mouse fd (use O_NONBLOCK so that
48          *   read will return -1 when there are no more events instead of blocking).
49          * - process each event and update the pointer and button state
50          * - send each pointer move and button press/release to the tompost window
51          *   with the pointer on it.
52          */
53 }
54
55 void get_pointer_pos(int *x, int *y)
56 {
57         *x = pointer_x;
58         *y = pointer_y;
59 }
60
61 int get_button_state(int bn)
62 {
63         // TODO
64         return 0;
65 }