mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
Userland: Preserve keyboard mapping preference on reboot (#6955)
This commit is contained in:
parent
4c43fc0515
commit
d922c2f5f3
Notes:
sideshowbarker
2024-07-18 18:26:33 +09:00
Author: https://github.com/Omerktn 🔰 Commit: https://github.com/SerenityOS/serenity/commit/d922c2f5f3e Pull-request: https://github.com/SerenityOS/serenity/pull/6955 Reviewed-by: https://github.com/awesomekling
6 changed files with 68 additions and 1 deletions
2
Base/etc/Keyboard.ini
Normal file
2
Base/etc/Keyboard.ini
Normal file
|
@ -0,0 +1,2 @@
|
|||
[Mapping]
|
||||
Keymap=en-us
|
|
@ -161,6 +161,10 @@ AcceptSocketConnections=1
|
|||
KeepAlive=1
|
||||
User=anon
|
||||
|
||||
[KeyboardPreferenceLoader]
|
||||
KeepAlive=0
|
||||
User=anon
|
||||
|
||||
[TestRunner@ttyS0]
|
||||
Executable=/home/anon/tests/run-tests-and-shutdown.sh
|
||||
StdIO=/dev/ttyS0
|
||||
|
|
|
@ -6,6 +6,7 @@ add_subdirectory(DHCPClient)
|
|||
add_subdirectory(EchoServer)
|
||||
add_subdirectory(FileOperation)
|
||||
add_subdirectory(ImageDecoder)
|
||||
add_subdirectory(KeyboardPreferenceLoader)
|
||||
add_subdirectory(LaunchServer)
|
||||
add_subdirectory(LookupServer)
|
||||
add_subdirectory(NotificationServer)
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
serenity_bin(KeyboardPreferenceLoader)
|
||||
target_link_libraries(KeyboardPreferenceLoader LibCore)
|
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);
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/ConfigFile.h>
|
||||
#include <LibKeyboard/CharacterMap.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -12,7 +13,7 @@
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (pledge("stdio setkeymap getkeymap rpath", nullptr) < 0) {
|
||||
if (pledge("stdio setkeymap getkeymap rpath wpath cpath", nullptr) < 0) {
|
||||
perror("pledge");
|
||||
return 1;
|
||||
}
|
||||
|
@ -22,6 +23,11 @@ int main(int argc, char** argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (unveil("/etc/Keyboard.ini", "rwc") < 0) {
|
||||
perror("unveil /etc/Keyboard.ini");
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* path = nullptr;
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_positional_argument(path, "The mapping file to be used", "file", Core::ArgsParser::Required::No);
|
||||
|
@ -60,7 +66,12 @@ int main(int argc, char** argv)
|
|||
int rc = character_map.value().set_system_map();
|
||||
if (rc != 0) {
|
||||
perror("setkeymap");
|
||||
return rc;
|
||||
}
|
||||
|
||||
auto mapper_config(Core::ConfigFile::open("/etc/Keyboard.ini"));
|
||||
mapper_config->write_entry("Mapping", "Keymap", path);
|
||||
mapper_config->sync();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue