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:
parent
4c43fc0515
commit
d922c2f5f3
6 changed files with 68 additions and 1 deletions
43
Userland/Services/KeyboardPreferenceLoader/main.cpp
Normal file
43
Userland/Services/KeyboardPreferenceLoader/main.cpp
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue