4

Within my Firefox extension I'm trying to keep track when the window is actually the active window. For this, I add the following two listener to the window:

  window.addEventListener("deactivate", function(event) { alert("deactivate"); }, false);
  window.addEventListener("activate", function(event) { alert("activate");  }, false);

Basically everything works fine. When I toggle between different windows, or minimize/maximize Firefox, the events fire quite as I would expect it. However, both events also fired when I move the window even if it is already active. When I start moving the window, the "deactivate" event is fired; when I stop moving and release the mouse button, the "activate" event is fired. I have no idea how can I detect and ignore this behavior. Intuitively, the window is all the time active.

I tried to check before I handle the "deactivate" event if the mouse button is pressed. However, adding a "click" event listener to the window seem not to include the window's title bar. Anyone any idea how I can distinguish beween "really" de-/activating the window and moving the window? Thanks a lot in advance!

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
Christian
  • 3,239
  • 5
  • 38
  • 79
  • Can you listen for the focus/blur window events instead? Not sure if you can do this for extensions, but in javascript the window focus event is thrown when a window is brought to the foreground (ie: activated) and the blur is thrown when another window is selected. Just an idea... – ndtreviv Feb 24 '12 at 16:59
  • Thanks for your comment! I've already tried focus/blur. It seems to have the same effect, i.e. moving a focused window fires focus/blur event pair. – Christian Feb 25 '12 at 07:54

1 Answers1

0

You can use this answer to detect the browser position on the screen. If you do this at the start you can compare if they are changing.

Something like when the page loads:

var x,
    y,
    win = window;

if(win.screenTop !== undefined) {
    x = win.screenleft;
    y = win.screenTop;
} else {
    x = win.screenX;
    y = win.screenY
}

and compare those values to the current values when your events triggers.

(Note that this only works when the position of the window changes)

Community
  • 1
  • 1
askmike
  • 1,900
  • 4
  • 21
  • 27