summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXNotify.c
diff options
context:
space:
mode:
Diffstat (limited to 'macosx/tkMacOSXNotify.c')
-rw-r--r--macosx/tkMacOSXNotify.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/macosx/tkMacOSXNotify.c b/macosx/tkMacOSXNotify.c
index b400423..3e0dfde 100644
--- a/macosx/tkMacOSXNotify.c
+++ b/macosx/tkMacOSXNotify.c
@@ -24,8 +24,8 @@ typedef struct ThreadSpecificData {
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;
-#define TSD_INIT() ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, \
- sizeof(ThreadSpecificData))
+#define TSD_INIT() ThreadSpecificData *tsdPtr = \
+ Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData))
static void TkMacOSXNotifyExitHandler(ClientData clientData);
static void TkMacOSXEventsSetupProc(ClientData clientData, int flags);
@@ -34,11 +34,12 @@ static void TkMacOSXEventsCheckProc(ClientData clientData, int flags);
#pragma mark TKApplication(TKNotify)
@interface NSApplication(TKNotify)
-- (void)_modalSession:(NSModalSession)session sendEvent:(NSEvent *)event;
+- (void) _modalSession: (NSModalSession) session sendEvent: (NSEvent *) event;
@end
@implementation NSWindow(TKNotify)
-- (id)tkDisplayIfNeeded {
+- (id) tkDisplayIfNeeded
+{
if (![self isAutodisplay]) {
[self displayIfNeeded];
}
@@ -47,14 +48,18 @@ static void TkMacOSXEventsCheckProc(ClientData clientData, int flags);
@end
@implementation TKApplication(TKNotify)
-- (NSEvent *)nextEventMatchingMask:(NSUInteger)mask
- untilDate:(NSDate *)expiration inMode:(NSString *)mode
- dequeue:(BOOL)deqFlag {
+- (NSEvent *) nextEventMatchingMask: (NSUInteger) mask
+ untilDate: (NSDate *) expiration inMode: (NSString *) mode
+ dequeue: (BOOL) deqFlag
+{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
+
[NSApp makeWindowsPerform:@selector(tkDisplayIfNeeded) inOrder:NO];
+
int oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
NSEvent *event = [[super nextEventMatchingMask:mask untilDate:expiration
inMode:mode dequeue:deqFlag] retain];
+
Tcl_SetServiceMode(oldMode);
if (event) {
TSD_INIT();
@@ -68,9 +73,12 @@ static void TkMacOSXEventsCheckProc(ClientData clientData, int flags);
[pool drain];
return [event autorelease];
}
-- (void)sendEvent:(NSEvent *)theEvent {
+
+- (void) sendEvent: (NSEvent *) theEvent
+{
TSD_INIT();
int oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL);
+
tsdPtr->sendEventNestingLevel++;
[super sendEvent:theEvent];
tsdPtr->sendEventNestingLevel--;
@@ -135,6 +143,7 @@ void
Tk_MacOSXSetupTkNotifier(void)
{
TSD_INIT();
+
if (!tsdPtr->initialized) {
tsdPtr->initialized = 1;
@@ -183,6 +192,7 @@ TkMacOSXNotifyExitHandler(
ClientData clientData) /* Not used. */
{
TSD_INIT();
+
Tcl_DeleteEventSource(TkMacOSXEventsSetupProc,
TkMacOSXEventsCheckProc, GetMainEventQueue());
tsdPtr->initialized = 0;
@@ -214,14 +224,15 @@ TkMacOSXEventsSetupProc(
{
if (flags & TCL_WINDOW_EVENTS &&
![[NSRunLoop currentRunLoop] currentMode]) {
- static Tcl_Time zeroBlockTime = { 0, 0 };
-
+ static const Tcl_Time zeroBlockTime = { 0, 0 };
TSD_INIT();
+
if (!tsdPtr->currentEvent) {
NSEvent *currentEvent = [NSApp nextEventMatchingMask:NSAnyEventMask
untilDate:[NSDate distantPast]
inMode:GetRunLoopMode(TkMacOSXGetModalSession())
dequeue:YES];
+
if (currentEvent) {
tsdPtr->currentEvent =
TkMacOSXMakeUncollectableAndRetain(currentEvent);
@@ -263,7 +274,7 @@ TkMacOSXEventsCheckProc(
TSD_INIT();
if (tsdPtr->currentEvent) {
currentEvent = TkMacOSXMakeCollectableAndAutorelease(
- tsdPtr->currentEvent);
+ tsdPtr->currentEvent);
}
do {
modalSession = TkMacOSXGetModalSession();