bakkeby/patches

renamedscratchpads toggles same scratchpad though different keybinding.

gcoelho05 opened this issue · 2 comments

In my config.h, I have the following:

static const char *muttscratchcmd[] = {"s", "st", "-n", "muttscratch", "-g", "130x28", "-e", "neomutt", NULL};
static const char *pulsescratchcmd[] = {"s", "st", "-n", "pulsescratch", "-g", "100x28", "-e", "pulsemixer", NULL};
static const char *yubiscratchcmd[] = {"s", "yubioath-desktop", NULL};
static const char *whatsscratchcmd[] = {"s", "whatsdesk", NULL};
static const char *topscratchcmd[] = {"s", "st", "-n", "topscratch", "-g", "100x28", "-e", "htop", NULL};
RULE(.instance = "muttscratch", .scratchkey = 's', .isfloating = 0)
RULE(.instance = "pulsescratch", .scratchkey = 's', .isfloating = 0)
RULE(.instance = "yubioath-desktop", .scratchkey = 's', .isfloating = 1)
RULE(.instance = "whatsdesk", .scratchkey = 's', .isfloating = 1)
RULE(.instance = "topscratch", .scratchkey = 's', .isfloating = 0)
{ MODKEY|ControlMask,           XK_m,          togglescratch,          {.v = muttscratchcmd } },
{ MODKEY|ControlMask,           XK_p,          togglescratch,          {.v = pulsescratchcmd } },
{ MODKEY|ControlMask,           XK_y,          togglescratch,          {.v = yubiscratchcmd } },
{ MODKEY|ControlMask,           XK_w,          togglescratch,          {.v = whatsscratchcmd } },
{ MODKEY|ControlMask,           XK_t,          togglescratch,          {.v = topscratchcmd } },

I might be doing something wrong, but when I press, say, mod+control+m, to toggle the mutt scratchpad, it'll open just fine. Though, if the mutt scratchpad has already been opened, pressing, say, mod+control+p, will toggle mutt again, instead of pulsemixer.


EDIT: I am using this patch from dwm-flexipatch.

The way the togglescratch function works is that it will search through all clients looking for a given scratch key. If such a client is found then it will be brought into view, but if there is no such client then it will execute the given command to spawn the program.

At some point later in time a window will come up asking to be mapped. There is no direct correlation between starting a program and a window popping up, so this process is asynchronous - which is the very reason why we need to have this dance around scratch keys and client rules. The client rules are there to identify the window as to associate it with the corresponding scratch key - so that the next time you trigger togglescratch it will find said client and bring that into view rather than spawning a new program.

Your config is all fine, the only problem is that you are using the same scratch key of s for all of them.

My personal recommendation is to use the same character as for the keybinding, i.e. m, p, y, w and t in this case. Likewise with the command variable names I would recommend using similar references, e.g.

{ MODKEY|ControlMask,           XK_m,          togglescratch,          {.v = spcmd_m } },
{ MODKEY|ControlMask,           XK_p,          togglescratch,          {.v = spcmd_p } },
{ MODKEY|ControlMask,           XK_y,          togglescratch,          {.v = spcmd_y } },
{ MODKEY|ControlMask,           XK_w,          togglescratch,          {.v = spcmd_w } },
{ MODKEY|ControlMask,           XK_t,          togglescratch,          {.v = spcmd_t } },

This just because it makes it a bit more generic and you don't need to touch it again should you want to replace the scratchpad on MOD+Ctrl+y - you just need to change the command inside spcmd_y and the rule to match.

Thank you for your help and detailed explanation. I did not realise I had to change the scratch key.
I also followed your rule name suggestion, making it generic is indeed a good idea.