1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:58:11 +00:00

Userland: Preserve keyboard mapping preference on reboot (#6955)

This commit is contained in:
Ömer Kurttekin 2021-05-09 16:56:03 +03:00 committed by GitHub
parent 4c43fc0515
commit d922c2f5f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 68 additions and 1 deletions

View file

@ -0,0 +1,43 @@
/*
* Copyright (c) 2021, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibCore/ConfigFile.h>
#include <spawn.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
if (pledge("stdio proc exec rpath", nullptr) < 0) {
perror("pledge");
return 1;
}
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(nullptr, nullptr) < 0) {
perror("unveil");
return 1;
}
auto mapper_config(Core::ConfigFile::open("/etc/Keyboard.ini"));
auto keymap = mapper_config->read_entry("Mapping", "Keymap", "");
pid_t child_pid;
const char* argv[] = { "/bin/keymap", keymap.characters(), nullptr };
if ((errno = posix_spawn(&child_pid, "/bin/keymap", nullptr, nullptr, const_cast<char**>(argv), environ))) {
perror("posix_spawn");
exit(1);
}
}