summaryrefslogtreecommitdiff
path: root/Kernel/Keyboard.h
blob: 3b8e75c7472fc20efd9eeecff60b4d4efadfbd3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#pragma once

#include <AK/Types.h>
#include <AK/DoublyLinkedList.h>
#include <AK/CircularQueue.h>
#include <VirtualFileSystem/CharacterDevice.h>
#include "IRQHandler.h"

class KeyboardClient {
public:
    virtual ~KeyboardClient();
    virtual void onKeyPress(byte) = 0;
};

class Keyboard final : public IRQHandler, public CharacterDevice {
public:
    static Keyboard& the() PURE;

    virtual ~Keyboard() override;
    Keyboard();

    void setClient(KeyboardClient* client) { m_client = client; }

private:
    // ^IRQHandler
    virtual void handleIRQ() override;

    // ^CharacterDevice
    virtual ssize_t read(byte* buffer, size_t) override;
    virtual ssize_t write(const byte* buffer, size_t) override;
    virtual bool hasDataAvailableForRead() const override;

    void emit(byte);

    KeyboardClient* m_client { nullptr };
    CircularQueue<byte, 16> m_queue;
    byte m_modifiers { 0 };
};