[gnome-settings-daemon] power: Simplify support for mock external monitor plug/unplug



commit b550bf139ca7724c6f21ee3a51a330b8d58ff1fc
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Apr 16 16:24:00 2013 +0200

    power: Simplify support for mock external monitor plug/unplug
    
    Instead of requiring sending SIGUSR2, just monitor the fake file

 plugins/power/gpm-common.c        | 40 +++++++++++++++++++++++++++++++++++++++
 plugins/power/gpm-common.h        |  1 +
 plugins/power/gsd-power-manager.c | 16 +++-------------
 3 files changed, 44 insertions(+), 13 deletions(-)
---
diff --git a/plugins/power/gpm-common.c b/plugins/power/gpm-common.c
index 55736ad..48927dd 100644
--- a/plugins/power/gpm-common.c
+++ b/plugins/power/gpm-common.c
@@ -1687,6 +1687,44 @@ randr_output_is_on (GnomeRROutput *output)
         return gnome_rr_crtc_get_current_mode (crtc) != NULL;
 }
 
+#ifdef GSD_MOCK
+static void
+mock_monitor_changed (GFileMonitor     *monitor,
+                     GFile            *file,
+                     GFile            *other_file,
+                     GFileMonitorEvent event_type,
+                     gpointer          user_data)
+{
+       GnomeRRScreen *screen = (GnomeRRScreen *) user_data;
+
+       g_debug ("Mock screen configuration changed");
+       g_signal_emit_by_name (G_OBJECT (screen), "changed");
+}
+
+static void
+screen_destroyed (gpointer  user_data,
+                 GObject  *where_the_object_was)
+{
+       g_object_unref (G_OBJECT (user_data));
+}
+#endif /* GSD_MOCK */
+
+void
+watch_external_monitor (GnomeRRScreen *screen)
+{
+#ifdef GSD_MOCK
+       GFile *file;
+       GFileMonitor *monitor;
+
+       file = g_file_new_for_commandline_arg ("GSD_MOCK_EXTERNAL_MONITOR");
+       monitor = g_file_monitor (file, G_FILE_MONITOR_NONE, NULL, NULL);
+       g_object_unref (file);
+       g_signal_connect (monitor, "changed",
+                         G_CALLBACK (mock_monitor_changed), screen);
+       g_object_weak_ref (G_OBJECT (screen), screen_destroyed, monitor);
+#endif /* GSD_MOCK */
+}
+
 gboolean
 external_monitor_is_connected (GnomeRRScreen *screen)
 {
@@ -1699,9 +1737,11 @@ external_monitor_is_connected (GnomeRRScreen *screen)
        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);
+                       g_debug ("Mock external monitor is on");
                        return TRUE;
                } else if (mock_external_monitor_contents[0] == '0') {
                        g_free (mock_external_monitor_contents);
+                       g_debug ("Mock external monitor is off");
                        return FALSE;
                }
 
diff --git a/plugins/power/gpm-common.h b/plugins/power/gpm-common.h
index 6d321c2..291f333 100644
--- a/plugins/power/gpm-common.h
+++ b/plugins/power/gpm-common.h
@@ -69,6 +69,7 @@ int              backlight_set_abs                      (GnomeRRScreen *rr_scree
                                                          GError **error);
 
 /* RandR helpers */
+void             watch_external_monitor                 (GnomeRRScreen *screen);
 gboolean         external_monitor_is_connected          (GnomeRRScreen *screen);
 
 /* Sound helpers */
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index 076c52c..4242bce 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -3330,6 +3330,8 @@ on_randr_event (GnomeRRScreen *screen, gpointer user_data)
 {
         GsdPowerManager *manager = GSD_POWER_MANAGER (user_data);
 
+        g_debug ("Screen configuration changed");
+
         if (suspend_on_lid_close (manager)) {
                 restart_inhibit_lid_switch_timer (manager);
                 return;
@@ -3347,15 +3349,6 @@ on_randr_event (GnomeRRScreen *screen, gpointer user_data)
         setup_inhibit_lid_switch_timer (manager);
 }
 
-#ifdef GSD_MOCK
-static gboolean
-received_sigusr2 (GsdPowerManager *manager)
-{
-        on_randr_event (NULL, manager);
-        return TRUE;
-}
-#endif /* GSD_MOCK */
-
 static void
 handle_suspend_actions (GsdPowerManager *manager)
 {
@@ -3548,13 +3541,10 @@ gsd_power_manager_start (GsdPowerManager *manager,
         /* set up the screens */
         if (manager->priv->rr_screen) {
                 g_signal_connect (manager->priv->rr_screen, "changed", G_CALLBACK (on_randr_event), manager);
+                watch_external_monitor (manager->priv->rr_screen);
                 on_randr_event (manager->priv->rr_screen, manager);
         }
 
-#ifdef GSD_MOCK
-        g_unix_signal_add (SIGUSR2, (GSourceFunc) received_sigusr2, manager);
-#endif /* GSD_MOCK */
-
         /* check whether a backlight is available */
         manager->priv->backlight_available = backlight_available (manager->priv->rr_screen);
 


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