Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Linux] NativeWindow::restore() doesn't work after NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGE event #2497

Open
itlancer opened this issue Feb 28, 2023 · 0 comments
Labels

Comments

@itlancer
Copy link

Problem Description

NativeWindow::restore() doesn't work after NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGE event for Linux.
It happens if I want to wait when NativeWindow::maximize() to be applied and then change window state again.

Tested with multiple AIR versions, even with latest AIR 50.2.1.1 with multiple different Linux Ubuntu 22.04.1 LTS devices with different applications.
Same problem in all cases.
There is no such issue with Windows/macOS devices.

Related issues (not the same):
#2495
#2493
#2492
#2486

Steps to Reproduce

Launch application with code below with Linux Ubuntu 22.04.1 LTS device.
Application window should be maximized and then restored to normal after launch.

Application example with sources attached.
linux_nativewindow_restore_normal_event_bug.zip

package {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.NativeWindowDisplayStateEvent;
	import flash.display.NativeWindowDisplayState;
	
	public class LinuxNativeWindowRestoreNormalEventBug extends Sprite {
		
		public function LinuxNativeWindowRestoreNormalEventBug() {
			addEventListener(Event.ADDED_TO_STAGE, addedToStage);
		}
		
		private function addedToStage(e:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
			
			stage.nativeWindow.addEventListener(NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGE, windowDisplayStateChangeForMaximize);
			stage.nativeWindow.maximize();
		}
		
		private function windowDisplayStateChangeForMaximize(e:NativeWindowDisplayStateEvent):void {
			trace("windowDisplayStateChangeForMaximize", e.beforeDisplayState, e.afterDisplayState);
			if (e.afterDisplayState == NativeWindowDisplayState.MAXIMIZED){//Window maximized
				e.target.removeEventListener(NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGE, windowDisplayStateChangeForMaximize);
				
				stage.nativeWindow.addEventListener(NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGE, windowDisplayStateChangeForNormal);
				stage.nativeWindow.restore();//This line doesn't restore window
			}
		}
		
		private function windowDisplayStateChangeForNormal(e:NativeWindowDisplayStateEvent):void {
			trace("windowDisplayStateChangeForNormal", e.beforeDisplayState, e.afterDisplayState);
		}
	}
}

Actual Result:
Application window maximized (not restored).
In traces you will see:

windowDisplayStateChangeForMaximize normal maximized
windowDisplayStateChangeForNormal maximized normal
windowDisplayStateChangeForNormal normal maximized

Seems like window maximized again immediately.

Expected Result:
Application window restored to normal state.
In traces you will see:

windowDisplayStateChangeForMaximize normal maximized
windowDisplayStateChangeForNormal maximized normal

Known Workarounds

Handle such behaviour by application logic somehow. May be dispatch extra event by your own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant