Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automatically-unhide-macos-hidden-apps-exceptions config option. #1117

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions Sources/AppBundle/GlobalObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@ class GlobalObserver {
// "Hide app" (cmd-h) -> force focus
MacApp.allAppsMap.values.filter({ $0.nsApp.isHidden }).count == 1
{
// Force focus
_ = w.focusWindow()
_ = w.nativeFocus()
if let identifier = w.macAppUnsafe.nsApp.bundleIdentifier,
config.automaticallyUnhideMacosHiddenAppsExceptions.contains(identifier)
{}
else {
// Force focus
_ = w.focusWindow()
_ = w.nativeFocus()
}
}
for app in MacApp.allAppsMap.values {
if let identifier = app.nsApp.bundleIdentifier,
config.automaticallyUnhideMacosHiddenAppsExceptions.contains(identifier)
{
continue
}
app.nsApp.unhide()
}
}
Expand Down
1 change: 1 addition & 0 deletions Sources/AppBundle/config/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct Config: Copyable {
var defaultRootContainerOrientation: DefaultContainerOrientation = .auto
var startAtLogin: Bool = false
var automaticallyUnhideMacosHiddenApps: Bool = false
var automaticallyUnhideMacosHiddenAppsExceptions: [String] = []
var accordionPadding: Int = 30
var enableNormalizationOppositeOrientationForNestedContainers: Bool = true
var execOnWorkspaceChange: [String] = [] // todo deprecate
Expand Down
16 changes: 16 additions & 0 deletions Sources/AppBundle/config/parseConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ private let configParser: [String: any ParserProtocol<Config>] = [

"start-at-login": Parser(\.startAtLogin, parseBool),
"automatically-unhide-macos-hidden-apps": Parser(\.automaticallyUnhideMacosHiddenApps, parseBool),
"automatically-unhide-macos-hidden-apps-exceptions": Parser(\.automaticallyUnhideMacosHiddenAppsExceptions, parseStringArray),
"accordion-padding": Parser(\.accordionPadding, parseInt),
"exec-on-workspace-change": Parser(\.execOnWorkspaceChange, parseExecOnWorkspaceChange),
"exec": Parser(\.execConfig, parseExecConfig),
Expand Down Expand Up @@ -201,6 +202,14 @@ func parseConfig(_ rawToml: String) -> (config: Config, errors: [TomlParseError]
)]
}
}

if !config.automaticallyUnhideMacosHiddenApps && !config.automaticallyUnhideMacosHiddenAppsExceptions.isEmpty {
errors.append(.semantic(
.root,
"automatically-unhide-macos-hidden-apps is false but automatically-unhide-macos-hidden-apps-exceptions is not empty"
))
}

return (config, errors)
}

Expand Down Expand Up @@ -286,6 +295,13 @@ private func parseExecOnWorkspaceChange(_ raw: TOMLValueConvertible, _ backtrace
}
}

private func parseStringArray(_ raw: TOMLValueConvertible, _ backtrace: TomlBacktrace) -> ParsedToml<[String]> {
parseTomlArray(raw, backtrace)
.flatMap { arr in
arr.mapAllOrFailure { elem in parseString(elem, backtrace) }
}
}

private func parseDefaultContainerOrientation(_ raw: TOMLValueConvertible, _ backtrace: TomlBacktrace) -> ParsedToml<DefaultContainerOrientation> {
parseString(raw, backtrace).flatMap {
DefaultContainerOrientation(rawValue: $0)
Expand Down
3 changes: 2 additions & 1 deletion Sources/AppBundle/normalizeLayoutReason.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ private func _normalizeLayoutReason(workspace: Workspace, windows: [Window]) {
let isMacosFullscreen = window.isMacosFullscreen
let isMacosMinimized = !isMacosFullscreen && window.isMacosMinimized
let isMacosWindowOfHiddenApp = !isMacosFullscreen && !isMacosMinimized &&
!config.automaticallyUnhideMacosHiddenApps && window.macAppUnsafe.nsApp.isHidden
(!config.automaticallyUnhideMacosHiddenApps || config.automaticallyUnhideMacosHiddenAppsExceptions.contains(window.app.id ?? "")) &&
window.macAppUnsafe.nsApp.isHidden
switch window.layoutReason {
case .standard:
if isMacosFullscreen {
Expand Down
1 change: 1 addition & 0 deletions docs/config-examples/default-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ on-focused-monitor-changed = ['move-mouse monitor-lazy-center']
# Useful if you don't use this macOS feature, but accidentally hit cmd-h or cmd-alt-h key
# Also see: https://nikitabobko.github.io/AeroSpace/goodies#disable-hide-app
automatically-unhide-macos-hidden-apps = false
automatically-unhide-macos-hidden-apps-exceptions = []

# Possible values: (qwerty|dvorak)
# See https://nikitabobko.github.io/AeroSpace/guide#key-mapping
Expand Down
Loading