[gnome-session] tools: Add an inhibit-only mode
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-session] tools: Add an inhibit-only mode
- Date: Wed, 7 Nov 2012 13:11:19 +0000 (UTC)
commit f48f42429302c1f4702dec33d2f30bd9a3310059
Author: Bastien Nocera <hadess hadess net>
Date: Wed Nov 7 13:38:29 2012 +0100
tools: Add an inhibit-only mode
It's better for some applications that want to integrate
into GNOME without using D-Bus to launch the inhibitor
directly when they need it, and stop it when they don't.
https://bugzilla.gnome.org/show_bug.cgi?id=687404
doc/man/gnome-session-inhibit.xml | 9 ++++++++-
tools/gnome-session-inhibit.c | 19 +++++++++++++++++--
2 files changed, 25 insertions(+), 3 deletions(-)
---
diff --git a/doc/man/gnome-session-inhibit.xml b/doc/man/gnome-session-inhibit.xml
index 8716246..d7ed4c8 100644
--- a/doc/man/gnome-session-inhibit.xml
+++ b/doc/man/gnome-session-inhibit.xml
@@ -20,7 +20,7 @@
<cmdsynopsis>
<command>gnome-session-inhibit</command>
<arg choice="opt" rep="repeat">OPTION</arg>
-<arg choice="req">COMMAND</arg>
+<arg choice="opt">COMMAND</arg>
</cmdsynopsis>
</refsynopsisdiv>
@@ -81,6 +81,13 @@ If this option is not specified, "idle" is assumed.
</para></listitem>
</varlistentry>
+<varlistentry>
+<term><option>--inhibit-only</option></term>
+<listitem><para>
+Do not launch COMMAND and wait forever instead
+</para></listitem>
+</varlistentry>
+
</variablelist>
</refsect1>
diff --git a/tools/gnome-session-inhibit.c b/tools/gnome-session-inhibit.c
index 4e758fc..f844e36 100644
--- a/tools/gnome-session-inhibit.c
+++ b/tools/gnome-session-inhibit.c
@@ -24,6 +24,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
+#include <stdint.h>
#include <locale.h>
#include <glib.h>
@@ -117,6 +118,7 @@ static void usage (void)
" --reason REASON The reason for inhibiting (optional)\n"
" --inhibit ARG Things to inhibit, colon-separated list of:\n"
" logout, switch-user, suspend, idle, automount\n"
+ " --inhibit-only Do not launch COMMAND and wait forever instead\n"
"\n"
"If no --inhibit option is specified, idle is assumed.\n"),
g_get_prgname ());
@@ -159,7 +161,14 @@ wait_for_child_app (char **argv)
exit (WEXITSTATUS (status));
} while (!WIFEXITED (status) && ! WIFSIGNALED(status));
+}
+static void
+wait_forever (void)
+{
+ g_print ("Inhibiting until Ctrl+C is pressed...\n");
+ while (1)
+ sleep (UINT32_MAX);
}
int main (int argc, char *argv[])
@@ -168,6 +177,7 @@ int main (int argc, char *argv[])
GsmInhibitorFlag inhibit_flags = 0;
gboolean show_help = FALSE;
gboolean show_version = FALSE;
+ gboolean no_launch = FALSE;
gint i;
const gchar *app_id = "unknown";
const gchar *reason = "not specified";
@@ -188,6 +198,8 @@ int main (int argc, char *argv[])
show_help = TRUE;
else if (strcmp (argv[i], "--version") == 0)
show_version = TRUE;
+ else if (strcmp (argv[i], "--inhibit-only") == 0)
+ no_launch = TRUE;
else if (strcmp (argv[i], "--app-id") == 0)
{
i++;
@@ -228,7 +240,7 @@ int main (int argc, char *argv[])
return 0;
}
- if (show_help || i == argc)
+ if (show_help || (i == argc && !no_launch))
{
usage ();
return 0;
@@ -239,7 +251,10 @@ int main (int argc, char *argv[])
inhibit (app_id, reason, inhibit_flags);
- wait_for_child_app (argv + i);
+ if (!no_launch)
+ wait_for_child_app (argv + i);
+ else
+ wait_forever ();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]