In no signal I’m trying to add a new embedded window, for a total of two embedded windows: the notes window and the map window. I want the user to be able to show and hide these windows, but for some reason when I make a window visible and tell it to grab focus, the other window does not update its visual appearance to show that it is unfocused:

func _on_notes_button_pressed() -> void:
	notes_ui.visible = not notes_ui.visible
	if notes_ui.visible:
		notes_ui.grab_focus()
 
func _on_map_button_pressed() -> void:
	map_ui.visible = not map_ui.visible
	if map_ui.visible:
		map_ui.grab_focus()

I wasn’t able to find a way to explicitly drop focus or find out why the other window was not dropping focus, so I worked around it by grabbing the focus of all of the other windows before grabbing the focus of the window I wanted to focus:

func _on_notes_button_pressed() -> void:
	notes_ui.visible = not notes_ui.visible
	if notes_ui.visible:
		focus_window(notes_ui)
 
func _on_map_button_pressed() -> void:
	map_ui.visible = not map_ui.visible
	if map_ui.visible:
		focus_window(map_ui)
 
func focus_window(window_to_focus: Window) -> void:
	# For some reason, focus isn't dropped when we focus the new window and
	# there's no function to explicitly drop focus. So, to work around this
	# we focus the window we want to unfocus right before we focus the
	# window we want to focus
	for window: Window in get_viewport().get_embedded_subwindows():
		if window != window_to_focus:
			window.grab_focus()
 
	window_to_focus.grab_focus()