chiark / gitweb /
Normalise commodity name case (from uploads)
[ypp-sc-tools.db-test.git] / yarrg / pages.c
index 955add9bda46b56e20dcba84a7bcd3f637be08c9..d5385d3bdd71102cf715a1606cf13a8d62881a66 100644 (file)
@@ -55,6 +55,7 @@ static XImage *shmim;
 static XShmSegmentInfo shminfo;
 
 DEBUG_DEFINE_DEBUGF(pages)
+DEBUG_DEFINE_SOME_DEBUGF(keymap,keydebugf)
 
 #define xassert(what)                                  \
   ((what) ? (void)0 :                                  \
@@ -91,18 +92,22 @@ static MappedModifier mm_shift, mm_modeswitch, mm_isol3shift;
 static KeySym *mapping;
 static int mapwidth;
 
-static void keymap_lookup_modifier(MappedModifier *mm, KeySym sym,
-                                  char ifnot) {
+static void keymap_lookup_modifier(MappedModifier *mm, const char *what,
+                                  KeySym sym, char ifnot) {
   int kc;
+  keydebugf("KEYMAP modifier lookup %-10s %#lx or '%c' ", what,
+           (unsigned long)sym, ifnot);
 
   mm->isdef= ifnot;
   for (kc=kc_min; kc <= kc_max; kc++) {
     if (mapping[(kc-kc_min)*mapwidth] == sym) {
+      keydebugf(" found kc=%d\n", kc);
       mm->isdef= 'y';
       mm->kc= kc;
       return;
     }
   }
+  keydebugf(" none\n");
 }
 
 static void keymap_lookup_key(MappedKey *mk, KeySym sym, const char *what) {
@@ -114,12 +119,15 @@ static void keymap_lookup_key(MappedKey *mk, KeySym sym, const char *what) {
   cols[MAXMAPCOL]= 0;
 
   for (col=0; col<mapwidth && col<MAXMAPCOL; col++) {
-
-#define CHECK_SHIFT(sh) do{                    \
-      if ((sh) && (sh)->isdef!='y') {          \
-       cols[col]= (sh)->isdef;                 \
-       continue;                               \
-      }                                                \
+    keydebugf("KEYMAP lookup %-10s %#lx col=%d ",
+             what, (unsigned long)sym, col);
+
+#define CHECK_SHIFT(sh) do{                                    \
+      if ((sh) && (sh)->isdef!='y') {                          \
+       cols[col]= (sh)->isdef;                                 \
+        keydebugf("no-modifier " #sh "'%c'\n", (sh)->isdef);   \
+       continue;                                               \
+      }                                                                \
     }while(0)
 
     shift= col & 1 ? &mm_shift : 0;
@@ -135,6 +143,7 @@ static void keymap_lookup_key(MappedKey *mk, KeySym sym, const char *what) {
        goto found;
     }
     cols[col]= '_';
+    keydebugf("not-found\n");
   }
   fprintf(stderr,"\n"
          "Unable to find a key to press to generate %s.\n"
@@ -149,34 +158,42 @@ static void keymap_lookup_key(MappedKey *mk, KeySym sym, const char *what) {
   
   if (xshift) *fill++ = xshift->kc;
   if (shift)  *fill++ = shift->kc;
-  *fill += kc;
+  *fill++ += kc;
   mk->len= fill - mk->kc;
+  keydebugf("found kc=%d len=%d\n",kc,mk->len);
 }
 
 static void keymap_startup(void) {
   xassert( XDisplayKeycodes(disp,&kc_min,&kc_max) );
+  keydebugf("KEYMAP keycodes %d..%d\n",kc_min,kc_max);
+
   xassert( mapping= XGetKeyboardMapping(disp, kc_min, kc_max-kc_min+1,
                                        &mapwidth) );
+  keydebugf("KEYMAP got keyboard map\n");
 
   XModifierKeymap *modmap;
   xassert( modmap= XGetModifierMapping(disp) );
+  keydebugf("KEYMAP got modifier map\n");
 
   /* find a shift keycode */
   mm_shift.isdef= 'x';
   int modent;
   for (modent=0; modent<modmap->max_keypermod; modent++) {
-    KeySym shiftsym= modmap->modifiermap[modent];
-    if (shiftsym==NoSymbol) continue;
-    keymap_lookup_modifier(&mm_shift, shiftsym, 's');
-    if (mm_shift.isdef!='y') break;
+    int kc= modmap->modifiermap[modent];
+    keydebugf("KEYMAP modifier #0 key #%d is %d ", modent, kc);
+    if (!kc) { keydebugf("none\n"); continue; }
+    keydebugf("ok\n");
+    mm_shift.kc= kc;
+    mm_shift.isdef= 'y';
+    break;
   }
 
-  /* find keycodes for mode_switch (column+=2) and ISO L3 shift (column+=4) */
-  keymap_lookup_modifier(&mm_modeswitch, XK_Mode_switch,      0);
-  keymap_lookup_modifier(&mm_isol3shift, XK_ISO_Level3_Shift, 0);
-  
   XFreeModifiermap(modmap);
 
+  /* find keycodes for mode_switch (column+=2) and ISO L3 shift (column+=4) */
+  keymap_lookup_modifier(&mm_modeswitch,"modeswitch", XK_Mode_switch,     'm');
+  keymap_lookup_modifier(&mm_isol3shift,"isol3shift", XK_ISO_Level3_Shift,'l');
+  
 #define KEY_MAP_LOOKUP(xk) \
   keymap_lookup_key(&mk_##xk, xk, #xk);
   KEYS(KEY_MAP_LOOKUP)
@@ -294,6 +311,7 @@ static void check_pointer_not_disturbed(void) {
 static void send_key(MappedKey *mk) {
   int i;
   check_not_disturbed();
+  keydebugf("KEYMAP SEND_KEY len=%d kc=%d\n", mk->len, mk->kc[mk->len-1]);
   for (i=0; i<mk->len; i++) XTestFakeKeyEvent(disp, mk->kc[i], 1, 0);
   for (i=mk->len; --i>=0; ) XTestFakeKeyEvent(disp, mk->kc[i], 0, 0);
 }