Add launchers patch to bottom bar

- removed left extra status
- removed/renamed some l/r specific variables
This commit is contained in:
Jakub 2024-05-22 10:05:25 -04:00
parent 7a754e4c6d
commit f463bb987f
4 changed files with 187 additions and 19 deletions

View File

@ -44,6 +44,15 @@ static const char *const autostart[] = {
/* tagging */ /* tagging */
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
/* launcher commands (They must be NULL terminated) */
static const char* browser[] = { "firefox", "--newwindow", "search.brave.com", NULL };
static const char* terminal[] = { "st", NULL };
static const Launcher launchers[] = {
{ terminal, "st" },
{ browser, "firefox" }
};
static const unsigned int ulinepad = 5; /* horizontal padding between the underline and tag */ static const unsigned int ulinepad = 5; /* horizontal padding between the underline and tag */
static const unsigned int ulinestroke = 2; /* thickness / height of the underline */ static const unsigned int ulinestroke = 2; /* thickness / height of the underline */
static const unsigned int ulinevoffset = 0; /* how far above the bottom of the bar the line should appear */ static const unsigned int ulinevoffset = 0; /* how far above the bottom of the bar the line should appear */

55
dwm.c
View File

@ -163,6 +163,12 @@ typedef struct {
int monitor; int monitor;
} Rule; } Rule;
typedef struct {
const char** command;
const char* name;
} Launcher;
/* function declarations */ /* function declarations */
static void applyrules(Client *c); static void applyrules(Client *c);
static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact); static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
@ -286,8 +292,7 @@ static pid_t winpid(Window w);
static Client *prevzoom = NULL; static Client *prevzoom = NULL;
static const char broken[] = "broken"; static const char broken[] = "broken";
static char stext[256]; static char stext[256];
static char estextl[256]; static char estext[256];
static char estextr[256];
static char wfsymbol[2]; static char wfsymbol[2];
static int screen; static int screen;
static int sw, sh; /* X display screen geometry width, height */ static int sw, sh; /* X display screen geometry width, height */
@ -619,6 +624,18 @@ buttonpress(XEvent *e)
arg.v = c; arg.v = c;
} }
} }
} else if (ev->window == selmon->extrabarwin) {
i = x = 0;
for(i = 0; i < LENGTH(launchers); i++) {
x += TEXTW(launchers[i].name);
if (ev->x < x) {
Arg a;
a.v = launchers[i].command;
spawn(&a);
return;
} else if (ev->x > selmon->ww - TEXTW(estext))
click = ClkStatusText;
}
} else if ((c = wintoclient(ev->window))) { } else if ((c = wintoclient(ev->window))) {
focus(c); focus(c);
restack(selmon); restack(selmon);
@ -991,10 +1008,17 @@ drawbar(Monitor *m)
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeNorm]);
/* clear default bar draw buffer by drawing a blank rectangle */ /* clear default bar draw buffer by drawing a blank rectangle */
drw_rect(drw, 0, 0, m->ww, bh, 1, 1); drw_rect(drw, 0, 0, m->ww, bh, 1, 1);
etwr = TEXTW(estextr) - lrpad + 2; /* 2px right padding */ w = TEXTW(estext) - lrpad + 2; /* 2px right padding */
drw_text(drw, m->ww - etwr - 2 * sp, 0, etwr, bh, 0, estextr, 0); drw_text(drw, m->ww - w - 2 * sp, 0, w, bh, 0, estext, 0);
etwl = TEXTW(estextl);
drw_text(drw, 0, 0, etwl + 2 * sp, bh, 0, estextl, 0); x = 0;
for (i = 0; i < LENGTH(launchers); i++)
{
w = TEXTW(launchers[i].name);
drw_text(drw, x, 0, w, bh, lrpad / 2, launchers[i].name, 0 );
x += w;
}
drw_map(drw, m->extrabarwin, 0, 0, m->ww, bh); drw_map(drw, m->extrabarwin, 0, 0, m->ww, bh);
} }
@ -2755,21 +2779,14 @@ updatestatus(void)
char text[768]; char text[768];
if (!gettextprop(root, XA_WM_NAME, text, sizeof(text))) { if (!gettextprop(root, XA_WM_NAME, text, sizeof(text))) {
strcpy(stext, "dwm-"VERSION); strcpy(stext, "dwm-"VERSION);
estextl[0] = '\0'; estext[0] = '\0';
estextr[0] = '\0';
} else { } else {
char *l = strchr(text, statussep); char *s = strchr(text, statussep);
if (l) { if (s) {
*l = '\0'; l++; *s = '\0'; s++;
strncpy(estextl, l, sizeof(estextl) - 1); strncpy(estext, s, sizeof(estext) - 1);
} else } else
estextl[0] = '\0'; estext[0] = '\0';
char *r = strchr(estextl, statussep);
if (r) {
*r = '\0'; r++;
strncpy(estextr, r, sizeof(estextr) - 1);
} else
estextr[0] = '\0';
strncpy(stext, text, sizeof(stext) - 1); strncpy(stext, text, sizeof(stext) - 1);
} }
for(m = mons; m; m = m->next) for(m = mons; m; m = m->next)

View File

@ -0,0 +1,58 @@
diff --git a/config.def.h b/config.def.h
index 1c0b587..961a189 100644
--- a/config.def.h
+++ b/config.def.h
@@ -70,6 +70,7 @@ static Key keys[] = {
{ MODKEY, XK_d, incnmaster, {.i = -1 } },
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
+ { MODKEY, XK_r, reorganizetags, {0} },
{ MODKEY, XK_Return, zoom, {0} },
{ MODKEY, XK_Tab, view, {0} },
{ MODKEY|ShiftMask, XK_c, killclient, {0} },
diff --git a/dwm.c b/dwm.c
index 4465af1..723d675 100644
--- a/dwm.c
+++ b/dwm.c
@@ -188,6 +188,7 @@ static void pop(Client *);
static void propertynotify(XEvent *e);
static void quit(const Arg *arg);
static Monitor *recttomon(int x, int y, int w, int h);
+static void reorganizetags(const Arg *arg);
static void resize(Client *c, int x, int y, int w, int h, int interact);
static void resizeclient(Client *c, int x, int y, int w, int h);
static void resizemouse(const Arg *arg);
@@ -1265,6 +1266,33 @@ recttomon(int x, int y, int w, int h)
return r;
}
+void
+reorganizetags(const Arg *arg) {
+ Client *c;
+ unsigned int occ, unocc, i;
+ unsigned int tagdest[LENGTH(tags)];
+
+ occ = 0;
+ for (c = selmon->clients; c; c = c->next)
+ occ |= (1 << (ffs(c->tags)-1));
+ unocc = 0;
+ for (i = 0; i < LENGTH(tags); ++i) {
+ while (unocc < i && (occ & (1 << unocc)))
+ unocc++;
+ if (occ & (1 << i)) {
+ tagdest[i] = unocc;
+ occ &= ~(1 << i);
+ occ |= 1 << unocc;
+ }
+ }
+
+ for (c = selmon->clients; c; c = c->next)
+ c->tags = 1 << tagdest[ffs(c->tags)-1];
+ if (selmon->sel)
+ selmon->tagset[selmon->seltags] = selmon->sel->tags;
+ arrange(selmon);
+}
+
void
resize(Client *c, int x, int y, int w, int h, int interact)
{

View File

@ -0,0 +1,84 @@
From 6b5e23cdf8108a9033acc7c21c8926c0c72647fc Mon Sep 17 00:00:00 2001
From: Adham Zahran <adhamzahranfms@gmail.com>
Date: Wed, 27 May 2020 18:07:57 +0200
Subject: [PATCH] Top bar now has buttons that launches programs
---
config.def.h | 8 ++++++++
dwm.c | 36 ++++++++++++++++++++++++++++++++++--
2 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/config.def.h b/config.def.h
index 1c0b587..9231cd5 100644
--- a/config.def.h
+++ b/config.def.h
@@ -21,6 +21,14 @@ static const char *colors[][3] = {
/* tagging */
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
+/* launcher commands (They must be NULL terminated) */
+static const char* surf[] = { "surf", "duckduckgo.com", NULL };
+
+static const Launcher launchers[] = {
+ /* command name to display */
+ { surf, "surf" },
+};
+
static const Rule rules[] = {
/* xprop(1):
* WM_CLASS(STRING) = instance, class
diff --git a/dwm.c b/dwm.c
index 9fd0286..79e7e20 100644
--- a/dwm.c
+++ b/dwm.c
@@ -141,6 +141,11 @@ typedef struct {
int monitor;
} Rule;
/* function declarations */
static void applyrules(Client *c);
static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
@@ -438,9 +443,26 @@ buttonpress(XEvent *e)
if (i < LENGTH(tags)) {
click = ClkTagBar;
arg.ui = 1 << i;
- } else if (ev->x < x + blw)
+ goto execute_handler;
+ } else if (ev->x < x + blw) {
click = ClkLtSymbol;
- else if (ev->x > selmon->ww - TEXTW(stext))
+ goto execute_handler;
+ }
+
+ if (ev->x > selmon->ww - TEXTW(stext))
click = ClkStatusText;
else
click = ClkWinTitle;
@@ -450,6 +472,9 @@ buttonpress(XEvent *e)
XAllowEvents(dpy, ReplayPointer, CurrentTime);
click = ClkClientWin;
}
+
+execute_handler:
+
for (i = 0; i < LENGTH(buttons); i++)
if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
&& CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
@@ -728,6 +753,13 @@ drawbar(Monitor *m)
w = blw = TEXTW(m->ltsymbol);
drw_setscheme(drw, scheme[SchemeNorm]);
x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
+
+ for (i = 0; i < LENGTH(launchers); i++)
+ {
+ w = TEXTW(launchers[i].name);
+ drw_text(drw, x, 0, w, bh, lrpad / 2, launchers[i].name, urg & 1 << i);
+ x += w;
+ }
if ((w = m->ww - tw - x) > bh) {
if (m->sel) {
--
2.17.1