aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2019-09-04 15:04:39 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-09-05 22:03:21 -0600
commitb60ba847109f07f5e02a84a6e6f993e4a5684128 (patch)
tree3d7eb28ae374b4abf71ae6618c3b6ae220420d60 /ui
parentui: fix log view alternating row high-contrast theme switching issue (diff)
downloadwireguard-windows-b60ba847109f07f5e02a84a6e6f993e4a5684128.tar.xz
wireguard-windows-b60ba847109f07f5e02a84a6e6f993e4a5684128.zip
ui: syntax: xor colors with background
This makes syntax highlighting retain text contrast on black background (e.g. high-contrast mode) Maybe using a smarter arithmetic than XOR could be used to retain errors in red. They turn cyan on black background now. Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'ui')
-rw-r--r--ui/syntax/syntaxedit.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/ui/syntax/syntaxedit.c b/ui/syntax/syntaxedit.c
index 0050af4c..921cc7b6 100644
--- a/ui/syntax/syntaxedit.c
+++ b/ui/syntax/syntaxedit.c
@@ -141,6 +141,7 @@ static void highlight_text(HWND hWnd)
CHARRANGE orig_selection;
POINT original_scroll;
bool found_private_key = false;
+ COLORREF bg_color, bg_inversion;
if (this->highlight_guard)
return;
@@ -175,10 +176,13 @@ static void highlight_text(HWND hWnd)
SendMessage(hWnd, EM_GETSCROLLPOS, 0, (LPARAM)&original_scroll);
SendMessage(hWnd, EM_HIDESELECTION, TRUE, 0);
SendMessage(hWnd, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&format);
+ bg_color = GetSysColor(COLOR_WINDOW);
+ bg_inversion = (bg_color & RGB(0xFF, 0xFF, 0xFF)) ^ RGB(0xFF, 0xFF, 0xFF);
+ SendMessage(hWnd, EM_SETBKGNDCOLOR, 0, bg_color);
for (struct highlight_span *span = spans; span->type != HighlightEnd; ++span) {
CHARRANGE selection = { span->start, span->len + span->start };
SendMessage(hWnd, EM_EXSETSEL, 0, (LPARAM)&selection);
- format.crTextColor = stylemap[span->type].color;
+ format.crTextColor = stylemap[span->type].color ^ bg_inversion;
format.dwEffects = stylemap[span->type].effects;
SendMessage(hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
if (span->type == HighlightPrivateKey && !found_private_key) {
@@ -354,6 +358,9 @@ static LRESULT CALLBACK child_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lP
case WM_CONTEXTMENU:
context_menu(hWnd, LOWORD(lParam), HIWORD(lParam));
return 0;
+ case WM_THEMECHANGED:
+ highlight_text(hWnd);
+ break;
}
return parent_proc(hWnd, Msg, wParam, lParam);
}