Events when dock is showing or hiding

戏子无情 提交于 2020-01-23 11:56:38

问题


How can I get events when the Dock is showing or hiding?


回答1:


You can get a notification if the dock is visible or not using Carbon. I do not know of any way to do it in Cocoa.

(I haven't tested this; it's 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 wherever you want to start listening for the notification:

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


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



来源:https://stackoverflow.com/questions/6135265/events-when-dock-is-showing-or-hiding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!