From 137cbbd141ee9e6e8fa635d1800930e12578ed12 Mon Sep 17 00:00:00 2001 From: Giovanni Campagna Date: Sun, 14 Jul 2013 16:20:49 +0200 Subject: [PATCH] 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(+) diff --git a/js/ui/screenShield.js b/js/ui/screenShield.js index f85871f7a..5e7693cd0 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 0f19efcf3..84adad9aa 100644 --- a/src/shell-util.c +++ b/src/shell-util.c @@ -9,6 +9,8 @@ #include #include #include +#include +#include #ifdef HAVE__NL_TIME_FIRST_WEEKDAY #include @@ -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 6fc2a5db0..2d462c1c5 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__ */