[ohm] ohm: Branch 'master' - 4 commits

Rob Taylor robtaylor at kemper.freedesktop.org
Thu Sep 13 05:14:52 PDT 2007


 configure.in                        |   16 +++++++++++++---
 libidletime/libidletime.c           |   35 +++++++++++++++++++++++++++++++++--
 libidletime/libidletime.h           |    4 +++-
 ohmd/ohm-plugin.c                   |    1 +
 plugins/glue/idle/ohm-plugin-idle.c |   30 +++++++++++++++++++++---------
 plugins/glue/xorg/ohm-plugin-xorg.c |   18 ++++++++++++++----
 6 files changed, 85 insertions(+), 19 deletions(-)

New commits:
diff-tree f3e2735d7d2a1dcc9a6cff9cdadba79446c5dd7d (from dcd3cd3922cff75d4d1314529be560e8d3171d15)
Author: Rob Taylor <rob.taylor at codethink.co.uk>
Date:   Thu Sep 13 12:14:40 2007 +0100

    add --without-xauth configure option
    
    Allow single-user-devices to be configured --without-xauth, which tells ohm that it can connect to the xserver without needing an .Xauthority.

diff --git a/configure.in b/configure.in
index 9eda015..1a4ecdd 100644
--- a/configure.in
+++ b/configure.in
@@ -118,16 +118,26 @@ single_user_device="yes"
 if test "$single_user_device" = yes; then
 	AC_DEFINE(OHM_SINGLE_USER_DEVICE, 1, [Whether OHM is built for a single-user device with a known .Xauthority location])
 
+	AC_ARG_WITH(xauth,
+		[AC_HELP_STRING([--without-xauth],
+			[Whether xauth is needed to access the Xserver.]
+			)],
+		[with_xauth="$withval"], [with_xauth="yes"]
+		)
+
+
 	AC_ARG_WITH(xauth-dir,
 		[AC_HELP_STRING([--with-xauth-dir=<dir>],
 			[directory where we can find .Xauthority (for single-user device)]
 			)]
 		)
 
-	if test -z "$with_xauth_dir"; then
-		AC_MSG_ERROR([Must use --with-xauth-dir for a single-user device]) 
+	if test "x$with_xauth" = "xno"; then
+		AC_DEFINE(OHM_DEVICE_NO_XAUTH, 1, [No Xauth needed for Xserver access])
+	elif test -z "$with_xauth_dir"; then
+		AC_MSG_ERROR([Must use --without-xauth or --with-xauth-dir for a single-user device])
 	else
-		AC_DEFINE(OHM_DEVICE_XAUTH_DIR, "$xauth_dir", [Where to find .Xauthority])
+		AC_DEFINE_UNQUOTED(OHM_DEVICE_XAUTH_DIR, "$with_xauth_dir", [Where to find .Xauthority])
 	fi
 fi
 
diff --git a/plugins/glue/xorg/ohm-plugin-xorg.c b/plugins/glue/xorg/ohm-plugin-xorg.c
index 28b3f1a..3bca47b 100644
--- a/plugins/glue/xorg/ohm-plugin-xorg.c
+++ b/plugins/glue/xorg/ohm-plugin-xorg.c
@@ -32,10 +32,13 @@ static gboolean
 plugin_poll_startup (gpointer data)
 {
 	OhmPlugin *plugin = (OhmPlugin *) data;
+
+#ifdef OHM_SINGLE_USER_DEVICE
+#ifndef OHM_DEVICE_NO_XAUTH
+
 	gboolean ret;
 	const gchar *xauth;
 
-#ifdef OHM_SINGLE_USER_DEVICE
 	xauth = OHM_DEVICE_XAUTH_DIR "/.Xauthority";
 	g_debug ("xorg: testing %s", xauth);
 	ret = g_file_test (xauth, G_FILE_TEST_EXISTS);
@@ -53,14 +56,21 @@ plugin_poll_startup (gpointer data)
 		g_debug ("xorg: no .Xauthority found");
 		return TRUE;
 	}
+	setenv ("XAUTHORITY", xauth, 1);
+	g_debug ("Using XAUTHORITY %s", xauth);
+#else
+	g_debug ("Not using XAuth");
+#endif
+
 #else
 #error ConsoleKit support not yet implemented
 #endif
+
+	setenv ("DISPLAY", ":0", 1);
+
 	/* woot! X is alive */
 	g_debug ("Got X!");
 	ohm_plugin_conf_set_key (plugin, "xorg.has_xauthority", 1);
-	setenv ("XAUTHORITY", xauth, 1);
-	setenv ("DISPLAY", ":0", 1);
 	/* we don't need to poll anymore */
 	return FALSE;
 }
diff-tree dcd3cd3922cff75d4d1314529be560e8d3171d15 (from 7569bf2c692216927ff3690a3fc24a58d33206cb)
Author: Rob Taylor <rob.taylor at codethink.co.uk>
Date:   Thu Sep 13 12:03:53 2007 +0100

    xorg plugin: first call of plugin_poll_startup handled incorrectly
    
    In plugin_initialize, the return value of the first call to plugin_poll_startup is handled incorrectly - as plugin_poll_startup is a GSourceFunc, it returns FALSE when it's successful..

diff --git a/plugins/glue/xorg/ohm-plugin-xorg.c b/plugins/glue/xorg/ohm-plugin-xorg.c
index f91c8af..28b3f1a 100644
--- a/plugins/glue/xorg/ohm-plugin-xorg.c
+++ b/plugins/glue/xorg/ohm-plugin-xorg.c
@@ -82,7 +82,7 @@ plugin_initialize (OhmPlugin *plugin)
 
 	/* naive try... we might be running under X */
 	ret = plugin_poll_startup (plugin);
-	if (ret == FALSE) {
+	if (ret == TRUE) {
 		/* we failed to connect to X - maybe X is not alive yet? */
 		g_debug ("Could not connect to X, polling until we can");
 		g_timeout_add (2000, plugin_poll_startup, plugin);
diff-tree 7569bf2c692216927ff3690a3fc24a58d33206cb (from dda8bc9397a3f81e265a68b184cd4293b3734b6d)
Author: Rob Taylor <rob.taylor at codethink.co.uk>
Date:   Wed Sep 5 12:52:13 2007 +0100

    add some debug for which plugin changed which key

diff --git a/ohmd/ohm-plugin.c b/ohmd/ohm-plugin.c
index 1480ebd..dcce2a6 100644
--- a/ohmd/ohm-plugin.c
+++ b/ohmd/ohm-plugin.c
@@ -159,6 +159,7 @@ ohm_plugin_conf_set_key (OhmPlugin   *pl
 	 * itself if it's interest in that key
 	 */
 	plugin->priv->key_being_set = key;
+	ohm_debug ("plugin %s setting key %s to %d", plugin->priv->name, key, value);
 	ret = ohm_conf_set_key_internal (plugin->priv->conf, key, value, TRUE, &error);
 	plugin->priv->key_being_set = NULL;
 
diff-tree dda8bc9397a3f81e265a68b184cd4293b3734b6d (from 437a86a4b18a2be033225432fd099bcb7f0c3114)
Author: Rob Taylor <rob.taylor at codethink.co.uk>
Date:   Wed Sep 5 13:03:07 2007 +0100

    add idle.reset
    
    Adds a reset key to the idle plugin. This allows other plugins to reset the state back to 0 and restart the timer. The idle plugin finds the current time idle and uses this as an offset until the xserver signals activity.

diff --git a/libidletime/libidletime.c b/libidletime/libidletime.c
index 0d75b50..feecef1 100644
--- a/libidletime/libidletime.c
+++ b/libidletime/libidletime.c
@@ -41,6 +41,21 @@ static void     idletime_finalize   (GOb
 
 #define LIBIDLETIME_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LIBIDLETIME_TYPE, LibIdletimePrivate))
 
+inline gint64
+xsyncvalue_to_int64 (XSyncValue *value)
+{
+	return ((guint64) XSyncValueHigh32 (*value)) << 32
+		| (guint64) XSyncValueLow32 (*value);
+}
+
+inline XSyncValue
+int64_to_xsyncvalue (gint64 value)
+{
+	XSyncValue ret;
+	XSyncIntsToValue (&ret, value, ((guint64)value) >> 32);
+	return ret;
+}
+
 struct LibIdletimePrivate
 {
 	int			 sync_event;
@@ -268,7 +283,7 @@ idletime_alarm_get (LibIdletime *idletim
  * idletime_alarm_set:
  */
 gboolean
-idletime_alarm_set (LibIdletime *idletime, guint id, guint timeout)
+idletime_alarm_set (LibIdletime *idletime, guint id, gint64 timeout)
 {
 	LibIdletimeAlarm *alarm;
 	if (id == 0) {
@@ -294,7 +309,7 @@ idletime_alarm_set (LibIdletime *idletim
 	}
 
 	/* set the timeout */
-	XSyncIntToValue (&alarm->timeout, timeout);
+	alarm->timeout = int64_to_xsyncvalue(timeout);
 
 	/* set, and start the timer */
 	idletime_xsync_alarm_set (idletime, alarm, TRUE);
@@ -332,6 +347,22 @@ idletime_alarm_remove (LibIdletime *idle
 }
 
 /**
+ * idletime_get_current_idle:
+ * @idletime: An #LibIdletime instantiation
+ * 
+ * Returns the current number of milliseconds idle
+ */
+gint64
+idletime_get_current_idle (LibIdletime *idletime)
+{
+	XSyncValue value;
+	if (XSyncQueryCounter (idletime->priv->dpy, idletime->priv->idle_counter, &value))
+		return xsyncvalue_to_int64 (&value);
+	else
+		return 0LL;
+}
+
+/**
  * idletime_class_init:
  * @klass: This class instance
  **/
diff --git a/libidletime/libidletime.h b/libidletime/libidletime.h
index cfd7a81..dfaee7e 100644
--- a/libidletime/libidletime.h
+++ b/libidletime/libidletime.h
@@ -55,10 +55,12 @@ void		 idletime_alarm_reset_all		(LibIdl
 guint		 idletime_alarm_get			(LibIdletime	*idletime);
 gboolean	 idletime_alarm_set			(LibIdletime	*idletime,
 							 guint		 id,
-							 guint		 timeout);
+							 gint64		 timeout);
 gboolean	 idletime_alarm_remove			(LibIdletime	*idletime,
 							 guint		 id);
 
+gint64		 idletime_get_current_idle		(LibIdletime *idletime);
+
 G_END_DECLS
 
 #endif	/* __LIBIDLETIME_H */
diff --git a/plugins/glue/idle/ohm-plugin-idle.c b/plugins/glue/idle/ohm-plugin-idle.c
index 5c6bff4..3b55202 100644
--- a/plugins/glue/idle/ohm-plugin-idle.c
+++ b/plugins/glue/idle/ohm-plugin-idle.c
@@ -26,11 +26,12 @@
 #include <stdlib.h>
 
 static LibIdletime *idletime = NULL;
+static gint64 timeout_offset = 0;
 
 enum {
 	CONF_XORG_HASXAUTH_CHANGED,
 	CONF_IDLE_TIMEOUT_CHANGED,
-	CONF_IDLE_STATE_CHANGED,
+	CONF_IDLE_RESET,
 	CONF_LAST
 };
 
@@ -43,6 +44,7 @@ ohm_alarm_expired_cb (LibIdletime *idlet
 	if (alarm == 0 ) {
 		/* activity, reset state to 0 */
 		ohm_plugin_conf_set_key (plugin, "idle.state", 0);
+		timeout_offset = 0;
 	} else {
 		ohm_plugin_conf_get_key (plugin, "idle.state", &state);
 		ohm_plugin_conf_set_key (plugin, "idle.state", state+1);
@@ -68,6 +70,7 @@ plugin_connect_idletime (OhmPlugin *plug
 			  G_CALLBACK (ohm_alarm_expired_cb), plugin);
 
 	ohm_plugin_conf_set_key (plugin, "idle.state", 0);
+	ohm_plugin_conf_set_key (plugin, "idle.reset", 0);
 
 	ohm_plugin_conf_get_key (plugin, "idle.timeout", &timeout);
 
@@ -111,6 +114,7 @@ plugin_initalize (OhmPlugin *plugin)
 static void
 plugin_notify (OhmPlugin *plugin, gint id, gint value)
 {
+	g_debug ("idle got notify, id = %d, value = %d", id, value);
 	gint timeout;
 	if (id == CONF_XORG_HASXAUTH_CHANGED) {
 		if (value == 1) {
@@ -120,12 +124,20 @@ plugin_notify (OhmPlugin *plugin, gint i
 	if (idletime) {
 		if (id == CONF_IDLE_TIMEOUT_CHANGED ) {
 			g_debug("setting new timeout %d", value);
-			idletime_alarm_set (idletime, 1, value);
-		} else if (id == CONF_IDLE_STATE_CHANGED ) {
-			if (value == 0) {
-				ohm_plugin_conf_get_key (plugin, "idle.timeout", &timeout);
-				idletime_alarm_set (idletime, 1, timeout);
-			}
+			idletime_alarm_set (idletime, 1, timeout_offset+value);
+		} else if (id == CONF_IDLE_RESET && value == 1) {
+			timeout_offset = idletime_get_current_idle (idletime);
+			ohm_plugin_conf_get_key (plugin, "idle.timeout", &timeout);
+			g_debug ("idle plugin reset. current timeout = %d, timeout-offset = %lld", timeout, timeout_offset);
+
+			/* most of the time this isn't needed as the below set
+			 * of idle.state will result in a timout change,
+			 * but just incase it doesn't happen. or the
+			 * new timeout is the same as the old..
+			 */
+			idletime_alarm_set (idletime, 1, timeout_offset+timeout);
+			ohm_plugin_conf_set_key (plugin, "idle.reset", 0);
+			ohm_plugin_conf_set_key (plugin, "idle.state", 0);
 		}
 	}
 }
@@ -148,9 +160,9 @@ OHM_PLUGIN_DESCRIPTION (
 
 OHM_PLUGIN_REQUIRES ("xorg");
 
-OHM_PLUGIN_PROVIDES ("idle.state", "idle.timeout");
+OHM_PLUGIN_PROVIDES ("idle.state", "idle.timeout", "idle.reset");
 
 OHM_PLUGIN_INTERESTED (
 	{"xorg.has_xauthority", CONF_XORG_HASXAUTH_CHANGED},
 	{"idle.timeout", CONF_IDLE_TIMEOUT_CHANGED},
-	{"idle.state", CONF_IDLE_STATE_CHANGED});
+	{"idle.reset", CONF_IDLE_RESET});


More information about the Ohm-devel mailing list