1
0
Fork 0

Fix window-clickthrough

What was happening here is that because we were detecting window clicks
inside _input, when you clicked overlapping windows, all of them would
receive the click, and all of them would set themselves to active and
move to the foreground. The solution to this was to move the
click-detection into _gui_input instead, which stops the event from
traveling to the back elements. There is, however, a gotcha. Because
_gui_input only fires on the topmost element clicked, the window itself
doesn't receive the event because its children are covering it up and
receive the event instead. To work around this I iterated all the
children of the window, connecting to and forwarding their _gui_input
events to the window root. Thus, buttons still work when you click on
them, but the window also gets to respond as it needs to.
This commit is contained in:
under 2024-03-20 15:17:22 -07:00
parent 6286d4338a
commit 35a8fc2f1a
1 changed files with 20 additions and 2 deletions

View File

@ -7,13 +7,31 @@ extends Control
var windowed_rect: Rect2
func _input(event: InputEvent):
func get_descendants(node: Node) -> Array[Node]:
var nodes: Array[Node] = []
for child in node.get_children():
if child.get_child_count() > 0:
nodes.append(child)
nodes.append_array(get_descendants(child))
else:
nodes.append(child)
return nodes
func _ready() -> void:
for descendant in get_descendants(self):
descendant.gui_input.connect(_gui_input)
func _gui_input(event: InputEvent) -> void:
if event is InputEventMouseButton:
if event.pressed:
if get_global_rect().has_point(get_global_mouse_position()):
desktop.current_window = self
get_parent().move_child(self, get_parent().get_child_count())
elif event is InputEventKey:
func _input(event: InputEvent):
if event is InputEventKey:
if event.keycode == KEY_F11:
if event.pressed:
if desktop.current_window == self: