I want to write a Gnome-Shell extension that can tell how long a session has not received any user input. I know that calling XScreenSaverQueryInfo will give me that information, but I can't find a way to call it from my gjs extension. What do I need to do to get this to work?
Probably the easiest way to do this is to use D-Bus to call the org.gnome.Mutter.IdleMonitor.GetIdletime
method on the /org/gnome/Mutter/IdleMonitor/Core
path of org.gnome.Shell
. That will give you the time in milliseconds that the shell has not seen any user input for.
You can test this on the command line using:
while true; do
gdbus call --session --dest org.gnome.Shell \
--object-path /org/gnome/Mutter/IdleMonitor/Core \
--method org.gnome.Mutter.IdleMonitor.GetIdletime
done
You can use GIO’s D-Bus support from GJS to call the method from your extension. There’s an example here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With