diff --git a/awesome-menu.c b/awesome-menu.c index 26fb721f3..8768a1fe4 100644 --- a/awesome-menu.c +++ b/awesome-menu.c @@ -60,7 +60,7 @@ typedef struct item_t item_t; struct item_t { char *data; - item_t *next; + item_t *prev, *next; Bool match; }; @@ -363,7 +363,7 @@ compute_match(const char *word) if(a_strlen(globalconf.text)) item_list_fill_file(NULL); for(item = globalconf.items; item; item = item->next) - item->match = True; + item->match = True; } } @@ -389,7 +389,7 @@ static void redraw(void) { item_t *item; - Area geometry = { 0, 0, 0, 0, NULL }; + Area geometry = { 0, 0, 0, 0, NULL, NULL }; Bool selected_item_is_drawn = False; int len, prompt_len, x_of_previous_item; @@ -604,7 +604,7 @@ main(int argc, char **argv) char *configfile = NULL, *cmd; ssize_t len; const char *shell = getenv("SHELL"); - Area geometry = { 0, 0, 0, 0, NULL }; + Area geometry = { 0, 0, 0, 0, NULL, NULL }; static struct option long_options[] = { {"help", 0, NULL, 'h'}, diff --git a/awesome-message.c b/awesome-message.c index 3e97ca643..23a730c19 100644 --- a/awesome-message.c +++ b/awesome-message.c @@ -137,8 +137,8 @@ main(int argc, char **argv) SimpleWindow *sw; DrawCtx *ctx; XEvent ev; - Area geometry = { 0, 0, 200, 50, NULL }, - icon_geometry = { -1, -1, -1, -1, NULL }; + Area geometry = { 0, 0, 200, 50, NULL, NULL }, + icon_geometry = { -1, -1, -1, -1, NULL, NULL }; int opt, ret; int delay = 0; char *configfile = NULL; diff --git a/common/draw.c b/common/draw.c index c027fce95..28e0b4de1 100644 --- a/common/draw.c +++ b/common/draw.c @@ -531,7 +531,7 @@ draw_image(DrawCtx *ctx, int x, int y, int wanted_h, const char *filename) Area draw_get_image_size(const char *filename) { - Area size = { -1, -1, -1, -1, NULL }; + Area size = { -1, -1, -1, -1, NULL, NULL }; cairo_surface_t *surface; cairo_status_t cairo_st; diff --git a/common/draw.h b/common/draw.h index eac47b2d8..ac04fed8c 100644 --- a/common/draw.h +++ b/common/draw.h @@ -46,7 +46,7 @@ struct Area int y; int width; int height; - Area *next; + Area *prev, *next; }; DO_SLIST(Area, area, p_delete); diff --git a/common/list.h b/common/list.h index 724b41a9d..8589e9e28 100644 --- a/common/list.h +++ b/common/list.h @@ -29,19 +29,25 @@ { \ return item->next; \ } \ + \ static inline type *prefix##_list_pop(type **list) \ { \ if (*list) \ { \ type *res = *list; \ *list = res->next; \ + if(res->next) \ + res->next->prev = NULL; \ res->next = NULL; \ return res; \ } \ return NULL; \ } \ + \ static inline void prefix##_list_push(type **list, type *item) \ { \ + if(*list) \ + (*list)->prev = item; \ item->next = *list; \ *list = item; \ } \ @@ -56,10 +62,14 @@ static inline void prefix##_list_append(type **list, type *item) \ { \ if(*(list = prefix##_list_last(list))) \ + { \ (*list)->next = item; \ + item->prev = *list; \ + } \ else \ (*list) = item; \ } \ + \ static inline type *prefix##_list_rev(type *list) \ { \ type *l = NULL; \ @@ -73,6 +83,7 @@ *list = NULL; \ return list; \ } \ + \ static inline void prefix##_list_wipe(type **list) \ { \ while (*list) \ @@ -81,62 +92,83 @@ dtor(&item); \ } \ } \ - static inline type *prefix##_list_prev(type **list, type *item) \ + \ + static inline type *prefix##_list_prev(type **list __attribute__ ((unused)), \ + type *item) \ { \ - type *tmp; \ - if(*list == item) return NULL; \ - for(tmp = *list; tmp && tmp->next != item; tmp = tmp->next); \ - return tmp; \ + return item->prev; \ } \ - static inline void prefix##_list_swap(type **list, type *item1, \ - type *item2) \ + \ + static inline void prefix##_list_swap(type **list, type *item1, type *item2) \ { \ if(!item1 || !item2) return; \ \ type *i1n = item1->next; \ type *i2n = item2->next; \ - type * i1p = prefix##_list_prev(list, item1); \ - type * i2p = prefix##_list_prev(list, item2); \ - item1->next = i2n == item1 ? item2 : i2n; \ - item2->next = i1n == item2 ? item1 : i1n; \ - \ - \ - if(i1p && i1p != item2) \ - i1p->next = item2; \ - if(i2p && i2p != item1) \ - i2p->next = item1; \ + type *i1p = item1->prev; \ + type *i2p = item2->prev; \ \ + if(item1 == i2n) \ + { \ + item1->next = item2; \ + item2->prev = item1; \ + if((item1->prev = i2p)) \ + i2p->next = item1; \ + if((item2->next = i1n)) \ + i1n->prev = item2; \ + } \ + else if(item2 == i1n) \ + { \ + item2->next = item1; \ + item1->prev = item2; \ + if((item2->prev = i1p)) \ + i1p->next = item2; \ + if((item1->next = i2n)) \ + i2n->prev = item1; \ + } \ + else \ + { \ + if((item1->next = i2n)) \ + item1->next->prev = item1; \ + if((item1->prev = i2p)) \ + item1->prev->next = item1; \ + if((item2->prev = i1p)) \ + item2->prev->next = item2; \ + if((item2->next = i1n)) \ + item2->next->prev = item2; \ + } \ if(*list == item1) \ *list = item2; \ else if(*list == item2) \ *list = item1; \ } \ + \ static inline type *prefix##_list_prev_cycle(type **list, type *item) \ { \ - type *tmp = prefix##_list_prev(list, item); \ - if(!tmp) \ - tmp = *prefix##_list_last(list); \ - return tmp; \ + if(!item->prev) \ + return *prefix##_list_last(list); \ + return item->prev; \ } \ + \ static inline type *prefix##_list_next_cycle(type **list, type *item) \ { \ - if(item) \ - { \ - if(item->next) \ - return item->next; \ - else \ - return *list; \ - } \ + if(item->next) \ + return item->next; \ + else \ + return *list; \ return NULL; \ } \ + \ static inline void prefix##_list_detach(type **list, type *item) \ { \ - type *prev = prefix##_list_prev(list, item); \ - if(prev) \ - prev->next = item->next; \ if(item == *list) \ *list = item->next; \ + else if(item->prev) \ + item->prev->next = item->next; \ + if(item->next) \ + item->next->prev = item->prev; \ item->next = NULL; \ + item->prev = NULL; \ } \ #endif diff --git a/layout.h b/layout.h index 2d57f0156..593900cc8 100644 --- a/layout.h +++ b/layout.h @@ -35,7 +35,7 @@ struct Layout { char *image; LayoutArrange *arrange; - Layout *next; + Layout *prev, *next; }; DO_SLIST(Layout, layout, p_delete); diff --git a/layouts/tile.c b/layouts/tile.c index bd8cc7683..91c00f74c 100644 --- a/layouts/tile.c +++ b/layouts/tile.c @@ -133,7 +133,7 @@ _tile(int screen, const Position position) unsigned int mw = 0, mh = 0; int n, i, masterwin = 0, otherwin = 0; int real_ncol = 1, win_by_col = 1, current_col = 0; - Area area, geometry = { 0, 0, 0, 0, NULL }; + Area area, geometry = { 0, 0, 0, 0, NULL, NULL }; Client *c; Tag **curtags = tags_get_current(screen); diff --git a/mouse.c b/mouse.c index d5a635875..b1487f29d 100644 --- a/mouse.c +++ b/mouse.c @@ -149,7 +149,7 @@ uicb_client_resizemouse(int screen, char *arg __attribute__ ((unused))) Client *c = globalconf.focus->client; Tag **curtags = tags_get_current(screen); Layout *layout = curtags[0]->layout; - Area area = { 0, 0, 0, 0 , NULL}, geometry; + Area area = { 0, 0, 0, 0, NULL, NULL }, geometry; double mwfact; /* only handle floating and tiled layouts */ diff --git a/placement.c b/placement.c index 1346f988e..791e03c67 100644 --- a/placement.c +++ b/placement.c @@ -64,7 +64,7 @@ Area placement_smart(Area geometry, int border, int screen) { Client *c; - Area newgeometry = { 0, 0, 0, 0, NULL }; + Area newgeometry = { 0, 0, 0, 0, NULL, NULL }; Area *screen_geometry, *arealist = NULL, *r; Bool found = False; diff --git a/screen.c b/screen.c index 736b86706..afe46ffcc 100644 --- a/screen.c +++ b/screen.c @@ -81,7 +81,7 @@ screen_get_area(int screen, Statusbar *statusbar, Padding *padding) Area get_display_area(int screen, Statusbar *statusbar, Padding *padding) { - Area area = { 0, 0, 0, 0, NULL }; + Area area = { 0, 0, 0, 0, NULL, NULL }; Statusbar *sb; area.width = DisplayWidth(globalconf.display, screen); diff --git a/statusbar.c b/statusbar.c index cc57369e4..e84a4d754 100644 --- a/statusbar.c +++ b/statusbar.c @@ -74,7 +74,7 @@ statusbar_draw(Statusbar *statusbar) int phys_screen = get_phys_screen(statusbar->screen); Widget *widget; int left = 0, right = 0; - Area rectangle = { 0, 0, 0, 0, NULL }; + Area rectangle = { 0, 0, 0, 0, NULL, NULL }; Drawable d; /* don't waste our time */ diff --git a/structs.h b/structs.h index d736f9e3a..bb73e1ab2 100644 --- a/structs.h +++ b/structs.h @@ -66,7 +66,8 @@ struct Rule regex_t *prop_r; regex_t *tags_r; regex_t *xpropval_r; - Rule *next; + /** Next and previous rules */ + Rule *prev, *next; }; /** Key bindings */ @@ -77,7 +78,8 @@ struct Key KeyCode keycode; Uicb *func; char *arg; - Key *next; + /** Next and previous keys */ + Key *prev, *next; }; /** Mouse buttons bindings */ @@ -88,7 +90,8 @@ struct Button unsigned int button; Uicb *func; char *arg; - Button *next; + /** Next and previous buttons */ + Button *prev, *next; }; /** Widget tell status code */ @@ -138,8 +141,8 @@ struct Widget Bool needs_update; int flags; } cache; - /** Next widget */ - Widget *next; + /** Next and previous widgets */ + Widget *prev, *next; }; /** Status bar */ @@ -161,8 +164,8 @@ struct Statusbar int screen; /** Widget list */ Widget *widgets; - /** Next statusbar */ - Statusbar *next; + /** Next and previous statusbars */ + Statusbar *prev, *next; }; /** Client type */ @@ -194,8 +197,8 @@ struct Client Bool skip; /** True if the client must be skipped from task bar client list */ Bool skiptb; - /** Next client */ - Client *next; + /** Next and previous clients */ + Client *prev, *next; /** Window of the client */ Window win; /** Client logical screen */ @@ -208,7 +211,8 @@ typedef struct client_node_t client_node_t; struct client_node_t { Client *client; - client_node_t *next; + /** Next and previous client_nodes */ + client_node_t *prev, *next; }; /** Tag type */ @@ -231,8 +235,8 @@ struct Tag int nmaster; /** Number of columns in tile layout */ int ncol; - /** Next tag */ - Tag *next; + /** Next and previous tags */ + Tag *prev, *next; }; /** tag_client_node type */ @@ -241,7 +245,8 @@ struct tag_client_node_t { Tag *tag; Client *client; - tag_client_node_t *next; + /** Next and previous tag_client_nodes */ + tag_client_node_t *prev, *next; }; /** Padding type */ diff --git a/widgets/taglist.c b/widgets/taglist.c index 0cce77990..4d0335798 100644 --- a/widgets/taglist.c +++ b/widgets/taglist.c @@ -116,7 +116,7 @@ taglist_draw(Widget *widget, widget->area.y, flagsize, flagsize, - NULL }; + NULL, NULL }; draw_rectangle(ctx, rectangle, sel && is_client_tagged(sel, tag), colors[ColFG]); } widget->area.width += w;