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 Sep 3, 2022
1 parent c16b6a4 commit 5abb483
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion 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 Expand Up @@ -451,7 +452,7 @@
<constraints>
<constraint firstItem="DG2-8b-vTy" firstAttribute="centerY" secondItem="LV9-pp-2tz" secondAttribute="centerY" id="5gA-e2-0RM"/>
<constraint firstItem="BE8-Ux-QD2" firstAttribute="leading" secondItem="DG2-8b-vTy" secondAttribute="trailing" constant="8" id="66I-Ch-hG0"/>
<constraint firstItem="DG2-8b-vTy" firstAttribute="leading" secondItem="LV9-pp-2tz" secondAttribute="leading" constant="21" id="826-cy-w1T"/>
<constraint firstItem="DG2-8b-vTy" firstAttribute="leading" secondItem="LV9-pp-2tz" secondAttribute="leading" constant="21" identifier="lyricsOffsetConstraint" id="826-cy-w1T"/>
<constraint firstItem="FwA-Sj-odc" firstAttribute="leading" secondItem="BE8-Ux-QD2" secondAttribute="trailing" constant="5" id="9G1-eA-c8X"/>
<constraint firstItem="BE8-Ux-QD2" firstAttribute="top" secondItem="LV9-pp-2tz" secondAttribute="top" constant="2" id="Jw4-sr-Qu8"/>
<constraint firstItem="0ii-PC-ZCl" firstAttribute="centerY" secondItem="LV9-pp-2tz" secondAttribute="centerY" id="Yhp-74-yJR"/>
Expand Down
16 changes: 16 additions & 0 deletions LyricsX/Component/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ 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!
Expand Down Expand Up @@ -140,6 +141,21 @@ 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

let lyricsOffsetConstraint = lyricsOffsetView.constraints.first(where: {$0.identifier == "lyricsOffsetConstraint"})

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

// MARK: - Menubar Action

var lyricsHUD: NSWindowController?
Expand Down

0 comments on commit 5abb483

Please sign in to comment.