diff --git a/include/Mw/Core.h b/include/Mw/Core.h index 7a75f51..c8866e2 100644 --- a/include/Mw/Core.h +++ b/include/Mw/Core.h @@ -323,6 +323,13 @@ MWDECL MwClass MwGetClass(MwWidget handle); */ MWDECL MwWidget* MwGetChildren(MwWidget handle); +/*! + * @brief Gets the cursor coordinate + * @param handle Widget + * @param point Point + */ +MWDECL void MwGetCursorCoord(MwWidget handle, MwPoint* point); + #ifdef __cplusplus } #endif diff --git a/include/Mw/LowLevel.h b/include/Mw/LowLevel.h index d9bc17e..a2e55df 100644 --- a/include/Mw/LowLevel.h +++ b/include/Mw/LowLevel.h @@ -192,6 +192,8 @@ MWDECL void (*MwLLGrabPointer)(MwLL handle, int toggle); MWDECL void (*MwLLSetClipboard)(MwLL handle, const char* text); MWDECL char* (*MwLLGetClipboard)(MwLL handle); +MWDECL void (*MwLLGetCursorCoord)(MwLL handle, MwPoint* point); + #ifdef __cplusplus } #endif diff --git a/include/Mw/LowLevel/GDI.h b/include/Mw/LowLevel/GDI.h index eb0fc0a..a316779 100644 --- a/include/Mw/LowLevel/GDI.h +++ b/include/Mw/LowLevel/GDI.h @@ -18,7 +18,7 @@ struct _MwLLGDI { HWND hWnd; HDC hDC; HCURSOR cursor; - HICON icon; + HICON icon; int grabbed; }; diff --git a/src/backend/call.c b/src/backend/call.c index fc3dc9b..f29e48d 100644 --- a/src/backend/call.c +++ b/src/backend/call.c @@ -52,6 +52,8 @@ \ MwLLSetClipboard = MwLLSetClipboardImpl; \ MwLLGetClipboard = MwLLGetClipboardImpl; \ +\ + MwLLGetCursorCoord = MwLLGetCursorCoordImpl; \ \ return 0; \ } diff --git a/src/backend/gdi.c b/src/backend/gdi.c index f3e8a45..426d21e 100644 --- a/src/backend/gdi.c +++ b/src/backend/gdi.c @@ -240,7 +240,7 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) { r->gdi.hWnd = CreateWindow("milsko", "Milsko", parent == NULL ? (WS_OVERLAPPEDWINDOW) : (WS_CHILD | WS_VISIBLE), x == MwDEFAULT ? CW_USEDEFAULT : x, y == MwDEFAULT ? CW_USEDEFAULT : y, width, height, parent == NULL ? NULL : parent->gdi.hWnd, 0, wc.hInstance, NULL); r->gdi.hInstance = wc.hInstance; r->gdi.cursor = NULL; - r->gdi.icon = NULL; + r->gdi.icon = NULL; u->ll = r; u->min_set = 0; @@ -716,13 +716,23 @@ static void MwLLMakeToolWindowImpl(MwLL handle) { SetWindowPos(handle->gdi.hWnd, NULL, 0, 0, w, h, SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER); } +static void MwLLGetCursorCoordImpl(MwLL handle, MwPoint* point) { + POINT p; + + (void)handle; + + GetCursorPos(&p); + + point->x = p.x; + point->y = p.y; +} + static void MwLLBeginStateChangeImpl(MwLL handle) { (void)handle; } static void MwLLEndStateChangeImpl(MwLL handle) { (void)handle; - ; } static int MwLLGDICallInitImpl(void) { diff --git a/src/backend/x11.c b/src/backend/x11.c index 6e5399a..f658864 100644 --- a/src/backend/x11.c +++ b/src/backend/x11.c @@ -990,6 +990,17 @@ static void MwLLMakeToolWindowImpl(MwLL handle) { XChangeProperty(handle->x11.display, handle->x11.window, wndtype, XA_ATOM, 32, PropModeReplace, (unsigned char*)&wndmenu, 1); } +static void MwLLGetCursorCoordImpl(MwLL handle, MwPoint* point) { + Window root, child; + int rx, ry, wx, wy; + unsigned int m; + + XQueryPointer(handle->x11.display, DefaultRootWindow(handle->x11.display), &root, &child, &rx, &ry, &wx, &wy, &m); + + point->x = rx; + point->y = ry; +} + static void MwLLBeginStateChangeImpl(MwLL handle) { MwLLShow(handle, 0); } diff --git a/src/core.c b/src/core.c index 6fb31a3..1dfee65 100644 --- a/src/core.c +++ b/src/core.c @@ -705,3 +705,7 @@ MwWidget* MwGetChildren(MwWidget handle) { return c; } + +void MwGetCursorCoord(MwWidget handle, MwPoint* point) { + MwLLGetCursorCoord(handle->lowlevel, point); +} diff --git a/src/lowlevel.c b/src/lowlevel.c index 6a06e29..cef29f3 100644 --- a/src/lowlevel.c +++ b/src/lowlevel.c @@ -48,6 +48,8 @@ void (*MwLLGrabPointer)(MwLL handle, int toggle); void (*MwLLSetClipboard)(MwLL handle, const char* text); char* (*MwLLGetClipboard)(MwLL handle); +void (*MwLLGetCursorCoord)(MwLL handle, MwPoint* point); + void MwLLCreateCommon(MwLL handle) { handle->common.handler = malloc(sizeof(*handle->common.handler)); memset(handle->common.handler, 0, sizeof(*handle->common.handler));