sites

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

dwm-launchers-20200527-f09418b.diff (2689B)


      1 From 6b5e23cdf8108a9033acc7c21c8926c0c72647fc Mon Sep 17 00:00:00 2001
      2 From: Adham Zahran <adhamzahranfms@gmail.com>
      3 Date: Wed, 27 May 2020 18:07:57 +0200
      4 Subject: [PATCH] Top bar now has buttons that launches programs
      5 
      6 ---
      7  config.def.h |  8 ++++++++
      8  dwm.c        | 36 ++++++++++++++++++++++++++++++++++--
      9  2 files changed, 42 insertions(+), 2 deletions(-)
     10 
     11 diff --git a/config.def.h b/config.def.h
     12 index 1c0b587..9231cd5 100644
     13 --- a/config.def.h
     14 +++ b/config.def.h
     15 @@ -21,6 +21,14 @@ static const char *colors[][3]      = {
     16  /* tagging */
     17  static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
     18  
     19 +/* launcher commands (They must be NULL terminated) */
     20 +static const char* surf[]      = { "surf", "duckduckgo.com", NULL };
     21 +
     22 +static const Launcher launchers[] = {
     23 +       /* command       name to display */
     24 +	{ surf,         "surf" },
     25 +};
     26 +
     27  static const Rule rules[] = {
     28  	/* xprop(1):
     29  	 *	WM_CLASS(STRING) = instance, class
     30 diff --git a/dwm.c b/dwm.c
     31 index 9fd0286..79e7e20 100644
     32 --- a/dwm.c
     33 +++ b/dwm.c
     34 @@ -141,6 +141,11 @@ typedef struct {
     35  	int monitor;
     36  } Rule;
     37  
     38 +typedef struct {
     39 +	const char** command;
     40 +	const char* name;
     41 +} Launcher;
     42 +
     43  /* function declarations */
     44  static void applyrules(Client *c);
     45  static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
     46 @@ -438,9 +443,26 @@ buttonpress(XEvent *e)
     47  		if (i < LENGTH(tags)) {
     48  			click = ClkTagBar;
     49  			arg.ui = 1 << i;
     50 -		} else if (ev->x < x + blw)
     51 +			goto execute_handler;
     52 +		} else if (ev->x < x + blw) {
     53  			click = ClkLtSymbol;
     54 -		else if (ev->x > selmon->ww - TEXTW(stext))
     55 +			goto execute_handler;
     56 +		}
     57 +
     58 +		x += blw;
     59 +
     60 +		for(i = 0; i < LENGTH(launchers); i++) {
     61 +			x += TEXTW(launchers[i].name);
     62 +			
     63 +			if (ev->x < x) {
     64 +				Arg a;
     65 +				a.v = launchers[i].command;
     66 +				spawn(&a);
     67 +				return;
     68 +			}
     69 +		}	
     70 +
     71 +		if (ev->x > selmon->ww - TEXTW(stext))
     72  			click = ClkStatusText;
     73  		else
     74  			click = ClkWinTitle;
     75 @@ -450,6 +472,9 @@ buttonpress(XEvent *e)
     76  		XAllowEvents(dpy, ReplayPointer, CurrentTime);
     77  		click = ClkClientWin;
     78  	}
     79 +
     80 +execute_handler:
     81 +
     82  	for (i = 0; i < LENGTH(buttons); i++)
     83  		if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
     84  		&& CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
     85 @@ -728,6 +753,13 @@ drawbar(Monitor *m)
     86  	w = blw = TEXTW(m->ltsymbol);
     87  	drw_setscheme(drw, scheme[SchemeNorm]);
     88  	x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
     89 +	
     90 +	for (i = 0; i < LENGTH(launchers); i++)
     91 +	{
     92 +		w = TEXTW(launchers[i].name);
     93 +		drw_text(drw, x, 0, w, bh, lrpad / 2, launchers[i].name, urg & 1 << i);
     94 +		x += w;
     95 +	}
     96  
     97  	if ((w = m->ww - tw - x) > bh) {
     98  		if (m->sel) {
     99 -- 
    100 2.17.1
    101