diff options
author | Søren Sandmann Pedersen <ssp@l3000.localdomain> | 2011-12-07 23:54:35 -0500 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@l3000.localdomain> | 2011-12-07 23:54:35 -0500 |
commit | 22a80c020663496bd10bc27f6880c4d51569d275 (patch) | |
tree | 90104f280395b50997f066b1ecbcfca007234dc0 | |
parent | c01bafa96d8c4152ea5c2f9f58c7d4436a17edf1 (diff) |
Add lists
-rw-r--r-- | list.h | 65 | ||||
-rw-r--r-- | window.c | 33 |
2 files changed, 93 insertions, 5 deletions
@@ -0,0 +1,65 @@ +#ifndef LIST_H +#define LIST_H + +/* Doubly linked lists */ +typedef struct link_t link_t; +struct link_t +{ + link_t *next; + link_t *prev; +}; + +typedef struct list_t list_t; +struct list_t +{ + link_t *head; + link_t *tail; +}; + +static inline void +list_init (list_t *list) +{ + list->head = (link_t *)list; + list->tail = (link_t *)list; +} + +static inline void +list_prepend (list_t *list, link_t *link) +{ + link->next = list->head; + link->prev = (link_t *)list; + list->head->prev = link; + list->head = link; +} + +static inline void +list_unlink (link_t *link) +{ + link->prev->next = link->next; + link->next->prev = link->prev; +} + +static inline void +list_move_to_front (list_t *list, link_t *link) +{ + list_unlink (link); + list_prepend (list, link); +} + +#define LIST_FOREACH(list, link) \ + for ((link) = (list)->head; \ + (link) != (link_t *)(list); \ + (link) = (link)->next) + +#if defined(__GNUC__) && __GNUC__ >= 4 +# define OFFSET_OF(type, member) \ + ((unsigned long)__builtin_offsetof(type, member)) +#else +# define OFFSET_OF(type, member) \ + ((unsigned long)(&(((type *)0)->member)) +#endif + +#define CONTAINER_OF(type, member, data) \ + ((type *)(((uint8_t *)data) - OFFSET_OF(type, member))) + +#endif @@ -3,6 +3,7 @@ #include <X11/Xutil.h> #include <assert.h> #include "window.h" +#include "list.h" struct ws_t { @@ -12,15 +13,18 @@ struct ws_t pixman_bool_t composited; pixman_bool_t has_alpha; int byte_order; + + list_t windows; }; struct window_t { - ws_t *ws; - XID xid; - int ref_count; - pixman_image_t *backing_store; - int x, y; + link_t link; + ws_t * ws; + XID xid; + int ref_count; + pixman_image_t * backing_store; + int x, y; }; static pixman_bool_t @@ -185,6 +189,22 @@ ws_open (void) return ws; } +static window_t * +find_window (ws_t *ws, XID xid) +{ + link_t *link; + + LIST_FOREACH (&ws->windows, link) + { + window_t *window = CONTAINER_OF (window_t, link, link); + + if (window->xid == xid) + return window; + } + + return NULL; +} + /* Window */ window_t * ws_create_window (ws_t *ws, @@ -210,6 +230,9 @@ ws_create_window (ws_t *ws, window->ws = ws; window->x = x; window->y = y; + + list_prepend (&ws->windows, &window->link); + return window; } |