+ return bnstate;
+}
+
+int get_button(int bn)
+{
+ if(bn < 0 || bn >= 3) {
+ return 0;
+ }
+ return (bnstate & (1 << bn)) != 0;
+}
+
+
+int read_mouse()
+{
+ int rd;
+ signed char state[3] = {0, 0, 0};
+
+ if((rd = read(dev_fd, state, 3)) == -1) {
+ fprintf(stderr, "Unable to get mouse state : %s\n", strerror(errno));
+ return -1;
+ }
+
+ bnstate = state[0] & 7;
+ pointer_x += state[1];
+ pointer_y -= state[2];
+
+ if(pointer_x < bounds.x) {
+ pointer_x = bounds.x;
+ }
+
+ if(pointer_y < bounds.y) {
+ pointer_y = bounds.y;
+ }
+
+ if(pointer_x > bounds.x + bounds.width - 1) {
+ pointer_x = bounds.x + bounds.width - 1;
+ }
+
+ if(pointer_y > bounds.y + bounds.height - 1) {
+ pointer_y = bounds.y + bounds.height - 1;
+ }
+