MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / Poll

Method Poll

System/LemonWM/input.cpp:100–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100void InputManager::Poll(){
101 auto handlePacketPress = [=](Lemon::MousePacket& pkt) -> void {
102 if((!!(pkt.buttons & Lemon::MouseButton::Left)) != mouse.left){ /* Use a double negative to make the statement 0 or 1*/
103 mouse.left = !!(pkt.buttons & Lemon::MouseButton::Left);
104
105 if(mouse.left){
106 wm->MouseDown();
107 } else {
108 wm->MouseUp();
109 }
110 }
111
112 if((!!(pkt.buttons & Lemon::MouseButton::Right)) != mouse.right){ /* Use a double negative to make the statement 0 or 1*/
113 mouse.right = !!(pkt.buttons & Lemon::MouseButton::Right);
114
115 wm->MouseRight(mouse.right);
116 }
117 };
118
119 if(Lemon::MousePacket mousePacket; Lemon::PollMouse(mousePacket)){
120 mouse.pos.x += mousePacket.xMovement;
121 mouse.pos.y += mousePacket.yMovement;
122
123 if(mouse.pos.x > wm->surface.width) mouse.pos.x = wm->surface.width;
124 else if (mouse.pos.x < 0) mouse.pos.x = 0;
125
126 if(mouse.pos.y > wm->surface.height) mouse.pos.y = wm->surface.height;
127 else if (mouse.pos.y < 0) mouse.pos.y = 0;
128
129 handlePacketPress(mousePacket);
130
131 while(Lemon::PollMouse(mousePacket)){
132 mouse.pos.x += mousePacket.xMovement;
133 mouse.pos.y += mousePacket.yMovement;
134
135 if(mouse.pos.x > wm->surface.width) mouse.pos.x = wm->surface.width;
136 else if (mouse.pos.x < 0) mouse.pos.x = 0;
137
138 if(mouse.pos.y > wm->surface.height) mouse.pos.y = wm->surface.height;
139 else if (mouse.pos.y < 0) mouse.pos.y = 0;
140
141 handlePacketPress(mousePacket); // If necessary send a mouse press event for each packet, however only send move event after processing all packets
142 }
143
144 wm->MouseMove();
145 }
146
147 uint8_t buf[32];
148 ssize_t count = Lemon::PollKeyboard(buf, 32);
149
150 for(ssize_t i = 0; i < count; i++){
151 uint8_t code = buf[i] & 0x7F;
152 bool isPressed = !((buf[i] >> 7) & 1);
153 int key = 0;
154
155 if(keyboard.shift){
156 key = keymap_us_shift[code];
157 } else {

Callers

nothing calls this directly

Calls 7

PollMouseFunction · 0.85
PollKeyboardFunction · 0.85
MouseDownMethod · 0.80
MouseUpMethod · 0.80
MouseRightMethod · 0.80
MouseMoveMethod · 0.80
KeyUpdateMethod · 0.80

Tested by

no test coverage detected