[mutter] x11: Remove async-getprop



commit 0e73ceb4bd101c12d273a5eb903134a134ee095d
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Wed Jun 17 17:43:04 2015 -0700

    x11: Remove async-getprop
    
    xcb can do this for us now.

 src/Makefile-tests.am      |    7 +-
 src/Makefile.am            |    2 -
 src/x11/async-getprop.c    |  680 --------------------------------------------
 src/x11/async-getprop.h    |   67 -----
 src/x11/testasyncgetprop.c |  496 --------------------------------
 src/x11/xprops.c           |  179 ++++++-------
 6 files changed, 85 insertions(+), 1346 deletions(-)
---
diff --git a/src/Makefile-tests.am b/src/Makefile-tests.am
index ac3d5d7..a9554a0 100644
--- a/src/Makefile-tests.am
+++ b/src/Makefile-tests.am
@@ -41,9 +41,6 @@ endif
 # Some random test programs for bits of the code
 
 testboxes_SOURCES = core/testboxes.c
-testasyncgetprop_SOURCES = x11/testasyncgetprop.c
-
-noinst_PROGRAMS+=testboxes testasyncgetprop
-
 testboxes_LDADD = $(MUTTER_LIBS) libmutter.la
-testasyncgetprop_LDADD = $(MUTTER_LIBS) libmutter.la
+
+noinst_PROGRAMS += testboxes
diff --git a/src/Makefile.am b/src/Makefile.am
index 301452d..9316e95 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -210,8 +210,6 @@ libmutter_la_SOURCES =                              \
        meta/theme.h                            \
        ui/theme-private.h                      \
        ui/ui.c                                 \
-       x11/async-getprop.c                     \
-       x11/async-getprop.h                     \
        x11/atomnames.h                         \
        x11/events.c                            \
        x11/events.h                            \
diff --git a/src/x11/xprops.c b/src/x11/xprops.c
index 35b3749..ae3068f 100644
--- a/src/x11/xprops.c
+++ b/src/x11/xprops.c
@@ -78,17 +78,21 @@ from The Open Group.
 */
 
 
-#include <config.h>
+#include "config.h"
+
+#include <string.h>
+#include <stdlib.h>
+
 #include "xprops.h"
 #include <meta/errors.h>
 #include "util-private.h"
-#include "async-getprop.h"
 #include "ui.h"
 #include "mutter-Xatomtype.h"
-#include <X11/Xatom.h>
-#include <string.h>
 #include "window-private.h"
 
+#include <X11/Xatom.h>
+#include <X11/Xlib-xcb.h>
+
 typedef struct
 {
   MetaDisplay   *display;
@@ -168,13 +172,50 @@ validate_or_free_results (GetPropertyResults *results,
 
   if (results->prop)
     {
-      XFree (results->prop);
+      g_free (results->prop);
       results->prop = NULL;
     }
 
   return FALSE;
 }
 
+static xcb_get_property_cookie_t
+async_get_property (xcb_connection_t *xcb_conn, Window xwindow,
+                    Atom xatom, Atom required_type)
+{
+  return xcb_get_property (xcb_conn, False, xwindow,
+                           xatom, required_type, 0, G_MAXULONG);
+}
+
+static gboolean
+async_get_property_finish (xcb_connection_t          *xcb_conn,
+                           xcb_get_property_cookie_t  cookie,
+                           GetPropertyResults        *results)
+{
+  xcb_get_property_reply_t *reply;
+  xcb_generic_error_t *error;
+
+  reply = xcb_get_property_reply (xcb_conn, cookie, &error);
+  if (error)
+    {
+      free (error);
+      return FALSE;
+    }
+
+  results->n_items = reply->value_len;
+  results->type = reply->type;
+  results->bytes_after = reply->bytes_after;
+  results->format = reply->format;
+  results->prop = NULL;
+
+  if (results->type != None)
+    results->prop = g_memdup (xcb_get_property_value (reply),
+                              xcb_get_property_value_length (reply));
+
+  free (reply);
+  return (results->prop != NULL);
+}
+
 static gboolean
 get_property (MetaDisplay        *display,
               Window              xwindow,
@@ -182,6 +223,9 @@ get_property (MetaDisplay        *display,
               Atom                req_type,
               GetPropertyResults *results)
 {
+  xcb_get_property_cookie_t cookie;
+  xcb_connection_t *xcb_conn = XGetXCBConnection (display->xdisplay);
+
   results->display = display;
   results->xwindow = xwindow;
   results->xatom = xatom;
@@ -191,29 +235,8 @@ get_property (MetaDisplay        *display,
   results->bytes_after = 0;
   results->format = 0;
 
-  meta_error_trap_push (display);
-  if (XGetWindowProperty (display->xdisplay, xwindow, xatom,
-                          0, G_MAXLONG,
-                          False, req_type, &results->type, &results->format,
-                          &results->n_items,
-                          &results->bytes_after,
-                          &results->prop) != Success ||
-      results->type == None)
-    {
-      if (results->prop)
-        XFree (results->prop);
-      meta_error_trap_pop_with_return (display);
-      return FALSE;
-    }
-
-  if (meta_error_trap_pop_with_return (display) != Success)
-    {
-      if (results->prop)
-        XFree (results->prop);
-      return FALSE;
-    }
-
-  return TRUE;
+  cookie = async_get_property (xcb_conn, xwindow, xatom, req_type);
+  return async_get_property_finish (xcb_conn, cookie, results);
 }
 
 static gboolean
@@ -318,7 +341,7 @@ motif_hints_from_results (GetPropertyResults *results,
    * MotifWmHints than the one we expect, apparently.  I'm not sure of
    * the history behind it. See bug #89841 for example.
    */
-  *hints_p = ag_Xmalloc (sizeof (MotifWmHints));
+  *hints_p = malloc (sizeof (MotifWmHints));
   if (*hints_p == NULL)
     {
       if (results->prop)
@@ -409,7 +432,7 @@ utf8_string_from_results (GetPropertyResults *results,
       meta_warning ("Property %s on window 0x%lx contained invalid UTF-8\n",
                     name, results->xwindow);
       meta_XFree (name);
-      XFree (results->prop);
+      g_free (results->prop);
       results->prop = NULL;
 
       return FALSE;
@@ -492,7 +515,7 @@ utf8_list_from_results (GetPropertyResults *results,
           meta_warning ("Property %s on window 0x%lx contained invalid UTF-8 for item %d in the list\n",
                         name, results->xwindow, i);
           meta_XFree (name);
-          meta_XFree (results->prop);
+          g_free (results->prop);
           results->prop = NULL;
 
           g_strfreev (retval);
@@ -508,7 +531,7 @@ utf8_list_from_results (GetPropertyResults *results,
   *str_p = retval;
   *n_str_p = i;
 
-  meta_XFree (results->prop);
+  g_free (results->prop);
   results->prop = NULL;
 
   return TRUE;
@@ -585,7 +608,7 @@ latin1_list_from_results (GetPropertyResults *results,
   *str_p = retval;
   *n_str_p = i;
 
-  meta_XFree (results->prop);
+  g_free (results->prop);
   results->prop = NULL;
 
   return TRUE;
@@ -844,7 +867,7 @@ wm_hints_from_results (GetPropertyResults *results,
       return FALSE;
     }
 
-  hints = ag_Xmalloc0 (sizeof (XWMHints));
+  hints = calloc (1, sizeof (XWMHints));
 
   raw = (xPropWMHints*) results->prop;
 
@@ -902,7 +925,7 @@ class_hint_from_results (GetPropertyResults *results,
     return FALSE;
 
   len_name = strlen ((char *) results->prop);
-  if (! (class_hint->res_name = ag_Xmalloc (len_name+1)))
+  if (! (class_hint->res_name = malloc (len_name+1)))
     {
       XFree (results->prop);
       results->prop = NULL;
@@ -916,7 +939,7 @@ class_hint_from_results (GetPropertyResults *results,
 
   len_class = strlen ((char *)results->prop + len_name + 1);
 
-  if (! (class_hint->res_class = ag_Xmalloc(len_class+1)))
+  if (! (class_hint->res_class = malloc(len_class+1)))
     {
       XFree(class_hint->res_name);
       class_hint->res_name = NULL;
@@ -970,7 +993,7 @@ size_hints_from_results (GetPropertyResults *results,
 
   raw = (xPropSizeHints*) results->prop;
 
-  hints = ag_Xmalloc (sizeof (XSizeHints));
+  hints = malloc (sizeof (XSizeHints));
 
   /* XSizeHints misdeclares these as int instead of long */
   hints->flags = raw->flags;
@@ -1027,18 +1050,6 @@ meta_prop_get_size_hints (MetaDisplay   *display,
   return size_hints_from_results (&results, hints_p, flags_p);
 }
 
-static AgGetPropertyTask*
-get_task (MetaDisplay        *display,
-          Window              xwindow,
-          Atom                xatom,
-          Atom                req_type)
-{
-  return ag_task_create (display->xdisplay,
-                         xwindow,
-                         xatom, 0, G_MAXLONG,
-                         False, req_type);
-}
-
 static char*
 latin1_to_utf8 (const char *text)
 {
@@ -1064,7 +1075,8 @@ meta_prop_get_values (MetaDisplay   *display,
                       int            n_values)
 {
   int i;
-  AgGetPropertyTask **tasks;
+  xcb_get_property_cookie_t *tasks;
+  xcb_connection_t *xcb_conn = XGetXCBConnection (display->xdisplay);
 
   meta_verbose ("Requesting %d properties of 0x%lx at once\n",
                 n_values, xwindow);
@@ -1072,7 +1084,7 @@ meta_prop_get_values (MetaDisplay   *display,
   if (n_values == 0)
     return;
 
-  tasks = g_new0 (AgGetPropertyTask*, n_values);
+  tasks = g_new0 (xcb_get_property_cookie_t, n_values);
 
   /* Start up tasks. The "values" array can have values
    * with atom == None, which means to ignore that element.
@@ -1132,9 +1144,7 @@ meta_prop_get_values (MetaDisplay   *display,
         }
 
       if (values[i].atom != None)
-        tasks[i] = get_task (display, xwindow,
-                             values[i].atom, values[i].required_type);
-
+        tasks[i] = async_get_property (xcb_conn, xwindow, values[i].atom, values[i].required_type);
       ++i;
     }
 
@@ -1147,10 +1157,11 @@ meta_prop_get_values (MetaDisplay   *display,
   i = 0;
   while (i < n_values)
     {
-      AgGetPropertyTask *task;
       GetPropertyResults results;
 
-      if (tasks[i] == NULL)
+      /* We're relying on the fact that sequence numbers can never be zero
+       * in Xorg. This is a bit disgusting... */
+      if (tasks[i].sequence == 0)
         {
           /* Probably values[i].type was None, or ag_task_create()
            * returned NULL.
@@ -1159,10 +1170,6 @@ meta_prop_get_values (MetaDisplay   *display,
           goto next;
         }
 
-      task = ag_get_next_completed_task (display->xdisplay);
-      g_assert (task != NULL);
-      g_assert (ag_task_have_reply (task));
-
       results.display = display;
       results.xwindow = xwindow;
       results.xatom = values[i].atom;
@@ -1172,21 +1179,8 @@ meta_prop_get_values (MetaDisplay   *display,
       results.bytes_after = 0;
       results.format = 0;
 
-      if (ag_task_get_reply_and_free (task,
-                                      &results.type, &results.format,
-                                      &results.n_items,
-                                      &results.bytes_after,
-                                      &results.prop) != Success ||
-          results.type == None)
-        {
-          values[i].type = META_PROP_VALUE_INVALID;
-          if (results.prop)
-            {
-              XFree (results.prop);
-              results.prop = NULL;
-            }
-          goto next;
-        }
+      if (!async_get_property_finish (xcb_conn, tasks[i], &results))
+        goto next;
 
       switch (values[i].type)
         {
@@ -1216,18 +1210,9 @@ meta_prop_get_values (MetaDisplay   *display,
           else
             {
               char *new_str;
-              char *xmalloc_new_str;
-
               new_str = latin1_to_utf8 (values[i].v.str);
-              xmalloc_new_str = ag_Xmalloc (strlen (new_str) + 1);
-              if (xmalloc_new_str != NULL)
-                {
-                  strcpy (xmalloc_new_str, new_str);
-                  meta_XFree (values[i].v.str);
-                  values[i].v.str = xmalloc_new_str;
-                }
-
-              g_free (new_str);
+              free (values[i].v.str);
+              values[i].v.str = new_str;
             }
           break;
         case META_PROP_VALUE_MOTIF_HINTS:
@@ -1305,42 +1290,44 @@ free_value (MetaPropValue *value)
       break;
     case META_PROP_VALUE_UTF8:
     case META_PROP_VALUE_STRING:
+      free (value->v.str);
+      break;
     case META_PROP_VALUE_STRING_AS_UTF8:
-      meta_XFree (value->v.str);
+      g_free (value->v.str);
       break;
     case META_PROP_VALUE_MOTIF_HINTS:
-      meta_XFree (value->v.motif_hints);
+      free (value->v.motif_hints);
       break;
     case META_PROP_VALUE_CARDINAL:
       break;
     case META_PROP_VALUE_WINDOW:
       break;
     case META_PROP_VALUE_ATOM_LIST:
-      meta_XFree (value->v.atom_list.atoms);
+      free (value->v.atom_list.atoms);
       break;
     case META_PROP_VALUE_TEXT_PROPERTY:
-      meta_XFree (value->v.str);
+      free (value->v.str);
       break;
     case META_PROP_VALUE_WM_HINTS:
-      meta_XFree (value->v.wm_hints);
+      free (value->v.wm_hints);
       break;
     case META_PROP_VALUE_CLASS_HINT:
-      meta_XFree (value->v.class_hint.res_class);
-      meta_XFree (value->v.class_hint.res_name);
+      free (value->v.class_hint.res_class);
+      free (value->v.class_hint.res_name);
       break;
     case META_PROP_VALUE_SIZE_HINTS:
-      meta_XFree (value->v.size_hints.hints);
+      free (value->v.size_hints.hints);
       break;
     case META_PROP_VALUE_UTF8_LIST:
       g_strfreev (value->v.string_list.strings);
       break;
     case META_PROP_VALUE_CARDINAL_LIST:
-      meta_XFree (value->v.cardinal_list.cardinals);
+      free (value->v.cardinal_list.cardinals);
       break;
     case META_PROP_VALUE_SYNC_COUNTER:
       break;
     case META_PROP_VALUE_SYNC_COUNTER_LIST:
-      meta_XFree (value->v.xcounter_list.counters);
+      free (value->v.xcounter_list.counters);
       break;
     }
 }


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