might be functional

This commit is contained in:
Nishi 2026-01-27 17:34:25 +09:00
commit 8b28b3e1b0
4 changed files with 32 additions and 1 deletions

View file

@ -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

View file

@ -22,6 +22,7 @@ struct _MwLLGDI {
int grabbed;
int force_render;
int get_clipboard;
int get_darktheme;
};
struct _MwLLGDIColor {

View file

@ -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);

View file

@ -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);