151

Is there a way to set up "focus follows mouse" behavior in Unity?

2
  • You probably want to remove the appmenu-* packages if you enable focus follows mouse mode. Otherwise menus become very anoying to use.
    – user52885
    Mar 31, 2012 at 19:31
  • 1
    @brandon In Precise 12.04, the availablity of the Head-Up Display (HUD) mitigates the Unified Menu Bar (UMB) problems, as does the older Alt-F10 option for getting to the menu. For those that love the keyboard, focus follows mouse can still be great. See also the suggestions and discussion at Bug #674138 ""Global” appmenu breaks sloppy focus” : Bugs : unity
    – nealmcb
    Apr 30, 2012 at 20:55

4 Answers 4

162

13.04 and later (GUI) (also works on Ubuntu Unity 22.10)

Follow-on-focus settings can be set using the unity-tweak-tool Install unity-tweak-tool

enter image description here

enter image description here

12.10 and later (command line)

The following controls follow-on focus

gsettings set org.gnome.desktop.wm.preferences focus-mode 'sloppy'

or

gsettings set org.gnome.desktop.wm.preferences focus-mode 'mouse'

Use the value 'click' to reset to the standard focus-control.

Note: the difference between 'sloppy' and 'mouse' is described at the bottom of this answer.

In addition you have the following option which when set, automatically raises the window to have focus:

gsettings set org.gnome.desktop.wm.preferences auto-raise true

You can control the delay for this auto-raise capability (in milliseconds):

gsettings set org.gnome.desktop.wm.preferences auto-raise-delay 500

You can change raise-on-click to control what window is on top:

gsettings set org.gnome.desktop.wm.preferences raise-on-click false

12.04

Two methods for 12.04 are presented below:

method 1

enter image description here

Use gconf-editor and change the focus-mode value shown to mouse or sloppy

(see note below)

If do not have gconf-editor already installed then you can install via the terminal command:

sudo apt-get install gconf-editor

In addition you have the following key which when set, automatically raises the window to have focus - auto-raise.

You can control the delay for this auto-raise capability (in milliseconds) by changing the key value auto-raise-delay

method 2

use gnome-tweak-tool

enter image description here

change windows focus mode to mouse or sloppy

(see note below)

"mouse" vs "sloppy"

A focus mode "sloppy" seems to work better at allowing Alt+TAB to override focus.

"mouse" means that if the mouse isn't in the window, the window isn't selected, no matter what you've selected in any other way.

The window focus mode indicates how windows are activated. It has three possible values; "click" means windows must be clicked in order to focus them, "sloppy" means windows are focused when the mouse enters the window, and "mouse" means windows are focused when the mouse enters the window and unfocused when the mouse leaves the window.

Controlling What Window is on Top

The following window options control what window is in the front of others (or "on top"). It's slightly different than what window has the input focus. The following descriptions help explain slightly.

raise-on-click

Some users who use focus-follows-mouse do not like the windows the interact with to come to the top unless they explicity click on the tilebar of the window. This gives a finer grain of control when working with multiple windows, but can be frustrating for most users.

auto-raise

Some users who use focus-follows-mouse, like to have the window their cursor is over automatically raise to the top. This makes the window in full view, with no other windows eclipsing it.

auto-raise-delay

The length of time to wait before triggering the auto-raise behavior.

6
  • 1
    Interestingly, on my 12.10 install, gsettings ... 'sloppy' has the same effect as 'mouse' and thus effectively breaks <alt><tab> selection.
    – cfi
    Jan 27, 2013 at 12:27
  • 6
    I wish I could upvote this answer for every time I need to look it up. Thanks.
    – sarnold
    Feb 3, 2013 at 6:21
  • Since basic WM functions are not accessible in the default install, one has to wonder why this tweak tool isn't installed by default, replacing the meager default system settings software entirely.
    – Christian
    May 11, 2014 at 17:43
  • Note: Command line doesn't work with sudo
    – myol
    Apr 30, 2015 at 10:52
  • 1
    I have sloppy focus enabled. This works fine as long as I stay on one workspace. However when I move to another workspace, the window under the pointer gets focus. This is bad, because the pointer position has nothing to do with the windows on the new workspace. Can focus be constrained to enter / leave / click events? Jul 22, 2015 at 20:39
29

This can be done through CompizConfig Settings Manager. I've tested it on 11.10, 12.04, and 12.10, and Elder Geek successfully tested it on 14.04. and 16.04

CompizConfig

Select the "Focus & Raise Behavior Tab", then uncheck "Click To Focus." Make sure "Auto-Raise" is checked.

More CompizConfig

If you don't have CompizConfig Settings Manager (also known as 'CCSM') installed, you can do so from the Software Center, or from the command line:

sudo apt-get install compizconfig-settings-manager

You can then launch it with as ccsm from the command line, or from the launcher with "compiz" or "ccsm",

Here are some general caveats for running ccsm: what are some of the issues with ccsm?

4
  • 2
    The answer is in itself correct. Maybe one should explictly mention that using this without auto-raise effectively breaks <alt>-<tab> switching: No matter what gets selected, the window under the mouse cursor becomes active.
    – cfi
    Jan 27, 2013 at 12:25
  • 1
    @cfi I think this depends on the auto-raise interval -- I run in this fashion myself. The default isn't zero, as far as I know. What are the settings that would effectively break alt-tab?
    – belacqua
    Jan 28, 2013 at 15:26
  • Are you saying that even with auto raising disabled, the value of the auto-raise interval does matter??
    – cfi
    Jan 28, 2013 at 15:56
  • @cfi -- ha - no, right, that wouldn't make sense (and I hope that's not what I've set to). I'll check my various installations and see if I can clarify and address your point.
    – belacqua
    Jan 30, 2013 at 18:22
24

While you can use the gconf-editor or gnome-tweak-tool to do this, they are not installed by default. I also found (on the intarwebs from http://blog.bodhizazen.com/linux/gnome-3-focus-follows-mouse):

gconftool-2 --type string --set /apps/metacity/general/focus_mode mouse
gconftool-2 --type boolean --set /apps/metacity/general/auto_raise true
gconftool-2 --type integer --set /apps/metacity/general/auto_raise_delay 600

Personally, I don't like the auto_raise feature, so I set the second option to "false" and didn't set the auto_raise_delay option.

Note, however, that this ultimately "breaks" the Unified Menu Bar (UMB) (when you mouse off the item you're using and onto another one, the Unified Menu Bar is now reflective of whatever you're now hovering over).

Two Workarounds:

  • Move the window to the top of the screen before accessing UMB
  • Press F10, which will keep UMB open on focused window for you to interact with

Tested as recently as Precise

more edits: I've put "breaks" in quotes - yes, it's not really broken, but it breaks IMO the intent of the UMB, or at least makes it challenging to use as Reese correctly points out in the comment. IMO, that's a "breaks simple usability, but with an annoying workaround." Though given Linux's focus on providing very strong multitasking (which tends to lead to a "cluttered" desktop), it seems that either the UMB diminishes multitasking, or multitasking diminishes the UMB's capabilities. I'll leave that as an exercise to the reader to decide...

4
  • There should be a delay after which the focus would change, defaulting to e.g. 200ms - this would allow to quickly move across other windows to reach the UMB for example.
    – blueyed
    Apr 15, 2012 at 16:09
  • if you prefer to not have a window raised when you interact with it, useful for things like keeping a log tail in a terminal on top while you interact with a browser, the setting you want is: gconftool-2 --type boolean --set /apps/metacity/general/raise_on_click false. Use this in combination with auto_raise false. With this setting windows can still be raised by clicking on the title bar.
    – pgraham
    Sep 3, 2014 at 19:14
  • Where do you get gconftool-2 from?
    – matanox
    Jan 13, 2015 at 16:06
  • On Gnome 2.16.0 you have to restart gnome-session for the gconftool-2 settings to have effect. Nov 26, 2016 at 9:41
2

Another way to enable focus-follows-mouse worked for me in a recent 12.10 install. There is currently a bug in 12.10 (and a special shout-out to nealmcb for the link) that causes changes made with ccsm or gsettings to revert on logout or reboot. I tried a couple different ways of tricking the bug, but eventually had success with this post about using Unsettings.

In case that page migrates away, the process boils down to:

sudo add-apt-repository ppa:diesch/testing
sudo apt-get update
sudo apt-get install unsettings

Start up unsettings, go to the Windows tab, and turn off Click to Focus. I rebooted to get it to "take", but probably only needed to log out and back in again.

For future reference, it sounds like this bugfix will be available shortly, so the normal methods of CCSM or gsettings should go back to working correctly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .