-
Notifications
You must be signed in to change notification settings - Fork 946
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move keyboard handling to separate classes
Encapsulate all the platform specific magic around keyboard in to specific classes, in order to keep the core code more readable.
- Loading branch information
1 parent
d4b64f4
commit 82bb4e2
Showing
14 changed files
with
1,609 additions
and
1,290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* Copyright 2011-2021 Pierre Ossman <[email protected]> for Cendio AB | ||
* | ||
* This is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this software; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | ||
* USA. | ||
*/ | ||
|
||
#ifndef __KEYBOARD_H__ | ||
#define __KEYBOARD_H__ | ||
|
||
#include <stdint.h> | ||
|
||
class KeyboardHandler | ||
{ | ||
public: | ||
virtual void handleKeyPress(int systemKeyCode, | ||
uint32_t keyCode, uint32_t keySym) = 0; | ||
virtual void handleKeyRelease(int systemKeyCode) = 0; | ||
}; | ||
|
||
class Keyboard | ||
{ | ||
public: | ||
Keyboard(KeyboardHandler* handler_) : handler(handler_) {}; | ||
virtual ~Keyboard() {}; | ||
|
||
virtual bool handleEvent(const void* event) = 0; | ||
|
||
virtual void reset() {}; | ||
|
||
virtual unsigned getLEDState() = 0; | ||
virtual void setLEDState(unsigned state) = 0; | ||
|
||
protected: | ||
KeyboardHandler* handler; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* Copyright 2011-2021 Pierre Ossman <[email protected]> for Cendio AB | ||
* | ||
* This is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this software; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | ||
* USA. | ||
*/ | ||
|
||
#ifndef __KEYBOARDMACOS_H__ | ||
#define __KEYBOARDMACOS_H__ | ||
|
||
#include "Keyboard.h" | ||
|
||
#ifdef __OBJC__ | ||
@class NSEvent; | ||
@class NSString; | ||
#else | ||
class NSEvent; | ||
class NSString; | ||
#endif | ||
|
||
class KeyboardMacOS : public Keyboard | ||
{ | ||
public: | ||
KeyboardMacOS(KeyboardHandler* handler); | ||
virtual ~KeyboardMacOS(); | ||
|
||
bool handleEvent(const void* event) override; | ||
|
||
unsigned getLEDState() override; | ||
void setLEDState(unsigned state) override; | ||
|
||
// Special helper on macOS | ||
static bool isKeyboardSync(const void* event); | ||
|
||
protected: | ||
bool isKeyboardEvent(const NSEvent* nsevent); | ||
bool isKeyPress(const NSEvent* nsevent); | ||
uint32_t translateSystemKeyCode(int systemKeyCode); | ||
unsigned getSystemKeyCode(const NSEvent* nsevent); | ||
|
||
NSString* keyTranslate(unsigned keyCode, unsigned modifierFlags); | ||
uint32_t translateEventKeysym(const NSEvent* nsevent); | ||
|
||
int openHID(unsigned int* ioc); | ||
int getModifierLockState(int modifier, bool* on); | ||
int setModifierLockState(int modifier, bool on); | ||
}; | ||
|
||
#endif |
Oops, something went wrong.