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 ServiceManagement
import OSLog
fileprivate enum Metrics {
static let contentMinWidth = 400.0
@@ -11,6 +12,11 @@ fileprivate enum Metrics {
}
class CmdViewController: NSViewController {
fileprivate static let logger = Logger(
subsystem: Bundle.main.bundleIdentifier!,
category: String(describing: CmdViewController.self)
)
private weak var cmdFile: CmdFile?
private var timer: DispatchSourceTimer?
private var keyboardEvents: EventMonitor?
@@ -346,6 +352,12 @@ class CmdViewController: NSViewController {
private func setupKeyEvents() {
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) {
self?.reloadButton.image = systemImage("arrow.clockwise.circle.fill", .title2, .large, .init(paletteColors: [.white, .systemCyan]))
self?.reloadButton.action = #selector(self?.reloadWidgets)
@@ -356,24 +368,34 @@ class CmdViewController: NSViewController {
self?.reloadButton.toolTip = "Reload Current"
}
if event.modifierFlags.contains(.command) && event.keyCode == 15 { // r
self?.reloadWidget()
}
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
// NOTE: Standalone keys should go last!
if (modifiers & command) == command,
(modifiers & (control | shift | option)) == 0,
event.keyCode == 12 // Q
{
self?.terminateApp()
}
if event.modifierFlags.contains(.command) && event.keyCode == 8 { // c
} else if (modifiers & command) == command,
(modifiers & (control | shift | option)) == 0,
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)
} else if event.keyCode == 12 || event.keyCode == 53 { // Q, ESC
self?.view.superview?.window?.resignKey()
}
return event

View File

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

View File

@@ -2,7 +2,7 @@ import Cocoa
class PopoverPanel: NSPanel {
override var canBecomeKey: Bool { true }
init(viewController: NSViewController) {
super.init(
contentRect: CGRect(x: 0, y: 0, width: 100, height: 100),
@@ -11,7 +11,7 @@ class PopoverPanel: NSPanel {
defer: false
)
super.contentViewController = viewController
title = ""
isMovable = false
isMovableByWindowBackground = false
@@ -20,18 +20,22 @@ class PopoverPanel: NSPanel {
level = .statusBar
titleVisibility = .hidden
titlebarAppearsTransparent = true
animationBehavior = .none
collectionBehavior = [.moveToActiveSpace, .fullScreenAuxiliary, .transient]
isReleasedWhenClosed = false
hidesOnDeactivate = false
standardWindowButton(.closeButton)?.isHidden = true
standardWindowButton(.miniaturizeButton)?.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 {
return super.performKeyEquivalent(with: event)
// return super.performKeyEquivalent(with: event)
return true
}
}