How does OS.is_window_maximized() work?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ramxa
:warning: Old Version Published before Godot 3 was released.

I’m trying to make my own scaling system for different systems of the game, so far using the signal “screen_resized” from the SceneTree I didn’t had any issues, but it seems it doesn’t work if the screen gets maximized (using the window bar button), thus everything looks out of place.

I’ve tried using “OS.is_window_maximized()” as it seemed the most logical step, but I always get a “false” return no matter what I do or try… (I’m only trying to print the value for now).

I’m on a Windows 10 machine by the way.

:bust_in_silhouette: Reply From: Hinsbart

OS.is_window_maximized() only returns true if you’ve maximized the window from godot (using OS.set_window_maximized()).
If you’re resizing using the window titlebar, it will stilll print false even when the window is actually maximized.

See the implementation details.

I see! Seeing the implementation was useful, Thank you!

Is there any way then to check if the window itself is maximized? (regardless of the editor/game options)

I could make it check for positions and scale every frame, but I feel that’s not ideal performance wise…

Ramxa | 2016-08-29 14:44

I’m afraid there’s no way to do this currently (other than checking it manually, as you said).

However, I’m pretty sure that on the c++ side, windows provides some kind of calback or notificiation for when then window gets maximized. So it shouldn’t be too hard to listen for these and set the maximized property accordingly.
Feel free to open an issue on Github about it :slight_smile:

Hinsbart | 2016-08-29 15:41

:bust_in_silhouette: Reply From: hungrypho

problem is in source code https://github.com/godotengine/godot/blob/master/platform/windows/os_windows.cpp#L1691-L1694

if you want to know if windows is maximized by titlebar icon, download source code, replace it with

bool OS_Windows::is_window_maximized() const{

    WINDOWPLACEMENT wp;
    wp.length = sizeof(wp);
    GetWindowPlacement(hWnd, &wp);

    if (wp.showCmd == SW_MAXIMIZE)
	    return true;
    else
	    return false;	
}

compile and run