2021-05-09 10:56:03 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, the SerenityOS developers.
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibCore/ConfigFile.h>
|
2021-07-05 16:51:54 -03:00
|
|
|
#include <LibCore/File.h>
|
2021-11-29 17:22:07 -03:00
|
|
|
#include <LibCore/System.h>
|
|
|
|
|
#include <LibMain/Main.h>
|
2021-05-14 11:32:57 -03:00
|
|
|
#include <errno.h>
|
2021-05-09 10:56:03 -03:00
|
|
|
#include <spawn.h>
|
|
|
|
|
#include <stdio.h>
|
2021-07-05 16:51:54 -03:00
|
|
|
#include <sys/ioctl.h>
|
2021-05-09 10:56:03 -03:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2021-11-29 17:22:07 -03:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments)
|
2021-05-09 10:56:03 -03:00
|
|
|
{
|
2022-04-09 07:35:21 -03:00
|
|
|
TRY(Core::System::pledge("stdio proc exec rpath cpath"));
|
2022-02-06 10:33:42 -03:00
|
|
|
auto keyboard_settings_config = TRY(Core::ConfigFile::open_for_app("KeyboardSettings"));
|
2021-07-03 20:41:28 -03:00
|
|
|
|
2021-11-29 17:22:07 -03:00
|
|
|
TRY(Core::System::unveil("/bin/keymap", "x"));
|
|
|
|
|
TRY(Core::System::unveil("/etc/Keyboard.ini", "r"));
|
2022-09-10 06:25:20 -03:00
|
|
|
TRY(Core::System::unveil("/dev/input/keyboard/0", "r"));
|
2021-11-29 17:22:07 -03:00
|
|
|
TRY(Core::System::unveil(nullptr, nullptr));
|
2022-02-06 10:33:42 -03:00
|
|
|
auto mapper_config = TRY(Core::ConfigFile::open("/etc/Keyboard.ini"));
|
2022-01-19 12:20:42 -03:00
|
|
|
auto keymaps = mapper_config->read_entry("Mapping", "Keymaps", "");
|
|
|
|
|
|
|
|
|
|
auto keymaps_vector = keymaps.split(',');
|
2022-02-03 08:45:06 -03:00
|
|
|
if (keymaps_vector.size() == 0)
|
|
|
|
|
exit(1);
|
2021-05-09 10:56:03 -03:00
|
|
|
|
|
|
|
|
pid_t child_pid;
|
2022-04-01 14:58:27 -03:00
|
|
|
char const* argv[] = { "/bin/keymap", "-m", keymaps_vector.first().characters(), nullptr };
|
2021-05-09 10:56:03 -03:00
|
|
|
if ((errno = posix_spawn(&child_pid, "/bin/keymap", nullptr, nullptr, const_cast<char**>(argv), environ))) {
|
|
|
|
|
perror("posix_spawn");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2021-07-03 20:41:28 -03:00
|
|
|
|
2021-07-13 18:04:04 -03:00
|
|
|
bool enable_num_lock = keyboard_settings_config->read_bool_entry("StartupEnable", "NumLock", true);
|
2022-09-10 06:25:20 -03:00
|
|
|
auto keyboard_device = TRY(Core::File::open("/dev/input/keyboard/0", Core::OpenMode::ReadOnly));
|
2021-11-29 19:09:43 -03:00
|
|
|
TRY(Core::System::ioctl(keyboard_device->fd(), KEYBOARD_IOCTL_SET_NUM_LOCK, enable_num_lock));
|
2021-11-29 17:22:07 -03:00
|
|
|
|
|
|
|
|
return 0;
|
2021-05-09 10:56:03 -03:00
|
|
|
}
|