Skip to content

Commit 3a1f732

Browse files
author
Cosimo Crocchini
committed
fix: Ignore i2c mouse devices. Ref: https://askubuntu.com/q/1280003
Related (to be tested!) issues: askmrsinh#40, askmrsinh#61, askmrsinh#64 and maybe askmrsinh#67
1 parent 9201f74 commit 3a1f732

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

Diff for: lib.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,22 @@ function makePointingDevice(pointingDeviceLines) {
153153
//assuming that N: & P: always appear at lines 2 and 3 respectively
154154
if (pointingDeviceLines[1].startsWith('N: Name=') &&
155155
pointingDeviceLines[2].startsWith('P: Phys=')) {
156+
157+
let name = pointingDeviceLines[1].split('"')[1];
158+
let phys = pointingDeviceLines[2].split('=')[1];
159+
160+
// Ignore i2c mouse devices: they are ephemeral.
161+
// See https://askubuntu.com/q/1280003
162+
// WARNING: don't make check for 'touchpad' device!
163+
// Related (to be tested) issues: #40, #61, #64 and maybe #67
164+
// TODO: How can we check in a clean way not hardcoded?
165+
if (name.toLowerCase().indexOf("mouse") !== -1 && phys.toLowerCase().startsWith("i2c")) {
166+
return;
167+
}
168+
156169
let pointingDevice = {};
157-
pointingDevice.name = pointingDeviceLines[1].split('"')[1];
158-
pointingDevice.phys = pointingDeviceLines[2].split('=')[1];
170+
pointingDevice.name = name;
171+
pointingDevice.phys = phys;
159172
pointingDevice.type = 'mouse'; //default
160173
for (let type in ALL_TYPES) {
161174
if (ALL_TYPES[type].some((t) => {
@@ -175,7 +188,7 @@ function listPointingDevices() {
175188
let comp = executeCmdSync('cat /proc/bus/input/devices');
176189
let allDeviceChunks = comp[1].split('\n\n');
177190
for (let x = 0; x < allDeviceChunks.length; x++) {
178-
if (allDeviceChunks[x].indexOf('mouse') !== -1) {
191+
if (allDeviceChunks[x].toLowerCase().indexOf('mouse') !== -1) {
179192
let pointingDeviceLines = allDeviceChunks[x].split('\n');
180193
let pointingDevice = makePointingDevice(pointingDeviceLines);
181194
if (pointingDevice !== undefined) {

0 commit comments

Comments
 (0)