Skip to content

Commit

Permalink
Added a defaults config to allow the old way of obtaining the window …
Browse files Browse the repository at this point in the history
…under the cursor
  • Loading branch information
rxhanson committed Sep 28, 2023
1 parent 5cc48ce commit df2f102
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Rectangle/AccessibilityElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ extension AccessibilityElement {

private static func getWindowInfo(_ location: CGPoint) -> WindowInfo? {
let infoAtLocation = WindowUtil.getWindowList().first(where: {windowInfo in
windowInfo.level < 23
windowInfo.level < 23 // 23 is the level of the Notification Center
&& !["Dock", "WindowManager"].contains(windowInfo.processName)
&& windowInfo.frame.contains(location)
})
Expand All @@ -314,6 +314,15 @@ extension AccessibilityElement {

static func getWindowElementUnderCursor() -> AccessibilityElement? {
let position = NSEvent.mouseLocation.screenFlipped

let systemWideFirst = Defaults.systemWideMouseDown.userEnabled

if systemWideFirst,
let element = AccessibilityElement(position),
let windowElement = element.windowElement {
return windowElement
}

if let info = getWindowInfo(position) {
if !Defaults.dragFromStage.userDisabled {
if StageUtil.stageCapable && StageUtil.stageEnabled,
Expand All @@ -333,7 +342,11 @@ extension AccessibilityElement {
}
}
}
if let element = AccessibilityElement(position), let windowElement = element.windowElement {

if !systemWideFirst,
let element = AccessibilityElement(position),
let windowElement = element.windowElement {

if Logger.logging, let pid = windowElement.pid {
let appName = NSRunningApplication(processIdentifier: pid)?.localizedName ?? ""
Logger.log("Window under cursor fallback matched: \(appName)")
Expand Down
2 changes: 2 additions & 0 deletions Rectangle/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class Defaults {
static let doubleClickTitleBar = IntDefault(key: "doubleClickTitleBar")
static let doubleClickTitleBarRestore = OptionalBoolDefault(key: "doubleClickTitleBarRestore")
static let ignoreDragSnapToo = OptionalBoolDefault(key: "ignoreDragSnapToo")
static let systemWideMouseDown = OptionalBoolDefault(key: "systemWideMouseDown")

static var array: [Default] = [
launchOnLogin,
Expand Down Expand Up @@ -155,6 +156,7 @@ class Defaults {
doubleClickTitleBar,
doubleClickTitleBarRestore,
ignoreDragSnapToo,
systemWideMouseDown
]
}

Expand Down

0 comments on commit df2f102

Please sign in to comment.