Changeset 6655


Ignore:
Timestamp:
Jun 3, 2007, 2:50:50 AM (17 years ago)
Author:
Gary Byers
Message:

No mouse-events. Remove some CLX code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ide-1.0/ccl/hemlock/src/key-event.lisp

    r778 r6655  
    104104(defvar *modifiers-to-internal-masks*)
    105105
    106 ;;; TRANSLATE-KEY-EVENT -- Public.
    107 ;;;
    108 #+clx
    109 (defun translate-key-event (display scan-code bits)
    110   "Translates the X scan-code and X bits to a key-event.  First this maps
    111    scan-code to an X keysym using XLIB:KEYCODE->KEYSYM looking at bits and
    112    supplying index as 1 if the X shift bit is on, 0 otherwise.
    113 
    114    If the resulting keysym is undefined, and it is not a modifier keysym, then
    115    this signals an error.  If the keysym is a modifier key, then this returns
    116    nil.
    117 
    118    If the following conditions are satisfied
    119       the keysym is defined
    120       the X shift bit is off
    121       the X lock bit is on
    122       the X keysym represents a lowercase letter
    123    then this maps the scan-code again supplying index as 1 this time, treating
    124    the X lock bit as a caps-lock bit.  If this results in an undefined keysym,
    125    this signals an error.  Otherwise, this makes a key-event with the keysym
    126    and bits formed by mapping the X bits to key-event bits.
    127 
    128    If any state bit is set that has no suitable modifier translation, it is
    129    passed to XLIB:DEFAULT-KEYSYM-INDEX in order to handle Mode_Switch keys
    130    appropriately.
    131 
    132    Otherwise, this makes a key-event with the keysym and bits formed by mapping
    133    the X bits to key-event bits."
    134   (let ((new-bits 0)
    135         shiftp lockp)
    136     (dolist (map *modifier-translations*)
    137       (unless (zerop (logand (car map) bits))
    138         ;; ignore the bits of the mapping for the determination of a key index
    139         (setq bits (logxor bits (car map)))
    140         (cond
    141          ((string-equal (cdr map) "Shift")
    142           (setf shiftp t))
    143          ((string-equal (cdr map) "Lock")
    144           (setf lockp t))
    145          (t (setf new-bits
    146                   (logior new-bits (key-event-modifier-mask (cdr map))))))))
    147     ;; here pass any remaining modifier bits to clx
    148     (let* ((index  (and (not (zerop bits))
    149                         (xlib:default-keysym-index display scan-code bits)))
    150            (keysym (xlib:keycode->keysym display scan-code (or index (if shiftp 1 0)))))
    151       (cond ((null (keysym-names keysym))
    152              nil)
    153             ((and (not shiftp) lockp (<= 97 keysym 122)) ; small-alpha-char-p
    154              (let ((keysym (xlib:keycode->keysym display scan-code 1)))
    155                (if (keysym-names keysym)
    156                    (make-key-event keysym new-bits)
    157                    nil)))
    158             (t
    159              (make-key-event keysym new-bits))))))
    160 
    161 
    162 
    163 
    164 ;;;; Mouse key-event stuff.
    165 
    166 ;;; Think of this data as a three dimensional array indexed by the following
    167 ;;; domains:
    168 ;;;    1-5
    169 ;;;       for the mouse scan-codes (button numbers) delivered by X.
    170 ;;;    :button-press or :button-release
    171 ;;;       whether the button was pressed or released.
    172 ;;;    :keysym or :shifted-modifier-name
    173 ;;;       whether the X shift bit was set.
    174 ;;; For each button, pressed and released, we store a keysym to be used in a
    175 ;;; key-event representing the button and whether it was pressed or released.
    176 ;;; We also store a modifier name that TRANSLATE-MOUSE-KEY-EVENT turns on
    177 ;;; whenever a mouse event occurs with the X shift bit on.  This is basically
    178 ;;; an archaic feature since we now can specify key-events like the following:
    179 ;;;    #k"shift-leftdown"
    180 ;;; Previously we couldn't, so we mapped the shift bit to a bit we could
    181 ;;; talke about, such as super.
    182 ;;;
    183 (defvar *mouse-translation-info*)
    184 
    185 (eval-when (:compile-toplevel :execute)
    186   (defmacro button-press-info (event-dispatch) `(car ,event-dispatch))
    187   (defmacro button-release-info (event-dispatch) `(cdr ,event-dispatch))
    188   (defmacro button-keysym (info) `(car ,info))
    189   (defmacro button-shifted-modifier-name (info) `(cdr ,info))
    190 ) ;eval-when
    191 
    192 ;;; MOUSE-TRANSLATION-INFO -- Internal.
    193 ;;;
    194 ;;; This returns the requested information, :keysym or :shifted-modifier-name,
    195 ;;; for the button cross event-key.  If the information is undefined, this
    196 ;;; signals an error.
    197 ;;;
    198 (defun mouse-translation-info (button event-key info)
    199   (let ((event-dispatch (svref *mouse-translation-info* button)))
    200     (unless event-dispatch
    201       (error "No defined mouse translation information for button ~S." button))
    202     (let ((data (ecase event-key
    203                   (:button-press (button-press-info event-dispatch))
    204                   (:button-release (button-release-info event-dispatch)))))
    205       (unless data
    206         (error
    207          "No defined mouse translation information for button ~S and event ~S."
    208          button event-key))
    209       (ecase info
    210         (:keysym (button-keysym data))
    211         (:shifted-modifier-name (button-shifted-modifier-name data))))))
    212 
    213 ;;; %SET-MOUSE-TRANSLATION-INFO -- Internal.
    214 ;;;
    215 ;;; This walks into *mouse-translation-info* the same way MOUSE-TRANSLATION-INFO
    216 ;;; does, filling in the data structure on an as-needed basis, and stores
    217 ;;; the value for the indicated info.
    218 ;;;
    219 (defun %set-mouse-translation-info (button event-key info value)
    220   (let ((event-dispatch (svref *mouse-translation-info* button)))
    221     (unless event-dispatch
    222       (setf event-dispatch
    223             (setf (svref *mouse-translation-info* button) (cons nil nil))))
    224     (let ((data (ecase event-key
    225                   (:button-press (button-press-info event-dispatch))
    226                   (:button-release (button-release-info event-dispatch)))))
    227       (unless data
    228         (setf data
    229               (ecase event-key
    230                 (:button-press
    231                  (setf (button-press-info event-dispatch) (cons nil nil)))
    232                 (:button-release
    233                  (setf (button-release-info event-dispatch) (cons nil nil))))))
    234       (ecase info
    235         (:keysym
    236          (setf (button-keysym data) value))
    237         (:shifted-modifier-name
    238          (setf (button-shifted-modifier-name data) value))))))
    239 ;;;
    240 (defsetf mouse-translation-info %set-mouse-translation-info)
    241 
    242 ;;; DEFINE-MOUSE-KEYSYM -- Public.
    243 ;;;
    244 (defun define-mouse-keysym (button keysym name shifted-bit event-key)
    245   "This defines keysym named name for the X button cross the X event-key.
    246    Shifted-bit is a defined modifier name that TRANSLATE-MOUSE-KEY-EVENT sets
    247    in the key-event it returns whenever the X shift bit is on."
    248   (unless (<= 1 button 5)
    249     (error "Buttons are number 1-5, not ~D." button))
    250   (setf (gethash keysym *keysyms-to-names*) (list name))
    251   (setf (gethash  (get-name-case-right name) *names-to-keysyms*) keysym)
    252   (setf (mouse-translation-info button event-key :keysym) keysym)
    253   (setf (mouse-translation-info button event-key :shifted-modifier-name)
    254         shifted-bit))
    255 
    256 ;;; TRANSLATE-MOUSE-KEY-EVENT -- Public.
    257 ;;;
    258 (defun translate-mouse-key-event (scan-code bits event-key)
    259   "This translates the X button code, scan-code, and modifier bits, bits, for
    260    the X event-key into a key-event.  See DEFINE-MOUSE-KEYSYM."
    261   (let ((keysym (mouse-translation-info scan-code event-key :keysym))
    262         (new-bits 0))
    263     (dolist (map *modifier-translations*)
    264       (when (logtest (car map) bits)
    265         (setf new-bits
    266               (if (string-equal (cdr map) "Shift")
    267                   (logior new-bits
    268                           (key-event-modifier-mask
    269                            (mouse-translation-info
    270                             scan-code event-key :shifted-modifier-name)))
    271                   (logior new-bits
    272                           (key-event-modifier-mask (cdr map)))))))
    273     (make-key-event keysym new-bits)))
     106
     107
     108
     109
     110
    274111
    275112
Note: See TracChangeset for help on using the changeset viewer.