mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
Kernel: Add keyboard ioctl to get num/caps lock state
This commit is contained in:
parent
864b50b5c2
commit
385e2ccb66
Notes:
sideshowbarker
2024-07-18 10:15:24 +09:00
Author: https://github.com/EdwinHoksberg Commit: https://github.com/SerenityOS/serenity/commit/385e2ccb66b Pull-request: https://github.com/SerenityOS/serenity/pull/8474
@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user