PopoverPanel no longer handles key equivalents.
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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 \
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import Cocoa
|
|||||||
|
|
||||||
class PopoverPanel: NSPanel {
|
class PopoverPanel: NSPanel {
|
||||||
override var canBecomeKey: Bool { true }
|
override var canBecomeKey: Bool { true }
|
||||||
|
|
||||||
init(viewController: NSViewController) {
|
init(viewController: NSViewController) {
|
||||||
super.init(
|
super.init(
|
||||||
contentRect: CGRect(x: 0, y: 0, width: 100, height: 100),
|
contentRect: CGRect(x: 0, y: 0, width: 100, height: 100),
|
||||||
@@ -11,7 +11,7 @@ class PopoverPanel: NSPanel {
|
|||||||
defer: false
|
defer: false
|
||||||
)
|
)
|
||||||
super.contentViewController = viewController
|
super.contentViewController = viewController
|
||||||
|
|
||||||
title = ""
|
title = ""
|
||||||
isMovable = false
|
isMovable = false
|
||||||
isMovableByWindowBackground = false
|
isMovableByWindowBackground = false
|
||||||
@@ -20,18 +20,22 @@ class PopoverPanel: NSPanel {
|
|||||||
level = .statusBar
|
level = .statusBar
|
||||||
titleVisibility = .hidden
|
titleVisibility = .hidden
|
||||||
titlebarAppearsTransparent = true
|
titlebarAppearsTransparent = true
|
||||||
|
|
||||||
animationBehavior = .none
|
animationBehavior = .none
|
||||||
collectionBehavior = [.moveToActiveSpace, .fullScreenAuxiliary, .transient]
|
collectionBehavior = [.moveToActiveSpace, .fullScreenAuxiliary, .transient]
|
||||||
isReleasedWhenClosed = false
|
isReleasedWhenClosed = false
|
||||||
hidesOnDeactivate = false
|
hidesOnDeactivate = false
|
||||||
|
|
||||||
standardWindowButton(.closeButton)?.isHidden = true
|
standardWindowButton(.closeButton)?.isHidden = true
|
||||||
standardWindowButton(.miniaturizeButton)?.isHidden = true
|
standardWindowButton(.miniaturizeButton)?.isHidden = true
|
||||||
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user