[gnome-settings-daemon] power: Add ability to override XRandR detection
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] power: Add ability to override XRandR detection
- Date: Tue, 22 Jan 2013 15:20:55 +0000 (UTC)
commit 8519828df96618819dfa0d4b6af9bb94d6991ca6
Author: Bastien Nocera <hadess hadess net>
Date: Tue Jan 22 15:21:43 2013 +0100
power: Add ability to override XRandR detection
For our tests. The only thing we know how to do is check whether
there's an external screen or not, so that's what we allow to override
by creating a GSD_MOCK_EXTERNAL_MONITOR file in the current directory
with either '0' (no external screen) or '1' (with external screen) as
the content. Send the SIGUSR1 signal to gsd-test-power to generate
a fake XRandR change event, and get the file re-read.
echo 1 > GSD_MOCK_EXTERNAL_MONITOR
killall -USR2 gsd-test-power
plugins/power/Makefile.am | 2 +-
plugins/power/gpm-common.c | 18 ++++++++++++++++++
plugins/power/gsd-power-manager.c | 14 ++++++++++++++
3 files changed, 33 insertions(+), 1 deletions(-)
---
diff --git a/plugins/power/Makefile.am b/plugins/power/Makefile.am
index 83b7170..2397c8a 100644
--- a/plugins/power/Makefile.am
+++ b/plugins/power/Makefile.am
@@ -68,7 +68,7 @@ gsd_test_power_SOURCES = \
test-power.c
gsd_test_power_CFLAGS = $(libpower_la_CFLAGS)
-gsd_test_power_CPPFLAGS = $(libpower_la_CPPFLAGS)
+gsd_test_power_CPPFLAGS = $(libpower_la_CPPFLAGS) -DMOCK_EXTERNAL_MONITOR=1
gsd_test_power_LDADD = \
-lm \
$(top_builddir)/plugins/common/libcommon.la \
diff --git a/plugins/power/gpm-common.c b/plugins/power/gpm-common.c
index fc8c0c5..1b053a1 100644
--- a/plugins/power/gpm-common.c
+++ b/plugins/power/gpm-common.c
@@ -1606,6 +1606,24 @@ external_monitor_is_connected (GnomeRRScreen *screen)
GnomeRROutput **outputs;
guint i;
+#ifdef MOCK_EXTERNAL_MONITOR
+ char *mock_external_monitor_contents;
+ gboolean ret;
+
+ if (g_file_get_contents ("GSD_MOCK_EXTERNAL_MONITOR", &mock_external_monitor_contents, NULL, NULL)) {
+ if (mock_external_monitor_contents[0] == '1') {
+ g_free (mock_external_monitor_contents);
+ return TRUE;
+ } else if (mock_external_monitor_contents[0] == '0') {
+ g_free (mock_external_monitor_contents);
+ return FALSE;
+ }
+
+ g_warning ("Unhandled value for GSD_MOCK_EXTERNAL_MONITOR contents: %s", mock_external_monitor_contents);
+ g_free (mock_external_monitor_contents);
+ }
+#endif /* MOCK_EXTERNAL_MONITOR */
+
/* see if we have more than one screen plugged in */
outputs = gnome_rr_screen_list_outputs (screen);
for (i = 0; outputs[i] != NULL; i++) {
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index 3347bd3..624a13d 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -30,6 +30,7 @@
#include <libupower-glib/upower.h>
#include <libnotify/notify.h>
#include <canberra-gtk.h>
+#include <glib-unix.h>
#include <gio/gunixfdlist.h>
#define GNOME_DESKTOP_USE_UNSTABLE_API
@@ -3212,6 +3213,15 @@ on_randr_event (GnomeRRScreen *screen, gpointer user_data)
setup_inhibit_lid_switch_timer (manager);
}
+#ifdef MOCK_EXTERNAL_MONITOR
+static gboolean
+received_sigusr2 (GsdPowerManager *manager)
+{
+ on_randr_event (NULL, manager);
+ return TRUE;
+}
+#endif /* MOCK_EXTERNAL_MONITOR */
+
static gboolean
screen_lock_done_cb (gpointer data)
{
@@ -3447,6 +3457,10 @@ gsd_power_manager_start (GsdPowerManager *manager,
g_signal_connect (manager->priv->rr_screen, "changed", G_CALLBACK (on_randr_event), manager);
on_randr_event (manager->priv->rr_screen, manager);
+#ifdef MOCK_EXTERNAL_MONITOR
+ g_unix_signal_add (SIGUSR2, (GSourceFunc) received_sigusr2, manager);
+#endif /* MOCK_EXTERNAL_MONITOR */
+
/* ensure the default dpms timeouts are cleared */
ret = gnome_rr_screen_set_dpms_mode (manager->priv->rr_screen,
GNOME_RR_DPMS_ON,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]