Ax-Shell icon indicating copy to clipboard operation
Ax-Shell copied to clipboard

Caffeine not working

Open Deivis44 opened this issue 1 year ago • 13 comments

Hi, I was trying to use the caffeine function in the dock, however when I click the button there is no action that shows me if it's activated or no.

https://github.com/user-attachments/assets/b3769267-8dca-40f4-a983-cb1bd4cb00ab

Deivis44 avatar May 29 '25 16:05 Deivis44

I also noticed this, I'm already searching for the error

johannSo avatar May 29 '25 17:05 johannSo

6 minutes later...... It is probably because you don't have 'wlinhibit' installed (that was the case for me). 🤦‍♂️

johannSo avatar May 29 '25 17:05 johannSo

For now, I use this partial solution just visually cuz the button it's not updated anyway:

  1. Make a script for toggle and notify about caffeine status:
#!/bin/bash

CAFFEINE_FILE="$HOME/.config/hypr/caffeine.enabled"

if [[ -f "$CAFFEINE_FILE" ]]; then
    rm "$CAFFEINE_FILE"
    notify-send "☕ Caffeine OFF"
else
    touch "$CAFFEINE_FILE"
    notify-send "☕ Caffeine ON"
fi

  1. Modify actual hypridle.conf file (you can use the one that makes an overwrite, created by the author)

Reference:

Image

general {
    lock_cmd = pidof hyprlock || hyprlock
    before_sleep_cmd = if [ ! -f "$HOME/.config/hypr/caffeine.enabled" ]; then loginctl lock-session; fi
    after_sleep_cmd = hyprctl dispatch dpms on
}

listener {
    timeout = 150
    on-timeout = brightnessctl -s set 10
    on-resume = brightnessctl -r
}

listener {
    timeout = 300
    on-timeout = if [ ! -f "$HOME/.config/hypr/caffeine.enabled" ]; then loginctl lock-session; fi
}

listener {
    timeout = 330
    on-timeout = if [ ! -f "$HOME/.config/hypr/caffeine.enabled" ]; then hyprctl dispatch dpms off; fi
    on-resume = hyprctl dispatch dpms on
}

listener {
    timeout = 1800
    on-timeout = if [ ! -f "$HOME/.config/hypr/caffeine.enabled" ]; then systemctl suspend; fi
}

I just modified the original version:

general {
    lock_cmd = pidof hyprlock || hyprlock       # avoid starting multiple hyprlock instances.
    before_sleep_cmd = loginctl lock-session    # lock before suspend.
    after_sleep_cmd = hyprctl dispatch dpms on  # to avoid having to press a key twice to turn on the display.
}

listener {
    timeout = 150                                # 2.5min.
    on-timeout = brightnessctl -s set 10         # set monitor backlight to minimum, avoid 0 on OLED monitor.
    on-resume = brightnessctl -r                 # monitor backlight restore.
}

listener {
    timeout = 300                                 # 5min
    on-timeout = loginctl lock-session            # lock screen when timeout has passed
}

listener {
    timeout = 330                                 # 5.5min
    on-timeout = hyprctl dispatch dpms off        # screen off when timeout has passed
    on-resume = hyprctl dispatch dpms on          # screen on when activity is detected after timeout has fired.
}

listener {
    timeout = 1800                                # 30min
    on-timeout = systemctl suspend                # suspend pc
}
  1. (Optinal) Add ad keybind for use it more easily, in my case:
bind = $mainMod SHIFT, C, exec, sh -c '$HOME/ruta/al/toggle-caffeine.sh'

Preview:

Image

Deivis44 avatar May 29 '25 17:05 Deivis44

6 minutes later...... It is probably because you don't have 'wlinhibit' installed (that was the case for me). 🤦‍♂️

Oh, I'll try, I just finished my partial solution when you updated your case

Deivis44 avatar May 29 '25 17:05 Deivis44

6 minutes later...... It is probably because you don't have 'wlinhibit' installed (that was the case for me). 🤦‍♂️

How did you install it? I'm having an error in yay I think that's the reason why the script for this config just skipped it

Deivis44 avatar May 29 '25 17:05 Deivis44

I am on Fedora, there it isnt even in the repo, so I just built it myself:

git clone https://github.com/0x5a4/wlinhibit.git
cd wlinhibit
meson setup build
cd build
meson install

johannSo avatar May 29 '25 17:05 johannSo

Hi, indeed, you need wlinhibit. I'm glad to see that the button correctly checks for it instead of showing as activated when it's not.

Anyway, I'll try to replace wlinhibit today, but for now you could try to install the git version or the one precompiled from Chaotic AUR.

Axenide avatar May 29 '25 17:05 Axenide

I am on Fedora, there it isnt even in the repo, so I just built it myself:

git clone https://github.com/0x5a4/wlinhibit.git
cd wlinhibit
meson setup build
cd build
meson install

Yessir, worked in my arch, tx

Deivis44 avatar May 29 '25 17:05 Deivis44

Hi, indeed, you need wlinhibit. I'm glad to see that the button correctly checks for it instead of showing as activated when it's not.

Anyway, I'll try to replace wlinhibit today, but for now you could try to install the git version or the one precompiled from Chaotic AUR.

Can I configure a keybind to activate caffeine in the dock and visualize the change as I did? I don't find where in the source code this button has an action or how

Deivis44 avatar May 29 '25 17:05 Deivis44

The button just runs wlinhibit, so you can just add a keybind in Hyprland for this:

pgrep wlinhibit && pkill wlinhibit || wlinhibit &

Axenide avatar May 29 '25 18:05 Axenide

Though it won't update the button, because the button updates on start and on click. I'll add something to trigger it.

Axenide avatar May 29 '25 18:05 Axenide

Alright, bind this:

fabric-cli exec ax-shell 'notch.dashboard.widgets.buttons.caffeine_button.toggle_wlinhibit()'

Axenide avatar May 29 '25 18:05 Axenide

@Deivis44 I added a shortcut for Caffeine. Just update and reapply the config. :)

Axenide avatar May 30 '25 02:05 Axenide