gonzui


Format: Advanced Search

tkernel_2/driver/tef_em1d/kbpd/src/innevt.cbare sourcepermlink (0.01 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    T-Kernel 2.0 Software Package
    4:  *
    5:  *    Copyright 2011 by Ken Sakamura.
    6:  *    This software is distributed under the latest version of T-License 2.x.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by T-Engine Forum(http://www.t-engine.org/) at 2011/05/17.
   10:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/01.
   11:  *
   12:  *----------------------------------------------------------------------
   13:  */
   14: 
   15: /*
   16:  *      innevt.c
   17:  *
   18:  *       KB/PD device manager
   19:  *       internal event processing
   20:  */
   21: 
   22: #include "kbpd.h"
   23: 
   24: /*
   25:  * lock key down
   26:  *      if a code is processed as lock key, then return TRUE
   27:  */
   28: LOCAL BOOL lockKeyDown( UH code )
   29: {
   30:         InputMode      mode;
   31:         UW             meta;
   32:         BOOL           chgLED;
   33:         union {
   34:                 MetaBut       stat;
   35:                 UW    uw;
   36:         } u;
   37: 
   38:         mode = kpMgrInfo.kpState.stat.mode;
   39:         u.stat = kpMgrInfo.kpState.stat;
   40:         meta = u.uw;
   41: 
   42:         switch ( code ) {
   43:           case KC_EIJI:        /* English <-> Japanese swap */
   44:                 mode ^= AlphaMode;
   45:                 break;
   46:           case KC_CAPN:        /* Hiragana <-> Katakana swap */
   47:                 mode ^= KataMode;
   48:                 break;
   49:           case KC_JPN0_Z: /* Japanese Hiragana & Zenkaku */
   50:                 meta &= ~ES_HAN;
   51:           case KC_JPN0:        /* Japanese Hiragana */
   52:                 mode = HiraMode;
   53:                 break;
   54:           case KC_JPN1_Z: /* Japanese Katakana & Zenkaku */
   55:                 meta &= ~ES_HAN;
   56:           case KC_JPN1:        /* Japanese Katanaka */
   57:                 mode = KataMode;
   58:                 break;
   59:           case KC_ENG0_H: /* English & Hankaku */
   60:                 meta |= ES_HAN;
   61:           case KC_ENG0:        /* English */
   62:                 mode = AlphaMode;
   63:                 break;
   64:           case KC_ENG1_H: /* English CAPS & Hanaku */
   65:                 meta |= ES_HAN;
   66:           case KC_ENG1:        /* English CAPS */
   67:                 mode = CapsMode;
   68:                 break;
   69:           case KC_ENGALT:      /* -> English <--> English CAPS */
   70:                 if (mode & AlphaMode) mode ^= KataMode;
   71:                 else  mode = AlphaMode;
   72:                 break;
   73:           case KC_JPNALT:      /* ->Hiragana<-->Katakana */
   74:                 if (mode & AlphaMode) mode = HiraMode;
   75:                 else  mode ^= KataMode;
   76:                 break;
   77: 
   78:           case KC_KBSEL:       /* Kana <--> Roman Input */
   79:                 meta ^= ES_KBSEL;
   80:                 break;
   81:           case KC_HAN:         /* Zenkaku <--> Hankaku */
   82:                 meta ^= ES_HAN;
   83:                 break;
   84:           default:
   85:                 /* not a lock key */
   86:                 return FALSE;
   87:         }
   88: 
   89:         if ( (chgLED = ( mode != kpMgrInfo.kpState.stat.mode ))
   90:           || meta != u.uw ) {
   91: 
   92:                 /* change input mode */
   93:                 u.uw = meta;
   94:                 kpMgrInfo.kpState.stat = u.stat;
   95:                 kpMgrInfo.kpState.stat.mode = mode;
   96: 
   97:                 if ( chgLED ) {
   98:                         /* change keyboard LED */
   99:                         kpChangeKbInputMode(mode);
  100:                 }
  101: 
  102:                 /* notify meta key status change event */
  103:                 kpNotifyMetaEvent();
  104:         }
  105: 
  106:         return TRUE;
  107: }
  108: 
  109: /*
  110:  * key down
  111:  */
  112: LOCAL void ieKeyDown( InnerEvent *evt, TMO *tmout )
  113: {
  114:         KeyEvt         keyEvt;
  115:         UH             code;
  116: 
  117:         /* convert to character code */
  118:         code = kpToKeycode(evt->i.key.keytop, &evt->i.key.meta);
  119: 
  120:         /* lock key processing */
  121:         if ( lockKeyDown(code) ) {
  122:                 /* process only lock key and finish */
  123:                 return;
  124:         }
  125: 
  126:         /* PD simulation processing */
  127:         if ( kpExecPdSimKeyDown(evt, code, tmout) ) {
  128:                 /* process PD simulation only and finish */
  129:                 return;
  130:         }
  131: 
  132:         /* notify key down event */
  133:         keyEvt.h.evttyp = TDE_KEYDOWN;
  134:         keyEvt.keytop = kpKeyTopCode(evt->i.key.keytop,
  135:                                 evt->i.key.meta.o.kbsel);
  136:         keyEvt.code = code;
  137:         keyEvt.stat = evt->i.key.meta.o;
  138:         kpNotifyEvent(&keyEvt, sizeof(keyEvt));
  139: }
  140: 
  141: /*
  142:  * key up
  143:  */
  144: LOCAL void ieKeyUp( InnerEvent *evt, TMO *tmout )
  145: {
  146:         KeyEvt         keyEvt;
  147:         UH             code;
  148: 
  149:         /* convert to character code */
  150:         code = kpToKeycode(evt->i.key.keytop, &evt->i.key.meta);
  151: 
  152:         /* lock key needs no processing */
  153:         if ( isMetaKey(code) ) goto skip;
  154: 
  155:         /* PD simulation processing */
  156:         if ( kpExecPdSimKeyUp(evt, code, tmout) ) {
  157:                 /* process PD simulation only */
  158:                 goto skip;
  159:         }
  160: 
  161:         /* notify key up event */
  162:         keyEvt.h.evttyp = TDE_KEYUP;
  163:         keyEvt.keytop = kpKeyTopCode(evt->i.key.keytop,
  164:                                 evt->i.key.meta.o.kbsel);
  165:         keyEvt.code = code;
  166:         keyEvt.stat = evt->i.key.meta.o;
  167:         kpNotifyEvent(&keyEvt, sizeof(keyEvt));
  168: 
  169: skip:
  170:         /* switch temporary shift or simple lock modes */
  171:         if ( kpChangeShiftLock(evt->type, NoShift) ) {
  172: 
  173:                 /* notify meta key status change event */
  174:                 kpNotifyMetaEvent();
  175:         }
  176: }
  177: 
  178: /*
  179:  * shift key press / relea
  180:  */
  181: LOCAL void ieShift( InnerEvent *evt )
  182: {
  183:         ShiftKeyKind   shift;
  184:         KpMetaBut      *meta = (KpMetaBut*)&kpMgrInfo.kpState.stat;
  185:         BOOL           chg = FALSE;
  186: 
  187:         if ( evt->type == IE_S_PRESS ) {
  188:                 /* set press status (press) */
  189:                 kpMgrInfo.spress |= evt->i.sft.kind;
  190:         } else {
  191:                 /* set press status (release) */
  192:                 kpMgrInfo.spress &= ~evt->i.sft.kind;
  193: 
  194:                 /* switch temporary shift or simple lock modes */
  195:                 chg = kpChangeShiftLock(evt->type, evt->i.sft.kind);
  196:         }
  197: 
  198:         /* shift status */
  199:         shift = meta->u.tmpShift | meta->u.shiftLock | kpMgrInfo.spress;
  200: 
  201:         if ( shift != meta->u.shift || chg ) {
  202: 
  203:                 /* change shift status */
  204:                 meta->u.shift = shift;
  205: 
  206:                 /* notify meta key status change event */
  207:                 kpNotifyMetaEvent();
  208:         }
  209: }
  210: 
  211: /*
  212:  * key input error
  213:  */
  214: LOCAL void ieKeyErr( InnerEvent *evt, TMO *tmout )
  215: {
  216:         InnerEvent     shift;
  217: 
  218:         if ( evt->i.key.keytop.w == InvalidKeytop ) {
  219:                 /* shift release */
  220:                 shift.type = IE_S_REL;
  221:                 shift.i.sft.kind = SK_ALL;
  222:                 ieShift(&shift);
  223:         } else {
  224:                 /* key up */
  225:                 ieKeyUp(evt, tmout);
  226:         }
  227: }
  228: 
  229: /*
  230:  * PD button up / down, move
  231:  */
  232: LOCAL void iePd( InnerEvent *evt )
  233: {
  234:         InnEvtType     type = evt->type;
  235:         TDEvtTyp       devEvt = 0;
  236:         BOOL           qpress = FALSE;
  237:         UW             nodsp;
  238: 
  239:         if ( (type & IE_PDMOVE) != 0 ) {
  240:                 /* move */
  241:                 devEvt = kpPdMoveEvent(evt);
  242:         }
  243:         if ( (type & IE_PDBUT) != 0 ) {
  244:                 /* button change */
  245:                 devEvt = kpPdButEvent(evt);
  246: 
  247:                 /* is this a quick press? */
  248:                 qpress = ( (type & IE_MBUT) == IE_MBUTDOWN
  249:                                 && evt->i.pd.stat.o.qpress
  250:                                 && kpMgrInfo.pd.pdMode.attr.qpress );
  251:         }
  252: 
  253:         if ( devEvt != 0 ) {
  254:                 /* notify PD event */
  255:                 kpNotifyPdEvent(devEvt, nodsp = evt->i.pd.stat.o.nodsp);
  256: 
  257:                 if ( qpress ) {
  258:                         /* quickpress */
  259:                         kpMgrInfo.kpState.stat.main = 0;
  260:                         kpNotifyPdEvent(TDE_PDBUT, nodsp);
  261: 
  262:                         kpMgrInfo.kpState.stat.main = 1;
  263:                         kpNotifyPdEvent(TDE_PDBUT, nodsp);
  264:                 }
  265: 
  266:                 /* switch temporary shift or simple lock modes */
  267:                 if ( kpChangeShiftLock(evt->type, NoShift) ) {
  268:                         /* notify meta key status change event */
  269:                         kpNotifyMetaEvent();
  270:                 }
  271:         }
  272: }
  273: 
  274: /*
  275:  * internal event processing
  276:  */
  277: EXPORT void kpInnerEventProcess( InnerEvent *evt, TMO *tmout )
  278: {
  279:         switch ( evt->type ) {
  280:           case IE_NULL:                /* no event */
  281:                 return;
  282: 
  283:           case IE_KEYDOWN:      /* key down */
  284:                 ieKeyDown(evt, tmout);
  285:                 break;
  286:           case IE_KEYUP:       /* key up */
  287:                 ieKeyUp(evt, tmout);
  288:                 break;
  289: 
  290:           case IE_S_PRESS:     /* shift press */
  291:           case IE_S_REL:       /* shift release */
  292:           case IE_S_SCLK:      /* shift single click */
  293:           case IE_S_DCLK:      /* shift double click */
  294:                 ieShift(evt);
  295:                 break;
  296: 
  297:           case IE_KEYERR:      /* key input error */
  298:                 ieKeyErr(evt, tmout);
  299:                 break;
  300: 
  301:           default:             /* PD related */
  302:                 iePd(evt);
  303:         }
  304: }