From: Po Lu <luangruo@yahoo.com>
Date: Mon, 10 Mar 2025 04:41:12 +0000 (+0800)
Subject: Fix bug#76805
X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=3a14f2e3c6630db7e68182cf40d137a128d67d71;p=emacs.git

Fix bug#76805

* src/xterm.c (x_fast_mouse_position): Clear the mouse_moved
flag whether or not mouse motion is reported, to avoid repeated
polling for mouse movement.  (bug#76806)

(cherry picked from commit ab5bfcebddf4c0613ef352231628d4034c8cb178)
---

diff --git a/src/xterm.c b/src/xterm.c
index 2ccf267bbd3..b21efd5a2a2 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -14878,6 +14878,14 @@ x_fast_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
       return;
     }
 
+  FOR_EACH_FRAME (tail, frame)
+    {
+      if (FRAME_X_P (XFRAME (frame))
+	  && (FRAME_DISPLAY_INFO (XFRAME (frame))
+	      == dpyinfo))
+	XFRAME (frame)->mouse_moved = false;
+    }
+
   if (!EQ (Vx_use_fast_mouse_position, Qreally_fast))
     {
       /* This means that Emacs should select a frame and report the
@@ -14886,14 +14894,6 @@ x_fast_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
 	 window beneath the pointer, and was borrowed from
 	 haiku_mouse_position in haikuterm.c.  */
 
-      FOR_EACH_FRAME (tail, frame)
-	{
-	  if (FRAME_X_P (XFRAME (frame))
-	      && (FRAME_DISPLAY_INFO (XFRAME (frame))
-		  == dpyinfo))
-	    XFRAME (frame)->mouse_moved = false;
-	}
-
       if (gui_mouse_grabbed (dpyinfo)
 	  && !EQ (track_mouse, Qdropping)
 	  && !EQ (track_mouse, Qdrag_source))
@@ -14952,8 +14952,8 @@ x_fast_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
     }
   else
     {
-      /* This means Emacs should only report the coordinates of the
-	 last mouse motion.  */
+      /* This means Emacs should only report the coordinates of the last
+	 mouse motion.  */
 
       if (dpyinfo->last_mouse_motion_frame)
 	{
@@ -14963,15 +14963,6 @@ x_fast_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
 	  *y = make_fixnum (dpyinfo->last_mouse_motion_y);
 	  *bar_window = Qnil;
 	  *part = scroll_bar_nowhere;
-
-	  FOR_EACH_FRAME (tail, frame)
-	    {
-	      if (FRAME_X_P (XFRAME (frame))
-		  && (FRAME_DISPLAY_INFO (XFRAME (frame))
-		      == dpyinfo))
-		XFRAME (frame)->mouse_moved = false;
-	    }
-
 	  dpyinfo->last_mouse_motion_frame->mouse_moved = false;
 	}
     }