BsLinuxKeyboard.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Input/BsKeyboard.h"
  4. #include "Input/BsInput.h"
  5. #include "Linux/BsLinuxPlatform.h"
  6. namespace bs
  7. {
  8. /** Contains private data for the Linux Keyboard implementation. */
  9. struct Keyboard::Pimpl
  10. {
  11. bool hasInputFocus;
  12. };
  13. Keyboard::Keyboard(const String& name, Input* owner)
  14. : mName(name), mOwner(owner)
  15. {
  16. m = bs_new<Pimpl>();
  17. m->hasInputFocus = true;
  18. }
  19. Keyboard::~Keyboard()
  20. {
  21. bs_delete(m);
  22. }
  23. void Keyboard::capture()
  24. {
  25. Lock lock(LinuxPlatform::eventLock);
  26. if(m->hasInputFocus)
  27. {
  28. while (!LinuxPlatform::buttonEvents.empty())
  29. {
  30. LinuxButtonEvent& event = LinuxPlatform::buttonEvents.front();
  31. if(event.pressed)
  32. mOwner->_notifyButtonPressed(0, event.button, event.timestamp);
  33. else
  34. mOwner->_notifyButtonReleased(0, event.button, event.timestamp);
  35. LinuxPlatform::buttonEvents.pop();
  36. }
  37. }
  38. else
  39. {
  40. // Discard queued data
  41. while (!LinuxPlatform::buttonEvents.empty())
  42. LinuxPlatform::buttonEvents.pop();
  43. }
  44. }
  45. void Keyboard::changeCaptureContext(UINT64 windowHandle)
  46. {
  47. m->hasInputFocus = windowHandle != (UINT64)-1;
  48. }
  49. }