Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mouse_passthrough_rectangles #8568

Open
arlo-phoenix opened this issue Dec 2, 2023 · 7 comments · May be fixed by godotengine/godot#88558
Open

Add mouse_passthrough_rectangles #8568

arlo-phoenix opened this issue Dec 2, 2023 · 7 comments · May be fixed by godotengine/godot#88558

Comments

@arlo-phoenix
Copy link

arlo-phoenix commented Dec 2, 2023

Describe the project you are working on

A transparent overlay with many widgets spread out on the screen.

Describe the problem or limitation you are having in your project

It is not straightforward to add multiple mouse passthrough regions. On X11 it is possible to make a polygon out of several rectangles (4 points each in the array), but that doesn't always work like when there are overlaps and I doubt this functionality was really intended in the first place.

With people slowly moving on from X11 and polygons not being supported in Wayland's wl_region this would bring back an API working on all major desktop display servers.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add a new window property which contains a list of rectangles which works the same as the current mouse_passthrough_polygon. I think mouse_passthrough_rectangles is a fitting name.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

For this to work:

  1. Window needs the new property mouse_passthrough_rectangles of type TypedArray<Rect2i>
  2. The DisplayServer needs a new method window_set_mouse_passthrough_rectangles (similar to window_set_mouse_passthrough for polygons)
  3. The platform dependent DisplayServers need to be updated to work with the new property.

I already implemented a quick prototype for X11 and Wayland.

The idea there is to not remove mouse passthrough polygon support on the display servers that currently have it, but instead create a combined Region with the specific API's. So first create a region based on the passthrough polygon and then combine/union it with every rectangle.

  • Windows has
HRGN hrgn = CreateRectRgn(0, 0, 0, 0);
CombineRgn(region, region, hrgn, RGN_OR);

so you can just use it same as I did in the X11 implementation.

  • MacOS leaves passthrough handling to the application anyways so it's possible there as well by checking if a point intersects any of the rectangles.

If this enhancement will not be used often, can it be worked around with a few lines of script?

No. Passthrough is handled within the different DisplayServers.

Is there a reason why this should be core and not an add-on in the asset library?

Not possible with an add-on.

@Riteo
Copy link

Riteo commented Dec 2, 2023

The idea there is to not remove mouse passthrough polygon support on the display servers that currently have it, but instead create a combined Region with the specific API's. So first create a region based on the passthrough polygon and then combine/union it with every rectangle.

Oooh, that's clever! I was slightly concerned about what we would do to the poly API.

Still, I wonder, should we mark it as deprecated?

@Calinou
Copy link
Member

Calinou commented Dec 3, 2023

Still, I wonder, should we mark it as deprecated?

Considering Linux distributions are starting to move away from X11 as a default, it makes sense to deprecate this API when Wayland is merged.

@Riteo
Copy link

Riteo commented Dec 3, 2023

@Calinou note that poly regions are also available on Windows and MacOS, it's not an X11 only thing.

@arlo-phoenix
Copy link
Author

Still, I wonder, should we mark it as deprecated?

I think changing the documentation under that polygon that the rectangle one is recommended for wider support is enough. Like if someone wants to use polygon regions for more accurate passthrough it'd be pretty hard to accurately do it with rectangles. This is a very niche property not used by games and mostly tools anyways and it's not worth it to deprecate that imo.

@Riteo
Copy link

Riteo commented Dec 4, 2023

@arlo-phoenix great point. Count me as favorable to this idea :D

@arlo-phoenix
Copy link
Author

Since I don't see anyone against it I plan to work on this in the near future (since polygon passthrough already exists seems like an easy change). Just a quick question: Should the property/functions be called mouse_passthrough_rectangles or mouse_passthrough_rects? Since the class is called Rect2i I assume mouse_passthrough_rects is correct.

@Riteo
Copy link

Riteo commented Dec 15, 2023

@arlo-phoenix I just grepped the code for rectangle( and rect( (with plural alternatives) and it looks like there are both of those, although with a preference for rect, so I'd go for that.

Also note that the method/property name is pretty long, so I'd also choose rect because of this reason.

@arlo-phoenix arlo-phoenix linked a pull request Feb 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants