Examples: Apple: standardize activation and bringing to front.

+ fix warnings.

# Conflicts:
#	backends/imgui_impl_metal4.mm
This commit is contained in:
ocornut 2026-11-04 18:20:12 +01:00
parent b2298afa71
commit 8c8b8fc266
5 changed files with 26 additions and 24 deletions

View File

@ -139,7 +139,7 @@ void ImGui_ImplMetal4_NewFrame(MTL4RenderPassDescriptor* renderPassDescriptor, i
{
ImGui_ImplMetal4_Data* bd = ImGui_ImplMetal4_GetBackendData();
IM_ASSERT(bd != nil && "Context or backend not initialized! Did you call ImGui_ImplMetal4_Init()?");
IM_ASSERT(frameInFlightIndex < bd->SharedMetalContext.framesInFlight && "frameInFlightIndex out of range! See framesInFlight passed to ImGui_ImplMetal4_Init().");
IM_ASSERT(frameInFlightIndex < (int)bd->SharedMetalContext.framesInFlight && "frameInFlightIndex out of range! See framesInFlight passed to ImGui_ImplMetal4_Init().");
#ifdef IMGUI_IMPL_METAL_CPP
bd->SharedMetalContext.framebufferDescriptor = [[[FramebufferDescriptor alloc] initWithRenderPassDescriptor:renderPassDescriptor]autorelease];
#else
@ -479,7 +479,7 @@ bool ImGui_ImplMetal4_Init(id<MTLDevice> device, id<MTL4CommandQueue> commandQue
bd->SharedMetalContext.commandQueue = commandQueue;
bd->SharedMetalContext.framesInFlight = (NSUInteger)framesInFlight;
NSMutableArray<NSMutableArray<MetalBuffer*>*>* bufferCaches = [NSMutableArray array];
for (NSUInteger i = 0; i < framesInFlight; i++)
for (NSUInteger i = 0; i < (NSUInteger)framesInFlight; i++)
[bufferCaches addObject:[NSMutableArray array]];
bd->SharedMetalContext.bufferCaches = bufferCaches;
return true;

View File

@ -111,7 +111,6 @@
#if TARGET_OS_OSX
ImGui_ImplOSX_Init(self.view);
[NSApp activateIgnoringOtherApps:YES];
#endif
}
@ -285,6 +284,8 @@
[appMenuItem setSubmenu:appMenu];
[mainMenuBar addItem:appMenuItem];
[NSApp setMainMenu:mainMenuBar];
[NSApp activateIgnoringOtherApps:YES];
}
-(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
@ -349,7 +350,6 @@ int main(int, const char**)
AppDelegate *appDelegate = [[AppDelegate alloc] init]; // creates window
[NSApp setDelegate:appDelegate];
[NSApp activateIgnoringOtherApps:YES];
[NSApp run];
}
return 0;

View File

@ -117,7 +117,6 @@
#if TARGET_OS_OSX
ImGui_ImplOSX_Init(self.view);
[NSApp activateIgnoringOtherApps:YES];
#endif
}
@ -301,6 +300,8 @@
[appMenuItem setSubmenu:appMenu];
[mainMenuBar addItem:appMenuItem];
[NSApp setMainMenu:mainMenuBar];
[NSApp activateIgnoringOtherApps:YES];
}
-(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
@ -365,7 +366,6 @@ int main(int, const char**)
AppDelegate *appDelegate = [[AppDelegate alloc] init]; // creates window
[NSApp setDelegate:appDelegate];
[NSApp activateIgnoringOtherApps:YES];
[NSApp run];
}
return 0;

View File

@ -209,10 +209,6 @@
-(void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Make the application a foreground application (else it won't receive keyboard events)
ProcessSerialNumber psn = {0, kCurrentProcess};
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
// Menu
[self setupMenu];
@ -236,6 +232,8 @@
NSLog(@"No OpenGL Context!");
[view initialize];
[NSApp activateIgnoringOtherApps:YES];
}
@end
@ -244,14 +242,17 @@
// Application main() function
//-----------------------------------------------------------------------------------
int main(int argc, const char* argv[])
int main(int, const char**)
{
@autoreleasepool
{
NSApp = [NSApplication sharedApplication];
AppDelegate* delegate = [[AppDelegate alloc] init];
[[NSApplication sharedApplication] setDelegate:delegate];
[NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
AppDelegate* appDelegate = [[AppDelegate alloc] init];
[NSApp setDelegate:appDelegate];
[NSApp run];
}
return NSApplicationMain(argc, argv);
return 0;
}

View File

@ -209,10 +209,6 @@
-(void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Make the application a foreground application (else it won't receive keyboard events)
ProcessSerialNumber psn = {0, kCurrentProcess};
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
// Menu
[self setupMenu];
@ -237,6 +233,8 @@
NSLog(@"No OpenGL Context!");
[view initialize];
[NSApp activateIgnoringOtherApps:YES];
}
@end
@ -245,14 +243,17 @@
// Application main() function
//-----------------------------------------------------------------------------------
int main(int argc, const char* argv[])
int main(int, const char**)
{
@autoreleasepool
{
NSApp = [NSApplication sharedApplication];
AppDelegate* delegate = [[AppDelegate alloc] init];
[[NSApplication sharedApplication] setDelegate:delegate];
[NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
AppDelegate* appDelegate = [[AppDelegate alloc] init];
[NSApp setDelegate:appDelegate];
[NSApp run];
}
return NSApplicationMain(argc, argv);
return 0;
}