Auto-adjust docked position to match available screen space #39
Auto-adjust docked position to match available screen space #39
Conversation
How about swizzling This is what I've used for swizzling in the past: func swizzle(type: AnyClass, original originalSelector: Selector, swizzled swizzledSelector: Selector) {
guard
let originalMethod = class_getInstanceMethod(type, originalSelector),
let swizzledMethod = class_getInstanceMethod(type, swizzledSelector)
else {
return
}
// Check if the original method has been swizzelled
if class_addMethod(
type,
originalSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod)
) {
class_replaceMethod(
type,
swizzledSelector,
originalMethod,
method_getTypeEncoding(originalMethod)
)
} else {
method_exchangeImplementations(
originalMethod,
swizzledMethod
)
}
} |
I would also like to see the |
@ThatsJustCheesy Bump :) @Mortennn Any thoughts on this? |
When the size of the Dock changes a notification is fired which we can then listen for. func applicationDidFinishLaunching(_ notification: Notification) {
DistributedNotificationCenter.default().addObserver(self, selector: #selector(dockChangedSize), name: Notification.Name(rawValue: "com.apple.dock.prefchanged"), object: nil)
}
@objc
private func dockSettingsChanged() {
print("Dock settings changed")
} |
@Mortennn That only fires when the Dock preferences are changes, not when the Dock is auto-shown/hidden, which is what we want. |
Hey, sorry for leaving this undone! It looks like there's no
So I'll move the current logic into an NSScreen extension, if that's okay. |
Previously, the touch bar window would obstruct menubar clicks when the menubar was set to auto-hide. Now, the touch bar stays below a hardcoded distance of 22 pixels from the top of the screen.
I found a better way. Turns out the |
Touch Bar Simulator/util.swift
Outdated
@@ -72,7 +73,7 @@ extension NSWindow { | |||
} | |||
switch yPositioning { | |||
case .top: | |||
y = visibleFrame.maxY - frame.height | |||
y = min(visibleFrame.maxY - frame.height, screen.frame.maxY - 22 - frame.height) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a short comment that explains this logic (Like in the commit message).
And can you move 22
into a variable with a descriptive name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use NSStatusBar.system.thickness
to retrieve the status bar height (22
).
Oh, excellent! API discoverability is fun… And I initially saw |
This reverts commit 1894d48.
Actually, looking back, this solution could've worked:
Since none of our solutions have accounted for auto-show anyhow. But, now that we've found it, it's probably best to rely on the documented notification. |
Replaces polling.
fee1065
to
b6f63e4
Compare
Can you fix the merge conflict? |
🙌 |
Fixes #35
Implemented by polling for the size of the "visible frame" every fraction of a second when in docked mode. I don't know of a way to get notified when it changes, but polling allows us to automatically adjust the docked position, fixing the issue described.
IssueHunt Summary
Referenced issues
This pull request has been submitted to:
IssueHunt has been backed by the following sponsors. Become a sponsor