mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
KeyboardSettings: Port to GML compiler
This commit is contained in:
parent
c2c7365494
commit
ca2aaaeac2
Notes:
sideshowbarker
2024-07-17 08:35:21 +09:00
Author: https://github.com/notSanil Commit: https://github.com/SerenityOS/serenity/commit/ca2aaaeac2 Pull-request: https://github.com/SerenityOS/serenity/pull/22685 Reviewed-by: https://github.com/timschumi ✅
7 changed files with 60 additions and 20 deletions
|
@ -4,17 +4,14 @@ serenity_component(
|
|||
TARGETS KeyboardSettings
|
||||
)
|
||||
|
||||
stringify_gml(Keyboard.gml KeyboardWidgetGML.h keyboard_widget_gml)
|
||||
stringify_gml(KeymapDialog.gml KeymapDialogGML.h keymap_dialog_gml)
|
||||
compile_gml(Keyboard.gml KeyboardWidgetGML.cpp)
|
||||
compile_gml(KeymapDialog.gml KeymapDialogGML.cpp)
|
||||
|
||||
set(SOURCES
|
||||
KeyboardSettingsWidget.cpp
|
||||
main.cpp
|
||||
)
|
||||
|
||||
set(GENERATED_SOURCES
|
||||
KeyboardWidgetGML.h
|
||||
KeymapDialogGML.h
|
||||
KeyboardWidgetGML.cpp
|
||||
KeymapDialogGML.cpp
|
||||
)
|
||||
|
||||
serenity_app(KeyboardSettings ICON app-keyboard-settings)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@GUI::Frame {
|
||||
@KeyboardSettings::KeyboardSettingsWidget {
|
||||
fill_with_background_color: true
|
||||
layout: @GUI::VerticalBoxLayout {
|
||||
margins: [8]
|
||||
|
|
|
@ -8,10 +8,9 @@
|
|||
*/
|
||||
|
||||
#include "KeyboardSettingsWidget.h"
|
||||
#include "KeymapDialog.h"
|
||||
#include <AK/JsonObject.h>
|
||||
#include <AK/QuickSort.h>
|
||||
#include <Applications/KeyboardSettings/KeyboardWidgetGML.h>
|
||||
#include <Applications/KeyboardSettings/KeymapDialogGML.h>
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibCore/Directory.h>
|
||||
#include <LibFileSystem/FileSystem.h>
|
||||
|
@ -29,6 +28,7 @@
|
|||
#include <LibKeyboard/CharacterMap.h>
|
||||
#include <spawn.h>
|
||||
|
||||
namespace KeyboardSettings {
|
||||
class KeymapSelectionDialog final : public GUI::Dialog {
|
||||
C_OBJECT(KeymapSelectionDialog)
|
||||
public:
|
||||
|
@ -36,7 +36,13 @@ public:
|
|||
|
||||
static ByteString select_keymap(Window* parent_window, Vector<ByteString> const& selected_keymaps)
|
||||
{
|
||||
auto dialog = KeymapSelectionDialog::construct(parent_window, selected_keymaps);
|
||||
auto dialog_or_error = KeymapSelectionDialog::create(parent_window, selected_keymaps);
|
||||
if (dialog_or_error.is_error()) {
|
||||
GUI::MessageBox::show(parent_window, "Couldn't load \"add keymap\" dialog"sv, "Error while opening \"add keymap\" dialog"sv, GUI::MessageBox::Type::Error);
|
||||
return ByteString::empty();
|
||||
}
|
||||
|
||||
auto dialog = dialog_or_error.release_value();
|
||||
dialog->set_title("Add a keymap");
|
||||
|
||||
if (dialog->exec() == ExecResult::OK) {
|
||||
|
@ -49,11 +55,17 @@ public:
|
|||
ByteString selected_keymap() { return m_selected_keymap; }
|
||||
|
||||
private:
|
||||
KeymapSelectionDialog(Window* parent_window, Vector<ByteString> const& selected_keymaps)
|
||||
static ErrorOr<NonnullRefPtr<KeymapSelectionDialog>> create(Window* parent_window, Vector<ByteString> const& selected_keymaps)
|
||||
{
|
||||
auto widget = TRY(KeyboardSettings::KeymapDialog::try_create());
|
||||
auto dialog = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) KeymapSelectionDialog(parent_window, selected_keymaps, widget)));
|
||||
return dialog;
|
||||
}
|
||||
|
||||
KeymapSelectionDialog(Window* parent_window, Vector<ByteString> const& selected_keymaps, NonnullRefPtr<KeymapDialog> widget)
|
||||
: Dialog(parent_window)
|
||||
{
|
||||
auto widget = set_main_widget<GUI::Widget>();
|
||||
widget->load_from_gml(keymap_dialog_gml).release_value_but_fixme_should_propagate_errors();
|
||||
set_main_widget(widget);
|
||||
|
||||
set_resizable(false);
|
||||
resize(190, 54);
|
||||
|
@ -149,16 +161,15 @@ private:
|
|||
ByteString m_active_keymap;
|
||||
};
|
||||
|
||||
ErrorOr<NonnullRefPtr<KeyboardSettingsWidget>> KeyboardSettingsWidget::try_create()
|
||||
ErrorOr<NonnullRefPtr<KeyboardSettingsWidget>> KeyboardSettingsWidget::create()
|
||||
{
|
||||
auto widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) KeyboardSettingsWidget()));
|
||||
auto widget = TRY(try_create());
|
||||
TRY(widget->setup());
|
||||
return widget;
|
||||
}
|
||||
|
||||
ErrorOr<void> KeyboardSettingsWidget::setup()
|
||||
{
|
||||
TRY(load_from_gml(keyboard_widget_gml));
|
||||
auto proc_keymap = TRY(Core::File::open("/sys/kernel/keymap"sv, Core::File::OpenMode::Read));
|
||||
|
||||
auto keymap = TRY(proc_keymap->read_until_eof());
|
||||
|
@ -327,3 +338,5 @@ ErrorOr<bool> KeyboardSettingsWidget::read_caps_lock_to_ctrl_sys_variable()
|
|||
StringView contents_string((char const*)buffer.data(), min(1, buffer.size()));
|
||||
return contents_string == "1";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,17 +15,20 @@
|
|||
#include <LibGUI/SettingsWindow.h>
|
||||
#include <LibGUI/TextEditor.h>
|
||||
|
||||
namespace KeyboardSettings {
|
||||
|
||||
class KeyboardSettingsWidget final : public GUI::SettingsWindow::Tab {
|
||||
C_OBJECT_ABSTRACT(KeyboardSettingsWidget)
|
||||
public:
|
||||
static ErrorOr<NonnullRefPtr<KeyboardSettingsWidget>> try_create();
|
||||
virtual ~KeyboardSettingsWidget() override;
|
||||
|
||||
virtual void apply_settings() override;
|
||||
|
||||
void window_activated(bool is_active_window);
|
||||
static ErrorOr<NonnullRefPtr<KeyboardSettingsWidget>> create();
|
||||
|
||||
private:
|
||||
static ErrorOr<NonnullRefPtr<KeyboardSettingsWidget>> try_create();
|
||||
KeyboardSettingsWidget() = default;
|
||||
ErrorOr<void> setup();
|
||||
|
||||
|
@ -50,3 +53,5 @@ private:
|
|||
|
||||
Function<void()> m_activate_keymap_event;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@GUI::Widget {
|
||||
@KeyboardSettings::KeymapDialog {
|
||||
fill_with_background_color: true
|
||||
layout: @GUI::VerticalBoxLayout {
|
||||
margins: [4]
|
||||
|
|
23
Userland/Applications/KeyboardSettings/KeymapDialog.h
Normal file
23
Userland/Applications/KeyboardSettings/KeymapDialog.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Sanil Gupta <sanilg566@gmail.com>.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibGUI/Widget.h>
|
||||
|
||||
namespace KeyboardSettings {
|
||||
|
||||
class KeymapDialog : public GUI::Widget {
|
||||
C_OBJECT_ABSTRACT(KeymapDialog)
|
||||
public:
|
||||
static ErrorOr<NonnullRefPtr<KeymapDialog>> try_create();
|
||||
virtual ~KeymapDialog() override = default;
|
||||
|
||||
private:
|
||||
KeymapDialog() = default;
|
||||
};
|
||||
|
||||
}
|
|
@ -37,7 +37,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
auto window = TRY(GUI::SettingsWindow::create("Keyboard Settings"));
|
||||
window->set_icon(app_icon.bitmap_for_size(16));
|
||||
auto keyboard_settings_widget = TRY(window->add_tab<KeyboardSettingsWidget>("Keyboard"_string, "keyboard"sv));
|
||||
|
||||
auto keyboard_settings_widget = TRY(KeyboardSettings::KeyboardSettingsWidget::create());
|
||||
TRY(window->add_tab(keyboard_settings_widget, "Keyboard"_string, "keyboard"sv));
|
||||
window->set_active_tab(selected_tab);
|
||||
|
||||
window->on_active_window_change = [&](bool is_active_window) {
|
||||
|
|
Loading…
Add table
Reference in a new issue