From d8c047bcd4af06420271482d385fb684195d6e31 Mon Sep 17 00:00:00 2001 From: DeXP Date: Sun, 31 Mar 2013 17:46:58 +0300 Subject: [PATCH] first commit --- libxkbswitchwin.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 libxkbswitchwin.c diff --git a/libxkbswitchwin.c b/libxkbswitchwin.c new file mode 100644 index 0000000..072d05f --- /dev/null +++ b/libxkbswitchwin.c @@ -0,0 +1,78 @@ +/* xkb-switch-lib API port to Win32/Win64 + * Copyright (C) 2013 Dmitry Hrabrov a.k.a. DeXPeriX + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include + +#define MAX_LAYS 10 +#define LBUF 3 + +char lName[LBUF+1]; + +__declspec(dllexport) +const char * Xkb_Switch_getXkbLayout( const char * param /* unused */ ){ + unsigned int x; + HWND hwnd; + DWORD threadId; + HKL currentLayout; + LCID localez; + + hwnd = GetForegroundWindow(); + if( hwnd ){ + threadId = GetWindowThreadProcessId(hwnd, NULL); + currentLayout = GetKeyboardLayout(threadId); + x = (unsigned int)currentLayout & 0x0000FFFF; + localez = MAKELCID( (LANGID)x, SORT_DEFAULT); + GetLocaleInfo(localez, LOCALE_SISO639LANGNAME, lName, LBUF); + + if( (lName[0]=='e') && (lName[1]=='n') ){ + /* Replace 'en' string to 'us' */ + lName[0] = 'u'; + lName[1] = 's'; + lName[2] = 0; + } + return lName; + } else return NULL; +} + + +__declspec(dllexport) +const char * Xkb_Switch_setXkbLayout( const char * newgrp ){ + unsigned int i, n, Lid; + HKL lpList[MAX_LAYS]; + HKL currentLayout; + HWND hwnd; + + if ( newgrp == NULL || newgrp[ 0 ] == '\0' ) return NULL; + + n = GetKeyboardLayoutList(0, NULL); + n = GetKeyboardLayoutList(n, lpList); + hwnd = GetForegroundWindow(); + + for(i=0; i