Chess: Automatically update and repaint when the config changes

This commit is contained in:
Sam Atkins 2023-02-01 21:33:31 +00:00 committed by Andreas Kling
parent 05913b853a
commit 89d7d29d68
3 changed files with 34 additions and 1 deletions

View file

@ -699,3 +699,28 @@ int ChessWidget::resign()
return 0;
}
void ChessWidget::config_string_did_change(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key, DeprecatedString const& value)
{
if (domain != "Games"sv && group != "Chess"sv)
return;
if (key == "PieceSet"sv) {
set_piece_set(value);
update();
} else if (key == "BoardTheme"sv) {
set_board_theme(value);
update();
}
}
void ChessWidget::config_bool_did_change(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key, bool value)
{
if (domain != "Games"sv && group != "Chess"sv)
return;
if (key == "ShowCoordinates"sv) {
set_coordinates(value);
update();
}
}

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2020-2022, the SerenityOS developers.
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -11,10 +12,13 @@
#include <AK/NonnullRefPtr.h>
#include <AK/Optional.h>
#include <LibChess/Chess.h>
#include <LibConfig/Listener.h>
#include <LibGUI/Frame.h>
#include <LibGfx/Bitmap.h>
class ChessWidget final : public GUI::Frame {
class ChessWidget final
: public GUI::Frame
, public Config::Listener {
C_OBJECT(ChessWidget);
public:
@ -107,6 +111,9 @@ public:
private:
ChessWidget();
virtual void config_string_did_change(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key, DeprecatedString const& value) override;
virtual void config_bool_did_change(DeprecatedString const& domain, DeprecatedString const& group, DeprecatedString const& key, bool value) override;
Chess::Board m_board;
Chess::Board m_board_playback;
bool m_playback { false };

View file

@ -27,6 +27,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto app = TRY(GUI::Application::try_create(arguments));
Config::pledge_domain("Games");
Config::monitor_domain("Games");
TRY(Desktop::Launcher::add_allowed_handler_with_only_specific_urls("/bin/Help", { URL::create_with_file_scheme("/usr/share/man/man6/Chess.md") }));
TRY(Desktop::Launcher::seal_allowlist());