Skip to content

Commit

Permalink
Fix lyrics offset on macOS Big Sur and later
Browse files Browse the repository at this point in the history
  • Loading branch information
dnicolson committed Aug 29, 2022
1 parent c16b6a4 commit fdcf986
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions LyricsX/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
<connections>
<outlet property="lyricsOffsetStepper" destination="FwA-Sj-odc" id="Wpt-Xo-ryF"/>
<outlet property="lyricsOffsetTextField" destination="BE8-Ux-QD2" id="U25-Zx-LxS"/>
<outlet property="lyricsOffsetView" destination="LV9-pp-2tz" id="XY6-hn-HAX"/>
<outlet property="statusBarMenu" destination="OCV-Y8-x1C" id="zHx-WQ-Hu4"/>
</connections>
</customObject>
Expand Down
22 changes: 22 additions & 0 deletions LyricsX/Component/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation, NSMenu
return NSApplication.shared.delegate as? AppDelegate
}

@IBOutlet weak var lyricsOffsetView: NSView!
@IBOutlet weak var lyricsOffsetTextField: NSTextField!
@IBOutlet weak var lyricsOffsetStepper: NSStepper!
@IBOutlet weak var statusBarMenu: NSMenu!

var karaokeLyricsWC: KaraokeLyricsWindowController?
var lyricsOffsetViewConstraint: NSLayoutConstraint?

lazy var searchLyricsWC: NSWindowController = {
// swiftlint:disable:next force_cast
Expand All @@ -48,6 +50,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation, NSMenu
Crashes.self
])
#endif

if #available(macOS 10.16, *) {
for constraint in lyricsOffsetView.constraints where (
constraint.firstAttribute == .leading && constraint.constant == 19) {
lyricsOffsetViewConstraint = constraint
}
}

let controller = AppController.shared

Expand Down Expand Up @@ -140,6 +149,19 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation, NSMenu
menu.item(withTag: 202)?.isEnabled = AppController.shared.currentLyrics != nil
}

func menuWillOpen(_ menu: NSMenu) {
if #available(macOS 10.16, *) {
let menuHasOnState = statusBarMenu.items.filter { menuItem in
return menuItem.state == .on
}.count > 0

lyricsOffsetViewConstraint?.constant = 14
if menuHasOnState {
lyricsOffsetViewConstraint?.constant += 10
}
}
}

// MARK: - Menubar Action

var lyricsHUD: NSWindowController?
Expand Down

0 comments on commit fdcf986

Please sign in to comment.