Skip to content

Commit 4fdbf46

Browse files
committed
fix: Calling [NSCurser set] unconditionally is expensive
1 parent f56bf5f commit 4fdbf46

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

backends/imgui_impl_osx.mm

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ - (void)keyDown:(NSEvent *)event {
9696
- (void)insertText:(id)aString replacementRange:(NSRange)replacementRange
9797
{
9898
ImGuiIO& io = ImGui::GetIO();
99-
99+
100100
NSString *characters;
101101
if ([aString isKindOfClass:[NSAttributedString class]])
102102
characters = [aString string];
103103
else
104104
characters = (NSString *)aString;
105-
105+
106106
io.AddInputCharactersUTF8(characters.UTF8String);
107107
}
108108

@@ -271,7 +271,7 @@ bool ImGui_ImplOSX_Init(NSView *view)
271271
selector:@selector(onApplicationBecomeInactive:)
272272
name:NSApplicationDidResignActiveNotification
273273
object:nil];
274-
274+
275275
g_KeyEventResponder = [[KeyEventResponder alloc] initWithFrame:NSZeroRect];
276276
[view addSubview:g_KeyEventResponder];
277277

@@ -309,8 +309,13 @@ static void ImGui_ImplOSX_UpdateMouseCursorAndButtons()
309309
}
310310
else
311311
{
312+
NSCursor *desired = g_MouseCursors[imgui_cursor] ?: g_MouseCursors[ImGuiMouseCursor_Arrow];
312313
// Show OS mouse cursor
313-
[g_MouseCursors[g_MouseCursors[imgui_cursor] ? imgui_cursor : ImGuiMouseCursor_Arrow] set];
314+
if (desired != NSCursor.currentCursor)
315+
{
316+
[desired set];
317+
}
318+
// [g_MouseCursors[g_MouseCursors[imgui_cursor] ? imgui_cursor : ImGuiMouseCursor_Arrow] set];
314319
if (g_MouseCursorHidden)
315320
{
316321
g_MouseCursorHidden = false;

0 commit comments

Comments
 (0)