MCPcopy Create free account
hub / github.com/SFML/SFML / keepFileDescriptor

Function keepFileDescriptor

src/SFML/Window/DRM/InputImpl.cpp:109–135  ·  view source on GitHub ↗

Only keep fileDescriptors that we think are a keyboard, mouse or touchpad/touchscreen Joysticks are handled in /src/SFML/Window/Unix/JoystickImpl.cpp

Source from the content-addressed store, hash-verified

107// Only keep fileDescriptors that we think are a keyboard, mouse or touchpad/touchscreen
108// Joysticks are handled in /src/SFML/Window/Unix/JoystickImpl.cpp
109bool keepFileDescriptor(int fileDesc)
110{
111 std::array<unsigned long, NBITS(EV_MAX)> bitmaskEv{};
112 std::array<unsigned long, NBITS(KEY_MAX)> bitmaskKey{};
113 std::array<unsigned long, NBITS(ABS_MAX)> bitmaskAbs{};
114 std::array<unsigned long, NBITS(REL_MAX)> bitmaskRel{};
115
116 ioctl(fileDesc, EVIOCGBIT(0, sizeof(bitmaskEv)), bitmaskEv.data());
117 ioctl(fileDesc, EVIOCGBIT(EV_KEY, sizeof(bitmaskKey)), bitmaskKey.data());
118 ioctl(fileDesc, EVIOCGBIT(EV_ABS, sizeof(bitmaskAbs)), bitmaskAbs.data());
119 ioctl(fileDesc, EVIOCGBIT(EV_REL, sizeof(bitmaskRel)), bitmaskRel.data());
120
121 // This is the keyboard test used by SDL.
122 // The first 32 bits are ESC, numbers and Q to D; If we have any of those,
123 // consider it a keyboard device; do not test for KEY_RESERVED, though
124 const bool isKeyboard = (bitmaskKey[0] & 0xFFFFFFFE);
125
126 const bool isAbs = TEST_BIT(EV_ABS, bitmaskEv) && TEST_BIT(ABS_X, bitmaskAbs) && TEST_BIT(ABS_Y, bitmaskAbs);
127
128 const bool isRel = TEST_BIT(EV_REL, bitmaskEv) && TEST_BIT(REL_X, bitmaskRel) && TEST_BIT(REL_Y, bitmaskRel);
129
130 const bool isMouse = (isAbs || isRel) && TEST_BIT(BTN_MOUSE, bitmaskKey);
131
132 const bool isTouch = isAbs && (TEST_BIT(BTN_TOOL_FINGER, bitmaskKey) || TEST_BIT(BTN_TOUCH, bitmaskKey));
133
134 return isKeyboard || isMouse || isTouch;
135}
136
137void initFileDescriptors()
138{

Callers 1

initFileDescriptorsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected