ianyh / Amethyst

Automatic tiling window manager for macOS à la xmonad.
https://ianyh.com/amethyst/
MIT License
14.79k stars 488 forks source link

Support mouse-follows-focus for window focuses not performed by Amethyst #643

Open fooness opened 7 years ago

fooness commented 7 years ago

Dear community,

how do I get mouse-follows-focus working (and that’s the only thing I want, no tiling) for moving the cursor between monitor 1 and 2 when changing the focus via cmd-tab? I activated it, but it just does not work … sorry if I missed anything.

Or is there any other tool, which does exactly that? Did not find any yet …

Thank you!

screen shot 2017-08-22 at 20 23 58

Trello Card

dendeffe commented 7 years ago

Have the same problem. Downgraded all the way to 0.9.10 but it still persists.

ianyh commented 7 years ago

Have you tried the newest pre release?

fooness commented 7 years ago

Is there a way to install it via brew?

dendeffe commented 7 years ago

Tried 0.11.4b - doesn't make mouse follow, but does create erratic mouse behaviour: http://take.ms/oaduf

The mouse gets pushed away from the top corner until I quit Amethyst

ianyh commented 7 years ago

@fooness You can enable development versions in settings, relaunch the app, and then check for updates.

Do you have multiple screens? Could you let me know their arrangement in the display panel in System Preferences?

ianyh commented 7 years ago

Oh, sorry, I misread your preferences. @fooness you have the wrong one enabled. You want focus follows mouse, but there is a dIfferent setting called mouse follows focus. You have the second enabled right now.

@dendefe do you have the second one enabled in addition to mouse follows focus?

dendeffe commented 7 years ago

http://take.ms/FRV5h This is the arrangement - two external Iiyama plx2380H 23" (1920 x 1080) screens on the left, my laptop screen (retina 15.4" - 2880 x 1800) on the right

fooness commented 7 years ago

Updated to development release. No change so far.

I don’t need ~/.amethyst, do I?

screen shot 2017-08-23 at 15 55 37

macbook pro 13" retina on the left, cinema display on the right …

dendeffe commented 7 years ago

When I disable Focus follows mouse, the erratic mouse behaviour stops. Still no Mouse follows focus, though.

ianyh commented 7 years ago

Scratch that, I misread the entire issue. On a phone. Will take a better look when I get to a laptop.

ianyh commented 7 years ago

Okay, so general question: what are your expectations for how it should work?

fooness commented 7 years ago

CMD-tabbing to an application on the right monitor pushes the mouse to the center(?) of that application on the right monitor.

CMD-tabbing back to an application on the left monitor pushes the mouse back to the left monitor.

ianyh commented 7 years ago

Okay. So that is not currently how it works. It moves the mouse to a window when that window is focused by Amethyst, but Command+Tab is an OS level change. I don't think it is unreasonable -- perhaps it is even correct! -- to expect the mouse to move to windows when traversing to them via keyboard outside of the scope of Amethyst.

One tricky case to consider is what to do when the mouse itself was used to focus the window as you probably don't want the mouse to move out from under you. That is actually what was happening with the erratic mouse position for @dendeffe. focus-follows-mouse was causing Amethyst to focus the window, but mouse-follows-focus was moving the cursor to the center of the window. I think that @ifreecarve's work on mouse tracking could make detecting that case easier.

ianfixes commented 7 years ago

I can look into this. Full disclosure, it's not a feature that I use, and some experimenting just now suggests that either (1) I have no idea how to use this or (2) my mouse is not properly following focus.

@ianyh what's the use case for changing window focus using Amethyst (i.e. as opposed to cmd-tab)?

ianfixes commented 7 years ago

It looks like this will be as simple as adding focused && window.am_focusWindow() to FrameAssignment.perform(). However, this introduces the problem where changing focus via a mouse click causes the mouse pointer to recenter in that window.

Fortunately, there's an possible workaround using the mouse manager in #627 -- I might be able to track the last time a leftMouseUp event happens and ignore any focus behavior in the milliseconds immediately following it. That would require providing the mouse statekeeper instance to the FrameAssignment struct, and I'll defer to @ianyh on how best to do that.

ianyh commented 7 years ago

It's not that simple. Frame assignments are intentionally oblivious to side effects. All they do is set a frame. If they start focusing windows -- and worse, focusing with the intention of causing a mouse move -- suddenly it becomes tied up with the rest of the system. This would prevent optimizing them away, would necessitate preventing duplicates, and so on. I'm not sure what the right solution is.

The use case is that command tabbing is application level, Amethyst works at a window level.

peabnuts123 commented 7 years ago

As an outsider to this thread, it appears @dendeffe is speaking about an entirely separate issue. This thread is about Mouse Follows Focus, and not Focus Follows Mouse. I too came here looking to read about Focus Follows Mouse and got a bit confused reading this thread.

ianyh commented 6 years ago

I should really just rename the feature.

kdheepak commented 5 years ago

I too would like this feature. In hammerspoon this is how I implemented it:

windows = hs.window.filter.new()

-- make mouse always in the center of focused window
windows:subscribe(hs.window.filter.windowFocused, function(window, appName)
    local f = window:frame()
    hs.mouse.setAbsolutePosition({x=(f.x + (f.w / 2)), y=(f.y + (f.h / 2))})
end)