sidorares/node-x11

GetImage returns error

Closed this issue · 9 comments

code as following:

var x11 = require('x11');
x11.createClient({display: ":1"}, function(err, display) {
    var X = display.client;
    var root = display.screen[0].root;
    X.ChangeWindowAttributes(root, {
        eventMask: x11.eventMask.StructureNotify | x11.eventMask.SubstructureRedirect | x11.eventMask.SubstructureNotify | x11.eventMask.ProperityChange
    }, function(err) {
        if(err.error === 10) {
            console.log("Error: maybe another window manager had already ran?");
            process.exit(1);
        }
    });
    X.on('event', function(ev){
        console.log(ev);
        switch(ev.type){
            case 16: // CreateNotify
                break;
            case 20: //MapRequest
                X.GetGeometry(ev.wid, function(err, clientGeom) {
                    X.GetImage(2, ev.wid, 0, 0, clientGeom.width, clientGeom.height, 0xffffffff, function(d) {
                    });
                });
        }
    })
});

error:

{ type: 16,
  seq: 3,
  name: 'CreateNotify',
  parent: 365,
  wid: 4194314,
  x: 0,
  y: 150,
  width: 100,
  height: 1,
  borderWidth: 0,
  overrideRedirect: false,
  rawData: <Buffer 10 00 03 00 6d 01 00 00 0a 00 40 00 00 00 00 00 96 00 64 00 01 00 00 00 00 00 00 00 00 00 00 00> }
{ type: 20,
  seq: 3,
  name: 'MapRequest',
  parent: 365,
  wid: 4194314,
  rawData: <Buffer 14 00 03 00 6d 01 00 00 0a 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00> }

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: Bad match
    at ReadFixedRequest.callback (/home/ubuntu/cw-ws/node_modules/x11/lib/xcore.js:429:29)
    at ReadFixedRequest.execute (/home/ubuntu/cw-ws/node_modules/x11/lib/unpackstream.js:41:10)
    at UnpackStream.resume (/home/ubuntu/cw-ws/node_modules/x11/lib/unpackstream.js:165:30)
    at UnpackStream.write (/home/ubuntu/cw-ws/node_modules/x11/lib/unpackstream.js:102:10)
    at Socket.<anonymous> (/home/ubuntu/cw-ws/node_modules/x11/lib/xcore.js:58:21)
    at Socket.EventEmitter.emit (events.js:95:17)
    at Socket.<anonymous> (_stream_readable.js:746:14)
    at Socket.EventEmitter.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:408:10)
    at emitReadable (_stream_readable.js:404:5)

@sidorares the createnotify seems still not matching the actual value~, y, width, height are not correct.
I have already use the commit 28fdbad

@guodong check with latest master. A fix was commited to fix that. See: #104

@guodong For the CreateNotify issue I mean

The BadMatch error by looking at the spec:

If the drawable is a pixmap, then the given rectangle must be wholly contained
within the pixmap (or a Match error results). If the drawable is a window, the win-
dow must be viewable, and it must be the case that, if there were no inferiors or
overlapping windows, the specified rectangle of the window would be fully visible
on the screen and wholly contained within the outside edges of the window (or a
Match error results)

thx @santigimeno , CreateNotify is right now. But how can I get window content image when it mapped? Can you give me some examples?

The window must be viewable. Map it after receiving the MapRequest

var x11 = require('./');
x11.createClient(function(err, display) {
    var X = display.client;
    var root = display.screen[0].root;
    X.ChangeWindowAttributes(root, {
        eventMask: x11.eventMask.StructureNotify | x11.eventMask.SubstructureRedirect | x11.eventMask.SubstructureNotify | x11.eventMask.ProperityChange
    }, function(err) {
        if(err.error === 10) {
            console.log("Error: maybe another window manager had already ran?");
            process.exit(1);
        }
    });
    X.on('event', function(ev){
        console.log(ev);
        switch(ev.type){
            case 16: // CreateNotify
                break;
            case 20: //MapRequest
                X.MapWindow(ev.wid);
                break;
            case 19: // Map Notify
                X.GetGeometry(ev.wid, function(err, clientGeom) {
                    X.GetImage(2, ev.wid, 0, 0, clientGeom.width, clientGeom.height, 0xffffffff, function(d) {
                    });
                });
                break;
        }
    })
});


@guodong you need to use Composite extension, NameWindowPixmap request. Take a look at this article - http://www.talisman.org/~erlkonig/misc/x11-composite-tutorial/

thank you! It works! @sidorares @santigimeno

@guodong are you using Composite extension? Can't remember if I tried it myself, feel free to post examples here