X11InputManager -> KeyboardImpl

This commit is contained in:
Elias Daler 2018-03-31 02:58:01 +03:00 committed by Lukas Dürrenberger
parent 281d3d8528
commit 56457d922a
5 changed files with 36 additions and 30 deletions

View file

@ -91,6 +91,10 @@ elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_OPENBSD)
${SRCROOT}/Unix/Display.hpp ${SRCROOT}/Unix/Display.hpp
${SRCROOT}/Unix/InputImpl.cpp ${SRCROOT}/Unix/InputImpl.cpp
${SRCROOT}/Unix/InputImpl.hpp ${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.cpp
${SRCROOT}/Unix/SensorImpl.hpp ${SRCROOT}/Unix/SensorImpl.hpp
${SRCROOT}/Unix/VideoModeImpl.cpp ${SRCROOT}/Unix/VideoModeImpl.cpp

View file

@ -28,7 +28,7 @@
#include <SFML/Window/Window.hpp> // important to be included first (conflict with None) #include <SFML/Window/Window.hpp> // important to be included first (conflict with None)
#include <SFML/Window/Unix/Display.hpp> #include <SFML/Window/Unix/Display.hpp>
#include <SFML/Window/Unix/InputImpl.hpp> #include <SFML/Window/Unix/InputImpl.hpp>
#include <SFML/Window/Unix/X11InputManager.hpp> #include <SFML/Window/Unix/KeyboardImpl.hpp>
#include <SFML/System/Err.hpp> #include <SFML/System/Err.hpp>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/keysym.h> #include <X11/keysym.h>
@ -41,13 +41,13 @@ namespace priv
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool InputImpl::isKeyPressed(Keyboard::Key key) bool InputImpl::isKeyPressed(Keyboard::Key key)
{ {
return X11InputManager::isKeyPressed(key); return KeyboardImpl::isKeyPressed(key);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool InputImpl::isKeyPressed(Keyboard::Scancode code) bool InputImpl::isKeyPressed(Keyboard::Scancode code)
{ {
return X11InputManager::isKeyPressed(code); return KeyboardImpl::isKeyPressed(code);
} }
// Open a connection with the X server // Open a connection with the X server
@ -56,7 +56,7 @@ bool InputImpl::isKeyPressed(Keyboard::Scancode code)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Keyboard::Key InputImpl::localize(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 // 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) Keyboard::Scancode InputImpl::unlocalize(Keyboard::Key key)
{ {
return X11InputManager::unlocalize(key); return KeyboardImpl::unlocalize(key);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
String InputImpl::getDescription(Keyboard::Scancode code) String InputImpl::getDescription(Keyboard::Scancode code)
{ {
return X11InputManager::getDescription(code); return KeyboardImpl::getDescription(code);
} }

View file

@ -25,7 +25,7 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Window/Unix/X11InputManager.hpp> #include <SFML/Window/Unix/KeyboardImpl.hpp>
#include <SFML/System/Utf.hpp> #include <SFML/System/Utf.hpp>
#include <SFML/Window/Unix/Display.hpp> #include <SFML/Window/Unix/Display.hpp>
#include <SFML/Window/Unix/KeySymToSFKeyMapping.hpp> #include <SFML/Window/Unix/KeySymToSFKeyMapping.hpp>
@ -44,7 +44,7 @@ namespace {
KeyCode scancodeToKeycode[sf::Keyboard::ScanCodeCount]; ///< Mapping of SFML scancode to X11 KeyCode KeyCode scancodeToKeycode[sf::Keyboard::ScanCodeCount]; ///< Mapping of SFML scancode to X11 KeyCode
sf::Keyboard::Scancode keycodeToScancode[256]; ///< Mapping of X11 KeyCode to SFML scancode 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) sf::Keyboard::Scancode translateKeyCode(Display* display, KeyCode keycode)
@ -324,13 +324,13 @@ void initMapping()
CloseDisplay(display); CloseDisplay(display);
is_init = true; isMappingInitialized = true;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
KeyCode SFScancodeToKeyCode(sf::Keyboard::Scancode code) KeyCode SFScancodeToKeyCode(sf::Keyboard::Scancode code)
{ {
if (!is_init) if (!isMappingInitialized)
initMapping(); initMapping();
return scancodeToKeycode[code]; return scancodeToKeycode[code];
@ -339,7 +339,7 @@ KeyCode SFScancodeToKeyCode(sf::Keyboard::Scancode code)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sf::Keyboard::Scancode keyCodeToSFScancode(KeyCode code) sf::Keyboard::Scancode keyCodeToSFScancode(KeyCode code)
{ {
if (!is_init) if (!isMappingInitialized)
initMapping(); initMapping();
return keycodeToScancode[code]; return keycodeToScancode[code];
@ -383,7 +383,7 @@ bool isKeyPressedImpl(Display* display, KeyCode keycode)
} // anonymous namespace } // anonymous namespace
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool X11InputManager::isKeyPressed(sf::Keyboard::Key key) bool KeyboardImpl::isKeyPressed(sf::Keyboard::Key key)
{ {
Display* display = OpenDisplay(); Display* display = OpenDisplay();
bool pressed = isKeyPressedImpl(display, SFKeyToKeyCode(key)); 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(); Display* display = OpenDisplay();
bool pressed = isKeyPressedImpl(display, SFScancodeToKeyCode(code)); 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); KeyCode keycode = SFKeyToKeyCode(key);
return keyCodeToSFScancode(keycode); 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); KeySym keysym = SFScancodeToKeySym(code);
return keySymToSFKey(keysym); return keySymToSFKey(keysym);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sf::String X11InputManager::getDescription(Keyboard::Scancode code) sf::String KeyboardImpl::getDescription(Keyboard::Scancode code)
{ {
bool checkInput = true; bool checkInput = true;
// these scancodes actually correspond to keys with input // these scancodes actually correspond to keys with input
// but we want to return their description, not their behaviour // but we want to return their description, not their behaviour
if (code == sf::Keyboard::ScanEnter || if (code == sf::Keyboard::ScanEnter ||
code == sf::Keyboard::ScanReturn || code == sf::Keyboard::ScanReturn ||
code == sf::Keyboard::ScanTab || code == sf::Keyboard::ScanTab ||
code == sf::Keyboard::ScanDelete || code == sf::Keyboard::ScanDelete ||
code == sf::Keyboard::ScanBackspace || code == sf::Keyboard::ScanBackspace ||
code == sf::Keyboard::ScanSpace) { code == sf::Keyboard::ScanSpace) {
checkInput = false; checkInput = false;
@ -437,6 +437,7 @@ sf::String X11InputManager::getDescription(Keyboard::Scancode code)
{ {
KeySym keysym = SFScancodeToKeySym(code); KeySym keysym = SFScancodeToKeySym(code);
sf::Uint32 unicode = keysymToUnicode(keysym); sf::Uint32 unicode = keysymToUnicode(keysym);
if (unicode != 0) if (unicode != 0)
return sf::String(unicode); 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; 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); return keyCodeToSFScancode(event.keycode);
} }

View file

@ -22,8 +22,8 @@
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#ifndef SFML_X11INPUTMANAGER_HPP #ifndef SFML_KEYBOARD_IMPL_HPP
#define SFML_X11INPUTMANAGER_HPP #define SFML_KEYBOARD_IMPL_HPP
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Headers // Headers
@ -44,7 +44,7 @@ namespace priv {
/// Its purpose is to help sf::priv::InputImpl class. /// Its purpose is to help sf::priv::InputImpl class.
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
class X11InputManager class KeyboardImpl
{ {
public: public:
@ -103,4 +103,4 @@ public:
} // namespace sf } // namespace sf
#endif // SFML_X11INPUTMANAGER_HPP #endif // SFML_KEYBOARD_IMPL_HPP

View file

@ -29,6 +29,7 @@
#include <SFML/Window/Unix/ClipboardImpl.hpp> #include <SFML/Window/Unix/ClipboardImpl.hpp>
#include <SFML/Window/Unix/Display.hpp> #include <SFML/Window/Unix/Display.hpp>
#include <SFML/Window/Unix/InputImpl.hpp> #include <SFML/Window/Unix/InputImpl.hpp>
#include <SFML/Window/Unix/KeyboardImpl.hpp>
#include <SFML/System/Utf.hpp> #include <SFML/System/Utf.hpp>
#include <SFML/System/Err.hpp> #include <SFML/System/Err.hpp>
#include <SFML/System/Mutex.hpp> #include <SFML/System/Mutex.hpp>
@ -1830,8 +1831,8 @@ bool WindowImplX11::processEvent(XEvent& windowEvent)
// TODO: if modifiers are wrong, use XGetModifierMapping to retrieve the actual modifiers mapping // TODO: if modifiers are wrong, use XGetModifierMapping to retrieve the actual modifiers mapping
Event event; Event event;
event.type = Event::KeyPressed; event.type = Event::KeyPressed;
event.key.code = X11InputManager::getKeyFromEvent(windowEvent.xkey); event.key.code = KeyboardImpl::getKeyFromEvent(windowEvent.xkey);
event.key.scancode = X11InputManager::getScancodeFromEvent(windowEvent.xkey); event.key.scancode = KeyboardImpl::getScancodeFromEvent(windowEvent.xkey);
event.key.alt = windowEvent.xkey.state & Mod1Mask; event.key.alt = windowEvent.xkey.state & Mod1Mask;
event.key.control = windowEvent.xkey.state & ControlMask; event.key.control = windowEvent.xkey.state & ControlMask;
event.key.shift = windowEvent.xkey.state & ShiftMask; event.key.shift = windowEvent.xkey.state & ShiftMask;
@ -1895,8 +1896,8 @@ bool WindowImplX11::processEvent(XEvent& windowEvent)
// Fill the event parameters // Fill the event parameters
Event event; Event event;
event.type = Event::KeyReleased; event.type = Event::KeyReleased;
event.key.code = X11InputManager::getKeyFromEvent(windowEvent.xkey); event.key.code = KeyboardImpl::getKeyFromEvent(windowEvent.xkey);
event.key.scancode = X11InputManager::getScancodeFromEvent(windowEvent.xkey); event.key.scancode = KeyboardImpl::getScancodeFromEvent(windowEvent.xkey);
event.key.alt = windowEvent.xkey.state & Mod1Mask; event.key.alt = windowEvent.xkey.state & Mod1Mask;
event.key.control = windowEvent.xkey.state & ControlMask; event.key.control = windowEvent.xkey.state & ControlMask;
event.key.shift = windowEvent.xkey.state & ShiftMask; event.key.shift = windowEvent.xkey.state & ShiftMask;