diff --git a/include/Mw/Default.h b/include/Mw/Default.h index 322082b2..bd9967bb 100644 --- a/include/Mw/Default.h +++ b/include/Mw/Default.h @@ -42,6 +42,11 @@ MWDECL const char* MwDefaultTitleBackground; */ MWDECL const char* MwDefaultTitleForeground; +/*! + * @brief Default link foreground color + */ +MWDECL const char* MwDefaultLinkForeground; + /*! * @brief Default dark theme background color */ @@ -72,6 +77,11 @@ MWDECL const char* MwDefaultDarkTitleBackground; */ MWDECL const char* MwDefaultDarkTitleForeground; +/*! + * @brief Default dark theme link foreground color + */ +MWDECL const char* MwDefaultDarkLinkForeground; + /*! * @brief Default shadow difference */ diff --git a/include/Mw/LowLevel.h b/include/Mw/LowLevel.h index 5ef17f68..d2a8931d 100644 --- a/include/Mw/LowLevel.h +++ b/include/Mw/LowLevel.h @@ -42,10 +42,8 @@ struct _MwLLCommon { MwLLHandler handler; -#if defined(USE_WAYLAND) || defined(USE_X11) /* 0 = default, 1 = light, 2 = dark */ int theme_override; -#endif }; struct _MwLLCommonColor { diff --git a/include/Mw/StringDefs.h b/include/Mw/StringDefs.h index d04aee08..7906c1d0 100644 --- a/include/Mw/StringDefs.h +++ b/include/Mw/StringDefs.h @@ -69,6 +69,7 @@ #define MwNforeground "Sforeground" #define MwNsubForeground "SsubForeground" #define MwNtitleForeground "StitleForeground" +#define MwNlinkForeground "SlinkForeground" #define MwNvulkanExtension "SEvulkanExtension" #define MwNvulkanLayer "SEvulkanLayer" diff --git a/milsko.xml b/milsko.xml index 7624737e..4cf9038a 100644 --- a/milsko.xml +++ b/milsko.xml @@ -124,6 +124,7 @@ + diff --git a/src/abstract/directory.c b/src/abstract/directory.c index 904e63ce..e4f62080 100644 --- a/src/abstract/directory.c +++ b/src/abstract/directory.c @@ -20,7 +20,7 @@ typedef struct dir { void* MwDirectoryOpen(const char* path) { dir_t* dir = malloc(sizeof(*dir)); #ifdef _WIN32 - char* p; + char* p; #endif if(!dir) { printf("Out Of Memory\n"); diff --git a/src/backend/gdi.c b/src/backend/gdi.c index bd880f92..248a59b8 100644 --- a/src/backend/gdi.c +++ b/src/backend/gdi.c @@ -38,27 +38,32 @@ static void detect_darktheme_classictheme(MwLL handle) { /* Dark theme detection for modern Windows: use the registry to check if dark mode is enabled. */ static void detect_darktheme(MwLL handle) { - DWORD dw; - DWORD sz = sizeof(dw); - int err, t; - HKEY hkey; - DWORD type; + int t; + if(handle->common.theme_override > 0) { + t = handle->common.theme_override - 1; + } else { + DWORD dw; + DWORD sz = sizeof(dw); + int err; + HKEY hkey; + DWORD type; - err = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", 0, KEY_QUERY_VALUE, &hkey); - if(err != ERROR_SUCCESS) { - detect_darktheme_classictheme(handle); - return; + err = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", 0, KEY_QUERY_VALUE, &hkey); + if(err != ERROR_SUCCESS) { + detect_darktheme_classictheme(handle); + return; + } + + err = RegQueryValueEx(hkey, "AppsUseLightTheme", NULL, &type, (PBYTE)&dw, &sz); + RegCloseKey(hkey); + if(err != ERROR_SUCCESS || type != REG_DWORD) { + detect_darktheme_classictheme(handle); + return; + } + + t = dw ? 0 : 1; } - err = RegQueryValueEx(hkey, "AppsUseLightTheme", NULL, &type, (PBYTE)&dw, &sz); - RegCloseKey(hkey); - if(err != ERROR_SUCCESS || type != REG_DWORD) { - detect_darktheme_classictheme(handle); - return; - } - - t = dw ? 0 : 1; - /* no don't do this here (nishi) */ #if 0 if(t && DwmSetWindowAttribute != NULL) { diff --git a/src/core.c b/src/core.c index f537c5ab..547b7b1e 100644 --- a/src/core.c +++ b/src/core.c @@ -819,7 +819,7 @@ int MwGetInteger(MwWidget handle, const char* key) { } const char* MwGetString(MwWidget handle, const char* key) { - if((shgeti(handle->string, key) == -1 || strcmp(shget(handle->string, key), "DEFAULT") == 0) && (strcmp(key, MwNbackground) == 0 || strcmp(key, MwNforeground) == 0 || strcmp(key, MwNsubBackground) == 0 || strcmp(key, MwNsubForeground) == 0 || strcmp(key, MwNtitleBackground) == 0 || strcmp(key, MwNtitleForeground) == 0)) { + if((shgeti(handle->string, key) == -1 || strcmp(shget(handle->string, key), "DEFAULT") == 0) && (strcmp(key, MwNbackground) == 0 || strcmp(key, MwNforeground) == 0 || strcmp(key, MwNsubBackground) == 0 || strcmp(key, MwNsubForeground) == 0 || strcmp(key, MwNtitleBackground) == 0 || strcmp(key, MwNtitleForeground) == 0 || strcmp(key, MwNlinkForeground) == 0)) { const char* v = NULL; if(shgeti(handle->string, key) != -1 && strcmp(shget(handle->string, key), "DEFAULT") != 0) { MwWidget h = handle->parent; @@ -836,6 +836,7 @@ const char* MwGetString(MwWidget handle, const char* key) { if(strcmp(key, MwNsubForeground) == 0) return MwDefaultDarkSubForeground; if(strcmp(key, MwNtitleBackground) == 0) return MwDefaultDarkTitleBackground; if(strcmp(key, MwNtitleForeground) == 0) return MwDefaultDarkTitleForeground; + if(strcmp(key, MwNlinkForeground) == 0) return MwDefaultDarkLinkForeground; } else { if(strcmp(key, MwNbackground) == 0) return MwDefaultBackground; if(strcmp(key, MwNforeground) == 0) return MwDefaultForeground; @@ -843,6 +844,7 @@ const char* MwGetString(MwWidget handle, const char* key) { if(strcmp(key, MwNsubForeground) == 0) return MwDefaultSubForeground; if(strcmp(key, MwNtitleBackground) == 0) return MwDefaultTitleBackground; if(strcmp(key, MwNtitleForeground) == 0) return MwDefaultTitleForeground; + if(strcmp(key, MwNlinkForeground) == 0) return MwDefaultLinkForeground; } } return v; diff --git a/src/default.c b/src/default.c index 2cb16334..bad4ee13 100644 --- a/src/default.c +++ b/src/default.c @@ -9,6 +9,7 @@ const char* MwDefaultSubBackground = "#9ca0b0"; const char* MwDefaultSubForeground = "#6c6f85"; const char* MwDefaultTitleBackground = "#bcc0cc"; const char* MwDefaultTitleForeground = "#5c5f77"; +const char* MwDefaultLinkForeground = "#8839ef"; #else const char* MwDefaultBackground = "#d2d2d2"; const char* MwDefaultForeground = "#000"; @@ -16,6 +17,7 @@ const char* MwDefaultSubBackground = "#fff"; const char* MwDefaultSubForeground = "#000"; const char* MwDefaultTitleBackground = "#008"; const char* MwDefaultTitleForeground = "#fff"; +const char* MwDefaultLinkForeground = "#008"; #endif #ifdef USE_CATPPUCCIN_DARK @@ -25,6 +27,7 @@ const char* MwDefaultDarkSubBackground = "#313244"; const char* MwDefaultDarkSubForeground = "#a6adc8"; const char* MwDefaultDarkTitleBackground = "#45475a"; const char* MwDefaultDarkTitleForeground = "#bac2de"; +const char* MwDefaultDarkLinkForeground = "#cba6f7"; #else const char* MwDefaultDarkBackground = "#333"; const char* MwDefaultDarkForeground = "#ddd"; @@ -32,6 +35,7 @@ const char* MwDefaultDarkSubBackground = "#333"; const char* MwDefaultDarkSubForeground = "#ddd"; const char* MwDefaultDarkTitleBackground = "#008"; const char* MwDefaultDarkTitleForeground = "#fff"; +const char* MwDefaultDarkLinkForeground = "#008"; #endif const int MwDefaultShadow = -32; diff --git a/src/lowlevel.c b/src/lowlevel.c index d676310a..6577e35b 100644 --- a/src/lowlevel.c +++ b/src/lowlevel.c @@ -66,22 +66,19 @@ void (*MwLLRaise)(MwLL handle) = NULL; void (*MwLLClip)(MwLL handle, MwRect* rect) = NULL; void MwLLCreateCommon(MwLL handle) { -#if defined(USE_WAYLAND) || defined(USE_X11) char* light_theme = getenv("MW_LIGHT_THEME"); char* dark_theme = getenv("MW_DARK_THEME"); -#endif handle->common.handler = malloc(sizeof(*handle->common.handler)); memset(handle->common.handler, 0, sizeof(*handle->common.handler)); handle->common.supports_transparency = 0; -#if defined(USE_WAYLAND) || defined(USE_X11) if(light_theme || dark_theme) { handle->common.theme_override = (light_theme != NULL) ? 1 : ((dark_theme != NULL) ? 2 : 0); + } else { + handle->common.theme_override = 0; } - -#endif } void MwLLDestroyCommon(MwLL handle) { diff --git a/src/widget/document.c b/src/widget/document.c index 505a26da..797af6e9 100644 --- a/src/widget/document.c +++ b/src/widget/document.c @@ -54,6 +54,7 @@ static void draw(MwWidget handle) { MwDocument d = handle->internal; MwColor base = MwParseColor(handle, MwGetString(handle, MwNbackground)); MwColor text = MwParseColor(handle, MwGetString(handle, MwNforeground)); + MwColor link = MwParseColor(handle, MwGetString(handle, MwNlinkForeground)); MwRect r; int i; MwFLFont font = NULL; @@ -124,28 +125,16 @@ static void draw(MwWidget handle) { if(j == 1) s_p.x = line[1].x; if(j == 2) c_p.x = line[1].x; - if(j == 2) { - MwRect c_r; - - c_r.x = line[0].x; - c_r.y = line[0].y; - c_r.width = line[1].x - line[0].x; - c_r.height = MwTextHeight(handle, font, l->text); - - MwDrawRect(handle, &c_r, text); - } - - if(j == 0 || j == 1) { - line[0].y += MwTextHeight(handle, font, l->text) / 2 * (2 - j); - line[1].y += MwTextHeight(handle, font, l->text) / 2 * (2 - j); - MwLine(handle, line, (c ? base : text)); + if(j == 0 || j == 1 || j == 2) { + int am = MwTextHeight(handle, font, l->text) / 2 * (2 - (j == 2 ? 0 : j)); + line[0].y += am; + line[1].y += am; + MwLine(handle, line, (c ? link : text)); } } } - handle->bgcolor = c ? text : NULL; - MwDrawText(handle, font, &p, l->text, MwALIGNMENT_BEGINNING, c ? base : text); - handle->bgcolor = NULL; + MwDrawText(handle, font, &p, l->text, MwALIGNMENT_BEGINNING, c ? link : text); break; } case MwDOCUMENT_UNDERLINE: @@ -191,6 +180,7 @@ static void draw(MwWidget handle) { if(IsFontChange(l->type)) font = l->font; } + MwFreeColor(link); MwFreeColor(text); MwFreeColor(base); } @@ -658,23 +648,23 @@ static void resize(MwWidget handle) { } MwClassRec MwDocumentClassRec = { - wcreate, /* create */ - destroy, /* destroy */ - draw, /* draw */ - click, /* click */ - NULL, /* parent_resize */ - prop_change, /* prop_change */ - mouse_move, /* mouse_move */ - NULL, /* mouse_up */ - NULL, /* mouse_down */ - NULL, /* key */ - NULL, /* execute */ - NULL, /* tick */ - resize, /* resize */ - NULL, /* children_update */ - NULL, /* children_prop_change */ - NULL, /* clipboard */ - NULL, /* props_change */ + wcreate, /* create */ + destroy, /* destroy */ + draw, /* draw */ + click, /* click */ + NULL, /* parent_resize */ + prop_change, /* prop_change */ + mouse_move, /* mouse_move */ + MwForceRender2, /* mouse_up */ + MwForceRender2, /* mouse_down */ + NULL, /* key */ + NULL, /* execute */ + NULL, /* tick */ + resize, /* resize */ + NULL, /* children_update */ + NULL, /* children_prop_change */ + NULL, /* clipboard */ + NULL, /* props_change */ NULL, NULL, NULL};