From 54cdd8501574eb8ec5e1b39a15fabde53e728a17 Mon Sep 17 00:00:00 2001 From: IoIxD Date: Sun, 4 Jan 2026 13:06:36 -0700 Subject: [PATCH] coords --- include/Mw/Core.h | 5 +++++ include/Mw/LowLevel.h | 1 + include/Mw/TypeDefs.h | 6 ++++++ src/backend/wayland.c | 4 ++++ src/core.c | 8 ++++++++ src/widget/submenu.c | 16 ++++++++++++---- 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/include/Mw/Core.h b/include/Mw/Core.h index e714a32..cd7cabd 100644 --- a/include/Mw/Core.h +++ b/include/Mw/Core.h @@ -354,6 +354,11 @@ MWDECL void MwGetCursorCoord(MwWidget handle, MwPoint* point); */ MWDECL void MwGetScreenSize(MwWidget handle, MwRect* rect); +/*! + * @brief Reports whether a widget reports global or local coordinates upon GetXY/SetXY. Anything with a parent reports local, and most backends report global coordinates being supported for top level windows, but some (Wayland) do not. + */ +MWDECL int MwGetCoordinateType(MwWidget handle); + #ifdef __cplusplus } #endif diff --git a/include/Mw/LowLevel.h b/include/Mw/LowLevel.h index 3c8bdf7..c748bf9 100644 --- a/include/Mw/LowLevel.h +++ b/include/Mw/LowLevel.h @@ -33,6 +33,7 @@ struct _MwLLCommon { void* user; int copy_buffer; int type; + int coordinate_type; MwLLHandler handler; }; diff --git a/include/Mw/TypeDefs.h b/include/Mw/TypeDefs.h index caf3887..6434f52 100644 --- a/include/Mw/TypeDefs.h +++ b/include/Mw/TypeDefs.h @@ -219,4 +219,10 @@ struct _MwClass { void* reserved4; }; +/* Whether or not GetXY/SetXY works with global or local coordinates */ +enum MwCoordinateType { + MwCoordinatesGlobal = 0, + MwCoordinatesLocal, +}; + #endif diff --git a/src/backend/wayland.c b/src/backend/wayland.c index f6532fa..68aab8e 100644 --- a/src/backend/wayland.c +++ b/src/backend/wayland.c @@ -1344,6 +1344,10 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) { memset(r, 0, sizeof(*r)); MwLLCreateCommon(r); + /* Wayland does not report global coordinates ever. Compositors are not even expected to have knowledge of this. + */ + r->common.coordinate_type = MwCoordinatesLocal; + r->common.type = MwLLBackendWayland; if(width < 2) width = 2; diff --git a/src/core.c b/src/core.c index 3d41a36..d47e3b8 100644 --- a/src/core.c +++ b/src/core.c @@ -797,3 +797,11 @@ void MwGetCursorCoord(MwWidget handle, MwPoint* point) { void MwGetScreenSize(MwWidget handle, MwRect* rect) { MwLLGetScreenSize(handle->lowlevel, rect); } + +int MwGetCoordinateType(MwWidget handle) { + if(handle->parent == NULL) { + return handle->lowlevel->common.coordinate_type; + } else { + return MwCoordinatesLocal; + } +}; diff --git a/src/widget/submenu.c b/src/widget/submenu.c index 54ee8ea..f05c573 100644 --- a/src/widget/submenu.c +++ b/src/widget/submenu.c @@ -183,10 +183,18 @@ static void mwSubMenuAppearImpl(MwWidget handle, MwMenu menu, MwPoint* point, in MwLLMakeToolWindow(handle->lowlevel); MwLLDetach(handle->lowlevel, &p); - if(MwGetInteger(handle, MwNy) + sz.height > rc.height) { - MwVaApply(handle, - MwNy, rc.height - sz.height, - NULL); + if(handle->lowlevel->common.coordinate_type == MwCoordinatesGlobal) { + if(MwGetInteger(handle, MwNy) + sz.height > rc.height) { + MwVaApply(handle, + MwNy, rc.height - sz.height, + NULL); + } + } else { + if(MwGetInteger(handle, MwNy) > sz.height) { + MwVaApply(handle, + MwNy, sz.height, + NULL); + } } MwLLEndStateChange(handle->lowlevel);