mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 17:40:27 +00:00
Hook up the Keyboard device to the AbstractScreen.
Basic text editing in a TextBox works. How very cool :^)
This commit is contained in:
parent
a3c39ea9d6
commit
b95aa18315
Notes:
sideshowbarker
2024-07-19 16:04:57 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/b95aa183152
4 changed files with 63 additions and 1 deletions
|
@ -108,7 +108,9 @@ void VirtualConsole::set_active(bool b)
|
|||
set_vga_start_row(0);
|
||||
flush_vga_cursor();
|
||||
|
||||
#if 0
|
||||
Keyboard::the().set_client(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool is_valid_parameter_character(byte ch)
|
||||
|
|
|
@ -29,6 +29,7 @@ AbstractScreen::AbstractScreen(unsigned width, unsigned height)
|
|||
m_cursor_location = rect().center();
|
||||
|
||||
PS2MouseDevice::the().set_client(this);
|
||||
Keyboard::the().set_client(this);
|
||||
}
|
||||
|
||||
AbstractScreen::~AbstractScreen()
|
||||
|
@ -62,3 +63,57 @@ void AbstractScreen::did_receive_mouse_data(int dx, int dy, bool left_button, bo
|
|||
if (m_cursor_location != prev_location)
|
||||
WindowManager::the().redraw_cursor();
|
||||
}
|
||||
|
||||
void AbstractScreen::on_key_pressed(Keyboard::Key key)
|
||||
{
|
||||
auto event = make<KeyEvent>(Event::KeyDown, 0);
|
||||
int key_code = 0;
|
||||
|
||||
switch (key.character) {
|
||||
case 8: key_code = KeyboardKey::Backspace; break;
|
||||
case 10: key_code = KeyboardKey::Return; break;
|
||||
}
|
||||
event->m_key = key_code;
|
||||
|
||||
if (key.character) {
|
||||
char buf[] = { 0, 0 };
|
||||
char& ch = buf[0];
|
||||
ch = key.character;
|
||||
if (key.shift()) {
|
||||
if (ch >= 'a' && ch <= 'z') {
|
||||
ch &= ~0x20;
|
||||
} else {
|
||||
switch (ch) {
|
||||
case '1': ch = '!'; break;
|
||||
case '2': ch = '@'; break;
|
||||
case '3': ch = '#'; break;
|
||||
case '4': ch = '$'; break;
|
||||
case '5': ch = '%'; break;
|
||||
case '6': ch = '^'; break;
|
||||
case '7': ch = '&'; break;
|
||||
case '8': ch = '*'; break;
|
||||
case '9': ch = '('; break;
|
||||
case '0': ch = ')'; break;
|
||||
case '-': ch = '_'; break;
|
||||
case '=': ch = '+'; break;
|
||||
case '`': ch = '~'; break;
|
||||
case ',': ch = '<'; break;
|
||||
case '.': ch = '>'; break;
|
||||
case '/': ch = '?'; break;
|
||||
case '[': ch = '{'; break;
|
||||
case ']': ch = '}'; break;
|
||||
case '\\': ch = '|'; break;
|
||||
case '\'': ch = '"'; break;
|
||||
case ';': ch = ':'; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
event->m_text = buf;
|
||||
}
|
||||
|
||||
event->m_shift = key.shift();
|
||||
event->m_ctrl = key.ctrl();
|
||||
event->m_alt = key.alt();
|
||||
|
||||
EventLoop::main().postEvent(&WindowManager::the(), move(event));
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@
|
|||
#include "Object.h"
|
||||
#include "Rect.h"
|
||||
#include "Size.h"
|
||||
#include "Keyboard.h"
|
||||
#include "PS2MouseDevice.h"
|
||||
|
||||
class AbstractScreen : public Object, public MouseClient {
|
||||
class AbstractScreen : public Object, public KeyboardClient, public MouseClient {
|
||||
public:
|
||||
virtual ~AbstractScreen();
|
||||
|
||||
|
@ -30,6 +31,9 @@ private:
|
|||
// ^MouseClient
|
||||
virtual void did_receive_mouse_data(int dx, int dy, bool left_button, bool right_button) final;
|
||||
|
||||
// ^KeyboardClient
|
||||
virtual void on_key_pressed(Keyboard::Key) final;
|
||||
|
||||
int m_width { 0 };
|
||||
int m_height { 0 };
|
||||
|
||||
|
|
|
@ -136,6 +136,7 @@ public:
|
|||
|
||||
private:
|
||||
friend class EventLoop;
|
||||
friend class AbstractScreen;
|
||||
int m_key { 0 };
|
||||
bool m_ctrl { false };
|
||||
bool m_alt { false };
|
||||
|
|
Loading…
Reference in a new issue