简体   繁体   中英

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM