Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Press "P" to "Pin on Top" #79

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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