[hackers] [tabbed] autofocus urgent tabs || Jonas Rabenstein

From: <git_AT_suckless.org>
Date: Fri, 1 Jan 2016 14:19:29 +0100 (CET)

commit 9d4b71ecadd5b3c2c777b273fa4d2c0cc0c3a464
Author: Jonas Rabenstein <jonas.rabenstein_AT_studium.uni-erlangen.de>
AuthorDate: Wed Aug 19 21:11:16 2015 +0200
Commit: Christoph Lohmann <20h_AT_r-36.net>
CommitDate: Wed Aug 19 21:17:37 2015 +0200

    autofocus urgent tabs
    
    When tabbed becomes urgent because one of it tabs becomes urgent, it
    may be desireable to automatically focus that tab. As a notification may
    be lost, if another notification comes in before you focused tabbed, the
    switch is only done, if tabbed is not urgent already.
    Moreover, it may be anoying, if you just type into one tab, another tab
    gets urgent -therfore focused- and you type into the other tab, you may
    switch between autofocus and nofocus using Ctrl-Shift-u.
    Maybe it would also be usefull, if there would be an commandline
    parameter to toggle that option, but as -u is already used for
    urgent-tab-color, i did not implement that.
    
    Signed-off-by: Jonas Rabenstein <jonas.rabenstein_AT_studium.uni-erlangen.de>
    Signed-off-by: Christoph Lohmann <20h_AT_r-36.net>

diff --git a/config.def.h b/config.def.h
index 55bec4c..41f39c3 100644
--- a/config.def.h
+++ b/config.def.h
_AT_@ -12,6 +12,7 @@ static const char before[] = "<";
 static const char after[] = ">";
 static const int tabwidth = 200;
 static const Bool foreground = True;
+static Bool urgentswitch = False;
 
 /*
  * Where to place a new tab when it is opened. When npisrelative is True,
_AT_@ -56,6 +57,7 @@ static Key keys[] = { \
         { MODKEY, XK_q, killclient, { 0 } },
 
         { MODKEY, XK_u, focusurgent, { .v = NULL } },
+ { MODKEY|ShiftMask, XK_u, toggle, { .v = (void*) &urgentswitch } },
 
         { 0, XK_F11, fullscreen, { 0 } },
 };
diff --git a/tabbed.1 b/tabbed.1
index 05ac355..593847e 100644
--- a/tabbed.1
+++ b/tabbed.1
_AT_@ -124,6 +124,9 @@ move selected tab one to the left
 .B Ctrl\-Shift\-k
 move selected tab one to the right
 .TP
+.B Ctrl\-Shift\-u
+toggle autofocus of urgent tabs
+.TP
 .B Ctrl\-Tab
 toggle between the selected and last selected tab
 .TP
diff --git a/tabbed.c b/tabbed.c
index 93c9d0f..ba69f21 100644
--- a/tabbed.c
+++ b/tabbed.c
_AT_@ -129,6 +129,7 @@ static void setcmd(int argc, char *argv[], int);
 static void sigchld(int unused);
 static void spawn(const Arg *arg);
 static int textnw(const char *text, unsigned int len);
+static void toggle(const Arg *arg);
 static void unmanage(int c);
 static void updatenumlockmask(void);
 static void updatetitle(int c);
_AT_@ -837,12 +838,21 @@ propertynotify(const XEvent *e) {
                         && (c = getclient(ev->window)) > -1
                         && (wmh = XGetWMHints(dpy, clients[c]->win))) {
                 if(wmh->flags & XUrgencyHint) {
+ XFree(wmh);
+ wmh = XGetWMHints(dpy, win);
                         if(c != sel) {
- clients[c]->urgent = True;
- drawbar();
+ if(urgentswitch && wmh && !(wmh->flags & XUrgencyHint)) {
+ /* only switch, if tabbed was focused since last urgency hint
+ * if WMHints could not be received, default to no switch */
+ focus(c);
+ } else {
+ /* if no switch should be performed, mark tab as urgent */
+ clients[c]->urgent = True;
+ drawbar();
+ }
                         }
- XFree(wmh);
- if((wmh = XGetWMHints(dpy, win))) {
+ if(wmh && !(wmh->flags & XUrgencyHint)) {
+ /* update tabbed urgency hint if not set already */
                                 wmh->flags |= XUrgencyHint;
                                 XSetWMHints(dpy, win, wmh);
                         }
_AT_@ -1094,6 +1104,11 @@ textnw(const char *text, unsigned int len) {
 }
 
 void
+toggle(const Arg *arg) {
+ *(Bool*) arg->v = !*(Bool*) arg->v;
+}
+
+void
 unmanage(int c) {
         if(c < 0 || c >= nclients) {
                 drawbar();
Received on Fri Jan 01 2016 - 14:19:29 CET

This archive was generated by hypermail 2.3.0 : Fri Jan 01 2016 - 14:24:21 CET