Commit: patch 9.2.0851: Focus autocommands triggered inconsistently

Christian Brabandt <[email protected]>
Newsgroups gmane.editors.vim.devel
Message-ID <[email protected]>
patch 9.2.0851: Focus autocommands triggered inconsistently

Commit: https://github.com/vim/vim/commit/729c10990ddfe736af2cc04ed7721dd64d4a5a49
Author: Christoffer Aasted <[email protected]>
Date:   Fri Jul 24 20:31:48 2026 +0000

    patch 9.2.0851: Focus autocommands triggered inconsistently
    
    Problem:  Focus autocommands triggered inconsistently
    Solution: Suppress dialog-generated focus events while a dialog is
              active and on X11 ignore the restoring focus_in_event()
              from closing a dialog (Christoffer Aasted).
    
    closes: #20780
    
    Signed-off-by: Christoffer Aasted <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/gui.c b/src/gui.c
index 3457c88f1..0e1306c86 100644
--- a/src/gui.c
+++ b/src/gui.c
@@ -485,6 +485,11 @@ gui_init_check(void)
     result = OK;
 #else
 # ifdef FEAT_GUI_GTK
+    gui.is_x11 = false;
+#  ifdef FEAT_GUI_DIALOG
+    gui.dialogs_active = 0;
+    gui.dialog_focus_pending = 0;
+#  endif
 #  ifdef GDK_WINDOWING_WAYLAND
     gui.is_wayland = false;
 #  endif
@@ -4905,7 +4910,11 @@ gui_focus_change(int in_focus)
     // Put events in the input queue only when allowed.
     // ui_focus_change() isn't called directly, because it invokes
     // autocommands and that must not happen asynchronously.
-    if (!hold_gui_events)
+    if (!hold_gui_events
+# if defined(FEAT_GUI_GTK) && defined(FEAT_GUI_DIALOG)
+	    && gui.dialogs_active == 0
+# endif
+       )
     {
 	char_u  bytes[3];
 
diff --git a/src/gui.h b/src/gui.h
index aa9f94ec9..1fadca0f0 100644
--- a/src/gui.h
+++ b/src/gui.h
@@ -412,6 +412,14 @@ typedef struct Gui
     char_u	*browse_fname;	    // file name from filedlg
 
     guint32	event_time;
+# ifdef FEAT_GUI_DIALOG
+    // Multiple dialogs not allowed, just tracked for future use.
+    int		dialogs_active;     // number of active GUI dialogs
+
+    // X11 focus_in_event() by dialogs, ignored to match wayland.
+    int		dialog_focus_pending;
+# endif
+    bool	is_x11;	            // active gdk backend in gtk is x11
 # ifdef GDK_WINDOWING_WAYLAND
     bool	is_wayland;	    // active gdk backend in gtk is wayland
 # endif
diff --git a/src/gui_gtk.c b/src/gui_gtk.c
index 13eaf70a7..620480289 100644
--- a/src/gui_gtk.c
+++ b/src/gui_gtk.c
@@ -1709,6 +1709,10 @@ gui_mch_dialog(int	type,	    // type of dialog
     int		response;
     DialogInfo  dialoginfo;
 
+    ++gui.dialogs_active;
+    if (gui.is_x11)
+	++gui.dialog_focus_pending;
+
     dialog = create_message_dialog(type, title, message);
     dialoginfo.dialog = GTK_DIALOG(dialog);
     dialog_add_buttons(GTK_DIALOG(dialog), buttons);
@@ -1796,6 +1800,7 @@ gui_mch_dialog(int	type,	    // type of dialog
 	gtk_widget_destroy(dialog);
     }
 
+    --gui.dialogs_active;
     return response > 0 ? response : 0;
 }
 
diff --git a/src/gui_gtk_x11.c b/src/gui_gtk_x11.c
index b12f4b22c..098892d5c 100644
--- a/src/gui_gtk_x11.c
+++ b/src/gui_gtk_x11.c
@@ -1080,7 +1080,12 @@ focus_in_event(GtkWidget *widget,
 	       GdkEventFocus *event UNUSED,
 	       gpointer data UNUSED)
 {
-    gui_focus_change(TRUE);
+#ifdef FEAT_GUI_DIALOG
+    if (gui.is_x11 && gui.dialog_focus_pending > 0)
+	--gui.dialog_focus_pending;
+    else
+#endif
+	gui_focus_change(TRUE);
 
     if (blink_state == BLINK_NONE)
 	gui_mch_start_blink();
@@ -4136,6 +4141,7 @@ gui_mch_init(void)
 #if GTK_CHECK_VERSION(3,4,0)
     if (GDK_IS_X11_DISPLAY(gdk_display_get_default()))
     {
+	gui.is_x11 = true;
 	// for X11, if we were using smooth scroll events, we
 	// would get an scroll without deltas on the very first user scroll* and
 	// get both "unsmooth" scroll and smooth scroll events after
diff --git a/src/version.c b/src/version.c
index 028ab8880..422af5fda 100644
--- a/src/version.c
+++ b/src/version.c
@@ -758,6 +758,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    851,
 /**/
     850,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1wnMlV-00C8Ed-1g%40256bit.org.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.