1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 20:47:45 +00:00

KeyboardPreferenceLoader: Port to LibMain :^)

This commit is contained in:
Andreas Kling 2021-11-29 21:22:07 +01:00
parent fbeebce4e3
commit 2bb27184b4
2 changed files with 12 additions and 33 deletions

View file

@ -9,4 +9,4 @@ set(SOURCES
) )
serenity_bin(KeyboardPreferenceLoader) serenity_bin(KeyboardPreferenceLoader)
target_link_libraries(KeyboardPreferenceLoader LibCore) target_link_libraries(KeyboardPreferenceLoader LibCore LibMain)

View file

@ -6,41 +6,23 @@
#include <LibCore/ConfigFile.h> #include <LibCore/ConfigFile.h>
#include <LibCore/File.h> #include <LibCore/File.h>
#include <LibCore/System.h>
#include <LibMain/Main.h>
#include <errno.h> #include <errno.h>
#include <spawn.h> #include <spawn.h>
#include <stdio.h> #include <stdio.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <unistd.h> #include <unistd.h>
int main() ErrorOr<int> serenity_main(Main::Arguments)
{ {
if (pledge("stdio proc exec rpath", nullptr) < 0) { TRY(Core::System::pledge("stdio proc exec rpath"));
perror("pledge");
return 1;
}
auto keyboard_settings_config = Core::ConfigFile::open_for_app("KeyboardSettings"); auto keyboard_settings_config = Core::ConfigFile::open_for_app("KeyboardSettings");
if (unveil("/bin/keymap", "x") < 0) { TRY(Core::System::unveil("/bin/keymap", "x"));
perror("unveil /bin/keymap"); TRY(Core::System::unveil("/etc/Keyboard.ini", "r"));
return 1; TRY(Core::System::unveil("/dev/keyboard0", "r"));
} TRY(Core::System::unveil(nullptr, nullptr));
if (unveil("/etc/Keyboard.ini", "r") < 0) {
perror("unveil /etc/Keyboard.ini");
return 1;
}
if (unveil("/dev/keyboard0", "r") < 0) {
perror("unveil /dev/keyboard0");
return 1;
}
if (unveil(nullptr, nullptr) < 0) {
perror("unveil");
return 1;
}
auto mapper_config(Core::ConfigFile::open("/etc/Keyboard.ini")); auto mapper_config(Core::ConfigFile::open("/etc/Keyboard.ini"));
auto keymap = mapper_config->read_entry("Mapping", "Keymap", ""); auto keymap = mapper_config->read_entry("Mapping", "Keymap", "");
@ -53,16 +35,13 @@ int main()
bool enable_num_lock = keyboard_settings_config->read_bool_entry("StartupEnable", "NumLock", true); bool enable_num_lock = keyboard_settings_config->read_bool_entry("StartupEnable", "NumLock", true);
auto keyboard_device_or_error = Core::File::open("/dev/keyboard0", Core::OpenMode::ReadOnly); auto keyboard_device = TRY(Core::File::open("/dev/keyboard0", Core::OpenMode::ReadOnly));
if (keyboard_device_or_error.is_error()) {
warnln("Failed to open /dev/keyboard0: {}", keyboard_device_or_error.error());
VERIFY_NOT_REACHED();
}
auto keyboard_device = keyboard_device_or_error.release_value();
int rc = ioctl(keyboard_device->fd(), KEYBOARD_IOCTL_SET_NUM_LOCK, enable_num_lock); int rc = ioctl(keyboard_device->fd(), KEYBOARD_IOCTL_SET_NUM_LOCK, enable_num_lock);
if (rc < 0) { if (rc < 0) {
perror("ioctl(KEYBOARD_IOCTL_SET_NUM_LOCK)"); perror("ioctl(KEYBOARD_IOCTL_SET_NUM_LOCK)");
return 1; return 1;
} }
return 0;
} }