For my application, I want to maintain a square viewport when the window gets resized. I have defined a windowSizeCallback function to redefine the viewport each time the window is resized; see attached example. This works fine when the window is resized when I drag the corner, but it doesn’t work when the window is maximized, even though the callback function does get called when the window is maximized. What am I doing wrong? Or is this a bug in GLFW? I think it might be GLFW, because a similar GLUT program does work as expected. Thanks in advance for any reply!
GLFW version: 3.3.8 Cocoa NSGL EGL OSMesa dynamic
MacOS 10.14.6
GLFW Python bindings version 2.5.5
Python 3.10
import glfw
from OpenGL.GL import *
# Make sure we always have a square viewport
def window_size_callback(window, x, y):
    if x > y:
        glViewport(0, 0, y, y)
    else:
        glViewport(0, y - x, x, x)
print(f"GLFW version: {glfw.get_version_string().decode()}")
# Initialize the GLFW library
if not glfw.init():
    exit()
# Create a windowed mode window and its OpenGL context
window = glfw.create_window(200, 200, "Test Viewport", None, None)
if not window:
    glfw.terminate()
    exit()
# Make the window's context current
glfw.make_context_current(window)
# Set the callback function for resizing the window
glfw.set_window_size_callback(window, window_size_callback)
while not glfw.window_should_close(window):
    glClear(GL_COLOR_BUFFER_BIT)
    glBegin(GL_LINES)
    glVertex(-1, -1)
    glVertex(1, 1)
    glVertex(-1, 1)
    glVertex(1, -1)
    glEnd()
    # Swap front and back buffers
    glfw.swap_buffers(window)
    # Wait for events
    glfw.wait_events()
glfw.terminate()