5

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?

Dan
  • 3,665
  • 1
  • 31
  • 39
  • If you're using Gjs, then you have access to the wealth of GObject libraries provided to you via introspection. You should see if any of them can report the idle time, and if not, you may have to create your own (I would recommend Vala). – robru Jun 27 '12 at 02:17

1 Answers1

4

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.

Philip Withnall
  • 5,293
  • 14
  • 28
  • 6 years later, exactly what I was looking for! I went a different route than this long ago, but this is the correct solution and much better, and I may try it if I get the chance. – Dan Oct 03 '17 at 11:03
  • another year later, found it and used without a problem. Works like a charm. Thank you! – ahwayakchih Oct 23 '18 at 10:39