mirror of
https://github.com/webui-dev/webui.git
synced 2024-09-11 22:17:13 +03:00
Support to disable default high contrast of browser.
This commit is contained in:
parent
f40d35a60b
commit
3bdacf4c12
@ -278,6 +278,16 @@ 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.
|
||||
*
|
||||
* @param window The window number
|
||||
* @param status True or False
|
||||
*
|
||||
* @example webui_set_high_contrast_support(myWindow, true);
|
||||
*/
|
||||
WEBUI_EXPORT void webui_set_high_contrast_support(size_t window, bool status);
|
||||
|
||||
/**
|
||||
* @brief Wait until all opened windows get closed.
|
||||
*
|
||||
|
37
src/webui.c
37
src/webui.c
@ -303,6 +303,7 @@ typedef struct _webui_window_t {
|
||||
bool has_events;
|
||||
char* server_root_path;
|
||||
bool kiosk_mode;
|
||||
bool disable_high_contrast_support;
|
||||
bool hide;
|
||||
int width;
|
||||
int height;
|
||||
@ -899,6 +900,23 @@ void webui_set_kiosk(size_t window, bool status) {
|
||||
win->kiosk_mode = status;
|
||||
}
|
||||
|
||||
void webui_set_high_contrast_support(size_t window, bool status) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[User] webui_set_high_contrast_support([%zu])\n", window);
|
||||
#endif
|
||||
|
||||
// Initialization
|
||||
_webui_init();
|
||||
|
||||
// Dereference
|
||||
if (_webui_mutex_is_exit_now(WEBUI_MUTEX_NONE) || _webui_core.wins[window] == NULL)
|
||||
return;
|
||||
_webui_window_t * win = _webui_core.wins[window];
|
||||
|
||||
win->disable_high_contrast_support = !status;
|
||||
}
|
||||
|
||||
void webui_close(size_t window) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
@ -4288,7 +4306,10 @@ 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);
|
||||
WEBUI_SCOPY_DYN(win->profile_name, WEBUI_MAX_PATH, WEBUI_PROFILE_NAME);
|
||||
if(!win->disable_high_contrast_support)
|
||||
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");
|
||||
}
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
@ -4363,8 +4384,12 @@ static bool _webui_browser_create_new_profile(_webui_window_t * win, size_t brow
|
||||
// macOS
|
||||
const char* path_ini = "~/Library/Application Support/Firefox/profiles.ini";
|
||||
#endif
|
||||
if (!win->custom_profile)
|
||||
WEBUI_SPF_DYN(win->profile_path, WEBUI_MAX_PATH, "%s%s.WebUI%sWebUIFirefoxProfile", temp, webui_sep, webui_sep);
|
||||
if (!win->custom_profile){
|
||||
if(!win->disable_high_contrast_support)
|
||||
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);
|
||||
}
|
||||
|
||||
if (!_webui_folder_exist(win->profile_path) ||
|
||||
!_webui_is_firefox_ini_profile_exist(path_ini, win->profile_name)) {
|
||||
@ -4415,6 +4440,9 @@ 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){
|
||||
fputs("user_pref(\"browser.display.document_color_use\", 1); ", file);
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
// userChrome.css
|
||||
@ -5497,6 +5525,9 @@ static int _webui_get_browser_args(_webui_window_t * win, size_t browser, char*
|
||||
// Kiosk Mode
|
||||
if (win->kiosk_mode)
|
||||
c += WEBUI_SPF_DYN(buffer + c, len, " %s", "--chrome-frame --kiosk");
|
||||
// High Contrast Support
|
||||
if (win->disable_high_contrast_support)
|
||||
c += WEBUI_SPF_DYN(buffer + c, len, " %s", "--disable-features=ForcedColors");
|
||||
// Hide Mode
|
||||
if (win->hide)
|
||||
c += WEBUI_SPF_DYN(buffer + c, len, " %s", "--headless --headless=new");
|
||||
|
Loading…
Reference in New Issue
Block a user