From cc0b61f0ab4a16a205ca714eed84f12c12cfc2ae Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Tue, 7 Oct 2025 02:26:40 +0000 Subject: [PATCH] add new function git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@188 b9cfdab3-6d41-4d17-bbe4-086880011989 --- include/Mw/LowLevel.h | 1 + src/backend/gdi.c | 5 +++++ src/backend/x11.c | 12 +++++++++--- src/widget/submenu.c | 16 ++++------------ 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/include/Mw/LowLevel.h b/include/Mw/LowLevel.h index c4a6b5a..018fe79 100644 --- a/include/Mw/LowLevel.h +++ b/include/Mw/LowLevel.h @@ -81,6 +81,7 @@ MWDECL void MwLLForceRender(MwLL handle); MWDECL void MwLLSetCursor(MwLL handle, MwCursor* image, MwCursor* mask); MWDECL void MwLLDetach(MwLL handle, MwPoint* point); +MWDECL void MwLLShow(MwLL handle, int show); #ifdef __cplusplus } diff --git a/src/backend/gdi.c b/src/backend/gdi.c index b58e2c6..396f6f5 100644 --- a/src/backend/gdi.c +++ b/src/backend/gdi.c @@ -389,3 +389,8 @@ void MwLLDetach(MwLL handle, MwPoint* point) { SetWindowLongPtr(handle->hWnd, GWL_STYLE, style); } + +void MwLLShow(MwLL handle, int show) { + ShowWindow(handle->hWnd, show ? SW_NORMAL : SW_HIDE); + if(show) SetFocus(handle->hWnd); +} diff --git a/src/backend/x11.c b/src/backend/x11.c index eb641dd..08b55a1 100644 --- a/src/backend/x11.c +++ b/src/backend/x11.c @@ -387,7 +387,13 @@ void MwLLDetach(MwLL handle, MwPoint* point) { XTranslateCoordinates(handle->display, parent, RootWindow(handle->display, DefaultScreen(handle->display)), 0, 0, &x, &y, &child); XReparentWindow(handle->display, handle->window, RootWindow(handle->display, DefaultScreen(handle->display)), x + point->x, y + point->y); - - XMapWindow(handle->display, handle->window); - // XSetInputFocus(handle->display, handle->window, RevertToNone, CurrentTime); +} + +void MwLLShow(MwLL handle, int show) { + if(show) { + XMapWindow(handle->display, handle->window); + XSetInputFocus(handle->display, handle->window, RevertToNone, CurrentTime); + } else { + XUnmapWindow(handle->display, handle->window); + } } diff --git a/src/widget/submenu.c b/src/widget/submenu.c index 63be8b5..58c30bd 100644 --- a/src/widget/submenu.c +++ b/src/widget/submenu.c @@ -4,14 +4,7 @@ #include "../external/stb_ds.h" static int create(MwWidget handle) { -/* todo: we should have a public "show" function here that is implemented per - platform, as opposed to just shoving it here. perchance. */ -#ifdef _WIN32 - ShowWindow(handle->lowlevel->hWnd, SW_HIDE); -#endif -#ifdef UNIX - XUnmapWindow(handle->lowlevel->display, handle->lowlevel->window); -#endif + MwLLShow(handle->lowlevel, 0); MwSetDefault(handle); @@ -181,15 +174,14 @@ void MwSubMenuAppear(MwWidget handle, MwMenu menu, MwPoint* point) { handle->internal = menu; MwLLDetach(handle->lowlevel, point); + #ifdef _WIN32 SetWindowLongPtr(handle->lowlevel->hWnd, GWL_STYLE, (LONG_PTR)0); SetWindowLongPtr(handle->lowlevel->hWnd, GWL_EXSTYLE, (LONG_PTR)WS_EX_TOOLWINDOW); - - ShowWindow(handle->lowlevel->hWnd, SW_NORMAL); - - SetFocus(handle->lowlevel->hWnd); #endif + MwLLShow(handle->lowlevel, 1); + for(i = 0; i < arrlen(menu->sub); i++) { int tw = MwTextWidth(handle, menu->sub[i]->name); h += MwTextHeight(handle, menu->sub[i]->name) + 3;