Skip to content

Commit

Permalink
Add support for "macos_dark_titlebar_color"
Browse files Browse the repository at this point in the history
  • Loading branch information
isaksamsten committed Jun 4, 2024
1 parent a3aeca4 commit d280bd1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pdf_viewer/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ bool ADJUST_ANNOTATION_COLORS_FOR_DARK_MODE = true;

#ifdef Q_OS_MACOS
float MACOS_TITLEBAR_COLOR[3] = { -1.0f, -1.0f, -1.0f };
float MACOS_DARK_TITLEBAR_COLOR[3] = {-1.0f, -1.0f, -1.0f};
bool MACOS_HIDE_TITLEBAR = false;
#endif

Expand Down Expand Up @@ -1088,6 +1089,7 @@ ConfigManager::ConfigManager(const Path& default_path, const Path& auto_path, co

#ifdef Q_OS_MACOS
add_color3(L"macos_titlebar_color", MACOS_TITLEBAR_COLOR);
add_color3(L"macos_dark_titlebar_color", MACOS_DARK_TITLEBAR_COLOR);
add_bool(L"macos_hide_titlebar", &MACOS_HIDE_TITLEBAR);
#endif

Expand Down
25 changes: 22 additions & 3 deletions pdf_viewer/main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ const unsigned int INTERVAL_TIME = 200;

#ifdef Q_OS_MACOS
extern float MACOS_TITLEBAR_COLOR[3];
extern float MACOS_DARK_TITLEBAR_COLOR[3];
extern bool MACOS_HIDE_TITLEBAR;
#endif

Expand Down Expand Up @@ -1226,7 +1227,11 @@ MainWidget::MainWidget(fz_context* mupdf_context,
#ifdef Q_OS_MACOS
// only apply titlebar menu if the user has specifically changed it in settings
if (MACOS_TITLEBAR_COLOR[0] >= 0){
changeTitlebarColor(winId(), MACOS_TITLEBAR_COLOR[0], MACOS_TITLEBAR_COLOR[1], MACOS_TITLEBAR_COLOR[2], 1.0f);
float *titlebar_colors = MACOS_TITLEBAR_COLOR;
if(opengl_widget->get_current_color_mode() != PdfViewOpenGLWidget::ColorPalette::Normal && MACOS_DARK_TITLEBAR_COLOR[0] >= 0) {
titlebar_colors = MACOS_DARK_TITLEBAR_COLOR;
}
changeTitlebarColor(winId(), titlebar_colors[0], titlebar_colors[1], titlebar_colors[2], 1.0f);
}

if (MACOS_HIDE_TITLEBAR) {
Expand Down Expand Up @@ -6825,6 +6830,16 @@ void MainWidget::set_color_mode_to_system_theme() {
set_dark_mode();
}
}
#ifdef Q_OS_MACOS
if (MACOS_TITLEBAR_COLOR[0] >= 0){
float *titlebar_colors = MACOS_TITLEBAR_COLOR;
if(opengl_widget->get_current_color_mode() != PdfViewOpenGLWidget::ColorPalette::Normal && MACOS_DARK_TITLEBAR_COLOR[0] >= 0) {
titlebar_colors = MACOS_DARK_TITLEBAR_COLOR;
}
changeTitlebarColor(winId(), titlebar_colors[0], titlebar_colors[1], titlebar_colors[2], 1.0f);
}
#endif

}
#endif
}
Expand Down Expand Up @@ -7436,8 +7451,12 @@ void MainWidget::on_configs_changed(std::vector<std::string>* config_names) {
for (int i = 0; i < config_names->size(); i++) {
QString confname = QString::fromStdString((*config_names)[i]);
#ifdef Q_OS_MACOS
if (confname == "macos_titlebar_color"){
changeTitlebarColor(winId(), MACOS_TITLEBAR_COLOR[0], MACOS_TITLEBAR_COLOR[1], MACOS_TITLEBAR_COLOR[2], 1.0f);
if (confname == "macos_titlebar_color" || confname == "macos_dark_titlebar_color"){
float *titlebar_colors = MACOS_TITLEBAR_COLOR;
if(opengl_widget->get_current_color_mode() != PdfViewOpenGLWidget::ColorPalette::Normal && MACOS_DARK_TITLEBAR_COLOR[0] >= 0) {
titlebar_colors = MACOS_DARK_TITLEBAR_COLOR;
}
changeTitlebarColor(winId(), titlebar_colors[0], titlebar_colors[1], titlebar_colors[2], 1.0f);
}
#endif
if (confname == "use_system_theme") {
Expand Down

0 comments on commit d280bd1

Please sign in to comment.