NSTouchBar
ボタンをプラグインを介して他の方法で変更できないアプリケーションに公開するサポートを追加しようとしています。プラグイン(共有ライブラリ)は、メインウィンドウの作成後に実行時にロードされます。 makeTouchBar
とtouchBar
機能を実装@implmentation
でメインウィンドウが作成された後にNSTouchBarサポートを追加する
@interface AppDelegate : NSResponder <NSTouchBarDelegate>
@end
:次のように私はAppDelegate
を作成しました
- (NSTouchBar *) makeTouchBar
- (nullable NSTouchBarItem *) touchBar:(NSTouchBar *)touchBar
makeItemForIdentifier: (NSTouchBarItemIdentifier)identifier
私は最終的にアプリケーションにそれを注入しようとすると、私は次のようにしていますonload
動的ライブラリがアプリケーションにロードされたときに呼び出される関数。
NSWindow *w = [NSApp mainWindow];
AppDelegate *a = [[AppDelegate alloc] init];
a.nextResponder = w.nextResponder;
w.nextResponder = a;
// Re-setting FirstResponder will trigger AppDelegate::makeTouchBar
// that was attached above.
NSResponder *n = w.firstResponder;
[w makeFirstResponder: nil];
[w makeFirstResponder: n];
しかし... AppDelegate::touchBar
は、呼び出されませんので、touchbarは私のテストボタンが移入されることはありません。
私はXcodeで新規プロジェクトを作成し、正確に同じAppDelegate
実装(同じ@interface
と@implementation
のコピー&ペースト)を使用する場合、私は両方示されており、イベントを押して応答している機能のボタンを取得し、それを注入です壊れそうな部分。 (Xcodeのすべてで、私は推測MainMenu.xib
経由でフックアップされている)
更新: 主な問題は、アプリケーションがTouchBarが動作するように防ぐ方法でコンパイルされたということでした。おそらく古いバージョンのMac OS上に構築されています。
NSApp.delegateを設定すると何も壊れませんでした。アプリケーションは以前と同じように動作します。私のAppDelegateのtouchBarはまだ呼び出されていません。私はNSApp.delegate = myappdelegate、myappdelegate.touchBar = nil、NSApp.touchBar = nil、myappdelegate.nextResponder = NSApp.nextResponder、NSApp.nextResponder = myappdelegateを設定しようとしました。問題のアプリケーションはEmacsであり、評価するときに読み込まれるネイティブelispモジュール経由でタッチバーを追加しようとしています(モジュールロード "/ path/to/module")。 – dsvensson
myappdelegate.touchBarはまだmakeTouchBarによって作成されます。 myappdelegate.touchBarをNSApp.touchBarに割り当てようとしましたが、まだタッチバーは割り当てられませんでした。 – dsvensson
この場合、Emacsにタッチバーを挿入しようとしているアプリケーションが、タッチバーのサポートを無効にするオプションでコンパイルされているのでしょうか?私はhttps://emacsformacosx.com/から最新のものを使用しています – dsvensson