summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSadrul Habib Chowdhury <sadrul@users.sourceforge.net>2010-02-26 12:09:31 -0500
committerSadrul Habib Chowdhury <sadrul@users.sourceforge.net>2010-02-26 12:09:31 -0500
commit48624f98db28bd8c117cf1aebfc2cd326f6243bc (patch)
tree7b92d12d07a72589435c7e25bde63021f0e534c4
parent4f28ba8c8fd9032763eac42ed3591a6b2751f84c (diff)
downloadscreen-48624f98db28bd8c117cf1aebfc2cd326f6243bc.tar.gz
Reduce a little code duplication.
-rw-r--r--src/list_window.c107
1 files changed, 44 insertions, 63 deletions
diff --git a/src/list_window.c b/src/list_window.c
index c6af77f..df83578 100644
--- a/src/list_window.c
+++ b/src/list_window.c
@@ -58,6 +58,29 @@ struct gl_Window_Data
struct win *fore; /* The foreground window we had. */
};
+/* This macro should not be used if 'fn' is expected to update the window list */
+#define FOR_EACH_WINDOW(_wdata, _w, fn) do { \
+ if ((_wdata)->order == WLIST_MRU) \
+ { \
+ struct win *_ww; \
+ for (_ww = windows; _ww; _ww = _ww->w_next) \
+ { \
+ _w = _ww; \
+ fn \
+ } \
+ } \
+ else \
+ { \
+ struct win **_ww, *_witer; \
+ for (_ww = wtab, _witer = windows; _witer && _ww - wtab < maxwin; _ww++) \
+ { \
+ if (!(_w = *_ww)) continue; \
+ fn \
+ _witer = _witer->w_next; \
+ } \
+ } \
+ } while (0)
+
/* Is 'a' an ancestor of 'd'? */
static int
window_ancestor(struct win *a, struct win *d)
@@ -104,43 +127,23 @@ gl_Window_add_group(struct ListData *ldata, struct ListRow *row)
{
/* Right now, 'row' doesn't have any child. */
struct gl_Window_Data *wdata = ldata->data;
- struct win *group = row->data;
+ struct win *group = row->data, *w;
struct ListRow *cur = row;
ASSERT(wdata->nested);
- if (wdata->order == WLIST_MRU)
- {
- struct win *w;
- for (w = windows; w; w = w->w_next)
- {
- if (w->w_group != group)
- continue;
+ FOR_EACH_WINDOW(wdata, w,
+ if (w->w_group != group)
+ continue;
- cur = glist_add_row(ldata, w, cur);
- if (w == wdata->fore)
- ldata->selected = cur;
-
- if (w->w_type == W_TYPE_GROUP)
- cur = gl_Window_add_group(ldata, cur);
- }
- }
- else if (wdata->order == WLIST_NUM)
- {
- struct win **w;
- for (w = wtab; w - wtab < maxwin; w++)
- {
- if (!*w || (*w)->w_group != group)
- continue;
+ cur = glist_add_row(ldata, w, cur);
+ if (w == wdata->fore)
+ ldata->selected = cur;
- cur = glist_add_row(ldata, *w, cur);
- if (*w == wdata->fore)
- ldata->selected = cur;
+ if (w->w_type == W_TYPE_GROUP)
+ cur = gl_Window_add_group(ldata, cur);
+ );
- if ((*w)->w_type == W_TYPE_GROUP)
- cur = gl_Window_add_group(ldata, cur);
- }
- }
return cur;
}
@@ -149,39 +152,17 @@ gl_Window_rebuild(struct ListData *ldata)
{
struct ListRow *row = NULL;
struct gl_Window_Data *wdata = ldata->data;
-
- if (wdata->order == WLIST_MRU)
- {
- struct win *w;
- for (w = windows; w; w = w->w_next)
- {
- if (w->w_group == wdata->group)
- {
- row = glist_add_row(ldata, w, row);
- if (w == wdata->fore)
- ldata->selected = row;
- if (w->w_type == W_TYPE_GROUP && wdata->nested)
- row = gl_Window_add_group(ldata, row);
- }
- }
- }
- else
- {
- struct win **w;
- struct win *wlist;
- for (w = wtab, wlist = windows; wlist && w - wtab < maxwin; w++)
- {
- if (*w && (*w)->w_group == wdata->group)
- {
- row = glist_add_row(ldata, *w, row);
- if (*w == wdata->fore)
- ldata->selected = row;
- wlist = wlist->w_next;
- if ((*w)->w_type == W_TYPE_GROUP && wdata->nested)
- row = gl_Window_add_group(ldata, row);
- }
- }
- }
+ struct win *w;
+
+ FOR_EACH_WINDOW(wdata, w,
+ if (w->w_group != wdata->group)
+ continue;
+ row = glist_add_row(ldata, w, row);
+ if (w == wdata->fore)
+ ldata->selected = row;
+ if (w->w_type == W_TYPE_GROUP && wdata->nested)
+ row = gl_Window_add_group(ldata, row);
+ );
glist_display_all(ldata);
}