1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#include "Input/BsKeyboard.h"
4#include "Input/BsInput.h"
5#include "Private/Linux/BsLinuxPlatform.h"
6
7namespace bs
8{
9
10 /** Contains private data for the Linux Keyboard implementation. */
11 struct Keyboard::Pimpl
12 {
13 bool hasInputFocus;
14 };
15
16 Keyboard::Keyboard(const String& name, Input* owner)
17 : mName(name), mOwner(owner)
18 {
19 m = bs_new<Pimpl>();
20 m->hasInputFocus = true;
21 }
22
23 Keyboard::~Keyboard()
24 {
25 bs_delete(m);
26 }
27
28 void Keyboard::capture()
29 {
30 Lock lock(LinuxPlatform::eventLock);
31
32 if(m->hasInputFocus)
33 {
34 while (!LinuxPlatform::buttonEvents.empty())
35 {
36 LinuxButtonEvent& event = LinuxPlatform::buttonEvents.front();
37 if(event.pressed)
38 mOwner->_notifyButtonPressed(0, event.button, event.timestamp);
39 else
40 mOwner->_notifyButtonReleased(0, event.button, event.timestamp);
41 LinuxPlatform::buttonEvents.pop();
42 }
43 }
44 else
45 {
46 // Discard queued data
47 while (!LinuxPlatform::buttonEvents.empty())
48 LinuxPlatform::buttonEvents.pop();
49 }
50 }
51
52 void Keyboard::changeCaptureContext(UINT64 windowHandle)
53 {
54 m->hasInputFocus = windowHandle != (UINT64)-1;
55 }
56}
57
58