[wiki] [sites] [dwm][patch][launcher] Adding a new patch || Adham Zahran

From: <git_AT_suckless.org>
Date: Wed, 27 May 2020 18:43:19 +0200

commit 815859e5e27f61ab9e59eb27246ee1a02437abf6
Author: Adham Zahran <lordadamson_AT_gmail.com>
Date: Wed May 27 18:42:20 2020 +0200

    [dwm][patch][launcher] Adding a new patch

diff --git a/dwm.suckless.org/patches/launcher/dwm-launchers-20200527-f09418b.diff b/dwm.suckless.org/patches/launcher/dwm-launchers-20200527-f09418b.diff
new file mode 100644
index 00000000..a6836365
--- /dev/null
+++ b/dwm.suckless.org/patches/launcher/dwm-launchers-20200527-f09418b.diff
_AT_@ -0,0 +1,101 @@
+From 6b5e23cdf8108a9033acc7c21c8926c0c72647fc Mon Sep 17 00:00:00 2001
+From: Adham Zahran <adhamzahranfms_AT_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
+_AT_@ -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
+_AT_@ -141,6 +141,11 @@ 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);
+_AT_@ -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;
++ }
++
++ x += blw;
++
++ 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;
++ }
++ }
++
++ if (ev->x > selmon->ww - TEXTW(stext))
+ click = ClkStatusText;
+ else
+ click = ClkWinTitle;
+_AT_@ -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))
+_AT_@ -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
+
diff --git a/dwm.suckless.org/patches/launcher/index.md b/dwm.suckless.org/patches/launcher/index.md
new file mode 100644
index 00000000..5acf0a57
--- /dev/null
+++ b/dwm.suckless.org/patches/launcher/index.md
_AT_@ -0,0 +1,35 @@
+launcher
+========
+
+Description
+-----------
+The bar at the top will have buttons that you can click to launch programs and commands.
+
+Usage:
+------
+In config.h make a command:
+
+
+ /* launcher command (Must be NULL terminated) */
+ static const char* surf[] = { "surf", "duckduckgo.com", NULL };
+
+
+Then add it to the launchers array:
+
+
+ static const Launcher launchers[] = {
+ /* command name to display */
+ { surf, "surf" },
+ };
+
+
+The result will be a little button that says "surf" at the top bar. When you click it, it launches surf. Have fun :D
+
+Download
+--------
+* [dwm-launchers-20200527-f09418b.diff](dwm-launchers-20200527-f09418b.diff)
+
+Author
+------
+* [Adham Zahran](mailto:adhamzahranfms_AT_gmail.com)
+
Received on Wed May 27 2020 - 18:43:19 CEST

This archive was generated by hypermail 2.3.0 : Wed May 27 2020 - 18:48:42 CEST