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

(in-package #:wheelwork)

(def:class listener ()
  (keydown
   keyup
   mousedown
   mouseup
   mousemotion
   mousewheel
   focus
   blur
   perframe
   :ro :prefix :type (or null event-handler) :initform nil)
  (keydown-table
   keyup-table
   mousedown-table
   mouseup-table
   mousemotion-table
   mousewheel-table
   focus-table
   blur-table
   perframe-table
   :noarg 
   :allocation :class
   :initform (make-hash-table :synchronized t :test #'eq)
   :documentation "Keyed by DISPLAY-UNIT instance, holds an EVENT-HANDLER if
    handler is defined for unit."))

(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))))