[gnome-shell] ScreenShield: wake up the screen when new notifications appear



commit 137cbbd141ee9e6e8fa635d1800930e12578ed12
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sun Jul 14 16:20:49 2013 +0200

    ScreenShield: wake up the screen when new notifications appear
    
    This way the user is immediately notified when something happens.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=703084

 js/ui/screenShield.js |    7 +++++++
 src/shell-util.c      |   29 +++++++++++++++++++++++++++++
 src/shell-util.h      |    2 ++
 3 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/js/ui/screenShield.js b/js/ui/screenShield.js
index f85871f..5e7693c 100644
--- a/js/ui/screenShield.js
+++ b/js/ui/screenShield.js
@@ -305,7 +305,9 @@ const NotificationsBox = new Lang.Class({
                                },
                                onCompleteScope: this
                              });
+
             this._updateVisibility();
+            Shell.util_wake_up_screen();
         }
     },
 
@@ -328,7 +330,10 @@ const NotificationsBox = new Lang.Class({
 
         obj.sourceBox.visible = obj.visible &&
             (source.unseenCount > (obj.musicNotification ? 1 : 0));
+
         this._updateVisibility();
+        if (obj.sourceBox.visible)
+            Shell.util_wake_up_screen();
     },
 
     _visibleChanged: function(source, obj) {
@@ -342,6 +347,8 @@ const NotificationsBox = new Lang.Class({
             source.unseenCount > (obj.musicNotification ? 1 : 0);
 
         this._updateVisibility();
+        if (obj.sourceBox.visible)
+            Shell.util_wake_up_screen();
     },
 
     _detailedChanged: function(source, obj) {
diff --git a/src/shell-util.c b/src/shell-util.c
index 0f19efc..84adad9 100644
--- a/src/shell-util.c
+++ b/src/shell-util.c
@@ -9,6 +9,8 @@
 #include <glib/gi18n-lib.h>
 #include <gtk/gtk.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gdk/gdkx.h>
+#include <X11/extensions/XTest.h>
 
 #ifdef HAVE__NL_TIME_FIRST_WEEKDAY
 #include <langinfo.h>
@@ -402,3 +404,30 @@ shell_util_create_pixbuf_from_data (const guchar      *data,
                                    bits_per_sample, width, height, rowstride,
                                    (GdkPixbufDestroyNotify) g_free, NULL);
 }
+
+/**
+ * shell_util_wake_up_screen:
+ *
+ * Send a fake key event, resetting the IDLETIME counter and
+ * causing gnome-settings-daemon to wake up the screen.
+ */
+/* Shamelessly taken from gnome-settings-daemon/plugins/power/gpm-common.c */
+void
+shell_util_wake_up_screen (void)
+{
+  static gboolean inited = FALSE;
+  static KeyCode keycode1, keycode2;
+  static gboolean first_keycode = FALSE;
+
+  if (inited == FALSE) {
+    keycode1 = XKeysymToKeycode (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), GDK_KEY_Alt_L);
+    keycode2 = XKeysymToKeycode (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), GDK_KEY_Alt_R);
+  }
+
+  gdk_error_trap_push ();
+  /* send a left or right alt key; first press, then release */
+  XTestFakeKeyEvent (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), first_keycode ? keycode1 : keycode2, 
True, CurrentTime);
+  XTestFakeKeyEvent (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), first_keycode ? keycode1 : keycode2, 
False, CurrentTime);
+  first_keycode = !first_keycode;
+  gdk_error_trap_pop_ignored ();
+}
diff --git a/src/shell-util.h b/src/shell-util.h
index 6fc2a5d..2d462c1 100644
--- a/src/shell-util.h
+++ b/src/shell-util.h
@@ -44,6 +44,8 @@ GdkPixbuf *shell_util_create_pixbuf_from_data (const guchar      *data,
                                                int                height,
                                                int                rowstride);
 
+void    shell_util_wake_up_screen             (void);
+
 G_END_DECLS
 
 #endif /* __SHELL_UTIL_H__ */


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