From 1d68a42ec0cb5b5219a1695572faa2b7d344ff99 Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 13 Dec 2013 14:40:52 +0000 Subject: [PATCH] Add support for XUrgency and matching _NET_WM_STATE_DEMANDS_ATTENTION ewmh hint; urgencyborder is configurable. The urgency flag will stick, even while on a client in a non-viewable group, until the client receives focus (where the border is reset). Initial diff from Thomas Adam with some changes/enhancements from me. --- app/cwm/calmwm.h | 8 ++++++-- app/cwm/client.c | 15 ++++++++++++++- app/cwm/conf.c | 4 +++- app/cwm/cwmrc.5 | 7 +++++-- app/cwm/parse.y | 9 +++++++-- app/cwm/xevents.c | 3 ++- app/cwm/xutil.c | 12 ++++++++++-- 7 files changed, 47 insertions(+), 11 deletions(-) diff --git a/app/cwm/calmwm.h b/app/cwm/calmwm.h index c4790778c..780fa1a5e 100644 --- a/app/cwm/calmwm.h +++ b/app/cwm/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.234 2013/12/12 20:15:07 okan Exp $ + * $OpenBSD: calmwm.h,v 1.235 2013/12/13 14:40:52 okan Exp $ */ #ifndef _CALMWM_H_ @@ -97,6 +97,7 @@ enum cursor_font { enum color { CWM_COLOR_BORDER_ACTIVE, CWM_COLOR_BORDER_INACTIVE, + CWM_COLOR_BORDER_URGENCY, CWM_COLOR_BORDER_GROUP, CWM_COLOR_BORDER_UNGROUP, CWM_COLOR_MENU_FG, @@ -162,6 +163,7 @@ struct client_ctx { #define CLIENT_INPUT 0x0080 #define CLIENT_WM_DELETE_WINDOW 0x0100 #define CLIENT_WM_TAKE_FOCUS 0x0200 +#define CLIENT_URGENCY 0x0400 #define CLIENT_HIGHLIGHT (CLIENT_GROUP | CLIENT_UNGROUP) #define CLIENT_MAXFLAGS (CLIENT_VMAXIMIZED | CLIENT_HMAXIMIZED) @@ -350,9 +352,10 @@ enum { _NET_WM_DESKTOP, _NET_CLOSE_WINDOW, _NET_WM_STATE, -#define _NET_WM_STATES_NITEMS 2 +#define _NET_WM_STATES_NITEMS 3 _NET_WM_STATE_MAXIMIZED_VERT, _NET_WM_STATE_MAXIMIZED_HORZ, + _NET_WM_STATE_DEMANDS_ATTENTION, EWMH_NITEMS }; enum { @@ -396,6 +399,7 @@ void client_setname(struct client_ctx *); int client_snapcalc(int, int, int, int, int); void client_transient(struct client_ctx *); void client_unhide(struct client_ctx *); +void client_urgency(struct client_ctx *); void client_vmaximize(struct client_ctx *); void client_vtile(struct client_ctx *); void client_warp(struct client_ctx *); diff --git a/app/cwm/client.c b/app/cwm/client.c index 5a0005fba..92c52f195 100644 --- a/app/cwm/client.c +++ b/app/cwm/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.160 2013/12/12 20:15:07 okan Exp $ + * $OpenBSD: client.c,v 1.161 2013/12/13 14:40:52 okan Exp $ */ #include @@ -192,6 +192,7 @@ client_setactive(struct client_ctx *cc) _curcc = cc; cc->active = 1; + cc->flags &= ~CLIENT_URGENCY; client_draw_border(cc); conf_grab_mouse(cc->win); xu_ewmh_net_active_window(sc, cc->win); @@ -461,6 +462,12 @@ client_unhide(struct client_ctx *cc) client_draw_border(cc); } +void +client_urgency(struct client_ctx *cc) +{ + cc->flags |= CLIENT_URGENCY; +} + void client_draw_border(struct client_ctx *cc) { @@ -482,6 +489,9 @@ client_draw_border(struct client_ctx *cc) else pixel = sc->xftcolor[CWM_COLOR_BORDER_INACTIVE].pixel; + if (cc->flags & CLIENT_URGENCY) + pixel = sc->xftcolor[CWM_COLOR_BORDER_URGENCY].pixel; + XSetWindowBorderWidth(X_Dpy, cc->win, cc->bwidth); XSetWindowBorder(X_Dpy, cc->win, pixel); } @@ -511,6 +521,9 @@ client_wm_hints(struct client_ctx *cc) if ((cc->wmh->flags & InputHint) && (cc->wmh->input)) cc->flags |= CLIENT_INPUT; + + if ((cc->wmh->flags & XUrgencyHint)) + client_urgency(cc); } void diff --git a/app/cwm/conf.c b/app/cwm/conf.c index 15375c841..feaafa887 100644 --- a/app/cwm/conf.c +++ b/app/cwm/conf.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: conf.c,v 1.150 2013/11/27 18:34:34 okan Exp $ + * $OpenBSD: conf.c,v 1.151 2013/12/13 14:40:52 okan Exp $ */ #include @@ -88,6 +88,7 @@ conf_ignore(struct conf *c, char *val) static char *color_binds[] = { "#CCCCCC", /* CWM_COLOR_BORDER_ACTIVE */ "#666666", /* CWM_COLOR_BORDER_INACTIVE */ + "#FC8814", /* CWM_COLOR_BORDER_URGENCY */ "blue", /* CWM_COLOR_BORDER_GROUP */ "red", /* CWM_COLOR_BORDER_UNGROUP */ "black", /* CWM_COLOR_MENU_FG */ @@ -687,6 +688,7 @@ static char *ewmhints[] = { "_NET_WM_STATE", "_NET_WM_STATE_MAXIMIZED_VERT", "_NET_WM_STATE_MAXIMIZED_HORZ", + "_NET_WM_STATE_DEMANDS_ATTENTION", }; void diff --git a/app/cwm/cwmrc.5 b/app/cwm/cwmrc.5 index cf9103266..24f4ab058 100644 --- a/app/cwm/cwmrc.5 +++ b/app/cwm/cwmrc.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: cwmrc.5,v 1.55 2013/11/27 16:24:17 okan Exp $ +.\" $OpenBSD: cwmrc.5,v 1.56 2013/12/13 14:40:52 okan Exp $ .\" .\" Copyright (c) 2004,2005 Marius Aamodt Eriksen .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: November 27 2013 $ +.Dd $Mdocdate: December 13 2013 $ .Dt CWMRC 5 .Os .Sh NAME @@ -125,6 +125,9 @@ Set menu background color. .It Ic color menufg Ar color Set menu foreground color. .Pp +.It Ic color urgencyborder Ar color +Set the color of the border of a window indicating urgency. +.Pp .It Ic color ungroupborder Ar color Set the color of the border while ungrouping a window. .Pp diff --git a/app/cwm/parse.y b/app/cwm/parse.y index 52e4466a9..c1137443a 100644 --- a/app/cwm/parse.y +++ b/app/cwm/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.48 2013/11/25 18:21:55 benno Exp $ */ +/* $OpenBSD: parse.y,v 1.49 2013/12/13 14:40:52 okan Exp $ */ /* * Copyright (c) 2002, 2003, 2004 Henning Brauer @@ -70,7 +70,7 @@ typedef struct { %token AUTOGROUP BIND COMMAND IGNORE %token YES NO BORDERWIDTH MOVEAMOUNT %token COLOR SNAPDIST -%token ACTIVEBORDER INACTIVEBORDER +%token ACTIVEBORDER INACTIVEBORDER URGENCYBORDER %token GROUPBORDER UNGROUPBORDER %token MENUBG MENUFG %token FONTCOLOR FONTSELCOLOR @@ -193,6 +193,10 @@ colors : ACTIVEBORDER STRING { free(conf->color[CWM_COLOR_BORDER_INACTIVE]); conf->color[CWM_COLOR_BORDER_INACTIVE] = $2; } + | URGENCYBORDER STRING { + free(conf->color[CWM_COLOR_BORDER_URGENCY]); + conf->color[CWM_COLOR_BORDER_URGENCY] = $2; + } | GROUPBORDER STRING { free(conf->color[CWM_COLOR_BORDER_GROUP]); conf->color[CWM_COLOR_BORDER_GROUP] = $2; @@ -271,6 +275,7 @@ lookup(char *s) { "snapdist", SNAPDIST}, { "sticky", STICKY}, { "ungroupborder", UNGROUPBORDER}, + { "urgencyborder", URGENCYBORDER}, { "yes", YES} }; const struct keywords *p; diff --git a/app/cwm/xevents.c b/app/cwm/xevents.c index e933ebbed..8459e69ad 100644 --- a/app/cwm/xevents.c +++ b/app/cwm/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.98 2013/12/12 20:15:07 okan Exp $ + * $OpenBSD: xevents.c,v 1.99 2013/12/13 14:40:52 okan Exp $ */ /* @@ -188,6 +188,7 @@ xev_handle_propertynotify(XEvent *ee) break; case XA_WM_HINTS: client_wm_hints(cc); + client_draw_border(cc); break; case XA_WM_TRANSIENT_FOR: client_transient(cc); diff --git a/app/cwm/xutil.c b/app/cwm/xutil.c index 439d7aec0..303346349 100644 --- a/app/cwm/xutil.c +++ b/app/cwm/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.79 2013/12/11 14:16:10 okan Exp $ + * $OpenBSD: xutil.c,v 1.80 2013/12/13 14:40:52 okan Exp $ */ #include @@ -333,6 +333,9 @@ xu_ewmh_handle_net_wm_state_msg(struct client_ctx *cc, int action, { _NET_WM_STATE_MAXIMIZED_HORZ, CLIENT_HMAXIMIZED, client_hmaximize }, + { _NET_WM_STATE_DEMANDS_ATTENTION, + CLIENT_URGENCY, + client_urgency }, }; for (i = 0; i < nitems(handlers); i++) { @@ -366,6 +369,8 @@ xu_ewmh_restore_net_wm_state(struct client_ctx *cc) client_hmaximize(cc); if (atoms[i] == ewmh[_NET_WM_STATE_MAXIMIZED_VERT]) client_vmaximize(cc); + if (atoms[i] == ewmh[_NET_WM_STATE_DEMANDS_ATTENTION]) + client_urgency(cc); } free(atoms); } @@ -380,7 +385,8 @@ xu_ewmh_set_net_wm_state(struct client_ctx *cc) atoms = xcalloc((n + _NET_WM_STATES_NITEMS), sizeof(Atom)); for (i = j = 0; i < n; i++) { if (oatoms[i] != ewmh[_NET_WM_STATE_MAXIMIZED_HORZ] && - oatoms[i] != ewmh[_NET_WM_STATE_MAXIMIZED_VERT]) + oatoms[i] != ewmh[_NET_WM_STATE_MAXIMIZED_VERT] && + oatoms[i] != ewmh[_NET_WM_STATE_DEMANDS_ATTENTION]) atoms[j++] = oatoms[i]; } free(oatoms); @@ -388,6 +394,8 @@ xu_ewmh_set_net_wm_state(struct client_ctx *cc) atoms[j++] = ewmh[_NET_WM_STATE_MAXIMIZED_HORZ]; if (cc->flags & CLIENT_VMAXIMIZED) atoms[j++] = ewmh[_NET_WM_STATE_MAXIMIZED_VERT]; + if (cc->flags & CLIENT_URGENCY) + atoms[j++] = ewmh[_NET_WM_STATE_DEMANDS_ATTENTION]; if (j > 0) XChangeProperty(X_Dpy, cc->win, ewmh[_NET_WM_STATE], XA_ATOM, 32, PropModeReplace, (unsigned char *)atoms, j);