diff options
author | Søren Sandmann Pedersen <ssp@l3000.localdomain> | 2011-12-08 01:05:05 -0500 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@l3000.localdomain> | 2011-12-08 01:05:05 -0500 |
commit | 99e9fbf0cc673538728901bd48e7d6c101826d7a (patch) | |
tree | f62ab1ecbc069a89ef62c435c4d3fcfd81383e7d | |
parent | 22a80c020663496bd10bc27f6880c4d51569d275 (diff) |
Initial event processing
-rw-r--r-- | main.c | 24 | ||||
-rw-r--r-- | window.c | 50 | ||||
-rw-r--r-- | window.h | 2 |
3 files changed, 74 insertions, 2 deletions
@@ -1,5 +1,8 @@ +#include <stdlib.h> #include <stdio.h> #include "window.h" +/* According to POSIX.1-2001 */ +#include <sys/select.h> int main () @@ -8,6 +11,7 @@ main () window_t *window; pixman_image_t *image; pixman_color_t color = { 0xffff, 0xabcd, 0x7777, 0x7777 }; + fd_set set; if (!ws) { @@ -15,16 +19,32 @@ main () return 0; } - window = ws_create_window (ws, 10, 10, 200, 200); + window = ws_create_window (ws, 300, 200, 200, 200); ws_window_show (window); image = pixman_image_create_solid_fill (&color); + ws_window_copy_from_image (window, image, 0, 0, 0, 0, 200, 200); + ws_window_finish (&window, 1); while (1) { - ws_window_copy_from_image (window, image, 0, 0, 0, 0, 200, 200); + pixman_color_t color = { 0xffff, 0xabcd, 0x7777, 0x7777 }; + int fd = ws_get_fd (ws); + + FD_ZERO (&set); + FD_SET (fd, &set); + + select (fd + 1, &set, NULL, NULL, NULL); + ws_process (ws); + + color.red = rand(); + color.blue = rand(); + + image = pixman_image_create_solid_fill (&color); + ws_window_copy_from_image (window, image, 0, 0, 0, 0, 200, 200); + pixman_image_unref (image); ws_window_finish (&window, 1); } @@ -13,6 +13,7 @@ struct ws_t pixman_bool_t composited; pixman_bool_t has_alpha; int byte_order; + int fd; list_t windows; }; @@ -186,9 +187,17 @@ ws_open (void) else ws->byte_order = MSBFirst; + list_init (&ws->windows); + return ws; } +int +ws_get_fd (ws_t *ws) +{ + return XConnectionNumber (ws->display); +} + static window_t * find_window (ws_t *ws, XID xid) { @@ -205,6 +214,45 @@ find_window (ws_t *ws, XID xid) return NULL; } +static void +process_configure_notify (ws_t *ws, XEvent *event) +{ + window_t *window = find_window (ws, event->xconfigure.window); + + +} + +static void +process_expose (ws_t *ws, const XEvent *event) +{ + printf ("expose\n"); +} + +void +ws_process (ws_t *ws) +{ + while (XPending (ws->display)) + { + XEvent event; + + XNextEvent (ws->display, &event); + + switch (event.type) + { + case ConfigureNotify: + process_configure_notify (ws, &event); + break; + case Expose: + process_expose (ws, &event); + break; + case MotionNotify: + case ButtonPress: + case ButtonRelease: + ; + } + } +} + /* Window */ window_t * ws_create_window (ws_t *ws, @@ -233,6 +281,8 @@ ws_create_window (ws_t *ws, list_prepend (&ws->windows, &window->link); + XSelectInput (ws->display, window->xid, ExposureMask); + return window; } @@ -18,6 +18,8 @@ typedef struct surfade_t surface_t; ws_t * ws_open (void); int ws_get_width (ws_t *ws); int ws_get_height (ws_t *ws); +int ws_get_fd (ws_t *ws); +void ws_process (ws_t *ws); /* Window */ window_t *ws_create_window (ws_t *ws, |