From 845a09a62bb545d3214cea62d4464893ff863d9c Mon Sep 17 00:00:00 2001 From: under Date: Wed, 20 Mar 2024 11:27:27 -0700 Subject: [PATCH] Prevent multiple windows from being dragged at the same time Before this, if the headers of two windows overlapped and you clicked and dragged in that overlap, both windows would move at the same time. After this, only the front window gets dragged. The way that this works is that we use _gui_input instead of _input. This works because _gui_input is only sent to the top-level control. --- RetroWindowsGUI/DesktopWindow.tscn | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/RetroWindowsGUI/DesktopWindow.tscn b/RetroWindowsGUI/DesktopWindow.tscn index 4ab78a9..73aeebe 100644 --- a/RetroWindowsGUI/DesktopWindow.tscn +++ b/RetroWindowsGUI/DesktopWindow.tscn @@ -30,15 +30,7 @@ func getmosposi() -> Vector2i: func _input(event: InputEvent): if event is InputEventMouseButton: if event.button_index == MOUSE_BUTTON_LEFT: - if event.double_click: - if get_global_rect().has_point(get_global_mouse_position()): - window.toggle_maximized() - elif event.pressed: - if get_global_rect().has_point(get_global_mouse_position()): - dragging = true - begmosposi = getmosposi() - begwndpos = window.get_global_rect().position - elif event.is_released(): + if event.is_released(): dragging = false # snap within game window var rect = window.get_global_rect() @@ -50,6 +42,18 @@ func _input(event: InputEvent): elif event is InputEventMouseMotion: if dragging: window.global_position = begwndpos + getmosposi() - begmosposi + +func _gui_input(event: InputEvent): + if event is InputEventMouseButton: + if event.button_index == MOUSE_BUTTON_LEFT: + if event.double_click: + if get_global_rect().has_point(get_global_mouse_position()): + window.toggle_maximized() + elif event.pressed: + if get_global_rect().has_point(get_global_mouse_position()): + dragging = true + begmosposi = getmosposi() + begwndpos = window.get_global_rect().position " [sub_resource type="GDScript" id="GDScript_fvsxv"]