From ed20fd9c611ebeca0221e4e88a29c859bccb9797 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Sun, 9 Feb 2020 14:55:40 +0100 Subject: [PATCH] Feature request to add alternative scratchpad patch by Gaspar Vardanyan ref. #8 --- README.md | 5 +++ config.def.h | 17 ++++++-- patch/include.c | 3 ++ patch/include.h | 3 ++ patch/scratchpad_alt_1.c | 92 ++++++++++++++++++++++++++++++++++++++++ patch/scratchpad_alt_1.h | 6 +++ patches.def.h | 12 ++++++ 7 files changed, 135 insertions(+), 3 deletions(-) create mode 100644 patch/scratchpad_alt_1.c create mode 100644 patch/scratchpad_alt_1.h diff --git a/README.md b/README.md index 3848afe..02076cf 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t ### Changelog: +2020-02-09 - Added alternative scratchpad patch + 2020-02-02 - Added fsignal and transferall patches 2020-01-29 - Added swapfocus and shiftview patches @@ -272,6 +274,9 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t - [scratchpad](https://dwm.suckless.org/patches/scratchpad/) - the scratchpad patch allows you to spawn or restore a floating terminal window + - [scratchpad_alt_1](https://github.com/GasparVardanyan/dwm-scratchpad) + - this alternative patch enables a scratchpad feature in dwm similar to the scratchpad feature in i3wm + - [selfrestart](https://dwm.suckless.org/patches/selfrestart/) - restart dwm without the unnecessary dependency of an external script diff --git a/config.def.h b/config.def.h index 3896b45..ebde903 100644 --- a/config.def.h +++ b/config.def.h @@ -555,6 +555,9 @@ static const char *termcmd[] = { "st", NULL }; static const char scratchpadname[] = "scratchpad"; static const char *scratchpadcmd[] = { "st", "-t", scratchpadname, "-g", "120x34", NULL }; #endif // SCRATCHPAD_PATCH +#if SCRATCHPAD_ALT_1_PATCH +static const unsigned scratchpad_mask = 1u << sizeof tags / sizeof * tags; +#endif // SCRATCHPAD_ALT_1_PATCH static Key keys[] = { /* modifier key function argument */ @@ -695,8 +698,16 @@ static Key keys[] = { #if STICKY_PATCH { MODKEY|ShiftMask, XK_s, togglesticky, {0} }, #endif // STICKY_PATCH + #if SCRATCHPAD_ALT_1_PATCH + { MODKEY, XK_0, view, {.ui = ~scratchpad_mask } }, + { MODKEY|ShiftMask, XK_0, tag, {.ui = ~scratchpad_mask } }, + { MODKEY, XK_minus, scratchpad_show, {0} }, + { MODKEY|ShiftMask, XK_minus, scratchpad_hide, {0} }, + { MODKEY, XK_equal, scratchpad_remove, {0} }, + #else { MODKEY, XK_0, view, {.ui = ~0 } }, { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, + #endif // SCRATCHPAD_ALT_1_PATCH { MODKEY, XK_comma, focusmon, {.i = -1 } }, { MODKEY, XK_period, focusmon, {.i = +1 } }, { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, @@ -779,9 +790,9 @@ static Key keys[] = { { MODKEY|ControlMask, XK_KP_5, togglemaximize, {.i = 0} }, #endif // EXRESIZE_PATCH #if SETBORDERPX_PATCH - { MODKEY|ShiftMask, XK_minus, setborderpx, {.i = -1 } }, - { MODKEY|ShiftMask, XK_plus, setborderpx, {.i = +1 } }, - { MODKEY|ShiftMask, XK_numbersign, setborderpx, {.i = 0 } }, + { MODKEY|ControlMask, XK_minus, setborderpx, {.i = -1 } }, + { MODKEY|ControlMask, XK_plus, setborderpx, {.i = +1 } }, + { MODKEY|ControlMask, XK_numbersign, setborderpx, {.i = 0 } }, #endif // SETBORDERPX_PATCH #if CYCLELAYOUTS_PATCH { MODKEY|ControlMask, XK_comma, cyclelayout, {.i = -1 } }, diff --git a/patch/include.c b/patch/include.c index 78177b3..ef71088 100644 --- a/patch/include.c +++ b/patch/include.c @@ -84,6 +84,9 @@ #if SCRATCHPAD_PATCH #include "scratchpad.c" #endif +#if SCRATCHPAD_ALT_1_PATCH +#include "scratchpad_alt_1.c" +#endif #if SELFRESTART_PATCH #include "selfrestart.c" #endif diff --git a/patch/include.h b/patch/include.h index d728729..62ecd46 100644 --- a/patch/include.h +++ b/patch/include.h @@ -84,6 +84,9 @@ #if SCRATCHPAD_PATCH #include "scratchpad.h" #endif +#if SCRATCHPAD_ALT_1_PATCH +#include "scratchpad_alt_1.h" +#endif #if SELFRESTART_PATCH #include "selfrestart.h" #endif diff --git a/patch/scratchpad_alt_1.c b/patch/scratchpad_alt_1.c new file mode 100644 index 0000000..9d89ac9 --- /dev/null +++ b/patch/scratchpad_alt_1.c @@ -0,0 +1,92 @@ +static Client * scratchpad_last_showed = NULL; + +static void scratchpad_hide () +{ + if (selmon -> sel) + { + selmon -> sel -> tags = scratchpad_mask; + focus(NULL); + arrange(selmon); + } +} + +static _Bool scratchpad_last_showed_is_killed (void) +{ + _Bool killed = 1; + for (Client * c = selmon -> clients; c != NULL; c = c -> next) + { + if (c == scratchpad_last_showed) + { + killed = 0; + break; + } + } + return killed; +} + +static void scratchpad_remove () +{ + if (selmon -> sel && scratchpad_last_showed != NULL && selmon -> sel == scratchpad_last_showed) + scratchpad_last_showed = NULL; +} + +static void scratchpad_show () +{ + if (scratchpad_last_showed == NULL || scratchpad_last_showed_is_killed ()) + scratchpad_show_first (); + else + { + if (scratchpad_last_showed -> tags != scratchpad_mask) + { + scratchpad_last_showed -> tags = scratchpad_mask; + focus(NULL); + arrange(selmon); + } + else + { + _Bool found_current = 0; + _Bool found_next = 0; + for (Client * c = selmon -> clients; c != NULL; c = c -> next) + { + if (found_current == 0) + { + if (c == scratchpad_last_showed) + { + found_current = 1; + continue; + } + } + else + { + if (c -> tags == scratchpad_mask) + { + found_next = 1; + scratchpad_show_client (c); + break; + } + } + } + if (found_next == 0) scratchpad_show_first (); + } + } +} + +static void scratchpad_show_client (Client * c) +{ + scratchpad_last_showed = c; + c -> tags = selmon->tagset[selmon->seltags]; + focus(c); + arrange(selmon); +} + +static void scratchpad_show_first (void) +{ + for (Client * c = selmon -> clients; c != NULL; c = c -> next) + { + if (c -> tags == scratchpad_mask) + { + scratchpad_show_client (c); + break; + } + } +} \ No newline at end of file diff --git a/patch/scratchpad_alt_1.h b/patch/scratchpad_alt_1.h new file mode 100644 index 0000000..4bbbf9b --- /dev/null +++ b/patch/scratchpad_alt_1.h @@ -0,0 +1,6 @@ +static void scratchpad_hide (); +static _Bool scratchpad_last_showed_is_killed (void); +static void scratchpad_remove (); +static void scratchpad_show (); +static void scratchpad_show_client (Client * c); +static void scratchpad_show_first (void); \ No newline at end of file diff --git a/patches.def.h b/patches.def.h index 3313bf7..73b7822 100644 --- a/patches.def.h +++ b/patches.def.h @@ -293,6 +293,8 @@ * This patch depends on an additional library lmdpclient so if you want to enable this * then you will also have to append -lmpdclient to the LIBS configuration in config.mk. * A placeholder has been added there for reference. + * This patch depends on the following additional library: + * - libmpdclient * https://dwm.suckless.org/patches/mpdcontrol/ */ #define MDPCONTROL_PATCH 0 @@ -387,6 +389,12 @@ */ #define SCRATCHPAD_PATCH 0 +/* This alternative patch enables a scratchpad feature in dwm similar to the scratchpad + * feature in i3wm. + * https://github.com/GasparVardanyan/dwm-scratchpad + */ +#define SCRATCHPAD_ALT_1_PATCH 0 + /* Allows restarting dwm without the dependency of an external script. * https://dwm.suckless.org/patches/selfrestart/ */ @@ -452,6 +460,10 @@ /* This patch depends on the pertag patch and makes it possible to switch focus with a single * shortcut (mod-s) instead of having to think if you should use mod-j or mod-k for reaching * the previously used window. + * This patch depends on the following additional libraries: + * - libxcb + * - Xlib-libxcb + * - xcb-res * https://dwm.suckless.org/patches/swapfocus/ */ #define SWAPFOCUS_PATCH 0