[uim-commit] r747 - in branches/composer: scm test
yamaken at freedesktop.org
yamaken at freedesktop.org
Thu Mar 3 23:03:40 PST 2005
Author: yamaken
Date: 2005-03-03 23:03:37 -0800 (Thu, 03 Mar 2005)
New Revision: 747
Modified:
branches/composer/scm/anthy.scm
branches/composer/scm/evmap.scm
branches/composer/scm/im-custom.scm
branches/composer/scm/japanese-nicola.scm
branches/composer/scm/legacy-api-bridge.scm
branches/composer/scm/ng-key.scm
branches/composer/scm/physical-key.scm
branches/composer/test/test-evmap.scm
Log:
* This commit adds generic and user configurable key-event translator
feature
* scm/japanese-nicola.scm
- (ja-nicola-jp106-pseudo-thumb-shift-ruleset): Comment out
temporarily
* scm/evmap.scm
- (evmap-context-action-seq): New procedure
- (qwerty-shift->space-ruleset,
jp106-henkan-muhenkan->shift-ruleset,
key-event-translator-ruleset, key-event-translator-ruletree): New
variable
- (ja-nicola-jp106-pseudo-thumb-shift-ruleset): Moved from
japanese-nicola.scm and modified to fit to the
key-event-translator as temporary workaround
- (key-event-translator-new, key-event-inspect,
key-event-translator-translate!): New procedure
* test/test-evmap.scm
- (testcase key-event translator): New testcase
- (test key-event-translator-translate!): New test
* scm/ng-key.scm
- (lkey->pkey): New procedure. This dummy implementation is replaced
with actual one when physical-key.scm loaded on demand
* scm/physical-key.scm
- Add require-custom im-custom.scm for keyboard settings
- (lkey-jp106-dvorak->pkey-jp106-alist): New variable
- (lkey->pkey-alist, lkey->pkey): New procedure
* scm/legacy-api-bridge.scm
- (legacy-key->key-event): Replace hardcoded
lkey-jp106-qwerty->pkey-jp106 translation with generic and user
configurable lkey->pkey
* scm/anthy.scm
- (anthy-context-rec-spec): Add new member 'keytrans-emc' as
evmap-context for key-event translator
- (anthy-context-new): Add initialization of keytrans-emc
- (anthy-key-handler):
* Add generic key-event translation process. The temporary
workaround for NICOLA input has been replaced with it.
* anthy-debug? has been obsoleted by inspect-key-event-translation?
* scm/im-custom.scm
- (custom-group keyboard, custom-group keyboard-env, custom-group
keyboard-translation): New custom group
- (custom system-physical-keyboard-type, custom
system-logical-key-mapping jp106-qwerty, custom
enable-jp106-henkan-muhenkan-shift?, custom
enable-ja-nicola-jp106-pseudo-thumb-shift?, custom
enable-qwerty-shift->space?, custom
inspect-key-event-translation?): New custom variable
Modified: branches/composer/scm/anthy.scm
===================================================================
--- branches/composer/scm/anthy.scm 2005-03-04 03:33:32 UTC (rev 746)
+++ branches/composer/scm/anthy.scm 2005-03-04 07:03:37 UTC (rev 747)
@@ -352,7 +352,8 @@
(list 'wide-latin #f)
(list 'kana-mode anthy-type-hiragana)
(list 'input-rule anthy-input-rule-roma)
- (list 'ruletree #f))))
+ (list 'ruletree #f)
+ (list 'keytrans-emc #f)))) ;; evmap-context for key-event translator
(define-record 'anthy-context anthy-context-rec-spec)
(define anthy-context-new-internal anthy-context-new)
@@ -366,6 +367,7 @@
(anthy-context-set-widgets! ac anthy-widgets)
(anthy-context-set-preconv-ustr! ac (ustr-new))
(anthy-context-set-segments! ac (ustr-new))
+ (anthy-context-set-keytrans-emc! ac (key-event-translator-new))
;; 2004-08-26 Takuro Ashie <ashie at homa.ne.jp>
;; * I think load-kana-table should be marked as depracated.
@@ -925,28 +927,10 @@
(define anthy-key-handler
(lambda (ac key key-state press?)
(let ((ev (legacy-key->key-event key key-state press?))
- (debug? (and (symbol-bound? 'anthy-debug?)
- anthy-debug?)))
-
- (if debug?
- (begin
- (puts "key-event: ")
- (puts (key-event-inspect ev))))
-
- ;; temporary workaround for NICOLA input
- ;; TODO: replace with ja-nicola-jp106-pseudo-thumb-shift-ruleset
- (if (eq? (key-event-lkey ev)
- 'lkey_Henkan)
- (key-event-set-lkey! ev 'lkey_Thumb_Shift_R))
- (if (eq? (key-event-lkey ev)
- 'lkey_Muhenkan)
- (key-event-set-lkey! ev 'lkey_Thumb_Shift_L))
-
- (if debug?
- (begin
- (puts "translated: ")
- (puts (key-event-inspect ev))))
-
+ (keytrans-emc (anthy-context-keytrans-emc ac)))
+ (key-event-inspect "key-event: " ev)
+ (key-event-translator-translate! keytrans-emc ev)
+ (key-event-inspect "translated: " ev)
(if (anthy-context-on ac)
(if (anthy-context-converting ac)
(anthy-proc-converting-state ac ev key key-state)
Modified: branches/composer/scm/evmap.scm
===================================================================
--- branches/composer/scm/evmap.scm 2005-03-04 03:33:32 UTC (rev 746)
+++ branches/composer/scm/evmap.scm 2005-03-04 07:03:37 UTC (rev 747)
@@ -98,6 +98,8 @@
(assq-cdr sym event-exp-directive-alist))))
;; #f means "don't care"
+;; TODO: replace default value of modifier with #f to allow
+;; overwriting by mod_None
(define-record 'event-exp-collector
(list
(list 'str #f) ;; precomposed string
@@ -754,6 +756,15 @@
(filter-map key-event-extract-press-str
(evmap-context-event-seq emc))))
+;; TODO: write test
+(define evmap-context-action-seq
+ (lambda (emc)
+ (let* ((tree (evmap-context-current-tree emc))
+ (ev (and tree
+ (evmap-tree-event tree))))
+ (and tree
+ (evmap-tree-action-seq tree)))))
+
;; returns string list
;; can be used as rk-peek-terminal-match
(define evmap-context-composed-string
@@ -828,9 +839,11 @@
(undo seq))))))
;;
-;; fundamental rulesets
+;; key-event translator
;;
+;; should be moved into appropriate file
+
(define combinational-shift-ruleset
'((((char-alphabet press) (char-alphabet press))
((($1 char-upcase mod_shift loopback)) (($2 loopback))))))
@@ -848,3 +861,73 @@
(define shift-lock-ruleset
'(((lkey_Shift_L lkey_Shift_L) (action_toggle_shift_lock))
((lkey_Shift_R lkey_Shift_R) (action_toggle_shift_lock))))
+
+;; for functional test and demonstration
+(define qwerty-shift->space-ruleset
+ '((((lkey_Shift press)) (($1 " " lkey_space mod_None)))
+ (((lkey_Shift release)) (($1 " " lkey_space mod_None)))))
+
+(define jp106-henkan-muhenkan->shift-ruleset
+ '((((lkey_Henkan press)) (($1 lkey_Shift_R)))
+ (((lkey_Henkan release)) (($1 lkey_Shift_R)))
+ (((lkey_Muhenkan press)) (($1 lkey_Shift_L)))
+ (((lkey_Muhenkan release)) (($1 lkey_Shift_L)))))
+
+;; temporary workaround for dedicated key-event translator
+(define ja-nicola-jp106-pseudo-thumb-shift-ruleset
+ '((((lkey_Henkan press)) (($1 lkey_Thumb_Shift_R)))
+ (((lkey_Henkan release)) (($1 lkey_Thumb_Shift_R)))
+ (((lkey_Muhenkan press)) (($1 lkey_Thumb_Shift_L)))
+ (((lkey_Muhenkan release)) (($1 lkey_Thumb_Shift_L)))))
+
+
+(define key-event-translator-ruleset
+ (append
+ ;;qwerty->dvorak-ruleset
+ ;;combinational-shift-ruleset
+ ;;sticky-shift-ruleset
+ ;;shift-lock-ruleset
+ ;;(if qwerty-enable-pseudo-multi-key?
+ ;; qwerty-enable-pseudo-multi-key-ruleset
+ ;; ())
+ ;;(if qwerty-enable-pseudo-dead-keys?
+ ;; qwerty-enable-pseudo-dead-keys-ruleset
+ ;; ())
+ (if enable-jp106-henkan-muhenkan-shift?
+ jp106-henkan-muhenkan-shift-ruleset
+ ())
+ (if enable-ja-nicola-jp106-pseudo-thumb-shift?
+ ja-nicola-jp106-pseudo-thumb-shift-ruleset
+ ())
+ (if enable-qwerty-shift->space?
+ qwerty-shift->space-ruleset
+ ())
+ ))
+
+(define key-event-translator-ruletree
+ (evmap-parse-ruleset key-event-translator-ruleset))
+
+(define key-event-translator-new
+ (lambda ()
+ (evmap-context-new key-event-translator-ruletree)))
+
+(define key-event-inspect
+ (lambda (msg ev)
+ (if inspect-key-event-translation?
+ (puts (string-append msg
+ (key-event-inspect ev))))))
+
+;; TODO: write test
+(define key-event-translator-translate!
+ (lambda (emc ev)
+ (if (evmap-context-input! emc ev)
+ (begin
+ (event-set-consumed! ev #f)
+ (event-set-loopback! ev #f)))
+ (if (evmap-context-complete? emc)
+ (let ((translated (safe-car (evmap-context-action-seq emc))))
+ (evmap-context-flush! emc)
+ (if (pair? translated)
+ (list-copy! ev translated)
+ ev))
+ ev)))
Modified: branches/composer/scm/im-custom.scm
===================================================================
--- branches/composer/scm/im-custom.scm 2005-03-04 03:33:32 UTC (rev 746)
+++ branches/composer/scm/im-custom.scm 2005-03-04 07:03:37 UTC (rev 747)
@@ -338,6 +338,103 @@
(_ "long description will be here."))
+(define-custom-group 'keyboard
+ (_ "Keyboard settings")
+ (_ "long description will be here."))
+
+;; subgroup
+(define-custom-group 'keyboard-env
+ (_ "System configuration of your keyboard")
+ (_ "long description will be here."))
+
+;; subgroup
+(define-custom-group 'keyboard-translation
+ (_ "Key-input translation for uim input methods")
+ (_ "long description will be here."))
+
+(define-custom 'system-physical-keyboard-type 'jp106
+ '(keyboard keyboard-env)
+ (list 'choice
+ (list 'qwerty
+ (_ "Standard QWERTY")
+ (_ "Standard QWERTY"))
+;; (list 'latin-qwerty
+;; (_ "Latin QWERTY")
+;; (_ "Latin QWERTY which has dead-keys and multi key"))
+ (list 'jp106
+ (_ "Japanese JP106 (QWERTY)")
+ (_ "Japanese JP106 (QWERTY)"))
+;; (list 'jp109
+;; (_ "Japanese JP109 (QWERTY)")
+;; (_ "Japanese JP109 (QWERTY)"))
+;; (list 'kinesis
+;; (_ "KINESIS Contoured (QWERTY)")
+;; (_ "KINESIS Contoured (QWERTY)"))
+ )
+ (_ "Physical keyboard type")
+ (_ "long description will be here."))
+
+(define-custom 'system-logical-key-mapping 'jp106-qwerty
+ '(keyboard keyboard-env)
+ (list 'choice
+ (list 'qwerty
+ (_ "QWERTY")
+ (_ "QWERTY"))
+ (list 'dvorak
+ (_ "Dvorak")
+ (_ "Dvorak"))
+ (list 'jp106-qwerty
+ (_ "QWERTY (JP106)")
+ (_ "QWERTY (JP106"))
+ (list 'jp106-dvorak
+ (_ "Dvorak (JP106)")
+ (_ "Dvorak (JP106")))
+ (_ "Logical key mapping")
+ (_ "long description will be here."))
+
+;;(define-custom 'key-event-basic-translator 'jp106-qwerty
+;; '(keyboard keyboard-env)
+;; (list 'choice
+;; (list 'qwerty
+;; (_ "QWERTY")
+;; (_ "QWERTY"))
+;; (list 'dvorak
+;; (_ "Dvorak")
+;; (_ "Dvorak"))
+;; (list 'jp106-qwerty
+;; (_ "QWERTY (JP106)")
+;; (_ "QWERTY (JP106"))
+;; (list 'jp106-dvorak
+;; (_ "Dvorak (JP106)")
+;; (_ "Dvorak (JP106")))
+;; (_ "Basic key-input translation")
+;; (_ "long description will be here."))
+
+(define-custom 'enable-jp106-henkan-muhenkan-shift? #f
+ '(keyboard keyboard-translation)
+ '(boolean)
+ (_ "Use Henkan and Muhenkan as ordinary shift key")
+ (_ "long description will be here."))
+
+(define-custom 'enable-ja-nicola-jp106-pseudo-thumb-shift? #f
+ '(keyboard keyboard-translation)
+ '(boolean)
+ (_ "Use Henkan and Muhenkan as NICOLA thumb shift keys")
+ (_ "long description will be here."))
+
+(define-custom 'enable-qwerty-shift->space? #f
+ '(keyboard keyboard-translation)
+ '(boolean)
+ (_ "Use shift keys as space key (testing purpose)")
+ (_ "long description will be here."))
+
+(define-custom 'inspect-key-event-translation? #f
+ '(keyboard keyboard-translation)
+ '(boolean)
+ (_ "Inspect key-event translation (for developer, use with LIBUIM_VERBOSE=1)")
+ (_ "long description will be here."))
+
+
;; EB Library support
;; 2005-02-08 Takuro Ashie <ashie at homa.ne.jp>
;; FIXME! Here isn't suitable position for EB support preference
Modified: branches/composer/scm/japanese-nicola.scm
===================================================================
--- branches/composer/scm/japanese-nicola.scm 2005-03-04 03:33:32 UTC (rev 746)
+++ branches/composer/scm/japanese-nicola.scm 2005-03-04 07:03:37 UTC (rev 747)
@@ -238,11 +238,11 @@
("¤Ý" "¥Ý" ("Î" "ß")))
))
-(define ja-nicola-jp106-pseudo-thumb-shift-ruleset
- '((((lkey_Henkan press peek)) (($1 lkey_Thumb_Shift_R loopback)))
- (((lkey_Henkan release peek)) (($1 lkey_Thumb_Shift_R loopback)))
- (((lkey_Muhenkan press peek)) (($1 lkey_Thumb_Shift_L loopback)))
- (((lkey_Muhenkan release peek)) (($1 lkey_Thumb_Shift_L loopback)))))
+;;(define ja-nicola-jp106-pseudo-thumb-shift-ruleset
+;; '((((lkey_Henkan press peek)) (($1 lkey_Thumb_Shift_R loopback)))
+;; (((lkey_Henkan release peek)) (($1 lkey_Thumb_Shift_R loopback)))
+;; (((lkey_Muhenkan press peek)) (($1 lkey_Thumb_Shift_L loopback)))
+;; (((lkey_Muhenkan release peek)) (($1 lkey_Thumb_Shift_L loopback)))))
(define ja-nicola-ruleset-name-list
'(core
Modified: branches/composer/scm/legacy-api-bridge.scm
===================================================================
--- branches/composer/scm/legacy-api-bridge.scm 2005-03-04 03:33:32 UTC (rev 746)
+++ branches/composer/scm/legacy-api-bridge.scm 2005-03-04 07:03:37 UTC (rev 747)
@@ -252,7 +252,6 @@
(lkey (safe-cdr (assoc (or str
key)
legacy-key->lkey-alist)))
- (pkey (and (symbol-bound? 'lkey-jp106-qwerty->pkey-jp106-alist)
- (assq-cdr lkey lkey-jp106-qwerty->pkey-jp106-alist)))
+ (pkey (lkey->pkey lkey))
(modifier (legacy-modifier->modifier state)))
(key-event-new str lkey pkey modifier press?))))
Modified: branches/composer/scm/ng-key.scm
===================================================================
--- branches/composer/scm/ng-key.scm 2005-03-04 03:33:32 UTC (rev 746)
+++ branches/composer/scm/ng-key.scm 2005-03-04 07:03:37 UTC (rev 747)
@@ -385,3 +385,9 @@
(lambda (key)
(and (symbol? key)
(memq key valid-physical-keys))))
+
+;; API
+;; will be replaced with actual one when physical-key.scm loaded
+(define lkey->pkey
+ (lambda (lkey)
+ #f))
Modified: branches/composer/scm/physical-key.scm
===================================================================
--- branches/composer/scm/physical-key.scm 2005-03-04 03:33:32 UTC (rev 746)
+++ branches/composer/scm/physical-key.scm 2005-03-04 07:03:37 UTC (rev 747)
@@ -37,7 +37,9 @@
(require "util.scm")
(require "ng-key.scm")
+(require-custom "im-custom.scm")
+
(define lkey-qwerty->pkey-qwerty-alist
'(
(lkey_BackSpace . pkey_qwerty_BackSpace)
@@ -538,7 +540,109 @@
;;(lkey_dead_horn . pkey_jp106_horn)
))
+(define lkey-jp106-dvorak->pkey-jp106-alist
+ (append
+ '(;; ASCII keys
+ ;(lkey_space . pkey_jp106_space)
+ ;(lkey_exclam . pkey_jp106_1)
+ (lkey_quotedbl . pkey_jp106_q)
+ ;(lkey_numbersign . pkey_jp106_3)
+ ;(lkey_dollar . pkey_jp106_4)
+ ;(lkey_percent . pkey_jp106_5)
+ ;(lkey_ampersand . pkey_jp106_7)
+ (lkey_apostrophe . pkey_jp106_q)
+ ;(lkey_parenleft . pkey_jp106_9)
+ ;(lkey_parenright . pkey_jp106_0)
+ ;(lkey_asterisk . pkey_jp106_8)
+ (lkey_plus . pkey_jp106_bracketright)
+ (lkey_comma . pkey_jp106_w)
+ (lkey_minus . pkey_jp106_apostrophe)
+ (lkey_period . pkey_jp106_e)
+ (lkey_slash . pkey_jp106_bracketleft)
+ ;(lkey_0 . pkey_jp106_0)
+ ;(lkey_1 . pkey_jp106_1)
+ ;(lkey_2 . pkey_jp106_2)
+ ;(lkey_3 . pkey_jp106_3)
+ ;(lkey_4 . pkey_jp106_4)
+ ;(lkey_5 . pkey_jp106_5)
+ ;(lkey_6 . pkey_jp106_6)
+ ;(lkey_7 . pkey_jp106_7)
+ ;(lkey_8 . pkey_jp106_8)
+ ;(lkey_9 . pkey_jp106_9)
+ (lkey_colon . pkey_jp106_z)
+ (lkey_semicolon . pkey_jp106_z)
+ (lkey_less . pkey_jp106_w)
+ (lkey_equal . pkey_jp106_bracketright)
+ (lkey_greater . pkey_jp106_e)
+ (lkey_question . pkey_jp106_bracketleft)
+ ;(lkey_at . pkey_jp106_2)
+ (lkey_A . pkey_jp106_a)
+ (lkey_B . pkey_jp106_n)
+ (lkey_C . pkey_jp106_i)
+ (lkey_D . pkey_jp106_h)
+ (lkey_E . pkey_jp106_d)
+ (lkey_F . pkey_jp106_y)
+ (lkey_G . pkey_jp106_u)
+ (lkey_H . pkey_jp106_j)
+ (lkey_I . pkey_jp106_g)
+ (lkey_J . pkey_jp106_c)
+ (lkey_K . pkey_jp106_v)
+ (lkey_L . pkey_jp106_p)
+ (lkey_M . pkey_jp106_m)
+ (lkey_N . pkey_jp106_l)
+ (lkey_O . pkey_jp106_s)
+ (lkey_P . pkey_jp106_r)
+ (lkey_Q . pkey_jp106_x)
+ (lkey_R . pkey_jp106_o)
+ (lkey_S . pkey_jp106_semicolon)
+ (lkey_T . pkey_jp106_k)
+ (lkey_U . pkey_jp106_f)
+ (lkey_V . pkey_jp106_period)
+ (lkey_W . pkey_jp106_comma)
+ (lkey_X . pkey_jp106_b)
+ (lkey_Y . pkey_jp106_t)
+ (lkey_Z . pkey_jp106_slash)
+ (lkey_bracketleft . pkey_jp106_minus)
+ ;;(lkey_backslash . pkey_jp106_backslash)
+ (lkey_bracketright . pkey_jp106_asciicircum)
+ ;;(lkey_asciicircum . pkey_jp106_6)
+ (lkey_underscore . pkey_jp106_colon)
+ ;;(lkey_grave . pkey_jp106_grave)
+ (lkey_a . pkey_jp106_a)
+ (lkey_b . pkey_jp106_n)
+ (lkey_c . pkey_jp106_i)
+ (lkey_d . pkey_jp106_h)
+ (lkey_e . pkey_jp106_d)
+ (lkey_f . pkey_jp106_y)
+ (lkey_g . pkey_jp106_u)
+ (lkey_h . pkey_jp106_j)
+ (lkey_i . pkey_jp106_g)
+ (lkey_j . pkey_jp106_c)
+ (lkey_k . pkey_jp106_v)
+ (lkey_l . pkey_jp106_p)
+ (lkey_m . pkey_jp106_m)
+ (lkey_n . pkey_jp106_l)
+ (lkey_o . pkey_jp106_s)
+ (lkey_p . pkey_jp106_r)
+ (lkey_q . pkey_jp106_x)
+ (lkey_r . pkey_jp106_o)
+ (lkey_s . pkey_jp106_semicolon)
+ (lkey_t . pkey_jp106_k)
+ (lkey_u . pkey_jp106_f)
+ (lkey_v . pkey_jp106_period)
+ (lkey_w . pkey_jp106_comma)
+ (lkey_x . pkey_jp106_b)
+ (lkey_y . pkey_jp106_t)
+ (lkey_z . pkey_jp106_slash)
+ (lkey_braceleft . pkey_jp106_minus)
+ ;;(lkey_bar . pkey_jp106_backslash)
+ (lkey_braceright . pkey_jp106_asciicircum)
+ ;;(lkey_asciitilde . pkey_jp106_grave)
+ )
+ lkey-jp106-qwerty->pkey-jp106-alist
+ ))
+
;; register physical key symbols to valid-physical-keys
(for-each (lambda (alist)
(for-each (lambda (entry)
@@ -550,3 +654,20 @@
(list lkey-qwerty->pkey-qwerty-alist
lkey-extended-qwerty->pkey-qwerty-alist
lkey-jp106-qwerty->pkey-jp106-alist))
+
+;; FIXME: bad procedure name
+(define lkey->pkey-alist
+ (lambda ()
+ (let ((alist-sym (symbolconc 'lkey-
+ system-logical-key-mapping
+ '->pkey-
+ system-physical-keyboard-type
+ '-alist)))
+ (or (and (symbol-bound? alist-sym)
+ (symbol-value alist-sym))
+ ()))))
+
+(define lkey->pkey
+ (lambda (lkey)
+ (let ((alist (lkey->pkey-alist)))
+ (assq-cdr lkey alist))))
Modified: branches/composer/test/test-evmap.scm
===================================================================
--- branches/composer/test/test-evmap.scm 2005-03-04 03:33:32 UTC (rev 746)
+++ branches/composer/test/test-evmap.scm 2005-03-04 07:03:37 UTC (rev 747)
@@ -3032,3 +3032,25 @@
(assert-equal '("KA")
(uim '(evmap-context-preedit-string test-emc))))
)
+
+(define-uim-test-case "testcase key-event translator"
+ (setup
+ (lambda ()
+ (uim '(begin
+ (define enable-ja-nicola-jp106-pseudo-thumb-shift? #t)
+ (require "evmap.scm")
+ (define key-event-translator-ruletree
+ (evmap-parse-ruleset key-event-translator-ruleset))
+ (define test-ruletree (evmap-parse-ruleset
+ ja-nicola-jp106-pseudo-thumb-shift-ruleset))))))
+
+ ("test key-event-translator-translate!"
+ (uim '(define test-emc (key-event-translator-new)))
+ (assert-equal (uim '(list 'key #f #f -1 #f 'lkey_Thumb_Shift_R #f
+ mod_None #t #f))
+ (uim '(key-event-translator-translate!
+ test-emc
+ (key-event-new #f 'lkey_Henkan))))
+ )
+)
+
More information about the Uim-commit
mailing list