简体   繁体   English

在Adobe AIR HTML应用程序中强制执行全屏

[英]Enforce full screen in Adobe AIR HTML application

For my HTML Adobe AIR app I run the following at startup to show the window as fullscreen: 对于我的HTML Adob​​e AIR应用程序,我在启动时运行以下命令将窗口显示为全屏:

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. 但是,当我单击最小化时,ACTIVATE甚至会被触发,因此窗口无法最小化。

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' eg at 800x600 the set size in the XML file before minimising it... so wonder if that's where the issue lies? 我注意到,如果我评论该行,当我在全屏模式下最小化时,它首先使窗口“窗口化”,例如在XML文件中设置大小为800x600,然后将其最小化...所以想知道这是不是问题在哪? 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) 这个想法是,当应用程序处于全屏状态时,如果用户选择远离它,或者最小化窗口,它应该隐藏它以便在其他窗口后面看不到它(因为Adobe AIR使用Flash Player来实现全屏)

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. 这里的问题是,当我离开窗口后使ALT-Tab或CMD-Tab到窗口并使其可见错误时,窗口永远不会再次可见。 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? 不知道这是因为Mac OS X动画最小化了吗?

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! CSS Display None不是一个选项!

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. 好的,所以我发布这是作为Windows 7上的当前工作解决方案(没有回答只显示当前进度的问题)基于Paul Facklam在下面通过检查displayState normal而不是最小化并将其与一些附加功能混合而发布的内容使窗口填满屏幕边界并使其居中。

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. 还没有机会在Mac OS X上测试这个,但似乎OS X确实以不同的方式对待ACTIVATE和DEACTIVATE事件......基于我之前尝试过的实验。

Can confirm this issue is on Mac OS X! 可以在Mac OS X上确认此问题! And works fine on Windows. 并且可以在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? 其他人在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). 将有助于解决OS X问题(我将在今晚进行测试)。

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();
});

One possible solution to fix the OS X issue is to do the following: 解决OS X问题的一种可能解决方案是执行以下操作:

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. 因此,如果正在使用OS X,它基本上忽略了DEACTIVATE的奇怪的第一次调用......然后像正常那样处理它。 Although this feels like an awful ugly hack! 虽然这感觉像一个可怕的丑陋的黑客!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM