diff options
| author | Po Lu | 2022-03-30 09:17:58 +0800 |
|---|---|---|
| committer | Po Lu | 2022-03-30 09:17:58 +0800 |
| commit | c4a1e8bd7a3c6582c036df98248ac3d37ad55835 (patch) | |
| tree | fefb8161763911d57be4ac07d24991496ff348b9 /src | |
| parent | c52b58d2903e3ff212dc1b9e9316ee26fae5aa66 (diff) | |
| download | emacs-c4a1e8bd7a3c6582c036df98248ac3d37ad55835.tar.gz emacs-c4a1e8bd7a3c6582c036df98248ac3d37ad55835.zip | |
Avoid calling XGetAtomName in a loop when fetching monitor attributes
* src/xfns.c (x_get_monitor_attributes_xrandr): Avoid syncing on
each monitor when waiting for XGetAtomName when built with XCB.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xfns.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/xfns.c b/src/xfns.c index 37e0628464f..4fa919f36a5 100644 --- a/src/xfns.c +++ b/src/xfns.c | |||
| @@ -5768,6 +5768,12 @@ x_get_monitor_attributes_xrandr (struct x_display_info *dpyinfo) | |||
| 5768 | 5768 | ||
| 5769 | #if RANDR_MAJOR > 1 || (RANDR_MAJOR == 1 && RANDR_MINOR >= 5) | 5769 | #if RANDR_MAJOR > 1 || (RANDR_MAJOR == 1 && RANDR_MINOR >= 5) |
| 5770 | XRRMonitorInfo *rr_monitors; | 5770 | XRRMonitorInfo *rr_monitors; |
| 5771 | #ifdef USE_XCB | ||
| 5772 | xcb_get_atom_name_cookie_t *atom_name_cookies; | ||
| 5773 | xcb_get_atom_name_reply_t *reply; | ||
| 5774 | xcb_generic_error_t *error; | ||
| 5775 | int length; | ||
| 5776 | #endif | ||
| 5771 | 5777 | ||
| 5772 | /* If RandR 1.5 or later is available, use that instead, as some | 5778 | /* If RandR 1.5 or later is available, use that instead, as some |
| 5773 | video drivers don't report correct dimensions via other versions | 5779 | video drivers don't report correct dimensions via other versions |
| @@ -5786,6 +5792,9 @@ x_get_monitor_attributes_xrandr (struct x_display_info *dpyinfo) | |||
| 5786 | goto fallback; | 5792 | goto fallback; |
| 5787 | 5793 | ||
| 5788 | monitors = xzalloc (n_monitors * sizeof *monitors); | 5794 | monitors = xzalloc (n_monitors * sizeof *monitors); |
| 5795 | #ifdef USE_XCB | ||
| 5796 | atom_name_cookies = alloca (n_monitors * sizeof *atom_name_cookies); | ||
| 5797 | #endif | ||
| 5789 | 5798 | ||
| 5790 | for (int i = 0; i < n_monitors; ++i) | 5799 | for (int i = 0; i < n_monitors; ++i) |
| 5791 | { | 5800 | { |
| @@ -5796,6 +5805,7 @@ x_get_monitor_attributes_xrandr (struct x_display_info *dpyinfo) | |||
| 5796 | monitors[i].mm_width = rr_monitors[i].mwidth; | 5805 | monitors[i].mm_width = rr_monitors[i].mwidth; |
| 5797 | monitors[i].mm_height = rr_monitors[i].mheight; | 5806 | monitors[i].mm_height = rr_monitors[i].mheight; |
| 5798 | 5807 | ||
| 5808 | #ifndef USE_XCB | ||
| 5799 | name = XGetAtomName (dpyinfo->display, rr_monitors[i].name); | 5809 | name = XGetAtomName (dpyinfo->display, rr_monitors[i].name); |
| 5800 | if (name) | 5810 | if (name) |
| 5801 | { | 5811 | { |
| @@ -5804,6 +5814,11 @@ x_get_monitor_attributes_xrandr (struct x_display_info *dpyinfo) | |||
| 5804 | } | 5814 | } |
| 5805 | else | 5815 | else |
| 5806 | monitors[i].name = xstrdup ("Unknown Monitor"); | 5816 | monitors[i].name = xstrdup ("Unknown Monitor"); |
| 5817 | #else | ||
| 5818 | atom_name_cookies[i] | ||
| 5819 | = xcb_get_atom_name (dpyinfo->xcb_connection, | ||
| 5820 | (xcb_atom_t) rr_monitors[i].name); | ||
| 5821 | #endif | ||
| 5807 | 5822 | ||
| 5808 | if (rr_monitors[i].primary) | 5823 | if (rr_monitors[i].primary) |
| 5809 | primary = i; | 5824 | primary = i; |
| @@ -5821,6 +5836,29 @@ x_get_monitor_attributes_xrandr (struct x_display_info *dpyinfo) | |||
| 5821 | monitors[i].work = monitors[i].geom; | 5836 | monitors[i].work = monitors[i].geom; |
| 5822 | } | 5837 | } |
| 5823 | 5838 | ||
| 5839 | #ifdef USE_XCB | ||
| 5840 | for (int i = 0; i < n_monitors; ++i) | ||
| 5841 | { | ||
| 5842 | reply = xcb_get_atom_name_reply (dpyinfo->xcb_connection, | ||
| 5843 | atom_name_cookies[i], &error); | ||
| 5844 | |||
| 5845 | if (!reply) | ||
| 5846 | { | ||
| 5847 | monitors[i].name = xstrdup ("Unknown monitor"); | ||
| 5848 | free (error); | ||
| 5849 | } | ||
| 5850 | else | ||
| 5851 | { | ||
| 5852 | length = xcb_get_atom_name_name_length (reply); | ||
| 5853 | name = xmalloc (length + 1); | ||
| 5854 | memcpy (name, xcb_get_atom_name_name (reply), length); | ||
| 5855 | name[length] = '\0'; | ||
| 5856 | monitors[i].name = name; | ||
| 5857 | free (reply); | ||
| 5858 | } | ||
| 5859 | } | ||
| 5860 | #endif | ||
| 5861 | |||
| 5824 | XRRFreeMonitors (rr_monitors); | 5862 | XRRFreeMonitors (rr_monitors); |
| 5825 | randr15_p = true; | 5863 | randr15_p = true; |
| 5826 | goto out; | 5864 | goto out; |