1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:17:35 +00:00

WindowServer: Use enum class for Effects and ShowGeometry

This commit is contained in:
Tom 2023-04-03 21:26:20 -06:00 committed by Linus Groh
parent 2125464b76
commit 6f9c5b71fd
2 changed files with 44 additions and 34 deletions

View file

@ -42,62 +42,62 @@ ErrorOr<void> EffectsSettingsWidget::setup_interface()
auto& animate_menus = *find_descendant_of_type_named<GUI::CheckBox>("animate_menus_checkbox"); auto& animate_menus = *find_descendant_of_type_named<GUI::CheckBox>("animate_menus_checkbox");
animate_menus.set_checked(m_system_effects.animate_menus()); animate_menus.set_checked(m_system_effects.animate_menus());
animate_menus.on_checked = [this](bool checked) { animate_menus.on_checked = [this](bool checked) {
m_system_effects.effects().at(Effects::AnimateMenus) = checked; if (m_system_effects.set_effect(Effects::AnimateMenus, checked))
set_modified(true); set_modified(true);
}; };
auto& flash_menus = *find_descendant_of_type_named<GUI::CheckBox>("flash_menus_checkbox"); auto& flash_menus = *find_descendant_of_type_named<GUI::CheckBox>("flash_menus_checkbox");
flash_menus.set_checked(m_system_effects.flash_menus()); flash_menus.set_checked(m_system_effects.flash_menus());
flash_menus.on_checked = [this](bool checked) { flash_menus.on_checked = [this](bool checked) {
m_system_effects.effects().at(Effects::FlashMenus) = checked; if (m_system_effects.set_effect(Effects::FlashMenus, checked))
set_modified(true); set_modified(true);
}; };
auto& animate_windows = *find_descendant_of_type_named<GUI::CheckBox>("animate_windows_checkbox"); auto& animate_windows = *find_descendant_of_type_named<GUI::CheckBox>("animate_windows_checkbox");
animate_windows.set_checked(m_system_effects.animate_windows()); animate_windows.set_checked(m_system_effects.animate_windows());
animate_windows.on_checked = [this](bool checked) { animate_windows.on_checked = [this](bool checked) {
m_system_effects.effects().at(Effects::AnimateWindows) = checked; if (m_system_effects.set_effect(Effects::AnimateWindows, checked))
set_modified(true); set_modified(true);
}; };
auto& smooth_scrolling = *find_descendant_of_type_named<GUI::CheckBox>("smooth_scrolling_checkbox"); auto& smooth_scrolling = *find_descendant_of_type_named<GUI::CheckBox>("smooth_scrolling_checkbox");
smooth_scrolling.set_checked(m_system_effects.smooth_scrolling()); smooth_scrolling.set_checked(m_system_effects.smooth_scrolling());
smooth_scrolling.on_checked = [this](bool checked) { smooth_scrolling.on_checked = [this](bool checked) {
m_system_effects.effects().at(Effects::SmoothScrolling) = checked; if (m_system_effects.set_effect(Effects::SmoothScrolling, checked))
set_modified(true); set_modified(true);
}; };
auto& tab_accents = *find_descendant_of_type_named<GUI::CheckBox>("tab_accents_checkbox"); auto& tab_accents = *find_descendant_of_type_named<GUI::CheckBox>("tab_accents_checkbox");
tab_accents.set_checked(m_system_effects.tab_accents()); tab_accents.set_checked(m_system_effects.tab_accents());
tab_accents.on_checked = [this](bool checked) { tab_accents.on_checked = [this](bool checked) {
m_system_effects.effects().at(Effects::TabAccents) = checked; if (m_system_effects.set_effect(Effects::TabAccents, checked))
set_modified(true); set_modified(true);
}; };
auto& splitter_knurls = *find_descendant_of_type_named<GUI::CheckBox>("splitter_knurls_checkbox"); auto& splitter_knurls = *find_descendant_of_type_named<GUI::CheckBox>("splitter_knurls_checkbox");
splitter_knurls.set_checked(m_system_effects.splitter_knurls()); splitter_knurls.set_checked(m_system_effects.splitter_knurls());
splitter_knurls.on_checked = [this](bool checked) { splitter_knurls.on_checked = [this](bool checked) {
m_system_effects.effects().at(Effects::SplitterKnurls) = checked; if (m_system_effects.set_effect(Effects::SplitterKnurls, checked))
set_modified(true); set_modified(true);
}; };
auto& tooltips = *find_descendant_of_type_named<GUI::CheckBox>("tooltips_checkbox"); auto& tooltips = *find_descendant_of_type_named<GUI::CheckBox>("tooltips_checkbox");
tooltips.set_checked(m_system_effects.tooltips()); tooltips.set_checked(m_system_effects.tooltips());
tooltips.on_checked = [this](bool checked) { tooltips.on_checked = [this](bool checked) {
m_system_effects.effects().at(Effects::Tooltips) = checked; if (m_system_effects.set_effect(Effects::Tooltips, checked))
set_modified(true); set_modified(true);
}; };
auto& menu_shadow = *find_descendant_of_type_named<GUI::CheckBox>("menu_shadow_checkbox"); auto& menu_shadow = *find_descendant_of_type_named<GUI::CheckBox>("menu_shadow_checkbox");
menu_shadow.set_checked(m_system_effects.menu_shadow()); menu_shadow.set_checked(m_system_effects.menu_shadow());
menu_shadow.on_checked = [this](bool checked) { menu_shadow.on_checked = [this](bool checked) {
m_system_effects.effects().at(Effects::MenuShadow) = checked; if (m_system_effects.set_effect(Effects::MenuShadow, checked))
set_modified(true); set_modified(true);
}; };
auto& window_shadow = *find_descendant_of_type_named<GUI::CheckBox>("window_shadow_checkbox"); auto& window_shadow = *find_descendant_of_type_named<GUI::CheckBox>("window_shadow_checkbox");
window_shadow.set_checked(m_system_effects.window_shadow()); window_shadow.set_checked(m_system_effects.window_shadow());
window_shadow.on_checked = [this](bool checked) { window_shadow.on_checked = [this](bool checked) {
m_system_effects.effects().at(Effects::WindowShadow) = checked; if (m_system_effects.set_effect(Effects::WindowShadow, checked))
set_modified(true); set_modified(true);
}; };
auto& tooltip_shadow = *find_descendant_of_type_named<GUI::CheckBox>("tooltip_shadow_checkbox"); auto& tooltip_shadow = *find_descendant_of_type_named<GUI::CheckBox>("tooltip_shadow_checkbox");
tooltip_shadow.set_checked(m_system_effects.tooltip_shadow()); tooltip_shadow.set_checked(m_system_effects.tooltip_shadow());
tooltip_shadow.on_checked = [this](bool checked) { tooltip_shadow.on_checked = [this](bool checked) {
m_system_effects.effects().at(Effects::TooltipShadow) = checked; if (m_system_effects.set_effect(Effects::TooltipShadow, checked))
set_modified(true); set_modified(true);
}; };
return {}; return {};
@ -130,14 +130,14 @@ ErrorOr<void> EffectsSettingsWidget::load_settings()
for (size_t i = 0; i < list.size(); ++i) for (size_t i = 0; i < list.size(); ++i)
TRY(m_geometry_list.try_append(TRY(String::from_utf8(list[i])))); TRY(m_geometry_list.try_append(TRY(String::from_utf8(list[i]))));
m_geometry_combobox->set_model(ItemListModel<String>::create(m_geometry_list)); m_geometry_combobox->set_model(ItemListModel<String>::create(m_geometry_list));
m_geometry_combobox->set_selected_index(m_system_effects.geometry()); m_geometry_combobox->set_selected_index(to_underlying(m_system_effects.geometry()));
return {}; return {};
} }
void EffectsSettingsWidget::apply_settings() void EffectsSettingsWidget::apply_settings()
{ {
ConnectionToWindowServer::the().async_set_system_effects(m_system_effects.effects(), m_system_effects.geometry()); ConnectionToWindowServer::the().async_set_system_effects(m_system_effects.effects(), to_underlying(m_system_effects.geometry()));
} }
} }

View file

@ -12,14 +12,14 @@
namespace WindowServer { namespace WindowServer {
enum ShowGeometry : u8 { enum class ShowGeometry : u8 {
OnMoveAndResize, OnMoveAndResize,
OnMoveOnly, OnMoveOnly,
OnResizeOnly, OnResizeOnly,
Never Never
}; };
enum Effects : size_t { enum class Effects : size_t {
AnimateMenus, AnimateMenus,
FlashMenus, FlashMenus,
AnimateWindows, AnimateWindows,
@ -81,18 +81,28 @@ public:
~SystemEffects() = default; ~SystemEffects() = default;
Vector<bool>& effects() { return m_effects; } Vector<bool>& effects() { return m_effects; }
bool animate_menus() const { return m_effects[AnimateMenus]; } bool set_effect(Effects effect, bool value)
bool flash_menus() const { return m_effects[FlashMenus]; } {
bool animate_windows() const { return m_effects[AnimateWindows]; } VERIFY(effect < Effects::__Count);
bool smooth_scrolling() const { return m_effects[SmoothScrolling]; } auto& effect_value = m_effects[to_underlying(effect)];
if (effect_value == value)
return false;
effect_value = value;
return true;
}
bool tab_accents() const { return m_effects[TabAccents]; } bool animate_menus() const { return m_effects[to_underlying(Effects::AnimateMenus)]; }
bool splitter_knurls() const { return m_effects[SplitterKnurls]; } bool flash_menus() const { return m_effects[to_underlying(Effects::FlashMenus)]; }
bool tooltips() const { return m_effects[Tooltips]; } bool animate_windows() const { return m_effects[to_underlying(Effects::AnimateWindows)]; }
bool smooth_scrolling() const { return m_effects[to_underlying(Effects::SmoothScrolling)]; }
bool menu_shadow() const { return m_effects[MenuShadow]; } bool tab_accents() const { return m_effects[to_underlying(Effects::TabAccents)]; }
bool window_shadow() const { return m_effects[WindowShadow]; } bool splitter_knurls() const { return m_effects[to_underlying(Effects::SplitterKnurls)]; }
bool tooltip_shadow() const { return m_effects[TooltipShadow]; } bool tooltips() const { return m_effects[to_underlying(Effects::Tooltips)]; }
bool menu_shadow() const { return m_effects[to_underlying(Effects::MenuShadow)]; }
bool window_shadow() const { return m_effects[to_underlying(Effects::WindowShadow)]; }
bool tooltip_shadow() const { return m_effects[to_underlying(Effects::TooltipShadow)]; }
void set_geometry(ShowGeometry g) { m_geometry = g; } void set_geometry(ShowGeometry g) { m_geometry = g; }
ShowGeometry geometry() const { return m_geometry; } ShowGeometry geometry() const { return m_geometry; }