diff options
author | culler <culler> | 2020-04-24 20:13:52 (GMT) |
---|---|---|
committer | culler <culler> | 2020-04-24 20:13:52 (GMT) |
commit | e2124e344267e83ec932ceaf23e7ad39bef98b1a (patch) | |
tree | 913cdf306482f6e4f04f2d9404d0b90dc5ec8e24 | |
parent | 7cd41e727ae5601c5ef0782145198200c680b31d (diff) | |
download | tk-e2124e344267e83ec932ceaf23e7ad39bef98b1a.zip tk-e2124e344267e83ec932ceaf23e7ad39bef98b1a.tar.gz tk-e2124e344267e83ec932ceaf23e7ad39bef98b1a.tar.bz2 |
Add x, y, X and Y to key events.
-rw-r--r-- | macosx/tkMacOSXKeyEvent.c | 41 | ||||
-rw-r--r-- | macosx/tkMacOSXMouseEvent.c | 3 |
2 files changed, 41 insertions, 3 deletions
diff --git a/macosx/tkMacOSXKeyEvent.c b/macosx/tkMacOSXKeyEvent.c index ec09306..c5fb93b 100644 --- a/macosx/tkMacOSXKeyEvent.c +++ b/macosx/tkMacOSXKeyEvent.c @@ -16,6 +16,7 @@ #include "tkMacOSXPrivate.h" #include "tkMacOSXInt.h" #include "tkMacOSXConstants.h" +#include "tkMacOSXWm.h" /* #ifdef TK_MAC_DEBUG @@ -33,6 +34,7 @@ static int caret_x = 0, caret_y = 0, caret_height = 0; static TkWindow *caret_win = NULL; static void setupXEvent(XEvent *xEvent, Tk_Window tkwin, NSUInteger modifiers); +static void setXeventPoint(XEvent *xEvent, Tk_Window tkwin, NSWindow *w); #pragma mark TKApplication(TKKeyEvent) @@ -190,9 +192,10 @@ static void setupXEvent(XEvent *xEvent, Tk_Window tkwin, NSUInteger modifiers); default: return theEvent; /* Unrecognized key event. */ } + setXeventPoint(&xEvent, tkwin, w); /* - * Finally we can queue an XEvent, inserting a KeyRelease before a + * Finally we can queue the XEvent, inserting a KeyRelease before a * repeated KeyPress. */ @@ -258,6 +261,7 @@ static void setupXEvent(XEvent *xEvent, Tk_Window tkwin, NSUInteger modifiers); */ setupXEvent(&xEvent, tkwin, 0); + setXeventPoint(&xEvent, tkwin, [self window]); xEvent.xany.type = KeyPress; /* @@ -546,6 +550,41 @@ setupXEvent(XEvent *xEvent, Tk_Window tkwin, NSUInteger modifiers) * because of the memset() above. */ } +static void +setXeventPoint( + XEvent *xEvent, + Tk_Window tkwin, + NSWindow *w) +{ + TkWindow *winPtr = (TkWindow *) tkwin; + NSPoint local = [w mouseLocationOutsideOfEventStream]; + NSPoint global = [w tkConvertPointToScreen: local]; + int win_x, win_y; + + if (Tk_IsEmbedded(winPtr)) { + TkWindow *contPtr = TkpGetOtherWindow(winPtr); + if (Tk_IsTopLevel(contPtr)) { + local.x -= contPtr->wmInfoPtr->xInParent; + local.y -= contPtr->wmInfoPtr->yInParent; + } else { + TkWindow *topPtr = TkMacOSXGetHostToplevel(winPtr)->winPtr; + local.x -= (topPtr->wmInfoPtr->xInParent + contPtr->changes.x); + local.y -= (topPtr->wmInfoPtr->yInParent + contPtr->changes.y); + } + } else { + local.x -= winPtr->wmInfoPtr->xInParent; + local.y -= winPtr->wmInfoPtr->yInParent; + } + tkwin = Tk_TopCoordsToWindow(tkwin, local.x, local.y, &win_x, &win_y); + local.x = win_x; + local.y = win_y; + global.y = TkMacOSXZeroScreenHeight() - global.y; + xEvent->xbutton.x = local.x; + xEvent->xbutton.y = local.y; + xEvent->xbutton.x_root = global.x; + xEvent->xbutton.y_root = global.y; +} + #pragma mark - /* diff --git a/macosx/tkMacOSXMouseEvent.c b/macosx/tkMacOSXMouseEvent.c index dd50d0a..d475dbc 100644 --- a/macosx/tkMacOSXMouseEvent.c +++ b/macosx/tkMacOSXMouseEvent.c @@ -123,7 +123,6 @@ enum { } } local.y = [eventWindow frame].size.height - local.y; - global.y = TkMacOSXZeroScreenHeight() - global.y; } else { /* @@ -143,7 +142,6 @@ enum { } local = [eventWindow tkConvertPointFromScreen: global]; local.y = [eventWindow frame].size.height - local.y; - global.y = TkMacOSXZeroScreenHeight() - global.y; } /* @@ -222,6 +220,7 @@ enum { tkwin = Tk_TopCoordsToWindow(tkwin, local.x, local.y, &win_x, &win_y); local.x = win_x; local.y = win_y; + global.y = TkMacOSXZeroScreenHeight() - global.y; /* * Generate an XEvent for this mouse event. |