13
0

Guess UI scale for copy-config dialog

This dialog shows before the new user wizard,
where a user would configure HDPI/UI scaling.
This commit is contained in:
Robin Gareus 2023-09-25 17:07:15 +02:00
parent 9f475d5427
commit d7c611e025
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
5 changed files with 54 additions and 38 deletions

View File

@ -215,6 +215,10 @@ static const gchar *_record_mode_strings[] = {
static bool static bool
ask_about_configuration_copy (string const & old_dir, string const & new_dir, int version) ask_about_configuration_copy (string const & old_dir, string const & new_dir, int version)
{ {
/* guess screen scaling */
UIConfiguration::instance ().set_font_scale (1024 * guess_default_ui_scale ());
UIConfiguration::instance ().reset_dpi ();
ArdourMessageDialog msg (string_compose ( ArdourMessageDialog msg (string_compose (
_("%1 %2.x has discovered configuration files from %1 %3.x.\n\n" _("%1 %2.x has discovered configuration files from %1 %3.x.\n\n"
"Would you like these files to be copied and used for %1 %2.x?\n\n" "Would you like these files to be copied and used for %1 %2.x?\n\n"
@ -367,6 +371,7 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir)
record_mode_strings = I18N (_record_mode_strings); record_mode_strings = I18N (_record_mode_strings);
if (ARDOUR::handle_old_configuration_files (boost::bind (ask_about_configuration_copy, _1, _2, _3))) { if (ARDOUR::handle_old_configuration_files (boost::bind (ask_about_configuration_copy, _1, _2, _3))) {
{ {
/* "touch" the been-here-before path now that config has been migrated */ /* "touch" the been-here-before path now that config has been migrated */
PBD::ScopedFileDescriptor fout (g_open (been_here_before_path ().c_str(), O_CREAT|O_TRUNC|O_RDWR, 0666)); PBD::ScopedFileDescriptor fout (g_open (been_here_before_path ().c_str(), O_CREAT|O_TRUNC|O_RDWR, 0666));

View File

@ -171,7 +171,18 @@ using the program.</span> \
hbox->show (); hbox->show ();
cbox->show (); cbox->show ();
guess_default_ui_scale (); int ui_scale = guess_default_ui_scale ();
if (ui_scale <= 100) {
ui_font_scale.set_active (0); // 100%
} else if (ui_scale <= 150) {
ui_font_scale.set_active (1); // 150%
} else if (ui_scale <= 200) {
ui_font_scale.set_active (2); // 200%
} else {
ui_font_scale.set_active (3); // 250%
}
rescale_ui ();
ui_font_scale.signal_changed ().connect (sigc::mem_fun (*this, &NewUserWizard::rescale_ui)); ui_font_scale.signal_changed ().connect (sigc::mem_fun (*this, &NewUserWizard::rescale_ui));
#endif #endif
@ -189,7 +200,7 @@ void
NewUserWizard::rescale_ui () NewUserWizard::rescale_ui ()
{ {
int rn = ui_font_scale.get_active_row_number (); int rn = ui_font_scale.get_active_row_number ();
if (rn < 0 ) { if (rn < 0) {
return; return;
} }
float ui_scale = 100 + rn * 50; float ui_scale = 100 + rn * 50;
@ -197,41 +208,6 @@ NewUserWizard::rescale_ui ()
UIConfiguration::instance ().reset_dpi (); UIConfiguration::instance ().reset_dpi ();
} }
void
NewUserWizard::guess_default_ui_scale ()
{
gint width = 0;
gint height = 0;
GdkScreen* screen = gdk_display_get_screen (gdk_display_get_default (), 0);
gint n_monitors = gdk_screen_get_n_monitors (screen);
if (!screen) {
return;
}
for (gint i = 0; i < n_monitors; ++i) {
GdkRectangle rect;
gdk_screen_get_monitor_geometry (screen, i, &rect);
width = std::max (width, rect.width);
height = std::max (height, rect.height);
}
float wx = width / 1920.f;
float hx = height / 1080.f;
float sx = std::min (wx, hx);
if (sx < 1.25) {
ui_font_scale.set_active (0); // 100%
} else if (sx < 1.6) {
ui_font_scale.set_active (1); // 150%
} else if (sx < 2.1) {
ui_font_scale.set_active (2); // 200%
} else {
ui_font_scale.set_active (3); // 250%
}
rescale_ui ();
}
void void
NewUserWizard::default_dir_changed () NewUserWizard::default_dir_changed ()
{ {

View File

@ -77,7 +77,6 @@ private:
/* Welcome */ /* Welcome */
Gtk::ComboBoxText ui_font_scale; Gtk::ComboBoxText ui_font_scale;
void rescale_ui (); void rescale_ui ();
void guess_default_ui_scale ();
/* first page */ /* first page */
Gtk::FileChooserButton* default_dir_chooser; Gtk::FileChooserButton* default_dir_chooser;

View File

@ -642,6 +642,40 @@ ARDOUR_UI_UTILS::key_is_legal_for_numeric_entry (guint keyval)
return false; return false;
} }
int
ARDOUR_UI_UTILS::guess_default_ui_scale ()
{
gint width = 0;
gint height = 0;
GdkScreen* screen = gdk_display_get_screen (gdk_display_get_default (), 0);
gint n_monitors = gdk_screen_get_n_monitors (screen);
if (!screen) {
return 100;
}
for (gint i = 0; i < n_monitors; ++i) {
GdkRectangle rect;
gdk_screen_get_monitor_geometry (screen, i, &rect);
width = std::max (width, rect.width);
height = std::max (height, rect.height);
}
float wx = width / 1920.f;
float hx = height / 1080.f;
float sx = std::min (wx, hx);
if (sx < 1.25) {
return 100;
} else if (sx < 1.6) {
return 150;
} else if (sx < 2.1) {
return 200;
} else {
return 250;
}
}
void void
ARDOUR_UI_UTILS::resize_window_to_proportion_of_monitor (Gtk::Window* window, int max_width, int max_height) ARDOUR_UI_UTILS::resize_window_to_proportion_of_monitor (Gtk::Window* window, int max_width, int max_height)
{ {

View File

@ -95,6 +95,8 @@ const char* const *get_xpm_data (std::string path);
std::string longest (std::vector<std::string>&); std::string longest (std::vector<std::string>&);
bool key_is_legal_for_numeric_entry (guint keyval); bool key_is_legal_for_numeric_entry (guint keyval);
int guess_default_ui_scale ();
void resize_window_to_proportion_of_monitor (Gtk::Window*, int, int); void resize_window_to_proportion_of_monitor (Gtk::Window*, int, int);
std::string escape_underscores (std::string const &); std::string escape_underscores (std::string const &);