Re: [dev] [dwm] [swaptags] Swapping the contents of two tags

From: Ricardo Jesus <rj.bcjesus_AT_gmail.com>
Date: Sat, 29 Jun 2019 11:23:19 +0100

On 6/29/19 7:32 AM, Danh Doan wrote:
> On 2019-06-28 19:34:59 +0100, Ricardo Jesus wrote:
>> Hello,
>>
>> I wrote a small patch for dwm 6.2 which enables it to swap the contents of
>> two tags (i.e. the clients which are visible in one are moved to the other
>> and vice-versa).
>>
>> This is my first time actually hacking into dwm's code on my own (so far I
>> had only applied patches others had made or changed defaults).
>>
>> I was looking forward to receive some feedback and/or corrections to my
>> modifications.
>>
>> Thanks in advance,
>> Ricardo Jesus
>
>> diff --git a/config.def.h b/config.def.h
>> index 1c0b587..2257afd 100644
>> --- a/config.def.h
>> +++ b/config.def.h
>> _AT_@ -43,13 +43,16 @@ static const Layout layouts[] = {
>> { "[M]", monocle },
>> };
>>
>> +void swaptags(const Arg *arg);
>> +
>> /* key definitions */
>> #define MODKEY Mod1Mask
>> #define TAGKEYS(KEY,TAG) \
>> { MODKEY, KEY, view, {.ui = 1 << TAG} }, \
>> { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \
>> { MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \
>> - { MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} },
>> + { MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} }, \
>> + { Mod1Mask|ShiftMask, KEY, swaptags, {.ui = 1 << TAG} },
>
> Isn't Mod1Mask|ShiftMask is MODEKEY|ShiftMask?
> Then, `tag' and `swaptags' have the same hotkey!

Of course you're right. I myself use Mod4 as ModKey, which is why I
didn't encounter any conflicts (and why I used that keybinding in the
first place).

But I forgot all about this when I copied my changes to a clean config
for the patch.

>>
>> /* helper for spawning shell commands in the pre dwm-5.0 fashion */
>> #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
>> _AT_@ -113,3 +116,24 @@ static Button buttons[] = {
>> { ClkTagBar, MODKEY, Button3, toggletag, {0} },
>> };
>>
>> +void
>> +swaptags(const Arg *arg)
>> +{
>> + unsigned int newtag = arg->ui & TAGMASK;
>> + unsigned int curtag = selmon->tagset[selmon->seltags];
>> +
>> + if (newtag == curtag || !curtag || (curtag & (curtag-1)))
>> + return;
>> +
>> + for (Client *c = selmon->clients; c != NULL; c = c->next) {
>> + if((c->tags & newtag) || (c->tags & curtag))
>> + c->tags ^= curtag ^ newtag;
>> +
>> + if(!c->tags) c->tags = newtag;
>> + }
>> +
>> + selmon->tagset[selmon->seltags] = newtag;
>> +
>> + focus(NULL);
>> + arrange(selmon);
>> +}
>
> Nitpick:
> Function's declaration and definition should be in dwm.c, no?
> Anyway, we use tab for indentation not spaces.

As for the function's declaration and definition, I simply followed
the customfuncs ( https://dwm.suckless.org/customisation/customfuncs/
) page.

I didn't know about the usage of tabs, but I'll use them then.

Thanks!

Best regards,
Ricardo Jesus
Received on Sat Jun 29 2019 - 12:23:19 CEST

This archive was generated by hypermail 2.3.0 : Sat Jun 29 2019 - 13:36:08 CEST