I know that you can track the window resize operation using:
glfwSetWindowSizeCallback(window, wsCallback = new GLFWWindowSizeCallback() {
@Override
public void invoke(long window, int w, int h) {
LOG.info("window resized");
if (w > 0 && h > 0) {
width = w;
height = h;
}
}
});
However, this way the invoke method gets invoked potentially Hundreds of times, and I only want the final event to store the new size in the configuration. How do I do this without using some sort of delay mechanism like a one second timer that gets refreshed on further invoke calls?
The way GLFW callbacks are set up is so they are refreshed upon each call of glfwPollEvents()
. If you only want to set the configuration variables on the final update, this in and of itself is not feasible. I would have a void dispose()
method in which you can call this:
public void dispose() {
try (MemoryStack stack = stackPush()) {
IntBuffer width = stack.ints(1);
IntBuffer height = stack.ints(1);
glfwGetWindowSize(windowID, width, height);
configuration.width = width.get();
configuration.height = height.get();
}
}
This allows for you to set the configuration data once when you want to close the window. The draw back to this technique is if the application crashes or the dispose()
method isn't called, the configuration data isn't saved.