aboutsummaryrefslogtreecommitdiff
path: root/keymaps.c
diff options
context:
space:
mode:
authoraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2009-03-06 20:27:10 +0000
committeraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2009-03-06 20:27:10 +0000
commit0483755a4d1fd61fe9c284166f67ae08af8d858b (patch)
tree2c1e9ac8af63b982a7e0501408fbb37d0780ab93 /keymaps.c
parent1ff7df1a848044f58d0f3540f1447db4bb1d2d20 (diff)
Refactor keymap code to avoid duplication ("Daniel P. Berrange")
Each of the graphical frontends #include a .c file, for keymap code resulting in duplicated definitions & duplicated compiled code. A couple of small changes allowed this to be sanitized, so instead of doing a #include "keymaps.c", duplicating all code, we can have a shared keymaps.h file, and only compile code once. This allows the next patch to move the VncState struct out into a header file without causing clashing definitions. Makefile | 9 +++++--- b/keymaps.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ curses.c | 3 -- curses_keys.h | 9 +++----- keymaps.c | 45 ++++++++++++++++--------------------------- sdl.c | 3 -- sdl_keysym.h | 7 ++---- vnc.c | 5 +--- vnc_keysym.h | 7 ++---- 9 files changed, 97 insertions(+), 51 deletions(-) Signed-off-by: Daniel P. Berrange <berrange@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6721 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'keymaps.c')
-rw-r--r--keymaps.c45
1 files changed, 17 insertions, 28 deletions
diff --git a/keymaps.c b/keymaps.c
index 216e37831b..3b86dc15eb 100644
--- a/keymaps.c
+++ b/keymaps.c
@@ -22,34 +22,20 @@
* THE SOFTWARE.
*/
-static int get_keysym(const char *name)
+#include "keymaps.h"
+#include "sysemu.h"
+
+static int get_keysym(const name2keysym_t *table,
+ const char *name)
{
const name2keysym_t *p;
- for(p = name2keysym; p->name != NULL; p++) {
+ for(p = table; p->name != NULL; p++) {
if (!strcmp(p->name, name))
return p->keysym;
}
return 0;
}
-struct key_range {
- int start;
- int end;
- struct key_range *next;
-};
-
-#define MAX_NORMAL_KEYCODE 512
-#define MAX_EXTRA_COUNT 256
-typedef struct {
- uint16_t keysym2keycode[MAX_NORMAL_KEYCODE];
- struct {
- int keysym;
- uint16_t keycode;
- } keysym2keycode_extra[MAX_EXTRA_COUNT];
- int extra_count;
- struct key_range *keypad_range;
- struct key_range *numlock_range;
-} kbd_layout_t;
static void add_to_key_range(struct key_range **krp, int code) {
struct key_range *kr;
@@ -73,7 +59,8 @@ static void add_to_key_range(struct key_range **krp, int code) {
}
}
-static kbd_layout_t *parse_keyboard_layout(const char *language,
+static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table,
+ const char *language,
kbd_layout_t * k)
{
FILE *f;
@@ -102,7 +89,7 @@ static kbd_layout_t *parse_keyboard_layout(const char *language,
if (!strncmp(line, "map ", 4))
continue;
if (!strncmp(line, "include ", 8)) {
- parse_keyboard_layout(line + 8, k);
+ parse_keyboard_layout(table, line + 8, k);
} else {
char *end_of_keysym = line;
while (*end_of_keysym != 0 && *end_of_keysym != ' ')
@@ -110,7 +97,7 @@ static kbd_layout_t *parse_keyboard_layout(const char *language,
if (*end_of_keysym) {
int keysym;
*end_of_keysym = 0;
- keysym = get_keysym(line);
+ keysym = get_keysym(table, line);
if (keysym == 0) {
// fprintf(stderr, "Warning: unknown keysym %s\n", line);
} else {
@@ -154,12 +141,14 @@ static kbd_layout_t *parse_keyboard_layout(const char *language,
return k;
}
-static void *init_keyboard_layout(const char *language)
+
+void *init_keyboard_layout(const name2keysym_t *table, const char *language)
{
- return parse_keyboard_layout(language, 0);
+ return parse_keyboard_layout(table, language, 0);
}
-static int keysym2scancode(void *kbd_layout, int keysym)
+
+int keysym2scancode(void *kbd_layout, int keysym)
{
kbd_layout_t *k = kbd_layout;
if (keysym < MAX_NORMAL_KEYCODE) {
@@ -180,7 +169,7 @@ static int keysym2scancode(void *kbd_layout, int keysym)
return 0;
}
-static inline int keycode_is_keypad(void *kbd_layout, int keycode)
+int keycode_is_keypad(void *kbd_layout, int keycode)
{
kbd_layout_t *k = kbd_layout;
struct key_range *kr;
@@ -191,7 +180,7 @@ static inline int keycode_is_keypad(void *kbd_layout, int keycode)
return 0;
}
-static inline int keysym_is_numlock(void *kbd_layout, int keysym)
+int keysym_is_numlock(void *kbd_layout, int keysym)
{
kbd_layout_t *k = kbd_layout;
struct key_range *kr;