Events when the dock is displayed or hidden

How can I receive events when the Dock shows or hides?

+2
source share
1 answer

You may receive a notification if the dock is visible or not using Carbon. I do not know how to do this in Cocoa.

(I have not tested this, this is from the code here )

Create your callback method:

#import <Carbon/Carbon.h>

static const EventTypeSpec appEvents[] = {
    { kEventClassApplication, kEventAppSystemUIModeChanged }
};

OSStatus DockChangedHandler(EventHandlerCallRef inCallRef, EventRef event, void *userData) {
    OSStatus status = eventNotHandledErr;
    switch(GetEventClass(event)) {
        case kEventClassApplication: {
            SystemUIMode *outMode;
            SystemUIOptions *outOptions;
            GetSystemUIMode(outMode, outOptions);
            status = noErr;
        }
            break;

        default: 
            return;

    }

    /*Insert whatever you want to do when you're notified of a dock change*/

    return status;
}

And then put this where you want to start listening to the notification:

    InstallApplicationEventHandler(NewEventHandlerUPP(DockChangedHandler), GetEventTypeCount(appEvents), appEvents, 0, NULL);


Additional information: http://developer.apple.com/library/mac/#technotes/tn2002/tn2062.html

+1
source

All Articles