'Is there a way to resize a Libgdx window based on the monitor's maximum bound?

What I mean is there a way to set the window size to related to the result given by this method: GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds() ? This gives back a different result compared to Gdx.graphics.getWidth() and Gdx.graphics.getHeight(): these return the screen size, but what I'd like to have is the screen area - menu bars area (for example the Dock on a Mac). I'd also like to keep the ratio of the window while doing so.

I tried to use the Java.awt method GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(), but it couldn't run. I was looking on google and people say that using Java.awt methods with Libgdx causes problems, so I presume that's why.

Main code Debug view



Solution 1:[1]

If you mean you want the window to be maximised on start then you can set that directly in the Lwjgl3ApplicationConfiguration config with

config.setMaximised(true);

You can maximise after the start with (which is going below the abstraction libGDX provides).

GLFW.glfwMaximizeWindow(window.getWindowHandle);

https://www.glfw.org/docs/3.3/window_guide.html#window_sizelimits

You can capture the window with a listener on config.

config.setWindowListener(new Lwjgl3WindowAdapter() {

@Override
public void created(final Lwjgl3Window window) {

If you need in the program to know what the available dimensions is without menu bars etc (which is the equivalent of AWT GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds() then

GLFW.glfwGetMonitorWorkarea?(long monitor, int[] xpos, int[] ypos, int[] width, int[] height);

using GLFW.glfwGetPrimaryMonitor()

and then you can build a custom window maximiser with

GLFW.glfwSetWindowPos?(long window, int xpos, int ypos);
GLFW.glfwSetWindowSize?(long window, int width, int height);

https://javadoc.lwjgl.org/org/lwjgl/glfw/GLFW.html

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 londonBadger