Windows: Refactor keyboard layout switching code into winbits.c and clean it up. No functional changes.

git-svn-id: https://svn.eduke32.com/eduke32@5970 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2016-12-26 06:02:45 +00:00
parent 735405ed7a
commit d0611405e9
4 changed files with 53 additions and 70 deletions

View file

@ -23,6 +23,9 @@ extern void win_setvideomode(int32_t c);
extern void win_uninit(void);
extern void win_close(void);
extern void Win_GetOriginalLayoutName(void);
extern void Win_SetKeyboardLayoutUS(int);
extern void ShowErrorBox(const char *m);
extern LPTSTR GetWindowsErrorMsg(DWORD code);

View file

@ -742,44 +742,6 @@ void debugprintf(const char *f, ...)
//
//
#ifdef _WIN32
static void switchlayout(const char *layout)
{
char layoutname[KL_NAMELENGTH];
GetKeyboardLayoutName(layoutname);
if (!Bstrcmp(layoutname, layout))
return;
initprintf("Switching keyboard layout from %s to %s\n", layoutname, layout);
LoadKeyboardLayout(layout, KLF_ACTIVATE|KLF_SETFORPROCESS|KLF_SUBSTITUTE_OK);
}
static void W_SetKeyboardLayoutUS(int32_t resetp)
{
static char defaultlayoutname[KL_NAMELENGTH];
if (!resetp)
{
static int done = 0;
if (!done)
{
GetKeyboardLayoutName(defaultlayoutname);
// 00000409 is "American English"
switchlayout("00000409");
done = 1;
}
}
else if (defaultlayoutname[0])
{
switchlayout(defaultlayoutname);
}
}
#endif
// static int32_t joyblast=0;
static SDL_Joystick *joydev = NULL;
@ -791,7 +753,8 @@ int32_t initinput(void)
int32_t i, j;
#ifdef _WIN32
W_SetKeyboardLayoutUS(0);
Win_GetOriginalLayoutName();
Win_SetKeyboardLayoutUS(1);
#endif
#if defined EDUKE32_OSX
@ -869,7 +832,7 @@ int32_t initinput(void)
void uninitinput(void)
{
#ifdef _WIN32
W_SetKeyboardLayoutUS(1);
Win_SetKeyboardLayoutUS(0);
#endif
uninitmouse();

View file

@ -257,6 +257,49 @@ void win_close(void)
}
// Keyboard layout switching
static void switchlayout(char const * layout)
{
char layoutname[KL_NAMELENGTH];
GetKeyboardLayoutName(layoutname);
if (!Bstrcmp(layoutname, layout))
return;
initprintf("Switching keyboard layout from %s to %s\n", layoutname, layout);
LoadKeyboardLayout(layout, KLF_ACTIVATE|KLF_SETFORPROCESS|KLF_SUBSTITUTE_OK);
}
static char OriginalLayoutName[KL_NAMELENGTH];
void Win_GetOriginalLayoutName(void)
{
GetKeyboardLayoutName(OriginalLayoutName);
}
void Win_SetKeyboardLayoutUS(int const toggle)
{
if (toggle)
{
static int done = 0;
if (!done)
{
// 00000409 is "American English"
switchlayout("00000409");
done = 1;
}
}
else if (OriginalLayoutName[0])
{
switchlayout(OriginalLayoutName);
}
}
//
// ShowErrorBox() -- shows an error message box
//

View file

@ -143,7 +143,6 @@ char quitevent=0;
char appactive=1;
char realfs=0;
char regrabmouse=0;
char defaultlayoutname[KL_NAMELENGTH];
int32_t inputchecked = 0;
//-------------------------------------------------------------------------------------------------
@ -709,27 +708,15 @@ int32_t handleevents(void)
}
void switchlayout(char const * layout)
{
char layoutname[KL_NAMELENGTH];
GetKeyboardLayoutName(layoutname);
if (!Bstrcmp(layoutname, layout))
return;
initprintf("Switching keyboard layout from %s to %s\n", layoutname, layout);
LoadKeyboardLayout(layout, KLF_ACTIVATE|KLF_SETFORPROCESS|KLF_SUBSTITUTE_OK);
}
//
// initinput() -- init input system
//
int32_t initinput(void)
{
int32_t i;
static int32_t readlayout=0;
Win_GetOriginalLayoutName();
Win_SetKeyboardLayoutUS(1);
moustat=0;
memset(keystatus, 0, sizeof(keystatus));
@ -745,18 +732,6 @@ int32_t initinput(void)
inputdevices = 1|2;
joyisgamepad = joynumaxes = joynumbuttons = joynumhats=0;
// 00000409 is "American English"
if (!readlayout)
{
GetKeyboardLayoutName(defaultlayoutname);
if (Bstrcmp(defaultlayoutname, "00000409"))
switchlayout("00000409");
readlayout = 1;
}
GetKeyNames();
InitDirectInput();
@ -769,8 +744,7 @@ int32_t initinput(void)
//
void uninitinput(void)
{
if (defaultlayoutname[0])
switchlayout(defaultlayoutname);
Win_SetKeyboardLayoutUS(0);
uninitmouse();
UninitDirectInput();