2018-10-16 11:01:38 +02:00
|
|
|
#pragma once
|
|
|
|
|
2018-10-22 12:58:29 +02:00
|
|
|
#include <AK/Types.h>
|
2018-10-23 10:12:50 +02:00
|
|
|
#include <AK/DoublyLinkedList.h>
|
|
|
|
#include <AK/CircularQueue.h>
|
|
|
|
#include <VirtualFileSystem/CharacterDevice.h>
|
2018-10-22 12:58:29 +02:00
|
|
|
#include "IRQHandler.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
|
|
|
|
2018-10-23 10:12:50 +02:00
|
|
|
class Keyboard 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:
|
2018-11-02 14:06:48 +01:00
|
|
|
enum Modifier {
|
|
|
|
Mod_Alt = 0x01,
|
|
|
|
Mod_Ctrl = 0x02,
|
|
|
|
Mod_Shift = 0x04,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Key {
|
|
|
|
byte character { 0 };
|
|
|
|
byte modifiers { 0 };
|
|
|
|
bool alt() { return modifiers & Mod_Alt; }
|
|
|
|
bool ctrl() { return modifiers & Mod_Ctrl; }
|
|
|
|
bool shift() { return modifiers & Mod_Shift; }
|
|
|
|
};
|
|
|
|
|
2018-10-30 13:59:29 +01:00
|
|
|
static Keyboard& the() PURE;
|
|
|
|
|
2018-10-22 12:58:29 +02:00
|
|
|
virtual ~Keyboard() override;
|
|
|
|
Keyboard();
|
|
|
|
|
2018-10-30 15:33:37 +01:00
|
|
|
void setClient(KeyboardClient* client) { m_client = client; }
|
2018-10-30 13:59:29 +01:00
|
|
|
|
2018-10-22 12:58:29 +02:00
|
|
|
private:
|
2018-10-23 10:12:50 +02:00
|
|
|
// ^IRQHandler
|
2018-10-22 12:58:29 +02:00
|
|
|
virtual void handleIRQ() override;
|
2018-10-16 11:01:38 +02:00
|
|
|
|
2018-10-23 10:12:50 +02:00
|
|
|
// ^CharacterDevice
|
|
|
|
virtual ssize_t read(byte* buffer, size_t) override;
|
|
|
|
virtual ssize_t write(const byte* buffer, size_t) override;
|
2018-10-25 13:07:59 +02:00
|
|
|
virtual bool hasDataAvailableForRead() const override;
|
2018-10-23 10:12:50 +02:00
|
|
|
|
2018-10-30 15:33:37 +01:00
|
|
|
void emit(byte);
|
|
|
|
|
2018-10-30 13:59:29 +01:00
|
|
|
KeyboardClient* m_client { nullptr };
|
2018-11-02 14:06:48 +01:00
|
|
|
CircularQueue<Key, 16> m_queue;
|
2018-10-22 12:58:29 +02:00
|
|
|
byte m_modifiers { 0 };
|
|
|
|
};
|
2018-10-16 11:01:38 +02:00
|
|
|
|
2018-11-02 14:06:48 +01:00
|
|
|
class KeyboardClient {
|
|
|
|
public:
|
|
|
|
virtual ~KeyboardClient();
|
|
|
|
virtual void onKeyPress(Keyboard::Key) = 0;
|
|
|
|
};
|