# HG changeset patch # User Yoshiki Yazawa # Date 1268048297 -32400 # Node ID 688ac5040e7da72db2c35baf8e25b1581a7c0541 # Parent 598fcbe482b597e5fd7c29fd1a75b6b178fcb373 imported patch 20_kinput2-v3.1-canna-keybind2.patch diff -r 598fcbe482b5 -r 688ac5040e7d include/Canna.h --- a/include/Canna.h Mon Mar 08 20:38:17 2010 +0900 +++ b/include/Canna.h Mon Mar 08 20:38:17 2010 +0900 @@ -63,6 +63,10 @@ #define XtCCannafile "Cannafile" #define XtNsendReturnByString "sendReturnByString" #define XtCSendReturnByString "SendReturnByString" +#define XtNkeyBackslashAlwaysShifted "keyBackslashAlwaysShifted" +#define XtCKeyBackslashAlwaysShifted "KeyBackslashAlwaysShifted" +#define XtNconversionEndKeys "conversionEndKeys" +#define XtCConversionEndKeys "ConversionEndKeys" typedef struct _CannaClassRec *CannaObjectClass; typedef struct _CannaRec *CannaObject; diff -r 598fcbe482b5 -r 688ac5040e7d include/CannaP.h --- a/include/CannaP.h Mon Mar 08 20:38:17 2010 +0900 +++ b/include/CannaP.h Mon Mar 08 20:38:17 2010 +0900 @@ -82,12 +82,22 @@ #define CANNA_GLINE_End 2 #define CANNA_GLINE_Change 3 +typedef struct _cKeyList { + KeySym ksym; + long mods; + long chk_mods; + struct _cKeyList *next; +} cKeyList; + typedef struct { /* resources */ String cannahost; String cannafile; Boolean sendReturnByString; + Boolean keyBackslashAlwaysShifted; + String conversion_end_keys; /* private data */ + cKeyList *conv_end_key_list; iBuf *ibuf; Boolean textchanged; /* 変換テキストが変わったか */ Boolean selectionending;/* 選択モードを終了しようとしているか */ diff -r 598fcbe482b5 -r 688ac5040e7d lib/Canna.c --- a/lib/Canna.c Mon Mar 08 20:38:17 2010 +0900 +++ b/lib/Canna.c Mon Mar 08 20:38:17 2010 +0900 @@ -59,6 +59,7 @@ #include #endif #include "CannaP.h" +#include "ParseKey.h" #include "DebugPrint.h" /* Canna 3.7以降はこのように定義する */ @@ -79,6 +80,11 @@ { XtNsendReturnByString, XtCSendReturnByString, XtRBoolean, sizeof(Boolean), offset(sendReturnByString), XtRBoolean, False }, + { XtNkeyBackslashAlwaysShifted, XtCKeyBackslashAlwaysShifted, + XtRBoolean, sizeof(Boolean), + offset(keyBackslashAlwaysShifted), XtRBoolean, False }, + { XtNconversionEndKeys, XtCConversionEndKeys, XtRString, sizeof(String), + offset(conversion_end_keys), XtRImmediate, NULL } #undef offset }; @@ -211,16 +217,23 @@ static int XKanaLookup(event_struct, buffer_return, bytes_buffer, - keysym, status_return) + keysym, status_return, bs_flag) XKeyEvent *event_struct; char *buffer_return; int bytes_buffer; KeySym *keysym; XComposeStatus *status_return; +int bs_flag; { int res; res = XLookupString(event_struct, buffer_return, bytes_buffer, keysym, status_return); + if ( res == 1 && bs_flag ) { + /* かな入力で「ー」が入力できるように */ + if ( *keysym == XK_backslash && event_struct->keycode == 123 ) { + buffer_return[0] = '_'; + } + } if (!res && XK_overline <= *keysym && *keysym <= XK_semivoicedsound) { buffer_return[0] = (unsigned long)(*keysym) & 0xff; res = 1; @@ -248,11 +261,22 @@ /* 取りあえず文字に直してしまう */ kanabuf[0] = '\0'; - nbytes = XKanaLookup(event, kanabuf, 20, &ks, &compose_status); + nbytes = XKanaLookup(event, kanabuf, 20, &ks, &compose_status, + obj->canna.keyBackslashAlwaysShifted); buf[0] = (wchar)kanabuf[0]; /* きたない */ - if (ks == XK_space && (event->xkey.state & ShiftMask)) { + if ( obj->canna.conv_end_key_list != NULL ) { + cKeyList *listelem; + for ( listelem=obj->canna.conv_end_key_list; listelem!=NULL; listelem=listelem->next ) { + if (ks == listelem->ksym && event->xkey.state == listelem->mods) { + void convend(); + + convend(obj); + return 0; + } + } + } else if (ks == XK_space && (event->xkey.state & ShiftMask)) { void convend(); convend(obj); @@ -621,6 +645,44 @@ obj->canna.candlistsize = 0; obj->canna.numcand = 0; obj->canna.lastTextLengthIsZero = False; + obj->canna.conv_end_key_list = NULL; + + if ( obj->canna.conversion_end_keys != NULL ) { + char *p = obj->canna.conversion_end_keys; + char *buf = NULL; + size_t buf_size = 0; + cKeyList *prev_key_listelem = NULL, *new_key_listelem; + + while ( *p != '\0' ) { + KeySym ksym; + long mods, chk_mods; + unsigned int comp_len; + + comp_len = strcspn( p, "\n" ) + 1; + if ( buf_size < comp_len ) { + buf = XtRealloc( buf, comp_len * sizeof(char) ); + buf_size = comp_len; + } + memcpy( buf, p, comp_len ); + buf[comp_len - 1] = '\0'; + + if ( ParseKeyEvent( buf, &ksym, &mods, &chk_mods ) ) { + new_key_listelem = (cKeyList *)XtMalloc( sizeof(cKeyList) ); + new_key_listelem->ksym = ksym; + new_key_listelem->mods = mods; + new_key_listelem->chk_mods = chk_mods; + new_key_listelem->next = NULL; + if ( prev_key_listelem == NULL ) { + obj->canna.conv_end_key_list = new_key_listelem; + } else { + prev_key_listelem->next = new_key_listelem; + } + prev_key_listelem = new_key_listelem; + } + p += comp_len; + } + if ( buf != NULL ) XtFree( (char *)buf ); + } ibufInitialize(obj); @@ -717,6 +779,14 @@ int i; /* バッファの解放 */ + if ( obj->canna.conv_end_key_list != NULL ) { + cKeyList *listelem = obj->canna.conv_end_key_list; + while ( listelem != NULL) { + cKeyList *next_elem = listelem->next; + XtFree( (char*)listelem ); + listelem = next_elem; + } + } freeIBuf(obj->canna.ibuf);