From c2e652ef388b4c1bd005d42326c912175e9ec24c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 1 Sep 2018 03:05:51 +0200 Subject: [PATCH 1/4] Add HiDPI improvements allowing set app scale and text scale and scaling icons --- src/helper/icon-loader.cpp | 3 +++ src/inkscape.cpp | 22 +++++++++++++++++++++- src/main.cpp | 5 ++--- src/ui/dialog/inkscape-preferences.cpp | 5 +++++ src/ui/dialog/inkscape-preferences.h | 2 ++ 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/helper/icon-loader.cpp b/src/helper/icon-loader.cpp index 2e65ae019c..b36d58e97c 100644 --- a/src/helper/icon-loader.cpp +++ b/src/helper/icon-loader.cpp @@ -35,6 +35,9 @@ Glib::RefPtr sp_get_icon_pixbuf(Glib::ustring icon_name, gint size) icon_theme->prepend_search_path(get_path_ustring(SYSTEM, ICONS)); icon_theme->prepend_search_path(get_path_ustring(USER, ICONS)); } + double original_scale = atof(g_getenv("GDK_SCALE") ? g_getenv("GDK_SCALE") : "1"); + double scale = prefs->getDouble("/theme/gdkScale", original_scale); + size *= scale; try { if (prefs->getBool("/theme/symbolicIcons", false)) { gchar colornamed[64]; diff --git a/src/inkscape.cpp b/src/inkscape.cpp index 67bedb1f8b..e8bad73602 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -427,6 +427,22 @@ Application::add_style_sheet() } } +static void set_scale_env() +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + double original_scale = atof(g_getenv("GDK_SCALE") ? g_getenv("GDK_SCALE") : "1"); + double scale_value = prefs->getDouble("/theme/gdkScale", original_scale); + const gchar *gdk_scale = std::to_string(scale_value).c_str(); + g_setenv("GDK_SCALE", gdk_scale, TRUE); + double original_scale_dpi = atof(g_getenv("GDK_DPI_SCALE") ? g_getenv("GDK_DPI_SCALE") : "1"); + double scale_dpi_value = prefs->getDouble("/theme/gdkDPIScale",original_scale_dpi); + const gchar *gdk_scale_dpi = std::to_string(scale_dpi_value).c_str(); + g_setenv("GDK_DPI_SCALE", gdk_scale_dpi, TRUE); + + //printf("GDK_SCALE = %s\n", g_getenv("GDK_SCALE")); + //printf("GDK_DPI_SCALE = %s\n", g_getenv("GDK_DPI_SCALE")); +} + /* \brief Constructor for the application. * Creates a new Inkscape::Application. * @@ -472,6 +488,7 @@ Application::Application(const char* argv, bool use_gui) : if (use_gui) { add_style_sheet(); + set_scale_env(); /* Load the preferences and menus */ GtkSettings *settings = gtk_settings_get_default(); if (settings) { @@ -488,7 +505,10 @@ Application::Application(const char* argv, bool use_gui) : else { prefs->setString("/theme/gtkTheme", Glib::ustring(gtkThemeName)); } - + double scaleText = prefs->getDouble("/theme/scaleText", -1); + if (scaleText != -1) { + g_object_set (gtk_settings_get_default (), "gtk-xft-dpi", (gint)(scaleText * 96 * 1024),NULL); + } if (prefs->getString("/theme/iconTheme") != "") { g_object_set(settings, "gtk-icon-theme-name", prefs->getString("/theme/iconTheme").c_str(), NULL); } diff --git a/src/main.cpp b/src/main.cpp index 5206a64035..4483052e7b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -61,6 +61,7 @@ #include "selection.h" #include "selection-chemistry.h" #include "ui/interface.h" +#include "preferences.h" #include "print.h" #include "color.h" @@ -618,7 +619,6 @@ static void set_extensions_env() // printf("PYTHONPATH = %s\n", g_getenv("PYTHONPATH")); } - /** * This is the classic main() entry point of the program, though on some * architectures it might be called by something else. @@ -649,7 +649,6 @@ main(int argc, char **argv) rt.setPathInfo(); } #endif - set_extensions_env(); // Prevents errors like "Unable to wrap GdkPixbuf..." (in nr-filter-image.cpp for example) Gtk::Main::init_gtkmm_internals(); @@ -657,7 +656,7 @@ main(int argc, char **argv) LIBXML_TEST_VERSION Inkscape::GC::init(); - + Inkscape::Debug::Logger::init(); gboolean use_gui; diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index ecf470d21c..40b4d05a6f 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -882,6 +882,11 @@ void InkscapePreferences::initPageUI() _page_theme.add_line(false, _("Secondary toolbar icon size:"), _misc_small_secondary, "", _("Set the size for the icons in secondary toolbars to use (requires restart)"), false); } + _gdk_scale.init("/theme/gdkScale", 0.01, 10.0, 0.01, 0.1, 1.0, false, false); + _page_theme.add_line( true, _("Scale app"), _gdk_scale, "Need restart, common value for HiDPI is 2", "", false); + _gdk_dpi_scale.init("/theme/gdkDPIScale", 0.01, 10.0, 0.01, 0.1, 1.0, false, false); + _page_theme.add_line( true, _("Scale text dpi"), _gdk_dpi_scale, "Need restart, common value for HiDPI is 0.5", "", false); + _apply_theme.set_label(_("Reload icons")); _apply_theme.set_tooltip_text(_("Apply icon changes (may take a few seconds)")); _page_theme.add_line(false, "", _apply_theme, "Reloading icons will close all windows and open them again. No data will be lost.", "", false); diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h index 55ea35f634..18f3c1a4a5 100644 --- a/src/ui/dialog/inkscape-preferences.h +++ b/src/ui/dialog/inkscape-preferences.h @@ -250,6 +250,8 @@ protected: UI::Widget::PrefCombo _misc_small_toolbar; UI::Widget::PrefCombo _misc_small_secondary; UI::Widget::PrefCombo _misc_small_tools; + UI::Widget::PrefSpinButton _gdk_scale; + UI::Widget::PrefSpinButton _gdk_dpi_scale; Gtk::Button _apply_theme; UI::Widget::PrefRadioButton _win_dockable; -- GitLab From 00f3f168c80d876765405ba60ae474e256ec5e3e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 1 Sep 2018 03:19:36 +0200 Subject: [PATCH 2/4] Fixing coding style --- src/inkscape.cpp | 8 ++++---- src/main.cpp | 12 ++++++------ src/ui/dialog/inkscape-preferences.cpp | 8 +++++--- src/ui/dialog/inkscape-preferences.h | 4 ++-- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/inkscape.cpp b/src/inkscape.cpp index e8bad73602..02d6473c61 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -435,12 +435,12 @@ static void set_scale_env() const gchar *gdk_scale = std::to_string(scale_value).c_str(); g_setenv("GDK_SCALE", gdk_scale, TRUE); double original_scale_dpi = atof(g_getenv("GDK_DPI_SCALE") ? g_getenv("GDK_DPI_SCALE") : "1"); - double scale_dpi_value = prefs->getDouble("/theme/gdkDPIScale",original_scale_dpi); + double scale_dpi_value = prefs->getDouble("/theme/gdkDPIScale", original_scale_dpi); const gchar *gdk_scale_dpi = std::to_string(scale_dpi_value).c_str(); g_setenv("GDK_DPI_SCALE", gdk_scale_dpi, TRUE); - //printf("GDK_SCALE = %s\n", g_getenv("GDK_SCALE")); - //printf("GDK_DPI_SCALE = %s\n", g_getenv("GDK_DPI_SCALE")); + // printf("GDK_SCALE = %s\n", g_getenv("GDK_SCALE")); + // printf("GDK_DPI_SCALE = %s\n", g_getenv("GDK_DPI_SCALE")); } /* \brief Constructor for the application. @@ -507,7 +507,7 @@ Application::Application(const char* argv, bool use_gui) : } double scaleText = prefs->getDouble("/theme/scaleText", -1); if (scaleText != -1) { - g_object_set (gtk_settings_get_default (), "gtk-xft-dpi", (gint)(scaleText * 96 * 1024),NULL); + g_object_set(gtk_settings_get_default(), "gtk-xft-dpi", (gint)(scaleText * 96 * 1024), NULL); } if (prefs->getString("/theme/iconTheme") != "") { g_object_set(settings, "gtk-icon-theme-name", prefs->getString("/theme/iconTheme").c_str(), NULL); diff --git a/src/main.cpp b/src/main.cpp index 4483052e7b..b0573dacb6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -55,15 +55,15 @@ #undef AND #endif -#include "file.h" +#include "color.h" #include "document.h" +#include "file.h" #include "layer-model.h" -#include "selection.h" -#include "selection-chemistry.h" -#include "ui/interface.h" #include "preferences.h" #include "print.h" -#include "color.h" +#include "selection-chemistry.h" +#include "selection.h" +#include "ui/interface.h" #include "svg/svg.h" #include "svg/svg-color.h" @@ -656,7 +656,7 @@ main(int argc, char **argv) LIBXML_TEST_VERSION Inkscape::GC::init(); - + Inkscape::Debug::Logger::init(); gboolean use_gui; diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 40b4d05a6f..aa3c25d4a8 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -883,10 +883,12 @@ void InkscapePreferences::initPageUI() _("Set the size for the icons in secondary toolbars to use (requires restart)"), false); } _gdk_scale.init("/theme/gdkScale", 0.01, 10.0, 0.01, 0.1, 1.0, false, false); - _page_theme.add_line( true, _("Scale app"), _gdk_scale, "Need restart, common value for HiDPI is 2", "", false); + _page_theme.add_line(true, _("Scale app"), _gdk_scale, + "Need restart, common value for HiDPI is 2", "", false); _gdk_dpi_scale.init("/theme/gdkDPIScale", 0.01, 10.0, 0.01, 0.1, 1.0, false, false); - _page_theme.add_line( true, _("Scale text dpi"), _gdk_dpi_scale, "Need restart, common value for HiDPI is 0.5", "", false); - + _page_theme.add_line(true, _("Scale text dpi"), _gdk_dpi_scale, + "Need restart, common value for HiDPI is 0.5", "", false); + _apply_theme.set_label(_("Reload icons")); _apply_theme.set_tooltip_text(_("Apply icon changes (may take a few seconds)")); _page_theme.add_line(false, "", _apply_theme, "Reloading icons will close all windows and open them again. No data will be lost.", "", false); diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h index 18f3c1a4a5..7e4e9cdd22 100644 --- a/src/ui/dialog/inkscape-preferences.h +++ b/src/ui/dialog/inkscape-preferences.h @@ -250,8 +250,8 @@ protected: UI::Widget::PrefCombo _misc_small_toolbar; UI::Widget::PrefCombo _misc_small_secondary; UI::Widget::PrefCombo _misc_small_tools; - UI::Widget::PrefSpinButton _gdk_scale; - UI::Widget::PrefSpinButton _gdk_dpi_scale; + UI::Widget::PrefSpinButton _gdk_scale; + UI::Widget::PrefSpinButton _gdk_dpi_scale; Gtk::Button _apply_theme; UI::Widget::PrefRadioButton _win_dockable; -- GitLab From 3809b83929a5708b974d82387c02274d1cce4563 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 1 Sep 2018 03:26:49 +0200 Subject: [PATCH 3/4] Remove unecessary string --- src/ui/dialog/inkscape-preferences.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index aa3c25d4a8..4c55178306 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -884,10 +884,10 @@ void InkscapePreferences::initPageUI() } _gdk_scale.init("/theme/gdkScale", 0.01, 10.0, 0.01, 0.1, 1.0, false, false); _page_theme.add_line(true, _("Scale app"), _gdk_scale, - "Need restart, common value for HiDPI is 2", "", false); + "Common value for HiDPI is 2", "", false); _gdk_dpi_scale.init("/theme/gdkDPIScale", 0.01, 10.0, 0.01, 0.1, 1.0, false, false); _page_theme.add_line(true, _("Scale text dpi"), _gdk_dpi_scale, - "Need restart, common value for HiDPI is 0.5", "", false); + "Common value for HiDPI is 0.5", "", false); _apply_theme.set_label(_("Reload icons")); _apply_theme.set_tooltip_text(_("Apply icon changes (may take a few seconds)")); -- GitLab From 70a6b19e581a8f2897f8514404c32a0bda637d2f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 1 Sep 2018 03:31:35 +0200 Subject: [PATCH 4/4] Fixing coding style --- src/ui/dialog/inkscape-preferences.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 4c55178306..bec409b065 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -883,8 +883,8 @@ void InkscapePreferences::initPageUI() _("Set the size for the icons in secondary toolbars to use (requires restart)"), false); } _gdk_scale.init("/theme/gdkScale", 0.01, 10.0, 0.01, 0.1, 1.0, false, false); - _page_theme.add_line(true, _("Scale app"), _gdk_scale, - "Common value for HiDPI is 2", "", false); + _page_theme.add_line(true, _("Scale app"), _gdk_scale, "Common value for HiDPI is 2", + "", false); _gdk_dpi_scale.init("/theme/gdkDPIScale", 0.01, 10.0, 0.01, 0.1, 1.0, false, false); _page_theme.add_line(true, _("Scale text dpi"), _gdk_dpi_scale, "Common value for HiDPI is 0.5", "", false); -- GitLab