2016-12-01 39 views
14

TouchSwitcher添加lightscreen和体积项旁边项目的应用: https://hazeover.com/touchswitcher.html enter image description here如何在右侧的Touch Bar控制中心获取物品?

是否有触摸栏右侧区域显示项目到控制带材中的溶液?

我在官方文档中找不到任何帮助... 请帮帮我!

+0

从NSTouchBar文件:“在触摸条的右侧时,系统供给始终可用的控制条上的控制条给予标准控制用户访问用于显示亮度,音量,Siri的。 (用户可以选择隐藏控制条,这会给最前面的应用程序提供整个触摸条的宽度)。“这意味着您的应用程序的条总是显示在控制条的左侧左边和右边的项目是不可能的。您甚至无法访问控制条栏项目。 – rocky

回答

4

反编译后,我在一个框架中发现了一些名为DFRFoundation的API,位于/ System/Library/PrivateFrameworks下,并且有一个相关的方法DFRElementSetControlStripPresenceForIdentifier。我觉得很难进一步,所以我在这里回答,只是让你知道这个API是在一个私人框架。希望有一天有人会透露秘密。

+0

谢谢。我也试图找到方法。 – jimwan

3

这是what I use。将NSView和您选择的标识符传递给controlStrippify()函数。我试图用Swift做同样的事情导致崩溃,端口欢迎:)。来自https://github.com/a2/touch-baer的灵感。

@import Cocoa; 
@import Foundation; 

// See: https://github.com/a2/touch-baer 
extern void DFRSystemModalShowsCloseBoxWhenFrontMost(BOOL); 
extern void DFRElementSetControlStripPresenceForIdentifier(NSString *string, BOOL enabled); 

@interface NSTouchBarItem() 
+ (void)addSystemTrayItem:(NSTouchBarItem *)item; 
@end 

@interface NSTouchBar() 
+ (void)presentSystemModalFunctionBar:(NSTouchBar *)touchBar systemTrayItemIdentifier:(NSString *)identifier; 
@end 

void controlStrippify(NSView *view, NSString *identifier) { 
    if (@available(macOS 10.12.2, *)) { 
    DFRSystemModalShowsCloseBoxWhenFrontMost(YES); 

    NSCustomTouchBarItem *touchBarItem = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]; 
    touchBarItem.view = view; 
    [NSTouchBarItem addSystemTrayItem:touchBarItem]; 
    DFRElementSetControlStripPresenceForIdentifier(identifier, YES); 
    } else { 
    // Fail! 
    } 
} 
+0

尽管此链接可能回答此问题,但最好在此处包含答案的基本部分,并提供供参考的链接。如果链接页面更改,则仅链接答案可能会失效。 - [来自评论](/ review/low-quality-posts/17548296) – the4kman

+0

@ the4kman,添加了代码片段。 –

+0

什么'DFRSystemModalShowsCloseBoxWhenFrontMost'呢?无论提供的布尔价值还是整条线的存在,似乎都不会产生任何效果 – ReDetection