summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSadrul Habib Chowdhury <sadrul@users.sourceforge.net>2010-02-24 08:46:57 -0500
committerSadrul Habib Chowdhury <sadrul@users.sourceforge.net>2010-02-24 08:46:57 -0500
commitd1d0cc4d63eed5234f55aa0228196815f9969ae0 (patch)
tree1c665144df7bff190b625e4728750de1a6cacc66
parentc6a9fa007720396b78a096eed9a9ffb95fc9cbc5 (diff)
downloadscreen-d1d0cc4d63eed5234f55aa0228196815f9969ae0.tar.gz
Allow moving windows around from the window list.
Press ',' to switch the selected window with its previous window (in the same group). Similarly, press '.' to switch with the next window.
-rw-r--r--src/ChangeLog1
-rw-r--r--src/list_window.c48
-rw-r--r--src/process.c39
-rw-r--r--src/window.c56
-rw-r--r--src/window.h7
5 files changed, 112 insertions, 39 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index c5c2241..7565fae 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -57,6 +57,7 @@ Version 4.1.0 (??/??/20??):
* Press 'g' to toggle nestedness.
* Press 'a' to view all windows in the list.
* Press '/' to search in the list.
+ * Press ',' and '.' to re-order windows in the list.
Display List:
* Press 'd' to detach a display, 'D' to power-detach.
diff --git a/src/list_window.c b/src/list_window.c
index 66156d1..f637a7a 100644
--- a/src/list_window.c
+++ b/src/list_window.c
@@ -82,6 +82,8 @@ gl_Window_add_group(struct ListData *ldata, struct ListRow *row)
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);
@@ -95,7 +97,9 @@ gl_Window_add_group(struct ListData *ldata, struct ListRow *row)
if (!*w || (*w)->w_group != group)
continue;
- cur = glist_add_row(ldata, *w, 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);
@@ -339,6 +343,35 @@ gl_Window_input(struct ListData *ldata, char **inp, int *len)
}
break;
+ case ',': /* Switch numbers with the previous window. */
+ if (wdata->order == WLIST_NUM && ldata->selected->prev)
+ {
+ struct win *pw = ldata->selected->prev->data;
+ win = ldata->selected->data;
+ if (win->w_group != pw->w_group)
+ break; /* Do not allow switching with the parent group */
+
+ /* When a windows's number is successfully changed, it triggers a WListUpdatecv
+ * with NULL window. So that causes a redraw of the entire list. So reset the
+ * 'selected' after that. */
+ wdata->fore = win;
+ WindowChangeNumber(win, pw->w_number);
+ }
+ break;
+
+ case '.': /* Switch numbers with the next window. */
+ if (wdata->order == WLIST_NUM && ldata->selected->next)
+ {
+ struct win *nw = ldata->selected->next->data;
+ win = ldata->selected->data;
+ if (win->w_group != nw->w_group)
+ break; /* Do not allow switching with the parent group */
+
+ wdata->fore = win;
+ WindowChangeNumber(win, nw->w_number);
+ }
+ break;
+
case 033: /* escape */
case 007: /* ^G */
if (wdata->group)
@@ -474,7 +507,7 @@ WListUpdate(struct win *p, struct ListData *ldata)
struct gl_Window_Data *wdata = ldata->data;
struct ListRow *row, *rbefore;
struct win *before;
- int d = 0;
+ int d = 0, sel = 0;
if (!p)
{
@@ -546,12 +579,19 @@ WListUpdate(struct win *p, struct ListData *ldata)
if (row)
{
if (row->prev != rbefore)
- gl_Window_remove(ldata, p);
+ {
+ sel = ldata->selected->data == p;
+ gl_Window_remove(ldata, p);
+ }
else
p = NULL; /* the window is in the correct place */
}
if (p)
- glist_add_row(ldata, p, rbefore);
+ {
+ row = glist_add_row(ldata, p, rbefore);
+ if (sel)
+ ldata->selected = row;
+ }
glist_display_all(ldata);
}
diff --git a/src/process.c b/src/process.c
index add2c2a..137037d 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1,4 +1,7 @@
-/* Copyright (c) 2008, 2009
+/* Copyright (c) 2010
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 2008, 2009
* Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
* Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
* Micah Cowan (micah@cowan.name)
@@ -2982,42 +2985,12 @@ int key;
n += old;
else if (rel < 0)
n = old - n;
- if (n < 0 || n >= maxwin)
+ if (!WindowChangeNumber(fore, n))
{
- Msg(0, "Given window position is invalid.");
+ /* Window number could not be changed. */
queryflag = -1;
return;
}
- p = wtab[n];
- wtab[n] = fore;
- fore->w_number = n;
- wtab[old] = p;
- if (p)
- p->w_number = old;
-#ifdef MULTIUSER
- /* exchange the acls for these windows. */
- AclWinSwap(old, n);
-#endif
-#ifdef UTMPOK
- /* exchange the utmp-slots for these windows */
- if ((fore->w_slot != (slot_t) -1) && (fore->w_slot != (slot_t) 0))
- {
- RemoveUtmp(fore);
- SetUtmp(fore);
- }
- if (p && (p->w_slot != (slot_t) -1) && (p->w_slot != (slot_t) 0))
- {
- /* XXX: first display wins? */
- display = fore->w_layer.l_cvlist ? fore->w_layer.l_cvlist->c_display : 0;
- RemoveUtmp(p);
- SetUtmp(p);
- }
-#endif
-
- WindowChanged(fore, 'n');
- WindowChanged((struct win *)0, 'w');
- WindowChanged((struct win *)0, 'W');
- WindowChanged((struct win *)0, 0);
}
break;
case RC_SILENCE:
diff --git a/src/window.c b/src/window.c
index 20bceac..edf04dd 100644
--- a/src/window.c
+++ b/src/window.c
@@ -1,4 +1,7 @@
-/* Copyright (c) 2008, 2009
+/* Copyright (c) 2010
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 2008, 2009
* Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
* Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
* Micah Cowan (micah@cowan.name)
@@ -2261,3 +2264,54 @@ struct display *d;
}
#endif
+
+int
+WindowChangeNumber(struct win *win, int n)
+{
+ struct win *p;
+ int old = win->w_number;
+
+ if (n < 0 || n >= maxwin)
+ {
+ Msg(0, "Given window position is invalid.");
+ return 0;
+ }
+
+ p = wtab[n];
+ wtab[n] = win;
+ win->w_number = n;
+ wtab[old] = p;
+ if (p)
+ p->w_number = old;
+#ifdef MULTIUSER
+ /* exchange the acls for these windows. */
+ AclWinSwap(old, n);
+#endif
+#ifdef UTMPOK
+ /* exchange the utmp-slots for these windows */
+ if ((win->w_slot != (slot_t) -1) && (win->w_slot != (slot_t) 0))
+ {
+ RemoveUtmp(win);
+ SetUtmp(win);
+ }
+ if (p && (p->w_slot != (slot_t) -1) && (p->w_slot != (slot_t) 0))
+ {
+ /* XXX: first display wins? */
+#if 0
+ /* Does this make more sense? */
+ display = p->w_lastdisp ? p->w_lastdisp : p->w_layer.l_cvlist ? p->w_layer.l_cvlist->c_display : 0;
+#else
+ display = win->w_layer.l_cvlist ? win->w_layer.l_cvlist->c_display : 0;
+#endif
+ RemoveUtmp(p);
+ SetUtmp(p);
+ }
+#endif
+
+ WindowChanged(win, 'n');
+ WindowChanged((struct win *)0, 'w');
+ WindowChanged((struct win *)0, 'W');
+ WindowChanged((struct win *)0, 0);
+ return 1;
+}
+
diff --git a/src/window.h b/src/window.h
index cd6c7da..6bd8e2d 100644
--- a/src/window.h
+++ b/src/window.h
@@ -1,4 +1,7 @@
-/* Copyright (c) 2008, 2009
+/* Copyright (c) 2010
+ * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
+ * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
+ * Copyright (c) 2008, 2009
* Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
* Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
* Micah Cowan (micah@cowan.name)
@@ -334,5 +337,7 @@ struct win
#define Layer2Window(l) ((struct win *)(l)->l_bottom->l_data)
+int WindowChangeNumber __P((struct win *, int));
+
#endif /* SCREEN_WINDOW_H */