Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

holdbar only when bar is hidden using togglebar #35

Closed
chhajedji opened this issue Jun 29, 2020 · 17 comments
Closed

holdbar only when bar is hidden using togglebar #35

chhajedji opened this issue Jun 29, 2020 · 17 comments

Comments

@chhajedji
Copy link

Hello,

Can you help me to modify holdbar patch to get into effect only when I have used togglebar to hide status bar and always show status bar when bar is visible using togglebar? Holdbar patch is very useful but sometimes I need to see details on status bar constantly and that time togglebar doesn't show status bar and it is too tedious to hold down a key constantly.

By looking at this repo, I though you could be the right person. Please suggest something. Thanks in advance! :)

Extra information
I use a custom bar using xsetroot.

@bakkeby
Copy link
Owner

bakkeby commented Jun 29, 2020

Can't you just do the default MOD+b shortcut to trigger togglebar?

As for having the bar show by default just keep the showbar config enabled.

static const int showbar                 = 1;   /* 0 means no bar */

Pressing and releasing the holdbar key hides the bar again. You can trigger togglebar to make the bar show constantly again.

That's at least how it works in my build. As far as I can see I haven't made any changes in this respect.

@chhajedji
Copy link
Author

Thanks for the quick reply.

I tried to trigger togglebar again to show bar but it wasn't working for me. Once togglebar hides the bar, it is only shown when MODKEY key is pressed. Here is a list of patches I have used. Could something be missing or misfiring in them?

@bakkeby
Copy link
Owner

bakkeby commented Jun 29, 2020

Could it be because you have set the HOLDKEY as Super_L, same as MODKEY?

#define HOLDKEY 0xffeb

You can set the holdkey to something like MOD+n if you want.

@bakkeby
Copy link
Owner

bakkeby commented Jun 29, 2020

Btw, I like your activetagindicatorbar showing at the bottom, might grab that.

@chhajedji
Copy link
Author

Could it be because you have set the HOLDKEY as Super_L, same as MODKEY?

#define HOLDKEY 0xffeb

You can set the holdkey to something like MOD+n if you want.

Oh yes, this was it.
But if I change the HOLDKEY to something other than Super_L then I would defeat the purpose of having this patch! I wanted this patch so that I can hide bar most of the time and only see it when changing tags. And of course when I need to monitor something on the bar (that's where togglebar comes into play). Is there any other way or workaround other than mapping to something other than MODKEY?

@bakkeby
Copy link
Owner

bakkeby commented Jun 29, 2020

In the holdbar function it starts like this:

void
holdbar(const Arg *arg)
{
    selmon->showbar = 1;
...

Try changing that to:

void
holdbar(const Arg *arg)
{
    if (selmon->showbar)
        return;
    selmon->showbar = 1;

@chhajedji
Copy link
Author

Nope, didn't work :/

@bakkeby
Copy link
Owner

bakkeby commented Jun 29, 2020

I think it should prevent the bar from disappearing if it is already enabled (i.e. on startup), i.e. if it is shown in full you can do MOD+4 to change tag and the bar should not disappear (unless I am missing something).

That said you may need a non-Super keybinding to toggle the bar on and off.

Actually one thing you may want to try as well is inside keyrelease you have:

...
    if (e->xkey.keycode == XKeysymToKeycode(dpy, HOLDKEY)) {
        selmon->showbar = 0;
...

I'm not 100% sure if this will work, but you could try changing it into:

...
    if (e->xkey.keycode == XKeysymToKeycode(dpy, HOLDKEY)) {
        selmon->showbar = !selmon->showbar;
...

Actually I'll try this myself and get back to you.

@bakkeby
Copy link
Owner

bakkeby commented Jun 29, 2020

That actually works beautifully, just also change your togglebar function to be simply this:

void
togglebar(const Arg *arg)
{
	selmon->showbar = !selmon->showbar;
}

@chhajedji
Copy link
Author

chhajedji commented Jun 29, 2020 via email

@bakkeby
Copy link
Owner

bakkeby commented Jun 29, 2020

No worries. I should have something for you soon.

@bakkeby
Copy link
Owner

bakkeby commented Jun 30, 2020

OK, this looks like what you'll have to do:

In holdbar change this:

 void
 holdbar(const Arg *arg)
 {
-       selmon->showbar = 1;
+       if (selmon->showbar)
+               return;
+       selmon->showbar = 2;
        updateholdbarpos(selmon);
...

in keyrelease change this:

...
-       if (e->xkey.keycode == XKeysymToKeycode(dpy, HOLDKEY)) {
+       if (e->xkey.keycode == XKeysymToKeycode(dpy, HOLDKEY) && selmon->showbar == 2) {
...

in togglebar change this:

togglebar(const Arg *arg)
{
-       selmon->showbar = !selmon->showbar;
+       if (selmon->showbar == 2)
+               selmon->showbar = 1;
+       else
+               selmon->showbar = !selmon->showbar;
...
}

you don't, but if you were to have the pertagbar patch then it would still work - just that it would be very unpractical and unintuitive to use when combined with holdbar.

Another side effect of using holdbar worth noting is that if you use it with the super key, as in this case, then dwm will effectively block external applications such as sxhkd from using it.

@chhajedji
Copy link
Author

Thanks a lot! These changes are working as expected. I also use pertag patch and it is in sync without any error (known until now!).
Thanks again for the help. 😃

chhajedji added a commit to chhajedji/dwm that referenced this issue Jun 30, 2020
Earlier when togglebar is triggered to show bar, it wouldn't work unless
HOLDKEY is mapped to something other than MODKEY. After this commit
MODKEY will also work for HOLDKEY.

For more details see this issue
bakkeby/dwm-flexipatch#35 (comment)
@chhajedji
Copy link
Author

It would be great if you could add this at official dwm patches as many people would want this feature. It was a default behavior I expected after applying holdbar patch.

chhajedji added a commit to chhajedji/dwm that referenced this issue Jun 30, 2020
Earlier when togglebar is triggered to show bar, it wouldn't work unless
HOLDKEY is mapped to something other than MODKEY. After this commit
MODKEY will also work for HOLDKEY.

For more details see this issue
bakkeby/dwm-flexipatch#35
@bakkeby
Copy link
Owner

bakkeby commented Jul 1, 2020

Yes that's an idea. I added that now, will likely be up on the site within a week.

@antoniomokuzai
Copy link

patch -p1 fails on this dwm-holdbar-modkey-6.2 patch, I had a quick look at it, it wasn't obvious why patch -p1 would fail, can you please have a look?

My system is gentoo, I put dwm patches in a local overlay that has higher priority than the official portage tree, which has been working great for all the dwm patches I have been using, until this one.

Thanks.

@bakkeby
Copy link
Owner

bakkeby commented Feb 6, 2021

@antoniomokuzai you mean

$ git status
HEAD detached at 6.2
nothing to commit, working tree clean

$ git apply ~/path/to/dwm-holdbar-modkey-6.2.diff
$ git status
HEAD detached at 6.2
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   config.def.h
	modified:   dwm.c

no changes added to commit (use "git add" and/or "git commit -a")

vs

$ git status
HEAD detached at 6.2
nothing to commit, working tree clean

$ patch -p1 < ~/path/to/dwm-holdbar-modkey-6.2.diff
patching file config.def.h
patching file dwm.c
$ git status
HEAD detached at 6.2
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   config.def.h
	modified:   dwm.c

no changes added to commit (use "git add" and/or "git commit -a")

Both work fine, even on the latest master.

Most likely you have applied other patches which means that the patch can not be applied cleanly. In general I recommend applying patches manually by hand even if it takes a lot more time to do - you learn practically nothing from using patch or git apply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants