From 8b28b3e1b0207ae061caebda0a6f62ce68ffb1be Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Tue, 27 Jan 2026 17:34:25 +0900 Subject: [PATCH] might be functional --- include/Mw/LowLevel.h | 1 + include/Mw/LowLevel/GDI.h | 1 + src/backend/gdi.c | 23 ++++++++++++++++++++++- src/core.c | 8 ++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/include/Mw/LowLevel.h b/include/Mw/LowLevel.h index 6bea6cd..b548328 100644 --- a/include/Mw/LowLevel.h +++ b/include/Mw/LowLevel.h @@ -163,6 +163,7 @@ struct _MwLLHandler { void (*focus_in)(MwLL handle, void* data); void (*focus_out)(MwLL handle, void* data); void (*clipboard)(MwLL handle, void* data); + void (*dark_theme)(MwLL handle, void* data); }; #ifdef __cplusplus diff --git a/include/Mw/LowLevel/GDI.h b/include/Mw/LowLevel/GDI.h index 1bf997c..c695cbd 100644 --- a/include/Mw/LowLevel/GDI.h +++ b/include/Mw/LowLevel/GDI.h @@ -22,6 +22,7 @@ struct _MwLLGDI { int grabbed; int force_render; int get_clipboard; + int get_darktheme; }; struct _MwLLGDIColor { diff --git a/src/backend/gdi.c b/src/backend/gdi.c index 764e983..20c47b2 100644 --- a/src/backend/gdi.c +++ b/src/backend/gdi.c @@ -8,6 +8,17 @@ typedef struct userdata { int max_set; } userdata_t; +static void detect_darktheme(MwLL handle){ + DWORD dw; + DWORD sz = sizeof(dw); + + if(RegGetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", "AppsUseLightTheme", RRF_RT_REG_DWORD, NULL, &dw, &sz) == ERROR_SUCCESS){ + int t = dw ? 0 : 1; + + MwLLDispatch(handle, dark_theme, &t); + } +} + static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { userdata_t* u = (userdata_t*)GetWindowLongPtr(hWnd, GWLP_USERDATA); @@ -205,6 +216,10 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { } else if(msg == WM_USER) { InvalidateRect(hWnd, NULL, FALSE); UpdateWindow(hWnd); + } else if(msg == WM_WININICHANGE){ + char* s = (char*)lp; + + if(s != NULL && strcmp(s, "ImmersiveColorSet") == 0) detect_darktheme(u->ll); } else { return DefWindowProc(hWnd, msg, wp, lp); } @@ -238,6 +253,7 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) { r->common.type = MwLLBackendGDI; r->gdi.get_clipboard = 1; + r->gdi.get_darktheme = 1; r->gdi.force_render = 0; r->gdi.grabbed = 0; 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); @@ -384,7 +400,7 @@ static int MwLLPendingImpl(MwLL handle) { (void)handle; - if(handle->gdi.get_clipboard) return 1; + if(handle->gdi.get_clipboard || handle->gdi.get_darktheme) return 1; return PeekMessage(&msg, handle->gdi.hWnd, 0, 0, PM_NOREMOVE) ? 1 : 0; } @@ -411,6 +427,11 @@ static void MwLLNextEventImpl(MwLL handle) { handle->gdi.get_clipboard = 0; } + if(handle->gdi.get_darktheme){ + detect_darktheme(handle); + + handle->gdi.get_clipboard = 0; + } while(PeekMessage(&msg, handle->gdi.hWnd, 0, 0, PM_NOREMOVE)) { GetMessage(&msg, handle->gdi.hWnd, 0, 0); TranslateMessage(&msg); diff --git a/src/core.c b/src/core.c index 78d2a94..9d0d18b 100644 --- a/src/core.c +++ b/src/core.c @@ -127,6 +127,13 @@ static void llclipboardhandler(MwLL handle, void* data) { */ #define IsFirstVisible(handle) ((handle)->widget_class != NULL && ((handle)->parent == NULL || (handle)->parent->widget_class == NULL)) +static void lldarkthemehandler(MwLL handle, void* data){ + MwWidget h = (MwWidget)handle->common.user; + int* ptr = data; + + if(IsFirstVisible(h)) MwToggleDarkTheme(h, *ptr); +} + MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height) { MwWidget h = malloc(sizeof(*h)); @@ -171,6 +178,7 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent, h->lowlevel->common.handler->focus_in = llfocusinhandler; h->lowlevel->common.handler->focus_out = llfocusouthandler; h->lowlevel->common.handler->clipboard = llclipboardhandler; + h->lowlevel->common.handler->dark_theme = lldarkthemehandler; } if(parent != NULL) arrput(parent->children, h);