Serenity Operating System
1/*
2 * Copyright (c) 2020, Hüseyin Aslıtürk <asliturk@hotmail.com>
3 * Copyright (c) 2022, the SerenityOS developers.
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
6 */
7
8#pragma once
9
10#include "KeyButton.h"
11#include <LibGUI/Button.h>
12#include <LibKeyboard/CharacterMapData.h>
13
14class KeyboardMapperWidget final : public GUI::Widget {
15 C_OBJECT(KeyboardMapperWidget)
16
17public:
18 virtual ~KeyboardMapperWidget() override = default;
19
20 void create_frame();
21 ErrorOr<void> load_map_from_file(DeprecatedString const&);
22 ErrorOr<void> load_map_from_system();
23 ErrorOr<void> save();
24 ErrorOr<void> save_to_file(StringView);
25 void show_error_to_user(Error);
26 void set_automatic_modifier(bool checked);
27
28 bool request_close();
29
30protected:
31 virtual void keydown_event(GUI::KeyEvent&) override;
32 virtual void keyup_event(GUI::KeyEvent&) override;
33
34 void set_current_map(const DeprecatedString);
35 void update_window_title();
36
37private:
38 KeyboardMapperWidget();
39
40 Vector<KeyButton*> m_keys;
41 RefPtr<GUI::Widget> m_map_group;
42 void add_map_radio_button(const StringView map_name, String button_text);
43 u32* map_from_name(const StringView map_name);
44 void update_modifier_radio_buttons(GUI::KeyEvent&);
45
46 DeprecatedString m_filename;
47 Keyboard::CharacterMapData m_character_map;
48 DeprecatedString m_current_map_name;
49 bool m_automatic_modifier { false };
50};