summary refs log tree commit diff
path: root/xutil.c
diff options
context:
space:
mode:
authorokan <okan>2013-05-20 21:13:58 +0000
committerokan <okan>2013-05-20 21:13:58 +0000
commit284af4ca0c40d7a90ea0f574924abb707db7db05 (patch)
tree394987beec0e33829e05f8ba817d7923fc3f8ec3 /xutil.c
parent270df196ac17363536c44fe342b4e71e1c8450e3 (diff)
downloadcwm-284af4ca0c40d7a90ea0f574924abb707db7db05.tar.gz
cwm-284af4ca0c40d7a90ea0f574924abb707db7db05.tar.xz
cwm-284af4ca0c40d7a90ea0f574924abb707db7db05.zip
add support for _NET_WM_STATE_MAXIMIZED_{HORZ,VERT}; from Alexander Polakov.
while I'm unsure of the final look of _NET_WM_STATE, there's no reason
to delay this support.
Diffstat (limited to 'xutil.c')
-rw-r--r--xutil.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/xutil.c b/xutil.c
index d5055f2..95bb0d4 100644
--- a/xutil.c
+++ b/xutil.c
@@ -257,6 +257,9 @@ struct atom_ctx ewmh[EWMH_NITEMS] = {
 	{"_NET_WM_NAME",		None},
 	{"_NET_WM_DESKTOP",		None},
 	{"_NET_CLOSE_WINDOW",		None},
+	{"_NET_WM_STATE", 		None},
+	{"_NET_WM_STATE_MAXIMIZED_VERT",None},
+	{"_NET_WM_STATE_MAXIMIZED_HORZ",None},
 };
 
 void
@@ -420,6 +423,64 @@ xu_ewmh_net_wm_desktop(struct client_ctx *cc)
 	    XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&no, 1);
 }
 
+Atom *
+xu_ewmh_get_net_wm_state(struct client_ctx *cc, int *n)
+{
+	Atom	*state, *p = NULL;
+
+	if ((*n = xu_getprop(cc->win, ewmh[_NET_WM_STATE].atom, XA_ATOM, 64L,
+	    (u_char **)&p)) <= 0)
+		return (NULL);
+
+	state = xmalloc(*n * sizeof(Atom));
+	memcpy(state, p, *n * sizeof(Atom));
+	XFree((char *)p);
+
+	return (state);
+}
+
+void
+xu_ewmh_restore_net_wm_state(struct client_ctx *cc)
+{
+	Atom	*atoms;
+	int	 i, n;
+
+	atoms = xu_ewmh_get_net_wm_state(cc, &n);
+	for (i = 0; i < n; i++) {
+		if (atoms[i] == ewmh[_NET_WM_STATE_MAXIMIZED_HORZ].atom)
+			client_hmaximize(cc);
+		if (atoms[i] == ewmh[_NET_WM_STATE_MAXIMIZED_VERT].atom)
+			client_vmaximize(cc);
+	}
+	free(atoms);
+}
+
+void
+xu_ewmh_set_net_wm_state(struct client_ctx *cc)
+{
+	Atom	*atoms, *oatoms;
+	int	 n, i, j;
+
+	oatoms = xu_ewmh_get_net_wm_state(cc, &n);
+	atoms = xmalloc((n + _NET_WM_STATES_NITEMS) * sizeof(Atom));
+	for (i = j = 0; i < n; i++) {
+		if (oatoms[i] != ewmh[_NET_WM_STATE_MAXIMIZED_HORZ].atom &&
+		    oatoms[i] != ewmh[_NET_WM_STATE_MAXIMIZED_VERT].atom)
+			atoms[j++] = oatoms[i];
+	}
+	free(oatoms);
+	if (cc->flags & CLIENT_HMAXIMIZED)
+		atoms[j++] = ewmh[_NET_WM_STATE_MAXIMIZED_HORZ].atom;
+	if (cc->flags & CLIENT_VMAXIMIZED)
+		atoms[j++] = ewmh[_NET_WM_STATE_MAXIMIZED_VERT].atom;
+	if (j > 0)
+		XChangeProperty(X_Dpy, cc->win, ewmh[_NET_WM_STATE].atom,
+		    XA_ATOM, 32, PropModeReplace, (unsigned char *)atoms, j);
+	else
+		XDeleteProperty(X_Dpy, cc->win, ewmh[_NET_WM_STATE].atom);
+	free(atoms);
+}
+
 void
 xu_xorcolor(XftColor a, XftColor b, XftColor *r)
 {