From: Po Lu Date: Sat, 30 Apr 2022 10:05:44 +0000 (+0800) Subject: Avoid server roundtrip on wheel events from scroll bars on XI2 X-Git-Tag: emacs-29.0.90~1931^2~196 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=5fd54723536efca5589f9b9ac64825e76f0d1360;p=emacs.git Avoid server roundtrip on wheel events from scroll bars on XI2 * src/xterm.c (handle_one_xevent): Translate coordinates for scroll bars correctly when handling XI2 wheel events. --- diff --git a/src/xterm.c b/src/xterm.c index 6d658cf2042..ea86b7f8033 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -16863,6 +16863,9 @@ handle_one_xevent (struct x_display_info *dpyinfo, double delta, scroll_unit; int scroll_height; Lisp_Object window; + struct scroll_bar *bar; + + bar = NULL; /* See the comment on top of x_init_master_valuators for more details on how @@ -16880,9 +16883,8 @@ handle_one_xevent (struct x_display_info *dpyinfo, if (!f) { #if defined USE_MOTIF || !defined USE_TOOLKIT_SCROLL_BARS - struct scroll_bar *bar - = x_window_to_scroll_bar (xi_event->display, - xev->event, 2); + bar = x_window_to_scroll_bar (dpyinfo->display, + xev->event, 2); if (bar) f = WINDOW_XFRAME (XWINDOW (bar->window)); @@ -16899,11 +16901,26 @@ handle_one_xevent (struct x_display_info *dpyinfo, #endif if (FRAME_X_WINDOW (f) != xev->event) - XTranslateCoordinates (dpyinfo->display, - xev->event, FRAME_X_WINDOW (f), - lrint (xev->event_x), - lrint (xev->event_y), - &real_x, &real_y, &dummy); + { + if (!bar) + bar = x_window_to_scroll_bar (dpyinfo->display, xev->event, 2); + + /* If this is a scroll bar, compute the + actual position directly to avoid an + extra roundtrip. */ + + if (bar) + { + real_x = lrint (xev->event_x + bar->left); + real_y = lrint (xev->event_y + bar->top); + } + else + XTranslateCoordinates (dpyinfo->display, + xev->event, FRAME_X_WINDOW (f), + lrint (xev->event_x), + lrint (xev->event_y), + &real_x, &real_y, &dummy); + } else { real_x = lrint (xev->event_x);