Focus-follows-mouse (plus auto-raise) on Mac OS X

[亡魂溺海] 提交于 2019-12-17 17:23:46

问题


(I don't want to hear about how crazy I am to want that! :)

Focus-follows-mouse is also known as point-to-focus, pointer focus, and (in some implementations) sloppy focus. [Add other terms that will make this more searchable!] X-mouse


回答1:


You can do it for Terminal.app by issuing the following command at the command line:

defaults write com.apple.Terminal FocusFollowsMouse -bool true

For X11 apps you can do this:

defaults write com.apple.x11 wm_ffm -bool true

In Snow Leopard, use this instead:

defaults write org.x.X11 wm_ffm -bool true

Apparently there's a program called CodeTek Virtual Desktop that'll emulate it systemwide, but it costs $$ (and they never got a version out for OSX Leopard).




回答2:


Steve Yegge wrote an essay about this a while back, where he tried and failed to write a suitable extension. I've since tried to find focus-follows-mouse applications for OS X and failed also.




回答3:


Focus-follows-mouse is not a particularly suitable input method for OS X because its menu bar was designed to be at the top of the screen. When you move the mouse out of your application window to get to the menus, if it crosses any other application's windows on the way, the menu changes.

So yes, in reply to dreeves comment, it works perfectly fine for Terminal (or for any other single application on the desktop), because the only other windows it's going to affect are Terminal windows, so the menu never changes as you switch windows. And it works fine for X11 because X11 apps generally have their menu bars embedded in the window, so you don't have to leave the window to access them.

Of course you can work around the menu-changing issue by introducing an artificial delay before the focus changes and/or the menu switches, but it's never going to work as well as it does on other desktops.




回答4:


Although this is far from a complete solution, two handy actions that are built into OSX (10.11) are:

⌃⌥-click (control-option-click) - switches focus without raising window

⌘-click (command-click) - clicks in window without switching focus

Not sure when these shortcuts were introduced, as I haven't been able to find them written about anywhere.




回答5:


The menu issue is the only reason traditional focus-follows-mouse wouldn't work.

Here's an alternative: don't change focus until a key is pressed on the keyboard. This would cover 95% of use cases for focus-follows-mouse, and would make this old curmudgeonly X user really happy. I don't know how many times I'll be scrolling through a web page in Chrome, and hit Command-T to open a new tab, and find the tab opening in the Terminal instead. If my brain hasn't picked up on this in 8 months of using a Mac, it never will.




回答6:


Amethyst supports this feature. It can be easily installed with brew cask install amethyst.

Here's the config file I use. It turns all the features off besides focus-follows-mouse. Save it to ~/.amethyst.

{
    "LAYOUTS": "----------------------",
    "layouts": [
    ],

    "MODIFIERS": "----------------------",
    "Valid modifiers are": [
        "option",
        "shift",
        "control",
        "command"
    ],

    "mod1": [
    ],
    "mod2": [
    ],

    "COMMANDS": "----------------------",
    "Commands are": {
        "cycle-layout": "Cycle layout to the next layout",
        "cycle-layout-backward": "Cycle layout to the previous layout",
        "focus-screen-1": "Focus the main window on the first screen",
        "focus-screen-2": "Focus the main window on the second screen",
        "focus-screen-3": "Focus the main window on the third screen",
        "focus-screen-2": "Focus the main window on the second screen",
        "focus-screen-3": "Focus the main window on the third screen",
        "focus-screen-4": "Focus the main window on the fourth screen",
        "throw-screen-1": "Throw the focused window to the first screen",
        "throw-screen-2": "Throw the focused window to the second screen",
        "throw-screen-3": "Throw the focused window to the third screen",
        "throw-screen-4": "Throw the focused window to the fourth screen",
        "shrink-main": "Shrink the main pane of the current layout",
        "expand-main": "Expand the main pane of the current layout",
        "increase-main": "Increase the number of windows in the main pane",
        "decrease-main": "Decrease the number of windows in the main pane",
        "focus-ccw": "Move window focus counter-clockwise on the current screen",
        "focus-cw": "Move window focus clockwise on the current screen",
        "swap-ccw": "Swap focused window with the next window going counter-clockwi$
        "swap-cw": "Swap focused window with the next window going clockwise",
        "swap-main": "Swap focused window with the main window of its screen",
        "throw-space-1": "Throw the focused window to the first space",
        "throw-space-2": "Throw the focused window to the second space",
        "throw-space-3": "Throw the focused window to the third space",
        "throw-space-4": "Throw the focused window to the fourth space",
        "throw-space-5": "Throw the focused window to the fifth space",
        "throw-space-6": "Throw the focused window to the sixth space",
        "throw-space-7": "Throw the focused window to the seventh space",
        "throw-space-8": "Throw the focused window to the eighth space",
        "throw-space-9": "Throw the focused window to the ninth space",
        "throw-space-8": "Throw the focused window to the eighth space",
        "throw-space-9": "Throw the focused window to the ninth space",
        "toggle-float": "Toggle the focused window between being floating and tiled"
    },

    "screens": "3",

    "cycle-layout": {
        "mod": "mod1",
    },
    "cycle-layout-backward": {
        "mod": "mod2",
    },
    "select-tall-layout": {
        "mod": "mod1"
    },
    "select-wide-layout": {
        "mod": "mod1"
    },
    "select-fullscreen-layout": {
        "mod": "mod1"
    },
    "select-column-layout": {
        "mod": "mod1"
    },
        "mod": "mod1"
    },
    "focus-screen-1": {
        "mod": "mod1"
    },
    "focus-screen-2": {
        "mod": "mod1"
    },
    "focus-screen-3": {
        "mod": "mod1"
    },
    "focus-screen-4": {
        "mod": "mod1"
    },
    "throw-screen-1": {
        "mod": "mod2"
    },
    "throw-screen-2": {
        "mod": "mod2"
    },
    "throw-screen-3": {
        "mod": "mod2"
    },
    "throw-screen-4": {
        "mod": "mod2"
    "throw-screen-4": {
        "mod": "mod2"
    },
    "shrink-main": {
        "mod": "mod1"
    },
    "expand-main": {
        "mod": "mod1"
    },
    "increase-main": {
        "mod": "mod1"
    },
    "decrease-main": {
        "mod": "mod1"
    },
    "focus-ccw": {
        "mod": "mod1"
    },
    "focus-cw": {
        "mod": "mod1"
    },
    "swap-screen-ccw": {
        "mod": "mod2"
    },
    "swap-screen-cw": {
    },
    "swap-screen-cw": {
        "mod": "mod2"
    },
    "swap-ccw": {
        "mod": "mod2"
    },
    "swap-cw": {
        "mod": "mod2"
    },
    "swap-main": {
        "mod": "mod1"
    },
    "throw-space-1": {
        "mod": "mod2"
    },
    "throw-space-2": {
        "mod": "mod2"
    },
    "throw-space-3": {
        "mod": "mod2"
    },
    "throw-space-4": {
        "mod": "mod2"
    },

        "mod": "mod2"
    },
    "throw-space-5": {
        "mod": "mod2"
    },
    "throw-space-6": {
        "mod": "mod2"
    },
    "throw-space-7": {
        "mod": "mod2"
    },
    "throw-space-8": {
        "mod": "mod2"
    },
    "throw-space-9": {
        "mod": "mod2"
    },
    "toggle-float": {
        "mod": "mod1"
    },
    "toggle-tiling": {
        "mod": "mod2"
    },
    "display-current-layout": {
        "mod": "mod1"
    "display-current-layout": {
        "mod": "mod1"
    },

    "MISC": "----------------------",
    "floating": [],
    "float-small-windows": false,
    "mouse-follows-focus": false,
    "focus-follows-mouse": true,
    "enables-layout-hud": false,
    "enables-layout-hud-on-space-change": false
}



回答7:


So I decided to improve again on the work I did on the MouseFocus.app which still had some flaws. Those are fixed now. I renamed the whole thing to "AutoRaise" to better reflect what this tool does: When you hover a window it will be raised to the front (with a delay of your choosing) and gets the focus. The tool can be downloaded here. To use it, copy it to your /Applications/ folder making sure it is executable (chmod 700 AutoRaise). Then double click it from within Finder. To quickly toggle it on/off you can use the applescript below and paste it into an automator service workflow. Then bind the created service to a keyboard shortcut via System Preferences|Keyboard|Shortcuts.

Update (29-03-2017): The AutoRaise binary has been updated. If no delay has been specified on the command line, it will now also look for an AutoRaise.delay file in the same folder. This is particularly useful when using the applescript below because 'launch application' does not support command line arguments. The delay should be specified in units of 50ms. For example to specify a delay of 150ms run this command once in a terminal: 'echo 3 > AutoRaise.delay'

on run {input, parameters}
    tell application "Finder"
        if exists of application process "AutoRaise" then
            quit application "/Applications/AutoRaise"
            display notification "AutoRaise Stopped"
        else
            launch application "/Applications/AutoRaise"
            display notification "AutoRaise Started"
        end if
    end tell
    return input
end run

Update (18-04-2019): The source https://github.com/sbmpost/AutoRaise




回答8:


I currently use MondoMouse and even with its quirks I couldn't use my mac without it. They have a free trial and I would recommend it to everyone.

MondoMouse




回答9:


Codetek had a product that did this but they never released a version for Leopard or later.

MondoMouse can sort of do focus-follows-mouse, but not auto-raise. Even the focus-follows-mouse is broken though. For example, it doesn't play well with command-tab (if you command-tab to a new application and don't touch the mouse then it should not switch focus back to wherever the mouse pointer happens to be -- I'm pretty sure every implementation in Linux I've seen gets this right but MondoMouse doesn't).

You can enable focus-follows-mouse (no autoraise) for just Terminal windows (just execute the following in a terminal):

defaults write com.apple.Terminal FocusFollowsMouse -string YES

And similarly for X11 windows:

defaults write org.x.X11 wm_ffm -bool true 

(For mac versions previous to 10.5.5 this was:

defaults write com.apple.x11 wm_ffm true

)

I don't know of any other applications that support it.




回答10:


chunkwm supports this too (by default I believe): chunkwm




回答11:


Interesting that Leopard has one flavor of focus-follows-mouse (sans autoraise) enabled by default. The scroll wheel works in unfocused windows.




回答12:


Focus follows mouse is now possible in macOS, Mojave in my case, using chunkwm. See this Stack Overflow response for a "no autoraise" solution. Autoraise is activated by leaving

chunkc set ffm_disable_autoraise         0

in ~/.chunkwmrc.

Edit 2019-09-12:

chunkwm has been superseded by yabai. To install:

brew tap koekeishiya/formulae
brew install yabai
mkdir -p ~/.config/yabai/
printf 'yabai -m config focus_follows_mouse autoraise' >> ~/.config/yabai/yabairc
brew services start yabai



回答13:


Unfortunately CodeTek Virtual Desktop Pro is no longer developed, and the company seems to have gone out of business a few years back..

Historic reference: http://www.codetek.com/ctvd/ (does not work on new OS X versions!)

Historic review: http://www.osnews.com/story/6144

Using CodeTek Virtual Desktop Pro you were able to get Focus-Follow-Mouse and disable Auto-Raise, and it also had a Pager for the virtual desktops -- similar to how Fvwm works on Linux. It really worked perfectly -- the best piece of software that I've ever bought. It worked consistently with all apps, and switching apps, moving windows to different workspaces, and navigating workspaces worked much easier than how it is implemented in the latest OS X versions [10.6, 10.7, 10.8]

Unfortunately with Mac OS X 10.5 VirtualDesktop Pro stopped working, and it looks like Apple actively made sure that CodeTek will not continue to work on it.

It is sad that Apple crushed CodeTek and it's product - Virtual Desktop Pro was really superior to how OS X workspaces are currently implemented. It worked basically like Fvwm on LINUX - super fast navigation -- without unnecessary clicks or mouse gestures...

It saddens me to see that Apple dictates window manager (Finder) behavior and does not seem to allow third-party replacements for the Finder anymore.




回答14:


There is also the related issue of raise-on-click. Under OSX each time a window is clicked, it is also raised, thus potentially hiding other windows. This is problematic when working with copy/paste from two windows where one of them covers most of the screen. I like to keep a global (active in all workspaces) notepad from which I copy/paste stuff (could be anything from commands, text, todo items etc). This is challenging under OSX. It would be nice to have an option to disable raise-on-click.




回答15:


Give DwellClick a try. Although, it's not for its intended purpose, the auto-click behavior has a side effect similar to auto-raise or focus-follows-mouse.

Personally, I only use the feature of left clicking after my cursor movement comes to rest, but there's also clicking with modifiers and a window dragging assist that's quite handy.

It's also a little frustrating while web browsing since you'll either want to disable the app or be more conscious of where the cursor rests (e.g. not on any links or buttons you don't intend to activate).




回答16:


Experimenting with those options, my Command-Tab started to behave oddly. Here is the solution of how it gives focus to apps again:

It appears that a previous feature, namely the ability for Terminal's window focus to change with mouse movement, is broken in 10.6 and causes Command-Tab to not transfer window focus correctly. To fix the problem, just paste the following command in a Terminal:

defaults write com.apple.Terminal FocusFollowsMouse -string NO

Then restart Terminal.




回答17:


Solution: Because I was so used to autoraise in Windows I badly missed it on the Mac. The solution I found for the Mac is Zooom (yes, three o's). It has an autoraise function. You can even set milliseconds to wait before autoraise. Can't live without it. Autoraise is an option in prefs as you can see in the screenshot https://www.macupdate.com/app/mac/23203/zooom http://coderage-software.com/zooom/index.html




回答18:


Use Dwell feature in mac. Go to Accessibility -> keyboard -> Accessibility keyboard (I'm on Catalina)

Click here for more info





回答19:


Tested MondoMouse (https://www.atomicbird.com/about/mac-apps) on MacOS Mojave. Seems to work fine for me!

To install the prefpane, there will be a notice "enable access for assistive devices" that does not reside in the System Preferences > Accessibility anymore. You'll have to set it in Security & Privacy > Accessibility > Privacy

There will be several warnings about allowing MondoMouse in each app you have open, but once set it works fine! What a relief :)




回答20:


You can't really do it well, because the Mac interface simply isn't designed with focus-follows-mouse (with or without auto-raise) in mind. I doubt that's going to change any time soon, and unless it does, everybody who tries to implement focus-follows-mouse will run into the same hurdles and wind up with an unsatisfactory result (to those who want such a thing).

So, yes, you are crazy for wanting this — but for technical reasons. Get used to using the Mac on its own terms and I'm sure your desire to force it to behave just like whatever X11 stuff you used to use will subside in a bit as you find new efficient ways of working.



来源:https://stackoverflow.com/questions/98310/focus-follows-mouse-plus-auto-raise-on-mac-os-x

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!