Skip to content

Commit

Permalink
Fix title bar element detection
Browse files Browse the repository at this point in the history
  • Loading branch information
decodism committed Dec 8, 2023
1 parent 0d1937e commit 42ab3b3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions Rectangle/AccessibilityElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,19 @@ class AccessibilityElement {
return elements
}

private func getChildElement(_ position: CGPoint) -> AccessibilityElement? {
return childElements?.first { $0.frame.contains(position) }
}

func getSelfOrChildElementRecursively(_ position: CGPoint) -> AccessibilityElement? {
var element = self
var elements = Set<AccessibilityElement>()
while let childElement = element.getChildElement(position), elements.insert(childElement).inserted {
element = childElement
}
return element
}

var windowId: CGWindowID? {
wrappedElement.getWindowId()
}
Expand Down Expand Up @@ -359,6 +372,18 @@ extension AccessibilityElement {
}
}

extension AccessibilityElement: Equatable {
static func == (lhs: AccessibilityElement, rhs: AccessibilityElement) -> Bool {
return lhs.wrappedElement == rhs.wrappedElement
}
}

extension AccessibilityElement: Hashable {
func hash(into hasher: inout Hasher) {
hasher.combine(wrappedElement)
}
}

class StageWindowAccessibilityElement: AccessibilityElement {
private let _windowId: CGWindowID

Expand Down
2 changes: 1 addition & 1 deletion Rectangle/TitleBarManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TitleBarManager {
TitleBarManager.systemSettingDisabled,
let action = WindowAction(rawValue: Defaults.doubleClickTitleBar.value - 1),
case let location = NSEvent.mouseLocation.screenFlipped,
let element = AccessibilityElement(location),
let element = AccessibilityElement(location)?.getSelfOrChildElementRecursively(location),
let windowElement = element.windowElement,
var titleBarFrame = windowElement.titleBarFrame
else {
Expand Down

0 comments on commit 42ab3b3

Please sign in to comment.