godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.83k stars 21.14k forks source link

"DisplayServer.window_set_mouse_passthrough" causes flickering around polygon border #97399

Open sblobs opened 1 month ago

sblobs commented 1 month ago

Tested versions

System information

Godot v4.3.stable - Windows 10.0.19045 - GLES3 (Compatibility) - GeForce GTX 1060 - Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz (12 Threads)

Issue description

https://github.com/user-attachments/assets/2f9acf0a-c61e-41a9-808d-00f779bfc0fa

When using window_set_mouse_passthrough and updating the clickable polygon area (e.g. when the player drags a desktop pet around on their screen), it causes clipping around the borders of the polygon area.

Similar issue to #80098, except I get clipping around the borders of the polygon instead of whole screen flickering.

Steps to reproduce

Run the minimal reproduction project and drag the test object around at a relatively fast pace.

The clipping does not happen if DisplayServer.window_set_mouse_passthrough(passthrough_polygon) (line 25 of Scenes/pet.gd) is commented out.

Minimal reproduction project (MRP)

test_window_set_mouse_passthrough_clipping.zip

lettucegoblin commented 2 weeks ago

An ugly workaround for anyone looking to get something working at the moment before a fix is available can do the following:

func _process(delta: float) -> void:
    if _is_dragging:
        global_position = get_global_mouse_position() + _drag_start_position
    update_passthrough(_is_dragging) # Added _is_dragging as a parameter            <-----

func update_passthrough(_is_dragging: bool = false) -> void:
    # Added the following to disable passthrough on dragging            <-----
    if _is_dragging:
        DisplayServer.window_set_mouse_passthrough([])
        return
    var clickable_polygon: PackedVector2Array = clickable_area.polygon
    var passthrough_polygon: PackedVector2Array

    for vector in range(clickable_polygon.size()):
        passthrough_polygon.push_back(to_global(clickable_polygon[vector]))
    DisplayServer.window_set_mouse_passthrough(passthrough_polygon)

This won't help anyone who is looking to have the sprite move without the user dragging it though.