18

I have set it to "suspend when inactive" after 30 minutes.

How does it determine whether it is inactive? Is it just user input via keyboard/mouse?

If I leave a program working away - say processing a video, which takes a long time, will it suspend after 30 minutes and stop that program? Same question for long downloads, will it suspend halfway through.

Jorge Castro
  • 71,754
Jazz
  • 2,737

1 Answers1

26

Good question. Let's find out!

  1. Beginning by investigating the "Suspend when inactive for" option,

    <property ...>Suspend when inactive for</property> ...
    <object ... id="combobox_sleep_ac">
    

    we can learn that it sets a GSettings key called sleep-inactive-ac-timeout:

    widget = GTK_WIDGET (gtk_builder_get_object (..., "combobox_sleep_ac")); ...
    g_object_set_data (G_OBJECT(widget), "_gsettings_key", "sleep-inactive-ac-timeout");
    

    The documentation for this key provides a brief description:

    The amount of time in seconds the computer on AC power needs to be inactive before it goes to sleep. A value of 0 means never.

    but still doesn't explain what "inactive" means.

  2. Searching for sleep-inactive-ac-timeout leads us to GNOME Settings Daemon,

    timeout_sleep = g_settings_get_int (..., "sleep-inactive-ac-timeout");
    

    which periodically checks a property of GNOME Session called Presence.status:

    result = g_dbus_proxy_get_cached_property (...->session_presence_proxy, "status");
    

    If it finds that the status is idle, it puts the system to sleep:

    idle_set_mode (..., GSD_POWER_IDLE_MODE_SLEEP);
    

    So we need to learn how GNOME Session decides whether the system is "idle."

  3. Following backwards from where GNOME Session updates the value of Presence.status,

    gsm_presence_set_status (presence, GSM_PRESENCE_STATUS_IDLE, ...);
    

    we can see that it uses the IDLETIME counter from Xorg:

    if (... && strcmp (counters[i].name, "IDLETIME") == 0) {
        ...->counter = counters[i].counter;
    
  4. The IDLETIME counter's behavior is summarized in a blog post by the author of GNOME Power Manager:

    gnome-power-manager uses a counter inside Xorg called IDLETIME. This counter is incremented only when the user does not move the mouse, or click some keys. When the user clicks something, the IDLECOUNTER is reset.

This tells us that Ubuntu determines inactivity by measuring the amount of time that has passed since the last keystroke or mouse motion. CPU usage and network activity do not factor in.

ændrük
  • 76,794
  • as you said in last line why The CPU usage not considerable ? My doubt is i came from http://askubuntu.com/questions/215870/how-can-i-shutdown-my-pc-when-the-system-is-idle . because if i put download of 1GB file then it can take a lot of time . even I am afk My PC still doing download of that file right . That means my PC active right ? :D – Raja G Nov 22 '12 at 13:12
  • 1
    +1 for excellent investigation and breakdown. And @AgentCool, no. Activity is determined by keyboard or mouse press. Your download isn't going to press any keys and keep the PC awake. – Oxwivi Sep 12 '14 at 19:19
  • @Oxwivi thats comment almost a year ago . not after the edit. :) – Raja G Sep 13 '14 at 04:45
  • @AgentCool My bad, I didn't notice. The post was recently bumped, likely due to yesterday's edit. Was a question I was interested in, so checked it. – Oxwivi Sep 14 '14 at 06:39
  • 1
    Awesome Socratic method! – Marcelo Scofano Diniz Jan 08 '21 at 12:23
  • 1
    Is answer this still true for current GNOME/Xorg versions? AFAIK, playing media also keeps the PC awake. Additionally some programs, like e.g. Matlab, keep the PC permanently awake, too. – Dunkelkoon Jun 09 '21 at 10:48