1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:07:35 +00:00

DisplaySettings: Add UI for switching the scale factor

For now, only support 1x and 2x scale.

I tried doing something "smarter" first where the UI would try
to keep the physical resolution constant when toggling between
1x and 2x, but many of the smaller 1x resolutions map to 2x
logical resolutions that Compositor rejects (e.g. 1024x768 becomes
512x384, which is less than the minimum 640x480 that Compositor
wants) and it felt complicated and overly magical.

So this instead just gives you a 1x/2x toggle and a dropdown
with logical (!) resolutions. That is, 800x600 @ 2x gives you
a physical resolution of 1600x1200.

If we don't like this after trying it for a while, we can change
the UI then.
This commit is contained in:
Nico Weber 2021-01-15 19:02:17 -05:00 committed by Andreas Kling
parent 05dbfe9ab6
commit f37f281f89
6 changed files with 76 additions and 12 deletions

View file

@ -39,6 +39,7 @@
#include <LibGUI/ItemListModel.h>
#include <LibGUI/Label.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/RadioButton.h>
#include <LibGUI/WindowServerConnection.h>
#include <LibGfx/Palette.h>
#include <LibGfx/SystemTheme.h>
@ -148,6 +149,21 @@ void DisplaySettingsWidget::create_frame()
m_monitor_widget->update();
};
m_display_scale_radio_1x = *find_descendant_of_type_named<GUI::RadioButton>("scale_1x");
m_display_scale_radio_1x->on_checked = [this](bool checked) {
if (checked) {
m_monitor_widget->set_desktop_scale_factor(1);
m_monitor_widget->update();
}
};
m_display_scale_radio_2x = *find_descendant_of_type_named<GUI::RadioButton>("scale_2x");
m_display_scale_radio_2x->on_checked = [this](bool checked) {
if (checked) {
m_monitor_widget->set_desktop_scale_factor(2);
m_monitor_widget->update();
}
};
m_color_input = *find_descendant_of_type_named<GUI::ColorInput>("color_input");
m_color_input->set_color_has_alpha_channel(false);
m_color_input->set_color_picker_title("Select color for desktop");
@ -215,13 +231,19 @@ void DisplaySettingsWidget::load_current_settings()
index = m_modes.find_first_index(mode).value();
m_mode_combo->set_selected_index(index);
/// Resolution ////////////////////////////////////////////////////////////////////////////////
Gfx::IntSize find_size;
/// Resolution and scale factor ///////////////////////////////////////////////////////////////
int scale_factor = ws_config->read_num_entry("Screen", "ScaleFactor", 1);
if (scale_factor != 1 && scale_factor != 2) {
dbgln("unexpected ScaleFactor {}, setting to 1", scale_factor);
scale_factor = 1;
}
(scale_factor == 1 ? m_display_scale_radio_1x : m_display_scale_radio_2x)->set_checked(true);
m_monitor_widget->set_desktop_scale_factor(scale_factor);
// Let's attempt to find the current resolution and select it!
Gfx::IntSize find_size;
find_size.set_width(ws_config->read_num_entry("Screen", "Width", 1024));
find_size.set_height(ws_config->read_num_entry("Screen", "Height", 768));
index = m_resolutions.find_first_index(find_size).value_or(0);
Gfx::IntSize m_current_resolution = m_resolutions.at(index);
m_monitor_widget->set_desktop_resolution(m_current_resolution);
@ -246,10 +268,9 @@ void DisplaySettingsWidget::load_current_settings()
void DisplaySettingsWidget::send_settings_to_window_server()
{
// FIXME: Add UI for changing the scale factor.
auto result = GUI::WindowServerConnection::the().send_sync<Messages::WindowServer::SetResolution>(m_monitor_widget->desktop_resolution(), 1);
auto result = GUI::WindowServerConnection::the().send_sync<Messages::WindowServer::SetResolution>(m_monitor_widget->desktop_resolution(), m_monitor_widget->desktop_scale_factor());
if (!result->success()) {
GUI::MessageBox::show(nullptr, String::formatted("Reverting to resolution {}x{}", result->resolution().width(), result->resolution().height()),
GUI::MessageBox::show(nullptr, String::formatted("Reverting to resolution {}x{} @ {}x", result->resolution().width(), result->resolution().height(), result->scale_factor()),
"Unable to set resolution", GUI::MessageBox::Type::Error);
}