mirror of
https://github.com/danbulant/node-x11
synced 2026-06-24 17:21:47 +00:00
initial SendEvent implementation
This commit is contained in:
parent
1696c4b28a
commit
a40ba7d874
4 changed files with 91 additions and 11 deletions
|
|
@ -224,6 +224,14 @@ module.exports = {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
|
SendEvent: [
|
||||||
|
|
||||||
|
function(destination, propagate, eventMask, eventRawData)
|
||||||
|
{
|
||||||
|
return [ 'CCSLLa', [25, propagate, 11, destination, eventMask, eventRawData] ];
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
QueryPointer: [
|
QueryPointer: [
|
||||||
[ 'CxSL', [38, 2] ],
|
[ 'CxSL', [38, 2] ],
|
||||||
function(buf) {
|
function(buf) {
|
||||||
|
|
|
||||||
|
|
@ -208,7 +208,7 @@ UnpackStream.prototype.pstr = function(str)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// TODO: measure node 0.5+ buffer serialisers performance
|
// TODO: measure node 0.5+ buffer serialisers performance
|
||||||
UnpackStream.prototype.pack = function(format, arguments)
|
UnpackStream.prototype.pack = function(format, args)
|
||||||
{
|
{
|
||||||
var packetlength = 0;
|
var packetlength = 0;
|
||||||
|
|
||||||
|
|
@ -220,9 +220,9 @@ UnpackStream.prototype.pack = function(format, arguments)
|
||||||
{
|
{
|
||||||
packetlength++;
|
packetlength++;
|
||||||
} else if (f == 'p') {
|
} else if (f == 'p') {
|
||||||
packetlength += xutil.padded_length(arguments[arg++].length);
|
packetlength += xutil.padded_length(args[arg++].length);
|
||||||
} else if (f == 'a') {
|
} else if (f == 'a') {
|
||||||
packetlength += arguments[arg].length;
|
packetlength += args[arg].length;
|
||||||
arg++;
|
arg++;
|
||||||
} else {
|
} else {
|
||||||
// this is a fixed-length format, get length from argument_length table
|
// this is a fixed-length format, get length from argument_length table
|
||||||
|
|
@ -242,25 +242,25 @@ UnpackStream.prototype.pack = function(format, arguments)
|
||||||
buf[offset++] = 0;
|
buf[offset++] = 0;
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
var n = arguments[arg++];
|
var n = args[arg++];
|
||||||
buf[offset++] = n;
|
buf[offset++] = n;
|
||||||
break;
|
break;
|
||||||
case 's': // TODO: implement signed INT16!!!
|
case 's': // TODO: implement signed INT16!!!
|
||||||
case 'S':
|
case 'S':
|
||||||
var n = arguments[arg++];
|
var n = args[arg++];
|
||||||
buf[offset++] = n & 0xff;
|
buf[offset++] = n & 0xff;
|
||||||
buf[offset++] = (n >> 8) & 0xff;
|
buf[offset++] = (n >> 8) & 0xff;
|
||||||
break;
|
break;
|
||||||
case 'l': // TODO: implement signed INT32!!!
|
case 'l': // TODO: implement signed INT32!!!
|
||||||
case 'L':
|
case 'L':
|
||||||
var n = arguments[arg++];
|
var n = args[arg++];
|
||||||
buf[offset++] = n & 0xff;
|
buf[offset++] = n & 0xff;
|
||||||
buf[offset++] = (n >> 8) & 0xff;
|
buf[offset++] = (n >> 8) & 0xff;
|
||||||
buf[offset++] = (n >> 16) & 0xff;
|
buf[offset++] = (n >> 16) & 0xff;
|
||||||
buf[offset++] = (n >> 24) & 0xff;
|
buf[offset++] = (n >> 24) & 0xff;
|
||||||
break;
|
break;
|
||||||
case 'a': // string or buffer
|
case 'a': // string or buffer
|
||||||
var str = arguments[arg++];
|
var str = args[arg++];
|
||||||
if (Buffer.isBuffer(str))
|
if (Buffer.isBuffer(str))
|
||||||
{
|
{
|
||||||
str.copy(buf, offset);
|
str.copy(buf, offset);
|
||||||
|
|
@ -272,7 +272,7 @@ UnpackStream.prototype.pack = function(format, arguments)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'p': // padded string
|
case 'p': // padded string
|
||||||
var str = arguments[arg++];
|
var str = args[arg++];
|
||||||
var len = padded(str);
|
var len = padded(str);
|
||||||
// TODO: buffer.write could be faster
|
// TODO: buffer.write could be faster
|
||||||
var c = 0;
|
var c = 0;
|
||||||
|
|
|
||||||
|
|
@ -172,7 +172,7 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw)
|
||||||
event.seq = seq;
|
event.seq = seq;
|
||||||
|
|
||||||
if (type == 2 || type == 4 || type == 5 || type == 6) { // motion event
|
if (type == 2 || type == 4 || type == 5 || type == 6) { // motion event
|
||||||
var values = raw.unpack('LLLSSSSSC'); //TODO: should be LLLLsssssSC
|
var values = raw.unpack('LLLssssSC');
|
||||||
//event.raw = values;
|
//event.raw = values;
|
||||||
// TODO: use unpackTo???
|
// TODO: use unpackTo???
|
||||||
event.time = extra;
|
event.time = extra;
|
||||||
|
|
@ -212,8 +212,8 @@ XClient.prototype.expectReplyHeader = function()
|
||||||
// TODO: BigReq!!!!
|
// TODO: BigReq!!!!
|
||||||
|
|
||||||
var client = this;
|
var client = this;
|
||||||
client.pack_stream.unpack(
|
client.pack_stream.get( 8, function(headerBuf) {
|
||||||
'CCSL', function(res) {
|
var res = headerBuf.unpack('CCSL');
|
||||||
var type = res[0];
|
var type = res[0];
|
||||||
var seq_num = res[2];
|
var seq_num = res[2];
|
||||||
|
|
||||||
|
|
@ -252,6 +252,13 @@ XClient.prototype.expectReplyHeader = function()
|
||||||
var extra = res[3];
|
var extra = res[3];
|
||||||
var code = res[1];
|
var code = res[1];
|
||||||
var ev = client.unpackEvent(type, seq_num, extra, code, buf);
|
var ev = client.unpackEvent(type, seq_num, extra, code, buf);
|
||||||
|
|
||||||
|
// raw event 32-bytes packet (primarily for use in SendEvent);
|
||||||
|
// TODO: Event::pack based on event parameters, inverse to unpackEvent
|
||||||
|
ev.rawData = new Buffer(32);
|
||||||
|
headerBuf.copy(ev.rawData);
|
||||||
|
buf.copy(ev.rawData, 8);
|
||||||
|
|
||||||
client.emit('event', ev);
|
client.emit('event', ev);
|
||||||
var ee = client.event_consumers[ev.wid];
|
var ee = client.event_consumers[ev.wid];
|
||||||
if (ee) {
|
if (ee) {
|
||||||
|
|
|
||||||
65
test/sendevent.js
Normal file
65
test/sendevent.js
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
var x11 = require('../lib/x11');
|
||||||
|
|
||||||
|
var xclient = x11.createClient();
|
||||||
|
var Exposure = x11.eventMask.Exposure;
|
||||||
|
var PointerMotion = x11.eventMask.PointerMotion;
|
||||||
|
var pts = [];
|
||||||
|
|
||||||
|
xclient.on('connect', function(display) {
|
||||||
|
var X = this;
|
||||||
|
var root = display.screen[0].root;
|
||||||
|
var white = display.screen[0].white_pixel;
|
||||||
|
var black = display.screen[0].black_pixel;
|
||||||
|
|
||||||
|
function createWindow()
|
||||||
|
{
|
||||||
|
|
||||||
|
var wid = X.AllocID();
|
||||||
|
X.CreateWindow(
|
||||||
|
wid, root,
|
||||||
|
10, 10, 400, 300,
|
||||||
|
1, 1, 0,
|
||||||
|
{
|
||||||
|
backgroundPixel: white, eventMask: Exposure|PointerMotion
|
||||||
|
}
|
||||||
|
);
|
||||||
|
X.MapWindow(wid);
|
||||||
|
return wid;
|
||||||
|
}
|
||||||
|
|
||||||
|
var wid = createWindow();
|
||||||
|
var wid1 = createWindow();
|
||||||
|
|
||||||
|
var gc = X.AllocID();
|
||||||
|
X.CreateGC(gc, wid, { foreground: black, background: white } );
|
||||||
|
|
||||||
|
X.on('event', function(ev) {
|
||||||
|
//console.log(ev);
|
||||||
|
if (ev.type == 12)
|
||||||
|
{
|
||||||
|
// expose
|
||||||
|
} else if (ev.type == 6) {
|
||||||
|
X.PolyPoint(0, ev.wid, gc, [ev.x, ev.y]);
|
||||||
|
// send copy of event to the second window
|
||||||
|
if (ev.wid == wid) // don't send it from second window
|
||||||
|
{
|
||||||
|
// set window in the event we are sending
|
||||||
|
var n = wid1;
|
||||||
|
var offset = 12;
|
||||||
|
var buf = ev.rawData;
|
||||||
|
buf[offset++] = n & 0xff;
|
||||||
|
buf[offset++] = (n >> 8) & 0xff;
|
||||||
|
buf[offset++] = (n >> 16) & 0xff;
|
||||||
|
buf[offset++] = (n >> 24) & 0xff;
|
||||||
|
|
||||||
|
X.SendEvent(wid1, 1, PointerMotion, ev.rawData);
|
||||||
|
} else {
|
||||||
|
console.log('GotData!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
X.on('error', function(e) {
|
||||||
|
console.log(e);
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue