diff --git a/LunarBarMac/Modules/Sources/AppKitExtensions/NSFont+Extension.swift b/LunarBarMac/Modules/Sources/AppKitExtensions/NSFont+Extension.swift index e8b96b5..0e0f0a8 100644 --- a/LunarBarMac/Modules/Sources/AppKitExtensions/NSFont+Extension.swift +++ b/LunarBarMac/Modules/Sources/AppKitExtensions/NSFont+Extension.swift @@ -7,7 +7,7 @@ import AppKit public extension NSFont { - static func mediumSystemFont(ofSize fontSize: CGFloat) -> NSFont { + static func mediumSystemFont(ofSize fontSize: Double) -> NSFont { .systemFont(ofSize: fontSize, weight: .medium) } } diff --git a/LunarBarMac/Resources/Localizable.xcstrings b/LunarBarMac/Resources/Localizable.xcstrings index 8e35b8a..7c42a63 100644 --- a/LunarBarMac/Resources/Localizable.xcstrings +++ b/LunarBarMac/Resources/Localizable.xcstrings @@ -1417,23 +1417,6 @@ } } }, - "Float on Top" : { - "comment" : "[Menu] Float the popover on top", - "localizations" : { - "zh-Hans" : { - "stringUnit" : { - "state" : "translated", - "value" : "保持在顶部" - } - }, - "zh-Hant" : { - "stringUnit" : { - "state" : "translated", - "value" : "保持在頂部" - } - } - } - }, "Ghost Festival" : { "comment" : "Chinese traditional festival", "localizations" : { @@ -2242,6 +2225,23 @@ } } }, + "Pin on Top" : { + "comment" : "[Menu] Pin the popover on top", + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "置顶显示" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "translated", + "value" : "置頂顯示" + } + } + } + }, "Please check your network connection or get the latest release from the version history." : { "comment" : "Message for failed to get the update", "localizations" : { diff --git a/LunarBarMac/Sources/Main/AppDelegate.swift b/LunarBarMac/Sources/Main/AppDelegate.swift index d8d5d4b..e3d08ea 100644 --- a/LunarBarMac/Sources/Main/AppDelegate.swift +++ b/LunarBarMac/Sources/Main/AppDelegate.swift @@ -239,9 +239,9 @@ private extension AppDelegate { return false } - // Prevent multiple popovers, e.g., when float on top is enabled + // Prevent multiple popovers, e.g., when pin on top is enabled if let popover = presentedPopover, popover.isShown { - // Just think of it as a "float on top" cancellation + // Just think of it as a "pin on top" cancellation popover.behavior = .transient popover.close() return false diff --git a/LunarBarMac/Sources/Main/AppMainVC+Menu.swift b/LunarBarMac/Sources/Main/AppMainVC+Menu.swift index dd46684..2737861 100644 --- a/LunarBarMac/Sources/Main/AppMainVC+Menu.swift +++ b/LunarBarMac/Sources/Main/AppMainVC+Menu.swift @@ -213,11 +213,19 @@ private extension AppMainVC { menu.addSeparator() - menu.addItem(withTitle: Localized.UI.menuTitleFloatOnTop) { [weak self] in - self?.floatOnTop.toggle() - self?.popover?.behavior = self?.floatOnTop == true ? .applicationDefined : .transient - } - .setOn(floatOnTop) + menu.addItem({ + let item = NSMenuItem(title: Localized.UI.menuTitlePinOnTop) + item.addAction { [weak self] in + self?.togglePinnedOnTop() + } + + // Just a hint here, event is handled using NSEvent.addLocalMonitor + item.keyEquivalent = "p" + item.keyEquivalentModifierMask = [] + + item.setOn(pinnedOnTop) + return item + }()) let item = NSMenuItem(title: Localized.UI.menuTitleAppearance) item.submenu = menu diff --git a/LunarBarMac/Sources/Main/AppMainVC.swift b/LunarBarMac/Sources/Main/AppMainVC.swift index c5dbe0d..23c2ffc 100644 --- a/LunarBarMac/Sources/Main/AppMainVC.swift +++ b/LunarBarMac/Sources/Main/AppMainVC.swift @@ -13,7 +13,7 @@ import LunarBarKit */ final class AppMainVC: NSViewController { // States - var floatOnTop = false + var pinnedOnTop = false var monthDate = Date.now weak var popover: NSPopover? @@ -90,6 +90,11 @@ extension AppMainVC { Logger.log(.info, "Moving the calendar by \(offset) \(unit)") updateCalendar(targetDate: newDate) } + + func togglePinnedOnTop() { + pinnedOnTop.toggle() + popover?.behavior = pinnedOnTop ? .applicationDefined : .transient + } } // MARK: - HeaderViewDelegate @@ -194,6 +199,9 @@ private extension AppMainVC { case .kVK_DownArrow: self.updateCalendar(moveBy: 1, unit: .year) return nil + case .kVK_ANSI_P: + self.togglePinnedOnTop() + return nil default: return event } diff --git a/LunarBarMac/Sources/Shared/AppDefinitions.swift b/LunarBarMac/Sources/Shared/AppDefinitions.swift index 175f54e..12a6e14 100644 --- a/LunarBarMac/Sources/Shared/AppDefinitions.swift +++ b/LunarBarMac/Sources/Shared/AppDefinitions.swift @@ -40,7 +40,7 @@ enum Localized { static let menuTitleScaleRoomy = String(localized: "Roomy", comment: "[Menu] Content scale: roomy") static let menuTitleReduceMotion = String(localized: "Reduce Motion", comment: "[Menu] Disable animations when presenting the calendar popover") static let menuTitleReduceTransparency = String(localized: "Reduce Transparency", comment: "[Menu] Reduce transparency of the calendar panel") - static let menuTitleFloatOnTop = String(localized: "Float on Top", comment: "[Menu] Float the popover on top") + static let menuTitlePinOnTop = String(localized: "Pin on Top", comment: "[Menu] Pin the popover on top") static let menuTitleCalendars = String(localized: "Calendars", comment: "[Menu] Show or hide system calendars") static let menuTitleShowReminders = String(localized: "Show Reminders", comment: "[Menu] To request access for Reminders") static let menuTitleSelectAll = String(localized: "Select All", comment: "[Menu] Select all calendars") @@ -203,6 +203,7 @@ enum AlphaLevels { extension UInt16 { static let kVK_ANSI_Q: Self = 0x0C static let kVK_ANSI_W: Self = 0x0D + static let kVK_ANSI_P: Self = 0x23 static let kVK_Space: Self = 0x31 static let kVK_Escape: Self = 0x35 static let kVK_LeftArrow: Self = 0x7B