summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2021-06-30 11:28:16 -0600
committerAndreas Kling <kling@serenityos.org>2021-07-03 12:27:23 +0200
commit5acee4b4d0213a9bcd67fc024615a7356e1e7082 (patch)
treed7f72fa27ed3df18e344eaf40e96179603ae88dd
parent6472ee0effe162ffd0c93ecbd2f7d4282f2cd5f5 (diff)
downloadserenity-5acee4b4d0213a9bcd67fc024615a7356e1e7082.zip
DisplaySettings: Add new Desktop tab with virtual desktop settings
This allows the user to configure the virtual desktop setup as desired.
-rw-r--r--Userland/Applications/DisplaySettings/CMakeLists.txt3
-rw-r--r--Userland/Applications/DisplaySettings/DesktopSettings.gml75
-rw-r--r--Userland/Applications/DisplaySettings/DesktopSettingsWidget.cpp61
-rw-r--r--Userland/Applications/DisplaySettings/DesktopSettingsWidget.h32
-rw-r--r--Userland/Applications/DisplaySettings/main.cpp4
5 files changed, 175 insertions, 0 deletions
diff --git a/Userland/Applications/DisplaySettings/CMakeLists.txt b/Userland/Applications/DisplaySettings/CMakeLists.txt
index 3dae443673..3950f15965 100644
--- a/Userland/Applications/DisplaySettings/CMakeLists.txt
+++ b/Userland/Applications/DisplaySettings/CMakeLists.txt
@@ -6,11 +6,14 @@ serenity_component(
compile_gml(MonitorSettings.gml MonitorSettingsGML.h monitor_settings_window_gml)
compile_gml(BackgroundSettings.gml BackgroundSettingsGML.h background_settings_gml)
+compile_gml(DesktopSettings.gml DesktopSettingsGML.h desktop_settings_gml)
compile_gml(FontSettings.gml FontSettingsGML.h font_settings_gml)
set(SOURCES
BackgroundSettingsGML.h
BackgroundSettingsWidget.cpp
+ DesktopSettingsWidget.cpp
+ DesktopSettingsGML.h
FontSettingsGML.h
FontSettingsWidget.cpp
MonitorSettingsWidget.cpp
diff --git a/Userland/Applications/DisplaySettings/DesktopSettings.gml b/Userland/Applications/DisplaySettings/DesktopSettings.gml
new file mode 100644
index 0000000000..c35c47b7aa
--- /dev/null
+++ b/Userland/Applications/DisplaySettings/DesktopSettings.gml
@@ -0,0 +1,75 @@
+@GUI::Widget {
+ fill_with_background_color: true
+
+ layout: @GUI::VerticalBoxLayout {
+ margins: [8, 8, 8, 8]
+ }
+
+ @GUI::GroupBox {
+ layout: @GUI::VerticalBoxLayout {
+ margins: [16, 24, 16, 6]
+ }
+
+ title: "Virtual Desktops"
+ shrink_to_fit: true
+
+ @GUI::Widget {
+ fixed_height: 32
+
+ layout: @GUI::HorizontalBoxLayout {
+ margins: [6, 6, 6, 6]
+ }
+
+ @GUI::Label {
+ text: "Rows:"
+ text_alignment: "CenterRight"
+ }
+
+ @GUI::SpinBox {
+ name: "virtual_desktop_rows_spinbox"
+ min: 1
+ max: 16
+ orientation: "Horizontal"
+ }
+
+ @GUI::Label {
+ text: "Columns:"
+ text_alignment: "CenterRight"
+ }
+
+ @GUI::SpinBox {
+ name: "virtual_desktop_columns_spinbox"
+ min: 1
+ max: 16
+ orientation: "Horizontal"
+ }
+ }
+
+ @GUI::Widget {
+ fixed_height: 76
+
+ layout: @GUI::HorizontalBoxLayout {
+ }
+ @GUI::Label {
+ name: "light_bulb_label"
+ fixed_height: 32
+ fixed_width: 32
+ }
+ @GUI::Widget {
+ layout: @GUI::VerticalBoxLayout {
+ margins: [6, 6, 6, 6]
+ }
+ @GUI::Label {
+ text: "Use the Ctrl+Alt+Arrow hotkeys to move between virtual desktops."
+ text_alignment: "TopLeft"
+ word_wrap: true
+ }
+ @GUI::Label {
+ text: "Use the Ctrl+Shift+Alt+Arrow hotkeys to move between virtual desktops and move the active window."
+ text_alignment: "TopLeft"
+ word_wrap: true
+ }
+ }
+ }
+ }
+}
diff --git a/Userland/Applications/DisplaySettings/DesktopSettingsWidget.cpp b/Userland/Applications/DisplaySettings/DesktopSettingsWidget.cpp
new file mode 100644
index 0000000000..122852e4bb
--- /dev/null
+++ b/Userland/Applications/DisplaySettings/DesktopSettingsWidget.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2020, the SerenityOS developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include "DesktopSettingsWidget.h"
+#include <AK/StringBuilder.h>
+#include <Applications/DisplaySettings/DesktopSettingsGML.h>
+#include <LibGUI/Application.h>
+#include <LibGUI/BoxLayout.h>
+#include <LibGUI/Desktop.h>
+#include <LibGUI/Label.h>
+#include <LibGUI/MessageBox.h>
+#include <LibGUI/SpinBox.h>
+#include <LibGUI/WindowServerConnection.h>
+
+namespace DisplaySettings {
+
+DesktopSettingsWidget::DesktopSettingsWidget()
+{
+ create_frame();
+ load_current_settings();
+}
+
+DesktopSettingsWidget::~DesktopSettingsWidget()
+{
+}
+
+void DesktopSettingsWidget::create_frame()
+{
+ load_from_gml(desktop_settings_gml);
+
+ auto& light_bulb_label = *find_descendant_of_type_named<GUI::Label>("light_bulb_label");
+ light_bulb_label.set_icon(Gfx::Bitmap::load_from_file("/res/icons/32x32/app-welcome.png"));
+
+ m_virtual_desktop_rows_spinbox = *find_descendant_of_type_named<GUI::SpinBox>("virtual_desktop_rows_spinbox");
+ m_virtual_desktop_columns_spinbox = *find_descendant_of_type_named<GUI::SpinBox>("virtual_desktop_columns_spinbox");
+}
+
+void DesktopSettingsWidget::load_current_settings()
+{
+ auto& desktop = GUI::Desktop::the();
+ m_virtual_desktop_rows_spinbox->set_value(desktop.virtual_desktop_rows());
+ m_virtual_desktop_columns_spinbox->set_value(desktop.virtual_desktop_columns());
+}
+
+void DesktopSettingsWidget::apply_settings()
+{
+ auto virtual_desktop_rows = (unsigned)m_virtual_desktop_rows_spinbox->value();
+ auto virtual_desktop_columns = (unsigned)m_virtual_desktop_columns_spinbox->value();
+ auto& desktop = GUI::Desktop::the();
+ if (virtual_desktop_rows != desktop.virtual_desktop_rows() || virtual_desktop_columns != desktop.virtual_desktop_columns()) {
+ if (!GUI::WindowServerConnection::the().apply_virtual_desktop_settings(virtual_desktop_rows, virtual_desktop_columns, true)) {
+ GUI::MessageBox::show(window(), String::formatted("Error applying virtual desktop settings"),
+ "Virtual desktop settings", GUI::MessageBox::Type::Error);
+ }
+ }
+}
+
+}
diff --git a/Userland/Applications/DisplaySettings/DesktopSettingsWidget.h b/Userland/Applications/DisplaySettings/DesktopSettingsWidget.h
new file mode 100644
index 0000000000..d894756cc5
--- /dev/null
+++ b/Userland/Applications/DisplaySettings/DesktopSettingsWidget.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2020, the SerenityOS developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibCore/Timer.h>
+#include <LibGUI/SpinBox.h>
+
+namespace DisplaySettings {
+
+class DesktopSettingsWidget : public GUI::Widget {
+ C_OBJECT(DesktopSettingsWidget);
+
+public:
+ virtual ~DesktopSettingsWidget() override;
+
+ void apply_settings();
+
+private:
+ DesktopSettingsWidget();
+
+ void create_frame();
+ void load_current_settings();
+
+ RefPtr<GUI::SpinBox> m_virtual_desktop_rows_spinbox;
+ RefPtr<GUI::SpinBox> m_virtual_desktop_columns_spinbox;
+};
+
+}
diff --git a/Userland/Applications/DisplaySettings/main.cpp b/Userland/Applications/DisplaySettings/main.cpp
index 4a3a6a8cdb..d908ae8e7a 100644
--- a/Userland/Applications/DisplaySettings/main.cpp
+++ b/Userland/Applications/DisplaySettings/main.cpp
@@ -6,6 +6,7 @@
*/
#include "BackgroundSettingsWidget.h"
+#include "DesktopSettingsWidget.h"
#include "FontSettingsWidget.h"
#include "MonitorSettingsWidget.h"
#include <LibGUI/Action.h>
@@ -52,6 +53,7 @@ int main(int argc, char** argv)
auto& background_settings_widget = tab_widget.add_tab<DisplaySettings::BackgroundSettingsWidget>("Background");
auto& font_settings_widget = tab_widget.add_tab<DisplaySettings::FontSettingsWidget>("Fonts");
auto& monitor_settings_widget = tab_widget.add_tab<DisplaySettings::MonitorSettingsWidget>("Monitor");
+ auto& desktop_settings_widget = tab_widget.add_tab<DisplaySettings::DesktopSettingsWidget>("Desktop");
tab_widget.on_change = [&](auto& widget) {
monitor_settings_widget.show_screen_numbers(&widget == &monitor_settings_widget);
};
@@ -67,6 +69,7 @@ int main(int argc, char** argv)
ok_button.on_click = [&](auto) {
background_settings_widget.apply_settings();
monitor_settings_widget.apply_settings();
+ desktop_settings_widget.apply_settings();
font_settings_widget.apply_settings();
app->quit();
};
@@ -82,6 +85,7 @@ int main(int argc, char** argv)
apply_button.on_click = [&](auto) {
background_settings_widget.apply_settings();
monitor_settings_widget.apply_settings();
+ desktop_settings_widget.apply_settings();
font_settings_widget.apply_settings();
};