{
int nwins = 0;
Window* wins = NULL;
- for (Client* c = mon->cspace->floating; c; c = c->next)
+ Client* c;
+ Column* col;
+ LIST_FOR_EACH(c, mon->cspace->floating)
{
wins = realloc(wins, ++nwins * sizeof(Window));
wins[nwins-1] = c->frame;
}
/* add in the monocled windows first */
- for (Column* col = mon->cspace->columns; col; col = col->next)
+ LIST_FOR_EACH(col, mon->cspace->columns)
{
if (col->focused)
{
}
}
/* now lower all of the tiled windows */
- for (Column* col = mon->cspace->columns; col; col = col->next)
+ LIST_FOR_EACH(col, mon->cspace->columns)
{
- for (Client* c = col->clients; c; c = c->next)
+ LIST_FOR_EACH(c, col->clients)
{
if (col->focused != c)
{
int mons_find(Window win, Location* loc)
{
- for (Monitor* mon = Monitors; mon; mon = mon->next)
+ Monitor* mon;
+ Workspace* wspace;
+ LIST_FOR_EACH(mon, Monitors)
{
- for (Workspace* wspace = mon->wspaces; wspace; wspace = wspace->next)
+ LIST_FOR_EACH(wspace, mon->wspaces)
{
Column* column = NULL;
Client* client = client_find(wspace->floating, win);
if (!client)
{
- for (column = wspace->columns; column; column = column->next)
+ LIST_FOR_EACH(column, wspace->columns)
{
if ( (client = client_find(column->clients, win)) )
{
if (mons_find(c->win, &loc) && !loc.column)
{
int maxarea = 0;
- Monitor* closest = NULL;
- for (Monitor* mon = Monitors; mon; mon = mon->next)
+ Monitor *mon = NULL, *closest = NULL;
+ LIST_FOR_EACH(mon, Monitors)
{
int left = max(cleft, mon->x);
int right = min(cright, mon->x + mon->w);
/* if we changed monitors, make sure we update accordingly */
if (closest && loc.monitor != closest)
{
- loc.workspace->floating = delclient(loc.workspace->floating, c);
+ loc.workspace->floating = list_del(loc.workspace->floating, c);
c->next = closest->cspace->floating;
closest->cspace->floating = c;
}
void mons_raise(Monitor* mon, Client* c)
{
- mon->cspace->floating = delclient(mon->cspace->floating, c);
+ mon->cspace->floating = list_del(mon->cspace->floating, c);
c->next = mon->cspace->floating;
mon->cspace->floating = c;
mons_layer(mon);
void mons_lower(Monitor* mon, Client* c)
{
- mon->cspace->floating = delclient(mon->cspace->floating, c);
+ mon->cspace->floating = list_del(mon->cspace->floating, c);
c->next = NULL;
if (mon->cspace->floating)
{
- Client* curr = mon->cspace->floating;
- for (; curr && curr->next; curr = curr->next);
+ Client* curr = list_last(mon->cspace->floating);
curr->next = c;
}
else
static Monitor* pickmon(void)
{
get_mouse(&PtrX, &PtrY);
- Monitor* mon = Monitors;
- for (; mon; mon = mon->next)
- {
- if ((mon->x <= PtrX && PtrX < mon->x+mon->w) && (mon->y <= PtrY && PtrY < mon->y+mon->h))
- {
- break;
- }
- }
+ Monitor* mon;
+ LIST_FOR_EACH_UNTIL(mon, Monitors,
+ (mon->x <= PtrX && PtrX < mon->x+mon->w) &&
+ (mon->y <= PtrY && PtrY < mon->y+mon->h)
+ );
mon = (mon ? mon : Monitors);
return mon;
}
static Column* pickcol(Column* cols, int relx)
{
- Column* col = cols;
+ Column* col;
int left = 0, right = 0;
- for (col = cols; col; col = col->next)
+ LIST_FOR_EACH(col, cols)
{
left = right, right += col->width;
if (left <= relx && relx < right)
static Workspace* pickws(Monitor* mon, int wsid)
{
- Workspace* wspace = mon->wspaces;
+ Workspace* wspace;
int i = 0;
- for (; wspace; wspace = wspace->next, i++)
- {
- if (i == wsid)
- {
- break;
- }
- }
+ LIST_FOR_EACH_UNTIL(wspace, mon->wspaces, (i++ == wsid));
return wspace;
}
static void client_visibility(Workspace* wspace, int show)
{
- for (Client* client = wspace->floating; client; client = client->next)
+ Column* col;
+ Client* client;
+ LIST_FOR_EACH(client, wspace->floating)
{
client_show(client, show);
}
- for (Column* col = wspace->columns; col; col = col->next)
+ LIST_FOR_EACH(col, wspace->columns)
{
- for (Client* client = col->clients; client; client = client->next)
+ LIST_FOR_EACH(client, col->clients)
{
client_show(client, show);
}
static Client* client_find(Client* clients, Window win)
{
- Client* client = clients;
- for (; client; client = client->next)
- {
- if (client->frame == win || client->win == win)
- {
- break;
- }
- }
+ Client* client;
+ LIST_FOR_EACH_UNTIL(client, clients,
+ (client->frame == win || client->win == win));
return client;
}
}
else
{
- Column* col = mon->cspace->columns;
/* find first empty column, and fill that first */
- for (; col && col->clients; col = col->next);
+ Column* col = list_last(mon->cspace->columns);
if (!col)
{
/* otherwise pick the column to the right or current column */
{
if (!loc->column)
{
- loc->workspace->floating = delclient(loc->workspace->floating, c);
+ loc->workspace->floating = list_del(loc->workspace->floating, c);
}
else if (loc->column->focused)
{
static void adjust_all(Column* col, int xoff)
{
- for (Client* c = col->clients; c; c = c->next)
+ Client* c;
+ LIST_FOR_EACH(c, col->clients)
{
c->x += xoff;
c->w = col->width;
static void coldims(Monitor* mon, Column* col, int *x, int *y, int *w, int *h)
{
+ Column* c;
*x = mon->x, *y = mon->y, *w = col->width-2, *h = mon->h-2;
- for (Column* c = mon->cspace->columns; c != col; *x += c->width, c = c->next);
+ LIST_FOR_EACH_UNTIL(c, mon->cspace->columns, (c == col))
+ {
+ *x += c->width;
+ }
}
void monocled_add(Monitor* mon, Column* col, Client* c)
void monocled_del(Monitor* mon, Column* col, Client* c)
{
- col->clients = delclient(col->clients, c);
+ col->clients = list_del(col->clients, c);
col->focused = col->clients;
c = col->clients;
if (c)
void monocled_set(Monitor* mon, Column* col, Client* c)
{
- col->clients = delclient(col->clients, c);
+ col->clients = list_del(col->clients, c);
c->next = col->clients;
col->clients = c;
col->focused = c;
coldims(mon, col, &(c->x), &(c->y), &(c->w), &(c->h));
if (col->clients)
{
- Client* max = col->clients;
- for (Client* c = max; c; c = c->next)
+ Client *cl, *max = col->clients;
+ LIST_FOR_EACH(cl, max)
{
- if (c->h > max->h)
+ if (cl->h > max->h)
{
- max = c;
+ max = cl;
}
}
if (max->h < 3*MIN_HEIGHT)
}
else
{
- Client* prev = col->clients;
- for (; prev->next != c; prev = prev->next);
+ Client* prev = list_prev(col->clients, c);
prev->next = c->next;
prev->h += c->h;
client_setshade(prev, 0);
{
(void)c;
col->focused = NULL;
- int nclients = 0;
- for (Client* c = col->clients->next; c; c = c->next, nclients++);
+ int nclients = list_length(col->clients->next);
int starty = (mon->y + mon->h) - (nclients * MIN_HEIGHT);
col->clients->h = starty - mon->y - 1;
client_adjust(col->clients);
- for (Client* c = col->clients->next; c; c = c->next)
+ LIST_FOR_EACH(c, col->clients->next)
{
c->y = starty;
c->h = MIN_HEIGHT;
void stacked_addheight(Monitor* mon, Column* col, Client* c, int amount)
{
- Client* prev = col->clients;
- for (; prev && prev->next != c; prev = prev->next);
+ Client* prev = list_prev(col->clients, c);
if (prev)
{
amount = (abs(amount) < BORDER_WIDTH ? min((int)(-c->h * 0.25), -2*MIN_HEIGHT) : amount);
c->y = max(miny, min(maxy, c->y + amount));
prev->h = c->y - prev->y;
c->h = (c->next ? c->next->y : mon->y + mon->h) - c->y;
- printf("ADD_HEIGHT1(w: %lx x: %d y: %d w: %d h: %d)\n", c->frame, c->x, c->y, c->w, c->h);
+ printf("ADD_HEIGHT(w: %lx x: %d y: %d w: %d h: %d)\n", c->frame, c->x, c->y, c->w, c->h);
client_setshade(prev, (prev->h <= MIN_HEIGHT));
client_setshade(c, (c->h <= MIN_HEIGHT));
client_adjust(prev);