2011-07-21 07:32:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011 Lai Jiangshan
|
|
|
|
*
|
|
|
|
* 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.1 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
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2011-07-21 07:32:34 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include "virkeycode.h"
|
|
|
|
#include <stddef.h>
|
|
|
|
|
2017-03-02 10:46:53 +00:00
|
|
|
#include "virkeycodetable_atset1.h"
|
|
|
|
#include "virkeycodetable_atset2.h"
|
|
|
|
#include "virkeycodetable_atset3.h"
|
|
|
|
#include "virkeycodetable_linux.h"
|
|
|
|
#include "virkeycodetable_osx.h"
|
2018-03-12 11:10:47 +00:00
|
|
|
#include "virkeycodetable_qnum.h"
|
2017-03-02 10:46:53 +00:00
|
|
|
#include "virkeycodetable_usb.h"
|
|
|
|
#include "virkeycodetable_win32.h"
|
|
|
|
#include "virkeycodetable_xtkbd.h"
|
|
|
|
#include "virkeynametable_linux.h"
|
|
|
|
#include "virkeynametable_osx.h"
|
|
|
|
#include "virkeynametable_win32.h"
|
2011-07-21 07:32:34 +00:00
|
|
|
|
2017-03-02 10:46:53 +00:00
|
|
|
static const char **virKeymapNames[VIR_KEYCODE_SET_LAST] = {
|
|
|
|
[VIR_KEYCODE_SET_LINUX] = virKeyNameTable_linux,
|
|
|
|
[VIR_KEYCODE_SET_OSX] = virKeyNameTable_osx,
|
|
|
|
[VIR_KEYCODE_SET_WIN32] = virKeyNameTable_win32,
|
2011-07-21 07:32:34 +00:00
|
|
|
};
|
2013-04-03 12:51:56 +00:00
|
|
|
|
2017-03-02 10:46:53 +00:00
|
|
|
static const unsigned short *virKeymapValues[VIR_KEYCODE_SET_LAST] = {
|
|
|
|
[VIR_KEYCODE_SET_LINUX] = virKeyCodeTable_linux,
|
2017-08-07 13:38:28 +00:00
|
|
|
/* XT is same as AT Set1 - it was included by mistake */
|
|
|
|
[VIR_KEYCODE_SET_XT] = virKeyCodeTable_atset1,
|
2017-03-02 10:46:53 +00:00
|
|
|
[VIR_KEYCODE_SET_ATSET1] = virKeyCodeTable_atset1,
|
|
|
|
[VIR_KEYCODE_SET_ATSET2] = virKeyCodeTable_atset2,
|
|
|
|
[VIR_KEYCODE_SET_ATSET3] = virKeyCodeTable_atset3,
|
|
|
|
[VIR_KEYCODE_SET_OSX] = virKeyCodeTable_osx,
|
|
|
|
[VIR_KEYCODE_SET_XT_KBD] = virKeyCodeTable_xtkbd,
|
|
|
|
[VIR_KEYCODE_SET_USB] = virKeyCodeTable_usb,
|
|
|
|
[VIR_KEYCODE_SET_WIN32] = virKeyCodeTable_win32,
|
2018-03-12 11:10:47 +00:00
|
|
|
[VIR_KEYCODE_SET_QNUM] = virKeyCodeTable_qnum,
|
2013-04-03 12:51:56 +00:00
|
|
|
};
|
2017-03-02 10:46:53 +00:00
|
|
|
|
|
|
|
#define VIR_KEYMAP_ENTRY_MAX ARRAY_CARDINALITY(virKeyCodeTable_linux)
|
|
|
|
|
|
|
|
verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_atset1));
|
|
|
|
verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_atset2));
|
|
|
|
verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_atset3));
|
|
|
|
verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_osx));
|
|
|
|
verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_xtkbd));
|
|
|
|
verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_usb));
|
|
|
|
verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_win32));
|
2018-03-12 11:10:47 +00:00
|
|
|
verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyCodeTable_qnum));
|
2017-03-02 10:46:53 +00:00
|
|
|
verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyNameTable_linux));
|
|
|
|
verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyNameTable_osx));
|
|
|
|
verify(VIR_KEYMAP_ENTRY_MAX == ARRAY_CARDINALITY(virKeyNameTable_win32));
|
2011-07-21 07:32:34 +00:00
|
|
|
|
2019-03-16 18:20:32 +00:00
|
|
|
VIR_ENUM_IMPL(virKeycodeSet,
|
|
|
|
VIR_KEYCODE_SET_LAST,
|
2018-09-19 08:38:14 +00:00
|
|
|
"linux",
|
|
|
|
"xt",
|
|
|
|
"atset1",
|
|
|
|
"atset2",
|
|
|
|
"atset3",
|
|
|
|
"os_x",
|
|
|
|
"xt_kbd",
|
|
|
|
"usb",
|
|
|
|
"win32",
|
|
|
|
"qnum",
|
2019-01-20 16:30:15 +00:00
|
|
|
);
|
2011-07-21 07:32:34 +00:00
|
|
|
|
2013-04-03 12:51:56 +00:00
|
|
|
int virKeycodeValueFromString(virKeycodeSet codeset,
|
|
|
|
const char *keyname)
|
2011-07-21 07:32:34 +00:00
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/util/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2011-07-21 07:32:34 +00:00
|
|
|
|
2013-04-03 12:51:56 +00:00
|
|
|
for (i = 0; i < VIR_KEYMAP_ENTRY_MAX; i++) {
|
|
|
|
if (!virKeymapNames[codeset] ||
|
|
|
|
!virKeymapValues[codeset])
|
|
|
|
continue;
|
2011-07-21 07:32:34 +00:00
|
|
|
|
2013-04-03 12:51:56 +00:00
|
|
|
const char *name = virKeymapNames[codeset][i];
|
2011-07-21 07:32:34 +00:00
|
|
|
|
2013-04-03 12:51:56 +00:00
|
|
|
if (name && STREQ_NULLABLE(name, keyname))
|
|
|
|
return virKeymapValues[codeset][i];
|
2011-07-21 07:32:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-04-03 12:51:56 +00:00
|
|
|
|
2011-07-21 07:32:34 +00:00
|
|
|
int virKeycodeValueTranslate(virKeycodeSet from_codeset,
|
|
|
|
virKeycodeSet to_codeset,
|
|
|
|
int key_value)
|
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/util/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2011-07-21 07:32:34 +00:00
|
|
|
|
2013-12-19 15:40:16 +00:00
|
|
|
if (key_value < 0)
|
2011-07-21 07:32:34 +00:00
|
|
|
return -1;
|
|
|
|
|
2013-04-03 12:51:56 +00:00
|
|
|
|
|
|
|
for (i = 0; i < VIR_KEYMAP_ENTRY_MAX; i++) {
|
|
|
|
if (virKeymapValues[from_codeset][i] == key_value)
|
|
|
|
return virKeymapValues[to_codeset][i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2011-07-21 07:32:34 +00:00
|
|
|
}
|