Skip to content

Commit

Permalink
Press "P" to "Pin on Top" (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanzhong authored Nov 21, 2024
1 parent 455fb47 commit 54cfbd9
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
34 changes: 17 additions & 17 deletions LunarBarMac/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -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" : {
Expand Down Expand Up @@ -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" : {
Expand Down
4 changes: 2 additions & 2 deletions LunarBarMac/Sources/Main/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 13 additions & 5 deletions LunarBarMac/Sources/Main/AppMainVC+Menu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion LunarBarMac/Sources/Main/AppMainVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion LunarBarMac/Sources/Shared/AppDefinitions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 54cfbd9

Please sign in to comment.