[Xfce4-commits] <xfce4-settings:master> Use gdk functions instead of querying X directly

Nick Schermer noreply at xfce.org
Sat Aug 28 23:04:13 CEST 2010


Updating branch refs/heads/master
         to 11d96252d33480b45e431d95ffe486419fecfe09 (commit)
       from ea111065925d08d17762a3677b9cc580f219c9c1 (commit)

commit 11d96252d33480b45e431d95ffe486419fecfe09
Author: Lionel Le Folgoc <mrpouit at gmail.com>
Date:   Sat Jun 12 16:25:05 2010 +0200

    Use gdk functions instead of querying X directly
    
    gdk (might do|does) some caching, so it might be faster. It can't hurt anyway…

 dialogs/display-settings/xfce-randr.c |    8 ++---
 xfce4-settings-helper/displays.c      |   54 +++++++++++++++-----------------
 2 files changed, 28 insertions(+), 34 deletions(-)

diff --git a/dialogs/display-settings/xfce-randr.c b/dialogs/display-settings/xfce-randr.c
index 5d898ca..491d00b 100644
--- a/dialogs/display-settings/xfce-randr.c
+++ b/dialogs/display-settings/xfce-randr.c
@@ -405,7 +405,7 @@ xfce_randr_friendly_name (XfceRandr   *randr,
     unsigned long    nitems, bytes_after;
     Atom             actual_type;
     Atom             connector_type;
-    gchar           *connector_name;
+    const gchar     *connector_name;
     gchar           *friendly_name = NULL;
 
     g_return_val_if_fail (randr != NULL && output != None && name != NULL, "<null>");
@@ -414,7 +414,7 @@ xfce_randr_friendly_name (XfceRandr   *randr,
     xdisplay = gdk_x11_display_get_xdisplay (randr->display);
 
     /* try to use the connector type first, more reliable */
-    connector_type = XInternAtom (xdisplay, RR_PROPERTY_CONNECTOR_TYPE, False);
+    connector_type = gdk_x11_get_xatom_by_name (RR_PROPERTY_CONNECTOR_TYPE);
 
     if (randr->has_1_3 && connector_type != None)
     {
@@ -425,7 +425,7 @@ xfce_randr_friendly_name (XfceRandr   *randr,
             if (actual_type == XA_ATOM && actual_format == 32 && nitems == 1)
             {
                 connector_type = *((Atom *) prop);
-                connector_name = XGetAtomName (xdisplay, connector_type);
+                connector_name = gdk_x11_get_xatom_name (connector_type);
 
                 if (connector_name)
                 {
@@ -441,8 +441,6 @@ xfce_randr_friendly_name (XfceRandr   *randr,
                         friendly_name = _("Television");
                     else
                         g_warning ("Unknown or unsupported connector type.");
-
-                    XFree (connector_name);
                 }
             }
             XFree (prop);
diff --git a/xfce4-settings-helper/displays.c b/xfce4-settings-helper/displays.c
index 4a2ce19..b4d9090 100644
--- a/xfce4-settings-helper/displays.c
+++ b/xfce4-settings-helper/displays.c
@@ -168,31 +168,27 @@ xfce_displays_helper_finalize (GObject *object)
 
 #ifdef HAS_RANDR_ONE_POINT_TWO
 static void
-xfce_displays_helper_process_screen_size (Display   *xdisplay,
-                                          gint       mode_width,
-                                          gint       mode_height,
-                                          gint       crtc_pos_x,
-                                          gint       crtc_pos_y,
-                                          gint      *width,
-                                          gint      *height,
-                                          gint      *mm_width,
-                                          gint      *mm_height)
+xfce_displays_helper_process_screen_size (gint  mode_width,
+                                          gint  mode_height,
+                                          gint  crtc_pos_x,
+                                          gint  crtc_pos_y,
+                                          gint *width,
+                                          gint *height,
+                                          gint *mm_width,
+                                          gint *mm_height)
 {
     gdouble dpi = 0;
-    gint    screen = gdk_x11_get_default_screen ();
-
-    g_return_if_fail (xdisplay != NULL);
 
     *width = MAX (*width, crtc_pos_x + mode_width);
     *height = MAX (*height, crtc_pos_y + mode_height);
 
-    dpi = 25.4 * DisplayHeight (xdisplay, screen);
-    dpi /= DisplayHeightMM (xdisplay, screen);
+    dpi = 25.4 * gdk_screen_height ();
+    dpi /= gdk_screen_height_mm ();
 
     if (dpi <= 0)
     {
-        *mm_width = DisplayWidthMM (xdisplay, screen);
-        *mm_height = DisplayHeightMM (xdisplay, screen);
+        *mm_width = gdk_screen_width_mm ();
+        *mm_height = gdk_screen_height_mm ();
     }
     else
     {
@@ -471,13 +467,15 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
 
                 /* get the sizes of the mode to enforce */
                 if ((rot & (RR_Rotate_90|RR_Rotate_270)) != 0)
-                    xfce_displays_helper_process_screen_size (xdisplay, resources->modes[j].height,
-                                                              resources->modes[j].width, pos_x, pos_y,
-                                                              &width, &height, &mm_width, &mm_height);
+                    xfce_displays_helper_process_screen_size (resources->modes[j].height,
+                                                              resources->modes[j].width,
+                                                              pos_x, pos_y, &width, &height,
+                                                              &mm_width, &mm_height);
                 else
-                    xfce_displays_helper_process_screen_size (xdisplay, resources->modes[j].width,
-                                                              resources->modes[j].height, pos_x, pos_y,
-                                                              &width, &height, &mm_width, &mm_height);
+                    xfce_displays_helper_process_screen_size (resources->modes[j].width,
+                                                              resources->modes[j].height,
+                                                              pos_x, pos_y, &width, &height,
+                                                              &mm_width, &mm_height);
 
                 /* check if we really need to do something */
                 if (crtc_info->mode != mode || crtc_info->rotation != rot
@@ -505,15 +503,13 @@ xfce_displays_helper_channel_apply (XfceDisplaysHelper *helper,
         g_free (output_name);
     }
 
-    /* everything has been applied, set the screen size */
-    n = gdk_x11_get_default_screen ();
-    /* call it only if it's really needed and valid */
+    /* set the screen size only if it's really needed and valid */
     if (width >= min_width && width <= max_width
         && height >= min_height && height <= max_height
-        && (width != DisplayWidth (xdisplay, n)
-            || height != DisplayHeight (xdisplay, n)
-            || mm_width != DisplayWidthMM (xdisplay, n)
-            || mm_height != DisplayHeightMM (xdisplay, n)))
+        && (width != gdk_screen_width ()
+            || height != gdk_screen_height ()
+            || mm_width != gdk_screen_width_mm ()
+            || mm_height != gdk_screen_height_mm ()))
         XRRSetScreenSize (xdisplay, GDK_WINDOW_XID (root_window),
                           width, height, mm_width, mm_height);
 



More information about the Xfce4-commits mailing list