KeyboardSettings+Kernel: Setting to enable Num Lock on login

This commit is contained in:
ForLoveOfCats 2021-07-03 19:41:28 -04:00 committed by Gunnar Beutner
parent 7fdeb0ec74
commit ce6658acc1
Notes: sideshowbarker 2024-07-18 10:25:01 +09:00
11 changed files with 58 additions and 1 deletions

View file

@ -143,6 +143,7 @@ namespace Kernel {
S(getrandom) \
S(getkeymap) \
S(setkeymap) \
S(set_num_lock) \
S(clock_gettime) \
S(clock_settime) \
S(clock_nanosleep) \

View file

@ -191,6 +191,7 @@ set(KERNEL_SOURCES
Syscalls/mmap.cpp
Syscalls/module.cpp
Syscalls/mount.cpp
Syscalls/num_lock.cpp
Syscalls/open.cpp
Syscalls/perf_event.cpp
Syscalls/pipe.cpp

View file

@ -98,6 +98,11 @@ void HIDManagement::set_maps(const Keyboard::CharacterMapData& character_map_dat
dbgln("New Character map '{}' passed in by client.", character_map_name);
}
void HIDManagement::set_num_lock(bool on)
{
m_i8042_controller->keyboard()->set_num_lock(on);
}
UNMAP_AFTER_INIT void HIDManagement::enumerate()
{
// FIXME: When we have USB HID support, we should ensure that we disable

View file

@ -45,6 +45,7 @@ public:
const Keyboard::CharacterMap& character_map() const { return m_character_map; }
void set_client(KeyboardClient* client) { m_client = client; }
void set_maps(const Keyboard::CharacterMapData& character_map, const String& character_map_name);
void set_num_lock(bool on);
private:
size_t generate_minor_device_number_for_mouse();

View file

@ -45,6 +45,8 @@ public:
m_modifiers &= ~modifier;
}
void set_num_lock(bool on) { m_num_lock_on = on; }
protected:
KeyboardDevice();
mutable SpinLock<u8> m_queue_lock;

View file

@ -291,6 +291,7 @@ public:
KResultOr<FlatPtr> sys$getresuid(Userspace<uid_t*>, Userspace<uid_t*>, Userspace<uid_t*>);
KResultOr<FlatPtr> sys$getresgid(Userspace<gid_t*>, Userspace<gid_t*>, Userspace<gid_t*>);
KResultOr<FlatPtr> sys$umask(mode_t);
KResultOr<FlatPtr> sys$set_num_lock(bool);
KResultOr<FlatPtr> sys$open(Userspace<const Syscall::SC_open_params*>);
KResultOr<FlatPtr> sys$close(int fd);
KResultOr<FlatPtr> sys$read(int fd, Userspace<u8*>, size_t);

View file

@ -0,0 +1,18 @@
/*
* Copyright (c) 2021, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/Devices/HID/HIDManagement.h>
#include <Kernel/Process.h>
namespace Kernel {
KResultOr<FlatPtr> Process::sys$set_num_lock(bool on)
{
HIDManagement::the().set_num_lock(on);
return 0;
}
}

View file

@ -8,12 +8,14 @@
#include <AK/JsonObject.h>
#include <AK/QuickSort.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/ConfigFile.h>
#include <LibCore/DirIterator.h>
#include <LibCore/File.h>
#include <LibGUI/Action.h>
#include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
#include <LibGUI/CheckBox.h>
#include <LibGUI/ComboBox.h>
#include <LibGUI/Label.h>
#include <LibGUI/Menu.h>
@ -33,11 +35,17 @@ int main(int argc, char** argv)
// If there is no command line parameter go for GUI.
auto app = GUI::Application::construct(argc, argv);
if (pledge("stdio rpath recvfd sendfd proc exec", nullptr) < 0) {
if (pledge("stdio rpath cpath wpath recvfd sendfd proc exec", nullptr) < 0) {
perror("pledge");
return 1;
}
auto config = Core::ConfigFile::get_for_app("KeyboardSettings");
if (unveil(config->filename().characters(), "rwc") < 0) {
perror("unveil");
return 1;
}
if (unveil("/res", "r") < 0) {
perror("unveil");
return 1;
@ -117,6 +125,9 @@ int main(int argc, char** argv)
character_map_file_combo.set_model(*CharacterMapFileListModel::create(character_map_files));
character_map_file_combo.set_selected_index(initial_keymap_index);
auto& num_lock_checkbox = root_widget.add<GUI::CheckBox>("Enable Num Lock on login");
num_lock_checkbox.set_checked(config->read_bool_entry("StartupEnable", "NumLock", true));
root_widget.layout()->add_spacer();
auto apply_settings = [&](bool quit) {
@ -131,6 +142,10 @@ int main(int argc, char** argv)
perror("posix_spawn");
exit(1);
}
config->write_bool_entry("StartupEnable", "NumLock", num_lock_checkbox.is_checked());
config->sync();
if (quit)
app->quit();
};

View file

@ -137,6 +137,11 @@ int getkeymap(char* name_buffer, size_t name_buffer_size, u32* map, u32* shift_m
__RETURN_WITH_ERRNO(rc, rc, -1);
}
void set_num_lock(bool on)
{
syscall(SC_set_num_lock, on);
}
u16 internet_checksum(const void* ptr, size_t count)
{
u32 checksum = 0;

View file

@ -105,6 +105,8 @@ int serenity_readlink(const char* path, size_t path_length, char* buffer, size_t
int getkeymap(char* name_buffer, size_t name_buffer_size, uint32_t* map, uint32_t* shift_map, uint32_t* alt_map, uint32_t* altgr_map, uint32_t* shift_altgr_map);
int setkeymap(const char* name, const uint32_t* map, uint32_t* const shift_map, const uint32_t* alt_map, const uint32_t* altgr_map, const uint32_t* shift_altgr_map);
void set_num_lock(bool on);
uint16_t internet_checksum(const void* ptr, size_t count);
__END_DECLS

View file

@ -6,6 +6,7 @@
#include <LibCore/ConfigFile.h>
#include <errno.h>
#include <serenity.h>
#include <spawn.h>
#include <stdio.h>
#include <unistd.h>
@ -17,6 +18,8 @@ int main()
return 1;
}
auto keyboard_settings_config = Core::ConfigFile::get_for_app("KeyboardSettings");
if (unveil("/bin/keymap", "x") < 0) {
perror("unveil /bin/keymap");
return 1;
@ -41,4 +44,7 @@ int main()
perror("posix_spawn");
exit(1);
}
bool enable_num_lock = keyboard_settings_config->read_bool_entry("StartupEnable", "NumLock", true);
set_num_lock(enable_num_lock);
}