sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

tabbed-basenames-0.7.diff (2704B)


      1 From a682145f0daf599b6d2f6c1326f064ec67b30f73 Mon Sep 17 00:00:00 2001
      2 From: Jacob Fong <jacobcfong@gmail.com>
      3 Date: Mon, 5 Jun 2023 15:57:54 -0700
      4 Subject: [PATCH] Added `-b` to display only basenames of tab titles.
      5 
      6 ---
      7  tabbed.1 |  3 +++
      8  tabbed.c | 24 ++++++++++++++++++++++--
      9  2 files changed, 25 insertions(+), 2 deletions(-)
     10 
     11 diff --git a/tabbed.1 b/tabbed.1
     12 index 07bdbd7..4a9c110 100644
     13 --- a/tabbed.1
     14 +++ b/tabbed.1
     15 @@ -106,6 +106,9 @@ defines the urgent background color.
     16  .BI \-U " urgfgbcol"
     17  defines the urgent foreground color.
     18  .TP
     19 +.BI \-b
     20 +print only basenames of tab titles.
     21 +.TP
     22  .B \-v
     23  prints version information to stderr, then exits.
     24  .SH USAGE
     25 diff --git a/tabbed.c b/tabbed.c
     26 index eafe28a..03b0c8c 100644
     27 --- a/tabbed.c
     28 +++ b/tabbed.c
     29 @@ -80,6 +80,7 @@ typedef struct {
     30  
     31  typedef struct {
     32  	char name[256];
     33 +	char *basename;
     34  	Window win;
     35  	int tabx;
     36  	Bool urgent;
     37 @@ -106,6 +107,7 @@ static void focusonce(const Arg *arg);
     38  static void focusurgent(const Arg *arg);
     39  static void fullscreen(const Arg *arg);
     40  static char *getatom(int a);
     41 +static char *getbasename(const char *name);
     42  static int getclient(Window w);
     43  static XftColor getcolor(const char *colstr);
     44  static int getfirsttab(void);
     45 @@ -156,7 +158,7 @@ static int bh, obh, wx, wy, ww, wh;
     46  static unsigned int numlockmask;
     47  static Bool running = True, nextfocus, doinitspawn = True,
     48              fillagain = False, closelastclient = False,
     49 -            killclientsfirst = False;
     50 +			killclientsfirst = False, basenametitles = False;
     51  static Display *dpy;
     52  static DC dc;
     53  static Atom wmatom[WMLast];
     54 @@ -367,7 +369,10 @@ drawbar(void)
     55  		} else {
     56  			col = clients[c]->urgent ? dc.urg : dc.norm;
     57  		}
     58 -		drawtext(clients[c]->name, col);
     59 +		if (basenametitles)
     60 +			drawtext(clients[c]->basename, col);
     61 +		else
     62 +			drawtext(clients[c]->name, col);
     63  		dc.x += dc.w;
     64  		clients[c]->tabx = dc.x;
     65  	}
     66 @@ -557,6 +562,16 @@ getatom(int a)
     67  	return buf;
     68  }
     69  
     70 +char *
     71 +getbasename(const char *name)
     72 +{
     73 +	char *pos = strrchr(name, '/');
     74 +	if (pos)
     75 +		return pos+1;
     76 +	else
     77 +		return (char *)name;
     78 +}
     79 +
     80  int
     81  getclient(Window w)
     82  {
     83 @@ -1217,6 +1232,8 @@ updatetitle(int c)
     84  	    sizeof(clients[c]->name)))
     85  		gettextprop(clients[c]->win, XA_WM_NAME, clients[c]->name,
     86  		            sizeof(clients[c]->name));
     87 +	if (basenametitles)
     88 +		clients[c]->basename = getbasename(clients[c]->name);
     89  	if (sel == c)
     90  		xsettitle(win, clients[c]->name);
     91  	drawbar();
     92 @@ -1333,6 +1350,9 @@ main(int argc, char *argv[])
     93  	case 'u':
     94  		urgbgcolor = EARGF(usage());
     95  		break;
     96 +	case 'b':
     97 +		basenametitles = True;
     98 +		break;
     99  	case 'v':
    100  		die("tabbed-"VERSION", © 2009-2016 tabbed engineers, "
    101  		    "see LICENSE for details.\n");
    102 -- 
    103 2.40.0
    104