+#include <stdio.h>
+
#include <errno.h>
#include <unistd.h>
#include <sys/select.h>
+
#include "event.h"
#include "wm.h"
#include "keyboard.h"
while(select(maxfd + 1, &read_set, 0, 0, 0) == -1 && errno == EINTR);
if(FD_ISSET(keyb_fd, &read_set)) {
+ printf("WINNIE TODO PROCESS KEYB\n");
process_keyboard_event();
}
- if(FD_ISSET(mouse_fd, &read_set)) {
+/* if(FD_ISSET(mouse_fd, &read_set)) {
process_mouse_event();
- }
+ }*/
}
}
void destroy_gfx()
{
+ clear_screen(0, 0, 0);
close(dev_fd);
dev_fd = -1;
#include <unistd.h>
#include "keyboard.h"
+#include "window.h"
+#include "wm.h"
-static int tty_fd = -1;
+static int dev_fd = -1;
static enum {RAW, CANONICAL} ttystate = CANONICAL;
-static int keyb_fd = -1;
-
bool init_keyboard()
{
- if((tty_fd = open("/dev/tty", O_RDWR)) == -1) {
+ if((dev_fd = open("/dev/tty", O_RDWR)) == -1) {
fprintf(stderr, "Cannot open /dev/tty : %s\n", strerror(errno));
return false;
}
struct termios buf;
- if(tcgetattr(tty_fd, &buf) < 0) {
+ if(tcgetattr(dev_fd, &buf) < 0) {
fprintf(stderr, "Cannot get the tty parameters : %s\n", strerror(errno));
return false;
}
buf.c_cflag &= ~(CSIZE | PARENB);
buf.c_cflag |= CS8;
buf.c_oflag &= ~(OPOST);
- buf.c_cc[VMIN] = 1;
- buf.c_cc[VTIME] = 0;
- if(tcsetattr(tty_fd, TCSAFLUSH, &buf) < 0) {
+ if(tcsetattr(dev_fd, TCSAFLUSH, &buf) < 0) {
return false;
}
{
struct termios buf;
+ if(tcgetattr(dev_fd, &buf) < 0) {
+ fprintf(stderr, "Cannot get the tty parameters : %s\n", strerror(errno));
+ }
+
buf.c_lflag |= (ECHO | ICANON | IEXTEN | ISIG);
buf.c_iflag |= (BRKINT | ICRNL | INPCK | ISTRIP | IXON);
buf.c_cflag |= (CSIZE | PARENB);
buf.c_cflag &= CS8;
buf.c_oflag |= (OPOST);
- buf.c_cc[VMIN] = 1;
- buf.c_cc[VTIME] = 0;
+
+ if(tcsetattr(dev_fd, TCSAFLUSH, &buf) < 0) {
+ fprintf(stderr, "Cannot set the tty parameters : %s\n", strerror(errno));
+ }
ttystate = CANONICAL;
- close(tty_fd);
+ close(dev_fd);
- tty_fd = -1;
+ dev_fd = -1;
}
int get_keyboard_fd()
{
- return tty_fd;
+ return dev_fd;
}
void process_keyboard_event()
{
char key;
- if(read(tty_fd, &key, 1) < 1) {
+ if(read(dev_fd, &key, 1) < 1) {
return;
}
if(key == 'q') {
exit(0);
}
+
+ Window *focused_win = wm->get_focused_window();
+ if(focused_win) {
+ KeyboardFuncType keyb_callback = focused_win->get_keyboard_callback();
+ if(keyb_callback) {
+ keyb_callback(focused_win, key, true);
+ }
+ }
+
/* TODO:
* - handle system-wide key combinations (alt-tab?)
* - otherwise send keypress/release to focused window
while(1) {
process_events();
}
-
- winnie_shutdown();
}
static void display(Window *win)
static void cleanup()
{
- destroy_gfx();
+ winnie_shutdown();
}
void destroy_mouse()
{
close(dev_fd);
+ dev_fd = -1;
}
void set_mouse_bounds(const Rect &rect)
{
callbacks.motion = func;
}
+
+const DisplayFuncType Window::get_display_callback() const
+{
+ return callbacks.display;
+}
+
+const KeyboardFuncType Window::get_keyboard_callback() const
+{
+ return callbacks.keyboard;
+}
+
+const MouseButtonFuncType Window::get_mouse_button_callback() const
+{
+ return callbacks.button;
+}
+
+const MouseMotionFuncType Window::get_mouse_motion_callback() const
+{
+ return callbacks.motion;
+}
void set_mouse_button_callback(MouseButtonFuncType func);
void set_mouse_motion_callback(MouseMotionFuncType func);
+ const DisplayFuncType get_display_callback() const;
+ const KeyboardFuncType get_keyboard_callback() const;
+ const MouseButtonFuncType get_mouse_button_callback() const;
+ const MouseMotionFuncType get_mouse_motion_callback() const;
+
// XXX remove if not needed
friend class WindowManager;
};
#include "winnie.h"
+#include "keyboard.h"
bool winnie_init()
{
return false;
}
+ if(!init_keyboard()) {
+ return false;
+ }
+
wm->invalidate_region(get_screen_size());
return true;
}
void winnie_shutdown()
{
destroy_gfx();
+ destroy_keyboard();
}
throw std::runtime_error("Trying to create a second instance of WindowManager!\n");
}
+ focused_win = 0;
+
bg_color[0] = 210;
bg_color[1] = 106;
bg_color[2] = 106;
if(intersect.width && intersect.height) {
(*it)->draw();
}
+ it++;
}
}
void WindowManager::add_window(Window *win)
{
+ if(windows.empty()) {
+ focused_win = win;
+ }
+
windows.push_back(win);
}
+
+void WindowManager::set_focused_window(Window *win)
+{
+ focused_win = win;
+}
+
+const Window *WindowManager::get_focused_window() const
+{
+ return focused_win;
+}
+
+Window *WindowManager::get_focused_window()
+{
+ return focused_win;
+}
std::list<Rect> dirty_rects;
int bg_color[3];
+ Window *focused_win;
public:
WindowManager();
void process_windows();
void add_window(Window *win);
+
+ void set_focused_window(Window *win);
+ const Window *get_focused_window() const;
+ Window *get_focused_window();
};
extern WindowManager *wm;