-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththeme.cpp
More file actions
148 lines (133 loc) · 5.1 KB
/
Copy paththeme.cpp
File metadata and controls
148 lines (133 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "theme.hpp"
#include <FL/Fl.H>
#include <FL/fl_draw.H>
#ifdef _WIN32
#include <dwmapi.h>
#else
#include <gio/gio.h>
#include <string.h>
#endif
bool is_dark_mode() {
#ifdef _WIN32
if (HKEY key; RegOpenKeyEx(
HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
0,
KEY_READ,
&key) == ERROR_SUCCESS) {
if (DWORD value, size = sizeof value; RegQueryValueExA(key, "AppsUseLightTheme", nullptr, nullptr, (LPBYTE) &value, &size) == ERROR_SUCCESS) {
RegCloseKey(key);
return !value;
}
RegCloseKey(key);
}
return false;
#else
// g_settings_new() and g_settings_get_string() abort the process rather than
// fail when the schema or key is missing, so neither may be called unguarded
GSettingsSchemaSource* source = g_settings_schema_source_get_default();
if (!source) {
return false;
}
GSettingsSchema* schema = g_settings_schema_source_lookup(source, "org.gnome.desktop.interface", TRUE);
if (!schema) {
return false;
}
bool has_key = g_settings_schema_has_key(schema, "color-scheme");
g_settings_schema_unref(schema);
if (!has_key) {
return false;
}
GSettings* settings = g_settings_new("org.gnome.desktop.interface");
char* theme = g_settings_get_string(settings, "color-scheme");
bool ret = strcmp(theme, "default") && strcmp(theme, "prefer-light");
g_free(theme);
g_object_unref(settings);
return ret;
#endif
}
static void draw_modern_frame(int x, int y, int w, int h, Fl_Color c) {
fl_begin_loop();
fl_vertex(x, y + 2);
fl_vertex(x + 2, y);
fl_vertex(x + w - 3, y);
fl_vertex(x + w - 1, y + 2);
fl_vertex(x + w - 1, y + h - 3);
fl_vertex(x + w - 3, y + h - 1);
fl_vertex(x + 2, y + h - 1);
fl_vertex(x, y + h - 3);
fl_end_loop();
}
static void draw_modern_box(int x, int y, int w, int h, Fl_Color bg, Fl_Color border) {
Fl::set_box_color(bg);
fl_begin_polygon();
fl_vertex(x, y + 2);
fl_vertex(x + 2, y);
fl_vertex(x + w - 3, y);
fl_vertex(x + w - 1, y + 2);
fl_vertex(x + w - 1, y + h - 3);
fl_vertex(x + w - 3, y + h - 1);
fl_vertex(x + 2, y + h - 1);
fl_vertex(x, y + h - 3);
fl_end_polygon();
Fl::set_box_color(border);
draw_modern_frame(x, y, w, h, border);
}
static void draw_dark_fltk_up_frame(int x, int y, int w, int h, Fl_Color c) {
Fl::set_box_color(fl_color_average(FL_WHITE, c, 0.15f));
draw_modern_frame(x, y, w, h, c);
}
static void draw_dark_fltk_up_box(int x, int y, int w, int h, Fl_Color c) {
Fl_Color bg = (c <= 255) ? fl_color_average(FL_WHITE, c, 0.06f) : c;
draw_modern_box(x, y, w, h, bg, fl_color_average(FL_WHITE, c, 0.16f));
}
static void draw_dark_fltk_down_frame(int x, int y, int w, int h, Fl_Color c) {
Fl::set_box_color(fl_color_average(FL_BLACK, c, 0.2f));
draw_modern_frame(x, y, w, h, c);
}
static void draw_dark_fltk_down_box(int x, int y, int w, int h, Fl_Color c) {
draw_modern_box(x, y, w, h, c, fl_color_average(FL_WHITE, c, 0.12f));
}
static void draw_light_fltk_up_frame(int x, int y, int w, int h, Fl_Color c) {
Fl::set_box_color(fl_color_average(FL_BLACK, c, 0.2f));
draw_modern_frame(x, y, w, h, c);
}
static void draw_light_fltk_up_box(int x, int y, int w, int h, Fl_Color c) {
Fl_Color bg = (c <= 255) ? fl_color_average(FL_WHITE, c, 0.4f) : c;
draw_modern_box(x, y, w, h, bg, fl_color_average(FL_BLACK, c, 0.2f));
}
static void draw_light_fltk_down_frame(int x, int y, int w, int h, Fl_Color c) {
Fl::set_box_color(fl_color_average(FL_BLACK, c, 0.3f));
draw_modern_frame(x, y, w, h, c);
}
static void draw_light_fltk_down_box(int x, int y, int w, int h, Fl_Color c) {
draw_modern_box(x, y, w, h, c, fl_color_average(FL_BLACK, c, 0.25f));
}
void configure_fltk_colors() {
Fl::scheme("gtk+");
if (is_dark_mode()) {
Fl::set_boxtype(FL_UP_BOX, draw_dark_fltk_up_box, 2, 2, 4, 4);
Fl::set_boxtype(FL_UP_FRAME, draw_dark_fltk_up_frame, 2, 2, 4, 4);
Fl::set_boxtype(FL_DOWN_BOX, draw_dark_fltk_down_box, 2, 2, 4, 4);
Fl::set_boxtype(FL_DOWN_FRAME, draw_dark_fltk_down_frame, 2, 2, 4, 4);
Fl::foreground(245, 245, 245);
Fl::background(40, 40, 40);
Fl::background2(24, 24, 24);
} else {
Fl::set_boxtype(FL_UP_BOX, draw_light_fltk_up_box, 2, 2, 4, 4);
Fl::set_boxtype(FL_UP_FRAME, draw_light_fltk_up_frame, 2, 2, 4, 4);
Fl::set_boxtype(FL_DOWN_BOX, draw_light_fltk_down_box, 2, 2, 4, 4);
Fl::set_boxtype(FL_DOWN_FRAME, draw_light_fltk_down_frame, 2, 2, 4, 4);
Fl::foreground(32, 32, 32);
Fl::background(235, 235, 235);
Fl::background2(255, 255, 255);
fl_contrast_level(50);
}
Fl::set_color(FL_SELECTION_COLOR, 0, 120, 215);
}
#ifdef _WIN32
void set_window_dark_mode(HWND window, bool value) {
BOOL use_immersive_dark_mode = value;
DwmSetWindowAttribute(window, DWMWA_USE_IMMERSIVE_DARK_MODE, &use_immersive_dark_mode, sizeof use_immersive_dark_mode);
}
#endif