diff options
Diffstat (limited to 'Applications')
-rw-r--r-- | Applications/KeyboardSettings/main.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Applications/KeyboardSettings/main.cpp b/Applications/KeyboardSettings/main.cpp index 6f53644c44..dd0eb5ca02 100644 --- a/Applications/KeyboardSettings/main.cpp +++ b/Applications/KeyboardSettings/main.cpp @@ -26,8 +26,10 @@ #include "CharacterMapFileListModel.h" #include <AK/QuickSort.h> +#include <AK/JsonObject.h> #include <LibCore/ArgsParser.h> #include <LibCore/DirIterator.h> +#include <LibCore/File.h> #include <LibGUI/AboutDialog.h> #include <LibGUI/Action.h> #include <LibGUI/Application.h> @@ -67,6 +69,11 @@ int main(int argc, char** argv) return 1; } + if (unveil("/proc/keymap", "r") < 0) { + perror("unveil"); + return 1; + } + if (unveil(nullptr, nullptr)) { perror("unveil"); return 1; @@ -74,6 +81,17 @@ int main(int argc, char** argv) auto app_icon = GUI::Icon::default_icon("app-keyboard-settings"); + auto proc_keymap = Core::File::construct("/proc/keymap"); + if (!proc_keymap->open(Core::IODevice::OpenMode::ReadOnly)) + ASSERT_NOT_REACHED(); + + auto json = JsonValue::from_string(proc_keymap->read_all()); + ASSERT(json.has_value()); + JsonObject keymap_object = json.value().as_object(); + ASSERT(keymap_object.has("keymap")); + String current_keymap = keymap_object.get("keymap").to_string(); + dbg() << "KeyboardSettings thinks the current keymap is: " << current_keymap; + Vector<String> character_map_files; Core::DirIterator iterator("/res/keymaps/", Core::DirIterator::Flags::SkipDots); if (iterator.has_error()) { @@ -88,6 +106,13 @@ int main(int argc, char** argv) } quick_sort(character_map_files); + size_t initial_keymap_index = SIZE_MAX; + for (size_t i = 0; i < character_map_files.size(); ++i) { + if (character_map_files[i].equals_ignoring_case(current_keymap)) + initial_keymap_index = i; + } + ASSERT(initial_keymap_index < character_map_files.size()); + auto window = GUI::Window::construct(); window->set_title("Keyboard settings"); window->resize(300, 70); @@ -115,6 +140,7 @@ int main(int argc, char** argv) character_map_file_combo.set_preferred_size(0, 22); character_map_file_combo.set_only_allow_values_from_model(true); character_map_file_combo.set_model(*CharacterMapFileListModel::create(character_map_files)); + character_map_file_combo.set_selected_index(initial_keymap_index); root_widget.layout()->add_spacer(); |