macos Mac OS X 上的焦点跟随鼠标(加上自动提升)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/98310/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:54:42  来源:igfitidea点击:

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

macosfocusmouse

提问by dreeves

(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

焦点跟随鼠标也称为点对焦点、指针焦点和(在某些实现中)草率焦点。[添加其他术语,使其更易于搜索!] X-mouse

回答by Clint Ecker

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

您可以通过在命令行发出以下命令来为 Terminal.app 执行此操作:

defaults write com.apple.Terminal FocusFollowsMouse -bool true

For X11 apps you can do this:

对于 X11 应用程序,您可以执行以下操作:

defaults write com.apple.x11 wm_ffm -bool true

In Snow Leopard, use this instead:

在 Snow Leopard 中,改用这个:

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).

显然有一个名为 CodeTek Virtual Desktop 的程序可以在系统范围内模拟它,但它的成本是 $$(而且他们从来没有为 OSX Leopard 推出一个版本)。

回答by John Millikin

Steve Yeggewrote 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.

Steve Yegge 不久前写了一篇关于这个的文章,他试图写一个合适的扩展,但失败了。从那以后,我一直试图为 OS X 寻找焦点跟随鼠标应用程序,但也失败了。

回答by calum_b

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.

Focus-follows-mouse 不是特别适合 OS X 的输入法,因为它的菜单栏被设计在屏幕顶部。当您将鼠标移出应用程序窗口以进入菜单时,如果它在途中穿过任何其他应用程序的窗口,则菜单会更改。

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.

所以是的,作为对 dreeves 评论的回复,它对于终端(或桌面上的任何其他单个应用程序)非常有效,因为它会影响的唯一其他窗口是终端窗口,因此菜单在您切换窗口时永远不会改变。它适用于 X11,因为 X11 应用程序的菜单栏通常嵌入在窗口中,因此您无需离开窗口即可访问它们。

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.

当然,您可以通过在焦点更改和/或菜单切换之前引入人为延迟来解决菜单更改问题,但它永远不会像在其他桌面上那样工作。

回答by dvj

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

尽管这远不是一个完整的解决方案,但 OSX (10.11) 中内置的两个方便的操作是:

??-click(control-option-click) - switches focus without raising window

??-click(control-option-click) - 切换焦点而不升起窗口

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

?-click(command-click) - 在窗口中点击而不切换焦点

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

不确定何时引入这些快捷方式,因为我无法在任何地方找到它们。

回答by wprl

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

Amethyst支持此功能。它可以很容易地安装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.

这是我使用的配置文件。它会关闭除焦点跟随鼠标之外的所有功能。将其保存到~/.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
}

回答by Kyle Rose

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.

这是另一种选择:在键盘上按下某个键之前不要改变焦点。这将涵盖 95% 的焦点跟随鼠标用例,并且会让这个老脾气的 X 用户非常高兴。我不知道我会在 Chrome 中滚动浏览网页多少次,然后按 Command-T 打开一个新选项卡,然后在终端中找到打开的选项卡。如果我的大脑在使用 Mac 的 8 个月内没有注意到这一点,它永远不会。

回答by sbmpost

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 serviceworkflow. Then bind the created service to a keyboard shortcut via System Preferences|Keyboard|Shortcuts.

所以我决定再次改进我在 MouseFocus.app 上所做的工作,它仍然存在一些缺陷。这些现在都修好了。我将整个内容重命名为“AutoRaise”以更好地反映此工具的作用:当您悬停窗口时,它将被提升到前面(您选择延迟)并获得焦点。该工具可以在这里下载。要使用它,请将它复制到您的 /Applications/ 文件夹,确保它是可执行的 (chmod 700 AutoRaise)。然后在 Finder 中双击它。要快速打开/关闭它,您可以使用下面的 applescript 并将其粘贴到自动化服务工作流程中。然后通过 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'

更新 (29-03-2017):AutoRaise 二进制文件已更新。如果命令行上没有指定延迟,它现在还会在同一文件夹中查找 AutoRaise.delay 文件。这在使用下面的 applescript 时特别有用,因为“启动应用程序”不支持命令行参数。延迟应以 50ms 为单位指定。例如,要指定 150 毫秒的延迟,请在终端中运行一次此命令:'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

更新(18-04-2019):来源https://github.com/sbmpost/AutoRaise

回答by Les Grieve

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

焦点跟随鼠标现在可以在 macOS 中使用,在我的情况下为 Mojave,使用chunkwm。请参阅堆栈溢出响应以获取“无自动提升”解决方案。离开时自动加注被激活

chunkc set ffm_disable_autoraise         0

in ~/.chunkwmrc.

~/.chunkwmrc.

Edit2019-09-12:

编辑2019-09-12:

chunkwm has been superseded by yabai. To install:

chunkwm 已被yabai取代。安装:

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

回答by dreeves

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

Codetek 有一款产品可以做到这一点,但他们从未发布过 Leopard 或更高版本的版本。

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 notswitch 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).

MondoMouse 可以做焦点跟随鼠标,但不能自动提升。即使焦点跟随鼠标也坏了。例如,它不使用命令选项卡发挥出色(如果你命令选项卡到一个新的应用程序,不要触摸鼠标,那么它应该不是焦点切换回哪里鼠标指针恰好是-我很确定我见过的 Linux 中的每个实现都正确但 MondoMouse 没有)。

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:

同样对于 X11 窗口:

defaults write org.x.X11 wm_ffm -bool true 

(For mac versions previous to 10.5.5 this was:

(对于 10.5.5 之前的 mac 版本,这是:

defaults write com.apple.x11 wm_ffm true

)

)

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

我不知道支持它的任何其他应用程序。

回答by mcotton

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,即使有它的怪癖,没有它我也无法使用我的 mac。他们有免费试用,我会向所有人推荐。

MondoMouse

盟多老鼠