PageRenderTime 50ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/clx/mit-clx/debug/keytrans.lisp

https://github.com/ynd/clisp-branch--ynd-devel
Lisp | 266 lines | 215 code | 19 blank | 32 comment | 0 complexity | d36684360df979cd61602c541a68a564 MD5 | raw file
Possible License(s): LGPL-2.0, GPL-2.0, BSD-3-Clause
  1. ;;; -*- Mode:Lisp; Package:XLIB; Syntax:COMMON-LISP; Base:10; Lowercase:T -*-
  2. ;;; CLX keysym-translation test programs
  3. ;;;
  4. ;;; TEXAS INSTRUMENTS INCORPORATED
  5. ;;; P.O. BOX 2909
  6. ;;; AUSTIN, TEXAS 78769
  7. ;;;
  8. ;;; Copyright (C) 1987 Texas Instruments Incorporated.
  9. ;;;
  10. ;;; Permission is granted to any individual or institution to use, copy, modify,
  11. ;;; and distribute this software, provided that this complete copyright and
  12. ;;; permission notice is maintained, intact, in all copies and supporting
  13. ;;; documentation.
  14. ;;;
  15. ;;; Texas Instruments Incorporated provides this software "as is" without
  16. ;;; express or implied warranty.
  17. ;;;
  18. (in-package :xlib)
  19. (defun list-missing-keysyms ()
  20. ;; Lists explorer characters which have no keysyms
  21. (dotimes (i 256)
  22. (unless (character->keysyms (int-char i))
  23. (format t "~%(define-keysym ~@c ~d)" (int-char i) i))))
  24. (defun list-multiple-keysyms ()
  25. ;; Lists characters with more than one keysym
  26. (dotimes (i 256)
  27. (when (cdr (character->keysyms (int-char i)))
  28. (format t "~%Character ~@c [~d] has keysyms" (int-char i) i)
  29. (dolist (keysym (character->keysyms (int-char i)))
  30. (format t " ~d ~d" (ldb (byte 8 8) keysym) (ldb (byte 8 0) keysym))))))
  31. (defun check-lowercase-keysyms ()
  32. ;; Checks for keysyms with incorrect :lowercase parameters
  33. (maphash #'(lambda (key mapping)
  34. (let* ((value (car mapping))
  35. (char (keysym-mapping-object value)))
  36. (if (and (characterp char) (both-case-p char)
  37. (= (char-int char) (char-int (char-upcase char))))
  38. ;; uppercase alphabetic character
  39. (unless (eq (keysym-mapping-lowercase value)
  40. (char-int (char-downcase char)))
  41. (let ((lowercase (keysym-mapping-lowercase value))
  42. (should-be (char-downcase char)))
  43. (format t "~%Error keysym ~3d ~3d (~@c) has :Lowercase ~3d ~3d (~s) Should be ~3d ~3d (~@c)"
  44. (ldb (byte 8 8) key)
  45. (ldb (byte 8 0) key)
  46. char
  47. (and lowercase (ldb (byte 8 8) lowercase))
  48. (and lowercase (ldb (byte 8 0) lowercase))
  49. (int-char lowercase)
  50. (ldb (byte 8 8) (char-int should-be))
  51. (ldb (byte 8 0) (char-int should-be))
  52. should-be)))
  53. (when (keysym-mapping-lowercase value)
  54. (let ((lowercase (keysym-mapping-lowercase value)))
  55. (format t "~%Error keysym ~3d ~3d (~@c) has :lowercase ~3d ~3d (~@c) and shouldn't"
  56. (ldb (byte 8 8) key)
  57. (ldb (byte 8 0) key)
  58. char
  59. (and lowercase (ldb (byte 8 8) (char-int lowercase)))
  60. (and lowercase (ldb (byte 8 0) (char-int lowercase)))
  61. lowercase
  62. ))))))
  63. *keysym->character-map*))
  64. (defun print-all-keysyms ()
  65. (let ((all nil))
  66. (maphash #'(lambda (key value) (push (cons key value) all)) *keysym->character-map*)
  67. (setq all (sort all #'< :key #'car))
  68. (format t "~%~d keysyms:" (length all))
  69. (dolist (keysym all)
  70. (format t "~%~3d ~3d~{ ~s~}"
  71. (ldb (byte 8 8) (car keysym))
  72. (ldb (byte 8 0) (car keysym))
  73. (cadr keysym))
  74. (dolist (mapping (cddr keysym))
  75. (format t "~%~7@t~{ ~s~}" mapping)))))
  76. (defun keysym-mappings (keysym &key display (mask-format #'identity))
  77. ;; Return all the keysym mappings for keysym.
  78. ;; Returns a list of argument lists that are argument-lists to define-keysym.
  79. ;; The following will re-create the mappings for KEYSYM:
  80. ;; (dolist (mapping (keysym-mappings) keysym)
  81. ;; (apply #'define-keysym mapping))
  82. (let ((mappings (append (and display (cdr (assoc keysym (display-keysym-translation display))))
  83. (gethash keysym *keysym->character-map*)))
  84. (result nil))
  85. (dolist (mapping mappings)
  86. (let ((object (keysym-mapping-object mapping))
  87. (translate (keysym-mapping-translate mapping))
  88. (lowercase (keysym-mapping-lowercase mapping))
  89. (modifiers (keysym-mapping-modifiers mapping))
  90. (mask (keysym-mapping-mask mapping)))
  91. (push (append (list object keysym)
  92. (when translate (list :translate translate))
  93. (when lowercase (list :lowercase lowercase))
  94. (when modifiers (list :modifiers (funcall mask-format modifiers)))
  95. (when mask (list :mask (funcall mask-format mask))))
  96. result)))
  97. (nreverse result)))
  98. #+comment
  99. (defun print-keysym-mappings (keysym &optional display)
  100. (format t "~%(keysym ~d ~3d) "
  101. (ldb (byte 8 8) keysym)
  102. (ldb (byte 8 0) keysym))
  103. (dolist (mapping (keysym-mappings keysym :display display))
  104. (format t "~16t~{ ~s~}~%" mapping)))
  105. (defun print-keysym-mappings (keysym &optional display)
  106. (flet ((format-mask (mask)
  107. (cond ((numberp mask)
  108. `(make-state-mask ,@(make-state-keys mask)))
  109. ((atom mask) mask)
  110. (t `(list ,@(mapcar
  111. #'(lambda (item)
  112. (if (numberp item)
  113. `(keysym ,(keysym-mapping-object
  114. (car (gethash item *keysym->character-map*))))
  115. item))
  116. mask))))))
  117. (dolist (mapping (keysym-mappings keysym :display display :mask-format #'format-mask))
  118. (format t "~%(define-keysym ~s (keysym ~d ~3d)~{ ~s~})"
  119. (car mapping)
  120. (ldb (byte 8 8) keysym)
  121. (ldb (byte 8 0) keysym)
  122. (cdr mapping)))))
  123. (defun keysym-test (host)
  124. ;; Server key-press Loop-back test
  125. (let* ((display (open-display host))
  126. (width 400)
  127. (height 400)
  128. (screen (display-default-screen display))
  129. (black (screen-black-pixel screen))
  130. (white (screen-white-pixel screen))
  131. (win (create-window
  132. :parent (screen-root screen)
  133. :background black
  134. :border white
  135. :border-width 1
  136. :colormap (screen-default-colormap screen)
  137. :bit-gravity :center
  138. :event-mask '(:exposure :key-press)
  139. :x 20 :y 20
  140. :width width :height height))
  141. #+comment
  142. (gc (create-gcontext
  143. :drawable win
  144. :background black
  145. :foreground white)))
  146. (initialize-extensions display)
  147. (map-window win) ; Map the window
  148. ;; Handle events
  149. (unwind-protect
  150. (dotimes (state 64)
  151. (do ((code (display-min-keycode display) (1+ code)))
  152. ((> code (display-max-keycode display)))
  153. (send-event win :key-press '(:key-press) :code code :state state
  154. :window win :root (screen-root screen) :time 0
  155. :x 1 :y 2 :root-x 10 :root-y 20 :same-screen-p t)
  156. (event-case (display :force-output-p t :discard-p t)
  157. (exposure ;; Come here on exposure events
  158. (window count)
  159. (when (zerop count) ;; Ignore all but the last exposure event
  160. (clear-area window))
  161. nil)
  162. (key-press (display code state)
  163. (princ (keycode->character display code state))
  164. t))))
  165. (close-display display))))
  166. (defun keysym-echo (host &optional keymap-p)
  167. ;; Echo characters typed to a window
  168. (let* ((display (open-display host))
  169. (width 400)
  170. (height 400)
  171. (screen (display-default-screen display))
  172. (black (screen-black-pixel screen))
  173. (white (screen-white-pixel screen))
  174. (win (create-window
  175. :parent (screen-root screen)
  176. :background black
  177. :border white
  178. :border-width 1
  179. :colormap (screen-default-colormap screen)
  180. :bit-gravity :center
  181. :event-mask '(:exposure :key-press :keymap-state :enter-window)
  182. :x 20 :y 20
  183. :width width :height height))
  184. (gc (create-gcontext
  185. :drawable win
  186. :background black
  187. :foreground white)))
  188. (initialize-extensions display)
  189. (map-window win) ; Map the window
  190. ;; Handle events
  191. (unwind-protect
  192. (event-case (display :force-output-p t :discard-p t)
  193. (exposure ;; Come here on exposure events
  194. (window count)
  195. (when (zerop count) ;; Ignore all but the last exposure event
  196. (clear-area window)
  197. (draw-glyphs window gc 10 10 "Press <escape> to exit"))
  198. nil)
  199. (key-press (display code state)
  200. (let ((char (keycode->character display code state)))
  201. (format t "~%Code: ~s State: ~s Char: ~s" code state char)
  202. ;; (PRINC char) (PRINC " ")
  203. (when keymap-p
  204. (let ((keymap (query-keymap display)))
  205. (unless (character-in-map-p display char keymap)
  206. (print "character-in-map-p failed")
  207. (print-keymap keymap))))
  208. ;; (when (eql char #\0) (setq disp display) (break))
  209. (eql char #\escape)))
  210. (keymap-notify (keymap)
  211. (print "Keymap-notify") ;; we never get here. Server bug?
  212. (when (keysym-in-map-p display 65 keymap)
  213. (print "Found A"))
  214. (when (character-in-map-p display #\b keymap)
  215. (print "Found B")))
  216. (enter-notify (event-window) (format t "~%Enter ~s" event-window)))
  217. (close-display display))))
  218. (defun print-keymap (keymap)
  219. (do ((j 32 (+ j 32))) ;; first 32 bits is for window
  220. ((>= j 256))
  221. (format t "~% ~3d: " j)
  222. (do ((i j (1+ i)))
  223. ((>= i (+ j 32)))
  224. (when (zerop (logand i 7))
  225. (princ " "))
  226. (princ (aref keymap i)))))
  227. (defun define-keysym-test (&key display printp
  228. (modifiers (list (keysym :left-meta))) (mask :modifiers))
  229. (let* ((keysym 067)
  230. (args `(baz ,keysym :modifiers ,modifiers ,@(and mask `(:mask ,mask))))
  231. (original (copy-tree (keysym-mappings keysym :display display))))
  232. (when printp (print-keysym-mappings 67) (terpri))
  233. (apply #'define-keysym args)
  234. (when printp (print-keysym-mappings 67) (terpri))
  235. (let ((is (keysym-mappings keysym :display display))
  236. (should-be (append original (list args))))
  237. (unless (equal is should-be)
  238. (cerror "Ignore" "define-keysym error. ~%is: ~s ~%Should be: ~s" is should-be)))
  239. (apply #'undefine-keysym args)
  240. (when printp (print-keysym-mappings 67) (terpri))
  241. (let ((is (keysym-mappings keysym :display display)))
  242. (unless (equal is original)
  243. (cerror "Ignore" "undefine-keysym error. ~%is: ~s ~%Should be: ~s" is original)))))
  244. (define-keysym-test)
  245. (define-keysym-test :modifiers (make-state-mask :shift :lock))
  246. (define-keysym-test :modifiers (list :shift (keysym :left-meta) :control))
  247. (define-keysym-test :modifiers (make-state-mask :shift :lock) :mask nil)