Skip to content

Commit

Permalink
Use custom colors as dark mode.
Browse files Browse the repository at this point in the history
A new configuration option `use_custom_as_dark` which if set uses the
custom color mode as dark mode.
  • Loading branch information
isaksamsten committed Mar 25, 2024
1 parent 9a9b961 commit dc23b27
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
9 changes: 9 additions & 0 deletions pdf_viewer/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extern bool HOVER_OVERVIEW;
//extern bool AUTO_EMBED_ANNOTATIONS;
extern bool DEFAULT_DARK_MODE;
extern bool USE_SYSTEM_THEME;
extern bool USE_CUSTOM_AS_DARK;
extern float HIGHLIGHT_COLORS[26 * 3];
extern std::wstring SEARCH_URLS[26];
extern std::wstring EXECUTE_COMMANDS[26];
Expand Down Expand Up @@ -716,6 +717,14 @@ ConfigManager::ConfigManager(const Path& default_path, const Path& auto_path, co
bool_deserializer,
bool_validator
});
configs.push_back({
L"use_custom_as_dark",
ConfigType::Bool,
&USE_CUSTOM_AS_DARK,
bool_serializer,
bool_deserializer,
bool_validator
});
configs.push_back({
L"render_freetext_borders",
ConfigType::Bool,
Expand Down
1 change: 1 addition & 0 deletions pdf_viewer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ bool SHOULD_USE_MULTIPLE_MONITORS = false;
bool SHOULD_CHECK_FOR_LATEST_VERSION_ON_STARTUP = false;
bool DEFAULT_DARK_MODE = false;
bool USE_SYSTEM_THEME = false;
bool USE_CUSTOM_AS_DARK = false;
bool SORT_BOOKMARKS_BY_LOCATION = true;
std::wstring LIBGEN_ADDRESS = L"";
std::wstring GOOGLE_SCHOLAR_ADDRESS = L"";
Expand Down
27 changes: 18 additions & 9 deletions pdf_viewer/main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ extern int NUM_CACHED_PAGES;
extern bool IGNORE_SCROLL_EVENTS;
extern bool DONT_FOCUS_IF_SYNCTEX_RECT_IS_VISIBLE;
extern bool USE_SYSTEM_THEME;
extern bool USE_CUSTOM_AS_DARK;

extern bool SHOW_RIGHT_CLICK_CONTEXT_MENU;
extern std::wstring CONTEXT_MENU_ITEMS;
Expand Down Expand Up @@ -3747,10 +3748,14 @@ CommandManager* MainWidget::get_command_manager() {
}

void MainWidget::toggle_dark_mode() {
this->opengl_widget->toggle_dark_mode();
if (USE_CUSTOM_AS_DARK) {
toggle_custom_color_mode();
} else {
this->opengl_widget->toggle_dark_mode();

if (helper_opengl_widget_) {
helper_opengl_widget_->toggle_dark_mode();
if (helper_opengl_widget_) {
helper_opengl_widget_->toggle_dark_mode();
}
}
}

Expand Down Expand Up @@ -6771,12 +6776,16 @@ int MainWidget::get_current_colorscheme_index() {
}

void MainWidget::set_dark_mode() {
if (opengl_widget->get_current_color_mode() != PdfViewOpenGLWidget::ColorPalette::Dark) {
opengl_widget->set_dark_mode(true);
}
if (helper_opengl_widget_) {
if (helper_opengl_widget_->get_current_color_mode() != PdfViewOpenGLWidget::ColorPalette::Dark) {
helper_opengl_widget_->set_dark_mode(true);
if (USE_CUSTOM_AS_DARK) {
set_custom_color_mode();
} else{
if (opengl_widget->get_current_color_mode() != PdfViewOpenGLWidget::ColorPalette::Dark) {
opengl_widget->set_dark_mode(true);
}
if (helper_opengl_widget_) {
if (helper_opengl_widget_->get_current_color_mode() != PdfViewOpenGLWidget::ColorPalette::Dark) {
helper_opengl_widget_->set_dark_mode(true);
}
}
}
}
Expand Down

0 comments on commit dc23b27

Please sign in to comment.