Almost got rid of singleton (move a lot of stuff into free functions)
This commit is contained in:
parent
e845e50142
commit
02b9dafc6f
|
@ -1606,9 +1606,6 @@ void WindowImplX11::initialize()
|
||||||
// Create the hidden cursor
|
// Create the hidden cursor
|
||||||
createHiddenCursor();
|
createHiddenCursor();
|
||||||
|
|
||||||
// init X11 keycode <-> SFML scancode mapping
|
|
||||||
X11InputManager::getInstance().initialize();
|
|
||||||
|
|
||||||
// Flush the commands queue
|
// Flush the commands queue
|
||||||
XFlush(m_display);
|
XFlush(m_display);
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,11 @@ namespace priv
|
||||||
{
|
{
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
KeyCode scancodeToKeycode[sf::Keyboard::ScanCodeCount]; ///< Mapping of SFML scancode to X11 KeyCode
|
||||||
|
sf::Keyboard::Scancode keycodeToScancode[256]; ///< Mapping of X11 KeyCode to SFML scancode
|
||||||
|
bool is_init = false;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sf::Keyboard::Scancode translateKeyCode(Display* display, KeyCode keycode)
|
sf::Keyboard::Scancode translateKeyCode(Display* display, KeyCode keycode)
|
||||||
{
|
{
|
||||||
|
@ -219,36 +224,18 @@ sf::Keyboard::Scancode translateKeyCode(Display* display, KeyCode keycode)
|
||||||
return sf::Keyboard::ScanUnknown;
|
return sf::Keyboard::ScanUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void init()
|
||||||
} // anonymous namespace
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
X11InputManager::X11InputManager()
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < sf::Keyboard::ScanCodeCount; ++i)
|
for (int i = 0; i < sf::Keyboard::ScanCodeCount; ++i)
|
||||||
{
|
{
|
||||||
m_scancodeToKeycode[i] = 0;
|
scancodeToKeycode[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 256; ++i)
|
for (int i = 0; i < 256; ++i)
|
||||||
{
|
{
|
||||||
m_keycodeToScancode[i] = sf::Keyboard::ScanUnknown;
|
keycodeToScancode[i] = sf::Keyboard::ScanUnknown;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
X11InputManager& X11InputManager::getInstance()
|
|
||||||
{
|
|
||||||
static X11InputManager instance;
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void X11InputManager::initialize()
|
|
||||||
{
|
|
||||||
Display* display = OpenDisplay();
|
Display* display = OpenDisplay();
|
||||||
|
|
||||||
// Find the X11 key code -> SFML key code mapping
|
// Find the X11 key code -> SFML key code mapping
|
||||||
|
@ -316,8 +303,8 @@ void X11InputManager::initialize()
|
||||||
|
|
||||||
if ((keycode >= 0) && (keycode < 256))
|
if ((keycode >= 0) && (keycode < 256))
|
||||||
{
|
{
|
||||||
m_scancodeToKeycode[sc] = keycode;
|
scancodeToKeycode[sc] = keycode;
|
||||||
m_keycodeToScancode[keycode] = sc;
|
keycodeToScancode[keycode] = sc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,20 +312,54 @@ void X11InputManager::initialize()
|
||||||
XkbFreeKeyboard(desc, 0, True);
|
XkbFreeKeyboard(desc, 0, True);
|
||||||
|
|
||||||
// Translate un-translated keycodes using traditional X11 KeySym lookups
|
// Translate un-translated keycodes using traditional X11 KeySym lookups
|
||||||
for (int keycode = 0; keycode < 256; ++keycode)
|
for (int keycode = 0; keycode < 256; ++keycode)
|
||||||
{
|
{
|
||||||
if (m_keycodeToScancode[keycode] == sf::Keyboard::ScanUnknown)
|
if (keycodeToScancode[keycode] == sf::Keyboard::ScanUnknown)
|
||||||
{
|
{
|
||||||
sf::Keyboard::Scancode sc = translateKeyCode(display, keycode);
|
sf::Keyboard::Scancode sc = translateKeyCode(display, keycode);
|
||||||
m_scancodeToKeycode[sc] = keycode;
|
scancodeToKeycode[sc] = keycode;
|
||||||
m_keycodeToScancode[keycode] = sc;
|
keycodeToScancode[keycode] = sc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseDisplay(display);
|
CloseDisplay(display);
|
||||||
|
|
||||||
|
is_init = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
KeyCode SFScancodeToKeyCode(sf::Keyboard::Scancode code)
|
||||||
|
{
|
||||||
|
if (!is_init)
|
||||||
|
init();
|
||||||
|
|
||||||
|
return scancodeToKeycode[code];
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
sf::Keyboard::Scancode keyCodeToSFScancode(KeyCode code)
|
||||||
|
{
|
||||||
|
if (!is_init)
|
||||||
|
init();
|
||||||
|
|
||||||
|
return keycodeToScancode[code];
|
||||||
|
}
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
X11InputManager::X11InputManager()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
X11InputManager& X11InputManager::getInstance()
|
||||||
|
{
|
||||||
|
static X11InputManager instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
@ -545,20 +566,6 @@ KeyCode X11InputManager::SFKeyToKeyCode(sf::Keyboard::Key key) const
|
||||||
return keycode;
|
return keycode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
KeyCode X11InputManager::SFScancodeToKeyCode(sf::Keyboard::Scancode code) const
|
|
||||||
{
|
|
||||||
return m_scancodeToKeycode[code];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
sf::Keyboard::Scancode X11InputManager::keyCodeToSFScancode(KeyCode code) const
|
|
||||||
{
|
|
||||||
return m_keycodeToScancode[code];
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
KeySym X11InputManager::SFScancodeToKeySym(sf::Keyboard::Scancode code) const
|
KeySym X11InputManager::SFScancodeToKeySym(sf::Keyboard::Scancode code) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -67,15 +67,6 @@ private:
|
||||||
X11InputManager();
|
X11InputManager();
|
||||||
public:
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Initialize the keyboard
|
|
||||||
///
|
|
||||||
/// Builds a mapping between sf::Keyboard::Scancode and
|
|
||||||
/// X11 keycodes
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
void initialize();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \copydoc sf::Keyboard::isKeyPressed(Key)
|
/// \copydoc sf::Keyboard::isKeyPressed(Key)
|
||||||
///
|
///
|
||||||
|
@ -138,26 +129,6 @@ private:
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
KeyCode SFKeyToKeyCode(sf::Keyboard::Key key) const;
|
KeyCode SFKeyToKeyCode(sf::Keyboard::Key key) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Converts sf::Keyboard::Scancode to X11 keycode
|
|
||||||
///
|
|
||||||
/// \param code A scancode to be converted
|
|
||||||
///
|
|
||||||
/// \return A corresponding X11 Keycode
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
KeyCode SFScancodeToKeyCode(sf::Keyboard::Scancode code) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \brief Convert X11 Keycode to sf::Keyboard::Scancode
|
|
||||||
///
|
|
||||||
/// \param code X11 keycode
|
|
||||||
///
|
|
||||||
/// \return The corresponding sf::Keyboard::Scancode
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
sf::Keyboard::Scancode keyCodeToSFScancode(KeyCode code) const;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Convert sf::Keyboard::Scancode to KeySym
|
/// \brief Convert sf::Keyboard::Scancode to KeySym
|
||||||
///
|
///
|
||||||
|
@ -167,12 +138,6 @@ private:
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
KeySym SFScancodeToKeySym(sf::Keyboard::Scancode code) const;
|
KeySym SFScancodeToKeySym(sf::Keyboard::Scancode code) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Member data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
KeyCode m_scancodeToKeycode[sf::Keyboard::ScanCodeCount]; ///< Mapping of SFML scancode to X11 KeyCode
|
|
||||||
sf::Keyboard::Scancode m_keycodeToScancode[256]; ///< Mapping of X11 KeyCode to SFML scancode
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace priv
|
} // namespace priv
|
||||||
|
|
Loading…
Reference in a new issue