Christian
Christian

Reputation: 3393

Firefox extension: check if window is minimized

I'm trying to keep track of the state of a Firefox window ("maximized", "minimized", "normal", "fullscreen"; see here). However, whatever I've tried, I never get to see the minimized event; the others doing fine. For example, if I add listeners to the window such as

window.addEventListener("activate", function(event) { dump("activate " + window.windowState + " " + window.screenX + " " + window.screenY + "\n"); }, false);
window.addEventListener("deactivate", function(event) { dump("deactivate " + window.windowState + " " + window.screenX + " " + window.screenY + "\n"); }, false);
window.addEventListener("resize", function(event) { dump("resize " + window.windowState + " " + window.screenX + " " + window.screenY + "\n"); }, false);

I never see 2 as the window.windowState (2 = STATE_MINIMIZED). I've tried a workaround using screenX and screenY, but that doesn't help. When I minimize the window the deactivate - not the resize - event fires with window.windowState being 3 (STATE_NORMAL) and the old screenX/screenY values.

Is there any way to detect when the Firefox window is being minimized? I'm at my wits' end.

Upvotes: 4

Views: 2004

Answers (1)

Wladimir Palant
Wladimir Palant

Reputation: 57651

You should be listening to the sizemodechange event. That's the event firing after the window is minimized or maximized. The resize event doesn't fire for window minimization because technically the window isn't resized - it is hidden. And the deactivate event likely fires before the window is minimized, when it still has the normal state (I didn't check however).

Upvotes: 4

Related Questions