0

I'm using SDL to create a window for use with OpenGL and the only information it gives back is the NSWindow object.

Can I use that to then subsequently associate an NSTouchBar with that window?

I've successfully done it by directly modifying the SDL code to do it in the ViewController, but as a user of the library API, that option isn't available to me.

I was previously thinking I could do so with a customer NSResponder, but am no longer convinced this is a valid option.

Thank you.

xaxxon
  • 19,189
  • 5
  • 50
  • 80

1 Answers1

1

Creating an NSWindowController and attaching it to the existing window works.

@interface WindowController : NSWindowController <NSTouchBarDelegate>

and

- (id)init:(NSWindow *) nswindow
{
    self = [super initWithWindow:nswindow];
    return self;
}

- (NSTouchBar *)makeTouchBar
{
        NSTouchBar *bar = [[NSTouchBar alloc] init];
        bar.delegate = self;
        bar.customizationIdentifier = PopoverCustomizationIdentifier;
        bar.defaultItemIdentifiers = @[PopoverItemIdentifier, NSTouchBarItemIdentifierOtherItemsProxy];
        bar.customizationAllowedItemIdentifiers = @[PopoverItemIdentifier];
        bar.principalItemIdentifier = PopoverItemIdentifier;
        return bar;
}

You can see https://developer.apple.com/library/content/samplecode/NSTouchBarCatalog/Listings/Objective_C_NSTouchBar_Catalog_TestViewControllers_PopoverViewController_m.html for a bunch more of the guts to put in these functions.

xaxxon
  • 19,189
  • 5
  • 50
  • 80
  • My problem seems very similar to this, but simply creating my a WindowController with [NSApp mainWindow] as argument does not give me any touchbar. See https://stackoverflow.com/questions/41383194/adding-nstouchbar-support-after-main-window-has-been-created – dsvensson Dec 29 '16 at 16:11