过滤 window 修改事件

Filtering window modifyning events

我有这个消息循环:

while (!shutdown_now_) 
    {
        NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
        NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask
                                            untilDate:[NSDate distantFuture]
                                               inMode:NSDefaultRunLoopMode
                                              dequeue:YES];
        if (event) [NSApp sendEvent:event];
        // If modifying window event, do something!!! 
        [pool drain];
    } 

我想过滤所有修改 window 的 NSEvent,例如移动、调整大小、排序 e.t.c。我试图在 Apple documentation 中寻找类型,但 w/o 成功了。有什么帮助吗?谢谢!

过滤事件不是解决此问题的正确方法。

如果您不想让用户移动 window,请将 window 的 movable 属性 设置为 false。

如果您不想让用户调整 window 的大小,请将 window 的 styleMask 设置为不包括 NSResizableWindowMask。或者,可能,将其 contentMinSizecontentMaxSize 设置为其当前大小。

没有事件可以直接命令一个window出来。 window 的委托通过实施 -windowShouldClose: 来决定关闭按钮是否实际关闭 window。如果您根本不想启用关闭按钮,请将 styleMask 设置为不包括 NSClosableWindowMask.

我要查找的事件类型是 NSAppKitDefined:

while (!shutdown_now_) 
    {
        NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
        NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask
                                            untilDate:[NSDate distantFuture]
                                               inMode:NSDefaultRunLoopMode
                                              dequeue:YES];
        if (event.type == NSAppKitDefined)
        {
            NSLog(@"NSAppKitDefinedEvent with subtype: %d", event.subtype);
        }
        if (event) [NSApp sendEvent:event];
        [pool drain];
    }