Reputation: 1835
I have this message loop:
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];
}
I want to filter all NSEvents that modifying a window, for example move, resize, order out e.t.c. I've trying looking for the type in Apple documentation but w/o success. Any help? Thanks!
Upvotes: 0
Views: 313
Reputation: 1835
The event type I was looking for is 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];
}
Upvotes: 0
Reputation: 90531
Filtering events is not the right approach for this.
If you don't want to allow the user to move a window, set the window's movable
property to false.
If you don't want to allow the user to resize the window, set the window's styleMask
to not include NSResizableWindowMask
. Or, possibly, set its contentMinSize
and contentMaxSize
to its current size.
No event can directly order a window out. The window's delegate gets to decide whether or not the close button actually closes the window, by implementing -windowShouldClose:
. If you don't want the close button to be enabled at all, set the styleMask
to not include NSClosableWindowMask
.
Upvotes: 2