Waybar
Waybar copied to clipboard
Custom module: click behavior
Hi, I have a minimal custom module that should act as a simple button to click on and then execute some command (ignoring the result):
"custom/mymodule": {
"format": "",
"on-click": "stuff"
}
This works fine, in the sense that the module shows up and my command is executed on click. However, there is some wired behavior as my command (stuff
in the example snippet) is now also executed when clicking other areas (like the workspace selector) on the bar, too.
How can I fix this so that my command is only executed when the module is actually clicked on?
Thanks :)
I've noticed this too with creating a "custom/power" module. If you click it once, it hijacks any further clicks across the entire bar.
One thing I've noticed is that it only happens on the custom/power
module. The relevant part of my config:
{
"custom/menu": {
"format": "!",
"tooltip": false,
"on-click": "rofi -show run"
},
"custom/power": {
"format": "⏻",
"tooltip": false,
"on-click": "~/.config/hypr/scripts/powermenu.sh"
},& pkill waylogout
}
My guess it's something to do with what is returned by the on-click event, because it doesn't happen to my menu
one and I change the on-click event of custom/power
to also call rofi
it works as expected, i.e. displays the menu but doesn't hijack future clicks.
Also powermenu.sh
just wraps around a long-winded call to waylogout
I'm having a similar with custom/clipboard
module I created.
"custom/clipboard": {
"exec": "~/bin/waybar-clipboard",
"return-type": "json",
"interval": "once",
"format": "{icon}",
"format-icons": {
"empty": "",
"full": "",
},
"on-click": "cliphist list | fuzzel -d | cliphist decode | wl-copy",
"on-click-middle": "cliphist wipe; pkill -RTMIN+9 waybar",
"exec-on-event": true,
"signal": 9,
},
When I click on the module, I get fuzzel
with a list of stuff in my clipboard. After picking one (or hitting escape), whenever I click on anything else in the bar, then fuzzel
appears again. The only way to fix it is to right (or middle) click on something.
P.S. waybar-clipboard
is:
#!/bin/bash
LINES=$(cliphist list | wc -l)
[[ $LINES -eq 0 ]] && ICON='empty' || ICON='full'
jq --unbuffered --compact-output \
--arg title 'clipboard' \
--arg icon "$ICON" \
--arg items "$LINES item(s)" \
-n '{text: $title, alt: $icon, tooltip: $items}'
I made two changes and the problem seems to be solved for my configuration:
- I added
"tooltip": false,
- I upgraded my system. I think there were some related package updates.
My tool (stuff
in my initial example) does not print anything. I guess this was the problem and somehow adding tooltip
or updating my packages (Arch Linux) fixed this issue for me.
If you guys are using Hyprland, the click issue is related to #1850 & hyprwm/Hyprland#1348
Until that fix gets merged into main releases, the workaround for me for now is if you right-click anywhere on the bar it is still picked up by the blocking module but it then seems to reset whatever is causing all future clicks to be captured by the same module.
The tooltip fix recommended above didn't work for me.
Until that fix gets merged into main releases, the workaround for me for now is if you right-click anywhere on the bar it is still picked up by the blocking module but it then seems to reset whatever is causing all future clicks to be captured by the same module.
The tooltip fix recommended above didn't work for me.
Have u tried this: https://github.com/hyprwm/Hyprland/issues/1348#issuecomment-1565604984 ?
Have u tried this: hyprwm/Hyprland#1348 (comment) ?
I've tried it, it sometimes works but it's really inconsistent. I can put a sleep value up to around 0.25 before the lag becomes annoyingly noticeable and it still sometimes doesn't work and I need to right-click on the bar to 'reset' from that captured state. So for now I'm preferring 'consistently broken' and right-clicking instead of 'consistently laggy and sometimes broken'.
this bug also affects swaync https://github.com/ErikReider/SwayNotificationCenter/issues/292
Can confirm also happens to me on Sway 1.9. This is my module:
"custom/display": {
"exec": "swayscript monbar",
"interval": 1,
"return-type": "json",
"on-click": "swayscript montoggle",
"on-click-right": "swayscript vrrtoggle"
}
and the output for swayscript monbar
: {"text": "", "tooltip": "Mon: on / Vrr: off"}
swayscript sends swaymsg commands to toggle power/freesync for predefined monitors.
Update: for me the only working fix was to add sleep delay before the click command: "on-click": "sleep 0.1 && swayscript montoggle",
Can confirm also happens to me on Sway 1.9. This is my module:
"custom/display": { "exec": "swayscript monbar", "interval": 1, "return-type": "json", "on-click": "swayscript montoggle", "on-click-right": "swayscript vrrtoggle" }
and the output for
swayscript monbar
:{"text": "", "tooltip": "Mon: on / Vrr: off"}
swayscript sends swaymsg commands to toggle power/freesync for predefined monitors.
Update: for me the only working fix was to add sleep delay before the click command:
"on-click": "sleep 0.1 && swayscript montoggle",
Also on 1.9 and sleep 0.1
fixed my custom widget I was testing out below:
"custom/test": {
"exec": "swaymsg -t get_outputs | jq 'map(select(.name==\"eDP-1\"))' | jq 'map({active})' | jq '.[0]' | jq '. + {\"class\": .active|tostring }' | jq 'if .active == true then .text=\"ON\" else .text=\"OFF\" end' | awk '{printf $0}'",
"on-click": "sleep 0.1 && swaymsg -t get_outputs | jq 'map(select(.name==\"eDP-1\"))' | jq 'map({active})' | jq '.[0]' | jq 'if .active == true then .value=\"disable\" else .value=\"enable\" end' | jq '.value' | xargs -I {} swaymsg output -s $SWAYSOCK eDP-1 {}",
"interval": 1,
"return-type": "json"
}