Subject: bug#49997: 27.2; idle-time reset when switching desktop-page

From: martin rudalics <[email-masked]>
Date: Sun, 22 Aug 2021 10:24:15 +0200

> If we end up with a list of ignored events, as I think we should, we
 > should consider making the same list control all of the relevant
 > features.

Not sure whether the attached is what you meant - it's just a first stab
in that direction.

martin
diff --git a/lisp/subr.el b/lisp/subr.el
index 0a31ef2b29..f100259e9e 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -4350,11 +4350,6 @@ with-local-quit
 	   ;; that intends to handle the quit signal next time.
 	   (eval '(ignore nil)))))

-;; Don't throw `throw-on-input' on those events by default.
-(setq while-no-input-ignore-events
-      '(focus-in focus-out help-echo iconify-frame
-        make-frame-visible selection-request))
-
 (defmacro while-no-input (&rest body)
   "Execute BODY only as long as there's no pending input.
 If input arrives, that ends the execution of BODY,
diff --git a/src/keyboard.c b/src/keyboard.c
index 2e4c4e6aab..48b9904d85 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -2927,20 +2927,8 @@ read_char (int commandflag, Lisp_Object map,
       last_input_event = c;
       call4 (Qcommand_execute, tem, Qnil, Fvector (1, &last_input_event), Qt);

-      if (CONSP (c)
-          && (EQ (XCAR (c), Qselect_window)
-              || EQ (XCAR (c), Qfocus_out)
-#ifdef HAVE_DBUS
-	      || EQ (XCAR (c), Qdbus_event)
-#endif
-#ifdef USE_FILE_NOTIFY
-	      || EQ (XCAR (c), Qfile_notify)
-#endif
-#ifdef THREADS_ENABLED
-	      || EQ (XCAR (c), Qthread_event)
-#endif
-	      || EQ (XCAR (c), Qconfig_changed_event))
-          && !end_time)
+      if (CONSP (c) && !NILP (Fmemq (XCAR (c), Vwhile_no_input_ignore_events))
+	  && !end_time)
 	/* We stopped being idle for this event; undo that.  This
 	   prevents automatic window selection (under
 	   mouse-autoselect-window) from acting as a real input event, for
@@ -11550,6 +11538,27 @@ init_keyboard (void)
   {SYMBOL_INDEX (Qselect_window),       SYMBOL_INDEX (Qswitch_frame)}
 };

+static Lisp_Object
+init_while_no_input_ignore_events (void)
+{
+  Lisp_Object events = listn (9, Qselect_window, Qhelp_echo, Qmove_frame,
+			      Qiconify_frame, Qmake_frame_visible,
+			      Qfocus_in, Qfocus_out, Qconfig_changed_event,
+			      Qselection_request);
+
+#ifdef HAVE_DBUS
+  events = Fcons (Qdbus_event, events);
+#endif
+#ifdef USE_FILE_NOTIFY
+  events = Fcons (Qfile_notify, events);
+#endif
+#ifdef THREADS_ENABLED
+  events = Fcons (Qthread_event, events);
+#endif
+
+  return events;
+}
+
 static void syms_of_keyboard_for_pdumper (void);

 void
@@ -12444,7 +12453,12 @@ syms_of_keyboard (void)

   DEFVAR_LISP ("while-no-input-ignore-events",
                Vwhile_no_input_ignore_events,
-               doc: /* Ignored events from while-no-input.  */);
+               doc: /* Ignored events from while-no-input.
+Events in this list do not count as pending input while running
+`while-no-input' and do not cause any idle timers to get reset when they
+occur.  */);
+
+  Vwhile_no_input_ignore_events = init_while_no_input_ignore_events ();

   pdumper_do_now_and_after_load (syms_of_keyboard_for_pdumper);
 }