mahkoh / jay

A Wayland Compositor
GNU General Public License v3.0
207 stars 10 forks source link

pointer movement during focus changes #218

Open junelva opened 1 week ago

junelva commented 1 week ago

These commits make two changes: the addition of the command "center-pointer-on-focused" and the addition of the option move-pointer (bool) to the "show-workspace" command type.

This was needed for my two-monitor setup. In my practice, it looks like this in the config:

# example
# alt-space = "center-pointer-on-focused"

alt-h = ["focus-left", "center-pointer-on-focused"]
alt-j = ["focus-down", "center-pointer-on-focused"]
alt-k = ["focus-up", "center-pointer-on-focused"]
alt-l = ["focus-right", "center-pointer-on-focused"]

and


alt-1 = { type = "show-workspace", name = "1", move-pointer = true }
alt-2 = { type = "show-workspace", name = "2", move-pointer = true }
alt-3 = { type = "show-workspace", name = "3", move-pointer = true }
alt-4 = { type = "show-workspace", name = "4", move-pointer = true }
alt-5 = { type = "show-workspace", name = "5", move-pointer = true }
alt-6 = { type = "show-workspace", name = "6", move-pointer = true }
alt-7 = { type = "show-workspace", name = "7", move-pointer = true }
alt-8 = { type = "show-workspace", name = "8", move-pointer = true }
alt-9 = { type = "show-workspace", name = "9", move-pointer = true }
alt-0 = { type = "show-workspace", name = "10", move-pointer = true }

A known issue is that pairing "center-pointer-on-focused" with a command such as "move-left", the cursor actually snaps to the wrong location. Perhaps a bug in move (tl rect not updated?) but I didn't look into it yet. Another issue is that when alacritty hides the cursor during typing (a feature that I like!), the activation that was necessary in order to move cross-monitor can sometimes prevent that behavior from resuming - but it will after toggling fullscreen, so perhaps activating the cursor before the cursor jump (if invisible), then deactivating it again to the previous state will be necessary.

Additional work I intend to do is allowing the "focus-*" commands to move between outputs/monitors. But I wanted to submit the PR for review in case I'm doing this all wrong. While it's working for me locally already, there may be other issues. If you get a chance to look at it, I'm interested in your thoughts.

One contribution question I had - I wasn't sure about updating spec.yaml. I did so for the option, but not the new command. Should that be completed also?

Edit: Looks like the test for "show-workspace" will need to be updated too.

mahkoh commented 1 week ago

A known issue is that pairing "center-pointer-on-focused" with a command such as "move-left", the cursor actually snaps to the wrong location.

This is because the new layout is only scheduled to be computed at this point but has not actually been computed yet: https://github.com/mahkoh/jay/blob/f94f199ab12a4545a455a04aec11ec84b62f7c27/src/tree/container.rs#L949

Another issue is that when alacritty hides the cursor during typing (a feature that I like!), the activation that was necessary in order to move cross-monitor can sometimes prevent that behavior from resuming

This is because you don't call cursor_moved so the cursor owner is not updated.