summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSadrul Habib Chowdhury <sadrul@users.sourceforge.net>2010-02-24 09:20:02 -0500
committerSadrul Habib Chowdhury <sadrul@users.sourceforge.net>2010-02-24 09:20:02 -0500
commit9a6defe5d992f866f8a82f56ee21e7a3d2ca2a8d (patch)
tree536e36e9ca8002728285424d355b55a7dfc97963
parentd1d0cc4d63eed5234f55aa0228196815f9969ae0 (diff)
downloadscreen-9a6defe5d992f866f8a82f56ee21e7a3d2ca2a8d.tar.gz
Some more window-management from the window-list.
Pressing 'K' in the window-list will kill a window (after confirmation). Also, added some notes.
-rw-r--r--src/ChangeLog1
-rw-r--r--src/list_window.c56
2 files changed, 50 insertions, 7 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 7565fae..c02d5cc 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -58,6 +58,7 @@ Version 4.1.0 (??/??/20??):
* Press 'a' to view all windows in the list.
* Press '/' to search in the list.
* Press ',' and '.' to re-order windows in the list.
+ * Press 'K' to kill a window (requires confirmation).
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 f637a7a..f6f058a 100644
--- a/src/list_window.c
+++ b/src/list_window.c
@@ -22,6 +22,11 @@
/* Deals with the list of windows */
+/* NOTE: A 'struct win *' is used as the 'data' for each row. It might make more sense
+ * to use 'struct win* ->w_number' as the 'data', instead, because that way, we can
+ * verify that the window does exist (by looking at wtab[]).
+ */
+
#include "config.h"
#include "screen.h"
#include "layer.h"
@@ -37,9 +42,11 @@ extern char *wliststr;
extern struct mchar mchar_blank, mchar_so;
extern int renditions[];
-extern struct win **wtab, *windows;
+extern struct win **wtab, *windows, *fore;
extern int maxwin;
+extern char *noargs[];
+
static char ListID[] = "window";
struct gl_Window_Data
@@ -63,6 +70,35 @@ window_ancestor(struct win *a, struct win *d)
return 0;
}
+static void
+window_kill_confirm(char *buf, int len, char *data)
+{
+ struct win *w = windows;
+ struct action act;
+
+ if (len || (*buf != 'y' && *buf != 'Y'))
+ {
+ *buf = 0;
+ return;
+ }
+
+ /* Loop over the windows to make sure that the window actually still exists. */
+ for (; w; w = w->w_next)
+ if (w == (struct win *)data)
+ break;
+
+ if (!w)
+ return;
+
+ /* Pretend the selected window is the foreground window. Then trigger a non-interactive 'kill' */
+ fore = w;
+ act.nr = RC_KILL;
+ act.args = noargs;
+ act.argl = 0;
+ act.quiet = 0;
+ DoAction(&act, -1);
+}
+
static struct ListRow *
gl_Window_add_group(struct ListData *ldata, struct ListRow *row)
{
@@ -263,12 +299,12 @@ gl_Window_input(struct ListData *ldata, char **inp, int *len)
++*inp;
--*len;
+ win = ldata->selected->data;
switch (ch)
{
case ' ':
case '\n':
case '\r':
- win = ldata->selected->data;
if (!win)
break;
#ifdef MULTIUSER
@@ -347,7 +383,6 @@ gl_Window_input(struct ListData *ldata, char **inp, int *len)
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 */
@@ -363,7 +398,6 @@ gl_Window_input(struct ListData *ldata, char **inp, int *len)
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 */
@@ -372,6 +406,15 @@ gl_Window_input(struct ListData *ldata, char **inp, int *len)
}
break;
+ case 'K': /* Kill a window */
+ {
+ char str[MAXSTR];
+ snprintf(str, sizeof(str) - 1, "Really kill window %d (%s) [y/n]",
+ win->w_number, win->w_title);
+ Input(str, 1, INP_RAW, window_kill_confirm, (char *)win, 0);
+ }
+ break;
+
case 033: /* escape */
case 007: /* ^G */
if (wdata->group)
@@ -430,7 +473,8 @@ void
display_windows(int onblank, int order, struct win *group)
{
struct win *p;
- struct wlistdata *wlistdata;
+ struct ListData *ldata;
+ struct gl_Window_Data *wdata;
if (flayer->l_width < 10 || flayer->l_height < 6)
{
@@ -471,8 +515,6 @@ display_windows(int onblank, int order, struct win *group)
if (!group && p)
group = p->w_group;
- struct ListData *ldata;
- struct gl_Window_Data *wdata;
ldata = glist_display(&gl_Window, ListID);
if (!ldata)
{