Recover minimized window correctly on gui input

Godot Version

4.2.1

Question

I have made a “minimize” button on my application, when clicked it minimizes the window to the taskbar. When I bring the application window back up, no matter where I click, it just minimizes it again. The correct usage would be the minimize buttont minimizes the window and when the window/application is brought back up again, it acts normal… A lot of forums show to use OS instead of DisplayServer but from what I can see OS doesn’t offer window settings anymore. Hopefully someone can help me with this, thanks.

func _on_gui_input(event):
	if event is InputEventMouseButton:
		if event.button_index == MOUSE_BUTTON_LEFT:
			if types == TYPES.close:
				get_tree().quit()
			elif types == TYPES.maximize:
				DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_MAXIMIZED)
			elif types == TYPES.minimize:
				DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_MINIMIZED)
1 Like

This looks like it is related to Buttons that miss mouse up events consume unrelated clicks afterwards · Issue #89917 · godotengine/godot · GitHub which will get fixed by Fix a special case for button masks by Sauermann · Pull Request #89926 · godotengine/godot · GitHub.

1 Like

Just an FYI, this has solved my issue, whether it is the best fix or not it seems to work.

var is_minimized = false

func _on_gui_input(event):
	if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
		if is_minimized:
			DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
			is_minimized = false
		else:
			DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_MINIMIZED)
			is_minimized = true
1 Like