diff options
author | Søren Sandmann Pedersen <ssp@redhat.com> | 2011-12-08 18:01:43 -0500 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@redhat.com> | 2011-12-08 18:01:43 -0500 |
commit | 81653f78a1568ba497fe19c4bcfbe1430445ef86 (patch) | |
tree | 03e2e5a8a18ba962e9315ee6908ad57947af54ce | |
parent | e692e88e33a61645ce073e19fabecd5981eec434 (diff) |
Better main loop
-rw-r--r-- | main.c | 42 | ||||
-rw-r--r-- | window.c | 22 | ||||
-rw-r--r-- | window.h | 1 |
3 files changed, 51 insertions, 14 deletions
@@ -31,34 +31,58 @@ main () while (1) { pixman_color_t color = { 0xffff, 0xabcd, 0x7777, 0xaaaa }; + pixman_color_t bg = { 0x0, 0x0, 0x0, 0xffff }; pixman_point_fixed_t p1 = { 0, 0 }; - pixman_point_fixed_t p2 = { ws_window_get_width (window) << 16, - ws_window_get_height (window) << 16 }; - pixman_gradient_stop_t stops[2] = + pixman_point_fixed_t p2 = { 0, 0 }; + pixman_gradient_stop_t stops[3] = { { pixman_int_to_fixed (0), { 0x2222, 0xeeee, 0xeeee, 0xeeee } }, + { pixman_double_to_fixed (0.5), { 0xdddd, 0xdddd, 0x0000, 0xdddd } }, { pixman_int_to_fixed (1), { 0xffff, 0x1111, 0x1111, 0x1111 } } }; int fd = ws_get_fd (ws); + struct timeval tv; + pixman_image_t *image; + int w, h; FD_ZERO (&set); FD_SET (fd, &set); - select (fd + 1, &set, NULL, NULL, NULL); + tv.tv_usec = 0; + tv.tv_sec = 5; + + if (!ws_pending (ws)) + select (fd + 1, &set, NULL, NULL, NULL); ws_process (ws); +#if 0 color.red = rand(); color.blue = rand(); +#endif - image = pixman_image_create_linear_gradient (&p1, &p2, stops, 2); - ws_window_copy_from_image (window, image, 0, 0, 0, 0, - ws_window_get_width (window), - ws_window_get_height (window)); + w = ws_window_get_width (window); + h = ws_window_get_height (window); + + image = pixman_image_create_solid_fill (&bg); + ws_window_copy_from_image (window, image, 0, 0, 0, 0, w, h); + pixman_image_unref (image); + + p2.x = w << 16; + p2.y = h << 16; + image = pixman_image_create_linear_gradient (&p1, &p2, stops, 3); + ws_window_copy_from_image (window, image, 0, 0, 0, 0, w, h); pixman_image_unref (image); + + image = pixman_image_create_solid_fill (&color); + ws_window_copy_from_image (window, image, 0, 0, 0, 0, 20, h); + ws_window_copy_from_image (window, image, 0, 0, w - 20, 0, 20, h); + ws_window_copy_from_image (window, image, 0, 0, 0, 0, w, 20); + ws_window_copy_from_image (window, image, 0, 0, 0, h - 20, w, 20); + pixman_image_unref (image); + ws_window_finish (&window, 1); } - printf ("Hello world\n"); while (1) ; return 0; @@ -290,7 +290,6 @@ update_local_geometry (window_t *window, int x, int y, int width, int height) if (width != old_width || height != old_height) { - printf ("resizing\n"); pixman_image_t *new_backing = pixman_image_create_bits ( window->ws->format, width, height, NULL, -1); @@ -369,7 +368,6 @@ process_expose (ws_t *ws, const XEvent *event) { window_t *window; - printf ("expose\n"); if (!(window = find_window (ws, event->xexpose.window))) return; @@ -377,10 +375,19 @@ process_expose (ws_t *ws, const XEvent *event) window, event->xexpose.x, event->xexpose.y, event->xexpose.width, event->xexpose.height); } +pixman_bool_t +ws_pending (ws_t *ws) +{ + return XPending (ws->display); +} + void ws_process (ws_t *ws) { - while (XPending (ws->display)) + int n_expose = 0; + int n_configure = 0; + + while (ws_pending (ws)) { XEvent event; @@ -389,9 +396,11 @@ ws_process (ws_t *ws) switch (event.type) { case ConfigureNotify: + n_configure++; process_configure_notify (ws, &event); break; case Expose: + n_expose++; process_expose (ws, &event); break; case MotionNotify: @@ -400,6 +409,8 @@ ws_process (ws_t *ws) ; } } + + printf ("expose: %d, configure: %d\n", n_expose, n_configure); } /* Window */ @@ -511,7 +522,8 @@ ws_window_copy_area (window_t *window, int width, int height) { - pixman_format_code_t format = pixman_image_get_format (window->backing_store); + pixman_format_code_t format = + pixman_image_get_format (window->backing_store); pixman_image_t *tmp = pixman_image_create_bits (format, width, height, NULL, -1); @@ -536,7 +548,7 @@ ws_window_copy_from_image (window_t *window, /* copy from image to backing */ pixman_image_composite32 (PIXMAN_OP_SRC, image, NULL, window->backing_store, - win_x, win_y, 0, 0, image_x, image_y, + image_x, image_y, 0, 0, win_x, win_y, width, height); } @@ -26,6 +26,7 @@ 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); +pixman_bool_t ws_pending (ws_t *ws); /* Window */ window_t *ws_create_window (ws_t *ws, |