Project

General

Profile

Actions

Bug #2442

open

gtk4 - allow focus unit that is not idle

Added by Andrew McGuinness 8 days ago. Updated 8 days ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
11/03/2026
Due date:
% Done:

0%

Estimated time:

Description

In the GTK 4.0 client, "Activate unit, close dialog" on the city screen does not give focus to the activated unit if it is Sentry or Fortified. You have to go in to the city twice, once to activate the unit, and again to give it the focus once it is in ACTIVITY_IDLE.

This was introduced as a fix for the crash #1868 , affecting both the city dialog and the unit selection dialog.

However, there is not an issue with giving focus to a unit in Sentry or Fortified state. The crashes in #1868 were caused, I believe, by removing the Event Controller from the unit icon in the city dialog while in a callback from that Event Controller.

The first patch here essentially reverts the fix for #1868 (and reintroduces that crash if you left-click or middle-click on a sentried unit in the city dialog)

The second patch restructures the lifetime of the Event Controllers in the Supported & Present Units boxes of the city dialog, to be created when the unit icon holders are created, and reset rather than removed and replaced when the dialog is refreshed. That avoids the crash.

(Logically they should really be the other way around).

I haven't found in the GTK docs if it is documented as unsafe to call gtk_widget_remove_controller from the callback of an event that controller generated. In general, I think it is quite common to deallocate GUI resources from their own callbacks - that is what a close button most often does. But the fix works for me. Note that (at least for me) the crash only happens when activating a unit with the mouse button, never from the popover menu.


Files

Actions #1

Updated by Andrew McGuinness 8 days ago

Redone the two patches as one, with more simplification, fully reverting the unit_focus_try() function.

Actions

Also available in: Atom PDF