@@ -592,15 +592,6 @@ extension MenuBarItemManager {
592
592
return CGPoint ( x: currentFrame. midX, y: currentFrame. midY)
593
593
}
594
594
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
-
604
595
/// Returns a Boolean value that indicates whether the given item is in the
605
596
/// correct position for the given destination.
606
597
///
@@ -920,14 +911,12 @@ extension MenuBarItemManager {
920
911
type: . move( . leftMouseDown) ,
921
912
location: CGPoint ( x: currentFrame. midX, y: currentFrame. midY) ,
922
913
item: item,
923
- pid: item. ownerPID,
924
914
source: source
925
915
) ,
926
916
let mouseUpEvent = CGEvent . menuBarItemEvent (
927
917
type: . move( . leftMouseUp) ,
928
918
location: CGPoint ( x: currentFrame. midX, y: currentFrame. midY) ,
929
919
item: item,
930
- pid: item. ownerPID,
931
920
source: source
932
921
)
933
922
else {
@@ -970,28 +959,24 @@ extension MenuBarItemManager {
970
959
let startPoint = CGPoint ( x: 20_000 , y: 20_000 )
971
960
let endPoint = try getEndPoint ( for: destination)
972
961
let fallbackPoint = try getFallbackPoint ( for: item)
973
- let targetItem = getTargetItem ( for: destination)
974
962
975
963
guard
976
964
let mouseDownEvent = CGEvent . menuBarItemEvent (
977
965
type: . move( . leftMouseDown) ,
978
966
location: startPoint,
979
967
item: item,
980
- pid: item. ownerPID,
981
968
source: source
982
969
) ,
983
970
let mouseUpEvent = CGEvent . menuBarItemEvent (
984
971
type: . move( . leftMouseUp) ,
985
972
location: endPoint,
986
- item: targetItem,
987
- pid: item. ownerPID,
973
+ item: nil ,
988
974
source: source
989
975
) ,
990
976
let fallbackEvent = CGEvent . menuBarItemEvent (
991
977
type: . move( . leftMouseUp) ,
992
978
location: fallbackPoint,
993
- item: item,
994
- pid: item. ownerPID,
979
+ item: nil ,
995
980
source: source
996
981
)
997
982
else {
@@ -1155,21 +1140,18 @@ extension MenuBarItemManager {
1155
1140
type: . click( buttonStates. down) ,
1156
1141
location: clickPoint,
1157
1142
item: item,
1158
- pid: item. ownerPID,
1159
1143
source: source
1160
1144
) ,
1161
1145
let mouseUpEvent = CGEvent . menuBarItemEvent (
1162
1146
type: . click( buttonStates. up) ,
1163
1147
location: clickPoint,
1164
1148
item: item,
1165
- pid: item. ownerPID,
1166
1149
source: source
1167
1150
) ,
1168
1151
let fallbackEvent = CGEvent . menuBarItemEvent (
1169
1152
type: . click( buttonStates. up) ,
1170
1153
location: clickPoint,
1171
1154
item: item,
1172
- pid: item. ownerPID,
1173
1155
source: source
1174
1156
)
1175
1157
else {
@@ -1595,10 +1577,9 @@ private extension CGEvent {
1595
1577
/// - Parameters:
1596
1578
/// - type: The type of the event.
1597
1579
/// - 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 ? {
1602
1583
let mouseType = type. cgEventType
1603
1584
let mouseButton = type. mouseButton
1604
1585
@@ -1608,14 +1589,10 @@ private extension CGEvent {
1608
1589
1609
1590
event. flags = type. cgEventFlags
1610
1591
1611
- let targetPID = Int64 ( pid)
1612
1592
let userData = Int64 ( truncatingIfNeeded: Int ( bitPattern: ObjectIdentifier ( event) ) )
1613
- let windowID = Int64 ( item. windowID)
1593
+ let windowID = Int64 ( item? . windowID ?? kCGNullWindowID )
1614
1594
1615
- event. setIntegerValueField ( . eventTargetUnixProcessID, value: targetPID)
1616
1595
event. setIntegerValueField ( . eventSourceUserData, value: userData)
1617
- event. setIntegerValueField ( . mouseEventWindowUnderMousePointer, value: windowID)
1618
- event. setIntegerValueField ( . mouseEventWindowUnderMousePointerThatCanHandleThisEvent, value: windowID)
1619
1596
event. setIntegerValueField ( . windowID, value: windowID)
1620
1597
1621
1598
if case . click = type {
0 commit comments