sidorares / node-x11

X11 node.js network protocol client
MIT License
518 stars 72 forks source link

No PointerMotion or KeyPress events on root from `on('event', ...)` #207

Open Cobertos opened 1 year ago

Cobertos commented 1 year ago

I ran some code from #69 to debug why my events weren't firing. When I run the below code, NO events show up on my system.

var x11 = require('x11');
x11.createClient(function(err, display) {
    var X = display.client;
    var root = display.screen[0].root;
    X.ChangeWindowAttributes(root, { eventMask: x11.eventMask.PointerMotion|x11.eventMask.KeyPress });
    X.on('event', function(ev) {
        console.log(ev);
    });
});

no_x11_events

I also tried the below code to see all possible events I could get

var x11 = require('../../lib');
x11.createClient(function(err, display) {
    var X = display.client;
    var root = display.screen[0].root;
    const mask = Object.entries(x11.eventMask)
        .filter(([k,v])=>k !== "SubstructureRedirect")
        .map(([k,v])=>v)
        .reduce((acc,i)=>acc|i,0x0);
    X.ChangeWindowAttributes(root, { eventMask: mask });
    const uniq = [];
    X.on('event', function(ev) {
        const name = ev.name || ev.type;
        if (!uniq.includes(name)) {
            console.log(name);
            uniq.push(name);
        }
    });
});

and I was able to see

ConfigureNotify
PropertyNotify
32
ClientMessage
MapNotify
UnmapNotify
CreateNotify
DestroyNotify
21

Lastly, I tried the Tetris game and I can get key presses and pointer motion when it's on a window I create, but I can't target a different window?

Any ideas why PointerMotion and KeyPress won't show up on my system?