diff options
| author | Ken Raeburn | 2015-11-07 03:06:32 -0500 |
|---|---|---|
| committer | Ken Raeburn | 2015-11-12 03:58:09 -0500 |
| commit | a838c8331cf3f360d919a75cc8d92c72e6d900f0 (patch) | |
| tree | f84758386b810487a95d08688e92bd4195699d75 /src | |
| parent | c7f2b6ad892c93b8b848d21835a4b093c424cae6 (diff) | |
| download | emacs-a838c8331cf3f360d919a75cc8d92c72e6d900f0.tar.gz emacs-a838c8331cf3f360d919a75cc8d92c72e6d900f0.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xterm.c | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/src/xterm.c b/src/xterm.c index d1cf8e4d0c1..36a914c8559 100644 --- a/src/xterm.c +++ b/src/xterm.c | |||
| @@ -10096,20 +10096,45 @@ get_current_wm_state (struct frame *f, | |||
| 10096 | int *size_state, | 10096 | int *size_state, |
| 10097 | bool *sticky) | 10097 | bool *sticky) |
| 10098 | { | 10098 | { |
| 10099 | Atom actual_type; | 10099 | unsigned long actual_size; |
| 10100 | unsigned long actual_size, bytes_remaining; | 10100 | int i; |
| 10101 | int i, rc, actual_format; | ||
| 10102 | bool is_hidden = false; | 10101 | bool is_hidden = false; |
| 10103 | struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f); | 10102 | struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f); |
| 10104 | long max_len = 65536; | 10103 | long max_len = 65536; |
| 10105 | Display *dpy = FRAME_X_DISPLAY (f); | ||
| 10106 | unsigned char *tmp_data = NULL; | 10104 | unsigned char *tmp_data = NULL; |
| 10107 | Atom target_type = XA_ATOM; | 10105 | Atom target_type = XA_ATOM; |
| 10106 | /* If XCB is available, we can avoid three XSync calls. */ | ||
| 10107 | #ifdef USE_XCB | ||
| 10108 | xcb_get_property_cookie_t prop_cookie; | ||
| 10109 | xcb_get_property_reply_t *prop; | ||
| 10110 | #else | ||
| 10111 | Display *dpy = FRAME_X_DISPLAY (f); | ||
| 10112 | unsigned long bytes_remaining; | ||
| 10113 | int rc, actual_format; | ||
| 10114 | Atom actual_type; | ||
| 10115 | #endif | ||
| 10108 | 10116 | ||
| 10109 | *sticky = false; | 10117 | *sticky = false; |
| 10110 | *size_state = FULLSCREEN_NONE; | 10118 | *size_state = FULLSCREEN_NONE; |
| 10111 | 10119 | ||
| 10112 | block_input (); | 10120 | block_input (); |
| 10121 | |||
| 10122 | #ifdef USE_XCB | ||
| 10123 | prop_cookie = xcb_get_property (dpyinfo->xcb_connection, 0, window, | ||
| 10124 | dpyinfo->Xatom_net_wm_state, | ||
| 10125 | target_type, 0, max_len); | ||
| 10126 | prop = xcb_get_property_reply (dpyinfo->xcb_connection, prop_cookie, NULL); | ||
| 10127 | if (prop && prop->type == target_type) | ||
| 10128 | { | ||
| 10129 | tmp_data = xcb_get_property_value (prop); | ||
| 10130 | actual_size = xcb_get_property_value_length (prop); | ||
| 10131 | } | ||
| 10132 | else | ||
| 10133 | { | ||
| 10134 | actual_size = 0; | ||
| 10135 | is_hidden = FRAME_ICONIFIED_P (f); | ||
| 10136 | } | ||
| 10137 | #else | ||
| 10113 | x_catch_errors (dpy); | 10138 | x_catch_errors (dpy); |
| 10114 | rc = XGetWindowProperty (dpy, window, dpyinfo->Xatom_net_wm_state, | 10139 | rc = XGetWindowProperty (dpy, window, dpyinfo->Xatom_net_wm_state, |
| 10115 | 0, max_len, False, target_type, | 10140 | 0, max_len, False, target_type, |
| @@ -10118,13 +10143,12 @@ get_current_wm_state (struct frame *f, | |||
| 10118 | 10143 | ||
| 10119 | if (rc != Success || actual_type != target_type || x_had_errors_p (dpy)) | 10144 | if (rc != Success || actual_type != target_type || x_had_errors_p (dpy)) |
| 10120 | { | 10145 | { |
| 10121 | if (tmp_data) XFree (tmp_data); | 10146 | actual_size = 0; |
| 10122 | x_uncatch_errors (); | 10147 | is_hidden = FRAME_ICONIFIED_P (f); |
| 10123 | unblock_input (); | ||
| 10124 | return !FRAME_ICONIFIED_P (f); | ||
| 10125 | } | 10148 | } |
| 10126 | 10149 | ||
| 10127 | x_uncatch_errors (); | 10150 | x_uncatch_errors (); |
| 10151 | #endif | ||
| 10128 | 10152 | ||
| 10129 | for (i = 0; i < actual_size; ++i) | 10153 | for (i = 0; i < actual_size; ++i) |
| 10130 | { | 10154 | { |
| @@ -10151,7 +10175,12 @@ get_current_wm_state (struct frame *f, | |||
| 10151 | *sticky = true; | 10175 | *sticky = true; |
| 10152 | } | 10176 | } |
| 10153 | 10177 | ||
| 10178 | #ifdef USE_XCB | ||
| 10179 | free (prop); | ||
| 10180 | #else | ||
| 10154 | if (tmp_data) XFree (tmp_data); | 10181 | if (tmp_data) XFree (tmp_data); |
| 10182 | #endif | ||
| 10183 | |||
| 10155 | unblock_input (); | 10184 | unblock_input (); |
| 10156 | return ! is_hidden; | 10185 | return ! is_hidden; |
| 10157 | } | 10186 | } |