Closing window ('X') button is inactive on MacOs 11.7 (GLUT)

52 Views Asked by At

I have simple code on C++ with using GLUT:

#include <GLUT/glut.h>

void myDisplayFunc() {}
void myCloseFunc() {}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);

    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(640, 480);

    glutCreateWindow("GLUT Program");
    glutWMCloseFunc(myCloseFunc);
    glutDisplayFunc(myDisplayFunc);

    glutMainLoop();
    return 0;
}

When i build it on MacOs 10.14, all window buttons (Close, Maximize, Minimize) is active, but when i build same code on MacOs 11.7, close button ('X') is inactive (grayed). How can i fix it?

I've looked for other functions instead of glWMCloseFunc, but with no luck. This function is marked as deprecated, but so are all other functions.

1

There are 1 best solutions below

0
Elmir On BEST ANSWER

To solve the problem, I compiled a static library in Objective-C with a C interface in XCode. I added the following code to this library:

NSWindow *window = [[NSApplication sharedApplication] keyWindow];

window.styleMask |= NSWindowStyleMaskClosable;
[[window standardWindowButton:NSWindowCloseButton] setHidden:NO];
[[window standardWindowButton:NSWindowCloseButton] setEnabled:YES];

I called this function after the glutSetWindowTitle function.