From 9a6defe5d992f866f8a82f56ee21e7a3d2ca2a8d Mon Sep 17 00:00:00 2001 From: Sadrul Habib Chowdhury Date: Wed, 24 Feb 2010 09:20:02 -0500 Subject: Some more window-management from the window-list. Pressing 'K' in the window-list will kill a window (after confirmation). Also, added some notes. --- src/ChangeLog | 1 + src/list_window.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++------- 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) { -- cgit v1.2.1