PopoverPanel no longer handles key equivalents.

This commit is contained in:
2025-01-05 14:04:18 -08:00
parent 4795f95416
commit 94a2c217ef
3 changed files with 49 additions and 24 deletions

View File

@@ -1,5 +1,6 @@
import Cocoa import Cocoa
import ServiceManagement import ServiceManagement
import OSLog
fileprivate enum Metrics { fileprivate enum Metrics {
static let contentMinWidth = 400.0 static let contentMinWidth = 400.0
@@ -11,6 +12,11 @@ fileprivate enum Metrics {
} }
class CmdViewController: NSViewController { class CmdViewController: NSViewController {
fileprivate static let logger = Logger(
subsystem: Bundle.main.bundleIdentifier!,
category: String(describing: CmdViewController.self)
)
private weak var cmdFile: CmdFile? private weak var cmdFile: CmdFile?
private var timer: DispatchSourceTimer? private var timer: DispatchSourceTimer?
private var keyboardEvents: EventMonitor? private var keyboardEvents: EventMonitor?
@@ -346,6 +352,12 @@ class CmdViewController: NSViewController {
private func setupKeyEvents() { private func setupKeyEvents() {
keyboardEvents = LocalEventMonitor(mask: [.flagsChanged, .keyDown], handler: { [weak self] event in keyboardEvents = LocalEventMonitor(mask: [.flagsChanged, .keyDown], handler: { [weak self] event in
let modifiers = event.modifierFlags.rawValue
let command = NSEvent.ModifierFlags.command.rawValue
let shift = NSEvent.ModifierFlags.shift.rawValue
let control = NSEvent.ModifierFlags.control.rawValue
let option = NSEvent.ModifierFlags.option.rawValue
if event.modifierFlags.contains(.shift) { if event.modifierFlags.contains(.shift) {
self?.reloadButton.image = systemImage("arrow.clockwise.circle.fill", .title2, .large, .init(paletteColors: [.white, .systemCyan])) self?.reloadButton.image = systemImage("arrow.clockwise.circle.fill", .title2, .large, .init(paletteColors: [.white, .systemCyan]))
self?.reloadButton.action = #selector(self?.reloadWidgets) self?.reloadButton.action = #selector(self?.reloadWidgets)
@@ -356,24 +368,34 @@ class CmdViewController: NSViewController {
self?.reloadButton.toolTip = "Reload Current" self?.reloadButton.toolTip = "Reload Current"
} }
if event.modifierFlags.contains(.command) && event.keyCode == 15 { // r // NOTE: Standalone keys should go last!
self?.reloadWidget() if (modifiers & command) == command,
} (modifiers & (control | shift | option)) == 0,
event.keyCode == 12 // Q
if event.modifierFlags.contains(.shift) && event.modifierFlags.contains(.command) && event.keyCode == 15 { // r {
self?.reloadWidgets()
}
if (event.modifierFlags.contains(.command) && event.keyCode == 13) || event.keyCode == 12 || event.keyCode == 53 { // w, q, esc
self?.view.superview?.window?.resignKey()
}
if event.modifierFlags.contains(.command) && event.keyCode == 12 { // q
self?.terminateApp() self?.terminateApp()
} } else if (modifiers & command) == command,
(modifiers & (control | shift | option)) == 0,
if event.modifierFlags.contains(.command) && event.keyCode == 8 { // c event.keyCode == 13 // W
{
self?.view.superview?.window?.resignKey()
} else if (modifiers & command) == command,
(modifiers & (control | shift | option)) == 0,
event.keyCode == 15 // R
{
self?.reloadWidget()
} else if (modifiers & (command & shift)) == command & shift,
(modifiers & (control | option)) == 0,
event.keyCode == 15 // R
{
self?.reloadWidgets()
} else if (modifiers & command) == command,
(modifiers & (control | shift | option)) == 0,
event.keyCode == 8 // C
{
self?.textLabel.currentEditor()?.copy(nil) self?.textLabel.currentEditor()?.copy(nil)
} else if event.keyCode == 12 || event.keyCode == 53 { // Q, ESC
self?.view.superview?.window?.resignKey()
} }
return event return event

View File

@@ -30,12 +30,11 @@ cmdbar_updater:
@cp updater/$@ . @cp updater/$@ .
./arm64/%.o: %.swift ./arm64/%.o: %.swift
@echo $<
swift -frontend -c $(if $(DEBUG), -D DEBUG,) \ swift -frontend -c $(if $(DEBUG), -D DEBUG,) \
-target arm64-apple-macos$(MACOS_VERSION) $(FLAGS) \ -target arm64-apple-macos$(MACOS_VERSION) $(FLAGS) \
-I./libs/Zip/Zip -I./libs/Zip/Zip/arm64 -L./libs/Zip/Zip/arm64 \ -I./libs/Zip/Zip -I./libs/Zip/Zip/arm64 -L./libs/Zip/Zip/arm64 \
-primary-file $< $(filter-out $<, $(SRCMODULES)) $(LIBS) \ -primary-file $< $(filter-out $<, $(SRCMODULES)) $(LIBS) \
-sdk $(SDK) -module-name $(EXEC) -o $@ -emit-module -sdk $(SDK) -module-name $(EXEC) -o $@ -emit-module && touch $@
ifdef UNIVERSAL ifdef UNIVERSAL
./x86_64/%.o: %.swift ./x86_64/%.o: %.swift
@@ -43,7 +42,7 @@ ifdef UNIVERSAL
-target x86_64-apple-macos$(MACOS_VERSION) $(FLAGS) \ -target x86_64-apple-macos$(MACOS_VERSION) $(FLAGS) \
-I./libs/Zip/Zip -I./libs/Zip/Zip/x86_64 -L./libs/Zip/Zip/x86_64 \ -I./libs/Zip/Zip -I./libs/Zip/Zip/x86_64 -L./libs/Zip/Zip/x86_64 \
-primary-file $< $(filter-out $<, $(SRCMODULES)) $(LIBS) \ -primary-file $< $(filter-out $<, $(SRCMODULES)) $(LIBS) \
-sdk $(SDK) -module-name $(EXEC) -o $@ -emit-module -sdk $(SDK) -module-name $(EXEC) -o $@ -emit-module && touch $@
endif endif
./arm64/$(EXEC): $(ARMOBJMODULES) ./arm64/$(EXEC): $(ARMOBJMODULES)
@ld -syslibroot $(SDK) -lSystem -arch arm64 -macos_version_min \ @ld -syslibroot $(SDK) -lSystem -arch arm64 -macos_version_min \

View File

@@ -31,7 +31,11 @@ class PopoverPanel: NSPanel {
standardWindowButton(.zoomButton)?.isHidden = true standardWindowButton(.zoomButton)?.isHidden = true
} }
// HACK: ???
// NOTE: All events should be managed by an NSViewController.
// Though, I am not sure how great of a solution this is.
override func performKeyEquivalent(with event: NSEvent) -> Bool { override func performKeyEquivalent(with event: NSEvent) -> Bool {
return super.performKeyEquivalent(with: event) // return super.performKeyEquivalent(with: event)
return true
} }
} }