[gpm] [RFC] [PATCH] Turn Display Off tray icon and functionality



This patch adds a tray icon item "Display _Off" next to "Suspend" and
"Hibernate", enabling users to turn their Display off in a very
convenient manner[1].
Comments, suggestions are welcome.

[1] : http://rajeeshknambiar.wordpress.com/2009/04/03/hacking-gnome-power-manager/

PS: Please CC me on replies, I'm not subscribed.

--
Cheers,
Rajeesh
http://rajeeshknambiar.wordpress.com
diff -uNpr gnome-power-manager-2.26.0/AUTHORS gnome-power-manager-2.26.0b/AUTHORS
--- gnome-power-manager-2.26.0/AUTHORS	2008-11-03 22:30:36.000000000 +0530
+++ gnome-power-manager-2.26.0b/AUTHORS	2009-04-03 08:16:25.000000000 +0530
@@ -2,3 +2,4 @@ Richard Hughes <richard hughsie com>
 William Jon McCann <mccann jhu edu>
 Jaap A. Haitsma <jaap haitsma org>
 Benjamin Canou <bookeldor gmail com>
+Rajeesh K Nambiar <rajeeshknambiar gmail com>
diff -uNpr gnome-power-manager-2.26.0/ChangeLog gnome-power-manager-2.26.0b/ChangeLog
--- gnome-power-manager-2.26.0/ChangeLog	2009-03-16 15:11:07.000000000 +0530
+++ gnome-power-manager-2.26.0b/ChangeLog	2009-04-03 08:30:50.000000000 +0530
@@ -1,3 +1,14 @@
+2009-04-02  Rajeesh K Nambiar <rajeeshknambiar gmail com>
+	
+	* src/gpm_manager.c: (gpm_manager_action_display_off),
+	(gpm_manager_tray_icon_display_off):
+	Callback functions for "Display Off" functionality
+
+	* src/gpm_tray_icon.h:
+	* src/gpm_tray_icon.c: (gpm_tray_icon_enable_display_off),
+	(gpm_tray_icon_display_off_cb):
+	MenuItem for "Display Off"
+
 2009-03-16  Richard Hughes  <richard hughsie com>
 
 	==== Version 2.26.0 ====
diff -uNpr gnome-power-manager-2.26.0/src/gpm-manager.c gnome-power-manager-2.26.0b/src/gpm-manager.c
--- gnome-power-manager-2.26.0/src/gpm-manager.c	2009-02-11 16:38:46.000000000 +0530
+++ gnome-power-manager-2.26.0b/src/gpm-manager.c	2009-04-03 08:38:22.000000000 +0530
@@ -2,6 +2,7 @@
  *
  * Copyright (C) 2005 William Jon McCann <mccann jhu edu>
  * Copyright (C) 2005-2008 Richard Hughes <richard hughsie com>
+ * Copyright (C) Rajeesh K Nambiar <rajeeshknambiar gmail com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -444,6 +445,18 @@ gpm_manager_action_hibernate (GpmManager
 }
 
 /**
+ * gpm_manager_action_display_off:
+ **/
+static gboolean
+gpm_manager_action_display_off (GpmManager *manager, const gchar *reason)
+{
+	egg_debug ("putting display to sleep, reason: %s", reason);
+	gpm_manager_blank_screen (manager, NULL);
+	gpm_button_reset_time (manager->priv->button);
+	return TRUE;
+}
+
+/**
  * manager_policy_do:
  * @manager: This class instance
  * @policy: The policy that we should do, e.g. "suspend"
@@ -1106,6 +1119,21 @@ gpm_manager_tray_icon_suspend (GpmManage
 }
 
 /**
+ * gpm_manager_tray_icon_display_off:
+ * @manager: This class instance
+ * @tray: The tray object
+ *
+ * The icon tray display off callback, which as implemented, happens
+ * when clicked. Need to change to happen if both policy and inhibit
+ * states are valid
+ **/
+static void
+gpm_manager_tray_icon_display_off (GpmManager *manager, GpmTrayIcon *tray)
+{
+	gpm_manager_action_display_off (manager, _("User clicked on tray"));
+}
+
+/**
  * screensaver_auth_request_cb:
  * @manager: This manager class instance
  * @auth: If we are trying to authenticate
@@ -1673,6 +1701,9 @@ gpm_manager_init (GpmManager *manager)
 	g_signal_connect_object (G_OBJECT (manager->priv->tray_icon),
 				 "hibernate", G_CALLBACK (gpm_manager_tray_icon_hibernate),
 				 manager, G_CONNECT_SWAPPED);
+	g_signal_connect_object (G_OBJECT (manager->priv->tray_icon),
+				 "display_off", G_CALLBACK (gpm_manager_tray_icon_display_off),
+				 manager, G_CONNECT_SWAPPED);
 
 	gpm_manager_sync_policy_sleep (manager);
 
diff -uNpr gnome-power-manager-2.26.0/src/gpm-tray-icon.c gnome-power-manager-2.26.0b/src/gpm-tray-icon.c
--- gnome-power-manager-2.26.0/src/gpm-tray-icon.c	2009-02-11 16:38:46.000000000 +0530
+++ gnome-power-manager-2.26.0b/src/gpm-tray-icon.c	2009-04-03 08:45:51.000000000 +0530
@@ -2,6 +2,7 @@
  *
  * Copyright (C) 2005 William Jon McCann <mccann jhu edu>
  * Copyright (C) 2005-2009 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2009 Rajeesh K Nambiar <rajeeshknambiar gmail com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -64,12 +65,14 @@ struct GpmTrayIconPrivate
 	GtkStatusIcon		*status_icon;
 	gboolean		 show_suspend;
 	gboolean		 show_hibernate;
+	gboolean		 show_display_off;
 	gboolean		 show_context_menu;
 };
 
 enum {
 	SUSPEND,
 	HIBERNATE,
+	DISPLAY_OFF,
 	LAST_SIGNAL
 };
 
@@ -100,6 +103,17 @@ gpm_tray_icon_enable_hibernate (GpmTrayI
 }
 
 /**
+ * gpm_tray_icon_enable_display_off:
+ * @enabled: If we should enable (i.e. show) the display off icon
+ **/
+static void
+gpm_tray_icon_enable_display_off (GpmTrayIcon *icon, gboolean enabled)
+{
+	g_return_if_fail(GPM_IS_TRAY_ICON (icon));
+	icon->priv->show_display_off = enabled;
+}
+
+/**
  * gpm_tray_icon_enable_context_menu:
  **/
 static void
@@ -249,6 +263,18 @@ gpm_tray_icon_suspend_cb (GtkMenuItem *i
 }
 
 /**
+ * gpm_tray_icon_display_off_cb:
+ * @action: A valid GtkAction
+ **/
+static void
+gpm_tray_icon_display_off_cb (GtkMenuItem *item, gpointer data)
+{
+	GpmTrayIcon *icon = GPM_TRAY_ICON (data);
+	egg_debug("emitting display off");
+	g_signal_emit (icon, signals [DISPLAY_OFF], 0);
+}
+
+/**
  * gpm_tray_icon_show_statistics_cb:
  * @action: A valid GtkAction
  **/
@@ -295,6 +321,7 @@ gpm_tray_icon_show_about_cb (GtkMenuItem
 		"Richard Hughes <richard hughsie com>",
 		"William Jon McCann <mccann jhu edu>",
 		"Jaap A. Haitsma <jaap haitsma org>",
+		"Rajeesh K Nambiar <rajeeshknambiar gmail com>",
 		NULL};
 	const char *documenters[] = {
 		"Richard Hughes <richard hughsie com>",
@@ -385,6 +412,15 @@ gpm_tray_icon_class_init (GpmTrayIconCla
 			      NULL, NULL, g_cclosure_marshal_VOID__VOID,
 			      G_TYPE_NONE,
 			      0);
+			      
+	signals [DISPLAY_OFF] =
+		g_signal_new ("display_off",
+			      G_TYPE_FROM_CLASS (object_class),
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (GpmTrayIconClass, display_off),
+			      NULL, NULL, g_cclosure_marshal_VOID__VOID,
+			      G_TYPE_NONE,
+
 }
 
 /**
@@ -557,6 +593,16 @@ gpm_tray_icon_activate_cb (GtkStatusIcon
 		gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 	}
 
+	/* Display Off if available */
+	if (icon->priv->show_display_off) {
+		item = gtk_image_menu_item_new_with_mnemonic (_("Display _Off"));
+		image = gtk_image_new_from_icon_name (GPM_STOCK_BRIGHTNESS_LCD, GTK_ICON_SIZE_MENU);
+		gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
+		g_signal_connect (G_OBJECT (item), "activate",
+				  G_CALLBACK (gpm_tray_icon_display_off_cb), icon);
+		gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+	}
+
 	/* show the menu */
 	gtk_widget_show_all (GTK_WIDGET (menu));
 	gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
@@ -652,6 +698,7 @@ gpm_tray_icon_init (GpmTrayIcon *icon)
 	gpm_tray_icon_enable_suspend (icon, enabled && allowed_in_menu);
 	gpm_control_allowed_hibernate (icon->priv->control, &enabled, NULL);
 	gpm_tray_icon_enable_hibernate (icon, enabled && allowed_in_menu);
+	gpm_tray_icon_enable_display_off (icon, enabled);
 
 	allowed_in_menu = gconf_client_get_bool (icon->priv->conf, GPM_CONF_UI_SHOW_CONTEXT_MENU, NULL);
 	gpm_tray_icon_enable_context_menu (icon, allowed_in_menu);
diff -uNpr gnome-power-manager-2.26.0/src/gpm-tray-icon.h gnome-power-manager-2.26.0b/src/gpm-tray-icon.h
--- gnome-power-manager-2.26.0/src/gpm-tray-icon.h	2009-01-23 17:34:39.000000000 +0530
+++ gnome-power-manager-2.26.0b/src/gpm-tray-icon.h	2009-04-03 08:47:03.000000000 +0530
@@ -2,6 +2,7 @@
  *
  * Copyright (C) 2005 William Jon McCann <mccann jhu edu>
  * Copyright (C) 2005-2007 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2009 Rajeesh K Nambiar <rajeeshknambiar gmail com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -47,6 +48,7 @@ typedef struct
 	GObjectClass	parent_class;
 	void	(* suspend)				(GpmTrayIcon	*tray_icon);
 	void	(* hibernate)				(GpmTrayIcon	*tray_icon);
+	void	(* display_off)				(GpmTrayIcon	*tray_icon);
 } GpmTrayIconClass;
 
 GType		 gpm_tray_icon_get_type			(void);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]