From fb1f0ff6ab479c68cbac5c2d55de5c2beb229efd Mon Sep 17 00:00:00 2001 From: Eleni Maria Stea Date: Fri, 8 Feb 2013 23:38:18 +0200 Subject: [PATCH] events should have a ptr to windows --- Makefile | 2 +- src/event.cc | 60 +++++++++++++++++++++++----------------------------------- src/event.h | 25 ++++++++++++------------ src/gfx.h | 7 +------ 4 files changed, 39 insertions(+), 55 deletions(-) diff --git a/Makefile b/Makefile index 3ced08b..c6b749a 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ bin = winnie dbg = -g opt = -O0 -inc = -Isrc -Isrc/shaders -Isrc/math +#inc = CXX = g++ CXXFLAGS = -pedantic -Wall $(dbg) $(opt) $(inc) diff --git a/src/event.cc b/src/event.cc index 4656575..e5a7182 100644 --- a/src/event.cc +++ b/src/event.cc @@ -1,46 +1,34 @@ +#include +#include +#include #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(); + } } diff --git a/src/event.h b/src/event.h index 0c2ccd2..e4ac286 100644 --- a/src/event.h +++ b/src/event.h @@ -1,19 +1,20 @@ #ifndef EVENT_H_ #define EVENT_H_ -typedef void (*DisplayFuncType)(); -typedef void (*KeyboardFuncType)(int key, bool pressed); -typedef void (*MouseButtonFuncType)(int bn, bool pressed); -typedef void (*MouseMotionFuncType)(int x, int y); +class Window; -void set_display_callback(DisplayFuncType display); -void set_keyboard_callback(KeyboardFuncType keyboard); -void set_mouse_button_callback(MouseButtonFuncType mouse_button); -void set_mouse_motion_callback(MouseMotionFuncType mouse_motion); +typedef void (*DisplayFuncType)(Window* win); +typedef void (*KeyboardFuncType)(Window* win, int key, bool pressed); +typedef void (*MouseButtonFuncType)(Window *win, int bn, bool pressed); +typedef void (*MouseMotionFuncType)(Window *win, int x, int y); -DisplayFuncType get_display_callback(); -KeyboardFuncType get_keyboard_callback(); -MouseButtonFuncType get_mouse_button_callback(); -MouseMotionFuncType get_mouse_motion_callback(); +struct Callbacks { + DisplayFuncType display; + KeyboardFuncType keyboard; + MouseButtonFuncType button; + MouseMotionFuncType motion; +}; + +void process_events(); #endif diff --git a/src/gfx.h b/src/gfx.h index 7868b01..8734e2d 100644 --- a/src/gfx.h +++ b/src/gfx.h @@ -1,12 +1,7 @@ #ifndef GFX_H_ #define GFX_H_ -struct Rect { - int x; - int y; - int width; - int height; -}; +#include "geom.h" bool init_gfx(); void destroy_gfx(); -- 1.7.10.4