AppKitFocusOverlay

main

Add hotkey(s) to display the key focus path for any window in your AppKit application.
dagronf/AppKitFocusOverlay

AppKitFocusOverlay

A simple package for displaying the current focus (nextKeyView) target path for an AppKit window.

  • Press and hold option-[ key to display the focus key path for the currently focussed window
  • Press and hold option-] key to display the focus key path from the currently focussed UI element.

Supports both Swift and Objective-C projects.

Why?

It's important for your app to be keyboard navigable and that the tab path makes sense to a user. There's been a bit of discussion of recent regarding keyboard navigation on iOS, highlighting the -UIFocusLoopDebuggerEnabled YES launch argument option for iOS apps in Xcode.. The question was posed as to whether this also worked for AppKit, and the short answer was no.

I built the prototype for this a few years back for use in my own apps. It's not as frictionless as adding a launch argument but it's straight forward enough to add. Given how useful it's been for me I thought I'd package it up cleanly and make it public.

Demo

Click here to see a demo video of the focus overlay added to the wonderful 'ControlRoom' application.

There are also very basic AppKit example applications (using both Swift and Objective-C) in the Demo subfolder you can play with.

Simple setup

  • Add the https://github.com/dagronf/AppKitFocusOverlay package to your application.

  • Define a global instance of AppKitFocusOverlay in your app and access the instance within a method that gets called early in your app's lifecycle, such as applicationDidFinishLaunching.

import AppKitFocusOverlay
let _globalFocusOverlay = AppKitFocusOverlay()

func applicationDidFinishLaunching(_ aNotification: Notification) {
   // Force the focus overlay instance to init.
   _ = _globalFocusOverlay
   ...
}

Features

Custom hotkeys

You can define the hotkeys to use in the initializer of the instance. By default, these are option-[ and option-], but you can change them to f13 and f14 (for example) if you want.

import AppKitFocusOverlay
import HotKey               // Available due to AppKitFocusOverlay dependency 

let _globalFocusOverlay: AppKitFocusOverlay(
   windowHotKey: HotKey(key: .f13, modifiers: []),
   viewHotKey: HotKey(key: .f14, modifiers: [])
)

func applicationDidFinishLaunching(_ aNotification: Notification) {
   // Force the focus overlay instance to init.
   _ = _globalFocusOverlay
   ...
}

Objective-C support

You can add AppKitFocusOverlay to your Objective-C project easily.

@import AppKitFocusOverlay;

@interface AppDelegate ()
/// Define an instance of the focus overlay
@property (nonatomic, strong) AppKitFocusOverlay* focusOverlay;
@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
   /// Create the overlay and attach
   AppKitFocusOverlay* focus = [[AppKitFocusOverlay alloc] init];
   [self setFocusOverlay: focus];
}

@end

Notes

  • You may need to embed the swift libraries (Build settings) if your app doesn't already if you're planning to distribute an archive or release build to (eg.) your QA dept.
  • If you need to customize the hotkeys for objective-c you'll need to fork this library and change the code in AppKitFocusOverlay.swift, as the HotKey library is not exposed through Objective-C and as such the hotkey-setting initializers are not exposed to objc.

Screenshots

Thanks!

Uses HotKey to define and detect hot-key presses.

License

MIT. Use it for anything you want, just attribute my work if you do. Let me know if you do use it somewhere, I'd love to hear about it!

MIT License

Copyright (c) 2021 Darren Ford

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Description

  • Swift Tools 5.3.0
View More Packages from this Author

Dependencies

Last updated: Sat Apr 06 2024 03:50:15 GMT-0900 (Hawaii-Aleutian Daylight Time)