From b4b19e3a4cebb3d2bca5777ad7c5a382737f7f8b Mon Sep 17 00:00:00 2001 From: bakkeby Date: Thu, 11 Jul 2024 22:38:58 +0200 Subject: [PATCH] Adding launcher patch --- README.md | 5 +++ config.def.h | 17 ++++++++-- dwm.c | 1 + patch/bar_launcher.c | 81 ++++++++++++++++++++++++++++++++++++++++++++ patch/bar_launcher.h | 8 +++++ patch/bar_ltsymbol.c | 1 - patch/bar_ltsymbol.h | 1 - patch/include.c | 3 ++ patch/include.h | 3 ++ patches.def.h | 5 +++ 10 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 patch/bar_launcher.c create mode 100644 patch/bar_launcher.h diff --git a/README.md b/README.md index e7c6e61..afcb571 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ Browsing patches? There is a [map of patches](https://coggle.it/diagram/X9IiSSM6 ### Changelog: +2024-07-11 - Added variant of the launcher patch + 2024-01-31 - Added the placedir patch 2023-12-22 - Added the do-not-die-on-color-allocation-failure patch @@ -522,6 +524,9 @@ Browsing patches? There is a [map of patches](https://coggle.it/diagram/X9IiSSM6 - [killunsel](https://dwm.suckless.org/patches/killunsel/) - kills all visible clients that are not selected (only the selected client will remain) + - [launcher](https://dwm.suckless.org/patches/launcher/) + - adds buttons to the bar that can be used to launch applications + - [~leftlayout~](http://dwm.suckless.org/patches/leftlayout/) - ~moves the layout symbol in the status bar to the left hand side~ diff --git a/config.def.h b/config.def.h index 1a44983..b0a7400 100644 --- a/config.def.h +++ b/config.def.h @@ -1,5 +1,9 @@ /* See LICENSE file for copyright and license details. */ +/* Helper macros for spawning commands */ +#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } +#define CMD(...) { .v = (const char*[]){ __VA_ARGS__, NULL } } + /* appearance */ #if ROUNDED_CORNERS_PATCH static const unsigned int borderpx = 0; /* border pixel of windows */ @@ -399,6 +403,13 @@ static char *statuscolors[][ColCount] = { static const char *layoutmenu_cmd = "layoutmenu.sh"; #endif +#if BAR_LAUNCHER_PATCH +static const Launcher launchers[] = { + /* icon to display command */ + { "surf", CMD("surf", "duckduckgo.com") }, +}; +#endif // BAR_LAUNCHER_PATCH + #if COOL_AUTOSTART_PATCH static const char *const autostart[] = { "st", NULL, @@ -548,6 +559,9 @@ static const BarRule barrules[] = { #if BAR_STATUSBUTTON_PATCH { -1, 0, BAR_ALIGN_LEFT, width_stbutton, draw_stbutton, click_stbutton, NULL, "statusbutton" }, #endif // BAR_STATUSBUTTON_PATCH + #if BAR_LAUNCHER_PATCH + { -1, 0, BAR_ALIGN_LEFT, width_launcher, draw_launcher, click_launcher, NULL, "launcher" }, + #endif // BAR_LAUNCHER_PATCH #if BAR_POWERLINE_TAGS_PATCH { 0, 0, BAR_ALIGN_LEFT, width_pwrl_tags, draw_pwrl_tags, click_pwrl_tags, hover_pwrl_tags, "powerline_tags" }, #endif // BAR_POWERLINE_TAGS_PATCH @@ -847,9 +861,6 @@ static const char *xkb_layouts[] = { #define HOLDKEY 0 // replace 0 with the keysym to activate holdbar #endif // BAR_HOLDBAR_PATCH -/* helper for spawning shell commands in the pre dwm-5.0 fashion */ -#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } - /* commands */ #if !NODMENU_PATCH static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */ diff --git a/dwm.c b/dwm.c index 198b77b..506e310 100644 --- a/dwm.c +++ b/dwm.c @@ -4102,6 +4102,7 @@ spawn(const Arg *arg) if (arg->v == dmenucmd) dmenumon[0] = '0' + selmon->num; #endif // NODMENU_PATCH +fprintf(stderr, "spawn running cmd:\n"); #if RIODRAW_PATCH if ((pid = fork()) == 0) diff --git a/patch/bar_launcher.c b/patch/bar_launcher.c new file mode 100644 index 0000000..0c40d52 --- /dev/null +++ b/patch/bar_launcher.c @@ -0,0 +1,81 @@ +#if BAR_STATUS2D_PATCH +int +width_launcher(Bar *bar, BarArg *a) +{ + int i, x = 0; + + for (i = 0; i < LENGTH(launchers); i++) { + x += status2dtextlength(launchers[i].name) + lrpad / 2; + } + return x ? x + lrpad / 2 : 0; +} + +int +draw_launcher(Bar *bar, BarArg *a) +{ + int i, w = 0;; + + for (i = 0; i < LENGTH(launchers); i++) { + w = status2dtextlength(launchers[i].name); + drawstatusbar(a, launchers[i].name); + a->x += w + lrpad / 2; + } + + return a->x ; +} + +int +click_launcher(Bar *bar, Arg *arg, BarArg *a) +{ + int i, x = 0; + + for (i = 0; i < LENGTH(launchers); i++) { + x += status2dtextlength(launchers[i].name) + lrpad / 2; + if (a->x < x) { + spawn(&launchers[i].command); + break; + } + } + return -1; +} +#else +int +width_launcher(Bar *bar, BarArg *a) +{ + int i, x = 0; + + for (i = 0; i < LENGTH(launchers); i++) { + x += TEXTW(launchers[i].name); + } + return x; +} + +int +draw_launcher(Bar *bar, BarArg *a) +{ + int i, x = 0, w = 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, True); + x += w; + } + + return x; +} + +int +click_launcher(Bar *bar, Arg *arg, BarArg *a) +{ + int i, x = 0; + + for (i = 0; i < LENGTH(launchers); i++) { + x += TEXTW(launchers[i].name); + if (a->x < x) { + spawn(&launchers[i].command); + break; + } + } + return -1; +} +#endif // BAR_STATUS2D_PATCH \ No newline at end of file diff --git a/patch/bar_launcher.h b/patch/bar_launcher.h new file mode 100644 index 0000000..c2b3259 --- /dev/null +++ b/patch/bar_launcher.h @@ -0,0 +1,8 @@ +typedef struct { + char* name; + const Arg command; +} Launcher; + +static int width_launcher(Bar *bar, BarArg *a); +static int draw_launcher(Bar *bar, BarArg *a); +static int click_launcher(Bar *bar, Arg *arg, BarArg *a); diff --git a/patch/bar_ltsymbol.c b/patch/bar_ltsymbol.c index 1fbd1b8..1004378 100644 --- a/patch/bar_ltsymbol.c +++ b/patch/bar_ltsymbol.c @@ -15,4 +15,3 @@ click_ltsymbol(Bar *bar, Arg *arg, BarArg *a) { return ClkLtSymbol; } - diff --git a/patch/bar_ltsymbol.h b/patch/bar_ltsymbol.h index 4de5720..4188584 100644 --- a/patch/bar_ltsymbol.h +++ b/patch/bar_ltsymbol.h @@ -1,4 +1,3 @@ static int width_ltsymbol(Bar *bar, BarArg *a); static int draw_ltsymbol(Bar *bar, BarArg *a); static int click_ltsymbol(Bar *bar, Arg *arg, BarArg *a); - diff --git a/patch/include.c b/patch/include.c index 239e7db..e3cacdb 100644 --- a/patch/include.c +++ b/patch/include.c @@ -21,6 +21,9 @@ #if COMBO_PATCH #include "combo.c" #endif +#if BAR_LAUNCHER_PATCH +#include "bar_launcher.c" +#endif #if BAR_LTSYMBOL_PATCH #include "bar_ltsymbol.c" #endif diff --git a/patch/include.h b/patch/include.h index 4255b36..3f400eb 100644 --- a/patch/include.h +++ b/patch/include.h @@ -24,6 +24,9 @@ #if BAR_HOLDBAR_PATCH #include "bar_holdbar.h" #endif +#if BAR_LAUNCHER_PATCH +#include "bar_launcher.h" +#endif #if BAR_LTSYMBOL_PATCH #include "bar_ltsymbol.h" #endif diff --git a/patches.def.h b/patches.def.h index 1af92cf..263dd34 100644 --- a/patches.def.h +++ b/patches.def.h @@ -67,6 +67,11 @@ */ #define BAR_FLEXWINTITLE_PATCH 0 +/* Adds buttons to the bar that can be used to launch applications. + * https://dwm.suckless.org/patches/launcher/ + */ +#define BAR_LAUNCHER_PATCH 0 + /* This patch adds a context menu for layout switching. * - xmenu needs to be installed. * - Edit layoutmenu.sh with the installed layouts and with correct indexes.