Skip to content

Commit bd4ff51

Browse files
committed
Update MenuBarItemManager.swift
1 parent ee38def commit bd4ff51

File tree

1 file changed

+6
-29
lines changed

1 file changed

+6
-29
lines changed

Diff for: Ice/MenuBar/MenuBarItems/MenuBarItemManager.swift

+6-29
Original file line numberDiff line numberDiff line change
@@ -592,15 +592,6 @@ extension MenuBarItemManager {
592592
return CGPoint(x: currentFrame.midX, y: currentFrame.midY)
593593
}
594594

595-
/// Returns the target item for the given destination.
596-
///
597-
/// - Parameter destination: The destination to get the target item from.
598-
private func getTargetItem(for destination: MoveDestination) -> MenuBarItem {
599-
switch destination {
600-
case .leftOfItem(let targetItem), .rightOfItem(let targetItem): targetItem
601-
}
602-
}
603-
604595
/// Returns a Boolean value that indicates whether the given item is in the
605596
/// correct position for the given destination.
606597
///
@@ -920,14 +911,12 @@ extension MenuBarItemManager {
920911
type: .move(.leftMouseDown),
921912
location: CGPoint(x: currentFrame.midX, y: currentFrame.midY),
922913
item: item,
923-
pid: item.ownerPID,
924914
source: source
925915
),
926916
let mouseUpEvent = CGEvent.menuBarItemEvent(
927917
type: .move(.leftMouseUp),
928918
location: CGPoint(x: currentFrame.midX, y: currentFrame.midY),
929919
item: item,
930-
pid: item.ownerPID,
931920
source: source
932921
)
933922
else {
@@ -970,28 +959,24 @@ extension MenuBarItemManager {
970959
let startPoint = CGPoint(x: 20_000, y: 20_000)
971960
let endPoint = try getEndPoint(for: destination)
972961
let fallbackPoint = try getFallbackPoint(for: item)
973-
let targetItem = getTargetItem(for: destination)
974962

975963
guard
976964
let mouseDownEvent = CGEvent.menuBarItemEvent(
977965
type: .move(.leftMouseDown),
978966
location: startPoint,
979967
item: item,
980-
pid: item.ownerPID,
981968
source: source
982969
),
983970
let mouseUpEvent = CGEvent.menuBarItemEvent(
984971
type: .move(.leftMouseUp),
985972
location: endPoint,
986-
item: targetItem,
987-
pid: item.ownerPID,
973+
item: nil,
988974
source: source
989975
),
990976
let fallbackEvent = CGEvent.menuBarItemEvent(
991977
type: .move(.leftMouseUp),
992978
location: fallbackPoint,
993-
item: item,
994-
pid: item.ownerPID,
979+
item: nil,
995980
source: source
996981
)
997982
else {
@@ -1155,21 +1140,18 @@ extension MenuBarItemManager {
11551140
type: .click(buttonStates.down),
11561141
location: clickPoint,
11571142
item: item,
1158-
pid: item.ownerPID,
11591143
source: source
11601144
),
11611145
let mouseUpEvent = CGEvent.menuBarItemEvent(
11621146
type: .click(buttonStates.up),
11631147
location: clickPoint,
11641148
item: item,
1165-
pid: item.ownerPID,
11661149
source: source
11671150
),
11681151
let fallbackEvent = CGEvent.menuBarItemEvent(
11691152
type: .click(buttonStates.up),
11701153
location: clickPoint,
11711154
item: item,
1172-
pid: item.ownerPID,
11731155
source: source
11741156
)
11751157
else {
@@ -1595,10 +1577,9 @@ private extension CGEvent {
15951577
/// - Parameters:
15961578
/// - type: The type of the event.
15971579
/// - location: The location of the event. Does not need to be within the bounds of the item.
1598-
/// - item: The target item of the event.
1599-
/// - pid: The target process identifier of the event. Does not need to be the item's `ownerPID`.
1600-
/// - source: The source of the event.
1601-
class func menuBarItemEvent(type: MenuBarItemEventType, location: CGPoint, item: MenuBarItem, pid: pid_t, source: CGEventSource) -> CGEvent? {
1580+
/// - item: The target item of the event, used to set the event's window. Can be `nil`.
1581+
/// - source: The event source.
1582+
class func menuBarItemEvent(type: MenuBarItemEventType, location: CGPoint, item: MenuBarItem?, source: CGEventSource) -> CGEvent? {
16021583
let mouseType = type.cgEventType
16031584
let mouseButton = type.mouseButton
16041585

@@ -1608,14 +1589,10 @@ private extension CGEvent {
16081589

16091590
event.flags = type.cgEventFlags
16101591

1611-
let targetPID = Int64(pid)
16121592
let userData = Int64(truncatingIfNeeded: Int(bitPattern: ObjectIdentifier(event)))
1613-
let windowID = Int64(item.windowID)
1593+
let windowID = Int64(item?.windowID ?? kCGNullWindowID)
16141594

1615-
event.setIntegerValueField(.eventTargetUnixProcessID, value: targetPID)
16161595
event.setIntegerValueField(.eventSourceUserData, value: userData)
1617-
event.setIntegerValueField(.mouseEventWindowUnderMousePointer, value: windowID)
1618-
event.setIntegerValueField(.mouseEventWindowUnderMousePointerThatCanHandleThisEvent, value: windowID)
16191596
event.setIntegerValueField(.windowID, value: windowID)
16201597

16211598
if case .click = type {

0 commit comments

Comments
 (0)