20 static int dev_fd = -1; // file descriptor for /dev/psaux
22 static int pointer_x, pointer_y;
27 if((dev_fd = open("/dev/psaux", O_RDONLY)) == -1) {
28 fprintf(stderr, "Cannot open /dev/psaux : %s\n", strerror(errno));
32 set_mouse_bounds(get_screen_size());
44 void set_mouse_bounds(const Rect &rect)
54 void process_mouse_event()
57 * - read all pending events from mouse fd (use O_NONBLOCK so that
58 * read will return -1 when there are no more events instead of blocking).
61 int prev_state = bnstate;
62 int prev_x = pointer_x;
63 int prev_y = pointer_y;
65 if(read_mouse() == -1) {
69 /* - process each event and update the pointer and button state
70 * - send each pointer move and button press/release to the topmost window
71 * with the pointer on it.
75 void get_pointer_pos(int *x, int *y)
81 int get_button_state(int bn)
86 int get_button(int bn)
88 if(bn < 0 || bn >= 3) {
91 return (bnstate & (1 << bn)) != 0;
98 signed char state[3] = {0, 0, 0};
100 if((rd = read(dev_fd, state, 3)) == -1) {
101 fprintf(stderr, "Unable to get mouse state : %s\n", strerror(errno));
105 bnstate = state[0] & 7;
106 pointer_x += state[1];
107 pointer_y -= state[2];
109 if(pointer_x < bounds.x) {
110 pointer_x = bounds.x;
113 if(pointer_y < bounds.y) {
114 pointer_y = bounds.y;
117 if(pointer_x > bounds.x + bounds.width - 1) {
118 pointer_x = bounds.x + bounds.width - 1;
121 if(pointer_y > bounds.y + bounds.height - 1) {
122 pointer_y = bounds.y + bounds.height - 1;