diff options
| author | Po Lu | 2022-03-29 18:31:24 +0800 |
|---|---|---|
| committer | Po Lu | 2022-03-29 18:33:00 +0800 |
| commit | 0e662f33e1a5b1c88fb3e0bf8be906c1937114d3 (patch) | |
| tree | 70e62600e0049b14d7e5dba5a3669a0933a2f82f /src | |
| parent | 9aecc241e6e78d90f894e4ca196f84a6b4dea71a (diff) | |
| download | emacs-0e662f33e1a5b1c88fb3e0bf8be906c1937114d3.tar.gz emacs-0e662f33e1a5b1c88fb3e0bf8be906c1937114d3.zip | |
Rewrite desktop workarea computation to avoid too many calls to XSync
* src/xfns.c (x_get_net_workarea): Rewrite using XCB without
using long_offset and long_length, since the data transfer is
usually negligible compared to the roundtrip delay.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xfns.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/xfns.c b/src/xfns.c index 534fb7c544e..37e0628464f 100644 --- a/src/xfns.c +++ b/src/xfns.c | |||
| @@ -5459,6 +5459,7 @@ On MS Windows, this just returns nil. */) | |||
| 5459 | static bool | 5459 | static bool |
| 5460 | x_get_net_workarea (struct x_display_info *dpyinfo, XRectangle *rect) | 5460 | x_get_net_workarea (struct x_display_info *dpyinfo, XRectangle *rect) |
| 5461 | { | 5461 | { |
| 5462 | #ifndef USE_XCB | ||
| 5462 | Display *dpy = dpyinfo->display; | 5463 | Display *dpy = dpyinfo->display; |
| 5463 | long offset, max_len; | 5464 | long offset, max_len; |
| 5464 | Atom target_type, actual_type; | 5465 | Atom target_type, actual_type; |
| @@ -5512,6 +5513,69 @@ x_get_net_workarea (struct x_display_info *dpyinfo, XRectangle *rect) | |||
| 5512 | x_uncatch_errors (); | 5513 | x_uncatch_errors (); |
| 5513 | 5514 | ||
| 5514 | return result; | 5515 | return result; |
| 5516 | #else | ||
| 5517 | xcb_get_property_cookie_t current_desktop_cookie; | ||
| 5518 | xcb_get_property_cookie_t workarea_cookie; | ||
| 5519 | xcb_get_property_reply_t *reply; | ||
| 5520 | xcb_generic_error_t *error; | ||
| 5521 | bool rc; | ||
| 5522 | uint32_t current_workspace, *values; | ||
| 5523 | |||
| 5524 | current_desktop_cookie | ||
| 5525 | = xcb_get_property (dpyinfo->xcb_connection, 0, | ||
| 5526 | (xcb_window_t) dpyinfo->root_window, | ||
| 5527 | (xcb_atom_t) dpyinfo->Xatom_net_current_desktop, | ||
| 5528 | XCB_ATOM_CARDINAL, 0, 1); | ||
| 5529 | |||
| 5530 | workarea_cookie | ||
| 5531 | = xcb_get_property (dpyinfo->xcb_connection, 0, | ||
| 5532 | (xcb_window_t) dpyinfo->root_window, | ||
| 5533 | (xcb_atom_t) dpyinfo->Xatom_net_workarea, | ||
| 5534 | XCB_ATOM_CARDINAL, 0, UINT32_MAX); | ||
| 5535 | |||
| 5536 | reply = xcb_get_property_reply (dpyinfo->xcb_connection, | ||
| 5537 | current_desktop_cookie, &error); | ||
| 5538 | rc = true; | ||
| 5539 | |||
| 5540 | if (!reply) | ||
| 5541 | free (error), rc = false; | ||
| 5542 | else | ||
| 5543 | { | ||
| 5544 | if (xcb_get_property_value_length (reply) != 4 | ||
| 5545 | || reply->type != XCB_ATOM_CARDINAL || reply->format != 32) | ||
| 5546 | rc = false; | ||
| 5547 | else | ||
| 5548 | current_workspace = *(uint32_t *) xcb_get_property_value (reply); | ||
| 5549 | |||
| 5550 | free (reply); | ||
| 5551 | } | ||
| 5552 | |||
| 5553 | reply = xcb_get_property_reply (dpyinfo->xcb_connection, | ||
| 5554 | workarea_cookie, &error); | ||
| 5555 | |||
| 5556 | if (!reply) | ||
| 5557 | free (error), rc = false; | ||
| 5558 | else | ||
| 5559 | { | ||
| 5560 | if (rc && reply->type == XCB_ATOM_CARDINAL && reply->format == 32 | ||
| 5561 | && (xcb_get_property_value_length (reply) / sizeof (uint32_t) | ||
| 5562 | >= current_workspace + 4)) | ||
| 5563 | { | ||
| 5564 | values = xcb_get_property_value (reply); | ||
| 5565 | |||
| 5566 | rect->x = values[current_workspace]; | ||
| 5567 | rect->y = values[current_workspace + 1]; | ||
| 5568 | rect->width = values[current_workspace + 2]; | ||
| 5569 | rect->height = values[current_workspace + 3]; | ||
| 5570 | } | ||
| 5571 | else | ||
| 5572 | rc = false; | ||
| 5573 | |||
| 5574 | free (reply); | ||
| 5575 | } | ||
| 5576 | |||
| 5577 | return rc; | ||
| 5578 | #endif | ||
| 5515 | } | 5579 | } |
| 5516 | #endif /* !(USE_GTK && HAVE_GTK3) */ | 5580 | #endif /* !(USE_GTK && HAVE_GTK3) */ |
| 5517 | 5581 | ||