diff options
author | Kevin Walzer <kw@codebykevin.com> | 2015-03-21 00:57:14 (GMT) |
---|---|---|
committer | Kevin Walzer <kw@codebykevin.com> | 2015-03-21 00:57:14 (GMT) |
commit | 4f6c1ad7943f8c595d9d539a6c6c33c96832554b (patch) | |
tree | 28a13f3c5fdd1724d3f1e4cce22305e2c775a2bd /macosx/tkMacOSXEvent.c | |
parent | c76fcabd431431b1acfc9d4113781872fcc9fe9b (diff) | |
download | tk-4f6c1ad7943f8c595d9d539a6c6c33c96832554b.zip tk-4f6c1ad7943f8c595d9d539a6c6c33c96832554b.tar.gz tk-4f6c1ad7943f8c595d9d539a6c6c33c96832554b.tar.bz2 |
Cleanup and improvement of tracking of native windows in Cocoa; thanks to Marc Culler for patch
Diffstat (limited to 'macosx/tkMacOSXEvent.c')
-rw-r--r-- | macosx/tkMacOSXEvent.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/macosx/tkMacOSXEvent.c b/macosx/tkMacOSXEvent.c index ea262ff..365dc9b 100644 --- a/macosx/tkMacOSXEvent.c +++ b/macosx/tkMacOSXEvent.c @@ -31,18 +31,19 @@ enum { NSEvent *processedEvent = theEvent; NSEventType type = [theEvent type]; NSInteger subtype; - NSUInteger flags; switch ((NSInteger)type) { case NSAppKitDefined: subtype = [theEvent subtype]; switch (subtype) { + /* Ignored at the moment. */ case NSApplicationActivatedEventType: break; case NSApplicationDeactivatedEventType: break; case NSWindowExposedEventType: + break; case NSScreenChangedEventType: break; case NSWindowMovedEventType: @@ -53,13 +54,12 @@ enum { default: break; } - break; + break; /* AppkitEvent. Return theEvent */ case NSKeyUp: case NSKeyDown: case NSFlagsChanged: - flags = [theEvent modifierFlags]; processedEvent = [self tkProcessKeyEvent:theEvent]; - break; + break; /* Key event. Return the processed event. */ case NSLeftMouseDown: case NSLeftMouseUp: case NSRightMouseDown: @@ -76,7 +76,7 @@ enum { case NSTabletPoint: case NSTabletProximity: processedEvent = [self tkProcessMouseEvent:theEvent]; - break; + break; /* Mouse event. Return the processed event. */ #if 0 case NSSystemDefined: subtype = [theEvent subtype]; @@ -100,7 +100,7 @@ enum { #endif default: - break; + break; /* return theEvent */ } return processedEvent; } @@ -113,14 +113,14 @@ enum { * * TkMacOSXFlushWindows -- * - * This routine flushes all the windows of the application. It is + * This routine flushes all the visible windows of the application. It is * called by XSync(). * * Results: * None. * * Side effects: - * Flushes all Carbon windows + * Flushes all visible Cocoa windows * *---------------------------------------------------------------------- */ @@ -128,22 +128,23 @@ enum { MODULE_SCOPE void TkMacOSXFlushWindows(void) { - NSInteger windowCount; - NSInteger *windowNumbers; + /* This can be called from outside the Appkit event loop, + * so it needs its own AutoreleasePool. + */ + NSAutoreleasePool *pool = [NSAutoreleasePool new]; + NSArray *macWindows = [NSApp orderedWindows]; + NSInteger windowCount = [macWindows count]; - NSCountWindows(&windowCount); if(windowCount) { - windowNumbers = ckalloc(windowCount * sizeof(NSInteger)); - NSWindowList(windowCount, windowNumbers); - for (NSInteger index = 0; index < windowCount; index++) { - NSWindow *w = [NSApp windowWithWindowNumber:windowNumbers[index]]; + for (NSWindow *w in macWindows) { if (TkMacOSXGetXWindow(w)) { [w flushWindow]; } } - ckfree(windowNumbers); } + [pool drain]; } + /* * Local Variables: |