GApplication: fix inactivity-timeout
authorRyan Lortie <desrt@desrt.ca>
Wed, 6 Oct 2010 18:05:40 +0000 (14:05 -0400)
committerRyan Lortie <desrt@desrt.ca>
Mon, 18 Oct 2010 23:16:46 +0000 (01:16 +0200)
Create the gobject property for it.

Tweak the logic of having a pending timeout at the time that the
application starts -- run the mainloop with a use count of zero if there
is a timeout active.

gio/gapplication.c

index d9beb2d..27d60b6 100644 (file)
@@ -372,6 +372,11 @@ g_application_class_init (GApplicationClass *class)
                           "If this application instance is remote",
                           FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 
+  g_object_class_install_property (object_class, PROP_INACTIVITY_TIMEOUT,
+    g_param_spec_boolean ("inactivity-timeout", "inactivity timeout",
+                          "time (ms) to stay alive after becoming idle",
+                          0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
 
   g_application_signals[SIGNAL_STARTUP] =
     g_signal_new ("startup", G_TYPE_APPLICATION, G_SIGNAL_RUN_LAST,
@@ -984,14 +989,17 @@ g_application_run_with_arguments (GApplication *application,
 
   g_variant_unref (arguments);
 
-  if (application->priv->use_count ||
-      application->priv->flags & G_APPLICATION_FLAGS_IS_SERVICE)
+  if (application->priv->flags & G_APPLICATION_FLAGS_IS_SERVICE &&
+      !application->priv->use_count &&
+      !application->priv->inactivity_timeout_id)
     {
-      if (!application->priv->use_count)
-        application->priv->inactivity_timeout_id =
-          g_timeout_add (10000, inactivity_timeout_expired, application);
-
+      application->priv->inactivity_timeout_id =
+        g_timeout_add (10000, inactivity_timeout_expired, application);
+    }
 
+  if (application->priv->use_count ||
+      application->priv->inactivity_timeout_id)
+    {
       G_APPLICATION_GET_CLASS (application)
         ->run_mainloop (application);
       status = 0;