hyprwm / hypridle

Hyprland's idle daemon
BSD 3-Clause "New" or "Revised" License
403 stars 25 forks source link

Doesn't work till locked once manually. #7

Closed niksingh710 closed 9 months ago

niksingh710 commented 9 months ago

Config

general {
    lock_cmd = swaylock -f                           
    unlock_cmd = killall -q -s SIGUSR1 swaylock       
    before_sleep_cmd = loginctl lock-session; sleep 2  
    ignore_dbus_inhibit = false        
}

listener {
    timeout = 10                          
    on-timeout = swaylock -f
}

listener {
    timeout = 20                                          
    on-timeout = sleep 1 && hyprctl dispatch dpms off       
    on-resume = sleep 1 && hyprctl dispatch dpms on         
}

listener {
    timeout = 30                                          
    on-timeout = systemctl suspend
}

# vim: commentstring=#\ %s

Logs

󰘧 killall hypridle; hypridle
[LOG] Registered timeout rule for 10s:
      on-timeout: swaylock -f
      on-resume:
[LOG] Registered timeout rule for 20s:
      on-timeout: sleep 1 && hyprctl dispatch dpms off
      on-resume: sleep 1 && hyprctl dispatch dpms on
[LOG] Registered timeout rule for 30s:
      on-timeout: systemctl suspend
      on-resume:
[LOG]   | got iface: wl_shm v1
[LOG]   | got iface: wl_drm v2
[LOG]   | got iface: zwp_linux_dmabuf_v1 v4
[LOG]   | got iface: wl_compositor v6
[LOG]   | got iface: wl_subcompositor v1
[LOG]   | got iface: wl_data_device_manager v3
[LOG]   | got iface: zwlr_export_dmabuf_manager_v1 v1
[LOG]   | got iface: zwlr_data_control_manager_v1 v2
[LOG]   | got iface: zwp_primary_selection_device_manager_v1 v1
[LOG]   | got iface: wp_viewporter v1
[LOG]   | got iface: zwlr_gamma_control_manager_v1 v1
[LOG]   | got iface: zwlr_output_power_manager_v1 v1
[LOG]   | got iface: xdg_wm_base v6
[LOG]   | got iface: wl_seat v9
[LOG]    > Bound to wl_seat v9
[LOG]   | got iface: wp_presentation v1
[LOG]   | got iface: ext_idle_notifier_v1 v1
[LOG]    > Bound to ext_idle_notifier_v1 v1
[LOG]   | got iface: zwlr_layer_shell_v1 v4
[LOG]   | got iface: org_kde_kwin_server_decoration_manager v1
[LOG]   | got iface: zxdg_decoration_manager_v1 v1
[LOG]   | got iface: zwlr_output_manager_v1 v4
[LOG]   | got iface: zwp_keyboard_shortcuts_inhibit_manager_v1 v1
[LOG]   | got iface: zwp_pointer_constraints_v1 v1
[LOG]   | got iface: zwp_relative_pointer_manager_v1 v1
[LOG]   | got iface: zwp_virtual_keyboard_manager_v1 v1
[LOG]   | got iface: zwlr_virtual_pointer_manager_v1 v2
[LOG]   | got iface: zwlr_foreign_toplevel_manager_v1 v3
[LOG]   | got iface: wp_drm_lease_device_v1 v1
[LOG]   | got iface: zwp_tablet_manager_v2 v1
[LOG]   | got iface: zwp_idle_inhibit_manager_v1 v1
[LOG]   | got iface: zxdg_exporter_v1 v1
[LOG]   | got iface: zxdg_importer_v1 v1
[LOG]   | got iface: zxdg_exporter_v2 v1
[LOG]   | got iface: zxdg_importer_v2 v1
[LOG]   | got iface: zwp_pointer_gestures_v1 v3
[LOG]   | got iface: zwp_text_input_manager_v3 v1
[LOG]   | got iface: zwp_input_method_manager_v2 v1
[LOG]   | got iface: xdg_activation_v1 v1
[LOG]   | got iface: ext_session_lock_manager_v1 v1
[LOG]   | got iface: wp_cursor_shape_manager_v1 v1
[LOG]   | got iface: wp_tearing_control_manager_v1 v1
[LOG]   | got iface: wp_single_pixel_buffer_manager_v1 v1
[LOG]   | got iface: xwayland_shell_v1 v1
[LOG]   | got iface: hyprland_toplevel_export_manager_v1 v2
[LOG]   | got iface: wp_fractional_scale_manager_v1 v1
[LOG]   | got iface: zwp_text_input_manager_v1 v1
[LOG]   | got iface: hyprland_global_shortcuts_manager_v1 v1
[LOG]   | got iface: zwlr_screencopy_manager_v1 v3
[LOG]   | got iface: zxdg_output_manager_v1 v3
[LOG]   | got iface: wl_output v4
[LOG]   | got iface: wl_output v4
[LOG] found 3 rules
[LOG] wayland done, registering dbus
[LOG] Using dbus path /org/freedesktop/login1/session/_310

This is the log and it keeps like this and nothing happens waited much long enough.

now if i lock the screen manually by issuing the command loginctl lock-session

[LOG] Got dbus .Session
[LOG] Got Lock from dbus
[LOG] Locking with swaylock -f
[LOG] Executing swaylock -f
[LOG] Process Created with pid 1404604

The logs add these few lines.

after this when i unlock everything works fine as expected.

alba4k commented 9 months ago

I can confirm that this is an issue! was trying to figure out why it wasn't working, nice catch!

Also, out of curiosity, why the "sleep 1" before dpms? Do you notice any benefits in having dpms on on resume, over just not having anything (as everything turns on by itself after I move something)?

Maybe you were trying to use hyprctl in a terminal, and noticed it didn't work without sleep 1? That would be due to you pressing enter and that counting as an input, I believe Edit: nvm I only now notice that misc:mouse_move_enables_dpms and misc:key_press_enables_dpms are false by default, and I had turned them on

niksingh710 commented 9 months ago

Also, out of curiosity, why the "sleep 1" before dpms? Do you notice any benefits in having dpms on on resume, over just not having anything (as everything turns on by itself after I move something)?

yep, sleep and hyprctl dpms is not required there. Was porting my swayidle config to hypridle and hypridle wasn't working, so putted there. 😅

vaxerski commented 9 months ago

seems to be working for me just fine, your config

niksingh710 commented 9 months ago

seems to be working for me just fine, your config

yep, just rebooted the system and it is working as expected. I guess either this need xdph working in bg or my system needed an reboot. Closing this.

niksingh710 commented 9 months ago

Nop, the issue is there. just updated hyprland-git and rebooted. hypridle won't kick in after first lock screen as mentioned in above logs.

alba4k commented 9 months ago

I guess here's my config, but I really doubt there's anything wrong with it

``` general { lock_cmd = /home/alba4k/.config/hypr/lock.sh unlock_cmd = killall -s SIGUSR1 swaylock # before_sleep_cmd = loginctl lock-session && sleep 1.5 ignore_dbus_inhibit = false } listener { timeout = 300 on-timeout = loginctl lock-session } listener { timeout = 600 on-timeout = hyprctl dispatch dpms off #on-resume = hyprctl dispatch dpms on } listener { timeout = 1800 on-timeout = systemctl suspend-then-hibernate } ```
JCMaxwell12 commented 9 months ago

Same issue, here's my config. I'm using latest hyprlang and hypridle

general {
    lock_cmd = notify-send "lock!"              # dbus/sysd lock command (loginctl lock-session) 
    unlock_cmd = notify-send "unlock!"          # same as above, but unlock
    before_sleep_cmd = notify-send "Zzz"        # command ran before sleep
    after_sleep_cmd = notify-send "Awake!"      # command ran after sleep
    ignore_dbus_inhibit = false                 # whether to ignore dbus-sent idle-inhibit requests (used by e.g. firefox or steam)
}

listener {
    timeout = 300                               # in seconds
    on-timeout = hyprctl dispatch dpms off  # command to run when timeout has passed
    on-resume = notify-send "Welcome back!"     # command to run when activity is detected after timeout has fired.
}
listener {
    timeout = 600                               # in seconds
    on-timeout = swaylock -c 000000         # command to run when timeout has passed
    on-resume = notify-send "Welcome back!"     # command to run when activity is detected after timeout has fired.
}
vaxerski commented 9 months ago

what if you set ignore dbus inhibit to true

JCMaxwell12 commented 9 months ago

Didn't fix it for me

[LOG] Registered timeout rule for 10s:
      on-timeout: hyprctl dispatch dpms off
      on-resume: notify-send "Welcome back!"
[LOG] Registered timeout rule for 600s:
      on-timeout: swaylock -c 000000
      on-resume: notify-send "Welcome back!"
[LOG]   | got iface: wl_shm v1
[LOG]   | got iface: wl_drm v2
[LOG]   | got iface: zwp_linux_dmabuf_v1 v4
[LOG]   | got iface: wl_compositor v6
[LOG]   | got iface: wl_subcompositor v1
[LOG]   | got iface: wl_data_device_manager v3
[LOG]   | got iface: zwlr_export_dmabuf_manager_v1 v1
[LOG]   | got iface: zwlr_data_control_manager_v1 v2
[LOG]   | got iface: zwp_primary_selection_device_manager_v1 v1
[LOG]   | got iface: wp_viewporter v1
[LOG]   | got iface: zwlr_gamma_control_manager_v1 v1
[LOG]   | got iface: zwlr_output_power_manager_v1 v1
[LOG]   | got iface: xdg_wm_base v5
[LOG]   | got iface: wl_seat v8
[LOG]    > Bound to wl_seat v8
[LOG]   | got iface: wp_presentation v1
[LOG]   | got iface: ext_idle_notifier_v1 v1
[LOG]    > Bound to ext_idle_notifier_v1 v1
[LOG]   | got iface: zwlr_layer_shell_v1 v4
[LOG]   | got iface: org_kde_kwin_server_decoration_manager v1
[LOG]   | got iface: zxdg_decoration_manager_v1 v1
[LOG]   | got iface: zwlr_output_manager_v1 v4
[LOG]   | got iface: zwp_keyboard_shortcuts_inhibit_manager_v1 v1
[LOG]   | got iface: zwp_pointer_constraints_v1 v1
[LOG]   | got iface: zwp_relative_pointer_manager_v1 v1
[LOG]   | got iface: zwp_virtual_keyboard_manager_v1 v1
[LOG]   | got iface: zwlr_virtual_pointer_manager_v1 v2
[LOG]   | got iface: zwlr_foreign_toplevel_manager_v1 v3
[LOG]   | got iface: wp_drm_lease_device_v1 v1
[LOG]   | got iface: zwp_tablet_manager_v2 v1
[LOG]   | got iface: zwp_idle_inhibit_manager_v1 v1
[LOG]   | got iface: zxdg_exporter_v1 v1
[LOG]   | got iface: zxdg_importer_v1 v1
[LOG]   | got iface: zxdg_exporter_v2 v1
[LOG]   | got iface: zxdg_importer_v2 v1
[LOG]   | got iface: zwp_pointer_gestures_v1 v3
[LOG]   | got iface: zwp_text_input_manager_v3 v1
[LOG]   | got iface: zwp_input_method_manager_v2 v1
[LOG]   | got iface: xdg_activation_v1 v1
[LOG]   | got iface: ext_session_lock_manager_v1 v1
[LOG]   | got iface: wp_cursor_shape_manager_v1 v1
[LOG]   | got iface: wp_tearing_control_manager_v1 v1
[LOG]   | got iface: wp_single_pixel_buffer_manager_v1 v1
[LOG]   | got iface: xwayland_shell_v1 v1
[LOG]   | got iface: hyprland_toplevel_export_manager_v1 v2
[LOG]   | got iface: wp_fractional_scale_manager_v1 v1
[LOG]   | got iface: zwp_text_input_manager_v1 v1
[LOG]   | got iface: hyprland_global_shortcuts_manager_v1 v1
[LOG]   | got iface: zwlr_screencopy_manager_v1 v3
[LOG]   | got iface: zxdg_output_manager_v1 v3
[LOG]   | got iface: wl_output v4
[LOG]   | got iface: wl_output v4
[LOG] found 2 rules
[LOG] wayland done, registering dbus
[LOG] Using dbus path /org/freedesktop/login1/session/_35
[ERR] Failed registering for /org/freedesktop/ScreenSaver, perhaps taken?
err: [org.freedesktop.DBus.Error.FileNotFound] Failed to open bus (No such file or directory)

After loginctl lock-session:

[LOG] Got dbus .Session
[LOG] Got Lock from dbus
[LOG] Locking with notify-send "lock!"
[LOG] Executing notify-send "lock!"
[LOG] Process Created with pid 26257

After the timeout:

[LOG] Idled: rule 56dfe59de030
[LOG] Running hyprctl dispatch dpms off
[LOG] Executing hyprctl dispatch dpms off
[LOG] Process Created with pid 26682
ok
[LOG] Resumed: rule 56dfe59de030
[LOG] Running notify-send "Welcome back!"
[LOG] Executing notify-send "Welcome back!"
[LOG] Process Created with pid 26684

Config:

general {
    lock_cmd = notify-send "lock!"              # dbus/sysd lock command (loginctl lock-session) 
    unlock_cmd = notify-send "unlock!"          # same as above, but unlock
    before_sleep_cmd = notify-send "Zzz"        # command ran before sleep
    after_sleep_cmd = notify-send "Awake!"      # command ran after sleep
    ignore_dbus_inhibit = true          # whether to ignore dbus-sent idle-inhibit requests (used by e.g. firefox or steam)
}

listener {
    timeout = 10                                # in seconds
    on-timeout = hyprctl dispatch dpms off  # command to run when timeout has passed
    on-resume = notify-send "Welcome back!"     # command to run when activity is detected after timeout has fired.
}
listener {
    timeout = 600                               # in seconds
    on-timeout = swaylock -c 000000         # command to run when timeout has passed
    on-resume = notify-send "Welcome back!"     # command to run when activity is detected after timeout has fired.
}
alba4k commented 9 months ago

@JCMaxwell12 pretty sure you already had hypridle running when you sent this but ok ahah

ItsDrike commented 9 months ago

I can also replicate this issue, the first commit this occurs on is 36d7238afdcbb04487212304fcbfa23e9d7bac27 (adding dbus support).

From my quick testing, I was able to figure out that the while loop in CHypridle::enterEventLoop (the 2nd one, not the one running in the thread) waits at this function call:

            m_sEventLoopInternals.loopSignal.wait(lk, [this] { return m_sEventLoopInternals.shouldProcess == true; }); // wait for events

which appears to be blocking until the manual lock-session occurs.

Details Running with this patch, introducing some debug prints: ```diff diff --git a/src/core/Hypridle.cpp b/src/core/Hypridle.cpp index af317e8..34b61ba 100644 --- a/src/core/Hypridle.cpp +++ b/src/core/Hypridle.cpp @@ -101,6 +101,7 @@ void CHypridle::enterEventLoop() { std::thread pollThr([this, &pollfds]() { while (1) { + Debug::log(LOG, "(Thread loop) Poll"); int ret = poll(pollfds, m_sDBUSState.screenSaverServiceConnection ? 3 : 2, 5000 /* 5 seconds, reasonable. It's because we might need to terminate */); if (ret < 0) { Debug::log(CRIT, "[core] Polling fds failed with {}", errno); @@ -133,8 +134,11 @@ void CHypridle::enterEventLoop() { m_sEventLoopInternals.loopRequestMutex.unlock(); // unlock, we are ready to take events std::unique_lock lk(m_sEventLoopInternals.loopMutex); - if (m_sEventLoopInternals.shouldProcess == false) // avoid a lock if a thread managed to request something already since we .unlock()ed + if (m_sEventLoopInternals.shouldProcess == false) { // avoid a lock if a thread managed to request something already since we .unlock()ed + Debug::log(LOG, "---> BLOCK"); m_sEventLoopInternals.loopSignal.wait(lk, [this] { return m_sEventLoopInternals.shouldProcess == true; }); // wait for events + Debug::log(LOG, "---> DONE"); + } m_sEventLoopInternals.loopRequestMutex.lock(); // lock incoming events ``` Here's the output from `hypridle -v` built with this patch. Letting it run for a while, this was the output:: ``` [LOG] ---> BLOCK [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll ``` Now, pretty much immediately after executing `loginctl lock-session`, this was the output: ``` [TRACE] [core] got poll event [LOG] (Thread loop) Poll [TRACE] [core] got poll event [LOG] (Thread loop) Poll [TRACE] [core] got poll event [LOG] (Thread loop) Poll [TRACE] [core] got poll event [LOG] (Thread loop) Poll [LOG] ---> DONE [TRACE] got dbus event [TRACE] [core] got poll event [LOG] Got dbus .Session [LOG] Got Lock from dbus [LOG] ---> BLOCK [LOG] (Thread loop) Poll [LOG] ---> DONE [TRACE] got dbus event [LOG] ---> BLOCK [TRACE] [core] got poll event [LOG] (Thread loop) Poll [TRACE] [core] got poll event [LOG] (Thread loop) Poll [TRACE] [core] got poll event [LOG] (Thread loop) Poll [TRACE] [core] got poll event [LOG] (Thread loop) Poll [LOG] [TRACE] ---> DONE[core] got poll event [TRACE] got wl event [LOG] ---> BLOCK [LOG] (Thread loop) Poll [LOG] ---> DONE [TRACE] got wl event [LOG] ---> BLOCK ``` Then, for a while, it ran similarly as before, until the 20s I have configured for my listener have elapsed, after which it now actually processed that and ran the configured command: ``` [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [LOG] (Thread loop) Poll [TRACE] [core] got poll event [LOG] (Thread loop) Poll [TRACE] [core] got poll event [LOG] (Thread loop) Poll [TRACE] [core] got poll event [LOG] (Thread loop) Poll [TRACE] [core] got poll event [LOG] (Thread loop) Poll [LOG] [TRACE] [core] got poll event [LOG] (Thread loop) Poll [TRACE] [core] got poll event [LOG] (Thread loop) Poll [TRACE] [core] got poll event [LOG] (Thread loop) Poll [TRACE] [core] got poll event [LOG] (Thread loop) Poll [TRACE] [core] got poll event [LOG] (Thread loop) Poll [TRACE] [core] got poll event [LOG] (Thread loop) Poll [TRACE] [core] got poll event [LOG] (Thread loop) Poll [TRACE] [core] got poll event [LOG] (Thread loop) Poll [TRACE] [core] got poll event [LOG] ---> DONE [TRACE] got wl event (Thread loop) Poll [LOG] Idled: rule 5933692e56c0 [LOG] Running notify-send "HyprIdle" "timeout" [LOG] Executing notify-send "HyprIdle" "timeout" [LOG] Process Created with pid 227199 [LOG] ---> BLOCK [TRACE] [core] got poll event [LOG] (Thread loop) Poll [TRACE] [core] got poll event [LOG] (Thread loop) Poll [TRACE] [core] got poll event [LOG] (Thread loop) Poll [LOG[] TRACE] [core] got poll event [LOG] (Thread loop) Poll [TRACE] ---> DONE[core] got poll event [TRACE] got wl event [LOG] Resumed: rule 5933692e56c0 [LOG] Running notify-send "HyprIdle" "resumed" [LOG] Executing notify-send "HyprIdle" "resumed" [LOG] Process Created with pid 227290 [LOG] ---> BLOCK [LOG] (Thread loop) Poll [LOG] ---> DONE [TRACE] got wl event [LOG] ---> BLOCK ```
vaxerski commented 9 months ago

patch.txt try this

ItsDrike commented 9 months ago

patch.txt try this

That fixed it!

JCMaxwell12 commented 9 months ago

Fixed it for me too

DonPiotr commented 8 months ago

For those who don't want to patch code, I found that it is enough to run it like that:

(hypridle &) && loginctl unlock-session

ItsDrike commented 8 months ago

For those who don't want to patch code, I found that it is enough to run it like that:

(hypridle &) && loginctl unlock-session @DonPiotr

Or just use the latest version with the fix lol