From b71605ba16879148bb8283c57a1a7d05b5f59015 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sun, 2 Aug 2026 07:10:30 +0300
Subject: [PATCH 42/42] gtk4(x): Don't pause music when "Turn Done" button
 pressed

Grab the focus to another widget before "Turn Done"
button goes insensitive. That avoids freeciv window from
losing focus completely. This in turn fixes behavior
of the "Silent when not in focus" client option.

See RM #2107

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/gui-gtk-4.0/gui_main.c | 4 ++++
 client/gui-gtk-5.0/gui_main.c | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/client/gui-gtk-4.0/gui_main.c b/client/gui-gtk-4.0/gui_main.c
index 5fe56b5cef..4be6d72ea0 100644
--- a/client/gui-gtk-4.0/gui_main.c
+++ b/client/gui-gtk-4.0/gui_main.c
@@ -2263,6 +2263,10 @@ static gboolean show_info_popup(GtkGestureClick *gesture, int n_press,
 **************************************************************************/
 static void end_turn_callback(GtkWidget *w, gpointer data)
 {
+  /* Button going insensitive is going to lose focus. Keep focus at least
+   * within the window */
+  gtk_widget_grab_focus(map_canvas);
+
   gtk_widget_set_sensitive(turn_done_button, FALSE);
   user_ended_turn();
 }
diff --git a/client/gui-gtk-5.0/gui_main.c b/client/gui-gtk-5.0/gui_main.c
index a2316a4f19..3d7139cd88 100644
--- a/client/gui-gtk-5.0/gui_main.c
+++ b/client/gui-gtk-5.0/gui_main.c
@@ -2322,6 +2322,10 @@ static gboolean show_info_popup(GtkGestureClick *gesture, int n_press,
 **************************************************************************/
 static void end_turn_callback(GtkWidget *w, gpointer data)
 {
+  /* Button going insensitive is going to lose focus. Keep focus at least
+   * within the window */
+  gtk_widget_grab_focus(map_canvas);
+
   gtk_widget_set_sensitive(turn_done_button, FALSE);
   user_ended_turn();
 }
-- 
2.53.0

