UtkarshVerma / dwmblocks-async

An efficient, lean, and asynchronous status feed generator for dwm.
GNU General Public License v2.0
232 stars 87 forks source link

Cant click blocks #11

Closed twoeightdev closed 2 years ago

twoeightdev commented 2 years ago

hi, thanks for your work, everythings good but i'm having problem with clicking on the blocks as it does nothing. here is my config:

#define CMDLENGTH 60
#define DELIMITER " | "
#define CLICKABLE_BLOCKS

const Block blocks[] = {
    BLOCK("sb-mail",        180,        17),
    BLOCK("sb-news",        1,          18),
    BLOCK("sb-forecast",    18000,      19),
    BLOCK("sb-memory",      1,          20),
    BLOCK("sb-gpu",         1,          21),
    BLOCK("sb-cpu",         1,          22),
    BLOCK("sb-time",        0,          23),
    BLOCK("sb-date",        1,          24),
    // BLOCK("sb-network", 5,    25),
};

and here is the script for sb-news

#!/bin/sh

case $BLOCK_BUTTON in
    1) setsid "$TERMINAL" -e newsboat ;;
esac

. sb-theme
display "$(cat /tmp/newsupdate 2>/dev/null || echo "$(newsboat -x print-unread | awk '{ if($1>0) print "NEWS:" $1}')")"

i use this statuscmd-status2d-with-signal

did i do it all correctly?😅 thanks for the help

Edit: distro- Void linux

UtkarshVerma commented 2 years ago

Did you patch your dwm as mentioned in the README under the clickability section? At a glance, everything you have here seems fine.

twoeightdev commented 2 years ago

Did you patch your dwm as mentioned in the README under the clickability section? At a glance, everything you have here seems fine.

yes sir i already did. i use this to patch dwm. i use the statuscmd-status2d the one wtih signal.

i have this on my dwm

#define STATUSBAR "dwmblocks"

    { ClkStatusText,        0,              Button1,        sigstatusbar,   {.i = 1} },
    { ClkStatusText,        0,              Button2,        sigstatusbar,   {.i = 2} },
    { ClkStatusText,        0,              Button3,        sigstatusbar,   {.i = 3} },
UtkarshVerma commented 2 years ago

You've applied the patch for status2d, but you need to change a line in the source code of dwm. Change these lines:

                return statuspid;
        }
    }
-   if (!(fp = popen("pidof -s "STATUSBAR, "r")))
+   if (!(fp = popen("pgrep -o "STATUSBAR, "r")))
        return -1;
    fgets(buf, sizeof(buf), fp);
    pclose(fp);

This is covered in the README. It you do this properly, clickability will start working.

twoeightdev commented 2 years ago

You've applied the patch for status2d, but you need to change a line in the source code of dwm. Change these lines:

              return statuspid;
      }
  }
- if (!(fp = popen("pidof -s "STATUSBAR, "r")))
+ if (!(fp = popen("pgrep -o "STATUSBAR, "r")))
      return -1;
  fgets(buf, sizeof(buf), fp);
  pclose(fp);

yea i already did that:

pid_t
getstatusbarpid()
{
    char buf[32], *str = buf, *c;
    FILE *fp;

    if (statuspid > 0) {
        snprintf(buf, sizeof(buf), "/proc/%u/cmdline", statuspid);
        if ((fp = fopen(buf, "r"))) {
            fgets(buf, sizeof(buf), fp);
            while ((c = strchr(str, '/')))
                str = c + 1;
            fclose(fp);
            if (!strcmp(str, STATUSBAR))
                return statuspid;
        }
    }
    if (!(fp = popen("pgrep -s "STATUSBAR, "r")))
        return -1;
    fgets(buf, sizeof(buf), fp);
    pclose(fp);
    return strtoul(buf, NULL, 10);
}

btw im using this on fresh dwm 6.3 no other patch atm only this.

twoeightdev commented 2 years ago

oops i think the pgrep -s and should be pgrep -o makes it not working. i'll try and report sir.

Edit: Fixed! thank you sir 😊

UtkarshVerma commented 2 years ago

oops i think the pgrep -s and should be pgrep -o makes it not working. i'll try and report sir.

Yeah, double check that command as it is responsible for sending click events to dwmblocks.

Also, for debugging, ensure that you only have one instance of dwmblocks running by using

killall -9 dwmblocks

And then launching dwmblocks.

kovmos commented 2 years ago

Hey sorry to reopen this but I'm having the same problem and changing pgrep -s to pgrep -o doesn't seem to fix it. Here is my config of dwmblocks:

#define CMDLENGTH 60
#define DELIMITER "  "
#define CLICKABLE_BLOCKS

const Block blocks[] = {
        BLOCK("sb-test",    1, 17),
};

Here is the script "sb-test":

#!/bin/sh

case $BLOCK_BUTTON in
        1) notify-send "hello" ;;
esac

case $BUTTON in
        1) notify-send "hello" ;;
esac

echo "hello"

I added a second case statement with the $BUTTON variable since that's what it's used on the example on the page for the statuscmd patch but it didn't work either. Here is the relevant seccion of dwm.c just in case:

                        fclose(fp);
                        if (!strcmp(str, STATUSBAR))
                                return statuspid;
                }
        }
        if (!(fp = popen("pidof -o "STATUSBAR, "r")))
                return -1;
        fgets(buf, sizeof(buf), fp);
        pclose(fp);
        return strtol(buf, NULL, 10);

I tested everything on a fresh install of dwm, only the statuscmd patch applied. I'm really lost on how to get this working so I appreciate any help :D

UtkarshVerma commented 2 years ago

It should work with the statsuscmd patch and changing the line I mentioned in the README to pgrep. Also, please use the $BLOCK_BUTTON variable.

You could try debugging this:

# Have only one block in config.h, set interval to 0

# Kill all previous instances
killall dwmblocks -9

# Create a new instance of dwmblocks and watch its stacktrace for signals
strace -e 'trace=!all' dwmblocks

Check if you get any updates in strace on clicking on the statusbar.