Activate / deactivate events when moving a window

In my Firefox extension, I am trying to track when a window is actually an active window. To do this, I add the following two listeners to the window:

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

In principle, everything is working fine. When I switch between different windows or minimize / maximize Firefox, events fire as I expected. However, both events also fire when I move the window, even if it is already active. When I start moving the window, the “deactivate” event occurs; when I stop moving and release the mouse button, the activate event is activated. I have no idea how I can detect and ignore this behavior. Intuitively the window is actively working.

I tried to check before handling the “deactivate” event if the mouse button is clicked. However, adding a click event to the window does not include the window title bar. Any idea how I can tell if "really" deactivate the window and move the window? Thank you very much in advance!

+4
source share
1 answer

You can use this answer to determine the position of the browser on the screen. If you do this at the beginning, you can compare if they change.

Something like when loading a page:

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

and compare these values ​​with the current values ​​when events are triggered.

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

0
source

Source: https://habr.com/ru/post/1391108/


All Articles