Skip to content

Commit

Permalink
Fix popover appearing behind the menu bar (#148)
Browse files Browse the repository at this point in the history
1.10.3 caused a new issue where the popover would
appear behind the menu bar for some calendar sizes
  • Loading branch information
pakerwreah authored Sep 22, 2023
1 parent 62dd489 commit 142b9c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
6 changes: 3 additions & 3 deletions Calendr.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 53;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -1259,7 +1259,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.10.3;
MARKETING_VERSION = 1.10.4;
PRODUCT_BUNDLE_IDENTIFIER = br.paker.Calendr;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Calendr/Config/Calendr-Bridging-Header.h";
Expand All @@ -1285,7 +1285,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.10.3;
MARKETING_VERSION = 1.10.4;
PRODUCT_BUNDLE_IDENTIFIER = br.paker.Calendr;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Calendr/Config/Calendr-Bridging-Header.h";
Expand Down
28 changes: 12 additions & 16 deletions Calendr/Main/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -370,16 +370,6 @@ class MainViewController: NSViewController, NSPopoverDelegate {
searchInputText
.bind(to: searchInput.rx.stringValue)
.disposed(by: disposeBag)

// 🔨 Dirty hack to force the window to update its position
// when switching screens with pinned (sticky) calendar
screenProvider.screenObservable
.bind { [weak self] _ in
guard let self, let window = self.view.window else { return }
window.setContentSize(.zero)
window.setContentSize(self.contentSize)
}
.disposed(by: disposeBag)
}

private func setUpSettings() {
Expand Down Expand Up @@ -429,10 +419,11 @@ class MainViewController: NSViewController, NSPopoverDelegate {
searchInput.isHidden = true
}

private func setUpPopover(_ popover: NSPopover) {
private func setUpAndShow(_ popover: NSPopover, from button: NSStatusBarButton) {

popover.contentViewController = self
popover.delegate = self
popover.animates = false

settingsViewController.rx.viewWillAppear
.map(.applicationDefined)
Expand All @@ -452,6 +443,14 @@ class MainViewController: NSViewController, NSPopoverDelegate {
.map { $0 == .on ? .applicationDefined : .transient }
.bind(to: popover.rx.behavior)
.disposed(by: popoverDisposeBag)

screenProvider.screenObservable
.withUnretained(popover) { p, _ in p }
.filter(\.animates.isFalse)
.bind {
$0.show(relativeTo: .zero, of: button, preferredEdge: .maxY)
}
.disposed(by: popoverDisposeBag)
}

private func setUpAutoClose() {
Expand All @@ -467,8 +466,6 @@ class MainViewController: NSViewController, NSPopoverDelegate {

func popoverWillShow(_ notification: Notification) {

notification.popover.animates = false

setUpAutoClose()
}

Expand All @@ -489,7 +486,7 @@ class MainViewController: NSViewController, NSPopoverDelegate {
private func forceLayout() {

let wctrl = NSWindowController(window: NSWindow(contentViewController: self))
wctrl.showWindow(nil)
wctrl.window?.orderFrontRegardless()
wctrl.close()

view.window?.setContentSize(contentSize)
Expand Down Expand Up @@ -523,8 +520,7 @@ class MainViewController: NSViewController, NSPopoverDelegate {
self.forceLayout()

let popover = NSPopover()
self.setUpPopover(popover)
popover.show(relativeTo: .zero, of: statusBarButton, preferredEdge: .maxY)
self.setUpAndShow(popover, from: statusBarButton)

return popover.rx.deallocated
}
Expand Down

0 comments on commit 142b9c1

Please sign in to comment.