Handle shift level for modifiers, too.
authorThibaut Girka <thib@sitedethib.com>
Thu, 21 Jul 2011 23:23:29 +0200
changeset 19 37cc422efb37
parent 18 db9a4d812715
child 20 7c18d7b35b56
Handle shift level for modifiers, too.
ui.c
--- a/ui.c	Thu Jul 21 23:07:30 2011 +0200
+++ b/ui.c	Thu Jul 21 23:23:29 2011 +0200
@@ -262,11 +262,31 @@
 }
 
 
+unsigned int ui_compute_key_shift_level(VirtualKeyboardUI *ui, VirtualKey vkey)
+{
+    unsigned int shift_level = 0;
+    unsigned int index, i, mask;
+    index = ui->vkb->xkb->map->key_sym_map[vkey.keycode].kt_index[ui->vkb->group];
+    mask = ui->vkb->xkb->map->types[index].mods.mask & ui->vkb->mods;
+
+    if (mask != 0)
+        shift_level = 1;
+
+    for (i=0; i < ui->vkb->xkb->map->types[index].map_count; i++)
+    {
+        if (mask == ui->vkb->xkb->map->types[index].map[i].mods.mask)
+            shift_level = ui->vkb->xkb->map->types[index].map[i].level;
+    }
+
+    return shift_level;
+}
+
+
 void ui_redraw(VirtualKeyboardUI *ui)
 {
     PangoLayout *layout;
     cairo_t *context;
-    int i, j, index;
+    int i;
 
     context = cairo_create(ui->cairo_surf);
     layout = pango_cairo_create_layout(context);
@@ -289,17 +309,7 @@
         /* TODO: cleanup */
 #if 1
         /* Compute shift level. FIXME: there must be a nicer way */
-        unsigned shift_level = 0;
-        unsigned int mask;
-        index = ui->vkb->xkb->map->key_sym_map[vkey.keycode].kt_index[ui->vkb->group];
-        mask = ui->vkb->xkb->map->types[index].mods.mask & ui->vkb->mods;
-        if (mask != 0)
-            shift_level = 1;
-        for (j=0; j < ui->vkb->xkb->map->types[index].map_count; j++)
-        {
-            if (mask == ui->vkb->xkb->map->types[index].map[j].mods.mask)
-                shift_level = ui->vkb->xkb->map->types[index].map[j].level;
-        }
+        unsigned int shift_level = ui_compute_key_shift_level(ui, vkey);
         if ((keysym = XkbKeycodeToKeysym(ui->vkb->display, vkey.keycode,
                                 ui->vkb->group, shift_level)) != NoSymbol)
 #else
@@ -494,8 +504,9 @@
                 /* TODO: clean up this mess */
                 if (vkey && vkey->keycode)
                 {
-                    /* TODO: shift level */
-                    XkbAction *action = XkbKeyActionEntry(ui->vkb->xkb, vkey->keycode, 0, ui->vkb->group);
+                    unsigned shift_level = ui_compute_key_shift_level(ui, *vkey);
+                    XkbAction *action = XkbKeyActionEntry(ui->vkb->xkb, vkey->keycode,
+                                                          shift_level, ui->vkb->group);
 
                     /* TODO: how is compose handled? */
                     if (action != NULL && (action->any.type == XkbSA_LockMods || action->any.type == XkbSA_SetMods)) /* modifier */
@@ -521,12 +532,10 @@
                     }
                     else
                     {
-                        if (!vkey->state)
-                        {
-                            vkey->state = VirtualKeyPressed;
-                            ui->vkb->pressed_key = vkey;
+                        if (vkey->state == VirtualKeyReleased)
                             XTestFakeKeyEvent(ui->vkb->display, vkey->keycode, True, CurrentTime);
-                        }
+                        vkey->state = VirtualKeyPressed;
+                        ui->vkb->pressed_key = vkey;
                     }
 
                     ui_redraw(ui);