From 643d2a6b265a9da288b562d0c64233cd2621a880 Mon Sep 17 00:00:00 2001 From: David Delassus Date: Fri, 4 May 2012 19:37:51 +0200 Subject: [PATCH] Manage _NET_WM_STATE_STICKY --- src/client.c | 23 ++++++++++++++++++++++- src/client.h | 1 + src/ewmh.c | 32 ++++++++++++++++++++++++++++++++ src/ewmh.h | 1 + src/layout.c | 2 +- src/wmfs.h | 1 + 6 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/client.c b/src/client.c index 39c9bc6..1ae6e72 100644 --- a/src/client.c +++ b/src/client.c @@ -972,12 +972,14 @@ client_new(Window w, XWindowAttributes *wa, bool scan) client_apply_rule(c); } + ewmh_manage_state_sticky(c); + /* * Conf option set per client, for possibility * to config only one client */ c->border = c->theme->client_border_width; - if(!(c->tbarw = c->theme->client_titlebar_width)) + if(!(c->tbarw = c->theme->client_titlebar_width) || (c->flags & CLIENT_STICKY)) c->tbarw = c->border; c->ncol = c->theme->client_n; @@ -1199,6 +1201,25 @@ client_moveresize(struct client *c, struct geo *g) client_configure(c); } +void +client_place_at_mouse(struct client *c) +{ + int x, y; + + Window w; + int d, u; + + XQueryPointer(W->dpy, W->root, &w, &w, &x, &y, &d, &d, (uint *)&u); + + if(x < c->screen->ugeo.x) + x = 0; + if(y < c->screen->ugeo.y) + y = 0; + + c->geo.x = ((x + c->geo.w) > c->screen->ugeo.w ? c->screen->ugeo.w - c->geo.w : x); + c->geo.y = ((y + c->geo.h) > c->screen->ugeo.h ? c->screen->ugeo.h - c->geo.h : y); +} + void client_maximize(struct client *c) { diff --git a/src/client.h b/src/client.h index 3783f80..0535aae 100644 --- a/src/client.h +++ b/src/client.h @@ -44,6 +44,7 @@ void client_geo_hints(struct geo *g, int *s); void client_get_sizeh(struct client *c); bool client_winsize(struct client *c, struct geo *geo); void client_moveresize(struct client *c, struct geo *g); +void client_place_at_mouse(struct client *c); void client_maximize(struct client *c); void client_fac_resize(struct client *c, enum position p, int fac); void client_fac_adjust(struct client *c); diff --git a/src/ewmh.c b/src/ewmh.c index e2472ea..417a09f 100644 --- a/src/ewmh.c +++ b/src/ewmh.c @@ -227,6 +227,38 @@ ewmh_manage_state(long data[], struct client *c) layout_fix_hole(c); } } + +} + +void +ewmh_manage_state_sticky(struct client *c) +{ + Atom *atom, rf; + int f; + unsigned long n, il, i; + unsigned char *data = NULL; + + if(XGetWindowProperty(W->dpy, c->win, W->net_atom[net_wm_state], 0L, 0x7FFFFFFFL, false, + XA_ATOM, &rf, &f, &n, &il, &data) == Success && n) + { + atom = (Atom*)data; + + for(i = 0; i < n; ++i) + { + /* manage _NET_WM_STATE_STICKY */ + if(atom[i] == W->net_atom[net_wm_state_sticky]) + { + c->flags |= CLIENT_STICKY; + c->flags |= CLIENT_FREE; + + client_place_at_mouse(c); + + break; + } + } + + XFree(data); + } } void diff --git a/src/ewmh.h b/src/ewmh.h index 28535fe..9f8c958 100644 --- a/src/ewmh.h +++ b/src/ewmh.h @@ -124,6 +124,7 @@ void ewmh_get_client_list(void); long ewmh_get_xembed_state(Window win); void ewmh_update_wmfs_props(void); void ewmh_manage_state(long data[], struct client *c); +void ewmh_manage_state_sticky(struct client *c); void ewmh_manage_window_type(struct client *c); bool ewmh_manage_window_type_desktop(Window win); diff --git a/src/layout.c b/src/layout.c index b73cea6..3d92dae 100644 --- a/src/layout.c +++ b/src/layout.c @@ -631,7 +631,7 @@ layout_client(struct client *c) return; } - if(c->flags & CLIENT_FREE) + if(c->flags & (CLIENT_FREE | CLIENT_STICKY)) { layout_split_arrange_closed(c); c->flags ^= CLIENT_TILED; diff --git a/src/wmfs.h b/src/wmfs.h index d754f78..6479387 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -217,6 +217,7 @@ struct client #define CLIENT_TILED 0x2000 #define CLIENT_MOUSE 0x4000 #define CLIENT_IGNORE_TAG 0x8000 +#define CLIENT_STICKY 0x10000 Flags flags; Window win, frame, tmp; SLIST_ENTRY(client) next; /* Global list */