/usr/share/uim/im.scm is in uim-data 1:1.8.6+gh20180114.64e3173-2build2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 | ;;; im.scm: Core IM management functions for uim
;;;
;;; Copyright (c) 2003-2013 uim Project https://github.com/uim/uim
;;;
;;; All rights reserved.
;;;
;;; Redistribution and use in source and binary forms, with or without
;;; modification, are permitted provided that the following conditions
;;; are met:
;;; 1. Redistributions of source code must retain the above copyright
;;; notice, this list of conditions and the following disclaimer.
;;; 2. Redistributions in binary form must reproduce the above copyright
;;; notice, this list of conditions and the following disclaimer in the
;;; documentation and/or other materials provided with the distribution.
;;; 3. Neither the name of authors nor the names of its contributors
;;; may be used to endorse or promote products derived from this software
;;; without specific prior written permission.
;;;
;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
;;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
;;; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
;;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
;;; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
;;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
;;; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
;;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
;;; SUCH DAMAGE.
;;;;
(require-extension (srfi 2 6 23 34))
; Comment should be written in English, UTF-8.
;
(require "util.scm")
(require "i18n.scm")
(require "load-action.scm")
(require "annotation.scm")
;; config
(define default-im-name #f)
;; preedit attributes: should be moved to another file
(define preedit-none 0)
(define preedit-underline 1)
(define preedit-reverse 2)
(define preedit-cursor 4)
(define preedit-separator 8)
(define preedit-attr?
(lambda (attr)
(memv attr (list preedit-none
preedit-underline
preedit-reverse
preedit-cursor
preedit-separator))))
(define text-area-id-alist
'((primary . 1)
(selection . 2)
(clipboard . 4)))
(define text-origin-alist
'((cursor . 1)
(beginning . 2)
(end . 3)))
(define text-extent-alist
'((full . -2)
(paragraph . -3)
(sentence . -5)
(word . -9)
(char-frags . -17)
(disp-rect . -33)
(disp-line . -65)
(line . -129)))
;;
;; im-management
;;
(define im-list ())
(define installed-im-list ())
(define enabled-im-list ())
(define-record 'im
(list
(list 'name #f) ;; must be first member
(list 'lang "")
(list 'encoding "")
(list 'name-label "") ;; under discussion
(list 'short-desc "")
(list 'init-arg #f)
(list 'init-handler list)
(list 'release-handler list)
(list 'mode-handler list)
(list 'key-press-handler list)
(list 'key-release-handler list)
(list 'reset-handler list)
(list 'get-candidate-handler list)
(list 'set-candidate-index-handler list)
(list 'prop-activate-handler list)
(list 'input-string-handler list)
(list 'focus-in-handler list)
(list 'focus-out-handler list)
(list 'place-handler list)
(list 'displace-handler list)
(list 'module-name "")
(list 'delay-activating-handler #f)))
(define im-custom-set-handler
(lambda (im)
(if (symbol-bound? 'custom-prop-update-custom-handler)
custom-prop-update-custom-handler
list)))
(define normalize-im-list
(lambda ()
(let ((ordinary-im-list (alist-delete 'direct im-list eq?))
(direct-im (retrieve-im 'direct)))
(if direct-im
(set! im-list (cons direct-im
ordinary-im-list))))))
;; TODO: rewrite test
;; accepts overwrite register
;; returns whether initial register or not
(define register-im
(lambda (name lang encoding name-label short-desc init-arg init release
mode key-press key-release reset
get-candidate set-candidate-index prop input-string
focus-in focus-out place displace)
;; Rejects symbols that cannot be valid external representation such
;; as "3foo", "#foo", ...
(if (guard (err (else #t))
(not (eq? name
(read (open-input-string (symbol->string name))))))
(begin
(if (symbol-bound? 'uim-notify-fatal)
(uim-notify-fatal (N_ "invalid IM name")))
(error "invalid IM name")))
(and (or (null? enabled-im-list) ;; bootstrap
(memq name enabled-im-list)
(eq? name 'direct)) ;; direct IM must always be enabled
(let ((im (im-new name lang encoding name-label short-desc
init-arg init release
mode key-press key-release reset
get-candidate set-candidate-index prop
input-string focus-in focus-out place displace
currently-loading-module-name))
(initial-registration? (not (assq name im-list))))
(set! im-list (alist-replace im im-list))
(normalize-im-list)
initial-registration?))))
;; strictly find out im by name
(define retrieve-im
(lambda (name)
(and name
(let ((im (assq name im-list)))
im))))
(define default-im-for-debug
(lambda ()
(and (provided? "debug")
(let* ((str (getenv "UIM_IM_ENGINE"))
(sym (and str
(string->symbol str))))
(retrieve-im sym)))))
(define find-im-for-locale
(lambda (localestr)
(let* ((lang (locale-zh-awared-lang (locale-new localestr)))
(ims-for-lang (filter (lambda (im)
(langgroup-covers? (im-lang im)
lang))
im-list))
(preference-ordered (and (not (null? ims-for-lang))
(reverse ims-for-lang))))
(and (not (null? preference-ordered))
(car preference-ordered)))))
(define find-default-im
(lambda (localestr)
(or (default-im-for-debug)
(retrieve-im default-im-name)
(find-im-for-locale localestr))))
;; find most suitable im by im-name and lang
(define find-im
(lambda (name localestr)
(or (retrieve-im name)
(find-default-im localestr))))
(define uim-filter-convertible-ims
(lambda (uc)
(filter (lambda (im)
(im-convertible? uc (im-encoding im)))
im-list)))
(define uim-n-convertible-ims
(lambda (uc)
(length (uim-filter-convertible-ims uc))))
(define uim-nth-convertible-im
(lambda (uc n)
(guard (err
(else #f))
(list-ref (uim-filter-convertible-ims uc) n))))
;; called from uim_get_default_im_name()
(define uim-get-default-im-name
(lambda (localestr)
(let ((name (im-name (find-default-im localestr))))
(symbol->string name))))
;; called from uim_get_im_name_for_locale()
(define uim-get-im-name-for-locale
(lambda (localestr)
(let ((name (im-name (find-im-for-locale localestr))))
(symbol->string name))))
;;
;; im-switching
;;
;; for C
(define uim-switch-im
(lambda (uc name)
(reset-handler uc)
;; Don't use remove-context. old and new context must (eq? old new)
(invoke-handler im-release-handler uc)
(let ((cur-context (im-retrieve-context uc))
(new-context (create-context uc #f name)))
(remove-context new-context)
(set-cdr! cur-context (cdr new-context))
(setup-context cur-context))))
;; for Scheme
(define im-switch-im
(lambda (c name)
(let ((uc (if (pair? c)
(context-uc c)
c)))
(uim-switch-im uc name)
(im-raise-configuration-change uc))))
(define next-im
(lambda (name)
(let* ((im-names enabled-im-list)
(im-rest (memq name im-names)))
(or (and im-rest
(pair? (cdr im-rest))
(cadr im-rest))
(car im-names)))))
(define next-im-for-switch-im
(lambda (name)
(let ((im (next-im name)))
(or
(and
switch-im-skip-direct-im?
(eq? im 'direct)
(next-im im))
im))))
;; 'switch-im' is not a API but an IM-switching method. Don't confuse with
;; im-switch-im
(define switch-im
(lambda (uc name)
(im-switch-im uc (next-im-for-switch-im name))))
;; FIXME: Input states are kept only if the state is appeared in the
;; toolbar.
(define toggle-im
(lambda (uc c)
(let* ((cur-state (toggle-state-new (context-primary-im? c)
(im-name (context-im c))
(context-current-widget-states c)))
(saved-state (context-toggle-state c)))
(im-switch-im uc (if saved-state
(toggle-state-im-name saved-state)
toggle-im-alt-im))
;; retrieve new context replaced by im-switch-im
(let ((c (im-retrieve-context uc)))
(if saved-state
(let ((orig-wstates (toggle-state-widget-states saved-state)))
(context-update-widget-states! c orig-wstates)))
(context-set-toggle-state! c cur-state)))))
(define reset-toggled-im
(lambda (uc c)
(let ((saved-state (context-toggle-state c)))
(im-switch-im uc (if saved-state
(toggle-state-im-name saved-state)
default-im-name)))))
(define reset-toggle-context!
(lambda (uc ctx)
(if (not (context-primary-im? ctx))
(reset-toggled-im uc ctx))
;; ctx may be expired by the toggle-im
(context-set-toggle-state! (im-retrieve-context uc) #f)))
;;
;; context-management
;;
(define context-list ())
(define context-rec-spec
'((uc #f) ;; Scheme-wrapped uim_context. must be first member
(im #f)
(widgets ()) ;; may be renamed
(toggle-state #f)
(key-passthrough #f)))
(define-record 'context context-rec-spec)
;; backward compatibility: should be replaced with context-uc and
;; context-set-uc!
(define context-id context-uc)
(define context-set-id! context-set-uc!)
(define toggle-state-rec-spec
'((primary? #f)
(im-name #f)
(widget-states ())))
(define-record 'toggle-state toggle-state-rec-spec)
(define context-primary-im?
(lambda (c)
(let ((toggle-state (context-toggle-state c)))
(or (not toggle-state)
(not (toggle-state-primary? toggle-state))))))
(define context-primary-im-name
(lambda (c)
(if (context-primary-im? c)
(im-name (context-im c))
(toggle-state-im-name (context-toggle-state c)))))
;; FIXME: implement
(define context-focused?
(lambda (c)
#t))
(define remove-context
(lambda (c)
(set! context-list
(delete c context-list eq?))))
(define register-context
(lambda (c)
(set! context-list
(cons c context-list))))
(define create-context
(lambda (uc lang name)
(let* ((im (find-im name lang))
(arg (and im (im-init-arg im))))
(im-set-encoding uc (im-encoding im))
(let* ((handler (im-init-handler im))
(c (handler uc im arg)))
(register-context c)
;; im-* procedures that require uc->sc must not called here since it
;; is not filled yet. Place such procedures to setup-context.
c))))
;; post create-context setup
(define setup-context
(lambda (c)
(let ((widget-ids (context-widgets c)))
(update-style uim-color-spec (symbol-value uim-color))
(context-init-widgets! c widget-ids))))
(define release-context
(lambda (uc)
(invoke-handler im-release-handler uc)
(remove-context (im-retrieve-context uc))
#f))
(define uim-context-im
(lambda (uc)
(let ((c (im-retrieve-context uc)))
(and c
(context-im c)))))
(define uim-context-encoding
(lambda (uc)
(and-let* ((im (uim-context-im uc)))
(im-encoding im))))
(define context-update-preedit
(lambda (context segments)
(im-clear-preedit context)
(for-each (lambda (segment)
(if segment
(let ((attr (car segment))
(str (cdr segment)))
(im-pushback-preedit context attr str))))
segments)
(im-update-preedit context)))
;; Backward compatibility. The term 'commit' is incorrect. No commit
;; operation is performed by this. This actually instructs 'pass-through' the
;; input key. The key filtering interface will be replaced with 'filtered'
;; boolean value returned by key-*-handler of each IM in some future. Current
;; semantics is not an ordinary design for IM and felt unnatural.
;; -- YamaKen 2007-01-10
(define im-commit-raw
(lambda (c)
(context-set-key-passthrough! (if (pair? c)
c
(im-retrieve-context c))
#t)))
;; Deprecated
(define im-get-raw-key-str
(lambda (key state)
(and (integer? key)
(<= key 255)
(integer? state)
(cond
((= state 0)
(charcode->string key))
((= state (assq-cdr 'Shift_key key-state-alist))
(charcode->string (ichar-upcase key)))
(else
#f)))))
;;
;; dispatchers
;;
(define invoke-handler
(lambda args
(let* ((handler-reader (car args))
(uc (cadr args))
(c (im-retrieve-context uc))
(handler-args (cons c (cddr args)))
(im (and c (context-im c)))
(handler (and im (handler-reader im)))
(result (and handler
(apply handler handler-args))))
(context-update-widgets c)
result)))
;; Returns #t if input is filtered.
;; Don't discard unnecessary key events. They are necessary for
;; proper GUI widget handling. More correction over entire uim
;; codes is needed.
(define key-press-handler
(lambda (uc key state)
(let* ((c (im-retrieve-context uc))
(im (and c (context-im c))))
(context-set-key-passthrough! c #f)
(cond
((and enable-im-toggle?
(toggle-im-key? key state))
(toggle-im uc c))
((and enable-im-switch?
(switch-im-key? key state))
(switch-im uc (im-name im)))
((modifier-key? key state)
;; don't discard modifier press/release edge for apps
(im-commit-raw c))
(else
(invoke-handler im-key-press-handler uc key state)))
(not (context-key-passthrough c)))))
;; Returns #t if input is filtered.
(define key-release-handler
(lambda (uc key state)
(let ((c (im-retrieve-context uc)))
(context-set-key-passthrough! c #f)
(cond
((modifier-key? key state)
;; don't discard modifier press/release edge for apps
(im-commit-raw c))
(else
(invoke-handler im-key-release-handler uc key state)))
(not (context-key-passthrough c)))))
(define reset-handler
(lambda (uc)
(invoke-handler im-reset-handler uc)))
(define focus-in-handler
(lambda (uc)
(invoke-handler im-focus-in-handler uc)))
(define focus-out-handler
(lambda (uc)
(invoke-handler im-focus-out-handler uc)))
(define place-handler
(lambda (uc)
(invoke-handler im-place-handler uc)))
(define displace-handler
(lambda (uc)
(invoke-handler im-displace-handler uc)))
(define mode-handler
(lambda (uc mode)
(invoke-handler im-mode-handler uc mode)))
(define prop-activate-handler
(lambda (uc message)
(invoke-handler im-prop-activate-handler uc message)))
(define input-string-handler
(lambda (uc str)
(invoke-handler im-input-string-handler uc str)))
(define custom-set-handler
(lambda (uc custom-sym custom-val)
(invoke-handler im-custom-set-handler uc custom-sym custom-val)))
(define get-candidate
(lambda (uc idx accel-enum-hint)
(let ((c (invoke-handler im-get-candidate-handler uc idx accel-enum-hint)))
(if (and (not enable-annotation?)
(not (string=? (last c) "")))
(set-cdr! (cdr c) (list ""))
(and (string=? (last c) "")
(set-cdr! (cdr c) (list (annotation-get-text (car c) (uim-context-encoding uc))))))
c)))
(define set-candidate-index
(lambda (uc idx)
(invoke-handler im-set-candidate-index-handler uc idx)))
(define delay-activating-handler
(lambda (uc)
(invoke-handler im-delay-activating-handler uc)))
(define im-acquire-text
(lambda (c id origin former-len latter-len)
(let ((text-id (cdr (assq id text-area-id-alist)))
(text-origin (cdr (assq origin text-origin-alist)))
(text-extent-former (if (symbol? former-len)
(cdr (assq former-len text-extent-alist))
former-len))
(text-extent-latter (if (symbol? latter-len)
(cdr (assq latter-len text-extent-alist))
latter-len)))
(im-acquire-text-internal
c text-id text-origin text-extent-former text-extent-latter))))
(define im-delete-text
(lambda (c id origin former-len latter-len)
(let ((text-id (cdr (assq id text-area-id-alist)))
(text-origin (cdr (assq origin text-origin-alist)))
(text-extent-former (if (symbol? former-len)
(cdr (assq former-len text-extent-alist))
former-len))
(text-extent-latter (if (symbol? latter-len)
(cdr (assq latter-len text-extent-alist))
latter-len)))
(im-delete-text-internal
c text-id text-origin text-extent-former text-extent-latter))))
|