swaywm / sway

i3-compatible Wayland compositor
https://swaywm.org
MIT License
14.14k stars 1.08k forks source link

Ability to run an arbitrary command when mouse touches or collides with an edge or corner of a display #8039

Open kittydoor opened 4 months ago

kittydoor commented 4 months ago

I would like to improve my setup for input switching with my virtual machine, but I also see this as something that would provide an opportunity to create automations (such as Gnome's hot corners) to suit various use-cases.

I have found one implementation of a similar feature in AndreasBackx/waycorner, though it would be ideal to have this internal to the wm.

I see two options that would be ideal.

  1. Ability to subscribe to events to get collision with edge boundaries of a display
  2. Sway Config option to run an arbitrary command on collision (could be helpful to provide only a single entrypoint which is good enough for my usecase, or one per edge/corner that is configurable and handle detection of that internal to sway and make it more accessible for everyone)

In either case, useful information to provide would be:

  1. Location where collision happened (likely pixel coordinates)
  2. Display name where collision happened
  3. In case of multiple displays "enter" vs "exit" vs "stop" as event type
  4. Ideally an "impact strength" value so the script in question can decide what impact is required to trigger a function

Perhaps I can already implement this in a simple way,and am missing something obvious, if so please give me directions.

If support within Sway is not something that you find interesting, what would your advice be for building this behavior via an external application? The reason I make this issue is because given the choice I would rather avoid constantly polling exact location of the mouse and basically making a mouselogger with extra steps, but only look into edge collision events for displays.

PS: After being unable to find info on a way to make this via web searches, I gave in and tried ChatGPT/CoPilot to search further. Wow they are still utter garbage piles that make things up no matter how hard you try to convince them and help them to tell you something useful.

emersion commented 4 months ago

Why isn't waycorner sufficient?

WhyNotHugo commented 3 days ago

I wrote a client that implements hot corners this week: https://git.sr.ht/~whynothugo/wlhc (I had no idea that waycorner existed).

The main issue is swallowing clicks, which is only really relevant when the hot corner has a delay. Reproduction example:

This is the only real drawback of implementing this in a client. Using layer-shell is abusing the protocol a bit, but it otherwise works.

I think that ext-screencopy-v1 could be use if one tracks the cursor separately, but that is definitely abusing the protocol and would likely have an unreasonable overhead for a feature like this.