summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXMouseEvent.c
diff options
context:
space:
mode:
authorKevin Walzer <kw@codebykevin.com>2015-11-07 18:41:19 (GMT)
committerKevin Walzer <kw@codebykevin.com>2015-11-07 18:41:19 (GMT)
commite0a9544076a1f3f079fdd4143ad1214a4cfc4729 (patch)
tree70d0b9cfb4a31fdfeaab0e080f544ace9352c31c /macosx/tkMacOSXMouseEvent.c
parentabbec4b67a98b0511d851db9fdaf10e9806c8fce (diff)
downloadtk-e0a9544076a1f3f079fdd4143ad1214a4cfc4729.zip
tk-e0a9544076a1f3f079fdd4143ad1214a4cfc4729.tar.gz
tk-e0a9544076a1f3f079fdd4143ad1214a4cfc4729.tar.bz2
Fix for issues with bitmap rendering and mouse events in Tk-Cocoa; thanks to Marc Culler for patches
Diffstat (limited to 'macosx/tkMacOSXMouseEvent.c')
-rw-r--r--macosx/tkMacOSXMouseEvent.c58
1 files changed, 42 insertions, 16 deletions
diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c
index 8c0a2e6..31038b5 100644
--- a/macosx/tkMacOSXMouseEvent.c
+++ b/macosx/tkMacOSXMouseEvent.c
@@ -34,6 +34,18 @@ enum {
NSWindowWillMoveEventType = 20
};
+/*
+ * In OS X 10.6 an NSEvent of type NSMouseMoved would always have a non-Nil
+ * window attribute when the mouse was inside a window. As of 10.8 this
+ * behavior had changed. The new behavior was that if the mouse were ever
+ * moved outside of a window, all subsequent NSMouseMoved NSEvents would have a
+ * Nil window attribute. To work around this we remember which window the
+ * mouse is in by saving the window attribute of each NSEvent of type
+ * NSMouseEntered. If an NSEvent has a Nil window attribute we use our saved
+ * window. It may be the case that the mouse has actually left the window, but
+ * this is harmless since Tk will ignore the event in that case.
+ */
+
@implementation TKApplication(TKMouseEvent)
- (NSEvent *) tkProcessMouseEvent: (NSEvent *) theEvent
{
@@ -49,12 +61,11 @@ enum {
switch (type) {
case NSMouseEntered:
+ /* Remember which window has the mouse. */
+ _windowWithMouse = [theEvent window];
+ break;
case NSMouseExited:
case NSCursorUpdate:
-#if 0
- trackingArea = [theEvent trackingArea];
- /* fall through */
-#endif
case NSLeftMouseDown:
case NSLeftMouseUp:
case NSRightMouseDown:
@@ -65,14 +76,6 @@ enum {
case NSRightMouseDragged:
case NSOtherMouseDragged:
case NSMouseMoved:
-#if 0
- eventNumber = [theEvent eventNumber];
- if (!trackingArea) {
- clickCount = [theEvent clickCount];
- buttonNumber = [theEvent buttonNumber];
- }
- /* fall through */
-#endif
case NSTabletPoint:
case NSTabletProximity:
case NSScrollWheel:
@@ -85,13 +88,36 @@ enum {
/* Create an Xevent to add to the Tk queue. */
win = [theEvent window];
NSPoint global, local = [theEvent locationInWindow];
- if (win) {
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
+ /* convertBaseToScreen and convertScreenToBase were deprecated in 10.7. */
+ NSRect pointrect;
+ pointrect.origin = local;
+ pointrect.size.width = 0;
+ pointrect.size.height = 0;
+#endif
+ if (win) { /* local will be in window coordinates. */
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
+ global = [win convertRectToScreen:pointrect].origin;
+#else
global = [win convertBaseToScreen:local];
+#endif
local.y = [win frame].size.height - local.y;
global.y = tkMacOSXZeroScreenHeight - global.y;
- } else {
- local.y = tkMacOSXZeroScreenHeight - local.y;
- global = local;
+ } else { /* local will be in screen coordinates. */
+ if (_windowWithMouse ) {
+ win = _windowWithMouse;
+ global = local;
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
+ local = [win convertRectFromScreen:pointrect].origin;
+#else
+ local = [win convertScreenToBase:local];
+#endif
+ local.y = [win frame].size.height - local.y;
+ global.y = tkMacOSXZeroScreenHeight - global.y;
+ } else { /* We have no window. Use the screen???*/
+ local.y = tkMacOSXZeroScreenHeight - local.y;
+ global = local;
+ }
}
Window window = TkMacOSXGetXWindow(win);