How do I control X-Mouse settings (active window tracking)?


For quite some time, Windows has had a setting officially called active window tracking but which informally goes by the name X-Mouse, because that was the name of the PowerToy which first exposed the feature. (The PowerToy was in turn so-named because it made the mouse behave in a manner similar to many X window managers.) The setting is exposed to end users in Windows 7 on Make the mouse easier to use under Activate a window by hovering over it with the mouse.

If you want to write your own PowerToy to control this setting, you can do so by calling the SystemParametersInfo function. There are three settings which collectively control the X-Mouse feature:

  1. SPI_SETACTIVEWINDOWTRACKING: This is the master switch which enables the behavior.
  2. SPI_SETACTIVEWNDTRKZORDER: This controls whether the window is brought to the top when it is activated by active window tracking.
  3. SPI_SETACTIVEWNDTRKTIMEOUT: This controls how long the mouse has to be in a window before it is auto-activated.

Note that X-Mouse is a user preference. Applications should not change the setting without the user's permission.

Comments (38)
  1. Adam Rosenfield says:

    Now if only Mac OS X could get focus-follows-mouse without extreme half-broken kludges.

  2. Yuri Khan says:

    Curiously, modern X window managers do not activate windows by hovering by default.

  3. Gabe says:

    I never understood why you would want to activate a window simply by moving your mouse over it. It meant that you could never completely move your mouse out of the way of the window you were interacting with!

    Of course there are always exceptional cases, but it didn't make sense for it to be the default.

  4. Joshua Ganes says:

    Please correct me if I misunderstand the impact of this feature, but this sounds like another opportunity for overzealous programmer abuse.

    Super hacker: "This X-Mouse juju is the greatest thing ever. All my users will learn to love it. They just need me to set this on their behalf to realize what they've been missing. They'll never want to go back to the dark ages where the mouse didn't activate windows automatically."

    Isn't this just another case of trusting programmers to do the right thing? Who is to say there won't be more abuse of this trust?

    [We've been through this before. And the feature has been around for over a decade and I don't see any abuse. Maybe I'm not looking hard enough. (And the alternative would be, what? Remove the documented API for enabling this feature? Remove the feature, because people have reverse-engineered the undocumented API?) -Raymond]
  5. Matusz says:

    Modern X Windows systems I've used don't bring the window to the front or give it keyboard focus, but scrolling the mouse wheel will apply to the window the mouse is over.  I find this to be very useful.  Some applications (including Visual Studio) implement this within the bounds of their own window, but I have not found any way to get this to work across windows.

  6. Paul M. Parks says:

    @Matusz: The shiny, metallic browser does that. It's awfully convenient.

  7. Joshua Ganes says:

    Raymond, Good point. If this has been around for a decade and not heavily abused, then I guess that trust was well-placed. Allowing applications to modify global configurations allows for power and flexibility, but also allows for abuse. For things done in the past, all we can do is tidy them up the best we can. For the future, we have many great examples of critical design decisions and their impact.

    I know that in the past Microsoft has taken steps to thwart third parties from exploiting these types of interfaces. I'm curious what could be done if this feature were equally abused.

  8. DeleteFile is public too.

    Just sayin'.

  9. Skyborne says:

    I've never been able to even imagine a case where you would want a window to auto-raise when you moused over it.  I've also had a hard time understanding strict mouse focus, where leaving the window blurs it, because it leads to exactly what Gabe said: you can no longer park the mouse outside your window in that case.  (I used sloppy focus for years, which leaves focus in the window on a window->desktop transition.  But eventually I discovered that window managers had settled on "middle-click titlebar to lower", which solved the rare case I had liked mouse-focus for: having an active window not on top.)

  10. Henning Makholm says:

    Thanks a gazillion to Raymond for this tip!

    @Skymore, for me the killer feature of focus-follow-mouse is not just to be able to type into a partially obscured window, but being able to switch between it and the one that obscures it quickly and easily without upsetting the z-order.

    As for parking the mouse, on my home computer (X with hand-tweaked antique fvwm) I have set alt-tab up to plonk the mouse in the middle of the new active window's title bar. Predictable and unobtrusive. On the other hand, at work I tend to forget where I left the mouse the last time I needed it, and have to flail around with it in until I can see where on which monitor there's something that moves in synchrony. Being able to restrict the search to the focus window would be an usability win for me.

  11. 640k says:

    Though i don't like autoactivate by mouse, I would gladly pay money for a front-button as sun had on thier sparc keyboards.

    The scrollwheel activation/focus is an evil abomination for which ms intellipoint software is the root cause.

  12. Alex Grigoriev says:

    @Matusz:

    Forwarding mouse wheel events to the active window is a legacy kludge, and I wish it just went away.

  13. Kelden says:

    I would love if there would be an option to scroll the control under the cursor. Doesn't matter if

    the windows is activated or not. Even in activated windows you can scroll the wrong list if there or

    two or more.

  14. Troll says:

    This setting is also exposed to end users in Windows Vista and to XP and earlier users all the way up to 95 via TweakUI. TweakUI also has the additional GUI to configure whether or not to Autoraise windows when activating.

  15. Nawak says:

    @Kelden: use Katmouse and you will have this behavior

  16. Andrew says:

    @Keldon & @Nawak

    Katmouse is great!

  17. Kelden says:

    @Nawak & @Andrew

    I'm using AutoHotKey atm. It's great but doesn't work with all apps. I will try Katmouse.

    But I would love to see such basic functionality included in Windows.

  18. Jim says:

    Thanks, Katmouse is fantastic! Outlook 2010 would only scroll with the mouse wheel when the cursor was over the taskbar (!!!), and Katmouse fixes that.

    (Hope you don't mind me naming Outlook Raymond. To balance the above comment, even with the above bug, I still used Outlook because it's f'ing awesome.)

    Henning Makholm: if you're losing your mouse cursor, you might want to try the "show location of pointer when I press the CTRL key", in the Mouse control panel.

  19. Steve says:

    Oh, I absolutely love this feature, and also hacked together a program that can change the behavior better and without resetting my cursors. *ahem*

    Sadly, there are some programs which insist to be brought to front when activated *cough* Visual Studio *cough*

  20. James says:

    @Gabe: That's not true.  If you need to move the mouse cursor out of the way, you can move it over the desktop.  The desktop window seems to be a special exception to the usual focus-follows-mouse rules.  Also, if you need the mouse cursor out of the way but still need the window to be active, presumably you're typing into it, and you also could configure modern Windows systems to hide the mouse cursor when typing.

    Focus-follows-mouse is very useful if you want to give keyboard focus to a window without raising it.  I never understood the point of auto-raising, though.

  21. Joshua says:

    Nice! Now I know how to make a hotkey to turn it on and off. (For the uninitiated: hotkey that starts a shortcut that calls this set of APIs.)

  22. Evan says:

    @James: "If you need to move the mouse cursor out of the way, you can move it over the desktop."

    That assumes there is a clear path from the frontmost window to the desktop.

    Personally, I would never in a million years want this feature, but whatever, some do. Myself, I use a tiling WM on Linux at work, and mostly just get annoyed at the lack of virtual desktops without extra software when I'm on Windows at home.

  23. steveg says:

    Off topic: I've always wanted Shift-Clicking on a scrollbar arrow to scroll the other way. Acorn RiscOS did that. It's really handy, you can scroll up and down without having to move the mouse all the way to the top of the scroll bar.

    Pre-emptive nitpickers: laptops and some mice don't have scroll wheels.

  24. jmthomas says:

    Did the "X-Mouse" feature go through the "every request starts at -100 points" filter?

    And just how did it accumulate 100 points?  Is backward compatibility to an unsupported feature worth 99 points?  Was X-Terminal compatibility required of the original code first written so many years ago?

    [There's a story here I'll save for another day. -Raymond]
  25. Worf says:

    I find X-mouse useful a few times, but they crop up infrequently enough that I don't use it. Having the mouse scooted away without activating another window though, I use a lot. Some better programs emulate the MacOS (it started way before OS X) behavior of hiding the mouse cursor when you started typing (it reappeared once you moved the mouse).

    Useful feature, as is scrolling with X-mouse behavior. But me personally, auto-activate just confuses, like popups that happen while typing.

  26. Burak KALAYCI says:

    Joshua Ganes: If this has been around for a decade and not heavily abused, then I guess that trust was well-placed.

    I beg to disagree. All features can be abused, no exceptions. An OS either powers the user (via allowing applications use its capabilities), or, it tries to be the Nanny-OS and fails miserably at some point inevitably.

  27. Skyborne says:

    @James – it depends on the WM or its setup. E.g. fvwm offers SloppyFocus, MouseFocus, and ClickToFocus.  An early run-in of mine with X11 was on an IRIX machine with MouseFocus.  Very surprising and annoying for the uninitiated, in addition to… the rest of Unix, pretty much.

  28. Voo says:

    I would never want this feature, but mouse wheel events to the window that's under the mouse? Now that sounds extremely useful (yay finally able to scroll the documentation without changing focus) – will have to try Katmouse :D

  29. evacchi says:

    I like taekwindow http://taekwindow.net/ which gives you alt-drag too

  30. X-Mouse is wonderful, but it's becomingly increasingly frustrating to actually use because modern UI toolkits insist (for some unfathomable reason) on raising themselves to the top of the z order when they receive focus. I can hack around this breakage with a global window hook, but implementing such a fix would require more effort than I'm willing to spend right now.

    It's a shame, too, because sloopy focus is a great productivity enhancer.

  31. AK says:

    @Daniel Colascione: they raise windows to the top because in the vast majority of cases for the vast majority of users, people want to see the entire window they are working with and not have it obscured by other windows. Is that really so hard to fathom???

  32. @AK What's hard to fathom is why a window receiving focus should lead to that window forcing itself to the top of the z-order. I'm sick of the "vast majority". For me, it's obnoxious, rude, and totally unnecessary behavior, since the "vast majority" of users use click-to-focus, and the window will raise itself when clicked anyway.

  33. Not Norman Diamond says:

    @Daniel Colascione: So how would you raise a window to the top of the z-order, if giving it focus doesn't do so?

  34. Matusz says:

    @Alex Grigoriev: I'm not familiar with the implementation, can you elaborate on how it's a kludge?  I find it extremely useful (thanks @Nawak for Katmouse), so I think it might be worth putting some thought into finding either a better way to implement it, or something to obviate the need for it.

  35. Brian G. says:

    @Not Norman Diamond: Clicking on a window is an operation that gives a window focus and raises it in the z-order.  The window isn't responsible for raising itself, it is raised by the window manager.  The complaint is that some windows take responsibity for raising themselves when given focus, making it impossible to grant focus to a window via X-Mouse without raising it in the z-order (which would happen if the user clicked).

  36. Kasper H. says:

    I presume that all these functions do is to set the proper registry keys (HKCUControl PanelDesktopUserPreferencesMask and ActiveWndTrkTimeout) and then tell explorer that stuff changed. This last part is new in Win7 – earlier versions of explorer only read these values on login and thus had no way of changing the behaviour without logging out and back in.

    [You have it backwards. I continue to be astounded how many people think the registry controls settings rather than vice versa. -Raymond]
  37. Cheong says:

    @Yuri Khan: That's because in X Window, every presentation of X server is connected X client that could be on different servers. That means introducing such feature would be difficult.

    See how it takes ages for them to finially introduce a common clipboard……

  38. James says:

    Since all my windows are always maximized, I've never used this feature although I've been aware of it since TweakUI launched.

Comments are closed.