UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MacApplication.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
7#include "Mac/MacWindow.h"
10
11class IModularFeature;
12
14{
16 : Event(nullptr)
17 , Window(nullptr)
18 , Type(0)
19 , LocationInWindow(FVector2D::ZeroVector)
20 , ModifierFlags(0)
21 , Timestamp(0.0)
22 , WindowNumber(0)
23 , Context(nullptr)
24 , Delta(FVector2D::ZeroVector)
25 , ScrollingDelta(FVector2D::ZeroVector)
26 , ButtonNumber(0)
27 , ClickCount(0)
31 , Character(0)
32 , CharCode(0)
35 , KeyCode(0)
36 , NotificationName(nullptr)
37 , DraggingPasteboard(nullptr)
38 {
39 }
40
66
68 {
70 if (Event)
71 {
72 [Event release];
73 }
74 if (Context)
75 {
77 }
79 {
81 }
83 {
85 }
86 }
87
88 // Using NSEvent on the game thread is unsafe, so we copy of all its properties and use them when processing the event.
89 // However, in some cases we need the original NSEvent (highlighting menus, resending unhandled key events), so we store it as well.
91
93
112
115};
116
132
137 : public GenericApplication
138 , public IInputInterface
139{
140public:
141
142 static FMacApplication* CreateMacApplication();
143
144public:
145
147
148public:
149
151#if WITH_ACCESSIBILITY
153
155 void OnVoiceoverEnabled();
156
158 void OnVoiceoverDisabled();
159#endif
160
161
162 virtual void PollGameDeviceState(const float TimeDelta) override;
163
164 virtual void PumpMessages(const float TimeDelta) override;
165
166 virtual void ProcessDeferredEvents(const float TimeDelta) override;
167
168 virtual TSharedRef<FGenericWindow> MakeWindow() override;
169
171
172 virtual FModifierKeysState GetModifierKeys() const override;
173
174 virtual bool IsCursorDirectlyOverSlateWindow() const override;
175
177
178 virtual void SetHighPrecisionMouseMode(const bool Enable, const TSharedPtr<FGenericWindow>& InWindow) override;
179
180 virtual bool IsUsingHighPrecisionMouseMode() const override { return bUsingHighPrecisionMouseInput; }
181
182 virtual bool IsUsingTrackpad() const override { return bUsingTrackpad; }
183
184 virtual bool IsGamepadAttached() const override;
185
186 virtual FPlatformRect GetWorkArea(const FPlatformRect& CurrentWindow) const override;
187
189
191
192 virtual ITextInputMethodSystem *GetTextInputMethodSystem() override { return TextInputMethodSystem.Get(); }
193
194#if WITH_EDITOR
195 virtual void SendAnalytics(IAnalyticsProvider* Provider) override;
196
198
199 void EndScopedModalEvent();
200#endif
201
202public:
203 void ResendLastEvent();
204
205 void CloseWindow(TSharedRef<FMacWindow> Window);
206
207 void DeferEvent(NSObject* Object);
208
209 bool IsProcessingDeferredEvents() const { return bIsProcessingDeferredEvents; }
210
211 TSharedPtr<FMacWindow> FindWindowByNSWindow(FCocoaWindow* WindowHandle);
212
213 void OnWindowWillResize(TSharedRef<FMacWindow> Window);
214
216 void InvalidateTextLayout(FCocoaWindow* Window);
217
218 void ResetModifierKeys() { ModifierKeysFlags = 0; }
219
220 bool IsWorkspaceSessionActive() const { return bIsWorkspaceSessionActive; }
221
222 void SystemModalMode(bool const bInSystemModalMode) { bSystemModalMode = bInSystemModalMode; }
223
225
226 FCriticalSection& GetWindowsArrayMutex() { return WindowsMutex; }
227
228 void OnCursorLock();
229
230 void IgnoreMouseMoveDelta() { FPlatformAtomics::InterlockedExchange(&bIgnoreMouseMoveDelta, 1); }
231
232 void SetIsRightClickEmulationEnabled(bool bEnabled) { bIsRightClickEmulationEnabled = bEnabled; }
233
234 void OnWindowDidResize(TSharedRef<FMacWindow> Window, bool bRestoreMouseCursorLocking = false);
235
236 void OnWindowChangedScreen(TSharedRef<FMacWindow> Window);
237
238 void OnWindowOrderedFront(TSharedRef<FMacWindow> Window);
239
240 void OnWindowActivationChanged(const TSharedRef<FMacWindow>& Window, const EWindowActivation ActivationType);
241
242 static void OnDisplayReconfiguration(CGDirectDisplayID Display, CGDisplayChangeSummaryFlags Flags, void* UserInfo);
243
244 inline bool IsDisplayReconfiguring() const { return bDisplayReconfiguring; }
245
246public:
247 virtual IInputInterface* GetInputInterface() override { return this; }
248
249 // IInputInterface overrides
250
251 virtual void SetForceFeedbackChannelValue (int32 ControllerId, FForceFeedbackChannelType ChannelType, float Value) override;
252 virtual void SetForceFeedbackChannelValues(int32 ControllerId, const FForceFeedbackValues &Values) override;
253 virtual void SetHapticFeedbackValues(int32 ControllerId, int32 Hand, const FHapticFeedbackValues& Values) override;
254 virtual void SetLightColor(int32 ControllerId, FColor Color) override { }
255 virtual void ResetLightColor(int32 ControllerId) override { }
256public:
257
258 static void UpdateScreensArray();
259
260 static FMacScreenRef FindScreenBySlatePosition(double X, double Y);
261
262 static FMacScreenRef FindScreenByCocoaPosition(double X, double Y);
263
264 static FVector2D ConvertSlatePositionToCocoa(double X, double Y);
265
266 static FVector2D ConvertCocoaPositionToSlate(double X, double Y);
267
268 static CGPoint ConvertSlatePositionToCGPoint(double X, double Y);
269
270 static FVector2D CalculateScreenOrigin(NSScreen* Screen);
271
272 static float GetPrimaryScreenBackingScaleFactor();
273
274 typedef void (*MenuBarShutdownFuncPtr)();
275 static MenuBarShutdownFuncPtr MenuBarShutdownFunc;
276
277 static unichar TranslateKeyCodeToUniCode(uint32 KeyCode, uint32 Modifier);
278
279private:
280
281 static NSEvent* HandleNSEvent(NSEvent* Event);
282#if WITH_EDITOR
283 static int32 MTContactCallback(void* Device, void* Data, int32 NumFingers, double TimeStamp, int32 Frame);
284#endif
285
287
288 void ProcessEvent(const FDeferredMacEvent& Event);
289 void ResendEvent(NSEvent* Event);
290
291 void ProcessMouseMovedEvent(const FDeferredMacEvent& Event, TSharedPtr<FMacWindow> EventWindow);
292 void ProcessMouseDownEvent(const FDeferredMacEvent& Event, TSharedPtr<FMacWindow> EventWindow);
293 void ProcessMouseUpEvent(const FDeferredMacEvent& Event, TSharedPtr<FMacWindow> EventWindow);
294 void ProcessScrollWheelEvent(const FDeferredMacEvent& Event, TSharedPtr<FMacWindow> EventWindow);
295 void ProcessGestureEvent(const FDeferredMacEvent& Event);
296 void ProcessKeyDownEvent(const FDeferredMacEvent& Event, TSharedPtr<FMacWindow> EventWindow);
297 void ProcessKeyUpEvent(const FDeferredMacEvent& Event);
298
299 void OnWindowDidMove(TSharedRef<FMacWindow> Window);
300 bool OnWindowDestroyed(TSharedRef<FMacWindow> DestroyedWindow);
301 void OnWindowActivated(TSharedRef<FMacWindow> Window);
302
303 void OnApplicationDidBecomeActive();
304 void OnApplicationWillResignActive();
305 void OnWindowsReordered();
306 void OnActiveSpaceDidChange();
307
308 void CacheKeyboardInputSource();
309
310 void ConditionallyUpdateModifierKeys(const FDeferredMacEvent& Event);
312
313 FCocoaWindow* FindEventWindow(NSEvent* CocoaEvent) const;
314 FCocoaWindow* FindSlateWindowUnderCursor() const;
315 EWindowZone::Type GetCurrentWindowZone(const TSharedRef<FMacWindow>& Window) const;
316 bool IsEdgeZone(EWindowZone::Type Zone) const;
317 bool IsPrintableKey(uint32 Character) const;
318 TCHAR ConvertChar(TCHAR Character) const;
319 TCHAR TranslateCharCode(TCHAR CharCode, uint32 KeyCode) const;
320
321 void CloseQueuedWindows();
322
324 void InvalidateTextLayouts();
325
326#if WITH_EDITOR
327 void RecordUsage(EGestureEvent Gesture);
328#else
329 void RecordUsage(EGestureEvent Gesture) { }
330#endif
331
332#if WITH_ACCESSIBILITY
334 #endif
335
336 void OnInputDeviceModuleRegistered(const FName& Type, IModularFeature* ModularFeature);
337
338private:
339
340 bool bUsingHighPrecisionMouseInput;
341
342 bool bUsingTrackpad;
343
344 EMouseButtons::Type LastPressedMouseButton;
345
346 FCriticalSection EventsMutex;
347 TArray<FDeferredMacEvent> DeferredEvents;
348
349 FCriticalSection WindowsMutex;
351
352 bool bIsProcessingDeferredEvents;
353
354 struct FSavedWindowOrderInfo
355 {
356 int32 WindowNumber;
357 int32 Level;
358 FSavedWindowOrderInfo(int32 InWindowNumber, int32 InLevel) : WindowNumber(InWindowNumber), Level(InLevel) {}
359 };
360 TArray<FSavedWindowOrderInfo> SavedWindowsOrder;
361
363
365 TArray<TSharedPtr<class IInputDevice>> ExternalInputDevices;
366 bool bHasLoadedInputPlugins;
367
368 FCocoaWindow* DraggedWindow;
369 FCocoaWindow* WindowUnderCursor;
370
372 uint32 SystemResolutionX;
373 uint32 SystemResolutionY;
374
375 bool bSystemModalMode;
376
378 uint32 ModifierKeysFlags;
379
381 NSUInteger CurrentModifierFlags;
382
383 bool bIsRightClickEmulationEnabled;
384 bool bEmulatingRightClick;
385
386 volatile int32 bIgnoreMouseMoveDelta;
387
388 FCriticalSection WindowsToCloseMutex;
389 TArray<FCocoaWindow*> CocoaWindowsToClose;
390 TArray<TSharedRef<FMacWindow>> SlateWindowsToClose;
391
392 TArray<FCocoaWindow*> WindowsRequiringTextInvalidation;
393
394 TSharedPtr<FMacTextInputMethodSystem> TextInputMethodSystem;
395
396 bool bIsWorkspaceSessionActive;
397
399 id AppActivationObserver;
400 id AppDeactivationObserver;
401 id WorkspaceActivationObserver;
402 id WorkspaceDeactivationObserver;
403 id WorkspaceActiveSpaceChangeObserver;
404
405 id EventMonitor;
406 id MouseMovedEventMonitor;
407
408#if WITH_EDITOR
411
414#endif
415
416 NSData* KeyBoardLayoutData;
417
418#if WITH_ACCESSIBILITY
421
423#endif
424
425 NSEvent* LastNativeEvent;
426
427 bool bDisplayReconfiguring;
428
429 friend class FMacWindow;
430};
431
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
DIRECTLINK_API Display
Definition DirectLinkLog.h:8
#define X(Name, Desc)
Definition FormatStringSan.h:47
EWindowActivation
Definition GenericApplicationMessageHandler.h:74
EGestureEvent
Definition GenericApplicationMessageHandler.h:138
EWindowTransparency
Definition GenericWindowDefinition.h:35
FForceFeedbackChannelType
Definition IInputInterface.h:17
APPLICATIONCORE_API FMacApplication * MacApplication
Definition MacApplication.cpp:34
TSharedRef< FMacScreen, ESPMode::ThreadSafe > FMacScreenRef
Definition MacApplication.h:131
EMacModifierKeys
Definition MacPlatformMisc.h:248
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition CocoaWindow.cpp:20
Definition MacApplication.h:139
virtual IInputInterface * GetInputInterface() override
Definition MacApplication.h:247
bool IsProcessingDeferredEvents() const
Definition MacApplication.h:209
virtual bool IsUsingTrackpad() const override
Definition MacApplication.h:182
virtual void ResetLightColor(int32 ControllerId) override
Definition MacApplication.h:255
static MenuBarShutdownFuncPtr MenuBarShutdownFunc
Definition MacApplication.h:275
const TArray< TSharedRef< FMacWindow > > & GetAllWindows() const
Definition MacApplication.h:224
virtual void SetLightColor(int32 ControllerId, FColor Color) override
Definition MacApplication.h:254
void SetIsRightClickEmulationEnabled(bool bEnabled)
Definition MacApplication.h:232
virtual EWindowTitleAlignment::Type GetWindowTitleAlignment() const override
Definition MacApplication.h:188
virtual EWindowTransparency GetWindowTransparencySupport() const override
Definition MacApplication.h:190
bool IsDisplayReconfiguring() const
Definition MacApplication.h:244
FCriticalSection & GetWindowsArrayMutex()
Definition MacApplication.h:226
void IgnoreMouseMoveDelta()
Definition MacApplication.h:230
void SystemModalMode(bool const bInSystemModalMode)
Definition MacApplication.h:222
void ResetModifierKeys()
Definition MacApplication.h:218
bool IsWorkspaceSessionActive() const
Definition MacApplication.h:220
virtual bool IsUsingHighPrecisionMouseMode() const override
Definition MacApplication.h:180
virtual ITextInputMethodSystem * GetTextInputMethodSystem() override
Definition MacApplication.h:192
Definition MacWindow.h:14
Definition GenericApplication.h:75
Definition NameTypes.h:617
Definition GenericApplication.h:437
virtual void InitializeWindow(const TSharedRef< FGenericWindow > &Window, const TSharedRef< FGenericWindowDefinition > &InDefinition, const TSharedPtr< FGenericWindow > &InParent, const bool bShowImmediately)
Definition GenericApplication.h:465
virtual void SetMessageHandler(const TSharedRef< FGenericApplicationMessageHandler > &InMessageHandler)
Definition GenericApplication.h:446
virtual FPlatformRect GetWorkArea(const FPlatformRect &CurrentWindow) const
Definition GenericApplication.h:495
virtual bool IsGamepadAttached() const
Definition GenericApplication.h:489
virtual void PollGameDeviceState(const float TimeDelta)
Definition GenericApplication.h:455
virtual void ProcessDeferredEvents(const float TimeDelta)
Definition GenericApplication.h:459
virtual void PumpMessages(const float TimeDelta)
Definition GenericApplication.h:457
virtual bool IsCursorDirectlyOverSlateWindow() const
Definition GenericApplication.h:474
virtual FModifierKeysState GetModifierKeys() const
Definition GenericApplication.h:471
virtual void SendAnalytics(IAnalyticsProvider *Provider)
Definition GenericApplication.h:545
virtual void SetHighPrecisionMouseMode(const bool Enable, const TSharedPtr< FGenericWindow > &InWindow)
Definition GenericApplication.h:481
virtual TSharedPtr< FGenericWindow > GetWindowUnderCursor()
Definition GenericApplication.h:477
virtual TSharedRef< FGenericWindow > MakeWindow()
Definition GenericApplication.h:463
Definition IAnalyticsProvider.h:52
Definition IInputInterface.h:309
virtual void SetForceFeedbackChannelValues(int32 ControllerId, const FForceFeedbackValues &Values)=0
virtual void SetHapticFeedbackValues(int32 ControllerId, int32 Hand, const FHapticFeedbackValues &Values)
Definition IInputInterface.h:342
virtual void SetForceFeedbackChannelValue(int32 ControllerId, FForceFeedbackChannelType ChannelType, float Value)=0
Definition IModularFeature.h:12
Definition ITextInputMethodSystem.h:169
Definition Array.h:670
Definition SharedPointer.h:692
Definition SharedPointer.h:153
Type
Definition GenericApplicationMessageHandler.h:18
Type
Definition GenericApplication.h:422
@ Center
Definition GenericApplication.h:426
Type
Definition GenericApplicationMessageHandler.h:87
Definition MinimalWindowsApi.h:62
@ false
Definition radaudio_common.h:23
Definition Color.h:486
Definition MacApplication.h:14
TCHAR CharCode
Definition MacApplication.h:108
NSEventPhase MomentumPhase
Definition MacApplication.h:105
bool IsDirectionInvertedFromDevice
Definition MacApplication.h:106
FDeferredMacEvent()
Definition MacApplication.h:15
FVector2D LocationInWindow
Definition MacApplication.h:95
TCHAR Character
Definition MacApplication.h:107
FDeferredMacEvent(const FDeferredMacEvent &Other)
Definition MacApplication.h:41
FVector2D Delta
Definition MacApplication.h:100
~FDeferredMacEvent()
Definition MacApplication.h:67
NSGraphicsContext * Context
Definition MacApplication.h:99
FCocoaWindow * Window
Definition MacApplication.h:92
NSEventPhase Phase
Definition MacApplication.h:104
int32 Type
Definition MacApplication.h:94
NSPasteboard * DraggingPasteboard
Definition MacApplication.h:114
int32 WindowNumber
Definition MacApplication.h:98
bool IsRepeat
Definition MacApplication.h:109
uint32 ModifierFlags
Definition MacApplication.h:96
int32 ClickCount
Definition MacApplication.h:103
NSEvent * Event
Definition MacApplication.h:90
uint32 KeyCode
Definition MacApplication.h:111
FVector2D ScrollingDelta
Definition MacApplication.h:101
int32 ButtonNumber
Definition MacApplication.h:102
NSTimeInterval Timestamp
Definition MacApplication.h:97
NSString * NotificationName
Definition MacApplication.h:113
bool IsPrintable
Definition MacApplication.h:110
Definition IInputInterface.h:26
Definition IInputInterface.h:70
Definition MacApplication.h:118
FMacScreen(NSScreen *InScreen)
Definition MacApplication.h:126
NSEdgeInsets SafeAreaInsets
Definition MacApplication.h:124
NSRect Frame
Definition MacApplication.h:120
NSRect VisibleFramePixels
Definition MacApplication.h:123
~FMacScreen()
Definition MacApplication.h:129
NSRect FramePixels
Definition MacApplication.h:122
NSRect VisibleFrame
Definition MacApplication.h:121
NSScreen * Screen
Definition MacApplication.h:119
Definition GenericApplication.h:320