aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Kanakarakis <ivan.kanak@gmail.com>2012-01-06 00:34:23 +0200
committerIvan Kanakarakis <ivan.kanak@gmail.com>2012-01-06 00:36:02 +0200
commitbd981b3255b2f5d38dcfbf4cdc6bae2ae44f64ae (patch)
tree5fb1ecaf3ae135114e1adf72de34415a194a4a32
parentcfff297a82b5d515c668af9730daf71e0fcf4b04 (diff)
remember the last focused window - closes #3 and duplicate #5
-rw-r--r--monsterwm.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/monsterwm.c b/monsterwm.c
index 7e5c235..495b91b 100644
--- a/monsterwm.c
+++ b/monsterwm.c
@@ -44,6 +44,7 @@ typedef struct {
int growth;
client *head;
client *current;
+ client *prevfocus;
Bool showpanel;
} desktop;
@@ -119,8 +120,7 @@ static unsigned int win_unfocus;
static unsigned int numlockmask = 0; /* dynamic key lock mask */
static Display *dis;
static Window root;
-static client *head = NULL;
-static client *current = NULL;
+static client *head, *prevfocus, *current;
static Atom wmatoms[WM_COUNT], netatoms[NET_COUNT];
static desktop desktops[DESKTOPS];
@@ -150,6 +150,7 @@ void addwindow(Window w) {
head = c;
}
+ prevfocus = current;
XSelectInput(dis, ((current = c)->win = w), PropertyChangeMask);
if (FOLLOW_MOUSE) XSelectInput(dis, c->win, EnterWindowMask);
}
@@ -455,14 +456,14 @@ void move_up() {
void next_win() {
if (!current || !head->next) return;
- current = (current->next) ? current->next : head;
+ current = ((prevfocus = current)->next) ? current->next : head;
if (mode == MONOCLE) XMapWindow(dis, current->win);
update_current();
}
void prev_win() {
if (!current || !head->next) return;
- if (head == current) while (current->next) current=current->next;
+ if (head == (prevfocus = current)) while (current->next) current=current->next;
else for (client *t=head; t; t=t->next) if (t->next == current) { current = t; break; }
if (mode == MONOCLE) XMapWindow(dis, current->win);
update_current();
@@ -489,8 +490,9 @@ void removeclient(client *c) {
int nd = 0, cd = current_desktop;
for (Bool found = False; nd<DESKTOPS && !found; nd++)
for (select_desktop(nd), p = &head; *p && !(found = *p == c); p = &(*p)->next);
- current = (*p = c->next) ? *p : head;
+ *p = c->next;
free(c);
+ current = (prevfocus && prevfocus != current) ? prevfocus : (*p) ? (prevfocus = *p) : (prevfocus = head);
select_desktop(cd);
tile();
if (mode == MONOCLE && cd == --nd && current) XMapWindow(dis, current->win);
@@ -526,6 +528,7 @@ void save_desktop(int i) {
desktops[i].head = head;
desktops[i].current = current;
desktops[i].showpanel = showpanel;
+ desktops[i].prevfocus = prevfocus;
}
void select_desktop(int i) {
@@ -537,6 +540,7 @@ void select_desktop(int i) {
head = desktops[i].head;
current = desktops[i].current;
showpanel = desktops[i].showpanel;
+ prevfocus = desktops[i].prevfocus;
current_desktop = i;
}