aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorokan2013-12-11 14:16:09 +0000
committerokan2013-12-11 14:16:09 +0000
commitae879f5d1b4867c9ce186f50cbb3cacca3daa284 (patch)
tree47ab45ede914d9d41b59d597c2891bf38066ecc5
parentbca0ab294bb5e82fd02249f93c1f43ee6fd56934 (diff)
downloadcwm-ae879f5d1b4867c9ce186f50cbb3cacca3daa284.tar.gz
Remove extra work and simplify client state handling.
-rw-r--r--calmwm.h7
-rw-r--r--client.c49
-rw-r--r--xevents.c5
-rw-r--r--xutil.c29
4 files changed, 41 insertions, 49 deletions
diff --git a/calmwm.h b/calmwm.h
index 5eca289..10d47cc 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: calmwm.h,v 1.231 2013/12/11 14:09:21 okan Exp $
+ * $OpenBSD: calmwm.h,v 1.232 2013/12/11 14:16:09 okan Exp $
*/
#ifndef _CALMWM_H_
@@ -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);
diff --git a/client.c b/client.c
index 00be83f..43ac689 100644
--- a/client.c
+++ b/client.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: client.c,v 1.154 2013/12/11 14:09:21 okan Exp $
+ * $OpenBSD: client.c,v 1.155 2013/12/11 14:16:09 okan Exp $
*/
#include <sys/param.h>
@@ -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);
+}
+
diff --git a/xevents.c b/xevents.c
index 98de3f6..3fcde36 100644
--- a/xevents.c
+++ b/xevents.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: xevents.c,v 1.95 2013/12/02 14:30:12 okan Exp $
+ * $OpenBSD: xevents.c,v 1.96 2013/12/11 14:16:09 okan Exp $
*/
/*
@@ -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);
diff --git a/xutil.c b/xutil.c
index be5ec8f..439d7ae 100644
--- a/xutil.c
+++ b/xutil.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: xutil.c,v 1.78 2013/10/20 02:00:02 okan Exp $
+ * $OpenBSD: xutil.c,v 1.79 2013/12/11 14:16:10 okan Exp $
*/
#include <sys/param.h>
@@ -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)