From a65613acafe3c7f1917fb00577f80609b61332aa Mon Sep 17 00:00:00 2001 From: Giuseppe Petrosino Date: Wed, 17 Jun 2020 23:40:58 +0200 Subject: [PATCH] Allow change of of a group button width (#336) --- MTMR/TouchBarController.swift | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/MTMR/TouchBarController.swift b/MTMR/TouchBarController.swift index 9bf1a78..e0af17e 100644 --- a/MTMR/TouchBarController.swift +++ b/MTMR/TouchBarController.swift @@ -100,7 +100,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate { } blacklistAppIdentifiers = AppSettings.blacklistedAppIds - + NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(activeApplicationChanged), name: NSWorkspace.didLaunchApplicationNotification, object: nil) NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(activeApplicationChanged), name: NSWorkspace.didTerminateApplicationNotification, object: nil) NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(activeApplicationChanged), name: NSWorkspace.didActivateApplicationNotification, object: nil) @@ -123,20 +123,20 @@ class TouchBarController: NSObject, NSTouchBarDelegate { let centerItems = centerIdentifiers.compactMap({ (identifier) -> NSTouchBarItem? in items[identifier] }) - + let centerScrollArea = NSTouchBarItem.Identifier("com.toxblh.mtmr.scrollArea.".appending(UUID().uuidString)) let scrollArea = ScrollViewItem(identifier: centerScrollArea, items: centerItems) touchBar.delegate = self touchBar.defaultItemIdentifiers = [basicViewIdentifier] - + let leftItems = leftIdentifiers.compactMap({ (identifier) -> NSTouchBarItem? in items[identifier] }) let rightItems = rightIdentifiers.compactMap({ (identifier) -> NSTouchBarItem? in items[identifier] }) - + basicView = BasicView(identifier: basicViewIdentifier, items:leftItems + [scrollArea] + rightItems, swipeItems: swipeItems) basicView?.legacyGesturesEnabled = AppSettings.multitouchGestures @@ -428,6 +428,12 @@ extension NSCustomTouchBarItem: CanSetWidth { } } +extension NSPopoverTouchBarItem: CanSetWidth { + func setWidth(value: CGFloat) { + view?.widthAnchor.constraint(equalToConstant: value).isActive = true + } +} + extension BarItemDefinition { var align: Align { if case let .align(result)? = additionalParameters[.align] {