summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXWm.c
diff options
context:
space:
mode:
authorKevin Walzer <kw@codebykevin.com>2015-03-21 00:57:14 (GMT)
committerKevin Walzer <kw@codebykevin.com>2015-03-21 00:57:14 (GMT)
commit4f6c1ad7943f8c595d9d539a6c6c33c96832554b (patch)
tree28a13f3c5fdd1724d3f1e4cce22305e2c775a2bd /macosx/tkMacOSXWm.c
parentc76fcabd431431b1acfc9d4113781872fcc9fe9b (diff)
downloadtk-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/tkMacOSXWm.c')
-rw-r--r--macosx/tkMacOSXWm.c79
1 files changed, 36 insertions, 43 deletions
diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c
index fc61c7f..ffb3c34 100644
--- a/macosx/tkMacOSXWm.c
+++ b/macosx/tkMacOSXWm.c
@@ -463,25 +463,18 @@ FrontWindowAtPoint(
int x, int y)
{
NSPoint p = NSMakePoint(x, tkMacOSXZeroScreenHeight - y);
- NSWindow *win = nil;
- NSInteger windowCount;
- NSInteger *windowNumbers;
-
- 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]];
+ NSAutoreleasePool *pool = [NSAutoreleasePool new];
+ NSArray *windows = [NSApp orderedWindows];
+ TkWindow *front = NULL;
+ for (NSWindow *w in windows) {
if (w && NSMouseInRect(p, [w frame], NO)) {
- win = w;
+ front = TkMacOSXGetTkWindow(w);
break;
}
}
- ckfree(windowNumbers);
- }
- return (win ? TkMacOSXGetTkWindow(win) : NULL);
+ [pool drain];
+ return front;
}
/*
@@ -677,6 +670,7 @@ TkWmMapWindow(
*/
XMapWindow(winPtr->display, winPtr->window);
+
}
/*
@@ -699,7 +693,7 @@ TkWmMapWindow(
void
TkWmUnmapWindow(
TkWindow *winPtr) /* Top-level window that's about to be
- * mapped. */
+ * unmapped. */
{
XUnmapWindow(winPtr->display, winPtr->window);
}
@@ -783,21 +777,26 @@ TkWmDeadWindow(
NSWindow *window = wmPtr->window;
if (window && !Tk_IsEmbedded(winPtr) ) {
- [[window parentWindow] removeChildWindow:window];
+ NSWindow *parent = [window parentWindow];
+ if (parent) {
+ [parent removeChildWindow:window];
+ }
[window setExcludedFromWindowsMenu:YES];
[window close];
TkMacOSXUnregisterMacWindow(window);
- if (winPtr->window) {
- ((MacDrawable *) winPtr->window)->view = nil;
+ if (winPtr->window) {
+ ((MacDrawable *) winPtr->window)->view = nil;
}
- [window release];
+ [window release];
wmPtr->window = NULL;
- /* Activate the highest window left on the screen. */
- NSArray *windows = [NSApp orderedWindows];
- NSWindow *front = [windows objectAtIndex:0];
- if ( front && [front canBecomeKeyWindow] ) {
- [front makeKeyAndOrderFront:NSApp];
- }
+ /* Activate the highest window left on the screen. */
+ NSArray *windows = [NSApp orderedWindows];
+ if ( [windows count] > 0 ) {
+ NSWindow *front = [windows objectAtIndex:0];
+ if ( front && [front canBecomeKeyWindow] ) {
+ [front makeKeyAndOrderFront:NSApp];
+ }
+ }
}
ckfree(wmPtr);
winPtr->wmInfoPtr = NULL;
@@ -5927,6 +5926,7 @@ TkpChangeFocus(
if (Tk_IsTopLevel(winPtr) && !Tk_IsEmbedded(winPtr) ){
NSWindow *win = TkMacOSXDrawableWindow(winPtr->window);
+ NSAutoreleasePool *pool = [NSAutoreleasePool new];
TkWmRestackToplevel(winPtr, Above, NULL);
if (force ) {
[NSApp activateIgnoringOtherApps:YES];
@@ -5934,6 +5934,7 @@ TkpChangeFocus(
if ( win && [win canBecomeKeyWindow] ) {
[win makeKeyAndOrderFront:NSApp];
}
+ [pool drain];
}
/*
@@ -5952,7 +5953,7 @@ TkpChangeFocus(
* WmStackorderToplevelWrapperMap --
*
* This procedure will create a table that maps the reparent wrapper X id
- * for a toplevel to the TkWindow structure that is wraps. Tk keeps track
+ * for a toplevel to the TkWindow structure that it wraps. Tk keeps track
* of a mapping from the window X id to the TkWindow structure but that
* does us no good here since we only get the X id of the wrapper window.
* Only those toplevel windows that are mapped have a position in the
@@ -6015,8 +6016,6 @@ TkWmStackorderToplevel(
Tcl_HashTable table;
Tcl_HashEntry *hPtr;
Tcl_HashSearch search;
- NSInteger windowCount;
- NSInteger *windowNumbers;
/*
* Map mac windows to a TkWindow of the wrapped toplevel.
@@ -6043,31 +6042,26 @@ TkWmStackorderToplevel(
goto done;
}
- NSCountWindows(&windowCount);
+ NSArray *macWindows = [NSApp orderedWindows];
+ NSInteger windowCount = [macWindows count];
+
if (!windowCount) {
ckfree(windows);
windows = NULL;
} else {
windowPtr = windows + table.numEntries;
*windowPtr-- = NULL;
- windowNumbers = ckalloc(windowCount * sizeof(NSInteger));
- NSWindowList(windowCount, windowNumbers);
- for (NSInteger index = 0; index < windowCount; index++) {
- NSWindow *w = [NSApp windowWithWindowNumber:windowNumbers[index]];
-
- if (w) {
- hPtr = Tcl_FindHashEntry(&table, (char*) w);
- if (hPtr != NULL) {
- childWinPtr = Tcl_GetHashValue(hPtr);
- *windowPtr-- = childWinPtr;
- }
+ for (NSWindow *w in macWindows) {
+ hPtr = Tcl_FindHashEntry(&table, (char*) w);
+ if (hPtr != NULL) {
+ childWinPtr = Tcl_GetHashValue(hPtr);
+ *windowPtr-- = childWinPtr;
}
}
if (windowPtr != windows-1) {
Tcl_Panic("num matched toplevel windows does not equal num "
- "children");
+ "children");
}
- ckfree(windowNumbers);
}
done:
@@ -6626,7 +6620,6 @@ RemapWindows(
MacDrawable *parentWin)
{
TkWindow *childPtr;
-
/*
* Remove the OS specific window. It will get rebuilt when the window gets
* Mapped.