Hi,

This patch contains a power-saving mode for Read.activity (implemented 
in the evince-olpc widget) whereby the system goes to sleep five seconds 
after the last scroll event, via a dbus call to olpc-power-manager.

This doesn't happen by default; running "touch /enable-ebook-sleep" 
enables the code in the patch.  It's a temporary solution -- eventually
we will be automatically suspending any time the CPU and display aren't 
doing anything.  The patch requires a recent kernel from the "master" 
tree of olpc-2.6, such as commit a0b2de995..

The B2 machines in the field don't have a hardware modification needed
to keep the screen image steady while the CPU is sleeping, so this is 
mostly useful for machines that OLPC has modded.  

Comments welcome.  Thanks!

- Chris.

diff --git a/shell/ev-view-private.h b/shell/ev-view-private.h
index a53fe54..9f903ae 100644
--- a/shell/ev-view-private.h
+++ b/shell/ev-view-private.h
@@ -99,6 +99,9 @@ struct _EvView {
 	gboolean presentation;
 	EvSizingMode sizing_mode;
 
+	/* Suspend timer active? */
+	guint suspend_tag;
+
 	/* Common for button press handling */
 	int pressed_button;
 
diff --git a/shell/ev-view.c b/shell/ev-view.c
index fdea8bb..2c3ef79 100644
--- a/shell/ev-view.c
+++ b/shell/ev-view.c
@@ -41,6 +41,11 @@
 #include "ev-pixbuf-cache.h"
 #include "ev-tooltip.h"
 
+#ifdef ENABLE_DBUS
+#include <dbus/dbus-glib-bindings.h>
+#include <sys/stat.h>
+#endif
+
 #define EV_VIEW_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), EV_TYPE_VIEW, EvViewClass))
 #define EV_IS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EV_TYPE_VIEW))
 #define EV_VIEW_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), EV_TYPE_VIEW, EvViewClass))
@@ -97,6 +102,7 @@ typedef enum {
 #define MAX_SCALE 4.0
 
 #define SCROLL_TIME 150
+#define SUSPEND_TIME 5000
 
 /*** Scrolling ***/
 static void       scroll_to_current_page 		     (EvView *view,
@@ -222,6 +228,7 @@ static void       page_changed_cb                            (EvPageCache
 							      EvView             *view);
 static void       on_adjustment_value_changed                (GtkAdjustment      *adjustment,
 							      EvView             *view);
+static gboolean   suspend_cb                                 (EvView             *view);
 
 /*** GObject ***/
 static void       ev_view_finalize                           (GObject            *object);
@@ -571,6 +578,34 @@ add_scroll_binding_keypad (GtkBindingSet  *binding_set,
 				G_TYPE_BOOLEAN, horizontal);
 }
 
+static gboolean
+suspend_cb (EvView *view)
+{
+	DBusGConnection *connection;
+	GError *error;
+	DBusGProxy *proxy;
+
+	error = NULL;
+	connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+	if (connection == NULL)	{
+		g_printerr ("Failed to open connection to bus: %s\n", error->message);
+		g_error_free (error);
+	}
+
+	error = NULL;
+	proxy = dbus_g_proxy_new_for_name (connection,
+					   "org.laptop.HardwareManager",
+					   "/org/laptop/HardwareManager",
+					   "org.laptop.HardwareManager");
+	if (!dbus_g_proxy_call (proxy, "set_kernel_suspend", &error, 
+				G_TYPE_INVALID, G_TYPE_INVALID)) {
+		g_printerr ("Proxy call failed: %s\n", error->message);
+		g_error_free (error);
+	}
+
+	return FALSE;
+}
+
 void
 ev_view_scroll (EvView        *view,
 	        EvScrollType   scroll,
@@ -580,6 +615,9 @@ ev_view_scroll (EvView        *view,
 	double value, increment;
 	gboolean first_page = FALSE;
 	gboolean last_page = FALSE;
+#ifdef ENABLE_DBUS
+	struct stat stat_buf;
+#endif
 
 	view->jump_to_find_result = FALSE;
 
@@ -657,8 +695,25 @@ ev_view_scroll (EvView        *view,
 		       adjustment->upper - adjustment->page_size);	
 
 	gtk_adjustment_set_value (adjustment, value);
+
+#ifdef ENABLE_DBUS
+#define SUSPEND_TAG_FILE "/enable-ebook-sleep"
+
+	/* First demo of OLPC power management.  We should only
+	   try sleeping if the user created a file for us.
+	 */
+	if (stat(SUSPEND_TAG_FILE, &stat_buf) >= 0) {	
+		/* Set a timer for five seconds, we'll go to sleep when
+		 * it hits.  If one already exists, destroy it. 
+		 */
+		if (view->suspend_tag)
+			g_source_remove(view->suspend_tag);
+		
+		view->suspend_tag = g_timeout_add(SUSPEND_TIME, (GSourceFunc)suspend_cb, view);
+	}
 }
 
+#endif
 #define MARGIN 5
 
 static void
-- 
Chris Ball   <[EMAIL PROTECTED]>
_______________________________________________
Sugar mailing list
[email protected]
http://mailman.laptop.org/mailman/listinfo/sugar

Reply via email to