# HG changeset patch
# User Chun Yan Liu <cyliu@novell.com>
# Date 1294271316 0
# Node ID a283996796c91dd29ecff444b78798e0ce902047
# Parent 39df13908a3ad54e79dd3b53ed307e57f12f6d3d
fix '|' key display problem in en-us with altgr processing

Commit f95d202ed644 handles altgr-insert problem.  Unfortunately, with
that patch, there is a problem in En-us keyboard: '|' (bar) cannot be
displayed. After checking keymap files, we found there are two
definitions to "bar" in en-us: bar 0x56 altgr (in "common") bar 0x2b
shift (in "en-us") First line is actually invalid in en-us
lanuage. The 2nd definition will cover the 1st one.

The previous change in didn't consider multi-definition case. It scans
keymap files, if keysym needs altgr, it will records that, after that,
if keysym is pressed but altgr not pressed, it will add an altgr press
opeartion. It is correct if all keysyms are unique and valid. But in
the above multi-definition case, there is problem: when reading bar
0x56 altgr (in "common") it will record altgr needed, but in fact,
that definition won't be used, it always use the 2nd definition and
won't need altgr. Then if the keysym is pressed, the code will still
add an altgr press operation, that will cause problem.

So, if we cannot avoid multi-definition in keymap files, the altgr
flag (whether altgr needed or not) should also be refreshed according
to the 2nd defintion. In the above case, when reading the 1st line, it
records altgr needed; then reading 2nd line, 2nd definition will cover
the 1st, meanwhile the altgr flag should be reset (the 2nd definition
doesn't need altgr, so altgr flag should be removed.)

Following patch supplements f95d202ed644, and solve the
problem.

Signed-off-by: Chun Yan Liu <cyliu@novell.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>

committer: Ian Jackson <Ian.Jackson@eu.citrix.com>
git-commit-id: 99d53fbb69d3e03be61ae10506a304a3d08d792f

# HG changeset patch
# User Jan Beulich <jbeulich@novell.com>
# Date 1295287237 0
# Node ID b47bf8f7a5e1959d6f5c62febaef9e81dc3231a0
# Parent b6bbe8be0afa54774a19ef43767a029ebddb2666
keymaps.c: fix use after free in del_key_range

Commit 99d53fbb69d3e03be61ae10506a304a3d08d792f introduced this, and
the compiler indirectly warned about it.

The patch is only compile tested (I don't even know how to reproduce
the original problem), but I suppose worth applying regardless.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
Cc: Chun Yan Liu <cyliu@novell.com>

committer: Ian Jackson <Ian.Jackson@eu.citrix.com>
git-commit-id: fdb22f24bc8adb3455b771d804496e11b4570085

Index: xen-4.0.3-testing/tools/ioemu-qemu-xen/keymaps.c
===================================================================
--- xen-4.0.3-testing.orig/tools/ioemu-qemu-xen/keymaps.c
+++ xen-4.0.3-testing/tools/ioemu-qemu-xen/keymaps.c
@@ -54,6 +54,17 @@ typedef struct {
     struct key_range *altgr_range;
 } kbd_layout_t;
 
+static void del_key_range(struct key_range **krp, int code) {
+    struct key_range *kr;
+    while ((kr = *krp) != NULL) {
+        if (code >= kr->start && code <= kr->end) {
+            *krp = kr->next;
+            qemu_free(kr);
+        } else
+            krp = &kr->next;
+    }
+}
+
 static void add_to_key_range(struct key_range **krp, int code) {
     struct key_range *kr;
     for (kr = *krp; kr; kr = kr->next) {
@@ -137,6 +148,8 @@ static kbd_layout_t *parse_keyboard_layo
 		    if (rest && strstr(rest, "altgr")) {
 			add_to_key_range(&k->altgr_range, keysym);
 			//fprintf(stderr, "altgr keysym %04x keycode %d\n", keysym, keycode);
+		    } else {
+			del_key_range(&k->altgr_range, keysym);
 		    }
 	
 		    /* if(keycode&0x80)
Index: xen-4.0.3-testing/tools/ioemu-qemu-xen/vnc.c
===================================================================
--- xen-4.0.3-testing.orig/tools/ioemu-qemu-xen/vnc.c
+++ xen-4.0.3-testing/tools/ioemu-qemu-xen/vnc.c
@@ -1279,11 +1279,9 @@ static void press_key_altgr_down(VncStat
     kbd_put_keycode(0xe0);
     if (down){
         kbd_put_keycode(0xb8 & 0x7f);
-        vs->modifiers_state[0xb8] = 1;
     }
     else {
         kbd_put_keycode(0xb8 | 0x80);
-        vs->modifiers_state[0xb8] = 0;
     }
 }
 
