aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/events/listener.lisp
blob: e66afe27b7394cfdf076f20f2e6a23356576295b (plain)
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
;;;; listener.lisp

(in-package #:wheelwork)

(defclass/std listener ()
  ((keydown
    keyup
    mousedown
    mouseup
    mousemotion
    mousewheel
    focus
    blur
    perframe
    :r :with :type (or null event-handler) :std nil)
   (keydown-table
    keyup-table
    mousedown-table
    mouseup-table
    mousemotion-table
    mousewheel-table
    focus-table
    blur-table
    perframe-table
    :static
    :std (make-hash-table :synchronized t)
    :doc "Keyed by DISPLAY-UNIT instance, holds an EVENT-HANDLER if
    handler is defined for unit."))
  (:documentation "Event handlers per object. The static hash tables
  are keyed by UNIT and hold Event-Handler instances."))

(defun listener-table-for (listener event-type)
  (ecase event-type
    (keydown (keydown-table listener))
    (keyup   (keyup-table listener))
    (mousedown (mousedown-table listener))
    (mouseup (mouseup-table listener))
    (mousemotion (mousemotion-table listener))
    (mousewheel (mousewheel-table listener))
    (focus (focus-table listener))
    (blur (blur-table listener))
    (perframe (perframe-table listener))))

(defun should-listen-for-p (event-type app)
  (plusp (hash-table-count (listener-table-for (listener app) event-type))))