2018-10-16 11:01:38 +02:00
|
|
|
#pragma once
|
|
|
|
|
2018-10-22 12:58:29 +02:00
|
|
|
#include "IRQHandler.h"
|
2019-01-26 06:39:13 +01:00
|
|
|
#include "KeyCode.h"
|
2019-05-28 11:53:16 +02:00
|
|
|
#include <AK/CircularQueue.h>
|
|
|
|
#include <AK/DoublyLinkedList.h>
|
|
|
|
#include <AK/Types.h>
|
|
|
|
#include <Kernel/Devices/CharacterDevice.h>
|
2018-10-16 11:01:38 +02:00
|
|
|
|
2018-11-02 14:06:48 +01:00
|
|
|
class KeyboardClient;
|
2018-10-30 13:59:29 +01:00
|
|
|
|
2019-05-28 11:53:16 +02:00
|
|
|
class KeyboardDevice final : public IRQHandler
|
|
|
|
, public CharacterDevice {
|
2018-10-31 23:19:15 +01:00
|
|
|
AK_MAKE_ETERNAL
|
2018-10-22 12:58:29 +02:00
|
|
|
public:
|
2019-02-17 00:13:47 +01:00
|
|
|
using Event = KeyEvent;
|
2018-11-02 14:06:48 +01:00
|
|
|
|
2019-07-16 13:44:41 +02:00
|
|
|
static KeyboardDevice& the();
|
2018-10-30 13:59:29 +01:00
|
|
|
|
2019-02-17 08:39:09 +01:00
|
|
|
virtual ~KeyboardDevice() override;
|
|
|
|
KeyboardDevice();
|
2018-10-22 12:58:29 +02:00
|
|
|
|
2018-12-03 00:39:25 +01:00
|
|
|
void set_client(KeyboardClient* client) { m_client = client; }
|
2018-10-30 13:59:29 +01:00
|
|
|
|
2018-10-23 10:12:50 +02:00
|
|
|
// ^CharacterDevice
|
2019-07-03 21:17:35 +02:00
|
|
|
virtual ssize_t read(FileDescription&, u8* buffer, ssize_t) override;
|
2019-06-07 09:36:51 +02:00
|
|
|
virtual bool can_read(FileDescription&) const override;
|
2019-07-03 21:17:35 +02:00
|
|
|
virtual ssize_t write(FileDescription&, const u8* buffer, ssize_t) override;
|
2019-06-07 09:36:51 +02:00
|
|
|
virtual bool can_write(FileDescription&) const override { return true; }
|
2018-10-23 10:12:50 +02:00
|
|
|
|
2019-01-16 17:20:58 +01:00
|
|
|
private:
|
|
|
|
// ^IRQHandler
|
|
|
|
virtual void handle_irq() override;
|
|
|
|
|
2019-01-21 02:33:01 +01:00
|
|
|
// ^CharacterDevice
|
2019-02-17 08:39:09 +01:00
|
|
|
virtual const char* class_name() const override { return "KeyboardDevice"; }
|
2019-01-21 02:33:01 +01:00
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
void key_state_changed(u8 raw, bool pressed);
|
|
|
|
void update_modifier(u8 modifier, bool state)
|
2019-01-21 07:05:31 +01:00
|
|
|
{
|
|
|
|
if (state)
|
|
|
|
m_modifiers |= modifier;
|
|
|
|
else
|
|
|
|
m_modifiers &= ~modifier;
|
|
|
|
}
|
2018-10-30 15:33:37 +01:00
|
|
|
|
2018-10-30 13:59:29 +01:00
|
|
|
KeyboardClient* m_client { nullptr };
|
2019-01-21 07:05:31 +01:00
|
|
|
CircularQueue<Event, 16> m_queue;
|
2019-07-03 21:17:35 +02:00
|
|
|
u8 m_modifiers { 0 };
|
2018-10-22 12:58:29 +02:00
|
|
|
};
|
2018-10-16 11:01:38 +02:00
|
|
|
|
2018-11-02 14:06:48 +01:00
|
|
|
class KeyboardClient {
|
|
|
|
public:
|
|
|
|
virtual ~KeyboardClient();
|
2019-02-17 08:39:09 +01:00
|
|
|
virtual void on_key_pressed(KeyboardDevice::Event) = 0;
|
2018-11-02 14:06:48 +01:00
|
|
|
};
|