mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-29 19:10:26 +00:00
KeyboardPreferenceLoader: Port to LibMain :^)
This commit is contained in:
parent
fbeebce4e3
commit
2bb27184b4
Notes:
sideshowbarker
2024-07-17 23:17:04 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/2bb27184b4e
2 changed files with 12 additions and 33 deletions
|
@ -9,4 +9,4 @@ set(SOURCES
|
|||
)
|
||||
|
||||
serenity_bin(KeyboardPreferenceLoader)
|
||||
target_link_libraries(KeyboardPreferenceLoader LibCore)
|
||||
target_link_libraries(KeyboardPreferenceLoader LibCore LibMain)
|
||||
|
|
|
@ -6,41 +6,23 @@
|
|||
|
||||
#include <LibCore/ConfigFile.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <errno.h>
|
||||
#include <spawn.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
ErrorOr<int> serenity_main(Main::Arguments)
|
||||
{
|
||||
if (pledge("stdio proc exec rpath", nullptr) < 0) {
|
||||
perror("pledge");
|
||||
return 1;
|
||||
}
|
||||
|
||||
TRY(Core::System::pledge("stdio proc exec rpath"));
|
||||
auto keyboard_settings_config = Core::ConfigFile::open_for_app("KeyboardSettings");
|
||||
|
||||
if (unveil("/bin/keymap", "x") < 0) {
|
||||
perror("unveil /bin/keymap");
|
||||
return 1;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
TRY(Core::System::unveil("/bin/keymap", "x"));
|
||||
TRY(Core::System::unveil("/etc/Keyboard.ini", "r"));
|
||||
TRY(Core::System::unveil("/dev/keyboard0", "r"));
|
||||
TRY(Core::System::unveil(nullptr, nullptr));
|
||||
auto mapper_config(Core::ConfigFile::open("/etc/Keyboard.ini"));
|
||||
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);
|
||||
|
||||
auto keyboard_device_or_error = 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();
|
||||
auto keyboard_device = TRY(Core::File::open("/dev/keyboard0", Core::OpenMode::ReadOnly));
|
||||
|
||||
int rc = ioctl(keyboard_device->fd(), KEYBOARD_IOCTL_SET_NUM_LOCK, enable_num_lock);
|
||||
if (rc < 0) {
|
||||
perror("ioctl(KEYBOARD_IOCTL_SET_NUM_LOCK)");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue