简体   繁体   English

如何让我的应用程序的触摸栏始终在macOS上可见?

[英]How can I make my application's touch bar always visible on macOS?

I am making a macOS menu bar application which displays a fullscreen overlay. 我正在制作一个显示全屏叠加的macOS菜单栏应用程序 The user is able to control the opacity of this overlay via a slider in the menu bar. 用户可以通过菜单栏中的滑块控制此叠加层的不透明度。 I wish to move these controls to the touch bar, because the application is used for screen recordings, and distractions on the main screen would be recorded. 我希望将这些控件移动到触摸栏,因为应用程序用于屏幕录制,并且将记录主屏幕上的干扰。 The slider in my application should act just like the brightness and volume sliders that are on the touch bar by default. 我的应用程序中的滑块应该像默认情况下触摸条上的亮度和音量滑块一样。

I have added my NSTouchBar by subclassing NSApplication and implementing makeTouchBar . 我通过NSTouchBar NSApplication并实现makeTouchBar添加了我的makeTouchBar The bar appears when the application is first launched. 首次启动应用程序时会出现该栏。 However, the touch bar disappears when focussing any other application, and there seems to be no way to bring my application's touch bar again. 但是,当聚焦任何其他应用程序时,触摸条会消失,似乎无法再次启动应用程序的触摸条。 The problem, I think, is that my application is a pure menu bar application with no windows. 我认为问题是我的应用程序是一个没有窗口的纯菜单栏应用程序。

Here are the ways I could make my application's touch bar visible, from most preferable to least preferable: 以下是我可以使应用程序的触摸条可见的方法,从最优选到最不可取:

  1. Add an icon for my application to the control strip, next to the brightness and volume icons. 将我的应用程序的图标添加到控制条,亮度和音量图标旁边。 This would let the user hit my icon to adjust the opacity, even when other applications are focussed. 即使其他应用程序被聚焦,这也会让用户点击我的图标来调整不透明度。 However, strangely, I am told that there is no public API to manipulate the control strip . 然而,奇怪的是, 我被告知没有公共API来操纵控制条

  2. Somehow give my user a way to manually add my application to the control strip. 不知何故,我的用户可以手动将我的应用程序添加到控制条。 The control strip can be customized via System Preferences > Keyboard > Customize Control Strip ... , which shows a variety of things to drag-and-drop into the control strip. 控制条可以通过System Preferences > Keyboard > Customize Control Strip ... ,它可以显示拖放到控制条中的各种内容。 I would like to register my application as an item to include here. 我想将我的申请注册为包含在这里的项目。 However, I cannot find any way to do this. 但是,我找不到任何方法来做到这一点。

  3. Register my application as a music application. 将我的应用程序注册为音乐应用程序 Spotify on my machine somehow uses the "music" icon in the Control Strip (the same icon that iTunes uses). 我的机器上的Spotify以某种方式使用控制条中的“音乐”图标(与iTunes使用的图标相同)。 I don't know how Spotify does this - does anyone else know? 我不知道Spotify如何做到这一点 - 其他人都知道吗? Obviously, this would be a hack, as my application is not playing audio, but it's better than nothing. 显然,这将是一个黑客,因为我的应用程序不播放音频,但它总比没有好。

  4. Somehow override the App Region so that my application's touch bar is always visible, clobbering all other applications' use of the touch bar. 以某种方式覆盖应用程序区域,以便我的应用程序的触摸栏始终可见,破坏所有其他应用程序对触摸条的使用。 This is obviously not ideal, since it doesn't play well with other applications. 这显然不是理想的,因为它不能很好地与其他应用程序一起使用。

Are any of these solutions possible? 这些解决方案是否可行? Are there other possible solutions? 有其他可能的解决方案吗? How do I make my application's touch bar always accessible via the touch bar? 如何通过触摸栏始终访问应用程序的触摸栏?

Maybe there's some hacky solution, but according to official documentation you can't do it: https://developer.apple.com/reference/appkit/nstouchbar 也许有一些hacky解决方案,但根据官方文档,你不能这样做: https//developer.apple.com/reference/appkit/nstouchbar

On supported MacBook Pro models, the Touch Bar, above the keyboard, shows instances of the NSTouch​Bar class from the front-most app. 在支持的MacBook Pro型号上,键盘上方的触控栏显示最前端应用程序中的NSTouch Bar类的实例。

If you could get your application into Control Strip area (where the volume-control and friends reside), then user can touch it there to bring up your touchbar. 如果您可以将您的应用程序放入Control Strip区域(音量控制和朋友驻留),那么用户可以在那里触摸它以显示您的触摸栏。 See hazeover's TouchSwitcher to get the idea. 请参阅hazeover的TouchSwitcher以了解相关信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM