Making pseudo-HiDPI tweaks optional, disabled by default

(see issue #5276)
This commit is contained in:
Hombre57
2019-04-14 16:58:11 +02:00
parent ace5a01136
commit 89e63639be
9 changed files with 41 additions and 18 deletions

View File

@@ -1036,6 +1036,7 @@ PREFERENCES_APPEARANCE_COLORPICKERFONT;Police des ancres de vérification couleu
PREFERENCES_APPEARANCE_CROPMASKCOLOR;Couleur du masque de recadrage
PREFERENCES_APPEARANCE_MAINFONT;Police principale
PREFERENCES_APPEARANCE_NAVGUIDECOLOR;Couleur du cadre dans le Navigateur
PREFERENCES_APPEARANCE_PSEUDOHIDPI;Mode pseudo-HiDPI
PREFERENCES_APPEARANCE_THEME;Thème
PREFERENCES_APPLNEXTSTARTUP;appliqué au prochain lancement
PREFERENCES_AUTOMONPROFILE;Utiliser automatiquement le profil de l'écran principal

View File

@@ -1039,6 +1039,7 @@ PREFERENCES_APPEARANCE_COLORPICKERFONT;Color picker font
PREFERENCES_APPEARANCE_CROPMASKCOLOR;Crop mask color
PREFERENCES_APPEARANCE_MAINFONT;Main font
PREFERENCES_APPEARANCE_NAVGUIDECOLOR;Navigator guide color
PREFERENCES_APPEARANCE_PSEUDOHIDPI;Pseudo-HiDPI mode
PREFERENCES_APPEARANCE_THEME;Theme
PREFERENCES_APPLNEXTSTARTUP;restart required
PREFERENCES_AUTOMONPROFILE;Use operating system's main monitor color profile

View File

@@ -375,14 +375,6 @@ int main (int argc, char **argv)
Glib::init(); // called by Gtk::Main, but this may be important for thread handling, so we call it ourselves now
Gio::init ();
// Reading/updating GDK_SCALE early if it exists
const gchar *gscale = g_getenv("GDK_SCALE");
if (gscale && gscale[0] == '2') {
initialGdkScale = 2;
}
// HOMBRE: On Windows, if resolution is set to 200%, Gtk internal variables are SCALE=2 and DPI=96
g_setenv("GDK_SCALE", "1", true);
#ifdef WIN32
if (GetFileType (GetStdHandle (STD_OUTPUT_HANDLE)) == 0x0003) {
// started from msys2 console => do not buffer stdout
@@ -536,6 +528,16 @@ int main (int argc, char **argv)
int ret = 0;
if (options.pseudoHiDPISupport) {
// Reading/updating GDK_SCALE early if it exists
const gchar *gscale = g_getenv("GDK_SCALE");
if (gscale && gscale[0] == '2') {
initialGdkScale = 2;
}
// HOMBRE: On Windows, if resolution is set to 200%, Gtk internal variables are SCALE=2 and DPI=96
g_setenv("GDK_SCALE", "1", true);
}
gdk_threads_set_lock_functions (G_CALLBACK (myGdkLockEnter), (G_CALLBACK (myGdkLockLeave)));
gdk_threads_init();
gtk_init (&argc, &argv); // use the "--g-fatal-warnings" command line flag to make warnings fatal

View File

@@ -345,6 +345,7 @@ void Options::setDefaults()
fontSize = 10;
CPFontFamily = "default";
CPFontSize = 8;
pseudoHiDPISupport = false;
lastScale = 5;
lastShowAllExif = false;
panAccelFactor = 5;
@@ -1252,6 +1253,10 @@ void Options::readFromFile(Glib::ustring fname)
CPFontSize = keyFile.get_integer("GUI", "CPFontSize");
}
if (keyFile.has_key("GUI", "ScaledIcons")) {
pseudoHiDPISupport = keyFile.get_boolean("GUI", "PseudoHiDPISupport");
}
if (keyFile.has_key("GUI", "LastPreviewScale")) {
lastScale = keyFile.get_integer("GUI", "LastPreviewScale");
}
@@ -2062,6 +2067,7 @@ void Options::saveToFile(Glib::ustring fname)
keyFile.set_integer("GUI", "FontSize", fontSize);
keyFile.set_string("GUI", "CPFontFamily", CPFontFamily);
keyFile.set_integer("GUI", "CPFontSize", CPFontSize);
keyFile.set_boolean("GUI", "PseudoHiDPISupport", pseudoHiDPISupport);
keyFile.set_integer("GUI", "LastPreviewScale", lastScale);
keyFile.set_boolean("GUI", "LastShowAllExif", lastShowAllExif);
keyFile.set_integer("GUI", "PanAccelFactor", panAccelFactor);

View File

@@ -212,6 +212,7 @@ public:
int fontSize; // RT's main font size (units: pt)
Glib::ustring CPFontFamily; // ColorPicker font family
int CPFontSize; // ColorPicker font size (units: pt)
bool pseudoHiDPISupport;
bool fbOnlyRaw;
bool fbShowDateTime;
bool fbShowBasicExif;

View File

@@ -1048,6 +1048,9 @@ Gtk::Widget* Preferences::getGeneralPanel ()
navGuideColorCB = Gtk::manage(new Gtk::ColorButton());
navGuideColorCB->set_use_alpha(true);
pseudoHiDPI = Gtk::manage(new Gtk::CheckButton(M("PREFERENCES_APPEARANCE_PSEUDOHIDPI") + Glib::ustring (" (") + M ("PREFERENCES_APPLNEXTSTARTUP") + ")"));
setExpandAlignProperties(pseudoHiDPI, false, false, Gtk::ALIGN_START, Gtk::ALIGN_BASELINE);
Gtk::VSeparator *vSep = Gtk::manage(new Gtk::VSeparator());
appearanceGrid->attach(*themeLbl, 0, 0, 1, 1);
@@ -1062,6 +1065,7 @@ Gtk::Widget* Preferences::getGeneralPanel ()
appearanceGrid->attach(*colorPickerFontFB, 1, 2, 1, 1);
appearanceGrid->attach(*navGuideColorLbl, 3, 2, 1, 1);
appearanceGrid->attach(*navGuideColorCB, 4, 2, 1, 1);
appearanceGrid->attach(*pseudoHiDPI, 0, 3, 5, 1);
appearanceFrame->add(*appearanceGrid);
vbGeneral->attach_next_to(*appearanceFrame, *flang, Gtk::POS_BOTTOM, 2, 1);
@@ -1642,6 +1646,8 @@ void Preferences::storePreferences ()
moptions.CPFontSize = cpfd.get_size() / Pango::SCALE;
}
moptions.pseudoHiDPISupport = pseudoHiDPI->get_active();
#ifdef WIN32
moptions.gimpDir = gimpDir->get_filename ();
moptions.psDir = psDir->get_filename ();
@@ -1906,6 +1912,8 @@ void Preferences::fillPreferences ()
colorPickerFontFB->set_font_name (Glib::ustring::compose ("%1 %2", options.CPFontFamily, options.CPFontSize));
}
pseudoHiDPI->set_active(options.pseudoHiDPISupport);
showDateTime->set_active (moptions.fbShowDateTime);
showBasicExif->set_active (moptions.fbShowBasicExif);
showExpComp->set_active (moptions.fbShowExpComp);

View File

@@ -145,6 +145,8 @@ class Preferences : public Gtk::Dialog, public ProfileStoreListener
Gtk::FontButton* colorPickerFontFB;
Gtk::ColorButton* cropMaskColorCB;
Gtk::ColorButton* navGuideColorCB;
Gtk::CheckButton* pseudoHiDPI;
Gtk::SpinButton* maxRecentFolders;
Gtk::SpinButton* maxThumbHeightSB;

View File

@@ -36,6 +36,12 @@ Gtk::TextDirection RTScalable::direction = Gtk::TextDirection::TEXT_DIR_NONE;
void RTScalable::setDPInScale (const double newDPI, const int newScale)
{
if (!options.pseudoHiDPISupport) {
scale = 1;
dpi = baseDPI;
return;
}
if (scale != newScale || (scale == 1 && dpi != newDPI)) {
// reload all images
scale = newScale;

View File

@@ -106,12 +106,6 @@ RTWindow::RTWindow ()
Gtk::Settings::get_for_screen (screen)->property_gtk_theme_name() = "Adwaita";
Gtk::Settings::get_for_screen (screen)->property_gtk_application_prefer_dark_theme() = true;
#if defined(__APPLE__)
// This will force screen resolution regarding font, but I don't think it's compliant with Gtk guidelines...
// Do not confuse with screen scaling, where everything is scaled up !
screen->set_resolution (RTScalable::baseDPI);
#endif
Glib::RefPtr<Glib::Regex> regex = Glib::Regex::create (THEMEREGEXSTR, Glib::RegexCompileFlags::REGEX_CASELESS);
Glib::ustring filename;
Glib::MatchInfo mInfo;
@@ -170,7 +164,9 @@ RTWindow::RTWindow ()
css = Glib::ustring::compose ("* { font-family: %1; font-size: %2pt}", options.fontFamily, options.fontSize * (int)initialGdkScale);
#endif
//GTK318
if (options.pseudoHiDPISupport) {
fontScale = options.fontSize / (float)RTScalable::baseFontSize;
}
if (options.rtSettings.verbose) {
printf("\"Non-Default\" font size(%d) * scale(%d) / fontScale(%.3f)\n", options.fontSize, (int)initialGdkScale, fontScale);
}
@@ -196,15 +192,15 @@ RTWindow::RTWindow ()
} else {
pt = fontSize / Pango::SCALE;
}
if (options.pseudoHiDPISupport) {
fontScale = (float)pt / (float)RTScalable::baseFontSize;
}
if ((int)initialGdkScale > 1 || pt != RTScalable::baseFontSize) {
css = Glib::ustring::compose ("* { font-size: %1pt}", pt * (int)initialGdkScale);
if (options.rtSettings.verbose) {
printf("\"Default\" font size(%d) * scale(%d) / fontScale(%.3f)\n", pt, (int)initialGdkScale, fontScale);
}
}
} else {
fontScale = 1.f;
}
}
if (!css.empty()) {