Search code examples
javascriptgnomegnome-shell

Using C libraries from a Gnome-Shell extension


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?


Solution

  • 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.