penrose
penrose copied to clipboard
Options to disable focus on mouse hover & mouse repositioning on window focus switching
Hello again! Before anything, I'd like to thank you for starting this project - it's been pretty fun to use and configure penrose, and it's pretty close to becoming my primary window manager.
So, there are two related mechanics on penrose which there doesn't seem to have options to disable them:
- Focus on mouse hover: when the mouse cursor hovers over a window, the focus goes to said window.
-
Mouse repositioning on window focus switching: when a window is focused via keyboard (with the
cycle_client
anddrag_client
commands), the mouse cursor is automatically placed at the center of said focused window.
To solve that there could be two new related bool
fields in the penrose::core::data_types::Config
struct - something like focus_on_hover
and reposition_cursor_on_focus
.
Hi! Thank you for taking an active interest in Penrose, it's really encouraging to see other people using it.
I think that adding the suggested config options and threading them through the WindowManager should be fairly simple to do but my gut feeling is that it's going to lead to some odd behaviour in a few places. I generally prefer "focus follow mouse" (hence the default behaviour) but before I got it implemented, the focus state of each Workspace (and sometimes the WindowManager as a whole) was prone to corrupting in places. Hopefully that is all ironed out now but I wouldn't want to guarantee that enforcing "focus follow mouse" isn't what's holding everything together(!)
The issues I was seeing were around new windows assuming they had focus on creation but the mouse pointer (or active focus) also setting a window to assume it had focus. That itself shouldn't be to fiddly to sort but it will complicate the focusing logic I suspect.
Presumably you'd want "click to focus"? If so, this would mean finally implementing listening to mouse button events which we currently drop on the floor :sweat_smile: (again, not massively complicated, but something to consider).
Yup, it would technically be a "click to focus". You could also simply add the option to disable the "focus follow mouse" and implement the "click to focus" later, but I'm not sure if that would be a good idea :P
@sminez As far as I can tell, this might be the last remaining blocker before I can switch over to using penrose instead of xmonad (besides porting the functionality I currently have in xmonad).
I would like to try my hand at implementing this, unless you prefer to do it yourself. I am guessing I would have to add some fields to Config
and modifying some of the internal methods on WindowManager
, is that correct?
Hey @TethysSvensson :wave:
If you are up for it I'd definitely be happy to accept this as a contribution. It's a little bit more than you suggest I think: for one thing this will involve handling mouse click events correctly (as opposed to the current handling of "button was clicked"). I haven't looked at this area of the code for a while I'm afraid, but hopefully there aren't too many horror stories in there. I have a PR open now that is improving the logic and testing around setting client focus but other than that, there isn't a huge amount of test coverage for what is there currently.
It would probably be best to get some tests in place first to pin down when focus is / is not updated in response to specific actions. If you take a look at the hook tests you should see how I have things set up for feeding in a stream of XEvents and checking that the correct state is maintained at the end. Once that's in place, you should be able to make the change to disable focus follow mouse and see what breaks :sweat_smile: Hopefully not too much, which should mean that yeah: it'll be the case of adding a new flag to Config
and modifying the methods that set focus in WindowManager
. If possible, factoring all that out to be a method that just early returns based on the value set in config is probably going to be the easiset to maintain long term.
Let me know how you get on with things! I'm working on a couple of changes at the moment (when I have time) but I don't think they should impact you working on this in parallel.
:sweat_smile:
Thanks you for the very detailed description. It makes a lot of sense that you would like to get tests improved before changing this part of the code. However doing these changes does seem a bit overwhelming, and I think it might be beyond my current understanding of the code.
Perhaps I will get back to this issue, once I become more comfortable with the code-base.
By the way, have you set up somewhere to discuss penrose with other users? Perhaps a discord server?
No worries 😄
This is all very much still a work in progress so there is definitely ni expectation for anyone other than me to deal with sorting out issues like this at the moment. I don't have anything set up as a place to discuss Penrose, no. It might be worthwhile setting something up but I'm not sure how much demand there is for it :male_shrug:
Would you mind opening an issue for that so I can gauge the interest levels from users?
Hello! I'm coming back to this issue now (2 years, wow... time passes by really fast.) and I think I've had an idea for the "click to focus" part - maybe adding a left-click keybinding with an action that gets the topmost client at the current mouse's coordinates, then focusing it. I'm not fully sure how get to this, though - is there any way to do that at the moment?
I think the only bit missing is whether or not you can get the active window from the cursor position or not? That sounds like it shouldn't be that tricky but I'll need to add it to the XConn API potentially.
Once that's done, you should be able to write an action that is essentially "get the ID of the window under the cursor, set it as the focus" and turn off focus follow mouse in your Config
@YohananDiamond I've been clearing out old issues in GitHub after working on some recent changes and I had forgotten about this one I'm afraid. As of the move to the new 0.3
APIs this has now been implemented via the focus_follow_mouse field on Config
(!)
I've not made extensive use of it myself but the implementation was based on what can be found in XMonad so hopefully that will suit your needs @TethysSvensson (if you are still interested in using Penrose that is)?