20 #include "pedigree/kernel/machine/InputManager.h" 21 #include "pedigree/kernel/LockGuard.h" 22 #include "pedigree/kernel/Log.h" 23 #include "pedigree/kernel/compiler.h" 24 #include "pedigree/kernel/process/Event.h" 25 #include "pedigree/kernel/process/Scheduler.h" 26 #include "pedigree/kernel/process/Thread.h" 27 #include "pedigree/kernel/process/eventNumbers.h" 28 #include "pedigree/kernel/processor/Processor.h" 29 #include "pedigree/kernel/processor/ProcessorInformation.h" 30 #include "pedigree/kernel/utilities/Iterator.h" 31 #include "pedigree/kernel/utilities/utility.h" 34 #define MOUSE_REDUCE_FACTOR 1 41 uintptr_t handlerAddress);
44 virtual size_t serialize(uint8_t *pBuffer);
46 static bool unserialize(uint8_t *pBuffer,
InputEvent &event);
50 InputManager::CallbackType getType();
57 void getButtonStates(
bool states[64],
size_t maxDesired = 64);
68 : m_InputQueue(), m_QueueLock(), m_Callbacks()
71 m_InputQueueSize(0), m_pThread(0)
90 reinterpret_cast<void *>(
this));
92 WARNING(
"InputManager: No thread support, no worker thread will be active");
114 note->data.key.key = key;
123 note->data.rawkey.scancode = scancode;
124 note->data.rawkey.keyUp = bKeyUp;
132 note->type = MachineKey;
133 note->data.machinekey.scancode = scancode;
134 note->data.machinekey.keyUp = bKeyUp;
140 ssize_t relX, ssize_t relY, ssize_t relZ, uint32_t buttonBitmap)
143 relX /= MOUSE_REDUCE_FACTOR;
144 relY /= MOUSE_REDUCE_FACTOR;
145 relZ /= MOUSE_REDUCE_FACTOR;
149 note->data.pointy.relx = relX;
150 note->data.pointy.rely = relY;
151 note->data.pointy.relz = relZ;
152 for (
size_t i = 0; i < 64; i++)
153 note->data.pointy.buttons[i] = buttonBitmap & (1 << i);
159 ssize_t relX, ssize_t relY, ssize_t relZ, uint32_t buttonBitmap)
162 note->type = Joystick;
163 note->data.pointy.relx = relX;
164 note->data.pointy.rely = relY;
165 note->data.pointy.relz = relZ;
166 for (
size_t i = 0; i < 64; i++)
167 note->data.pointy.buttons[i] = buttonBitmap & (1 << i);
177 WARNING(
"InputManager dropping input - no callbacks to send to!");
185 if (note->type == Mouse)
190 if ((*it)->type == Mouse)
192 (*it)->data.pointy.relx += note->data.pointy.relx;
193 (*it)->data.pointy.rely += note->data.pointy.rely;
194 (*it)->data.pointy.relz += note->data.pointy.relz;
196 for (
int i = 0; i < 64; i++)
198 if (note->data.pointy.buttons[i])
199 (*it)->data.pointy.buttons[i] =
true;
220 note->meta = (*it)->meta;
235 item->
func = callback;
256 (pThread == (*it)->pThread) &&
258 (callback == (*it)->func) && (meta == (*it)->meta))
279 if (pThread == (*it)->pThread)
317 WARNING(
"InputManager dropping input - no callbacks to send to!");
331 if ((*it)->filter & pNote->type)
333 Thread *pThread = (*it)->pThread;
339 pNote->meta = (*it)->meta;
345 pNote, (*it)->nParam,
346 reinterpret_cast<uintptr_t>(func));
347 NOTICE(
"InputManager: sending event " << pEvent <<
"!");
350 WARNING(
"InputManager - Thread::sendEvent failed, " 351 "skipping this callback");
366 InputEvent::InputEvent(
368 uintptr_t handlerAddress)
369 :
Event(handlerAddress,
true, 0), m_Notification(), m_nParam(param)
371 m_Notification = *pNote;
374 InputEvent::~InputEvent()
380 void *alignedBuffer = ASSUME_ALIGNMENT(pBuffer,
sizeof(uintptr_t));
381 uintptr_t *buf =
reinterpret_cast<uintptr_t *
>(alignedBuffer);
382 buf[0] = EventNumbers::InputEvent;
389 bool InputEvent::unserialize(uint8_t *pBuffer,
InputEvent &event)
391 void *alignedBuffer = ASSUME_ALIGNMENT(pBuffer,
sizeof(uintptr_t));
392 uintptr_t *buf =
reinterpret_cast<uintptr_t *
>(alignedBuffer);
393 if (*buf != EventNumbers::InputEvent)
397 &event.m_Notification, &buf[2],
404 return EventNumbers::InputEvent;
407 InputManager::CallbackType InputEvent::getType()
409 return m_Notification.type;
412 uint64_t InputEvent::getKey()
414 return m_Notification.data.key.key;
417 ssize_t InputEvent::getRelX()
419 return m_Notification.data.pointy.relx;
422 ssize_t InputEvent::getRelY()
424 return m_Notification.data.pointy.rely;
427 ssize_t InputEvent::getRelZ()
429 return m_Notification.data.pointy.relz;
432 void InputEvent::getButtonStates(
bool states[64],
size_t maxDesired)
434 for (
size_t i = 0; i < maxDesired; i++)
435 states[i] = m_Notification.data.pointy.buttons[i];
bool acquire(size_t n=1, size_t timeoutSecs=0, size_t timeoutUsecs=0)
bool acquire(bool recurse=false, bool safe=true)
static ProcessorInformation & information()
bool sendEvent(Event *pEvent)
::Iterator< T, node_t > Iterator
static Scheduler & instance()