Serenity Operating System
1/*
2 * Copyright (c) 2020-2022, the SerenityOS developers.
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include "DesktopSettingsWidget.h"
8#include <Applications/DisplaySettings/DesktopSettingsGML.h>
9#include <LibGUI/BoxLayout.h>
10#include <LibGUI/ConnectionToWindowServer.h>
11#include <LibGUI/Desktop.h>
12#include <LibGUI/Label.h>
13#include <LibGUI/MessageBox.h>
14#include <LibGUI/SpinBox.h>
15
16namespace DisplaySettings {
17
18DesktopSettingsWidget::DesktopSettingsWidget()
19{
20 create_frame();
21 load_current_settings();
22}
23
24void DesktopSettingsWidget::create_frame()
25{
26 load_from_gml(desktop_settings_gml).release_value_but_fixme_should_propagate_errors();
27
28 m_workspace_rows_spinbox = *find_descendant_of_type_named<GUI::SpinBox>("workspace_rows_spinbox");
29 m_workspace_rows_spinbox->on_change = [&](auto) {
30 set_modified(true);
31 };
32 m_workspace_columns_spinbox = *find_descendant_of_type_named<GUI::SpinBox>("workspace_columns_spinbox");
33 m_workspace_columns_spinbox->on_change = [&](auto) {
34 set_modified(true);
35 };
36
37 auto& keyboard_shortcuts_label = *find_descendant_of_type_named<GUI::Label>("keyboard_shortcuts_label");
38 keyboard_shortcuts_label.set_text("\xE2\x84\xB9\tCtrl+Alt+{Shift}+Arrows moves between workspaces");
39}
40
41void DesktopSettingsWidget::load_current_settings()
42{
43 auto& desktop = GUI::Desktop::the();
44 m_workspace_rows_spinbox->set_value(desktop.workspace_rows(), GUI::AllowCallback::No);
45 m_workspace_columns_spinbox->set_value(desktop.workspace_columns(), GUI::AllowCallback::No);
46}
47
48void DesktopSettingsWidget::apply_settings()
49{
50 auto workspace_rows = (unsigned)m_workspace_rows_spinbox->value();
51 auto workspace_columns = (unsigned)m_workspace_columns_spinbox->value();
52 auto& desktop = GUI::Desktop::the();
53 if (workspace_rows != desktop.workspace_rows() || workspace_columns != desktop.workspace_columns()) {
54 if (!GUI::ConnectionToWindowServer::the().apply_workspace_settings(workspace_rows, workspace_columns, true)) {
55 GUI::MessageBox::show(window(), DeprecatedString::formatted("Error applying workspace settings"),
56 "Workspace settings"sv, GUI::MessageBox::Type::Error);
57 }
58 }
59}
60
61}