Skip to content

Commit

Permalink
DisplaySettings: Port to GML compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
RatcheT2497 committed Jan 11, 2025
1 parent 83db5eb commit dabb372
Show file tree
Hide file tree
Showing 20 changed files with 86 additions and 132 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@GUI::Widget {
@DisplaySettings::BackgroundSettingsWidget {
fill_with_background_color: true
layout: @GUI::VerticalBoxLayout {
margins: [8]
Expand Down
29 changes: 7 additions & 22 deletions Userland/Applications/DisplaySettings/BackgroundSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "BackgroundSettingsWidget.h"
#include <AK/LexicalPath.h>
#include <AK/StringBuilder.h>
#include <Applications/DisplaySettings/BackgroundSettingsGML.h>
#include <LibConfig/Client.h>
#include <LibCore/ConfigFile.h>
#include <LibDesktop/Launcher.h>
Expand All @@ -31,29 +30,19 @@

namespace DisplaySettings {

ErrorOr<NonnullRefPtr<BackgroundSettingsWidget>> BackgroundSettingsWidget::try_create(bool& background_settings_changed)
ErrorOr<void> BackgroundSettingsWidget::initialize()
{
auto background_settings_widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) BackgroundSettingsWidget(background_settings_changed)));
TRY(m_modes.try_append("Tile"_string));
TRY(m_modes.try_append("Center"_string));
TRY(m_modes.try_append("Stretch"_string));

TRY(background_settings_widget->m_modes.try_append("Tile"_string));
TRY(background_settings_widget->m_modes.try_append("Center"_string));
TRY(background_settings_widget->m_modes.try_append("Stretch"_string));

TRY(background_settings_widget->create_frame());
TRY(background_settings_widget->load_current_settings());

return background_settings_widget;
}

BackgroundSettingsWidget::BackgroundSettingsWidget(bool& background_settings_changed)
: m_background_settings_changed { background_settings_changed }
{
TRY(create_frame());
TRY(load_current_settings());
return {};
}

ErrorOr<void> BackgroundSettingsWidget::create_frame()
{
TRY(load_from_gml(background_settings_gml));

m_monitor_widget = *find_descendant_of_type_named<DisplaySettings::MonitorWidget>("monitor_widget");

m_wallpaper_view = *find_descendant_of_type_named<GUI::IconView>("wallpaper_view");
Expand Down Expand Up @@ -113,7 +102,6 @@ ErrorOr<void> BackgroundSettingsWidget::create_frame()
return;
m_wallpaper_view->selection().clear();
m_monitor_widget->set_wallpaper(MUST(String::from_byte_string(response.release_value().filename())));
m_background_settings_changed = true;
set_modified(true);
};

Expand All @@ -123,7 +111,6 @@ ErrorOr<void> BackgroundSettingsWidget::create_frame()
bool first_mode_change = true;
m_mode_combo->on_change = [this, first_mode_change](auto&, const GUI::ModelIndex& index) mutable {
m_monitor_widget->set_wallpaper_mode(m_modes.at(index.row()));
m_background_settings_changed = !first_mode_change;
first_mode_change = false;
set_modified(true);
};
Expand All @@ -134,7 +121,6 @@ ErrorOr<void> BackgroundSettingsWidget::create_frame()
bool first_color_change = true;
m_color_input->on_change = [this, first_color_change]() mutable {
m_monitor_widget->set_background_color(m_color_input->color());
m_background_settings_changed = !first_color_change;
first_color_change = false;
set_modified(true);
};
Expand Down Expand Up @@ -172,7 +158,6 @@ ErrorOr<void> BackgroundSettingsWidget::load_current_settings()

m_color_input->set_color(palette_desktop_color, GUI::AllowCallback::No);
m_monitor_widget->set_background_color(palette_desktop_color);
m_background_settings_changed = false;

return {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (c) 2019-2020, Jesse Buhagiar <[email protected]>
* Copyright (c) 2021, Andreas Kling <[email protected]>
* Copyright (c) 2022, the SerenityOS developers.
* Copyright (c) 2025, RatcheT2497 <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
Expand All @@ -23,21 +24,20 @@ class BackgroundSettingsWidget : public GUI::SettingsWindow::Tab {
C_OBJECT_ABSTRACT(BackgroundSettingsWidget);

public:
static ErrorOr<NonnullRefPtr<BackgroundSettingsWidget>> try_create(bool& background_settings_changed);
static ErrorOr<NonnullRefPtr<BackgroundSettingsWidget>> try_create();
virtual ~BackgroundSettingsWidget() override = default;
ErrorOr<void> initialize();

virtual void apply_settings() override;

private:
BackgroundSettingsWidget(bool& background_settings_changed);
BackgroundSettingsWidget() = default;

ErrorOr<void> create_frame();
ErrorOr<void> load_current_settings();

Vector<String> m_modes;

bool& m_background_settings_changed;

RefPtr<DisplaySettings::MonitorWidget> m_monitor_widget;
RefPtr<GUI::IconView> m_wallpaper_view;
RefPtr<GUI::ComboBox> m_mode_combo;
Expand Down
26 changes: 12 additions & 14 deletions Userland/Applications/DisplaySettings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ serenity_component(
TARGETS DisplaySettings
)

stringify_gml(BackgroundSettings.gml BackgroundSettingsGML.h background_settings_gml)
stringify_gml(DesktopSettings.gml DesktopSettingsGML.h desktop_settings_gml)
stringify_gml(EffectsSettings.gml EffectsSettingsGML.h effects_settings_gml)
stringify_gml(FontSettings.gml FontSettingsGML.h font_settings_gml)
stringify_gml(MonitorSettings.gml MonitorSettingsGML.h monitor_settings_window_gml)
stringify_gml(ThemesSettings.gml ThemesSettingsGML.h themes_settings_gml)
compile_gml(BackgroundSettings.gml BackgroundSettingsGML.cpp)
compile_gml(DesktopSettings.gml DesktopSettingsGML.cpp)
compile_gml(EffectsSettings.gml EffectsSettingsGML.cpp)
compile_gml(FontSettings.gml FontSettingsGML.cpp)
compile_gml(MonitorSettings.gml MonitorSettingsGML.cpp)
compile_gml(ThemesSettings.gml ThemesSettingsGML.cpp)

set(SOURCES
BackgroundSettingsWidget.cpp
Expand All @@ -20,17 +20,15 @@ set(SOURCES
MonitorWidget.cpp
ThemePreviewWidget.cpp
ThemesSettingsWidget.cpp
BackgroundSettingsGML.cpp
DesktopSettingsGML.cpp
EffectsSettingsGML.cpp
FontSettingsGML.cpp
MonitorSettingsGML.cpp
ThemesSettingsGML.cpp
main.cpp
)

set(GENERATED_SOURCES
BackgroundSettingsGML.h
DesktopSettingsGML.h
EffectsSettingsGML.h
FontSettingsGML.h
MonitorSettingsGML.h
ThemesSettingsGML.h
)

serenity_app(DisplaySettings ICON app-display-settings)
target_link_libraries(DisplaySettings PRIVATE LibCore LibDesktop LibGfx LibGUI LibConfig LibIPC LibMain LibEDID LibThreading LibFileSystemAccessClient LibURL)
2 changes: 1 addition & 1 deletion Userland/Applications/DisplaySettings/DesktopSettings.gml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@GUI::Widget {
@DisplaySettings::DesktopSettingsWidget {
fill_with_background_color: true
layout: @GUI::VerticalBoxLayout {
margins: [8]
Expand Down
12 changes: 4 additions & 8 deletions Userland/Applications/DisplaySettings/DesktopSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

#include "DesktopSettingsWidget.h"
#include <Applications/DisplaySettings/DesktopSettingsGML.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/ConnectionToWindowServer.h>
#include <LibGUI/Desktop.h>
Expand All @@ -15,18 +14,15 @@

namespace DisplaySettings {

ErrorOr<NonnullRefPtr<DesktopSettingsWidget>> DesktopSettingsWidget::try_create()
ErrorOr<void> DesktopSettingsWidget::initialize()
{
auto desktop_settings_widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) DesktopSettingsWidget()));
TRY(desktop_settings_widget->create_frame());
desktop_settings_widget->load_current_settings();
return desktop_settings_widget;
TRY(create_frame());
load_current_settings();
return {};
}

ErrorOr<void> DesktopSettingsWidget::create_frame()
{
TRY(load_from_gml(desktop_settings_gml));

m_workspace_rows_spinbox = *find_descendant_of_type_named<GUI::SpinBox>("workspace_rows_spinbox");
m_workspace_rows_spinbox->on_change = [&](auto) {
set_modified(true);
Expand Down
2 changes: 2 additions & 0 deletions Userland/Applications/DisplaySettings/DesktopSettingsWidget.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2020-2022, the SerenityOS developers.
* Copyright (c) 2025, RatcheT2497 <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
Expand All @@ -18,6 +19,7 @@ class DesktopSettingsWidget : public GUI::SettingsWindow::Tab {
public:
static ErrorOr<NonnullRefPtr<DesktopSettingsWidget>> try_create();
virtual ~DesktopSettingsWidget() override = default;
ErrorOr<void> initialize();

virtual void apply_settings() override;

Expand Down
2 changes: 1 addition & 1 deletion Userland/Applications/DisplaySettings/EffectsSettings.gml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@GUI::Widget {
@DisplaySettings::EffectsSettingsWidget {
fill_with_background_color: true
layout: @GUI::VerticalBoxLayout {
margins: [8]
Expand Down
46 changes: 19 additions & 27 deletions Userland/Applications/DisplaySettings/EffectsSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,30 @@
*/

#include "EffectsSettingsWidget.h"
#include <Applications/DisplaySettings/EffectsSettingsGML.h>
#include <LibCore/ConfigFile.h>
#include <LibGUI/CheckBox.h>
#include <LibGUI/ComboBox.h>
#include <LibGUI/ConnectionToWindowServer.h>
#include <LibGUI/ItemListModel.h>

namespace GUI {

namespace DisplaySettings {

ErrorOr<NonnullRefPtr<EffectsSettingsWidget>> EffectsSettingsWidget::try_create()
ErrorOr<void> EffectsSettingsWidget::initialize()
{
auto effects_settings_widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) EffectsSettingsWidget()));
TRY(effects_settings_widget->setup_interface());
return effects_settings_widget;
TRY(setup_interface());
return {};
}

ErrorOr<void> EffectsSettingsWidget::setup_interface()
{
TRY(load_from_gml(effects_settings_gml));

m_geometry_combobox = find_descendant_of_type_named<ComboBox>("geometry_combobox");
m_geometry_combobox = find_descendant_of_type_named<GUI::ComboBox>("geometry_combobox");
m_geometry_combobox->set_only_allow_values_from_model(true);
m_geometry_combobox->on_change = [this](auto&, auto&) {
m_system_effects.set_geometry(static_cast<ShowGeometry>(m_geometry_combobox->selected_index()));
m_system_effects.set_geometry(static_cast<GUI::ShowGeometry>(m_geometry_combobox->selected_index()));
set_modified(true);
};

m_tile_window_combobox = find_descendant_of_type_named<ComboBox>("tile_window_combobox");
m_tile_window_combobox = find_descendant_of_type_named<GUI::ComboBox>("tile_window_combobox");
m_tile_window_combobox->set_only_allow_values_from_model(true);
m_tile_window_combobox->on_change = [this](auto&, auto&) {
m_system_effects.set_tile_window(static_cast<WindowServer::TileWindow>(m_tile_window_combobox->selected_index()));
Expand All @@ -49,61 +43,61 @@ ErrorOr<void> EffectsSettingsWidget::setup_interface()
auto& animate_menus = *find_descendant_of_type_named<GUI::CheckBox>("animate_menus_checkbox");
animate_menus.set_checked(m_system_effects.animate_menus());
animate_menus.on_checked = [this](bool checked) {
if (m_system_effects.set_effect(Effects::AnimateMenus, checked))
if (m_system_effects.set_effect(GUI::Effects::AnimateMenus, checked))
set_modified(true);
};
auto& flash_menus = *find_descendant_of_type_named<GUI::CheckBox>("flash_menus_checkbox");
flash_menus.set_checked(m_system_effects.flash_menus());
flash_menus.on_checked = [this](bool checked) {
if (m_system_effects.set_effect(Effects::FlashMenus, checked))
if (m_system_effects.set_effect(GUI::Effects::FlashMenus, checked))
set_modified(true);
};
auto& animate_windows = *find_descendant_of_type_named<GUI::CheckBox>("animate_windows_checkbox");
animate_windows.set_checked(m_system_effects.animate_windows());
animate_windows.on_checked = [this](bool checked) {
if (m_system_effects.set_effect(Effects::AnimateWindows, checked))
if (m_system_effects.set_effect(GUI::Effects::AnimateWindows, checked))
set_modified(true);
};
auto& smooth_scrolling = *find_descendant_of_type_named<GUI::CheckBox>("smooth_scrolling_checkbox");
smooth_scrolling.set_checked(m_system_effects.smooth_scrolling());
smooth_scrolling.on_checked = [this](bool checked) {
if (m_system_effects.set_effect(Effects::SmoothScrolling, checked))
if (m_system_effects.set_effect(GUI::Effects::SmoothScrolling, checked))
set_modified(true);
};
auto& tab_accents = *find_descendant_of_type_named<GUI::CheckBox>("tab_accents_checkbox");
tab_accents.set_checked(m_system_effects.tab_accents());
tab_accents.on_checked = [this](bool checked) {
if (m_system_effects.set_effect(Effects::TabAccents, checked))
if (m_system_effects.set_effect(GUI::Effects::TabAccents, checked))
set_modified(true);
};
auto& splitter_knurls = *find_descendant_of_type_named<GUI::CheckBox>("splitter_knurls_checkbox");
splitter_knurls.set_checked(m_system_effects.splitter_knurls());
splitter_knurls.on_checked = [this](bool checked) {
if (m_system_effects.set_effect(Effects::SplitterKnurls, checked))
if (m_system_effects.set_effect(GUI::Effects::SplitterKnurls, checked))
set_modified(true);
};
auto& tooltips = *find_descendant_of_type_named<GUI::CheckBox>("tooltips_checkbox");
tooltips.set_checked(m_system_effects.tooltips());
tooltips.on_checked = [this](bool checked) {
if (m_system_effects.set_effect(Effects::Tooltips, checked))
if (m_system_effects.set_effect(GUI::Effects::Tooltips, checked))
set_modified(true);
};
auto& menu_shadow = *find_descendant_of_type_named<GUI::CheckBox>("menu_shadow_checkbox");
menu_shadow.set_checked(m_system_effects.menu_shadow());
menu_shadow.on_checked = [this](bool checked) {
if (m_system_effects.set_effect(Effects::MenuShadow, checked))
if (m_system_effects.set_effect(GUI::Effects::MenuShadow, checked))
set_modified(true);
};
auto& window_shadow = *find_descendant_of_type_named<GUI::CheckBox>("window_shadow_checkbox");
window_shadow.set_checked(m_system_effects.window_shadow());
window_shadow.on_checked = [this](bool checked) {
if (m_system_effects.set_effect(Effects::WindowShadow, checked))
if (m_system_effects.set_effect(GUI::Effects::WindowShadow, checked))
set_modified(true);
};
auto& tooltip_shadow = *find_descendant_of_type_named<GUI::CheckBox>("tooltip_shadow_checkbox");
tooltip_shadow.set_checked(m_system_effects.tooltip_shadow());
tooltip_shadow.on_checked = [this](bool checked) {
if (m_system_effects.set_effect(Effects::TooltipShadow, checked))
if (m_system_effects.set_effect(GUI::Effects::TooltipShadow, checked))
set_modified(true);
};

Expand Down Expand Up @@ -137,7 +131,7 @@ ErrorOr<void> EffectsSettingsWidget::load_settings()
};
for (size_t i = 0; i < geometry_list.size(); ++i)
TRY(m_geometry_list.try_append(TRY(String::from_utf8(geometry_list[i]))));
m_geometry_combobox->set_model(ItemListModel<String>::create(m_geometry_list));
m_geometry_combobox->set_model(GUI::ItemListModel<String>::create(m_geometry_list));
m_geometry_combobox->set_selected_index(to_underlying(m_system_effects.geometry()));

static constexpr Array tile_window_list = {
Expand All @@ -147,17 +141,15 @@ ErrorOr<void> EffectsSettingsWidget::load_settings()
};
for (size_t i = 0; i < tile_window_list.size(); ++i)
TRY(m_tile_window_list.try_append(TRY(String::from_utf8(tile_window_list[i]))));
m_tile_window_combobox->set_model(ItemListModel<String>::create(m_tile_window_list));
m_tile_window_combobox->set_model(GUI::ItemListModel<String>::create(m_tile_window_list));
m_tile_window_combobox->set_selected_index(static_cast<size_t>(m_system_effects.tile_window()));

return {};
}

void EffectsSettingsWidget::apply_settings()
{
ConnectionToWindowServer::the().async_set_system_effects(m_system_effects.effects(), to_underlying(m_system_effects.geometry()), to_underlying(m_system_effects.tile_window()));
}

GUI::ConnectionToWindowServer::the().async_set_system_effects(m_system_effects.effects(), to_underlying(m_system_effects.geometry()), to_underlying(m_system_effects.tile_window()));
}

}
Loading

0 comments on commit dabb372

Please sign in to comment.