Add buttons to Mac window Title Bars, system-wide

后端 未结 4 1939
难免孤独
难免孤独 2021-02-05 12:44

I want to be able to add a button to the title bar of all windows that open on a Mac.

The button will go on the right hand side, opposite the X -

4条回答
  •  南旧
    南旧 (楼主)
    2021-02-05 12:46

    This is really a two-part question. As for how to get a button up there, I’d suggest using -[NSWindow standardWindowButton:] to get an existing window button and its superview (i. e. the title bar):

    NSButton *closeButton = [window standardWindowButton:NSWindowCloseButton]; // Get the existing close button of the window. Check documentation for the other window buttons.
    NSView *titleBarView = closeButton.superview; // Get the view that encloses that standard window buttons.
    NSButton *myButton = …; // Create custom button to be added to the title bar.
    myButton.frame = …; // Set the appropriate frame for your button. Use titleBarView.bounds to determine the bounding rect of the view that encloses the standard window buttons.
    [titleBarView addSubview:myButton]; // Add the custom button to the title bar.
    

    The plugging-in is probably easiest to do as a SIMBL plug-in.

提交回复
热议问题