Skip to content

feat: native module for idle detection on wayland#1198

Draft
T1mbits wants to merge 10 commits intoVencord:mainfrom
T1mbits:native-idle
Draft

feat: native module for idle detection on wayland#1198
T1mbits wants to merge 10 commits intoVencord:mainfrom
T1mbits:native-idle

Conversation

@T1mbits
Copy link

@T1mbits T1mbits commented Oct 31, 2025

Adds a native node module for native idle detection on Wayland linux. To be used by the NativeIdle plugin.

Fixes #396

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)
@Vendicated
Copy link
Member

Thanks for taking the time to work on this!

A few points:

  • Adding a third party native binary isn't something I'm comfortable doing. It would have to be first party (i.e. part of libvesktop)
  • This doesn't depend on any Vesktop specific things and has a lot of patches which have the potential to break regularely, so it would be much better to have this in the Vencord codebase instead of the Vesktop codebase. That way we can push fixes to it immediately without having to publish an entire new Vesktop release

Setting the CustomIdle timeout slider to 0 should now prevent you from
ever going idle automatically.
@T1mbits
Copy link
Author

T1mbits commented Oct 31, 2025

Adding a third party native binary isn't something I'm comfortable doing

I figured that would be the case. I'll see if I can put the source code into a /packages dir now that I know how napi-rs works better than before. Again, I don't really know c++ so I'm not sure I'd be able to integrate it into libvesktop

have this in the Vencord codebase instead of the Vesktop codebase

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!

@Vendicated
Copy link
Member

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
@T1mbits
Copy link
Author

T1mbits commented Oct 31, 2025

Moved the package into /packges, seems to work fine? Again, should probably test on other platforms and compositors. If you don't trust the prebuilt binaries you can feel free to rebuild them yourself.

@nixRidge
Copy link

nixRidge commented Nov 3, 2025

This works an absolute charm on Plasma Wayland! Thank you T1mbits.

@nixRidge
Copy link

nixRidge commented Nov 6, 2025

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.

@T1mbits
Copy link
Author

T1mbits commented Nov 6, 2025

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 :/

@nixRidge
Copy link

nixRidge commented Nov 6, 2025

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.
I'm working around it by using the CustomIdle plugin and making it set my status to idle just before the screen locks (4,8 minutes), and in that case everything is fine. It even sets my status back to online when I move my mouse/click on the lockscreen.

@T1mbits
Copy link
Author

T1mbits commented Nov 6, 2025

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.

@nixRidge
Copy link

nixRidge commented Nov 6, 2025

I'll do that tomorrow. Thanks for letting me know!

Vesktop still needs to provide the native node module for Wayland
@T1mbits T1mbits changed the title feat: native idle support feat: native module for idle detection on wayland Nov 7, 2025
@MatthewCash
Copy link

Moved the package into /packges, seems to work fine? Again, should probably test on other platforms and compositors. If you don't trust the prebuilt binaries you can feel free to rebuild them yourself.

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.

@T1mbits
Copy link
Author

T1mbits commented Dec 23, 2025

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

@MatthewCash
Copy link

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.

@T1mbits
Copy link
Author

T1mbits commented Dec 23, 2025

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.

@MatthewCash
Copy link

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 :)

@MatthewCash
Copy link

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 IdleNotifier, I'm not sure what the best approach for that is yet.

@MatthewCash
Copy link

Fixed some bugs and now the latest commit on https://github.com/MatthewCash/Vesktop/tree/native-idle works for me.

@eth-p
Copy link

eth-p commented Dec 28, 2025

it’s an unfixable problem for wayland, there isn’t a widely used protocol that allows clients to know if the system is locked

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:
https://invent.kde.org/plasma/kscreenlocker/-/blob/Plasma/6.5/dbus/org.freedesktop.ScreenSaver.xml?ref_type=heads

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

@T1mbits
Copy link
Author

T1mbits commented Dec 28, 2025

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

@MatthewCash
Copy link

I don't think Gnome even supports ext_idle_notifier_v1 so if we're adding bandaid/nonportable solutions then calling Mutter's GetIdletime method might also be worthwhile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Do not auto idle if user is still actively using their computer (e.g. mouse / keyboard activity)

5 participants