From bbd4ceb7113b96417133dd4b401fb60494ce5fff Mon Sep 17 00:00:00 2001 From: pouillot Date: Tue, 19 Apr 2011 17:07:45 +0000 Subject: [PATCH] Re #377 Fixed keyboard management regression of r3501 (back to usability) git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@3506 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 1e2cf3752d4d30e5698e891f36e7e4b266a52e50 Former-commit-id: 3657550457063ae63c641c31aa3e6100a096945b --- src/libs/tgf/application.cpp | 4 ++-- src/libs/tgf/eventloop.cpp | 26 ++++++++++++++------------ src/libs/tgfclient/guiapplication.cpp | 2 +- src/libs/tgfclient/guieventloop.cpp | 1 + src/libs/tgfclient/guiscreen.cpp | 6 +++++- src/modules/networking/network.cpp | 6 ------ 6 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/libs/tgf/application.cpp b/src/libs/tgf/application.cpp index 22ab4325..945b41cb 100644 --- a/src/libs/tgf/application.cpp +++ b/src/libs/tgf/application.cpp @@ -58,8 +58,8 @@ GfApplication::GfApplication(const char* pszName, const char* pszDesc, int argc, _pSelf = this; // Initialize the gaming framework. - GfInit(); - + GfInit(); + // Store the command line options. if (argv) for (int i = 0; i < argc; i++) diff --git a/src/libs/tgf/eventloop.cpp b/src/libs/tgf/eventloop.cpp index 9b2e60a7..0ed693cf 100644 --- a/src/libs/tgf/eventloop.cpp +++ b/src/libs/tgf/eventloop.cpp @@ -62,17 +62,14 @@ private: // Private data members. std::map _mapUnicodes; }; -//! Initialization flag for the underlying software layers. -bool GfEventLoop::Private::_bInitialized = 0; - - GfEventLoop::Private::Private() : cbKeyboardDown(0), cbKeyboardUp(0), cbIdle(0), cbTimer(0), bQuit(false) { - if (!_bInitialized) + static bool bInitialized = false; + if (!bInitialized) { SDL_EnableUNICODE(/*enable=*/1); // For keyboard "key press" event key code translation - _bInitialized = true; + bInitialized = true; } } @@ -85,23 +82,28 @@ GfEventLoop::Private::Private() // Known issues (TODO): No support for Caps and NumLock keys ... don't use them ! int GfEventLoop::Private::translateKeySym(int code, int modifier, int unicode) { - int keyUnicode; - + // Generate the key Id from its code and modifier. const Uint32 keyId = ((Uint32)code & 0x1FF) | (((Uint32)modifier) << 9); - + + // Search it in our unicode map. const std::map::const_iterator itUnicode = _mapUnicodes.find(keyId); - + + // If not found, update the map for next times. + int keyUnicode; if (itUnicode == _mapUnicodes.end()) { // Truncate unicodes above GF_MAX_KEYCODE (no need for more). keyUnicode = unicode ? (unicode & GF_MAX_KEYCODE) : code; _mapUnicodes[keyId] = keyUnicode; - //GfLogDebug("translateKeySym: New key id=0x%08X, unicode=%d (%d)\n", - // keyId, keyUnicode, _mapUnicodes.size()); + //GfLogDebug("translateKeySym(c=%d, m=%d, u=%d) : New key id=0x%08X, unicode=%d (%d)\n", + // code, modifier, unicode, keyId, keyUnicode, _mapUnicodes.size()); } + + // If found, get the unicode from the map. else keyUnicode = (*itUnicode).second; + // Done. return keyUnicode; } diff --git a/src/libs/tgfclient/guiapplication.cpp b/src/libs/tgfclient/guiapplication.cpp index 45bf81c2..d34aaa04 100644 --- a/src/libs/tgfclient/guiapplication.cpp +++ b/src/libs/tgfclient/guiapplication.cpp @@ -20,7 +20,7 @@ GfuiApplication::GfuiApplication(const char* pszName, const char* pszDesc, int argc, char **argv) -: GfApplication(pszName ? pszName : "GfuiApplication", pszDesc, argc, argv) +: GfApplication((pszName ? pszName : "GfuiApplication"), pszDesc, argc, argv) { // Help about the options. _optionsHelp.lstSyntaxLines.push_back("[-m|--hardmouse]"); diff --git a/src/libs/tgfclient/guieventloop.cpp b/src/libs/tgfclient/guieventloop.cpp index 80fe15f8..75428a37 100644 --- a/src/libs/tgfclient/guieventloop.cpp +++ b/src/libs/tgfclient/guieventloop.cpp @@ -52,6 +52,7 @@ GfuiEventLoop::Private::Private() // GfuiEventLoop class ============================================================ GfuiEventLoop::GfuiEventLoop() +: GfEventLoop() { _pPrivate = new Private; } diff --git a/src/libs/tgfclient/guiscreen.cpp b/src/libs/tgfclient/guiscreen.cpp index 5ee7c1b5..5e6fbdbf 100644 --- a/src/libs/tgfclient/guiscreen.cpp +++ b/src/libs/tgfclient/guiscreen.cpp @@ -344,7 +344,11 @@ bool GfScrInit(void) GfLogError("Couldn't initialize SDL video sub-system (%s)\n", SDL_GetError()); return false; } - + + // Enable unicode translation for SDL key press events, even if already done before + // (SDL_InitSubSystem(SDL_INIT_VIDEO) seems to break it). + SDL_EnableUNICODE(/*enable=*/1); + // Query system video capabilities. // Note: Does not work very well as long as you don't force SDL to use // a special hardware driver ... which we don't want at all (the default is the one). diff --git a/src/modules/networking/network.cpp b/src/modules/networking/network.cpp index 0e59b6f1..1395f673 100644 --- a/src/modules/networking/network.cpp +++ b/src/modules/networking/network.cpp @@ -785,12 +785,6 @@ Uint32 network_callbackfunc(Uint32 interval, void *param) bool NetworkInit() { - // Initialize SDL : not needed, as already done in GfInit. -// if ( SDL_InitSubSystem(SDL_INIT_TIMER) < 0 ) { -// GfLogTrace("NetworkInit : Couldn't initialize SDL: %s\n", SDL_GetError()); -// return false; -// } - g_bInit = true; return true;