Repository navigation
Expand file tree
/
Copy pathinput_router.cpp
More file actions
119 lines (102 loc) · 3.48 KB
/
Copy pathinput_router.cpp
File metadata and controls
119 lines (102 loc) · 3.48 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* Copyright (C) 2026 Shitty team
* MIT licensed
* See the file LICENSE.MIT for the full license.
*/
#include "input_router.h"
#include "composer.h"
#include "input_sink.h"
#include <std/mem/obj_pool.h>
using namespace stl;
namespace {
struct InputRouter final: public InputSink {
explicit InputRouter(Composer& composer);
bool key(const KeyInput& input) override;
bool text(const TextInput& input) override;
bool pointerMotion(const PointerMotionInput& input) override;
bool pointerButton(const PointerButtonInput& input) override;
bool scroll(const ScrollInput& input) override;
void focus(bool focused) override;
void pointerPresence(bool present) override;
void flush() override;
Composer& composer;
};
}
InputRouter::InputRouter(Composer& composer_)
: composer(composer_)
{
}
bool InputRouter::key(const KeyInput& input) {
for (IntrusiveNode* node = composer.inputSinks.mutFront(); node != composer.inputSinks.mutEnd();) {
InputSink* const sink = static_cast<InputSink*>(node);
node = node->next;
if (sink->key(input)) {
return true;
}
}
return false;
}
bool InputRouter::text(const TextInput& input) {
for (IntrusiveNode* node = composer.inputSinks.mutFront(); node != composer.inputSinks.mutEnd();) {
InputSink* const sink = static_cast<InputSink*>(node);
node = node->next;
if (sink->text(input)) {
return true;
}
}
return false;
}
bool InputRouter::pointerMotion(const PointerMotionInput& input) {
for (IntrusiveNode* node = composer.inputSinks.mutFront(); node != composer.inputSinks.mutEnd();) {
InputSink* const sink = static_cast<InputSink*>(node);
node = node->next;
if (sink->pointerMotion(input)) {
return true;
}
}
return false;
}
bool InputRouter::pointerButton(const PointerButtonInput& input) {
for (IntrusiveNode* node = composer.inputSinks.mutFront(); node != composer.inputSinks.mutEnd();) {
InputSink* const sink = static_cast<InputSink*>(node);
node = node->next;
if (sink->pointerButton(input)) {
return true;
}
}
return false;
}
bool InputRouter::scroll(const ScrollInput& input) {
for (IntrusiveNode* node = composer.inputSinks.mutFront(); node != composer.inputSinks.mutEnd();) {
InputSink* const sink = static_cast<InputSink*>(node);
node = node->next;
if (sink->scroll(input)) {
return true;
}
}
return false;
}
void InputRouter::focus(bool focused) {
for (IntrusiveNode* node = composer.inputSinks.mutFront(); node != composer.inputSinks.mutEnd();) {
InputSink* const sink = static_cast<InputSink*>(node);
node = node->next;
sink->focus(focused);
}
}
void InputRouter::pointerPresence(bool present) {
for (IntrusiveNode* node = composer.inputSinks.mutFront(); node != composer.inputSinks.mutEnd();) {
InputSink* const sink = static_cast<InputSink*>(node);
node = node->next;
sink->pointerPresence(present);
}
}
void InputRouter::flush() {
for (IntrusiveNode* node = composer.inputSinks.mutFront(); node != composer.inputSinks.mutEnd();) {
InputSink* const sink = static_cast<InputSink*>(node);
node = node->next;
sink->flush();
}
}
InputSink* createInputRouter(Composer& composer) {
return composer.pool->make<InputRouter>(composer);
}