c++macosglut

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


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.


Solution

  • 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.