summaryrefslogtreecommitdiff
path: root/Userland/Applications/DisplaySettings
diff options
context:
space:
mode:
authorEvilHowl <mrevilhowl@gmail.com>2021-02-02 11:34:45 +0100
committerAndreas Kling <kling@serenityos.org>2021-02-03 10:17:19 +0100
commita0c773da9ee77c7603e39c40524046b1b6c3c60d (patch)
tree70235a3e36f8ca0a76105749bf6a598c89850641 /Userland/Applications/DisplaySettings
parent2031baebce5f742f76aaafc08b75e38d62fc7ca6 (diff)
downloadserenity-a0c773da9ee77c7603e39c40524046b1b6c3c60d.zip
DisplaySettings: Show a confirmation message when applying changes
The changes will be reverted after 10 seconds of no user input.
Diffstat (limited to 'Userland/Applications/DisplaySettings')
-rw-r--r--Userland/Applications/DisplaySettings/DisplaySettings.cpp31
-rw-r--r--Userland/Applications/DisplaySettings/DisplaySettings.h1
2 files changed, 32 insertions, 0 deletions
diff --git a/Userland/Applications/DisplaySettings/DisplaySettings.cpp b/Userland/Applications/DisplaySettings/DisplaySettings.cpp
index 8ad1c01f91..3bc9799122 100644
--- a/Userland/Applications/DisplaySettings/DisplaySettings.cpp
+++ b/Userland/Applications/DisplaySettings/DisplaySettings.cpp
@@ -272,10 +272,41 @@ void DisplaySettingsWidget::load_current_settings()
void DisplaySettingsWidget::send_settings_to_window_server()
{
+ // Store the current screen resolution and scale factor in case the user wants to revert to it.
+ auto ws_config(Core::ConfigFile::open("/etc/WindowServer/WindowServer.ini"));
+ Gfx::IntSize current_resolution;
+ current_resolution.set_width(ws_config->read_num_entry("Screen", "Width", 1024));
+ current_resolution.set_height(ws_config->read_num_entry("Screen", "Height", 768));
+ int current_scale_factor = ws_config->read_num_entry("Screen", "ScaleFactor", 1);
+ if (current_scale_factor != 1 && current_scale_factor != 2) {
+ dbgln("unexpected ScaleFactor {}, setting to 1", current_scale_factor);
+ 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 (!result->success()) {
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);
+ } else {
+ auto box = GUI::MessageBox::construct(window(), String::formatted("Do you want to keep the new settings? They will be reverted after 10 seconds."),
+ String::formatted("New screen resolution: {}x{} @ {}x", m_monitor_widget->desktop_resolution().width(), m_monitor_widget->desktop_resolution().height(),
+ m_monitor_widget->desktop_scale_factor()),
+ 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.
+ auto timer = Core::Timer::construct(10000, [&] {
+ box->close();
+ });
+
+ // 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) {
+ result = GUI::WindowServerConnection::the().send_sync<Messages::WindowServer::SetResolution>(current_resolution, current_scale_factor);
+ if (!result->success()) {
+ 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);
+ }
+ }
}
if (!m_monitor_widget->wallpaper().is_empty()) {
diff --git a/Userland/Applications/DisplaySettings/DisplaySettings.h b/Userland/Applications/DisplaySettings/DisplaySettings.h
index ebda18addd..c232a798e5 100644
--- a/Userland/Applications/DisplaySettings/DisplaySettings.h
+++ b/Userland/Applications/DisplaySettings/DisplaySettings.h
@@ -27,6 +27,7 @@
#pragma once
#include "MonitorWidget.h"
+#include <LibCore/Timer.h>
#include <LibGUI/ColorInput.h>
#include <LibGUI/ComboBox.h>
#include <LibGUI/RadioButton.h>