3
votes

For my HTML Adobe AIR app I run the following at startup to show the window as fullscreen:

window.nativeWindow.stage.displayState = runtime.flash.display.StageDisplayState.FULL_SCREEN_INTERACTIVE;

And then for the activate state I do:

window.nativeWindow.addEventListener(air.Event.ACTIVATE, function() {

    window.nativeWindow.stage.displayState = runtime.flash.display.StageDisplayState.FULL_SCREEN_INTERACTIVE;

});

So the idea is that when the window is minimised or unfocused and then refocused, the window is made full screen and never windowed at a smaller size.

However the ACTIVATE even gets fired when I click minimise, so the window can't be minimised.

Any ideas why? Or how to fix this? I've noticed that if I comment that line out, when I minimise in full screen mode, it first makes the window 'windowed' e.g. at 800x600 the set size in the XML file before minimising it... so wonder if that's where the issue lies? That it actually makes the window activate by doing that step to go to minimised mode.

Any other suggestions for making sure the application goes into full screen when it's restored from a minimised state?


The second issue is with making the window visible and not visible when it's active or deactivated using:

window.nativeWindow.addEventListener(air.Event.ACTIVATE, function() {

    window.nativeWindow.visible = true;

});

window.nativeWindow.addEventListener(air.Event.DEACTIVATE, function() {

    window.nativeWindow.visible = false;

});

The idea being that as the application is in full screen, if the user tabs away from it, or minimises the window, it should hide it so that it can't be seen behind other windows (as Adobe AIR uses Flash Player to achieve the full screen)

The problem here, is that he window never becomes visible again when I ALT-Tab or CMD-Tab to the window after leaving the window and making its visble false. It also doesn't change the visibility states when minimising or maximising the window but DOES fire the activate and deactivate event. Wonder if this is because of the Mac OS X animation on minimise?

Any ideas on how to fix these two issues?

Is there an alternate to visible to hide or show the window? CSS Display None is not an option!

And why is the activate event being fired when I minimise the window causing the infinite loop of the fullscreen?


Okay so I'm posting this is as a current working solution on Windows 7 (not answering the question just showing current progress) based on what Paul Facklam posted below by checking for displayState normal rather than minimized and mixing it in with some addition functions to make the window fill the screen bounds and center it.

function centerWindow(instance){

    //default bounds of nativeWindow
    var applicationBounds = instance.nativeWindow.bounds;

    //determine which screen we're located on
    var screens = air.Screen.getScreensForRectangle(instance.nativeWindow.bounds);
    var screenBounds = (screens.length > 0) ? screens[0].visibleBounds : air.Screen.mainScreen.visibleBounds;

    //get initial position
    x = (screenBounds.width - applicationBounds.width) / 2;
    y = (screenBounds.height - applicationBounds.height) / 2;

    //adjust for offset x or offset y (multi monitors)
    x = screenBounds.x + x;
    y = screenBounds.y + y;
    instance.nativeWindow.x = x;
    instance.nativeWindow.y = y;
}

function resizeWindow(instance) {

    //default bounds of nativeWindow
    var applicationBounds = instance.nativeWindow.bounds;

    //determine which screen we're located on
    var screens = air.Screen.getScreensForRectangle(instance.nativeWindow.bounds);
    var screenBounds = (screens.length > 0) ? screens[0].visibleBounds : air.Screen.mainScreen.visibleBounds;

    //set the window widths and height to window (this so the aero peak doesn't show a small window)
    instance.nativeWindow.width = screenBounds.width;
    instance.nativeWindow.height = screenBounds.height;

    //then center the window
    centerWindow(instance);

}

$(document).ready(function() {

    //resize the window on load
    resizeWindow(window);

    //make window fullscreen
    window.nativeWindow.stage.displayState = runtime.flash.display.StageDisplayState.FULL_SCREEN_INTERACTIVE;               

    //make sure it's visible (if not already)
    window.nativeWindow.visible = true;

    //if window is activated and display is normal i.e. NOT fullscreen, make it fullscreen
    window.nativeWindow.addEventListener(air.Event.ACTIVATE, function() {

        if(window.nativeWindow.displayState == 'normal') {
            window.nativeWindow.stage.displayState = runtime.flash.display.StageDisplayState.FULL_SCREEN_INTERACTIVE;
        }

    });

    //if window is unfocused then minimize to the taskbar or dock
    window.nativeWindow.addEventListener(air.Event.DEACTIVATE, function() {

        window.nativeWindow.minimize(); // minimizes the window

    });

});

Not had chance to test this on Mac OS X yet, but it does seem that OS X treats the ACTIVATE and DEACTIVATE events differently... based on the previous experiments I have tried.

Can confirm this issue is on Mac OS X! And works fine on Windows. So it would seem the way the dock animates the windows causes the events to fire awkwardly causing loops etc.

Anyone else had issues with these events on Mac OS X for AIR?

Update: I wonder if using:

if(event.afterDisplayState == air.NativeWindowDisplayState.MINIMIZED)

Would help solve the OS X issue (I'll test tonight).

2

2 Answers

0
votes

Try this:

window.nativeWindow.stage.displayState = runtime.flash.display.StageDisplayState.FULL_SCREEN_INTERACTIVE;

window.nativeWindow.addEventListener(air.Event.ACTIVATE, function() {
    if(window.nativeWindow.displayState === air.NativeWindowDisplayState.MINIMIZED) {
        window.nativeWindow.stage.displayState = runtime.flash.display.StageDisplayState.FULL_SCREEN_INTERACTIVE;
    }           
});

window.nativeWindow.addEventListener(air.Event.DEACTIVATE, function() {
    window.nativeWindow.minimize();
});
0
votes

One possible solution to fix the OS X issue is to do the following:

if (air.Capabilities.os.indexOf("Mac OS") > -1) {

    var firstRun = false;

    window.nativeWindow.addEventListener(air.Event.DEACTIVATE, function() {

        if(firstRun) {

            air.trace('DEACTIVATE');

        } else {

            firstRun = true;
        }

    });

} else {

    window.nativeWindow.addEventListener(air.Event.DEACTIVATE, function() {

        air.trace('DEACTIVATE');

    });

}

So it basically ignores the weird first call of DEACTIVATE if OS X is being used... and then deals with it like normal. Although this feels like an awful ugly hack!