diff options
author | Søren Sandmann Pedersen <ssp@l3000.localdomain> | 2011-12-09 04:08:01 -0500 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@l3000.localdomain> | 2011-12-09 04:08:01 -0500 |
commit | 7d8876459ce6c4ac418046b93d31a46ce37fe496 (patch) | |
tree | 4b5374ca9614cb24a25676f4f7efd63e7ad0d342 | |
parent | fbf50bbc03b154f82efc85756e735e1c66c67cfb (diff) |
Paint less
-rw-r--r-- | list.h | 2 | ||||
-rw-r--r-- | main.c | 53 | ||||
-rw-r--r-- | window.c | 22 |
3 files changed, 43 insertions, 34 deletions
@@ -63,7 +63,7 @@ list_move_to_front (list_t *list, link_t *link) #define LIST_FOREACH(list, link) \ for ((link) = (list)->head; \ - (link) != (link_t *)(list); \ + (link) != (link_t *)(list); \ (link) = (link)->next) #if defined(__GNUC__) && __GNUC__ >= 4 @@ -19,41 +19,39 @@ repaint (window_t *window) }; pixman_image_t *image; int w, h; - + #if 0 color.red = rand(); color.blue = rand(); #endif - + 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); - -#if 0 + 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); -#endif - + 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); - + image = pixman_image_create_solid_fill (&bg); ws_window_copy_from_image (window, image, 0, 0, 0, 0, 1, h); ws_window_copy_from_image (window, image, 0, 0, w - 1, 0, 1, h); ws_window_copy_from_image (window, image, 0, 0, 0, 0, w, 1); ws_window_copy_from_image (window, image, 0, 0, 0, h - 1, w, 1); pixman_image_unref (image); - + ws_window_finish (&window, 1); } @@ -77,8 +75,11 @@ on_event (window_t *window, ws_event_t *event, void *data) switch (event->common.type) { case WS_CONFIGURE: +#if 0 printf ("configure %d %d %d %d\n", x, y, w, h); - need_repaint = 1; +#endif + if (event->configure.configure_type & WS_WINDOW_SIZE_CHANGED) + need_repaint = 1; break; case WS_BUTTON_DOWN: @@ -93,7 +94,7 @@ on_event (window_t *window, ws_event_t *event, void *data) { dragging = 2; } - + if (dragging) { drag_x = event->button.root_x; @@ -125,6 +126,9 @@ on_event (window_t *window, ws_event_t *event, void *data) int dx = event->motion.root_x - drag_x; int dy = event->motion.root_y - drag_y; +#if 0 + printf ("move to %d %d\n", drag_pos_x + dx, drag_pos_y + dy); +#endif ws_window_move (window, drag_pos_x + dx, drag_pos_y + dy); } } @@ -139,38 +143,35 @@ main () pixman_color_t color = { 0xffff, 0xabcd, 0x7777, 0x7777 }; fd_set set; int fd; - + if (!ws) { printf ("could not open display\n"); return 0; } - + fd = ws_get_fd (ws); - + window = ws_create_window (ws, 300, 200, 200, 200); - + ws_window_set_callback (window, on_event, ws); - + 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); - ws_process (ws); - + + repaint (window); + while (1) { if (!ws_pending (ws)) { struct timeval tv; - + FD_ZERO (&set); FD_SET (fd, &set); - + tv.tv_usec = 0; tv.tv_sec = 5; - + select (fd + 1, &set, NULL, NULL, NULL); } ws_process (ws); @@ -180,7 +181,7 @@ main () need_repaint = 0; } } - + while (1) ; return 0; @@ -400,11 +400,11 @@ static void process_expose (ws_t *ws, const XEvent *event) { window_t *window; - + if (!(window = find_window (ws, event->xexpose.window))) return; - pixman_region32_union_rect (&window->repaint, &window->repaint, + pixman_region32_union_rect (&window->repaint, &window->repaint, event->xexpose.x, event->xexpose.y, event->xexpose.width, event->xexpose.height); } @@ -425,7 +425,7 @@ emit_events (window_t *window) if (window->event_func) window->event_func (window, event, window->event_data); - + list_unlink (link); free (event); } @@ -467,7 +467,7 @@ get_motion_time (Display *dpy, XEvent *event, XPointer arg) return FALSE; } - + static int use_this_motion_notify (Display *dpy, window_t *window, uint32_t event_time) @@ -544,7 +544,7 @@ process_button_event (ws_t *ws, ws_event_type_t type, const XEvent *event) wsevent.button.y = event->xbutton.y; wsevent.button.root_x = event->xbutton.x_root; wsevent.button.root_y = event->xbutton.y_root; - + window_queue_event (window, &wsevent); } @@ -615,6 +615,9 @@ ws_process (ws_t *ws) boxes++; } + pixman_region32_fini (&window->repaint); + pixman_region32_init (&window->repaint); + emit_events (window); } } @@ -640,7 +643,7 @@ disable_decorations (window_t *window) memset (&hints, 0, sizeof (hints)); hints.flags = MWM_HINTS_DECORATIONS; hints.decorations = 0; - + XChangeProperty (dpy, window->xid, atom, atom, 32, PropModeReplace, (unsigned char *)&hints, @@ -695,7 +698,7 @@ ws_create_window (ws_t *ws, window->event_func = NULL; window->event_data = NULL; - + return window; } @@ -746,6 +749,11 @@ ws_window_move_resize (window_t *window, { int need = 0; + if (width < 1) + width = 1; + if (height < 1) + height = 1; + if (x != window->x || y != window->y) need |= 1; if (width != get_width (window) || height != get_height (window)) |