Skip to content

Commit

Permalink
fix: Calling [NSCurser set] unconditionally is expensive
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartcarnie committed Nov 29, 2021
1 parent f56bf5f commit 4fdbf46
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions backends/imgui_impl_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ - (void)keyDown:(NSEvent *)event {
- (void)insertText:(id)aString replacementRange:(NSRange)replacementRange
{
ImGuiIO& io = ImGui::GetIO();

NSString *characters;
if ([aString isKindOfClass:[NSAttributedString class]])
characters = [aString string];
else
characters = (NSString *)aString;

io.AddInputCharactersUTF8(characters.UTF8String);
}

Expand Down Expand Up @@ -271,7 +271,7 @@ bool ImGui_ImplOSX_Init(NSView *view)
selector:@selector(onApplicationBecomeInactive:)
name:NSApplicationDidResignActiveNotification
object:nil];

g_KeyEventResponder = [[KeyEventResponder alloc] initWithFrame:NSZeroRect];
[view addSubview:g_KeyEventResponder];

Expand Down Expand Up @@ -309,8 +309,13 @@ static void ImGui_ImplOSX_UpdateMouseCursorAndButtons()
}
else
{
NSCursor *desired = g_MouseCursors[imgui_cursor] ?: g_MouseCursors[ImGuiMouseCursor_Arrow];
// Show OS mouse cursor
[g_MouseCursors[g_MouseCursors[imgui_cursor] ? imgui_cursor : ImGuiMouseCursor_Arrow] set];
if (desired != NSCursor.currentCursor)
{
[desired set];
}
// [g_MouseCursors[g_MouseCursors[imgui_cursor] ? imgui_cursor : ImGuiMouseCursor_Arrow] set];
if (g_MouseCursorHidden)
{
g_MouseCursorHidden = false;
Expand Down

0 comments on commit 4fdbf46

Please sign in to comment.