1 module seat;
2 
3 import compositor;
4 import wayland.server;
5 
6 import std.algorithm;
7 
8 class Seat : WlSeat
9 {
10     Compositor comp;
11     ClPointer[] pointers;
12 
13     this(Compositor comp)
14     {
15         super(comp.display, ver);
16         this.comp = comp;
17     }
18 
19     void mouseButton(WlClient cl, int button, WlPointer.ButtonState state)
20     {
21         foreach(p; pointers)
22         {
23             if (p.client is cl)
24             {
25                 auto serial = comp.display.nextSerial();
26                 auto time = cast(uint)comp.time.total!"msecs";
27                 p.sendButton(serial, time, button, state);
28             }
29         }
30     }
31 
32     override Resource bind(WlClient cl, uint ver, uint id)
33     {
34         auto res = super.bind(cl, ver, id);
35 
36         res.sendCapabilities(Capability.pointer | Capability.keyboard);
37         if (ver >= nameSinceVersion) {
38             res.sendName("seat");
39         }
40         return res;
41     }
42 
43     override WlPointer getPointer(WlClient cl, Resource res, uint id)
44     {
45         auto p = new ClPointer(this, cl, id);
46         pointers ~= p;
47         return p;
48     }
49 
50     override WlTouch getTouch(WlClient cl, Resource res, uint id)
51     {
52         return null;
53     }
54 
55     override WlKeyboard getKeyboard(WlClient cl, Resource res, uint id)
56     {
57         return new ClKeyboard(cl, id);
58     }
59 
60     override void release(WlClient cl, Resource res)
61     {}
62 }
63 
64 class ClPointer : WlPointer
65 {
66     Seat seat;
67 
68     this(Seat seat, WlClient cl, uint id)
69     {
70         super(cl, ver, id);
71     }
72 
73     override protected void setCursor(WlClient cl,
74                                       uint serial,
75                                       WlSurface surface,
76                                       int hotspotX,
77                                       int hotspotY)
78     {}
79 
80 
81     override protected void release(WlClient cl)
82     {
83         seat.pointers = seat.pointers.remove!(p => p is this);
84     }
85 }
86 
87 class ClKeyboard : WlKeyboard
88 {
89     this(WlClient cl, uint id)
90     {
91         super(cl, ver, id);
92     }
93 
94     override protected void release(WlClient cl)
95     {}
96 }