Feature request to add alternative scratchpad patch by Gaspar Vardanyan ref. #8

This commit is contained in:
bakkeby 2020-02-09 14:55:40 +01:00
parent 69a7b2ad6b
commit ed20fd9c61
7 changed files with 135 additions and 3 deletions

View File

@ -15,6 +15,8 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t
### Changelog: ### Changelog:
2020-02-09 - Added alternative scratchpad patch
2020-02-02 - Added fsignal and transferall patches 2020-02-02 - Added fsignal and transferall patches
2020-01-29 - Added swapfocus and shiftview 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/) - [scratchpad](https://dwm.suckless.org/patches/scratchpad/)
- the scratchpad patch allows you to spawn or restore a floating terminal window - 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/) - [selfrestart](https://dwm.suckless.org/patches/selfrestart/)
- restart dwm without the unnecessary dependency of an external script - restart dwm without the unnecessary dependency of an external script

View File

@ -555,6 +555,9 @@ static const char *termcmd[] = { "st", NULL };
static const char scratchpadname[] = "scratchpad"; static const char scratchpadname[] = "scratchpad";
static const char *scratchpadcmd[] = { "st", "-t", scratchpadname, "-g", "120x34", NULL }; static const char *scratchpadcmd[] = { "st", "-t", scratchpadname, "-g", "120x34", NULL };
#endif // SCRATCHPAD_PATCH #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[] = { static Key keys[] = {
/* modifier key function argument */ /* modifier key function argument */
@ -695,8 +698,16 @@ static Key keys[] = {
#if STICKY_PATCH #if STICKY_PATCH
{ MODKEY|ShiftMask, XK_s, togglesticky, {0} }, { MODKEY|ShiftMask, XK_s, togglesticky, {0} },
#endif // STICKY_PATCH #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, XK_0, view, {.ui = ~0 } },
{ MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } },
#endif // SCRATCHPAD_ALT_1_PATCH
{ MODKEY, XK_comma, focusmon, {.i = -1 } }, { MODKEY, XK_comma, focusmon, {.i = -1 } },
{ MODKEY, XK_period, focusmon, {.i = +1 } }, { MODKEY, XK_period, focusmon, {.i = +1 } },
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
@ -779,9 +790,9 @@ static Key keys[] = {
{ MODKEY|ControlMask, XK_KP_5, togglemaximize, {.i = 0} }, { MODKEY|ControlMask, XK_KP_5, togglemaximize, {.i = 0} },
#endif // EXRESIZE_PATCH #endif // EXRESIZE_PATCH
#if SETBORDERPX_PATCH #if SETBORDERPX_PATCH
{ MODKEY|ShiftMask, XK_minus, setborderpx, {.i = -1 } }, { MODKEY|ControlMask, XK_minus, setborderpx, {.i = -1 } },
{ MODKEY|ShiftMask, XK_plus, setborderpx, {.i = +1 } }, { MODKEY|ControlMask, XK_plus, setborderpx, {.i = +1 } },
{ MODKEY|ShiftMask, XK_numbersign, setborderpx, {.i = 0 } }, { MODKEY|ControlMask, XK_numbersign, setborderpx, {.i = 0 } },
#endif // SETBORDERPX_PATCH #endif // SETBORDERPX_PATCH
#if CYCLELAYOUTS_PATCH #if CYCLELAYOUTS_PATCH
{ MODKEY|ControlMask, XK_comma, cyclelayout, {.i = -1 } }, { MODKEY|ControlMask, XK_comma, cyclelayout, {.i = -1 } },

View File

@ -84,6 +84,9 @@
#if SCRATCHPAD_PATCH #if SCRATCHPAD_PATCH
#include "scratchpad.c" #include "scratchpad.c"
#endif #endif
#if SCRATCHPAD_ALT_1_PATCH
#include "scratchpad_alt_1.c"
#endif
#if SELFRESTART_PATCH #if SELFRESTART_PATCH
#include "selfrestart.c" #include "selfrestart.c"
#endif #endif

View File

@ -84,6 +84,9 @@
#if SCRATCHPAD_PATCH #if SCRATCHPAD_PATCH
#include "scratchpad.h" #include "scratchpad.h"
#endif #endif
#if SCRATCHPAD_ALT_1_PATCH
#include "scratchpad_alt_1.h"
#endif
#if SELFRESTART_PATCH #if SELFRESTART_PATCH
#include "selfrestart.h" #include "selfrestart.h"
#endif #endif

92
patch/scratchpad_alt_1.c Normal file
View File

@ -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;
}
}
}

6
patch/scratchpad_alt_1.h Normal file
View File

@ -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);

View File

@ -293,6 +293,8 @@
* This patch depends on an additional library lmdpclient so if you want to enable this * 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. * then you will also have to append -lmpdclient to the LIBS configuration in config.mk.
* A placeholder has been added there for reference. * A placeholder has been added there for reference.
* This patch depends on the following additional library:
* - libmpdclient
* https://dwm.suckless.org/patches/mpdcontrol/ * https://dwm.suckless.org/patches/mpdcontrol/
*/ */
#define MDPCONTROL_PATCH 0 #define MDPCONTROL_PATCH 0
@ -387,6 +389,12 @@
*/ */
#define SCRATCHPAD_PATCH 0 #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. /* Allows restarting dwm without the dependency of an external script.
* https://dwm.suckless.org/patches/selfrestart/ * 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 /* 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 * shortcut (mod-s) instead of having to think if you should use mod-j or mod-k for reaching
* the previously used window. * the previously used window.
* This patch depends on the following additional libraries:
* - libxcb
* - Xlib-libxcb
* - xcb-res
* https://dwm.suckless.org/patches/swapfocus/ * https://dwm.suckless.org/patches/swapfocus/
*/ */
#define SWAPFOCUS_PATCH 0 #define SWAPFOCUS_PATCH 0