rust-windowing / rust-windowing/winit

Abstraction over window input areas

Open
#4,368 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

S - enhancement
Dominant language
Rust
Stars
6.2k
Forks
1.3k
Avg merge
2d 19h
Merged PRs (30d)
9

Description

Description

I'm working on a desktop toy of sorts with a no decoration window that should only be click interactable on the area that it's currently drawing to. On most desktop platforms you can just always have it be click transparent unless the global cursor position is over the area you want, but on Wayland this is problematic because Wayland (by design) presents no mechanism to get global cursor position, and stops sending cursor positions when you disable hittest.

This made me think that rather than having to "hand roll" this via manually controlling the hittest within your application maybe winit should instead expose some kind of common API for specifying what area of the window you want to successfully hit test.

The problematic part is that platforms have extremely different ways of handling windows with area that is input transparent. Windows has WM_NCHITTEST which is an API where you catch a hit test event and return whether the click should hit or not, X11 has XShape which supports a list of rectangles or a 1 bit pixmap, Wayland has input regions which are strictly a list of rectangles. I am unfamiliar with the situation on MacOS but I believe that it's simply the "default behavior" that undrawn areas are click transparent. I looked into it and it seems to be more like windows where you implement a function override, catching the test and then returning whether it should hit. Obviously these can be abstracted away, but the question becomes what abstraction models the concept closest.

Random idea throw out:

  • Some kind of enum over it, which you can provide a mask or a list of rectangles or so on. Potentially a footgun, because choosing an "incorrect" option could result in suboptimal performance due to the conversion required.
  • A simple boolean for "only hit area which you draw to" - limited, has performance implications on platforms which only support rectangles
  • Just expose each relevant API on the platform level as extension traits

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files, tests, or entry points are named. Start by comparing the described Windows, X11, Wayland, and macOS input-area mechanisms and determine which common abstraction can represent them without unacceptable platform-specific behavior; done means a resolved API design with agreed platform semantics.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
desktop
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.