Skip to content

Commit c98bb1c

Browse files
committed
ci(pytest): focus_force() crashes on Linux/X11 in python3.9 headless environments
So use focus_set() instead.
1 parent 118aeb6 commit c98bb1c

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

ardupilot_methodic_configurator/frontend_tkinter_parameter_editor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ def ask_user_choice(title: str, message: str, options: list[str]) -> ExperimentC
940940
# Show dialog at correct position and make it modal
941941
# On macOS, grab_set() causes UI freeze (issue #1264), so skip it
942942
if sys_platform != "darwin":
943-
dialog.focus_force()
943+
dialog.focus_set() # focus_force() crashes on Linux/X11 in python3.9 headless environments
944944
dialog.grab_set()
945945

946946
# Set focus after dialog is shown and modal

ardupilot_methodic_configurator/frontend_tkinter_parameter_editor_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ def _center_and_focus_window(self, window: Union[tk.Toplevel, tk.Tk]) -> None:
990990

991991
# On macOS, grab_set() causes UI freeze (issue #1264), so skip it
992992
if sys_platform != "darwin":
993-
window.focus_force()
993+
window.focus_set() # focus_force() crashes on Linux/X11 in python3.9 headless environments
994994
window.grab_set()
995995

996996
def _confirm_parameter_addition(self, param_name: str) -> bool:

ardupilot_methodic_configurator/frontend_tkinter_usage_popup_window.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,11 @@ def finalize_setup_popupwindow(
114114
popup_window.root.deiconify()
115115
popup_window.root.lift()
116116
popup_window.root.update() # Ensure the window is fully rendered before setting focus
117-
# Defer focus_force to after the event loop has processed the deiconify/lift,
118-
# avoiding a segfault in Python 3.9 on Linux (X11) in headless environments.
119-
popup_window.root.after(1, popup_window.root.focus_force)
117+
# Use focus_set() instead of focus_force(): focus_force() calls XSetInputFocus
118+
# directly via X11, which causes a segfault in Python 3.9 on Linux in headless
119+
# environments. focus_set() only updates Tk's internal focus state, avoiding the crash.
120+
# grab_set() below ensures modality regardless.
121+
popup_window.root.focus_set()
120122

121123
# On macOS, grab_set() causes UI freeze (issue #1264), so skip it
122124
# On Windows/Linux, make the popup modal and give it focus

0 commit comments

Comments
 (0)