Mac OS X Dock: How to programmatically maximize my application with the application's main icon, and not the minimized icon?

StackOverflow https://stackoverflow.com/questions/18941909

  •  29-06-2022
  •  | 
  •  

Question

According to Mac Dock documentation: "The Dock keeps applications on its left side, while Stacks and minimized windows are kept on its right. If you look closely, you'll see a vertical separator line that separates them."

Meaning, once the application is minimized, you have a NEW dock icon in the right side, and you need to click on it in order to maximize your application.

However, applications like Chrome and Finder behave differently: if you click on the the LEFT icon (the "main" application's icon), it will also maximize the application!

I have created my own mac application, and I'd like to make it behave like Chrome: meaning once it is minimized, if you click on either the left or right dock icons, it will maximize. How can I do that programmatically?

[I am attaching a dock screenshot. You can see both Chrome "main" icon and "minimized" icon next to it. Both icons will respond and will maximize the window. attaching However other applications (like TextEdit, and also the one I programmed in XCode): only the minimized icon maximizes them. The "main" icon does nothing.]

How can I make both icons maximize my application programmatically?

Thanks a million!

Nili

Était-ce utile?

La solution

Need to implement applicationShouldHandleReopen in order to open minimized windows from the "main" icon

- (BOOL)applicationShouldHandleReopen:(NSApplication *) __unused theApplication hasVisibleWindows:(BOOL)flag
{
    if (!flag){
        [[self window] makeKeyAndOrderFront:self];
    }
    return YES;
}

Autres conseils

Clicking on the Dock icon calls:

- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag

Reopen your windows in this message handler.

It is send to the Application Delegate and is part of the NSApplicationDelegate protocol.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top