Focus stealing

From Wikipedia, the free encyclopedia
Jump to: navigation, search

In computing, focus stealing is a mode error produced when a program not in focus (e.g. minimized or operating in background) places a window in the foreground and redirects all keyboard input to that window. This is considered to be an annoyance or hazard to some users because the program may steal the focus while their attention is not on the computer screen, such as when typing while reading copy to the side. This will cause everything typed after the window appeared to be lost - or worse, the typed input may cause an unintended effect in the newly focused window. On slow computers, users are sometimes not even alerted to this behavior in time, because the associated window is only actually displayed several seconds after the actual focus change happened.

Security issues[edit]

Focus stealing can cause damage as users may, while typing when their attention is away from the screen, inadvertently agree to a program doing something that causes damage. For example; when Microsoft Windows pops up the Disk Cleanup wizard, the user may "agree" to deleting files without realizing that the wizard was waiting for input. Focus stealing can also occasion security breaches, for example, when a user enters a password and the typed password appears instead in a new instant-messaging window in an unmasked input field.

Alternatives to focus stealing[edit]

These are alternative methods for grabbing the attention of the user that could be used instead of focus stealing:[1]

  1. Pulse the application's icon in the task bar, leaving the application in the background
  2. Output a message to the notification area
  3. Pulsate the display over scan area
  4. Use an audible alerting framework

Testing whether a window manager allows focus stealing[edit]

The launch test[edit]

Open a command-line terminal window. From within the window, run a GUI application, such as xcalc (X11) or calc (Microsoft Windows). The terminal window should remain in focus and continue to receive key presses; press a number key to test this. If the GUI application has gained focus so that key presses are now being directed to the GUI application, then the window manager allows focus stealing.

The JavaScript test[edit]

On a window manager that allows focus stealing, by pointing the browser at an Internet page that contains a this.focus() JavaScript facility, the browser window will regain focus:

<script type="text/javascript">
function test()
{
this.focus();
setTimeout('test()',50);
};
test();
</script>

Affected systems[edit]

X Window Managers[edit]

The following window manager systems allow focus stealing:

  • 9wm - fails the launch test, giving focus to window placement facility
  • compiz - configurable, and capable of passing both the launch test and the Javascript test
  • fvwm - configurable, and capable of passing or failing both the launch test and the Javascript test
  • IceWM - fails the launch test, giving focus to newly started applications
  • oroboros - fails the launch test, giving focus to newly started applications

Microsoft Windows[edit]

Microsoft Windows-based systems use pop-up dialogue boxes, which can steal focus from the current application. On pre-7 versions of Microsoft Windows, there is a system-wide setting that will by default prevent a cooperative application from stealing focus when launching another program or popping up a new window or dialogue box.[2] This does not work in Windows 7 anymore.[3] It is not possible to prevent an uncooperative or malicious application from either changing the setting, or bypassing it.[4]

Web Browsers[edit]

The following web browsers allow focus stealing via a this.focus() Javascript facility:

Detect Focus Stealing Program[edit]

This problem is sufficiently irritating to users that programs have been written to identify what is stealing focus.

See also[edit]

References[edit]

  1. ^ Documentation released by Mark Hobley via the computer accessibility wiki
  2. ^ Microsoft TechNet: ForegroundLockTimeout
  3. ^ [1]
  4. ^ John Barnett's Windows XP Help and Support: How Do I Prevent Applications from Stealing Focus
  5. ^ Mozilla Focus Stealing bugs

External links[edit]