Skip to content

Commit

Permalink
Examples: example_apple_opengl2: Fix keys remaining stuck in pressed …
Browse files Browse the repository at this point in the history
…state when using shortcuts with CMD. (ocornut#4253)

Fix follows event capture scheme of example_apple_metal, where this issue is not present.
  • Loading branch information
rokups committed Jun 25, 2021
1 parent e534c56 commit 1a41fab
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions examples/example_apple_opengl2/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ -(void)dealloc
}

// Forward Mouse/Keyboard events to Dear ImGui OSX backend.
-(void)keyUp:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, self); }
-(void)keyDown:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, self); }
-(void)flagsChanged:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, self); }
-(void)mouseDown:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, self); }
-(void)rightMouseDown:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, self); }
-(void)otherMouseDown:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, self); }
Expand All @@ -155,7 +152,6 @@ -(void)otherMouseMoved:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, s
-(void)mouseDragged:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, self); }
-(void)rightMouseDragged:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, self); }
-(void)otherMouseDragged:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, self); }
-(void)scrollWheel:(NSEvent *)event { ImGui_ImplOSX_HandleEvent(event, self); }

@end

Expand Down Expand Up @@ -243,6 +239,15 @@ -(void)applicationDidFinishLaunching:(NSNotification *)aNotification
if ([view openGLContext] == nil)
NSLog(@"No OpenGL Context!");

// Some events do not raise callbacks of ImGuiExampleView in some circumstances (for example when CMD key is held down).
// This monitor taps into global event stream and captures these events.
NSEventMask eventMask = NSEventMaskKeyDown | NSEventMaskKeyUp | NSEventMaskFlagsChanged | NSEventTypeScrollWheel;
[NSEvent addLocalMonitorForEventsMatchingMask:eventMask handler:^NSEvent * _Nullable(NSEvent *event)
{
ImGui_ImplOSX_HandleEvent(event, view);
return event;
}];

// Setup Dear ImGui context
// FIXME: This example doesn't have proper cleanup...
IMGUI_CHECKVERSION();
Expand Down

0 comments on commit 1a41fab

Please sign in to comment.