Set back previous session tag at reload

This commit is contained in:
Martin Duquesnoy 2011-11-03 13:03:20 +01:00
parent 3d2b04ba6b
commit 2504dbe4ee
5 changed files with 63 additions and 13 deletions

View File

@ -104,3 +104,26 @@ ewmh_set_wm_state(Window w, int state)
W->net_atom[wm_state], 32, PropModeReplace, d, 2);
}
void
ewmh_update_wmfs_props(void)
{
struct screen *s;
int n = 0;
unsigned char *cts = NULL;
SLIST_FOREACH(s, &W->h.screen, next)
++n;
cts = xcalloc(n, sizeof(char));
n = 0;
SLIST_FOREACH(s, &W->h.screen, next)
cts[n++] = s->seltag->id;
XChangeProperty(W->dpy, W->root, W->net_atom[wmfs_current_tag], XA_CARDINAL, 32,
PropModeReplace, (unsigned char*)cts, n);
free(cts);
}

View File

@ -70,5 +70,6 @@ enum
void ewmh_init(void);
void ewmh_set_wm_state(Window w, int state);
void ewmh_update_wmfs_props(void);
#endif /* EWMH_H */

View File

@ -68,6 +68,8 @@ tag_screen(struct screen *s, struct tag *t)
s->seltag = t;
infobar_elem_screen_update(s, ElemTag);
ewmh_update_wmfs_props();
}
/* Set t to NULL to untag c from c->tag */

View File

@ -8,6 +8,19 @@
#include "wmfs.h"
static inline struct tag*
tag_gb_id(struct screen *s, int id)
{
struct tag *t;
TAILQ_FOREACH(t, &s->tags, next)
if(t->id == id)
return t;
return TAILQ_FIRST(&s->tags);
}
struct tag *tag_new(struct screen *s, char *name);
void tag_screen(struct screen *s, struct tag *t);
void tag_client(struct tag *t, struct client *c);

View File

@ -175,8 +175,8 @@ wmfs_grab_keys(void)
}
}
/** Scan if there are windows on X
* for manage it
/** Scan xprops of previous session to set it back
* Check if there are windows on X (previous sessions windows)
*/
static void
wmfs_scan(void)
@ -184,7 +184,6 @@ wmfs_scan(void)
struct geo g;
struct tag *t;
struct client *c;
struct screen *s;
int i, n, rf;
int tag = -1, screen = -1, flags = -1;
unsigned long ir, il;
@ -195,6 +194,21 @@ wmfs_scan(void)
SLIST_INIT(&W->h.client);
/* Set back selected tag */
if(XGetWindowProperty(W->dpy, W->root, W->net_atom[wmfs_current_tag], 0, 32,
False, XA_CARDINAL, &rt, &rf, &ir, &il,
(unsigned char**)&ret)
== Success && ret)
{
struct screen *s;
for(i = 0; i < (int)ir; ++i)
{
s = screen_gb_id(i);
tag_screen(s, tag_gb_id(s, ret[i]));
}
}
if(XQueryTree(W->dpy, W->root, &usl, &usl2, &w, (unsigned int*)&n))
for(i = n - 1; i != -1; --i)
{
@ -243,22 +257,17 @@ wmfs_scan(void)
}
c = client_new(w[i], &wa, true);
if(flags != -1)
c->flags = flags;
if(tag != -1 && screen != -1)
{
c->screen = screen_gb_id(screen);
TAILQ_FOREACH(t, &c->screen->tags, next)
if(t->id == tag)
{
c->flags |= CLIENT_IGNORE_LAYOUT;
tag_client(t, c);
client_moveresize(c, &g);
client_get_name(c);
break;
}
c->flags |= CLIENT_IGNORE_LAYOUT;
tag_client(tag_gb_id(c->screen, tag), c);
client_moveresize(c, &g);
client_get_name(c);
}
}
}
@ -325,6 +334,8 @@ wmfs_quit(void)
* Screens -> tags
* -> Infobars -> Elements
*/
ewmh_update_wmfs_props();
screen_free();
XFreeGC(W->dpy, W->rgc);