summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSadrul Habib Chowdhury <sadrul@users.sourceforge.net>2010-02-23 20:30:53 -0500
committerSadrul Habib Chowdhury <sadrul@users.sourceforge.net>2010-02-23 20:30:53 -0500
commit94d954b97565a4b2625ca04152fca4e87cf9d730 (patch)
treead63377bb824aebe1762782bea4757ca2a6e5f28
parent68af85deb132f9b32685843cf8968c77a7a3d5a8 (diff)
downloadscreen-94d954b97565a4b2625ca04152fca4e87cf9d730.tar.gz
Final touches to the revamped window list.
This window list should be better than the old one, mostly code-wise, as there's yet no new functionality. However, it should be much simpler to add typeahead search and other nifty things now than before.
-rw-r--r--src/help.c4
-rw-r--r--src/list_generic.c6
-rw-r--r--src/list_generic.h1
-rw-r--r--src/list_window.c104
4 files changed, 82 insertions, 33 deletions
diff --git a/src/help.c b/src/help.c
index be344b7..7b3e3b5 100644
--- a/src/help.c
+++ b/src/help.c
@@ -691,6 +691,7 @@ int y, xs, xe, isblank;
**
*/
+#if 0
struct wlistdata;
static void WListProcess __P((char **, int *));
@@ -719,7 +720,6 @@ struct wlistdata {
int *list;
};
-#if 0
static struct LayFuncs WListLf =
{
WListProcess,
@@ -730,11 +730,9 @@ static struct LayFuncs WListLf =
WListResize,
DefRestore
};
-#endif
#define WTAB_GROUP_MATCHES(i) (group == wtab[i]->w_group)
-#if 0
static int
WListResize(wi, he)
int wi, he;
diff --git a/src/list_generic.c b/src/list_generic.c
index 61122a5..9f7d628 100644
--- a/src/list_generic.c
+++ b/src/list_generic.c
@@ -138,6 +138,8 @@ static void ListProcess(char **ppbuf, int *plen)
/* just redisplay the two lines. */
ldata->list_fn->gl_printrow(ldata, old);
ldata->list_fn->gl_printrow(ldata, ldata->selected);
+ flayer->l_y = ldata->selected->y;
+ LaySetCursor();
}
}
}
@@ -265,6 +267,10 @@ glist_display_all(struct ListData *list)
row->y = -1;
list->list_fn->gl_printfooter(list);
+ if (list->selected && list->selected->y != -1)
+ flayer->l_y = list->selected->y;
+ else
+ flayer->l_y = flayer->l_height - 1;
LaySetCursor();
}
diff --git a/src/list_generic.h b/src/list_generic.h
index 3e07c4c..489694c 100644
--- a/src/list_generic.h
+++ b/src/list_generic.h
@@ -26,7 +26,6 @@ struct ListRow
{
void *data; /* Some data relevant to this row */
struct ListRow *next, *prev; /* doubly linked list */
- struct ListRow *parent, *child; /* can also be tree */
int y; /* -1 if not on display */
};
diff --git a/src/list_window.c b/src/list_window.c
index d946fe1..f21b4f6 100644
--- a/src/list_window.c
+++ b/src/list_window.c
@@ -51,6 +51,59 @@ struct gl_Window_Data
struct win *fore; /* The foreground window we had. */
};
+/* Is 'a' an ancestor of 'd'? */
+static int
+window_ancestor(struct win *a, struct win *d)
+{
+ if (!a)
+ return 1; /* Every window is a descendant of the 'null' group */
+ for (; d; d = d->w_group)
+ if (d->w_group == a)
+ return 1;
+ return 0;
+}
+
+static struct ListRow *
+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 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;
+
+ cur = glist_add_row(ldata, w, 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)->w_type == W_TYPE_GROUP)
+ cur = gl_Window_add_group(ldata, cur);
+ }
+ }
+ return cur;
+}
+
static void
gl_Window_rebuild(struct ListData *ldata)
{
@@ -67,6 +120,8 @@ gl_Window_rebuild(struct ListData *ldata)
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);
}
}
}
@@ -82,6 +137,8 @@ gl_Window_rebuild(struct ListData *ldata)
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);
}
}
}
@@ -112,12 +169,6 @@ gl_Window_remove(struct ListData *ldata, struct win *p)
row->next->prev = row->prev;
if (row->prev)
row->prev->next = row->next;
- if (row->child)
- {
- /* Move the children to row->parent. Make sure the ordering is right. */
- }
- if (row->parent && row->parent->child == row)
- row->parent->child = row->next;
if (ldata->selected == row)
ldata->selected = row->prev ? row->prev : row->next;
@@ -154,25 +205,21 @@ static int
gl_Window_row(struct ListData *ldata, struct ListRow *lrow)
{
char *str;
- struct win *w;
+ struct win *w, *g;
int xoff;
struct mchar *mchar;
struct mchar mchar_rend = mchar_blank;
- struct ListRow *par = lrow;
+ struct gl_Window_Data *wdata = ldata->data;
w = lrow->data;
- /* XXX: First, make sure we want to display this window in the list.
+ /* First, make sure we want to display this window in the list.
* If we are showing a list for a group, and not on blank, then we must
* only show the windows directly belonging to that group.
* Otherwise, do some more checks. */
- for (xoff = 0, par = lrow->parent; par; par = par->parent)
- {
- if (par->y == -1)
- break;
- xoff += 2;
- }
+ for (xoff = 0, g = w->w_group; g != wdata->group; g = g->w_group)
+ xoff += 2;
display = Layer2Window(flayer) ? 0 : flayer->l_cvlist ? flayer->l_cvlist->c_display : 0;
str = MakeWinMsgEv(wliststr, w, '%', flayer->l_width - xoff, NULL, 0);
if (ldata->selected == lrow)
@@ -191,6 +238,9 @@ gl_Window_row(struct ListData *ldata, struct ListRow *lrow)
mchar = &mchar_blank;
LPutWinMsg(flayer, str, flayer->l_width, mchar, xoff, lrow->y);
+ if (xoff)
+ LPutWinMsg(flayer, "", xoff, mchar, 0, lrow->y);
+
return 1;
}
@@ -239,6 +289,13 @@ gl_Window_input(struct ListData *ldata, char **inp, int *len)
gl_Window_rebuild(ldata);
break;
+ case 'g':
+ /* Toggle nestedness */
+ wdata->nested = !wdata->nested;
+ glist_remove_rows(ldata);
+ gl_Window_rebuild(ldata);
+ break;
+
case 'a':
/* All-window view */
if (wdata->group)
@@ -427,14 +484,7 @@ WListUpdate(struct win *p, struct ListData *ldata)
if (!wdata->nested)
d = 0;
else
- {
- struct win *g = p->w_group;
- for (; g; g = g->w_group)
- if (g->w_group == wdata->group)
- break;
- if (!g)
- d = 0;
- }
+ d = window_ancestor(wdata->group, p);
}
}
@@ -473,15 +523,11 @@ WListUpdate(struct win *p, struct ListData *ldata)
}
}
- if (wdata->nested && before == NULL)
- {
- /* TODO: insert after the parent */
-#warning Fix me
- }
-
/* Now, find the row belonging to 'before' */
if (before)
rbefore = gl_Window_findrow(ldata, before);
+ else if (wdata->nested && p->w_group) /* There's no 'before'. So find the group window */
+ rbefore = gl_Window_findrow(ldata, p->w_group);
else
rbefore = NULL;