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

DisplaySettings: Show revert dialog only for resolution/dpi changes.

This commit is contained in:
belginul 2021-02-18 18:59:58 +02:00 committed by Andreas Kling
parent a4d4571522
commit 4f80bb6ce3

View file

@ -283,28 +283,30 @@ void DisplaySettingsWidget::send_settings_to_window_server()
current_scale_factor = 1; current_scale_factor = 1;
} }
auto result = GUI::WindowServerConnection::the().send_sync<Messages::WindowServer::SetResolution>(m_monitor_widget->desktop_resolution(), m_monitor_widget->desktop_scale_factor()); if (current_resolution != m_monitor_widget->desktop_resolution() || current_scale_factor != m_monitor_widget->desktop_scale_factor()) {
if (!result->success()) { auto result = GUI::WindowServerConnection::the().send_sync<Messages::WindowServer::SetResolution>(m_monitor_widget->desktop_resolution(), m_monitor_widget->desktop_scale_factor());
GUI::MessageBox::show(nullptr, String::formatted("Reverting to resolution {}x{} @ {}x", result->resolution().width(), result->resolution().height(), result->scale_factor()), if (!result->success()) {
"Unable to set resolution", GUI::MessageBox::Type::Error); GUI::MessageBox::show(nullptr, String::formatted("Reverting to resolution {}x{} @ {}x", result->resolution().width(), result->resolution().height(), result->scale_factor()),
} else { "Unable to set resolution", GUI::MessageBox::Type::Error);
auto box = GUI::MessageBox::construct(window(), String::formatted("Do you want to keep the new settings? They will be reverted after 10 seconds."), } else {
String::formatted("New screen resolution: {}x{} @ {}x", m_monitor_widget->desktop_resolution().width(), m_monitor_widget->desktop_resolution().height(), auto box = GUI::MessageBox::construct(window(), String::formatted("Do you want to keep the new settings? They will be reverted after 10 seconds."),
m_monitor_widget->desktop_scale_factor()), String::formatted("New screen resolution: {}x{} @ {}x", m_monitor_widget->desktop_resolution().width(), m_monitor_widget->desktop_resolution().height(),
GUI::MessageBox::Type::Question, GUI::MessageBox::InputType::YesNo); m_monitor_widget->desktop_scale_factor()),
box->set_icon(window()->icon()); GUI::MessageBox::Type::Question, GUI::MessageBox::InputType::YesNo);
box->set_icon(window()->icon());
// If after 10 seconds the user doesn't close the message box, just close it. // If after 10 seconds the user doesn't close the message box, just close it.
auto timer = Core::Timer::construct(10000, [&] { auto timer = Core::Timer::construct(10000, [&] {
box->close(); box->close();
}); });
// If the user selects "No", closes the window or the window gets closed by the 10 seconds timer, revert the changes. // If the user selects "No", closes the window or the window gets closed by the 10 seconds timer, revert the changes.
if (box->exec() != GUI::MessageBox::ExecYes) { if (box->exec() != GUI::MessageBox::ExecYes) {
result = GUI::WindowServerConnection::the().send_sync<Messages::WindowServer::SetResolution>(current_resolution, current_scale_factor); result = GUI::WindowServerConnection::the().send_sync<Messages::WindowServer::SetResolution>(current_resolution, current_scale_factor);
if (!result->success()) { if (!result->success()) {
GUI::MessageBox::show(nullptr, String::formatted("Reverting to resolution {}x{} @ {}x", result->resolution().width(), result->resolution().height(), result->scale_factor()), 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); "Unable to set resolution", GUI::MessageBox::Type::Error);
}
} }
} }
} }