driver/input, kernel: use a Condition for input
This commit is contained in:
parent
3aafc2a032
commit
6434fe4b63
@ -1,11 +1,12 @@
|
||||
|
||||
#include "input.h"
|
||||
#include "consts.h"
|
||||
#include "source.h"
|
||||
#include "internal.h"
|
||||
#include "../../util/minmax.h"
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
smp_Condition *input_Condition;
|
||||
int __input_CursorX, __input_CursorY;
|
||||
int __input_DesktopWidth, __input_DesktopHeight;
|
||||
uint64_t __input_KeyMask[input_Key_Count / 64 + 1], __input_MouseMask[input_MouseButton_Count / 64 + 1];
|
||||
@ -30,19 +31,38 @@ void input_DesktopSize(int *x, int *y) {
|
||||
*y = __input_DesktopHeight;
|
||||
}
|
||||
|
||||
void input_source_PressKey(input_Key key) { __input_KeyMask[key / 64] |= (1ull << key % 64); }
|
||||
void input_source_ReleaseKey(input_Key key) { __input_KeyMask[key / 64] &= ~(1ull << key % 64); }
|
||||
static inline void notify(void *data) {
|
||||
if (input_Condition)
|
||||
smp_Condition_NotifyAll(input_Condition, data);
|
||||
}
|
||||
|
||||
void input_source_PressMouse(input_MouseButton key) { __input_MouseMask[key / 64] |= (1ull << key & 64); }
|
||||
void input_source_ReleaseMouse(input_MouseButton key) { __input_MouseMask[key / 64] &= ~(1ull << key & 64); }
|
||||
void input_source_PressKey(input_Key key) {
|
||||
__input_KeyMask[key / 64] |= (1ull << key % 64);
|
||||
notify(NULL);
|
||||
}
|
||||
void input_source_ReleaseKey(input_Key key) {
|
||||
__input_KeyMask[key / 64] &= ~(1ull << key % 64);
|
||||
notify(NULL);
|
||||
}
|
||||
|
||||
void input_source_PressMouse(input_MouseButton key) {
|
||||
__input_MouseMask[key / 64] |= (1ull << key & 64);
|
||||
notify(NULL);
|
||||
}
|
||||
void input_source_ReleaseMouse(input_MouseButton key) {
|
||||
__input_MouseMask[key / 64] &= ~(1ull << key & 64);
|
||||
notify(NULL);
|
||||
}
|
||||
|
||||
void input_source_MoveMouse(int x, int y) {
|
||||
__input_CursorX = intminmax(__input_CursorX + x, 0, __input_DesktopWidth);
|
||||
__input_CursorY = intminmax(__input_CursorY + y, 0, __input_DesktopHeight);
|
||||
notify(NULL);
|
||||
}
|
||||
void input_source_PositionMouse(int x, int y) {
|
||||
__input_CursorX = intminmax(x, 0, __input_DesktopWidth);
|
||||
__input_CursorY = intminmax(y, 0, __input_DesktopHeight);
|
||||
notify(NULL);
|
||||
}
|
||||
|
||||
void input_source_SetDesktopSize(int x, int y) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../smp/condiction.h"
|
||||
#include <stdbool.h>
|
||||
#include "consts.h"
|
||||
|
||||
@ -8,6 +9,9 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
// If input_Condition is not NULL, it is notified on new input events.
|
||||
extern smp_Condition *input_Condition;
|
||||
|
||||
// input_KeyPressed tells if a given key is present and pressed.
|
||||
bool input_KeyPressed(input_Key key);
|
||||
|
||||
|
@ -11,7 +11,9 @@
|
||||
#include "../interrupt/syscall.h"
|
||||
#include "../driver/irq/pic/pic.h"
|
||||
#include "../driver/irq/pic/ps2/ps2.h"
|
||||
#include "../driver/input/input.h"
|
||||
#include "../smp/kthread.h"
|
||||
#include "../smp/condiction.h"
|
||||
|
||||
#include "../execformat/pe/reloc.h"
|
||||
void execformat_pe_ReadSystemHeader(execformat_pe_PortableExecutable *pe);
|
||||
@ -88,10 +90,10 @@ SYSV_ABI void kMain() {
|
||||
tid = smp_thread_Start(kThreader, &args, SMP_NICENESS_DEFAULT);
|
||||
io_Printf("New thread, id=%d\n", tid);
|
||||
|
||||
for (;;) {
|
||||
//asm volatile("hlt");
|
||||
input_Condition = smp_Condition_Create();
|
||||
|
||||
//io_WriteConsoleASCII("kMain: Interrupt hit\n");
|
||||
for (;;) {
|
||||
smp_Condition_Wait(input_Condition);
|
||||
graphics_SwapBuffer();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user