respect theme_override
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
This commit is contained in:
parent
c7ec3b8023
commit
7efdde3b15
10 changed files with 70 additions and 62 deletions
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@
|
|||
#define MwNforeground "Sforeground"
|
||||
#define MwNsubForeground "SsubForeground"
|
||||
#define MwNtitleForeground "StitleForeground"
|
||||
#define MwNlinkForeground "SlinkForeground"
|
||||
|
||||
#define MwNvulkanExtension "SEvulkanExtension"
|
||||
#define MwNvulkanLayer "SEvulkanLayer"
|
||||
|
|
|
|||
|
|
@ -124,6 +124,7 @@
|
|||
<string name="foreground" common="yes" />
|
||||
<string name="subForeground" common="yes" />
|
||||
<string name="titleForeground" common="yes" />
|
||||
<string name="linkForeground" common="yes" />
|
||||
|
||||
<!-- Early string properties -->
|
||||
<string name="vulkanExtension" early="yes" />
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue