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

Added option to stop cursor from following focused windows #765

Merged
merged 8 commits into from Jun 21, 2022

Conversation

Syudagye
Copy link
Contributor

@Syudagye Syudagye commented May 14, 2022

Description

A little feature that adds the mouse_follows_focus option that will decide if the cursor will follow windows as they're focused or not.
Currently when you change the focused window, the cursor will be placed on the center of the newly created window, and that can sometimes be a bit annoying.
I can also lead to some problematic behaviors: for example when a window spawns a popup sub-window, and focusing the parent window forces you to focus the popup, the cursor would always teleport in the center of the popup when you try to escape it, and so your cursor would be stuck in the popup. This happened a lot to me with kde applications, such as kdenlive and krita.
I've discussed this feature idea briefly on discord a while ago, but didn't really went to try to implement it since then.

I couldn't find any related issue for this feature, let me know if one exists so i can reference it here.

This PR is just a draft, i couldn't finish it as fast as i would have liked it, so there is still stuff to do, and also I need others to see if the implementation is ok or needs more work.

The cursor will not teleport when:

  • Changing focus
  • Spawning/Destroying a window
  • Resizing the main window
  • Changing layout*
  • Changing tag/workspace*
* Those looks like they are working, but still need to find if there is no issue

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Updated user documentation:

to be edited here: https://github.com/leftwm/leftwm/wiki/Config#focus-behaviour

Focus Behaviour

LeftWM now has 3 focusing behaviours (Sloppy, ClickTo, and Driven) and 2 options (focus_new_windows, sloppy_mouse_follows_focus), which alter the way focus is handled.
These encompass 5 different patterns:

  1. Sloppy Focus. Focus follows the mouse, hovering over a window brings it to focus. This behaviour have a variant which is toggled with the sloppy_mouse_follows_focus option:
  • When true, the cursor will follow the focus and teleport to the window that takes focus.
  • When false, the cursor isn't moved by LeftWM at all.
  1. Click-to-Focus. Focus follows the mouse, but only clicks change focus.
  2. Driven Focus. Focus disregards the mouse, only keyboard actions drive the focus.
  3. Event Focus. Focuses when requested by the window/new windows.

Default:

focus_behaviour = "Sloppy" # Can be Sloppy, ClickTo, or Driven
focus_new_windows = true
sloppy_mouse_follows_focus = true # Only active with the Sloppy behaviour

Note: This is only available in LeftWM >=0.2.8.

Checklist:

  • Ran make test locally with no errors or warnings reported
  • Enhanced review is performed with cargo clippy -- -W clippy::pedantic -A clippy::must_use_candidate -A clippy::cast_precision_loss -A clippy::cast_possible_truncation -A clippy::cast_possible_wrap -A clippy::cast_sign_loss -A clippy::mut_mut
  • Manual page has been updated accordingly
  • Wiki pages have been updated accordingly (to perform after merge)

@Syudagye
Copy link
Contributor Author

For now what i wanted for my personal use case have been addressed, but i'm looking forward to improve this.
First, i don't know if there is a better way to implement this option in the config (would it be better to have a completely new behavior?).

Also regarding the feeling of this addition, i made what was the most natural for me: the focus is recalculated when the cursor moves. But after looking at other window manager i noticed that it often changes focus only when a window is enter with the mouse. So i would like some feedback on which one could be the better option, and the most natural.

Also i have no idea why, but changing to a tag will focus the window under the cursor, even if i modified this in focus_handler.rs. I don't know what is forcing the focus on the mouse here.

@VuiMuich
Copy link
Member

VuiMuich commented Jun 6, 2022

Just started to get into this topic, but while answering questions on discord a thought came up: the reason why we have this is that in Sloppy focus mode when you drive focus away with the keyboard you would get unintentional refocus as soon as you move the mouse. In ClickTo and Driven this should not happen.
Of course with the necessary awareness, you could even build a workflow upon this refocus 🙃

Coming back to your questions later, sorry for all those delays.

@VuiMuich
Copy link
Member

VuiMuich commented Jun 8, 2022

For now what i wanted for my personal use case have been addressed, but i'm looking forward to improve this. First, i don't know if there is a better way to implement this option in the config (would it be better to have a completely new behavior?).

The more I get into this, the more I get the feeling this should actually be a variant of the Sloppy mode, as ClickTo and Driven are not effected by the initial issue at all, right?

Also regarding the feeling of this addition, i made what was the most natural for me: the focus is recalculated when the cursor moves. But after looking at other window manager i noticed that it often changes focus only when a window is enter with the mouse. So i would like some feedback on which one could be the better option, and the most natural.

Personally I think recalculating focus, when a window border is crossed is the most natural way, and I would expect it to be possibly a little less expensive.

Also i have no idea why, but changing to a tag will focus the window under the cursor, even if i modified this in focus_handler.rs. I don't know what is forcing the focus on the mouse here.

🤔 I would have guessed, that the same as you have in focus_handler.rs:80

@Syudagye
Copy link
Contributor Author

Syudagye commented Jun 8, 2022

The more I get into this, the more I get the feeling this should actually be a variant of the Sloppy mode, as ClickTo and Driven are not effected by the initial issue at all, right?

Yes, it's only with Sloppy. Perhaps renaming the mouse_follows_focus option to something that evokes that this is to activate a variant of the behaviour would be better. Maybe something like sloppy_static_mouse or sloppy_mouse_dont_follow_focus (the last one seems a bit too long tho...).

Personally I think recalculating focus, when a window border is crossed is the most natural way, and I would expect it to be possibly a little less expensive.

Ok this will be the way then.

Thank you for the feedback, i'll implement this asap !

@Syudagye
Copy link
Contributor Author

I finished tweaking the little things and i think it is now ready for merge.
I updated the wiki and the man page, so check it to see if it's ok like this of if it needs modifications

@Syudagye Syudagye marked this pull request as ready for review June 14, 2022 18:55
@VuiMuich
Copy link
Member

Reading on mobile this seems good to me.
I hope I can have a proper look at it before or at the weekend.

@VuiMuich VuiMuich merged commit 857f53a into leftwm:main Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants