events should have a ptr to windows
[winnie] / src / event.cc
index 4656575..e5a7182 100644 (file)
@@ -1,46 +1,34 @@
+#include <errno.h>
+#include <unistd.h>
+#include <sys/select.h>
 #include "event.h"
+#include "wm.h"
+#include "keyboard.h"
+#include "mouse.h"
 
-static DisplayFuncType display_func;
-static KeyboardFuncType keyboard_func;
-static MouseButtonFuncType mouse_button_func;
-static MouseMotionFuncType mouse_motion_func;
-
-void set_display_callback(DisplayFuncType display)
-{
-       display_func = display;
-}
-
-void set_keyboard_callback(KeyboardFuncType keyboard)
+void process_events()
 {
-       keyboard_func = keyboard;
-}
+       int keyb_fd = get_keyboard_fd();
+       int mouse_fd = get_mouse_fd();
 
-void set_mouse_button_callback(MouseButtonFuncType mouse_button)
-{
-       mouse_button_func = mouse_button;
-}
+       for(;;) {
+               fd_set read_set;
 
-void set_mouse_motion_callback(MouseMotionFuncType mouse_motion)
-{
-       mouse_motion_func = mouse_motion;
-}
+               FD_ZERO(&read_set);
+               FD_SET(keyb_fd, &read_set);
+               FD_SET(mouse_fd, &read_set);
 
-DisplayFuncType get_display_callback()
-{
-       return display_func;
-}
+               int maxfd = keyb_fd > mouse_fd ? keyb_fd : mouse_fd;
 
-KeyboardFuncType get_keyboard_callback()
-{
-       return keyboard_func;
-}
+               while(select(maxfd + 1, &read_set, 0, 0, 0) == -1 && errno == EINTR);
 
-MouseButtonFuncType get_mouse_button_callback()
-{
-       return mouse_button_func;
-}
+               if(FD_ISSET(keyb_fd, &read_set)) {
+                       process_keyboard_event();
+               }
+               if(FD_ISSET(mouse_fd, &read_set)) {
+                       process_mouse_event();
+               }
 
-MouseMotionFuncType get_mouse_motion_callback()
-{
-       return mouse_motion_func;
+               wm->process_windows();
+       }
 }