Stash Class and WM Hints in client_ctx

This commit is contained in:
okan 2013-12-11 14:09:21 +00:00
parent 1d68f0683a
commit 23a1abdd8a
4 changed files with 23 additions and 28 deletions

View File

@ -177,8 +177,8 @@ struct client_ctx {
char *label; char *label;
char *matchname; char *matchname;
struct group_ctx *group; struct group_ctx *group;
char *app_class; XClassHint ch;
char *app_name; XWMHints *wmh;
}; };
TAILQ_HEAD(client_ctx_q, client_ctx); TAILQ_HEAD(client_ctx_q, client_ctx);
TAILQ_HEAD(cycle_entry_q, client_ctx); TAILQ_HEAD(cycle_entry_q, client_ctx);

View File

@ -58,9 +58,7 @@ struct client_ctx *
client_init(Window win, struct screen_ctx *sc, int mapped) client_init(Window win, struct screen_ctx *sc, int mapped)
{ {
struct client_ctx *cc; struct client_ctx *cc;
XClassHint xch;
XWindowAttributes wattr; XWindowAttributes wattr;
XWMHints *wmhints;
int state; int state;
if (win == None) if (win == None)
@ -74,18 +72,16 @@ client_init(Window win, struct screen_ctx *sc, int mapped)
cc->sc = sc; cc->sc = sc;
cc->win = win; cc->win = win;
client_getsizehints(cc);
TAILQ_INIT(&cc->nameq); TAILQ_INIT(&cc->nameq);
client_setname(cc); client_setname(cc);
conf_client(cc); conf_client(cc);
if (XGetClassHint(X_Dpy, cc->win, &xch)) { XGetClassHint(X_Dpy, cc->win, &cc->ch);
cc->app_name = xch.res_name; cc->wmh = XGetWMHints(X_Dpy, cc->win);
cc->app_class = xch.res_class;
}
client_getmwmhints(cc); client_getmwmhints(cc);
client_wm_protocols(cc);
client_getsizehints(cc);
/* Saved pointer position */ /* Saved pointer position */
cc->ptr.x = -1; cc->ptr.x = -1;
@ -98,22 +94,20 @@ client_init(Window win, struct screen_ctx *sc, int mapped)
cc->geom.h = wattr.height; cc->geom.h = wattr.height;
cc->colormap = wattr.colormap; cc->colormap = wattr.colormap;
if ((wmhints = XGetWMHints(X_Dpy, cc->win)) != NULL) { if (cc->wmh != NULL) {
if (wmhints->flags & InputHint) { if (cc->wmh->flags & InputHint) {
if (wmhints->input == 1) if (cc->wmh->input == 1)
cc->flags |= CLIENT_INPUT; cc->flags |= CLIENT_INPUT;
} }
} }
if (wattr.map_state != IsViewable) { if (wattr.map_state != IsViewable) {
client_placecalc(cc); client_placecalc(cc);
client_move(cc); client_move(cc);
if ((wmhints) && (wmhints->flags & StateHint)) { if ((cc->wmh) && (cc->wmh->flags & StateHint)) {
cc->state = wmhints->initial_state; cc->state = cc->wmh->initial_state;
xu_set_wm_state(cc->win, cc->state); xu_set_wm_state(cc->win, cc->state);
} }
} }
if (wmhints)
XFree(wmhints);
client_draw_border(cc); client_draw_border(cc);
if (xu_get_wm_state(cc->win, &state) < 0) if (xu_get_wm_state(cc->win, &state) < 0)
@ -136,7 +130,6 @@ client_init(Window win, struct screen_ctx *sc, int mapped)
xu_ewmh_net_client_list(sc); xu_ewmh_net_client_list(sc);
client_wm_protocols(cc);
xu_ewmh_restore_net_wm_state(cc); xu_ewmh_restore_net_wm_state(cc);
if (mapped) if (mapped)
@ -165,17 +158,19 @@ client_delete(struct client_ctx *cc)
if (cc == client_current()) if (cc == client_current())
client_none(sc); client_none(sc);
if (cc->app_name != NULL)
XFree(cc->app_name);
if (cc->app_class != NULL)
XFree(cc->app_class);
while ((wn = TAILQ_FIRST(&cc->nameq)) != NULL) { while ((wn = TAILQ_FIRST(&cc->nameq)) != NULL) {
TAILQ_REMOVE(&cc->nameq, wn, entry); TAILQ_REMOVE(&cc->nameq, wn, entry);
free(wn->name); free(wn->name);
free(wn); free(wn);
} }
if (cc->ch.res_class)
XFree(cc->ch.res_class);
if (cc->ch.res_name)
XFree(cc->ch.res_name);
if (cc->wmh)
XFree(cc->wmh);
free(cc); free(cc);
} }

View File

@ -371,7 +371,7 @@ group_autogroup(struct client_ctx *cc)
int no = -1, both_match = 0; int no = -1, both_match = 0;
long *grpno; long *grpno;
if (cc->app_class == NULL || cc->app_name == NULL) if (cc->ch.res_class == NULL || cc->ch.res_name == NULL)
return; return;
if (xu_getprop(cc->win, ewmh[_NET_WM_DESKTOP], if (xu_getprop(cc->win, ewmh[_NET_WM_DESKTOP],
@ -385,9 +385,9 @@ group_autogroup(struct client_ctx *cc)
XFree(grpno); XFree(grpno);
} else { } else {
TAILQ_FOREACH(aw, &Conf.autogroupq, entry) { TAILQ_FOREACH(aw, &Conf.autogroupq, entry) {
if (strcmp(aw->class, cc->app_class) == 0) { if (strcmp(aw->class, cc->ch.res_class) == 0) {
if ((aw->name != NULL) && if ((aw->name != NULL) &&
(strcmp(aw->name, cc->app_name) == 0)) { (strcmp(aw->name, cc->ch.res_name) == 0)) {
no = aw->num; no = aw->num;
both_match = 1; both_match = 1;
} else if (aw->name == NULL && !both_match) } else if (aw->name == NULL && !both_match)

View File

@ -85,8 +85,8 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search)
} }
/* Then if there is a match on the window class name. */ /* Then if there is a match on the window class name. */
if (tier < 0 && strsubmatch(search, cc->app_class, 0)) { if (tier < 0 && strsubmatch(search, cc->ch.res_class, 0)) {
cc->matchname = cc->app_class; cc->matchname = cc->ch.res_class;
tier = 3; tier = 3;
} }