Kernel: Add keyboard ioctl to get num/caps lock state

This commit is contained in:
Edwin Hoksberg 2021-07-05 21:14:38 +02:00 committed by Gunnar Beutner
parent 864b50b5c2
commit 385e2ccb66
Notes: sideshowbarker 2024-07-18 10:15:24 +09:00
3 changed files with 47 additions and 0 deletions

View File

@ -1,6 +1,7 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
* Copyright (c) 2021, Edwin Hoksberg <mail@edwinhoksberg.nl>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -15,6 +16,7 @@
#include <Kernel/IO.h>
#include <Kernel/Sections.h>
#include <Kernel/TTY/VirtualConsole.h>
#include <LibC/sys/ioctl_numbers.h>
namespace Kernel {
@ -314,4 +316,36 @@ KResultOr<size_t> KeyboardDevice::write(FileDescription&, u64, const UserOrKerne
return 0;
}
int KeyboardDevice::ioctl(FileDescription&, unsigned request, FlatPtr arg)
{
switch (request) {
case KEYBOARD_IOCTL_GET_NUM_LOCK: {
auto* output = (bool*)arg;
if (!copy_to_user(output, &m_num_lock_on))
return -EFAULT;
return 0;
}
case KEYBOARD_IOCTL_SET_NUM_LOCK: {
if (arg != 0 && arg != 1)
return -EINVAL;
m_num_lock_on = arg;
return 0;
}
case KEYBOARD_IOCTL_GET_CAPS_LOCK: {
auto* output = (bool*)arg;
if (!copy_to_user(output, &m_caps_lock_on))
return -EFAULT;
return 0;
}
case KEYBOARD_IOCTL_SET_CAPS_LOCK: {
if (arg != 0 && arg != 1)
return -EINVAL;
m_caps_lock_on = arg;
return 0;
}
default:
return -EINVAL;
};
}
}

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
* Copyright (c) 2021, Edwin Hoksberg <mail@edwinhoksberg.nl>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -35,6 +36,9 @@ public:
// ^Device
virtual mode_t required_mode() const override { return 0440; }
// ^File
virtual int ioctl(FileDescription&, unsigned request, FlatPtr arg) override;
virtual String device_name() const override { return String::formatted("keyboard{}", minor()); }
void update_modifier(u8 modifier, bool state)

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Edwin Hoksberg <mail@edwinhoksberg.nl>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -63,6 +64,10 @@ enum IOCtlNumber {
FB_IOCTL_GET_BUFFER_OFFSET,
FB_IOCTL_SET_BUFFER,
FB_IOCTL_FLUSH_BUFFERS,
KEYBOARD_IOCTL_GET_NUM_LOCK,
KEYBOARD_IOCTL_SET_NUM_LOCK,
KEYBOARD_IOCTL_GET_CAPS_LOCK,
KEYBOARD_IOCTL_SET_CAPS_LOCK,
SIOCSIFADDR,
SIOCGIFADDR,
SIOCGIFHWADDR,
@ -97,6 +102,10 @@ enum IOCtlNumber {
#define FB_IOCTL_GET_BUFFER_OFFSET FB_IOCTL_GET_BUFFER_OFFSET
#define FB_IOCTL_SET_BUFFER FB_IOCTL_SET_BUFFER
#define FB_IOCTL_FLUSH_BUFFERS FB_IOCTL_FLUSH_BUFFERS
#define KEYBOARD_IOCTL_GET_NUM_LOCK KEYBOARD_IOCTL_GET_NUM_LOCK
#define KEYBOARD_IOCTL_SET_NUM_LOCK KEYBOARD_IOCTL_SET_NUM_LOCK
#define KEYBOARD_IOCTL_GET_CAPS_LOCK KEYBOARD_IOCTL_GET_CAPS_LOCK
#define KEYBOARD_IOCTL_SET_CAPS_LOCK KEYBOARD_IOCTL_SET_CAPS_LOCK
#define SIOCSIFADDR SIOCSIFADDR
#define SIOCGIFADDR SIOCGIFADDR
#define SIOCGIFHWADDR SIOCGIFHWADDR