From 56457d922a43c87c9e722de5aa44ccee9c96c837 Mon Sep 17 00:00:00 2001 From: Elias Daler Date: Sat, 31 Mar 2018 02:58:01 +0300 Subject: [PATCH] X11InputManager -> KeyboardImpl --- src/SFML/Window/CMakeLists.txt | 4 +++ src/SFML/Window/Unix/InputImpl.cpp | 12 +++---- .../{X11InputManager.cpp => KeyboardImpl.cpp} | 33 ++++++++++--------- .../{X11InputManager.hpp => KeyboardImpl.hpp} | 8 ++--- src/SFML/Window/Unix/WindowImplX11.cpp | 9 ++--- 5 files changed, 36 insertions(+), 30 deletions(-) rename src/SFML/Window/Unix/{X11InputManager.cpp => KeyboardImpl.cpp} (96%) rename src/SFML/Window/Unix/{X11InputManager.hpp => KeyboardImpl.hpp} (96%) diff --git a/src/SFML/Window/CMakeLists.txt b/src/SFML/Window/CMakeLists.txt index bd9571b4..61442e6a 100644 --- a/src/SFML/Window/CMakeLists.txt +++ b/src/SFML/Window/CMakeLists.txt @@ -91,6 +91,10 @@ elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_OPENBSD) ${SRCROOT}/Unix/Display.hpp ${SRCROOT}/Unix/InputImpl.cpp ${SRCROOT}/Unix/InputImpl.hpp + ${SRCROOT}/Unix/KeyboardImpl.hpp + ${SRCROOT}/Unix/KeyboardImpl.cpp + ${SRCROOT}/Unix/KeySymToSFKeyMapping.hpp + ${SRCROOT}/Unix/KeySymToUnicodeMapping.hpp ${SRCROOT}/Unix/SensorImpl.cpp ${SRCROOT}/Unix/SensorImpl.hpp ${SRCROOT}/Unix/VideoModeImpl.cpp diff --git a/src/SFML/Window/Unix/InputImpl.cpp b/src/SFML/Window/Unix/InputImpl.cpp index 9c8a0d12..a5d84de8 100644 --- a/src/SFML/Window/Unix/InputImpl.cpp +++ b/src/SFML/Window/Unix/InputImpl.cpp @@ -28,7 +28,7 @@ #include // important to be included first (conflict with None) #include #include -#include +#include #include #include #include @@ -41,13 +41,13 @@ namespace priv //////////////////////////////////////////////////////////// bool InputImpl::isKeyPressed(Keyboard::Key key) { - return X11InputManager::isKeyPressed(key); + return KeyboardImpl::isKeyPressed(key); } //////////////////////////////////////////////////////////// bool InputImpl::isKeyPressed(Keyboard::Scancode code) { - return X11InputManager::isKeyPressed(code); + return KeyboardImpl::isKeyPressed(code); } // Open a connection with the X server @@ -56,7 +56,7 @@ bool InputImpl::isKeyPressed(Keyboard::Scancode code) //////////////////////////////////////////////////////////// Keyboard::Key InputImpl::localize(Keyboard::Scancode code) { - return X11InputManager::localize(code); + return KeyboardImpl::localize(code); } // Close the connection with the X server @@ -65,14 +65,14 @@ Keyboard::Key InputImpl::localize(Keyboard::Scancode code) //////////////////////////////////////////////////////////// Keyboard::Scancode InputImpl::unlocalize(Keyboard::Key key) { - return X11InputManager::unlocalize(key); + return KeyboardImpl::unlocalize(key); } //////////////////////////////////////////////////////////// String InputImpl::getDescription(Keyboard::Scancode code) { - return X11InputManager::getDescription(code); + return KeyboardImpl::getDescription(code); } diff --git a/src/SFML/Window/Unix/X11InputManager.cpp b/src/SFML/Window/Unix/KeyboardImpl.cpp similarity index 96% rename from src/SFML/Window/Unix/X11InputManager.cpp rename to src/SFML/Window/Unix/KeyboardImpl.cpp index 97ea2f62..d340c9d0 100644 --- a/src/SFML/Window/Unix/X11InputManager.cpp +++ b/src/SFML/Window/Unix/KeyboardImpl.cpp @@ -25,7 +25,7 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// -#include +#include #include #include #include @@ -44,7 +44,7 @@ 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; +bool isMappingInitialized = false; //////////////////////////////////////////////////////////// sf::Keyboard::Scancode translateKeyCode(Display* display, KeyCode keycode) @@ -324,13 +324,13 @@ void initMapping() CloseDisplay(display); - is_init = true; + isMappingInitialized = true; } //////////////////////////////////////////////////////////// KeyCode SFScancodeToKeyCode(sf::Keyboard::Scancode code) { - if (!is_init) + if (!isMappingInitialized) initMapping(); return scancodeToKeycode[code]; @@ -339,7 +339,7 @@ KeyCode SFScancodeToKeyCode(sf::Keyboard::Scancode code) //////////////////////////////////////////////////////////// sf::Keyboard::Scancode keyCodeToSFScancode(KeyCode code) { - if (!is_init) + if (!isMappingInitialized) initMapping(); return keycodeToScancode[code]; @@ -383,7 +383,7 @@ bool isKeyPressedImpl(Display* display, KeyCode keycode) } // anonymous namespace //////////////////////////////////////////////////////////// -bool X11InputManager::isKeyPressed(sf::Keyboard::Key key) +bool KeyboardImpl::isKeyPressed(sf::Keyboard::Key key) { Display* display = OpenDisplay(); bool pressed = isKeyPressedImpl(display, SFKeyToKeyCode(key)); @@ -393,7 +393,7 @@ bool X11InputManager::isKeyPressed(sf::Keyboard::Key key) //////////////////////////////////////////////////////////// -bool X11InputManager::isKeyPressed(sf::Keyboard::Scancode code) +bool KeyboardImpl::isKeyPressed(sf::Keyboard::Scancode code) { Display* display = OpenDisplay(); bool pressed = isKeyPressedImpl(display, SFScancodeToKeyCode(code)); @@ -403,7 +403,7 @@ bool X11InputManager::isKeyPressed(sf::Keyboard::Scancode code) //////////////////////////////////////////////////////////// -sf::Keyboard::Scancode X11InputManager::unlocalize(sf::Keyboard::Key key) +sf::Keyboard::Scancode KeyboardImpl::unlocalize(sf::Keyboard::Key key) { KeyCode keycode = SFKeyToKeyCode(key); return keyCodeToSFScancode(keycode); @@ -411,23 +411,23 @@ sf::Keyboard::Scancode X11InputManager::unlocalize(sf::Keyboard::Key key) //////////////////////////////////////////////////////////// -sf::Keyboard::Key X11InputManager::localize(sf::Keyboard::Scancode code) +sf::Keyboard::Key KeyboardImpl::localize(sf::Keyboard::Scancode code) { KeySym keysym = SFScancodeToKeySym(code); return keySymToSFKey(keysym); } //////////////////////////////////////////////////////////// -sf::String X11InputManager::getDescription(Keyboard::Scancode code) +sf::String KeyboardImpl::getDescription(Keyboard::Scancode code) { bool checkInput = true; // these scancodes actually correspond to keys with input // but we want to return their description, not their behaviour - if (code == sf::Keyboard::ScanEnter || - code == sf::Keyboard::ScanReturn || - code == sf::Keyboard::ScanTab || - code == sf::Keyboard::ScanDelete || + if (code == sf::Keyboard::ScanEnter || + code == sf::Keyboard::ScanReturn || + code == sf::Keyboard::ScanTab || + code == sf::Keyboard::ScanDelete || code == sf::Keyboard::ScanBackspace || code == sf::Keyboard::ScanSpace) { checkInput = false; @@ -437,6 +437,7 @@ sf::String X11InputManager::getDescription(Keyboard::Scancode code) { KeySym keysym = SFScancodeToKeySym(code); sf::Uint32 unicode = keysymToUnicode(keysym); + if (unicode != 0) return sf::String(unicode); } @@ -534,7 +535,7 @@ sf::String X11InputManager::getDescription(Keyboard::Scancode code) //////////////////////////////////////////////////////////// -sf::Keyboard::Key X11InputManager::getKeyFromEvent(XKeyEvent& event) +sf::Keyboard::Key KeyboardImpl::getKeyFromEvent(XKeyEvent& event) { sf::Keyboard::Key key = Keyboard::Unknown; @@ -553,7 +554,7 @@ sf::Keyboard::Key X11InputManager::getKeyFromEvent(XKeyEvent& event) //////////////////////////////////////////////////////////// -sf::Keyboard::Scancode X11InputManager::getScancodeFromEvent(XKeyEvent& event) +sf::Keyboard::Scancode KeyboardImpl::getScancodeFromEvent(XKeyEvent& event) { return keyCodeToSFScancode(event.keycode); } diff --git a/src/SFML/Window/Unix/X11InputManager.hpp b/src/SFML/Window/Unix/KeyboardImpl.hpp similarity index 96% rename from src/SFML/Window/Unix/X11InputManager.hpp rename to src/SFML/Window/Unix/KeyboardImpl.hpp index aac32e89..6e43c296 100644 --- a/src/SFML/Window/Unix/X11InputManager.hpp +++ b/src/SFML/Window/Unix/KeyboardImpl.hpp @@ -22,8 +22,8 @@ // //////////////////////////////////////////////////////////// -#ifndef SFML_X11INPUTMANAGER_HPP -#define SFML_X11INPUTMANAGER_HPP +#ifndef SFML_KEYBOARD_IMPL_HPP +#define SFML_KEYBOARD_IMPL_HPP //////////////////////////////////////////////////////////// // Headers @@ -44,7 +44,7 @@ namespace priv { /// Its purpose is to help sf::priv::InputImpl class. /// //////////////////////////////////////////////////////////// -class X11InputManager +class KeyboardImpl { public: @@ -103,4 +103,4 @@ public: } // namespace sf -#endif // SFML_X11INPUTMANAGER_HPP +#endif // SFML_KEYBOARD_IMPL_HPP diff --git a/src/SFML/Window/Unix/WindowImplX11.cpp b/src/SFML/Window/Unix/WindowImplX11.cpp index b698acd7..2adfa7d6 100644 --- a/src/SFML/Window/Unix/WindowImplX11.cpp +++ b/src/SFML/Window/Unix/WindowImplX11.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -1830,8 +1831,8 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) // TODO: if modifiers are wrong, use XGetModifierMapping to retrieve the actual modifiers mapping Event event; event.type = Event::KeyPressed; - event.key.code = X11InputManager::getKeyFromEvent(windowEvent.xkey); - event.key.scancode = X11InputManager::getScancodeFromEvent(windowEvent.xkey); + event.key.code = KeyboardImpl::getKeyFromEvent(windowEvent.xkey); + event.key.scancode = KeyboardImpl::getScancodeFromEvent(windowEvent.xkey); event.key.alt = windowEvent.xkey.state & Mod1Mask; event.key.control = windowEvent.xkey.state & ControlMask; event.key.shift = windowEvent.xkey.state & ShiftMask; @@ -1895,8 +1896,8 @@ bool WindowImplX11::processEvent(XEvent& windowEvent) // Fill the event parameters Event event; event.type = Event::KeyReleased; - event.key.code = X11InputManager::getKeyFromEvent(windowEvent.xkey); - event.key.scancode = X11InputManager::getScancodeFromEvent(windowEvent.xkey); + event.key.code = KeyboardImpl::getKeyFromEvent(windowEvent.xkey); + event.key.scancode = KeyboardImpl::getScancodeFromEvent(windowEvent.xkey); event.key.alt = windowEvent.xkey.state & Mod1Mask; event.key.control = windowEvent.xkey.state & ControlMask; event.key.shift = windowEvent.xkey.state & ShiftMask;