From 97b3c3c7c9dfa16c335646e17ebb43a688856a0c Mon Sep 17 00:00:00 2001 From: Eleni Maria Stea Date: Tue, 19 Feb 2013 00:04:32 +0200 Subject: [PATCH] *in progress* mouse, keyboard events + focus window work!!!!!!!! --- src/event.cc | 1 - src/keyboard.cc | 4 ++-- src/mouse.cc | 19 ++++++++++--------- src/winnie.cc | 1 + 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/event.cc b/src/event.cc index 1586c95..a54fe7a 100644 --- a/src/event.cc +++ b/src/event.cc @@ -28,7 +28,6 @@ void process_events() 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)) { diff --git a/src/keyboard.cc b/src/keyboard.cc index 6275227..1b23e12 100644 --- a/src/keyboard.cc +++ b/src/keyboard.cc @@ -81,9 +81,9 @@ void process_keyboard_event() return; } -/* if(key == 'q') { + if(key == 'q') { exit(0); - }*/ + } Window *focused_win = wm->get_focused_window(); if(focused_win) { diff --git a/src/mouse.cc b/src/mouse.cc index f29841c..861b597 100644 --- a/src/mouse.cc +++ b/src/mouse.cc @@ -27,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; } @@ -69,6 +69,14 @@ void process_mouse_event() return; } + unsigned char *fb = get_framebuffer(); + fb += (bounds.width * pointer_y + pointer_x) * 4; + fb[0] = 0; + fb[1] = 0; + fb[2] = 0; + + //printf("pointer (x, y) = (%d, %d)\r\n", pointer_x, pointer_y); + Window *top = wm->get_window_at_pos(pointer_x, pointer_y); if(top) { wm->set_focused_window(top); @@ -92,7 +100,7 @@ void process_mouse_event() 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; @@ -104,13 +112,6 @@ void process_mouse_event() } } } - - unsigned char *fb = get_framebuffer(); - Rect scr = get_screen_size(); - fb += (scr.width * pointer_y + pointer_x) * 4; - fb[0] = 0; - fb[1] = 0; - fb[2] = 0; } void get_pointer_pos(int *x, int *y) diff --git a/src/winnie.cc b/src/winnie.cc index fe81799..4ec10b1 100644 --- a/src/winnie.cc +++ b/src/winnie.cc @@ -24,4 +24,5 @@ void winnie_shutdown() { destroy_gfx(); destroy_keyboard(); + destroy_mouse(); } -- 1.7.10.4