mirror of
https://github.com/webui-dev/webui.git
synced 2024-09-11 22:17:13 +03:00
Update high contrast
This commit is contained in:
parent
8e8abd2273
commit
acc77ce5d2
@ -279,23 +279,24 @@ WEBUI_EXPORT bool webui_show_wv(size_t window, const char* content);
|
||||
WEBUI_EXPORT void webui_set_kiosk(size_t window, bool status);
|
||||
|
||||
/**
|
||||
* @brief Set the window high contrast support. It would be useful when default high contrast support of browser is not working fine or you want to build better high contrast theme by CSS.
|
||||
* @brief Set the window with high-contrast support. Useful when you want to
|
||||
* build a better high-contrast theme with CSS.
|
||||
*
|
||||
* @param window The window number
|
||||
* @param status True or False
|
||||
*
|
||||
* @example webui_set_high_contrast_support(myWindow, true);
|
||||
* @example webui_set_high_contrast(myWindow, true);
|
||||
*/
|
||||
WEBUI_EXPORT void webui_set_high_contrast_support(size_t window, bool status);
|
||||
WEBUI_EXPORT void webui_set_high_contrast(size_t window, bool status);
|
||||
|
||||
/**
|
||||
* @brief Get user high contrast preference.
|
||||
* @brief Get OS high contrast preference.
|
||||
*
|
||||
* @return Returns True if user is using high contrast theme
|
||||
* @return Returns True if OS is using high contrast theme
|
||||
*
|
||||
* @example webui_user_prefers_high_contrast();
|
||||
* @example bool hc = webui_is_high_contrast();
|
||||
*/
|
||||
bool webui_user_prefers_high_contrast();
|
||||
WEBUI_EXPORT bool webui_is_high_contrast();
|
||||
|
||||
/**
|
||||
* @brief Wait until all opened windows get closed.
|
||||
|
75
src/webui.c
75
src/webui.c
@ -303,7 +303,7 @@ typedef struct _webui_window_t {
|
||||
bool has_events;
|
||||
char* server_root_path;
|
||||
bool kiosk_mode;
|
||||
bool disable_high_contrast_support;
|
||||
bool disable_browser_high_contrast;
|
||||
bool hide;
|
||||
int width;
|
||||
int height;
|
||||
@ -900,10 +900,10 @@ void webui_set_kiosk(size_t window, bool status) {
|
||||
win->kiosk_mode = status;
|
||||
}
|
||||
|
||||
void webui_set_high_contrast_support(size_t window, bool status) {
|
||||
void webui_set_high_contrast(size_t window, bool status) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[User] webui_set_high_contrast_support([%zu])\n", window);
|
||||
printf("[User] webui_set_high_contrast([%zu], [%d])\n", window, status);
|
||||
#endif
|
||||
|
||||
// Initialization
|
||||
@ -914,13 +914,13 @@ void webui_set_high_contrast_support(size_t window, bool status) {
|
||||
return;
|
||||
_webui_window_t * win = _webui_core.wins[window];
|
||||
|
||||
win->disable_high_contrast_support = !status;
|
||||
win->disable_browser_high_contrast = !status;
|
||||
}
|
||||
|
||||
bool webui_user_prefers_high_contrast() {
|
||||
bool webui_is_high_contrast() {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[User] webui_set_high_contrast_support()\n");
|
||||
printf("[User] webui_is_high_contrast()\n");
|
||||
#endif
|
||||
|
||||
// Initialization
|
||||
@ -929,33 +929,42 @@ bool webui_user_prefers_high_contrast() {
|
||||
bool is_enabled = false;
|
||||
|
||||
#ifdef _WIN32
|
||||
char high_contrast_flags_as_char[WEBUI_MAX_PATH];
|
||||
|
||||
_webui_get_windows_reg_value(
|
||||
char hc[WEBUI_MAX_PATH];
|
||||
if (_webui_get_windows_reg_value(
|
||||
HKEY_CURRENT_USER,
|
||||
L"Control Panel\\Accessibility\\"
|
||||
L"HighContrast",
|
||||
L"Flags", high_contrast_flags_as_char
|
||||
);
|
||||
|
||||
int high_contrast_flags = atoi(high_contrast_flags_as_char);
|
||||
|
||||
is_enabled = (high_contrast_flags & 0x01) == 1;
|
||||
|
||||
L"Control Panel\\Accessibility\\HighContrast",
|
||||
L"Flags",
|
||||
hc))
|
||||
{
|
||||
long flags = strtol(hc, NULL, 10);
|
||||
if (flags != LONG_MIN && flags != LONG_MAX) {
|
||||
is_enabled = ((flags & 0x01) == 1);
|
||||
}
|
||||
}
|
||||
#elif __linux__
|
||||
FILE* process_output;
|
||||
char buf[100];
|
||||
|
||||
char buf[128];
|
||||
process_output = popen("gsettings get org.gnome.desktop.a11y.interface high-contrast", "r");
|
||||
if (process_output != NULL && fgets(buf, sizeof(buf), process_output) != NULL) { // Running the command is not failed and fgets works correctly
|
||||
is_enabled = strstr(buf, "true") != NULL;
|
||||
if (process_output != NULL) {
|
||||
if (fgets(buf, sizeof(buf), process_output) != NULL) {
|
||||
is_enabled = (strstr(buf, "true") != NULL);
|
||||
}
|
||||
pclose(process_output);
|
||||
}
|
||||
#else
|
||||
FILE* process_output;
|
||||
char buf[128];
|
||||
process_output = popen("defaults read -g AppleInterfaceStyle", "r");
|
||||
if (process_output != NULL) {
|
||||
if (fgets(buf, sizeof(buf), process_output) != NULL) {
|
||||
is_enabled = (strstr(buf, "Dark") != NULL);
|
||||
}
|
||||
pclose(process_output);
|
||||
}
|
||||
|
||||
pclose(process_output);
|
||||
#endif
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[User] webui_set_high_contrast_support() -> %d", is_enabled);
|
||||
printf("[User] webui_is_high_contrast() -> %d\n", is_enabled);
|
||||
#endif
|
||||
|
||||
return is_enabled;
|
||||
@ -4350,7 +4359,7 @@ static bool _webui_browser_create_new_profile(_webui_window_t * win, size_t brow
|
||||
_webui_free_mem((void * ) win->profile_path);
|
||||
win->profile_path = (char*)_webui_malloc(WEBUI_MAX_PATH);
|
||||
win->profile_name = (char*)_webui_malloc(WEBUI_MAX_PATH);
|
||||
if(!win->disable_high_contrast_support)
|
||||
if(!win->disable_browser_high_contrast)
|
||||
WEBUI_SCOPY_DYN(win->profile_name, WEBUI_MAX_PATH, WEBUI_PROFILE_NAME);
|
||||
else
|
||||
WEBUI_SCOPY_DYN(win->profile_name, WEBUI_MAX_PATH, WEBUI_PROFILE_NAME "-NoHC");
|
||||
@ -4429,10 +4438,10 @@ static bool _webui_browser_create_new_profile(_webui_window_t * win, size_t brow
|
||||
const char* path_ini = "~/Library/Application Support/Firefox/profiles.ini";
|
||||
#endif
|
||||
if (!win->custom_profile){
|
||||
if(!win->disable_high_contrast_support)
|
||||
if(!win->disable_browser_high_contrast)
|
||||
WEBUI_SPF_DYN(win->profile_path, WEBUI_MAX_PATH, "%s%s.WebUI%sWebUIFirefoxProfile", temp, webui_sep, webui_sep);
|
||||
else
|
||||
WEBUI_SPF_DYN(win->profile_path, WEBUI_MAX_PATH, "%s%s.WebUI%sWebUIFirefoxNoHighContrastProfile", temp, webui_sep, webui_sep);
|
||||
WEBUI_SPF_DYN(win->profile_path, WEBUI_MAX_PATH, "%s%s.WebUI%sWebUIFirefoxProfile-NoHC", temp, webui_sep, webui_sep);
|
||||
}
|
||||
|
||||
if (!_webui_folder_exist(win->profile_path) ||
|
||||
@ -4484,7 +4493,7 @@ static bool _webui_browser_create_new_profile(_webui_window_t * win, size_t brow
|
||||
fputs("user_pref(\"browser.shell.checkDefaultBrowser\", false); ", file);
|
||||
fputs("user_pref(\"browser.tabs.warnOnClose\", false); ", file);
|
||||
fputs("user_pref(\"browser.tabs.inTitlebar\", 0); ", file);
|
||||
if(win->disable_high_contrast_support){
|
||||
if(win->disable_browser_high_contrast){
|
||||
fputs("user_pref(\"browser.display.document_color_use\", 1); ", file);
|
||||
}
|
||||
fclose(file);
|
||||
@ -4501,8 +4510,8 @@ static bool _webui_browser_create_new_profile(_webui_window_t * win, size_t brow
|
||||
if (file == NULL)
|
||||
return false;
|
||||
fputs(
|
||||
"#navigator-toolbox{opacity:0 !important; height:0px !important; max-height:0px !important;"
|
||||
"width:0px !important; max-width:0px !important;}"
|
||||
"#navigator-toolbox{opacity:0 !important; height:0px !important; max-height:0px !important;"
|
||||
"width:0px !important; max-width:0px !important;}"
|
||||
, file);
|
||||
fclose(file);
|
||||
}
|
||||
@ -5550,7 +5559,7 @@ static int _webui_get_browser_args(_webui_window_t * win, size_t browser, char*
|
||||
"--disable-sync-preferences",
|
||||
"--disable-component-update",
|
||||
"--allow-insecure-localhost",
|
||||
"--auto-accept-camera-and-microphone-capture",
|
||||
"--auto-accept-camera-and-microphone-capture",
|
||||
};
|
||||
|
||||
int c = 0;
|
||||
@ -5573,7 +5582,7 @@ static int _webui_get_browser_args(_webui_window_t * win, size_t browser, char*
|
||||
if (win->kiosk_mode)
|
||||
c += WEBUI_SPF_DYN(buffer + c, len, " %s", "--chrome-frame --kiosk");
|
||||
// High Contrast Support
|
||||
if (win->disable_high_contrast_support)
|
||||
if (win->disable_browser_high_contrast)
|
||||
c += WEBUI_SPF_DYN(buffer + c, len, " %s", "--disable-features=ForcedColors");
|
||||
// Hide Mode
|
||||
if (win->hide)
|
||||
|
Loading…
Reference in New Issue
Block a user