summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorculler <culler>2019-06-05 19:39:54 (GMT)
committerculler <culler>2019-06-05 19:39:54 (GMT)
commitd9d0148e639484278dfa8b8cb9423e1c6d4b7f23 (patch)
tree1a2d4105642c2b9781c2d2600fbc9625582aa60b
parente81cca9a1580b0ddae6685aa568a6b79a0796691 (diff)
parent702166b4a3baf652633f868e7ccf537ae4f3270e (diff)
downloadtk-d9d0148e639484278dfa8b8cb9423e1c6d4b7f23.zip
tk-d9d0148e639484278dfa8b8cb9423e1c6d4b7f23.tar.gz
tk-d9d0148e639484278dfa8b8cb9423e1c6d4b7f23.tar.bz2
Fix bug [9ebc6fd168]: Aqua can report incorrect mouse coordinates.
-rw-r--r--macosx/tkMacOSXMouseEvent.c72
-rw-r--r--macosx/tkMacOSXPrivate.h1
-rw-r--r--macosx/tkMacOSXWindowEvent.c4
-rw-r--r--macosx/tkMacOSXWm.c10
4 files changed, 35 insertions, 52 deletions
diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c
index adc24b1..26e1404 100644
--- a/macosx/tkMacOSXMouseEvent.c
+++ b/macosx/tkMacOSXMouseEvent.c
@@ -53,6 +53,7 @@ enum {
NSEventType eventType = [theEvent type];
TkWindow *winPtr, *grabWinPtr;
Tk_Window tkwin;
+ NSPoint local, global;
#if 0
NSTrackingArea *trackingArea = nil;
NSInteger eventNumber, clickCount, buttonNumber;
@@ -84,61 +85,54 @@ enum {
}
/*
- * Remember the window in case we need it next time.
- */
-
- if (eventWindow && eventWindow != _windowWithMouse) {
- if (_windowWithMouse) {
- [_windowWithMouse release];
- }
- _windowWithMouse = eventWindow;
- [_windowWithMouse retain];
- }
-
- /*
* Compute the mouse position in Tk screen coordinates (global) and in the
- * Tk coordinates of its containing Tk Window.
+ * Tk coordinates of its containing Tk Window (local). If a grab is in effect,
+ * the local coordinates should be relative to the grab window.
*/
- NSPoint global, local = [theEvent locationInWindow];
-
- /*
- * If the event has no NSWindow, try using the cached NSWindow from the
- * last mouse event.
- */
-
- if (eventWindow == NULL) {
- eventWindow = _windowWithMouse;
- }
if (eventWindow) {
- /*
- * Set the local mouse position to its NSWindow flipped coordinates,
- * with the origin at top left, and the global mouse position to the
- * flipped screen coordinates.
- */
-
+ local = [theEvent locationInWindow];
global = [eventWindow tkConvertPointToScreen: local];
+ tkwin = TkMacOSXGetCapture();
+ if (tkwin) {
+ winPtr = (TkWindow *) tkwin;
+ eventWindow = TkMacOSXDrawableWindow(winPtr->window);
+ if (eventWindow) {
+ local = [eventWindow tkConvertPointFromScreen: global];
+ } else {
+ return theEvent;
+ }
+ }
local.y = [eventWindow frame].size.height - local.y;
global.y = tkMacOSXZeroScreenHeight - global.y;
} else {
+
/*
- * As a last resort, with no NSWindow to work with, set both local and
- * global to the screen coordinates.
+ * If the event has no NSWindow, the location is in screen coordinates.
*/
- local.y = tkMacOSXZeroScreenHeight - local.y;
- global = local;
+ global = [theEvent locationInWindow];
+ tkwin = TkMacOSXGetCapture();
+ if (tkwin) {
+ winPtr = (TkWindow *) tkwin;
+ eventWindow = TkMacOSXDrawableWindow(winPtr->window);
+ } else {
+ eventWindow = [NSApp mainWindow];
+ }
+ if (!eventWindow) {
+ return theEvent;
+ }
+ local = [eventWindow tkConvertPointFromScreen: global];
+ local.y = [eventWindow frame].size.height - local.y;
+ global.y = tkMacOSXZeroScreenHeight - global.y;
}
/*
- * Find the toplevel which corresponds to the event NSWindow.
+ * Make sure tkwin is the toplevel which should receive the event.
*/
- winPtr = TkMacOSXGetTkWindow(eventWindow);
- if (winPtr == NULL) {
- tkwin = TkMacOSXGetCapture();
- winPtr = (TkWindow *) tkwin;
- } else {
+ if (!tkwin) {
+ winPtr = TkMacOSXGetTkWindow(eventWindow);
tkwin = (Tk_Window) winPtr;
}
if (!tkwin) {
diff --git a/macosx/tkMacOSXPrivate.h b/macosx/tkMacOSXPrivate.h
index b4da2b3..5632d95 100644
--- a/macosx/tkMacOSXPrivate.h
+++ b/macosx/tkMacOSXPrivate.h
@@ -263,7 +263,6 @@ VISIBILITY_HIDDEN
TKMenu *_defaultMainMenu, *_defaultApplicationMenu;
NSArray *_defaultApplicationMenuItems, *_defaultWindowsMenuItems;
NSArray *_defaultHelpMenuItems;
- NSWindow *_windowWithMouse;
NSAutoreleasePool *_mainPool;
#ifdef __i386__
/* The Objective C runtime used on i386 requires this. */
diff --git a/macosx/tkMacOSXWindowEvent.c b/macosx/tkMacOSXWindowEvent.c
index 3eda4ec..3703340 100644
--- a/macosx/tkMacOSXWindowEvent.c
+++ b/macosx/tkMacOSXWindowEvent.c
@@ -198,10 +198,6 @@ extern NSString *NSWindowDidOrderOffScreenNotification;
if (winPtr) {
TkGenWMDestroyEvent((Tk_Window) winPtr);
- if (_windowWithMouse == w) {
- _windowWithMouse = nil;
- [w release];
- }
}
/*
diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c
index e69f9ee..5d52db0 100644
--- a/macosx/tkMacOSXWm.c
+++ b/macosx/tkMacOSXWm.c
@@ -340,18 +340,12 @@ static void RemoveTransient(TkWindow *winPtr);
#else
- (NSPoint) tkConvertPointToScreen: (NSPoint) point
{
- NSRect pointrect;
- pointrect.origin = point;
- pointrect.size.width = 0;
- pointrect.size.height = 0;
+ NSRect pointrect = {point, {0,0}};
return [self convertRectToScreen:pointrect].origin;
}
- (NSPoint) tkConvertPointFromScreen: (NSPoint)point
{
- NSRect pointrect;
- pointrect.origin = point;
- pointrect.size.width = 0;
- pointrect.size.height = 0;
+ NSRect pointrect = {point, {0,0}};
return [self convertRectFromScreen:pointrect].origin;
}
#endif