diff --git a/client.c b/client.c index aa544ec..b0440f6 100644 --- a/client.c +++ b/client.c @@ -67,12 +67,20 @@ client_init(Window win, struct screen_ctx *sc) mapped = wattr.map_state != IsUnmapped; } - cc = xcalloc(1, sizeof(*cc)); + cc = xmalloc(sizeof(*cc)); XGrabServer(X_Dpy); cc->sc = sc; cc->win = win; + cc->label = NULL; + cc->gc = NULL; + cc->flags = 0; + cc->stackingorder = 0; + memset(&cc->hint, 0, sizeof(cc->hint)); + memset(&cc->ch, 0, sizeof(cc->ch)); + cc->ptr.x = -1; + cc->ptr.y = -1; TAILQ_INIT(&cc->nameq); client_setname(cc); @@ -85,10 +93,6 @@ client_init(Window win, struct screen_ctx *sc) client_getsizehints(cc); client_mwm_hints(cc); - /* Saved pointer position */ - cc->ptr.x = -1; - cc->ptr.y = -1; - cc->geom.x = wattr.x; cc->geom.y = wattr.y; cc->geom.w = wattr.width; @@ -173,12 +177,12 @@ client_delete(struct client_ctx *cc) xu_ewmh_net_client_list(sc); xu_ewmh_net_client_list_stacking(sc); + if (cc->flags & CLIENT_ACTIVE) + client_none(sc); + if (cc->gc != NULL) TAILQ_REMOVE(&cc->gc->clientq, cc, group_entry); - if (cc == client_current()) - client_none(sc); - while ((wn = TAILQ_FIRST(&cc->nameq)) != NULL) { TAILQ_REMOVE(&cc->nameq, wn, entry); free(wn->name); @@ -256,33 +260,21 @@ client_toggle_freeze(struct client_ctx *cc) if (cc->flags & CLIENT_FULLSCREEN) return; - if (cc->flags & CLIENT_FREEZE) - cc->flags &= ~CLIENT_FREEZE; - else - cc->flags |= CLIENT_FREEZE; - + cc->flags ^= CLIENT_FREEZE; xu_ewmh_set_net_wm_state(cc); } void client_toggle_hidden(struct client_ctx *cc) { - if (cc->flags & CLIENT_HIDDEN) - cc->flags &= ~CLIENT_HIDDEN; - else - cc->flags |= CLIENT_HIDDEN; - + cc->flags ^= CLIENT_HIDDEN; xu_ewmh_set_net_wm_state(cc); } void client_toggle_sticky(struct client_ctx *cc) { - if (cc->flags & CLIENT_STICKY) - cc->flags &= ~CLIENT_STICKY; - else - cc->flags |= CLIENT_STICKY; - + cc->flags ^= CLIENT_STICKY; xu_ewmh_set_net_wm_state(cc); } @@ -297,7 +289,8 @@ client_toggle_fullscreen(struct client_ctx *cc) return; if (cc->flags & CLIENT_FULLSCREEN) { - cc->bwidth = Conf.bwidth; + if (!(cc->flags & CLIENT_IGNORE)) + cc->bwidth = Conf.bwidth; cc->geom = cc->fullgeom; cc->flags &= ~(CLIENT_FULLSCREEN | CLIENT_FREEZE); goto resize; @@ -518,12 +511,12 @@ client_hide(struct client_ctx *cc) { XUnmapWindow(X_Dpy, cc->win); + if (cc->flags & CLIENT_ACTIVE) + client_none(cc->sc); + cc->flags &= ~CLIENT_ACTIVE; cc->flags |= CLIENT_HIDDEN; client_set_wm_state(cc, IconicState); - - if (cc == client_current()) - client_none(cc->sc); } void @@ -898,9 +891,6 @@ client_applysizehints(struct client_ctx *cc) if (cc->hint.maxh) cc->geom.h = MIN(cc->geom.h, cc->hint.maxh); - cc->geom.w = MAX(cc->geom.w, 1); - cc->geom.h = MAX(cc->geom.h, 1); - cc->dim.w = (cc->geom.w - cc->hint.basew) / cc->hint.incw; cc->dim.h = (cc->geom.h - cc->hint.baseh) / cc->hint.inch; } diff --git a/conf.c b/conf.c index 29e5577..24f1902 100644 --- a/conf.c +++ b/conf.c @@ -207,7 +207,7 @@ static const struct { { "CM-g", "grouptoggle" }, { "CM-f", "fullscreen" }, { "CM-m", "maximize" }, - { "CM-s", "sticky" }, + { "CM-s", "stick" }, { "CM-equal", "vmaximize" }, { "CMS-equal", "hmaximize" }, { "CMS-f", "freeze" }, @@ -408,7 +408,7 @@ static const struct { {.i = (CWM_CLIENT_RCYCLE | CWM_CLIENT_CYCLE_INGRP)} }, { "grouptoggle", kbfunc_client_grouptoggle, CWM_CONTEXT_CLIENT, {.i = CWM_KBD}}, - { "sticky", kbfunc_client_toggle_sticky, CWM_CONTEXT_CLIENT, {0} }, + { "stick", kbfunc_client_toggle_sticky, CWM_CONTEXT_CLIENT, {0} }, { "fullscreen", kbfunc_client_toggle_fullscreen, CWM_CONTEXT_CLIENT, {0} }, { "maximize", kbfunc_client_toggle_maximize, CWM_CONTEXT_CLIENT, {0} }, diff --git a/cwmrc.5 b/cwmrc.5 index ee8dd78..19a4152 100644 --- a/cwmrc.5 +++ b/cwmrc.5 @@ -301,7 +301,7 @@ Raise current window. Label current window. .It freeze Freeze current window geometry. -.It sticky +.It stick Stick current window to all groups (same as assigning to nogroup). .It fullscreen Full-screen current window (gap + border removed). diff --git a/group.c b/group.c index b5c1c34..69d4b92 100644 --- a/group.c +++ b/group.c @@ -209,19 +209,12 @@ int group_holds_only_hidden(struct group_ctx *gc) { struct client_ctx *cc; - int hidden = 0, same = 0; TAILQ_FOREACH(cc, &gc->clientq, group_entry) { - if (cc->flags & CLIENT_STICKY) - continue; - if (hidden == ((cc->flags & CLIENT_HIDDEN) ? 1 : 0)) - same++; + if (!(cc->flags & (CLIENT_HIDDEN | CLIENT_STICKY))) + return(0); } - - if (same == 0) - hidden = !hidden; - - return(hidden); + return(1); } void diff --git a/mousefunc.c b/mousefunc.c index 5be91bd..f55ebff 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -57,7 +57,6 @@ mousefunc_client_resize(struct client_ctx *cc, union arg *arg) XEvent ev; Time ltime = 0; struct screen_ctx *sc = cc->sc; - int x = cc->geom.x, y = cc->geom.y; if (cc->flags & CLIENT_FREEZE) return; @@ -81,12 +80,8 @@ mousefunc_client_resize(struct client_ctx *cc, union arg *arg) continue; ltime = ev.xmotion.time; - cc->geom.w = abs(x - ev.xmotion.x_root) - cc->bwidth; - cc->geom.h = abs(y - ev.xmotion.y_root) - cc->bwidth; - cc->geom.x = (x <= ev.xmotion.x_root) ? - x : x - cc->geom.w; - cc->geom.y = (y <= ev.xmotion.y_root) ? - y : y - cc->geom.h; + cc->geom.w = ev.xmotion.x; + cc->geom.h = ev.xmotion.y; client_applysizehints(cc); client_resize(cc, 1); mousefunc_sweep_draw(cc); diff --git a/search.c b/search.c index 60da260..6f826af 100644 --- a/search.c +++ b/search.c @@ -94,7 +94,7 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search) * window. Furthermore, this is denoted by a "!" when * printing the window name in the search menu. */ - if (cc == client_current() && tier < nitems(tierp) - 1) + if ((cc->flags & CLIENT_ACTIVE) && (tier < nitems(tierp) - 1)) tier++; /* Clients that are hidden get ranked one up. */ @@ -147,7 +147,7 @@ search_print_client(struct menu *mi, int list) struct client_ctx *cc = (struct client_ctx *)mi->ctx; char flag = ' '; - if (cc == client_current()) + if (cc->flags & CLIENT_ACTIVE) flag = '!'; else if (cc->flags & CLIENT_HIDDEN) flag = '&'; diff --git a/xevents.c b/xevents.c index 7fe0c43..2511205 100644 --- a/xevents.c +++ b/xevents.c @@ -250,10 +250,13 @@ xev_handle_buttonpress(XEvent *ee) static void xev_handle_buttonrelease(XEvent *ee) { - struct client_ctx *cc; + XButtonEvent *e = &ee->xbutton; + struct client_ctx *cc; - if ((cc = client_current()) != NULL) - group_toggle_membership_leave(cc); + if ((cc = client_find(e->window)) != NULL) { + if (cc->flags & CLIENT_ACTIVE) + group_toggle_membership_leave(cc); + } } static void