X-Git-Url: http://git.mutantstargoat.com?p=winnie;a=blobdiff_plain;f=src%2Fmouse.cc;h=b3f329b2dee4acfce96289edf9dd738d5afd2042;hp=80d52be1a593542b6636390d178dd93dce8fc466;hb=a43297a61d69ca5fa5bb7ae8407757da978b4dd4;hpb=52e08b5a5e7d44271d217892372c6c0878484c44 diff --git a/src/mouse.cc b/src/mouse.cc index 80d52be..b3f329b 100644 --- a/src/mouse.cc +++ b/src/mouse.cc @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -11,6 +12,8 @@ #include "geom.h" #include "gfx.h" #include "mouse.h" +#include "window.h" +#include "wm.h" #define BN_LEFT 1 #define BN_RIGHT 2 @@ -24,7 +27,7 @@ static int bnstate; bool init_mouse() { - if((dev_fd = open("/dev/psaux", O_RDONLY)) == -1) { + if((dev_fd = open("/dev/psaux", O_RDONLY | O_NONBLOCK)) == -1) { fprintf(stderr, "Cannot open /dev/psaux : %s\n", strerror(errno)); return false; } @@ -66,10 +69,41 @@ void process_mouse_event() return; } - /* - process each event and update the pointer and button state - * - send each pointer move and button press/release to the tompost window + Window *top = wm->get_window_at_pos(pointer_x, pointer_y); + if(top) { + wm->set_focused_window(top); + } + else { + wm->set_focused_window(0); + return; + } + + /* - send each pointer move and button press/release to the topmost window * with the pointer on it. */ + + int dx = pointer_x - prev_x; + int dy = pointer_y - prev_y; + + if(dx || dy) { + MouseMotionFuncType motion_callback = top->get_mouse_motion_callback(); + if(motion_callback) { + Rect rect = top->get_rect(); + motion_callback(top, pointer_x - rect.x, pointer_y - rect.y); + } + } + + MouseButtonFuncType button_callback = top->get_mouse_button_callback(); + if(button_callback && (bnstate != prev_state)) { + int num_bits = sizeof bnstate * CHAR_BIT; + for(int i=0; i> i) & 1; + int prev_s = (prev_state >> i) & 1; + if(s != prev_s) { + button_callback(top, i, s); + } + } + } } void get_pointer_pos(int *x, int *y)