emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master a838c83 4/5: Enable use of XCB for checking window


From: Ken Raeburn
Subject: [Emacs-diffs] master a838c83 4/5: Enable use of XCB for checking window manager state
Date: Thu, 12 Nov 2015 09:03:53 +0000

branch: master
commit a838c8331cf3f360d919a75cc8d92c72e6d900f0
Author: Ken Raeburn <address@hidden>
Commit: Ken Raeburn <address@hidden>

    Enable use of XCB for checking window manager state
    
    * src/xterm.c (get_current_wm_state) [USE_XCB]: Use XCB calls instead
    of XGetWindowProperty plus error-catching, since we can explicitly
    check for errors in the XCB version.  This eliminates 3 XSync calls on
    top of the round-trip actually fetching the information.
---
 src/xterm.c |   45 +++++++++++++++++++++++++++++++++++++--------
 1 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/src/xterm.c b/src/xterm.c
index d1cf8e4..36a914c 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -10096,20 +10096,45 @@ get_current_wm_state (struct frame *f,
                       int *size_state,
                       bool *sticky)
 {
-  Atom actual_type;
-  unsigned long actual_size, bytes_remaining;
-  int i, rc, actual_format;
+  unsigned long actual_size;
+  int i;
   bool is_hidden = false;
   struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
   long max_len = 65536;
-  Display *dpy = FRAME_X_DISPLAY (f);
   unsigned char *tmp_data = NULL;
   Atom target_type = XA_ATOM;
+  /* If XCB is available, we can avoid three XSync calls.  */
+#ifdef USE_XCB
+  xcb_get_property_cookie_t prop_cookie;
+  xcb_get_property_reply_t *prop;
+#else
+  Display *dpy = FRAME_X_DISPLAY (f);
+  unsigned long bytes_remaining;
+  int rc, actual_format;
+  Atom actual_type;
+#endif
 
   *sticky = false;
   *size_state = FULLSCREEN_NONE;
 
   block_input ();
+
+#ifdef USE_XCB
+  prop_cookie = xcb_get_property (dpyinfo->xcb_connection, 0, window,
+                                  dpyinfo->Xatom_net_wm_state,
+                                  target_type, 0, max_len);
+  prop = xcb_get_property_reply (dpyinfo->xcb_connection, prop_cookie, NULL);
+  if (prop && prop->type == target_type)
+    {
+      tmp_data = xcb_get_property_value (prop);
+      actual_size = xcb_get_property_value_length (prop);
+    }
+  else
+    {
+      actual_size = 0;
+      is_hidden = FRAME_ICONIFIED_P (f);
+    }
+#else
   x_catch_errors (dpy);
   rc = XGetWindowProperty (dpy, window, dpyinfo->Xatom_net_wm_state,
                            0, max_len, False, target_type,
@@ -10118,13 +10143,12 @@ get_current_wm_state (struct frame *f,
 
   if (rc != Success || actual_type != target_type || x_had_errors_p (dpy))
     {
-      if (tmp_data) XFree (tmp_data);
-      x_uncatch_errors ();
-      unblock_input ();
-      return !FRAME_ICONIFIED_P (f);
+      actual_size = 0;
+      is_hidden = FRAME_ICONIFIED_P (f);
     }
 
   x_uncatch_errors ();
+#endif
 
   for (i = 0; i < actual_size; ++i)
     {
@@ -10151,7 +10175,12 @@ get_current_wm_state (struct frame *f,
         *sticky = true;
     }
 
+#ifdef USE_XCB
+  free (prop);
+#else
   if (tmp_data) XFree (tmp_data);
+#endif
+
   unblock_input ();
   return ! is_hidden;
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]