23 static int read_mouse();
25 static int dev_fd = -1; // file descriptor for /dev/psaux
27 static int pointer_x, pointer_y;
32 if((dev_fd = open("/dev/psaux", O_RDONLY | O_NONBLOCK)) == -1) {
33 fprintf(stderr, "Cannot open /dev/psaux : %s\n", strerror(errno));
37 set_mouse_bounds(get_screen_size());
49 void set_mouse_bounds(const Rect &rect)
59 void process_mouse_event()
62 * - read all pending events from mouse fd (use O_NONBLOCK so that
63 * read will return -1 when there are no more events instead of blocking).
66 int prev_state = bnstate;
67 int prev_x = pointer_x;
68 int prev_y = pointer_y;
70 if(read_mouse() == -1) {
74 Window *top = wm->get_window_at_pos(pointer_x, pointer_y);
76 wm->set_focused_window(top);
79 wm->set_focused_window(0);
82 /* - send each pointer move and button press/release to the topmost window
83 * with the pointer on it.
86 int dx = pointer_x - prev_x;
87 int dy = pointer_y - prev_y;
89 if((dx || dy) && top) {
90 MouseMotionFuncType motion_callback = top->get_mouse_motion_callback();
92 Rect rect = top->get_absolute_rect();
93 motion_callback(top, pointer_x - rect.x, pointer_y - rect.y);
97 MouseButtonFuncType button_callback;
98 if((bnstate != prev_state) && top && (button_callback = top->get_mouse_button_callback())) {
99 int num_bits = sizeof bnstate * CHAR_BIT;
100 for(int i=0; i<num_bits; i++) {
101 int s = (bnstate >> i) & 1;
102 int prev_s = (prev_state >> i) & 1;
104 button_callback(top, i, s);
110 void get_pointer_pos(int *x, int *y)
116 int get_button_state()
121 int get_button(int bn)
123 if(bn < 0 || bn >= 3) {
126 return (bnstate & (1 << bn)) != 0;
129 static int read_mouse()
132 signed char state[3] = {0, 0, 0};
134 if((rd = read(dev_fd, state, 3)) == -1) {
135 fprintf(stderr, "Unable to get mouse state : %s\n", strerror(errno));
139 bnstate = state[0] & 7;
140 pointer_x += state[1];
141 pointer_y -= state[2];
143 if(pointer_x < bounds.x) {
144 pointer_x = bounds.x;
147 if(pointer_y < bounds.y) {
148 pointer_y = bounds.y;
151 if(pointer_x > bounds.x + bounds.width - 1) {
152 pointer_x = bounds.x + bounds.width - 1;
155 if(pointer_y > bounds.y + bounds.height - 1) {
156 pointer_y = bounds.y + bounds.height - 1;
161 #endif // WINNIE_FBDEV