[Xfce4-commits] <xfce4-settings:xrandr-display-settings> Refresh the ui when a change is detected

Jérôme Guelfucci noreply at xfce.org
Sun Jun 13 13:04:03 CEST 2010


Updating branch refs/heads/xrandr-display-settings
         to bc87cd9dfb663aa04338c1de37786c99097e6533 (commit)
       from 926e3aa02318d37c684d3caa74cf3637099ae9fb (commit)

commit bc87cd9dfb663aa04338c1de37786c99097e6533
Author: Lionel Le Folgoc <mrpouit at gmail.com>
Date:   Sat Jun 12 16:32:34 2010 +0200

    Refresh the ui when a change is detected
    
    Listen to events from X and rebuild the XfceRandr view and refresh the dialog
    when a "screen changed" notification comes up (e.g. when the user plays with
    another xrandr tool).
    
    Unfortunately, no event seems to be emitted when an output is physically
    {un,}plugged (it will be detected only when the hardware is reprobbed, with
    "xrandr -q" or by closing and reopening xfce4-displays-settings).

 dialogs/display-settings/main.c       |   49 +++++++++++++++++++++++++++++----
 dialogs/display-settings/xfce-randr.h |    6 +++-
 2 files changed, 48 insertions(+), 7 deletions(-)

diff --git a/dialogs/display-settings/main.c b/dialogs/display-settings/main.c
index b3e6908..a01e92d 100644
--- a/dialogs/display-settings/main.c
+++ b/dialogs/display-settings/main.c
@@ -724,6 +724,34 @@ display_settings_dialog_new (GtkBuilder *builder)
 
 
 
+#ifdef HAS_RANDR_ONE_POINT_TWO
+static GdkFilterReturn
+screen_on_event (GdkXEvent *xevent,
+                 GdkEvent  *event,
+                 gpointer   data)
+{
+    GtkBuilder *builder = data;
+    XEvent     *e = xevent;
+    gint        event_num;
+
+    if (!e)
+        return GDK_FILTER_CONTINUE;
+
+    event_num = e->type - XFCE_RANDR_EVENT_BASE (xfce_randr);
+
+    if (event_num == RRScreenChangeNotify)
+    {
+        xfce_randr_reload (xfce_randr);
+        display_settings_treeview_populate (builder);
+    }
+
+    /* Pass the event on to GTK+ */
+    return GDK_FILTER_CONTINUE;
+}
+#endif
+
+
+
 gint
 main (gint argc, gchar **argv)
 {
@@ -857,14 +885,18 @@ main (gint argc, gchar **argv)
             dialog = display_settings_dialog_new (builder);
             g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (display_settings_dialog_response), builder);
 
-#if 0
 #ifdef HAS_RANDR_ONE_POINT_TWO
-            if (xfce_randr == NULL)
-#endif
+            if (xfce_randr != NULL)
             {
-                /* destroy the devices box */
-                box = gtk_builder_get_object (builder, "randr-devices-tab");
-                gtk_widget_destroy (box);
+                XFCE_RANDR_EVENT_BASE (xfce_randr) = event_base;
+                /* set up notifications */
+                XRRSelectInput (gdk_x11_display_get_xdisplay (display),
+                                GDK_WINDOW_XID (gdk_get_default_root_window ()),
+                                RRScreenChangeNotifyMask);
+                gdk_x11_register_standard_event_type (display,
+                                                      event_base,
+                                                      RRNotify + 1);
+                gdk_window_add_filter (gdk_get_default_root_window (), screen_on_event, builder);
             }
 #endif
 
@@ -883,6 +915,11 @@ main (gint argc, gchar **argv)
             g_error_free (error);
         }
 
+#ifdef HAS_RANDR_ONE_POINT_TWO
+        if (xfce_randr != NULL)
+            gdk_window_remove_filter (gdk_get_default_root_window (), screen_on_event, builder);
+#endif
+
         /* release the builder */
         g_object_unref (G_OBJECT (builder));
 
diff --git a/dialogs/display-settings/xfce-randr.h b/dialogs/display-settings/xfce-randr.h
index e687394..517666b 100644
--- a/dialogs/display-settings/xfce-randr.h
+++ b/dialogs/display-settings/xfce-randr.h
@@ -24,6 +24,7 @@
 #ifndef __XFCE_RANDR_H__
 #define __XFCE_RANDR_H__
 
+#define XFCE_RANDR_EVENT_BASE(randr)      (randr->event_base)
 #define XFCE_RANDR_MODE(randr)            (randr->mode[randr->active_output])
 #define XFCE_RANDR_PREFERRED_MODE(randr)  (randr->preferred_mode[randr->active_output])
 #define XFCE_RANDR_ROTATION(randr)        (randr->rotation[randr->active_output])
@@ -79,7 +80,10 @@ struct _XfceRandr
 
     /* display for this randr config */
     GdkDisplay          *display;
-    
+
+    /* event base for notifications */
+    gint                 event_base;
+
     /* screen resource for this display */
     XRRScreenResources  *resources;
 



More information about the Xfce4-commits mailing list