From 4d01072ae6000d9dcc1fe70df7741aa0549f6b8b Mon Sep 17 00:00:00 2001 From: Jakub Date: Wed, 22 May 2024 10:05:25 -0400 Subject: [PATCH] Add launchers patch to bottom bar - removed left extra status - removed/renamed some l/r specific variables --- config.def.h | 9 ++ dwm.c | 55 +++++++----- .../dwm-launchers-20200527-f09418b.diff | 84 +++++++++++++++++++ 3 files changed, 129 insertions(+), 19 deletions(-) create mode 100644 patches/functions/dwm-launchers-20200527-f09418b.diff diff --git a/config.def.h b/config.def.h index d3bcbea..52d2cb7 100644 --- a/config.def.h +++ b/config.def.h @@ -44,6 +44,15 @@ static const char *const autostart[] = { /* tagging */ 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 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 */ diff --git a/dwm.c b/dwm.c index 4018f67..f1fedf5 100644 --- a/dwm.c +++ b/dwm.c @@ -163,6 +163,12 @@ typedef struct { int monitor; } Rule; +typedef struct { + const char** command; + const char* name; +} Launcher; + + /* function declarations */ static void applyrules(Client *c); 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 const char broken[] = "broken"; static char stext[256]; -static char estextl[256]; -static char estextr[256]; +static char estext[256]; static char wfsymbol[2]; static int screen; static int sw, sh; /* X display screen geometry width, height */ @@ -619,6 +624,18 @@ buttonpress(XEvent *e) 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))) { focus(c); restack(selmon); @@ -991,10 +1008,17 @@ drawbar(Monitor *m) drw_setscheme(drw, scheme[SchemeNorm]); /* clear default bar draw buffer by drawing a blank rectangle */ drw_rect(drw, 0, 0, m->ww, bh, 1, 1); - etwr = TEXTW(estextr) - lrpad + 2; /* 2px right padding */ - drw_text(drw, m->ww - etwr - 2 * sp, 0, etwr, bh, 0, estextr, 0); - etwl = TEXTW(estextl); - drw_text(drw, 0, 0, etwl + 2 * sp, bh, 0, estextl, 0); + w = TEXTW(estext) - lrpad + 2; /* 2px right padding */ + drw_text(drw, m->ww - w - 2 * sp, 0, w, bh, 0, estext, 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); } @@ -2755,21 +2779,14 @@ updatestatus(void) char text[768]; if (!gettextprop(root, XA_WM_NAME, text, sizeof(text))) { strcpy(stext, "dwm-"VERSION); - estextl[0] = '\0'; - estextr[0] = '\0'; + estext[0] = '\0'; } else { - char *l = strchr(text, statussep); - if (l) { - *l = '\0'; l++; - strncpy(estextl, l, sizeof(estextl) - 1); + char *s = strchr(text, statussep); + if (s) { + *s = '\0'; s++; + strncpy(estext, s, sizeof(estext) - 1); } else - estextl[0] = '\0'; - char *r = strchr(estextl, statussep); - if (r) { - *r = '\0'; r++; - strncpy(estextr, r, sizeof(estextr) - 1); - } else - estextr[0] = '\0'; + estext[0] = 'Christ is king'; strncpy(stext, text, sizeof(stext) - 1); } for(m = mons; m; m = m->next) diff --git a/patches/functions/dwm-launchers-20200527-f09418b.diff b/patches/functions/dwm-launchers-20200527-f09418b.diff new file mode 100644 index 0000000..af695df --- /dev/null +++ b/patches/functions/dwm-launchers-20200527-f09418b.diff @@ -0,0 +1,84 @@ +From 6b5e23cdf8108a9033acc7c21c8926c0c72647fc Mon Sep 17 00:00:00 2001 +From: Adham Zahran +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 +