~technomancy/menelaus

e5fc3c7fdc81ced671a59f80076ffb41e8aceda0 — Phil Hagelberg 8 months ago 317dd9a when
Use when special form instead of if+begin combos.

(This did not exist in Microscheme originally.)

(Technically it still doesn't outside my one branch that hasn't gotten
merged at the time of this writing.)
1 files changed, 15 insertions(+), 20 deletions(-)

M menelaus.scm
M menelaus.scm => menelaus.scm +15 -20
@@ 18,9 18,6 @@
;; it is written in a shared subset of Microscheme and Racket so that it
;; can be tested on a PC without uploading it to a device for every change.

;; For one example, we use `and' where `when' would be more idiomatic. We
;; are also missing the `cond' form.

;; When you see an -aux function, it is an internal function which recursively
;; steps thru a vector/list with the initial arguments calculated by its
;; non-aux equivalent. The -aux function is never called directly.


@@ 284,14 281,14 @@
  (let ((keycode (lookup key)))
    ;; Sometimes "keycodes" are procedures; in that case we call them with
    ;; true when the key is pressed and false when it's released.
    (if (procedure? keycode)
        (keycode #t)
        (if (modifier? keycode)
            (begin (press-modifier (unmodify keycode) key)
                   (if (uncombo keycode)
                       (press-normal-key (uncombo keycode) key)
                       #f))
            (press-normal-key keycode key)))))
    (when (procedure? keycode)
      (keycode #t))
    (when (modifier? keycode)
      (press-modifier (unmodify keycode) key)
      (when (uncombo keycode)
        (press-normal-key (uncombo keycode) key)))
    (when (number? keycode)
      (press-normal-key keycode key))))

;; Record that a given key being released resulted in a modifier release.
(define (release-modifier keycode key n)


@@ 299,7 296,8 @@
      (begin
        (vector-set! modifiers n 0)
        (vector-set! keys-for-modifiers n #f))
      (and (< n 3) (release-modifier keycode key (+ n 1)))))
      (when (< n 3)
        (release-modifier keycode key (+ n 1)))))

;; Record a key release, clearing it out of the press tracking data.
(define (release-key key)


@@ 311,14 309,11 @@
        (keycode #f)
        (let ((slot (find keys-for-frame key))
              (modifier-slot (find keys-for-modifiers key)))
          (if slot
              (begin
                (vector-set! keycodes-down slot 0)
                (vector-set! keys-for-frame slot #f))
              #f)
          (if modifier-slot
              (release-modifier modifier-slot key 0)
              #f)))))
          (when slot
              (vector-set! keycodes-down slot 0)
              (vector-set! keys-for-frame slot #f))
          (when modifier-slot
            (release-modifier modifier-slot key 0))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Send USB