Remove extra work and simplify client state handling.

This commit is contained in:
okan 2013-12-11 14:16:09 +00:00
parent 23a1abdd8a
commit 0d9b1becff
4 changed files with 37 additions and 45 deletions

View File

@ -167,7 +167,6 @@ struct client_ctx {
#define CLIENT_MAXFLAGS (CLIENT_VMAXIMIZED | CLIENT_HMAXIMIZED)
#define CLIENT_MAXIMIZED (CLIENT_VMAXIMIZED | CLIENT_HMAXIMIZED)
int flags;
int state;
int active;
int stackingorder;
struct winname_q nameq;
@ -374,6 +373,7 @@ void client_delete(struct client_ctx *);
void client_draw_border(struct client_ctx *);
struct client_ctx *client_find(Window);
void client_freeze(struct client_ctx *);
long client_get_wm_state(struct client_ctx *);
void client_getsizehints(struct client_ctx *);
void client_hide(struct client_ctx *);
void client_hmaximize(struct client_ctx *);
@ -389,6 +389,7 @@ void client_ptrwarp(struct client_ctx *);
void client_raise(struct client_ctx *);
void client_resize(struct client_ctx *, int);
void client_send_delete(struct client_ctx *);
void client_set_wm_state(struct client_ctx *, long);
void client_setactive(struct client_ctx *);
void client_setname(struct client_ctx *);
int client_snapcalc(int, int, int, int, int);
@ -509,7 +510,6 @@ void xev_loop(void);
void xu_btn_grab(Window, int, u_int);
void xu_btn_ungrab(Window);
int xu_getprop(Window, Atom, Atom, long, unsigned char **);
int xu_get_wm_state(Window, int *);
int xu_getstrprop(Window, Atom, char **);
void xu_key_grab(Window, u_int, KeySym);
void xu_key_ungrab(Window);
@ -518,7 +518,6 @@ int xu_ptr_grab(Window, u_int, Cursor);
int xu_ptr_regrab(u_int, Cursor);
void xu_ptr_setpos(Window, int, int);
void xu_ptr_ungrab(void);
void xu_set_wm_state(Window win, int);
void xu_xft_draw(struct screen_ctx *, const char *,
int, int, int);
int xu_xft_width(XftFont *, const char *, int);

View File

@ -68,7 +68,6 @@ client_init(Window win, struct screen_ctx *sc, int mapped)
XGrabServer(X_Dpy);
cc->state = mapped ? NormalState : IconicState;
cc->sc = sc;
cc->win = win;
@ -103,16 +102,11 @@ client_init(Window win, struct screen_ctx *sc, int mapped)
if (wattr.map_state != IsViewable) {
client_placecalc(cc);
client_move(cc);
if ((cc->wmh) && (cc->wmh->flags & StateHint)) {
cc->state = cc->wmh->initial_state;
xu_set_wm_state(cc->win, cc->state);
}
if ((cc->wmh) && (cc->wmh->flags & StateHint))
client_set_wm_state(cc, cc->wmh->initial_state);
}
client_draw_border(cc);
if (xu_get_wm_state(cc->win, &state) < 0)
state = NormalState;
XSelectInput(X_Dpy, cc->win, ColormapChangeMask | EnterWindowMask |
PropertyChangeMask | KeyReleaseMask);
@ -123,6 +117,9 @@ client_init(Window win, struct screen_ctx *sc, int mapped)
/* Notify client of its configuration. */
client_config(cc);
if ((state = client_get_wm_state(cc)) < 0)
state = NormalState;
(state == IconicState) ? client_hide(cc) : client_unhide(cc);
TAILQ_INSERT_TAIL(&sc->mruq, cc, mru_entry);
@ -425,7 +422,10 @@ client_ptrwarp(struct client_ctx *cc)
y = cc->geom.h / 2;
}
(cc->state == IconicState) ? client_unhide(cc) : client_raise(cc);
if (cc->flags & CLIENT_HIDDEN)
client_unhide(cc);
else
client_raise(cc);
xu_ptr_setpos(cc->win, x, y);
}
@ -451,8 +451,7 @@ client_hide(struct client_ctx *cc)
cc->active = 0;
cc->flags |= CLIENT_HIDDEN;
cc->state = IconicState;
xu_set_wm_state(cc->win, cc->state);
client_set_wm_state(cc, IconicState);
if (cc == client_current())
client_none(cc->sc);
@ -464,8 +463,7 @@ client_unhide(struct client_ctx *cc)
XMapRaised(X_Dpy, cc->win);
cc->flags &= ~CLIENT_HIDDEN;
cc->state = NormalState;
xu_set_wm_state(cc->win, cc->state);
client_set_wm_state(cc, NormalState);
client_draw_border(cc);
}
@ -982,3 +980,26 @@ client_vtile(struct client_ctx *cc)
i++;
}
}
long
client_get_wm_state(struct client_ctx *cc)
{
long *p, state = -1;
if (xu_getprop(cc->win, cwmh[WM_STATE], cwmh[WM_STATE], 2L,
(unsigned char **)&p) > 0) {
state = *p;
XFree(p);
}
return(state);
}
void
client_set_wm_state(struct client_ctx *cc, long state)
{
long data[] = { state, None };
XChangeProperty(X_Dpy, cc->win, cwmh[WM_STATE], cwmh[WM_STATE], 32,
PropModeReplace, (unsigned char *)data, 2);
}

View File

@ -99,8 +99,7 @@ xev_handle_unmapnotify(XEvent *ee)
if ((cc = client_find(e->window)) != NULL) {
if (e->send_event) {
cc->state = WithdrawnState;
xu_set_wm_state(cc->win, cc->state);
client_set_wm_state(cc, WithdrawnState);
} else {
if (!(cc->flags & CLIENT_HIDDEN))
client_delete(cc);

27
xutil.c
View File

@ -157,33 +157,6 @@ xu_getstrprop(Window win, Atom atm, char **text) {
return (nitems);
}
int
xu_get_wm_state(Window win, int *state)
{
long *p = NULL;
if (xu_getprop(win, cwmh[WM_STATE], cwmh[WM_STATE], 2L,
(unsigned char **)&p) <= 0)
return (-1);
*state = (int)*p;
XFree((char *)p);
return (0);
}
void
xu_set_wm_state(Window win, int state)
{
long dat[2];
dat[0] = state;
dat[1] = None;
XChangeProperty(X_Dpy, win, cwmh[WM_STATE], cwmh[WM_STATE], 32,
PropModeReplace, (unsigned char *)dat, 2);
}
/* Root Window Properties */
void
xu_ewmh_net_supported(struct screen_ctx *sc)