feat: native module for idle detection on wayland#1198
feat: native module for idle detection on wayland#1198T1mbits wants to merge 10 commits intoVencord:mainfrom
Conversation
Client should now in theory idle when system is suspended on all platforms, after 10 minutes on windows, mac, and xorg (I think?), and when the lockscreen is triggered on windows and mac. Still need to work on implementing wayland idle and lockscreen detection, most likely in a native module. Only tested with NixOS with hyprland, as expected getSystemIdleTime doesn't work and neither does lock-screen or unlock-screen events, but suspend and resume events work fine.
Uses vesktop-wayland-protocols package to read the ext-idle-notify-v1 wayland protocol to detect idle timeouts natively.
CustomIdle should in theory work completely for windows and macos out of the box already (I can't really test it though)
|
Thanks for taking the time to work on this! A few points:
|
Setting the CustomIdle timeout slider to 0 should now prevent you from ever going idle automatically.
I figured that would be the case. I'll see if I can put the source code into a
I'll see if I can figure out how to port it to Vencord, but it might take a little bit to figure out the codebase. Thanks for the quick response! |
|
Well it'd be a bit difficult to move it to Vencord while also having the native module, so I'm not sure about that. Don't worry about that part for now |
Moved vesktop-wayland-protocols source code into /packages mimicking libvesktop for binary naming and locations, and removed vesktop-wayland-protocols as a dependency
|
Moved the package into |
|
This works an absolute charm on Plasma Wayland! Thank you T1mbits. |
|
Actually, the only issue I've noticed is that Discord (Vesktop) doesn't auto-idle if my computer is on the lockscreen, which I've set Plasma to activate after five minutes. I don't know exactly where the problem is, but I'd guess that's something Plasma developers need to fix. |
|
it’s an unfixable problem for wayland, there isn’t a widely used protocol that allows clients to know if the system is locked or not so lockscreen idling is exclusive to windows and macos :/ |
|
Got it, makes sense to me. So when the lockscreen is active (at least on Plasma as per the example), it just won't ever detect the user as idle? In any case it's not a big issue. |
|
Not quite, it just doesn't know the lockscreen is active and as such will just continue acting as normal. That's why it sets the status back to online when you move your mouse on the lockscreen. I've already moved most of the functionality to a Vencord plugin btw, this PR will pretty much just be for wayland module (I'll be pushing a commit later tonight that removes the functionality from this PR) so it'd be great if you could test out the plugin version instead :). The plugin already works with this vesktop patch though since it already exposes the wayland module. |
|
I'll do that tomorrow. Thanks for letting me know! |
Vesktop still needs to provide the native node module for Wayland
I don't see how this is better, its still just a prebuilt binary manually committed into the tree? I think the idea was that building libvesktop should also build the node addon and that no binaries are committed or downloaded. |
|
Not quite sure what you mean but the reason I didn’t just add onto libvesktop is because I don’t know how to program in C++ and I couldn’t get an environment working. I moved the module and source code into the main repo with the hopes that someone could rebuild and verify the code and binary directly themselves without forcing a third party npm dependency |
The problem is the prebuilt binaries though, Rust builds are generally not reproducible so verification would be difficult. I doubt the maintainers would be fine with that anyway, your changes would need to be integrated into the build system. |
|
The maintainers are also free to completely replace the binaries with their own compiled versions if they want. I wrote it in rust because, as I said, I couldn't write in C++ to extend libvesktop. If you want you can rewrite the module into libvesktop yourself to circumvent whatever issue you see with the way it currently is, but I unfortunately can't as of right now. |
I might give it a shot if I get some time today :) |
|
I added a prototype C++ port of your code to libvesktop in be04d6b, so far completely untested or integrated, it builds though. It's missing the destructor for |
|
Fixed some bugs and now the latest commit on https://github.com/MatthewCash/Vesktop/tree/native-idle works for me. |
If you don't mind adding logic for specific desktop environments, it is possible to check the lock screen state using dbus. For KDE Plasma with kscreenlocker, you can query the lock screen state using dbus: dbus-send --dest=org.freedesktop.ScreenSaver --type=method_call --print-reply --session '/org/freedesktop/ScreenSaver' 'org.freedesktop.ScreenSaver.GetActive'For GNOME, there appears to be an equivalent (found mentioned here): dbus-send --print-reply=literal --session --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.GetActive |
|
Yeah I was aware of those when I originally wrote the module but I didn’t go through with it because I felt it was kind of a bandaid solution (and I also don’t use either environment so I couldn’t even test it lol). Might be worth asking @MatthewCash about it though since they seem to be capable of actually implementing something into libvesktop. I’ll probably get around to looking at their implementation when I get back and might close or replace this pr with their rewrite too. Not quite sure yet though because there’s still some other stuff I never got around to fixing or testing but I appreciate the suggestion |
|
I don't think Gnome even supports |
Adds a native node module for native idle detection on Wayland linux. To be used by the NativeIdle plugin.
Fixes #396