Subject: Re: bug#26104: 26.0.50; In Ubuntu, having mouse over other frame cause Alt key to produce a <switch-frame> event

From: martin rudalics <[email-masked]>
Date: Sat, 08 Apr 2017 10:59:58 +0200

> Magical incantations! ;-) I positioned it and then used `xinput
 > disable ID` for both my mouse and trackpad.

And what would make you that sure that the `handle-switch-frame' event
was not inserted before you disabled xinput?

Anyway, as a first attempt try to apply the attached patch to keyboard.c
and tell me what the value of the variable `lispy-switch-frame-source'
is when you try your M-y.

martin
diff --git a/src/keyboard.c b/src/keyboard.c
index 3e50142..f3a9dcf 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -3481,6 +3481,7 @@ static Lisp_Object kbd_buffer_get_event (KBOARD **kbp, bool *used_mouse_menu,

 	  if (single_kboard && kb != current_kboard)
 	    {
+	      Vlispy_switch_frame_source = Qkbd_buffer_store_buffered_event;
 	      kset_kbd_queue
 		(kb, list2 (make_lispy_switch_frame (event->ie.frame_or_window),
 			    make_number (c)));
@@ -4024,7 +4025,10 @@ static Lisp_Object kbd_buffer_get_event (KBOARD **kbp, bool *used_mouse_menu,
 #endif
               !EQ (frame, internal_last_event_frame)
               && !EQ (frame, selected_frame))
-            obj = make_lispy_switch_frame (frame);
+	    {
+	      Vlispy_switch_frame_source = Qfocus_in_event;
+	      obj = make_lispy_switch_frame (frame);
+	    }
           else
             obj = make_lispy_focus_in (frame);

@@ -4100,7 +4104,10 @@ static Lisp_Object kbd_buffer_get_event (KBOARD **kbp, bool *used_mouse_menu,

 	  if (! EQ (frame, internal_last_event_frame)
 	      && !EQ (frame, selected_frame))
-	    obj = make_lispy_switch_frame (frame);
+	    {
+	      Vlispy_switch_frame_source = Qdifferent_frame;
+	      obj = make_lispy_switch_frame (frame);
+	    }
 	  internal_last_event_frame = frame;

 	  /* If we didn't decide to make a switch-frame event, go ahead
@@ -4171,7 +4178,10 @@ static Lisp_Object kbd_buffer_get_event (KBOARD **kbp, bool *used_mouse_menu,

 	  if (! EQ (frame, internal_last_event_frame)
 	      && !EQ (frame, selected_frame))
-	    obj = make_lispy_switch_frame (frame);
+	    {
+	      Vlispy_switch_frame_source = Qmouse_track;
+	      obj = make_lispy_switch_frame (frame);
+	    }
 	  internal_last_event_frame = frame;
 	}

@@ -9169,6 +9179,7 @@ static void process_tool_bar_item (Lisp_Object, Lisp_Object, Lisp_Object,
 		  {
 		    Lisp_Object frame;
 		    XSETFRAME (frame, interrupted_frame);
+		    Vlispy_switch_frame_source = Qread_key_sequence;
 		    kset_kbd_queue
 		      (interrupted_kboard,
 		       Fcons (make_lispy_switch_frame (frame),
@@ -10498,9 +10509,11 @@ shows the events before all translations (except for input methods).

   if (FRAMEP (internal_last_event_frame)
       && !EQ (internal_last_event_frame, selected_frame))
-    do_switch_frame (make_lispy_switch_frame (internal_last_event_frame),
+    {
+      Vlispy_switch_frame_source = Qquit_throw_to_read_char;
+      do_switch_frame (make_lispy_switch_frame (internal_last_event_frame),
 		     0, 0, Qnil);
-
+    }
   sys_longjmp (getcjmp, 1);
 }
 
@@ -11242,6 +11255,13 @@ struct event_head
   help_form_saved_window_configs = Qnil;
   staticpro (&help_form_saved_window_configs);

+  DEFSYM (Qkbd_buffer_store_buffered_event, "kbd_buffer_store_buffered_event");
+  DEFSYM (Qfocus_in_event, "focus_in_event");
+  DEFSYM (Qdifferent_frame, "different_frame");
+  DEFSYM (Qmouse_track, "mouse_track");
+  DEFSYM (Qread_key_sequence, "read_key_sequence");
+  DEFSYM (Qquit_throw_to_read_char, "quit_throw_to_read_char");
+
   defsubr (&Scurrent_idle_time);
   defsubr (&Sevent_symbol_parse_modifiers);
   defsubr (&Sevent_convert_list);
@@ -11833,6 +11853,11 @@ shutdown when Emacs receives a fatal signal (e.g., a crash).
                Vwhile_no_input_ignore_events,
                doc: /* Ignored events from while-no-input.  */);
   Vwhile_no_input_ignore_events = Qnil;
+
+  DEFVAR_LISP ("lispy-switch-frame-source",
+               Vlispy_switch_frame_source,
+               doc: /* Source of last lispy-switch-frame event.  */);
+  Vlispy_switch_frame_source = Qnil;
 }

 void