Merge pull request #70 from Champii/master

CreateCursor, valueMask and format
This commit is contained in:
Andrey Sidorov 2014-09-24 08:46:14 +10:00
commit 3e3846d6e6
42 changed files with 500 additions and 412 deletions

View file

@ -15,7 +15,7 @@ var ButtonRelease = x11.eventMask.ButtonRelease;
var kbdImg = require('./node-jpg').readJpeg('./keyboard.jpg');
var keycoords = require('./coordinates');
// from https://github.com/substack/node-keysym
// from https://github.com/substack/node-keysym
var keysyms = require('./keysyms').records;
var ks2name = {};
for (var k in keysyms)
@ -23,18 +23,18 @@ for (var k in keysyms)
var kk2name = {};
x11.createClient(function(err, display)
x11.createClient(function(err, display)
{
var X = display.client;
X.require('big-requests', function(BigReq)
var X = display.client;
X.require('big-requests', function(err, BigReq)
{
X.require('render', function(Render) {
X.require('render', function(err, Render) {
X.Render = Render;
BigReq.Enable(function(err, maxLen)
{
var min = display.min_keycode;
var max = display.max_keycode;
X.GetKeyboardMapping(min, max-min, function(err, list)
X.GetKeyboardMapping(min, max-min, function(err, list)
{
// map keycode to key name
for (var i=0; i < list.length; ++i)
@ -62,26 +62,26 @@ function main(X)
var win = X.AllocID();
X.CreateWindow(
win, root,
0, 0, kbdImg.width, kbdImg.height,
win, root,
0, 0, kbdImg.width, kbdImg.height,
0, 0, 0, 0,
{
backgroundPixel: white, eventMask: Exposure|KeyPress|ButtonPress
{
backgroundPixel: white, eventMask: Exposure|KeyPress|ButtonPress
}
);
X.MapWindow(win);
var win1 = X.AllocID();
X.CreateWindow(
win1, root,
0, 0, kbdImg.width, kbdImg.height,
win1, root,
0, 0, kbdImg.width, kbdImg.height,
0, 0, 0, 0,
{
backgroundPixel: white, eventMask: Exposure|KeyPress|ButtonPress
{
backgroundPixel: white, eventMask: Exposure|KeyPress|ButtonPress
}
);
X.MapWindow(win1);
var gc = X.AllocID();
X.CreateGC(gc, win);
@ -103,15 +103,15 @@ function main(X)
var picKbd = X.AllocID();
X.PutImage(2, pixmapKbd, gc, kbdImg.width, kbdImg.height, 0, 0, 0, 24, kbdImg.data);
Render.CreatePicture(picKbd, pixmapKbd, Render.rgb24);
var pixmapHeat = X.AllocID();
X.CreatePixmap(pixmapHeat, win, 32, kbdImg.width, kbdImg.height);
var picHeat = X.AllocID();
Render.CreatePicture(picHeat, pixmapHeat, Render.rgba32);
var picWin = X.AllocID();
Render.CreatePicture(picWin, win, Render.rgb24);
var picWin1 = X.AllocID();
Render.CreatePicture(picWin1, win1, Render.rgb24);
@ -135,12 +135,12 @@ function main(X)
mindist = dist;
}
}
Render.Composite(3, picKbd, 0, picWin, 0, 0, 0, 0, 0, 0, kbdImg.width, kbdImg.height);
Render.Composite(3, picHeatPush, 0, picWin, 0, 0, 0, 0, x -150/2, y-150/2, 150, 150);
} if (ev.type == 2) {
var name = kk2name[ev.keycode];
for (var n in name)
{
@ -152,7 +152,7 @@ function main(X)
Render.Composite(3, picHeatPush, 0, picHeat, 0, 0, 0, 0, pt[0] -150/2, pt[1]-150/2, 150, 150);
Render.Composite(3, picHeatPush, 0, picWin1, 0, 0, 0, 0, pt[0] -150/2, pt[1]-150/2, 150, 150);
break;
} else {
//console.log(name);

View file

@ -294,7 +294,7 @@ x11.createClient(function(error, display) {
var root = display.screen[0].root;
var width = 500;
var height = 500;
X.require('glx', function(GLX) {
X.require('glx', function(err, GLX) {
var depth = 24;
findBestVisual(display, function(err, visual) {

View file

@ -13,7 +13,7 @@ var listId = 1;
x11.createClient(function(err, display) {
var X = display.client;
var root = display.screen[0].root;
X.require('glx', function(GLX) {
X.require('glx', function(err, GLX) {
var visual = 0;
var visuals = display.screen[0].depths[24];
for (visual in visuals) {

View file

@ -304,7 +304,7 @@ x11.createClient(function(err, display) {
var root = display.screen[0].root;
var width = 1000;
var height = 1000;
X.require('glx', function(GLX) {
X.require('glx', function(err, GLX) {
var visual = 0xa1;
var win = X.AllocID();
X.CreateWindow(win, root, 0, 0, width, height, 0, 0, 0, 0, { eventMask: eventmask });

View file

@ -8,7 +8,7 @@ for(var i=0; i < 20000; ++i) {
var xclient = x11.createClient(function(err, display) {
var X = display.client;
var root = display.screen[0].root;
X.require('glx', function(GLX) {
X.require('glx', function(err, GLX) {
var screen = 0;
var isDirect = 0;
var ctx = X.AllocID();

View file

@ -10,10 +10,10 @@ var gradNo = 0;
var xclient = x11.createClient(function(err, display) {
X = display.client;
var root = display.screen[0].root;
X.require('render', function(rendExt) {
X.require('render', function(err, rendExt) {
Render = rendExt;
var wid = X.AllocID();
var white = display.screen[0].white_pixel;
var black = display.screen[0].black_pixel;
X.CreateWindow(wid, root, 10, 10, 400, 300, 0, 0, 0, 0, { backgroundPixel: white, eventMask: PointerMotion|ButtonPress|ButtonRelease });
@ -36,8 +36,8 @@ var xclient = x11.createClient(function(err, display) {
function draw(x, y) {
Render.Composite(3, pictGrad[gradNo], 0, pict, 0, 0, 0, 0, x-50, y-50, 100, 100);
}
}
X.on('event', function(ev) {
if (ev.type == 4 && ev.keycode == 1)
pressed = true;
@ -45,14 +45,14 @@ var xclient = x11.createClient(function(err, display) {
pressed = false;
else if (ev.type == 5 && ev.keycode == 4)
{
gradNo--;
gradNo--;
if (gradNo < 0)
gradNo = 0;
console.log(gradNo);
}
else if (ev.type == 5 && ev.keycode == 5)
{
gradNo++;
gradNo++;
if (gradNo > 9)
gradNo = 9;
console.log(gradNo);

View file

@ -7,7 +7,7 @@ var Exposure = x11.eventMask.Exposure;
x11.createClient(function(err, display)
{
var X = display.client;
X.require('render', function(Render) {
X.require('render', function(err, Render) {
var root = display.screen[0].root;
main(root, X, Render);
});
@ -15,7 +15,7 @@ x11.createClient(function(err, display)
function main(root, X, Render) {
var win, picWin, pic, gc;
win = X.AllocID();
@ -39,7 +39,7 @@ function main(root, X, Render) {
Render.CreatePicture(logoPicture, logoPixmap, Render.rgb24);
var winPicture = X.AllocID();
Render.CreatePicture(winPicture, win, Render.rgb24);
X.on('event', function(ev) {
if (ev.name == 'Expose')
Render.Composite(3, logoPicture, 0, winPicture, 0, 0, 0, 0, 0, 0, logo.width, logo.height);

View file

@ -9,21 +9,21 @@ var x11 = require('../../lib');
x11.createClient(
function(err, display) {
var X = display.client;
X.require('render', function(Render) {
X.require('render', function(err, Render) {
var root = display.screen[0].root;
var win = X.AllocID();
var white = display.screen[0].white_pixel;
var black = display.screen[0].black_pixel;
X.CreateWindow(win, root, 0, 0, 500, 500, 0, 0, 0, 0,
{
backgroundPixel: white,
X.CreateWindow(win, root, 0, 0, 500, 500, 0, 0, 0, 0,
{
backgroundPixel: white,
eventMask: x11.eventMask.Exposure | x11.eventMask.ButtonPress | x11.eventMask.PointerMotion
});
X.MapWindow(win);
var picture = X.AllocID();
Render.CreatePicture(picture, win, Render.rgb24, { polyEdge: 1, polyMode: 0 } );
Render.CreatePicture(picture, win, Render.rgb24, { polyEdge: 1, polyMode: 0 } );
var pixmap = X.AllocID();
X.CreatePixmap(pixmap, win, 32, 2500, 2500);
var pix_pict = X.AllocID();
@ -34,30 +34,30 @@ x11.createClient(
//RenderRadialGradient(pic_grad, [0,0], [1000,100], 10, 1000,
//RenderConicalGradient(pic_grad, [250,250], 360,
[
[0, [0,0,0,0x3000 ] ],
[0.1, [0xfff, 0, 0xffff, 0x1000] ] ,
[0.25, [0xffff, 0, 0xfff, 0x3000] ] ,
[0.5, [0xffff, 0, 0xffff, 0x4000] ] ,
[1, [0xffff, 0xffff, 0, 0x8000] ]
[0, [0,0,0,0x3000 ] ],
[0.1, [0xfff, 0, 0xffff, 0x1000] ] ,
[0.25, [0xffff, 0, 0xfff, 0x3000] ] ,
[0.5, [0xffff, 0, 0xffff, 0x4000] ] ,
[1, [0xffff, 0xffff, 0, 0x8000] ]
]);
var pic_grad1 = X.AllocID();
Render.ConicalGradient(pic_grad1, [250,250], 10,
[
[0, [0,0,0,0x5000 ] ],
[0.1, [0xfff, 0, 0xffff, 0x3000] ] ,
[0.25, [0xffff, 0, 0xfff, 0x2000] ] ,
[0.5, [0xffff, 0, 0xffff, 0x1000] ] ,
[1, [0xffff, 0xffff, 0, 0x8000] ]
[0, [0,0,0,0x5000 ] ],
[0.1, [0xfff, 0, 0xffff, 0x3000] ] ,
[0.25, [0xffff, 0, 0xfff, 0x2000] ] ,
[0.5, [0xffff, 0, 0xffff, 0x1000] ] ,
[1, [0xffff, 0xffff, 0, 0x8000] ]
]);
var pic_grad2 = X.AllocID();
Render.RadialGradient(pic_grad2, [250,250], [250,250], 0, 250,
[
[0, [0,0,0,0x5000 ] ],
[0, [0,0,0,0x5000 ] ],
[0.99, [0xffff, 0xffff, 0, 0xffff] ],
[1, [0xffff, 0xffff, 0, 0x0] ]
[1, [0xffff, 0xffff, 0, 0x0] ]
]);
var pixmap1 = X.AllocID();
@ -112,7 +112,7 @@ x11.createClient(
draw();
} else {
draw();
}
}
});
});
}

View file

@ -4,7 +4,7 @@ var PointerMotion = x11.eventMask.PointerMotion;
var xclient = x11.createClient(function(err, display) {
var X = display.client;
var root = display.screen[0].root;
display.client.require('render', function(Render) {
display.client.require('render', function(err, Render) {
var wid = X.AllocID();
var white = display.screen[0].white_pixel;
varblack = display.screen[0].black_pixel;
@ -24,8 +24,8 @@ var xclient = x11.createClient(function(err, display) {
function draw(x, y) {
Render.Composite(3, pictGrad, 0, pict, 0, 0, 0, 0, x-26, y-26, 52, 52);
}
}
X.on('event', function(ev) {
draw(ev.x, ev.y);
});

View file

@ -39,7 +39,7 @@ function padWidth(buf, width) {
var xclient = x11.createClient({ debug: true }, function(err, display) {
var X = display.client;
var root = display.screen[0].root;
display.client.require('render', function(Render) {
display.client.require('render', function(err, Render) {
var wid = X.AllocID();
var white = display.screen[0].white_pixel;
varblack = display.screen[0].black_pixel;

View file

@ -3,18 +3,18 @@ var x11 = require('../../lib');
x11.createClient(function(err, display) {
var X = display.client;
var root = display.screen[0].root;
X.require('apple-wm', function(AppleWM) {
X.require('apple-wm', function(err, AppleWM) {
//AppleWM.SetFrontProcess();
//AppleWM.CanQuit(true);
//AppleWM.CanQuit(true);
AppleWM.SelectInput(AppleWM.NotifyMask.All)
/*
for (level in AppleWM.WindowLevel)
{
var win = X.AllocID();
X.CreateWindow(win, root, 0, 0, 300, 300);
X.MapWindow(win);
X.ChangeProperty(0, win, X.atoms.WM_NAME, X.atoms.STRING, 8, level);
X.ChangeProperty(0, win, X.atoms.WM_NAME, X.atoms.STRING, 8, level);
AppleWM.SetWindowLevel(win, AppleWM.WindowLevel[level]);
};
*/
@ -22,7 +22,7 @@ x11.createClient(function(err, display) {
var win1 = X.AllocID();
X.CreateWindow(win1, root, 0, 0, 300, 300);
X.MapWindow(win1);
X.ChangeProperty(0, win1, X.atoms.WM_NAME, X.atoms.STRING, 8, "parent");
X.ChangeProperty(0, win1, X.atoms.WM_NAME, X.atoms.STRING, 8, "parent");
var win2 = X.AllocID();
X.CreateWindow(win2, root, 0, 0, 200, 200);
X.MapWindow(win2);
@ -37,12 +37,12 @@ x11.createClient(function(err, display) {
// (screen, window, frameClass, attr, ix, iy, iw, ih, ox, oy, ow, oh, titleLength)
var gc = X.AllocID();
X.CreateGC(gc, win);
function r(v) { var res = parseInt(Math.random()*v); console.log(res); return res;}
function r(v) { var res = parseInt(Math.random()*v); console.log(res); return res;}
function df() { X.PolyFillRectangle(win, gc, [0, 0, 1000, 1000]); AppleWM.FrameDraw(0, win, 65535, r(65535), 30, 30, 500, 50, 0, 0, 550, 100, "title title");}
//setInterval(df, 100);
X.on('event', function(ev) { console.log("Event", ev); df(); });
});
X.on('error', function(err) { console.log("Error", err); });
});

View file

@ -3,8 +3,8 @@ var x11 = require('../../lib');
x11.createClient(function(err, display) {
var X = display.client;
var root = display.screen[0].root;
X.require('composite', function(Composite) {
X.require('damage', function(Damage) {
X.require('composite', function(err, Composite) {
X.require('damage', function(err, Damage) {
var wid = parseInt(process.argv[2]);
//Composite.GetOverlayWindow(wid, function(err, overlayid) {
// console.log("OVERLAY:", err, overlayid);

View file

@ -3,7 +3,7 @@ var x11 = require('../../lib');
x11.createClient(function(err, display) {
var X = display.client;
var root = display.screen[0].root;
X.require('damage', function(Damage) {
X.require('damage', function(err, Damage) {
console.log(Damage);
var id = parseInt(process.argv[2]);
var damage = X.AllocID();
@ -14,5 +14,5 @@ x11.createClient(function(err, display) {
});
});
X.on('error', function(err) { console.log(err); });
});

View file

@ -3,7 +3,7 @@ var x11 = require('../../lib');
x11.createClient(function(err, display) {
var X = display.client;
var root = display.screen[0].root;
X.require('fixes', function(Fixes) {
X.require('fixes', function(err, Fixes) {
console.log(Fixes);
var win = X.AllocID();
X.CreateWindow(win, root, 0, 0, 100, 100);

View file

@ -23,7 +23,7 @@ x11.createClient(function(err, display) {
if (err) throw err;
var X = display.client;
X.require('render', function(Render) {
X.require('render', function(err, Render) {
var root = display.screen[0].root;
var white = display.screen[0].white_pixel;

View file

@ -3,7 +3,7 @@ var x11 = require('../../lib');
x11.createClient(function(err, display) {
var X = display.client;
var root = display.screen[0].root;
X.require('randr', function(Randr) {
X.require('randr', function(err, Randr) {
//console.log(Randr);
//Randr.QueryVersion(1, 4, console.log);
Randr.SelectInput(root, Randr.NotifyMask.ScreenChange);

View file

@ -3,11 +3,11 @@ var x11 = require('../../lib');
x11.createClient(function(err, display) {
var X = display.client;
var root = display.screen[0].root;
X.require('shape', function(Shape) {
X.require('shape', function(err, Shape) {
var win = X.AllocID();
X.CreateWindow(win, root, 0, 0, 200, 200);
var gc = X.AllocID();
X.CreateGC(gc, win);
X.CreateGC(gc, win);
//X.MapWindow(win);
Shape.SelectInput(win, 1);
Shape.InputSelected(win, function(err, isSelected) {
@ -23,5 +23,5 @@ x11.createClient(function(err, display) {
});
});
X.on('error', function(err) { console.log(err); });
});

View file

@ -7,7 +7,7 @@ x11.createClient(function(err, display) {
X.SetScreenSaver(20, 10, 2, 2);
X.require('screen-saver', function(SS) {
X.require('screen-saver', function(err, SS) {
SS.SelectInput(root, SS.eventMask.Notify|SS.eventMask.Cycle);
//console.log(SS);
//setTimeout(function() {
@ -15,7 +15,7 @@ x11.createClient(function(err, display) {
//}, 5000);
setInterval(function() {
SS.QueryInfo(root, function(err, info) {
console.log(info.until);
console.log(info.until);
//SS.SelectInput(root, SS.eventMask.Notify|SS.eventMask.Cycle);
});
}, 1000);
@ -24,5 +24,5 @@ x11.createClient(function(err, display) {
});
});
X.on('error', function(err) { console.log(err); });
});

View file

@ -25,18 +25,18 @@ x11.createClient(function(err, display) {
var cmid = X.AllocID();
var depth = 32;
X.CreateColormap(cmid, root, visual, 0); // 0=AllocNone, 1 AllocAll
X.CreateColormap(cmid, root, visual, 0); // 0=AllocNone, 1 AllocAll
X.CreateWindow(wid, root, 10, 10, 168, 195, 1, depth, 1, visual, { eventMask: x11.eventMask.Exposure, colormap: cmid, backgroundPixel: 0, borderPixel: 0 });
X.MapWindow(wid);
var gc = X.AllocID();
X.require('render', function(Render) {
X.require('render', function(err, Render) {
var pict = X.AllocID();
Render.CreatePicture(pict, wid, Render.rgba32);
var gradients = [];
function randomLinear() {
var stops = [];
for (var i=0; i<3; ++i)
@ -49,8 +49,8 @@ x11.createClient(function(err, display) {
parseInt(Math.random()*65535),
parseInt(Math.random()*65535),
parseInt(Math.random()*65535)]]);
console.log(colors);
console.log(colors);
var gradient = X.AllocID();
Render.LinearGradient(gradient, [0, 0], [100+parseInt(Math.random()*500), parseInt(100+Math.random()*300)], colors);
@ -64,7 +64,7 @@ x11.createClient(function(err, display) {
var gid = parseInt(Math.random()*gradients.length);
console.log(gradients[gid]);
Render.Composite(1, gradients[gid], 0, pict, 0, 0, 0, 0, 0, 0, 400, 300);
}, 2000);
}, 2000);
});
//X.CreateGC(gc, wid, { foreground: black, background: white } );
//setInterval(function() {

View file

@ -3,7 +3,7 @@ var x11 = require('../../lib');
x11.createClient(function(err, display) {
var X = display.client;
var root = display.screen[0].root;
X.require('xc-misc', function(Misc) {
X.require('xc-misc', function(err, Misc) {
var xid = X.AllocID();
console.log("first ID from connection: " + xid);
debugger;
@ -15,5 +15,5 @@ x11.createClient(function(err, display) {
});
});
X.on('error', function(err) { console.log("Error", err); });
});

View file

@ -3,7 +3,7 @@ var x11 = require('../../lib');
var xclient = x11.createClient(function(err, display) {
var X = display.client;
var root = display.screen[0].root;
display.client.require('xtest', function(Test) {
display.client.require('xtest', function(err, Test) {
console.log(Test);
setInterval(function() {
Test.FakeInput(Test.KeyPress, 65, 0, root, 0, 0); // space

View file

@ -30,8 +30,8 @@ var KeyPress = x11.eventMask.KeyPress;
var KeyRelease = x11.eventMask.KeyRelease;
x11.createClient(function(err, display) {
var X = display.client;
X.require('big-requests', function(BigReq) {
var X = display.client;
X.require('big-requests', function(err, BigReq) {
BigReq.Enable(function(err, maxLen) {
var keycode2keysym = [];
var min = display.min_keycode;
@ -54,19 +54,19 @@ x11.createClient(function(err, display) {
var wid = X.AllocID();
X.CreateWindow(wid, root, 0, 0, r.width, r.height);
X.ChangeWindowAttributes(wid, {
backgroundPixel: black,
eventMask: Exposure|PointerMotion|ButtonPress|ButtonRelease|KeyPress|KeyRelease
X.ChangeWindowAttributes(wid, {
backgroundPixel: black,
eventMask: Exposure|PointerMotion|ButtonPress|ButtonRelease|KeyPress|KeyRelease
});
X.ChangeProperty(0, wid, X.atoms.WM_NAME, X.atoms.STRING, 8, r.title);
X.MapWindow(wid);
var gc = X.AllocID();
X.CreateGC(gc, wid, { foreground: black, background: white } );
//var pixbuf = X.AllocID();
//X.CreatePixmap(pixbuf, wid, 32, r.width, r.height);
//var pic = X.AllocID();
//var pic = X.AllocID();
//Render.CreatePicture(pic, pixbuf, Render.rgba32);
var buttonsState = 0;
@ -86,7 +86,7 @@ x11.createClient(function(err, display) {
// set button bit
if (ev.type == 4)
buttonsState |= buttonBit;
else
else
buttonsState &= ~buttonBit;
r.pointerEvent(ev.x, ev.y, buttonsState);
} else if (ev.type == 2 || ev.type == 3) {
@ -121,7 +121,7 @@ x11.createClient(function(err, display) {
});
}); // r.on('connect)
}); // GetKeyboardMapping
}); // GetKeyboardMapping
}); // BigReq.Enable
}); // require('big-requests

View file

@ -80,7 +80,7 @@ function ManageWindow(wid)
x11.createClient(function(err, display) {
X = display.client;
X.require('render', function(Render) {
X.require('render', function(err, Render) {
X.Render = Render;
root = display.screen[0].root;

View file

@ -6,70 +6,207 @@ var hexy = require('./hexy').hexy;
var valueMask = {
CreateWindow: {
backgroundPixmap: 0x00000001,
backgroundPixel : 0x00000002,
borderPixmap : 0x00000004,
borderPixel : 0x00000008,
bitGravity : 0x00000010,
winGravity : 0x00000020,
backingStore : 0x00000040,
backingPlanes : 0x00000080,
backingPixel : 0x00000100,
overrideRedirect: 0x00000200,
saveUnder : 0x00000400,
eventMask : 0x00000800,
doNotPropagateMask: 0x00001000,
colormap : 0x00002000,
cursor : 0x00004000
backgroundPixmap : {
mask: 0x00000001,
format: 'L'
},
backgroundPixel : {
mask: 0x00000002,
format: 'L'
},
borderPixmap : {
mask: 0x00000004,
format: 'L'
},
borderPixel : {
mask: 0x00000008,
format: 'L'
},
bitGravity : {
mask: 0x00000010,
format: 'C'
},
winGravity : {
mask: 0x00000020,
format: 'C'
},
backingStore : {
mask: 0x00000040,
format: 'C'
},
backingPlanes : {
mask: 0x00000080,
format: 'L'
},
backingPixel : {
mask: 0x00000100,
format: 'L'
},
overrideRedirect : {
mask: 0x00000200,
format: 'C'
},
saveUnder : {
mask: 0x00000400,
format: 'C'
},
eventMask : {
mask: 0x00000800,
format: 'L'
},
doNotPropagateMask : {
mask: 0x00001000,
format: 'L'
},
colormap : {
mask: 0x00002000,
format: 'L'
},
cursor : {
mask: 0x00004000,
format: 'L'
}
},
CreateGC: {
'function' : 0x00000001, // TODO: alias? _function?
planeMask : 0x00000002,
foreground : 0x00000004,
background : 0x00000008,
lineWidth : 0x00000010,
lineStyle : 0x00000020,
capStyle : 0x00000040,
joinStyle : 0x00000080,
fillStyle : 0x00000100,
fillRule : 0x00000200,
tile : 0x00000400,
stipple : 0x00000800,
tileStippleXOrigin: 0x00001000,
tileStippleYOrigin: 0x00002000,
font : 0x00004000,
subwindowMode: 0x00008000,
graphicsExposures: 0x00010000,
clipXOrigin : 0x00020000,
clipYOrigin : 0x00040000,
clipMask : 0x00080000,
dashOffset : 0x00100000,
dashes : 0x00200000,
arcMode : 0x00400000
'function' : { // TODO: alias? _function?
mask: 0x00000001,
format: 'C'
},
planeMask : {
mask: 0x00000002,
format: 'L'
},
foreground : {
mask: 0x00000004,
format: 'L'
},
background : {
mask: 0x00000008,
format: 'L'
},
lineWidth : {
mask: 0x00000010,
format: 'S'
},
lineStyle : {
mask: 0x00000020,
format: 'C'
},
capStyle : {
mask: 0x00000040,
format: 'C'
},
joinStyle : {
mask: 0x00000080,
format: 'C'
},
fillStyle : {
mask: 0x00000100,
format: 'C'
},
fillRule : {
mask: 0x00000200,
format: 'C'
},
tile : {
mask: 0x00000400,
format: 'L'
},
stipple : {
mask: 0x00000800,
format: 'L'
},
tileStippleXOrigin : {
mask: 0x00001000,
format: 's'
},
tileStippleYOrigin : {
mask: 0x00002000,
format: 's'
},
font : {
mask: 0x00004000,
format: 'L'
},
subwindowMode : {
mask: 0x00008000,
format: 'C'
},
graphicsExposures : {
mask: 0x00010000,
format: 'C'
},
clipXOrigin : {
mask: 0x00020000,
format: 'S'
},
clipYOrigin : {
mask: 0x00040000,
format: 'S'
},
clipMask : {
mask: 0x00080000,
format: 'L'
},
dashOffset : {
mask: 0x00100000,
format: 'S'
},
dashes : {
mask: 0x00200000,
format: 'C'
},
arcMode : {
mask: 0x00400000,
format: 'C'
}
},
ConfigureWindow: {
x: 0x000001,
y: 0x000002,
width: 0x000004,
height: 0x000008,
borderWidth: 0x000010,
sibling: 0x000020,
stackMode: 0x000040
x : {
mask: 0x000001,
format: 'sxx'
},
y : {
mask: 0x000002,
format: 'sxx'
},
width : {
mask: 0x000004,
format: 'Sxx'
},
height : {
mask: 0x000008,
format: 'Sxx'
},
borderWidth : {
mask: 0x000010,
format: 'Sxx'
},
sibling : {
mask: 0x000020,
format: 'L'
},
stackMode : {
mask: 0x000040,
format: 'Cxxx'
}
}
};
var valueMaskName = {};
for (var req in valueMask) {
var masks = valueMask[req];
var names = valueMaskName[req] = {};
for (var m in masks)
names[masks[m]] = m;
names[masks[m].mask] = m;
}
function packValueMask(reqname, values)
{
var bitmask = 0;
var masksList = [];
var format = '';
var reqValueMask = valueMask[reqname];
var reqValueMaskName = valueMaskName[reqname];
@ -78,7 +215,7 @@ function packValueMask(reqname, values)
for (var v in values)
{
var valueBit = reqValueMask[v];
var valueBit = reqValueMask[v].mask;
if (!valueBit)
throw new Error(reqname + ': incorrect value param ' + v);
masksList.push(valueBit);
@ -89,9 +226,10 @@ function packValueMask(reqname, values)
for (m in masksList)
{
var valueName = reqValueMaskName[masksList[m]];
format += reqValueMask[valueName].format
args.push( values[valueName] );
}
return [bitmask, args]
return [format, bitmask, args]
}
/*
@ -132,45 +270,21 @@ var templates = {
if (values === undefined)
values = {}
var packetLength = 8 + (values ? Object.keys(values).length : 0);
var format = 'CCSLLssSSSSLL';
// create bitmask
var bitmask = 0;
// TODO: slice from function arguments?
var args = [1, depth, packetLength, id, parentId, x, y, width, height, borderWidth, _class, visual];
// TODO: the code is a little bit mess
// additional values need to be packed in the following way:
// bitmask (bytes #24 to #31 in the packet) - 32 bit indicating what adittional arguments we supply
// values list (bytes #32 .. #32+4*num_values) in order of corresponding bits TODO: it's actually not 4*num. Some values are 4b ytes, some - 1 byte
// TODO: replace with packValueMask
var masksList = [];
for (var v in values)
{
var valueBit = valueMask['CreateWindow'][v];
if (!valueBit)
{
throw new Error('CreateWindow: incorrect value param ' + v);
}
masksList.push(valueBit);
bitmask |= valueBit;
format += 'L'; // TODO: not all values are 4 bytes CARD32!!!
}
// values packed in order of corresponding bit
masksList.sort();
// set bits to indicate additional values we are sending in this request
args.push(bitmask);
// add values in the order of the bits
// TODO: maybe it's better just to scan all 32 bits anstead of sorting parameters we are actually have?
for (var m in masksList)
{
var valueName = valueMaskName['CreateWindow'][masksList[m]];
args.push( values[valueName] );
}
var vals = packValueMask('CreateWindow', values);
var packetLength = 8 + (values ? vals[2].length : 0);
var args = [1, depth, packetLength, id, parentId, x, y, width, height, borderWidth, _class, visual];
format += vals[0];
args.push(vals[1]);
args = args.concat(vals[2]);
return [format, args];
}
@ -178,16 +292,13 @@ var templates = {
ChangeWindowAttributes:[
function(wid, values) {
var format = 'CxSLL';
var packetLength = 3 + (values ? Object.keys(values).length : 0);
var format = 'CxSLSxx';
var vals = packValueMask('CreateWindow', values);
var args = [2, packetLength, wid, vals[0]];
var valArr = vals[1];
for (var v in valArr)
{
format += 'L';
args.push(valArr[v]);
}
var packetLength = 3 + (values ? vals[2].length : 0);
var args = [2, packetLength, wid, vals[1]];
var valArr = vals[2];
format += vals[0];
args = args.concat(valArr);
return [format, args];
}
],
@ -248,60 +359,11 @@ var templates = {
* }
*/
function(win, options) {
var format = 'CxSLSxx';
var n = 3;
var mask = 0;
var params = [];
if (options.x !== undefined) {
mask |= valueMask.ConfigureWindow.x;
format += 'sxx';
params.push(options.x);
++ n;
}
if (options.y !== undefined) {
mask |= valueMask.ConfigureWindow.y;
format += 'sxx';
params.push(options.y);
++ n;
}
if (options.width !== undefined) {
mask |= valueMask.ConfigureWindow.width;
format += 'Sxx';
params.push(options.width);
++ n;
}
if (options.height !== undefined) {
mask |= valueMask.ConfigureWindow.height;
format += 'Sxx';
params.push(options.height);
++ n;
}
if (options.borderWidth !== undefined) {
mask |= valueMask.ConfigureWindow.borderWidth;
format += 'Sxx';
params.push(options.borderWidth);
++ n;
}
if (options.sibling !== undefined) {
mask |= valueMask.ConfigureWindow.sibling;
format += 'L';
params.push(options.sibling);
++ n;
}
if (options.stackMode !== undefined) {
mask |= valueMask.ConfigureWindow.stackMode;
format += 'Cxxx';
params.push(options.stackMode);
++ n;
}
return [format, [12, n, win, mask].concat(params)];
var vals = packValueMask('ConfigureWindow', options);
var format = 'CxSLSxx' + vals[0];
var args = [12, vals[2].length + 3, win, vals[1]];
args = args.concat(vals[2]);
return [format, args];
}
],
@ -412,7 +474,7 @@ var templates = {
},
function(buf, format) {
var res = buf.unpack('LLL');
var res = buf.unpack('LLL');
var prop = {};
prop.type = res[0];
prop.bytesAfter = res[1];
@ -651,19 +713,35 @@ var templates = {
}
],
FreePixmap: [
function (pixmap) {
return [ 'CxSL', [54, 2, pixmap] ];
}
],
CreateCursor: [
function(cid, source, mask, foreRGB, backRGB, x, y) {
foreR = foreRGB.R
foreG = foreRGB.G
foreB = foreRGB.B
backR = backRGB.R
backG = backRGB.G
backB = backRGB.B
return [ 'CxSLLLSSSSSSSS', [93, 8, cid, source, mask, foreR, foreG, foreB, backR, backG, backB, x, y] ];
}
],
// opcode 55
CreateGC: [
function(cid, drawable, values) {
var format = 'CxSLLL';
var packetLength = 4 + (values ? Object.keys(values).length : 0);
var args = [55, packetLength, cid, drawable];
var vals = packValueMask('CreateGC', values);
args.push(vals[0]); // values bitmask
var valArr = vals[1];
for (var v in valArr)
{
format += 'L'; // TODO: we know format string length in advance and += inefficient for string
args.push(valArr[v]);
}
var packetLength = 4 + (values ? vals[2].length : 0);
var args = [55, packetLength, cid, drawable];
format += vals[0]
args.push(vals[1]); // values bitmask
args = args.concat(vals[2])
return [format, args];
}
],
@ -671,9 +749,9 @@ var templates = {
ChangeGC: [
function(cid, values) {
var format = 'CxSLL';
var packetLength = 3 + (values ? Object.keys(values).length : 0);
var args = [56, packetLength, cid];
var vals = packValueMask('CreateGC', values);
var packetLength = 3 + (values ? vals[2].length : 0);
var args = [56, packetLength, cid];
args.push(vals[0]); // values bitmask
var valArr = vals[1];
for (var v in valArr)
@ -776,7 +854,7 @@ var templates = {
return {
depth: depth,
visualId: visualId,
data: buf.slice(20)
data: buf.slice(24)
};
}
],

View file

@ -18,10 +18,10 @@ var xutil = require('../xutil');
#define X_AppleWMAttachTransient 13
*/
exports.requireExt = function(display, callback)
exports.requireExt = function(display, callback)
{
var X = display.client;
X.QueryExtension('Apple-WM', function(err, ext) {
X.QueryExtension('Apple-WM', function(err, ext) {
if (!ext.present)
callback(new Error('extension not available'));
@ -32,7 +32,7 @@ exports.requireExt = function(display, callback)
X.pack_stream.pack('CCS', [ext.majorOpcode, 0, 1]);
X.replies[X.seq_num] = [
function(buf, opt) {
var res = buf.unpack('SSL');
var res = buf.unpack('SSL');
return res;
},
cb
@ -52,7 +52,7 @@ exports.requireExt = function(display, callback)
X.pack_stream.pack('CCSSSSSSSSSSS', [ext.majorOpcode, 1, 6, frame_class, frame_rect, ix, iy, iw, ih, ox, oy, ow, oh, cb]);
X.replies[X.seq_num] = [
function(buf, opt) {
var res = buf.unpack('SSSS');
var res = buf.unpack('SSSS');
return {
x: res[0],
y: res[1],
@ -64,7 +64,7 @@ exports.requireExt = function(display, callback)
];
X.pack_stream.flush();
}
ext.FrameHitTest = function(frame_class, px, py, ix, iy, iw, ih, ox, oy, ow, oh, cb)
{
X.seq_num++;
@ -80,7 +80,7 @@ exports.requireExt = function(display, callback)
}
// from /usr/include/Xplugin.h
// from /usr/include/Xplugin.h
ext.FrameClass = {
DecorLarge: 1,
Reserved1: 2,
@ -107,7 +107,7 @@ exports.requireExt = function(display, callback)
CloseBoxClicked: 0x800,
CollapseBoxClicked: 0x1000,
ZoomBoxClicked: 0x2000,
GrowBox: 0x4000
GrowBox: 0x4000
};
ext.FrameDraw = function(screen, window, frameClass, attr, ix, iy, iw, ih, ox, oy, ow, oh, title)
@ -189,7 +189,7 @@ exports.requireExt = function(display, callback)
var reqlen = 8;
var extlength = 0;
items.forEach(function(i) {
});
}
@ -209,13 +209,13 @@ exports.requireExt = function(display, callback)
X.pack_stream.flush();
}
callback(ext);
callback(null, ext);
/*
ext.QueryVersion(function(err, vers) {
ext.major = vers[0];
ext.minor = vers[1];
ext.patch = vers[2];
callback(ext);
callback(null, ext);
});
*/
@ -248,7 +248,7 @@ exports.requireExt = function(display, callback)
CopyToPasteboard: 0
}
};
X.eventParsers[ext.firstEvent + ext.events.AppleWMControllerNotify] =
X.eventParsers[ext.firstEvent + ext.events.AppleWMActivationNotify] =
X.eventParsers[ext.firstEvent + ext.events.AppleWMPasteboardNotify] = function(type, seq, extra, code, raw)

View file

@ -1,11 +1,11 @@
// http://www.x.org/releases/X11R7.6/doc/bigreqsproto/bigreq.html
// TODO: move to templates
exports.requireExt = function(display, callback)
exports.requireExt = function(display, callback)
{
var X = display.client;
X.QueryExtension('BIG-REQUESTS', function(err, ext) {
X.QueryExtension('BIG-REQUESTS', function(err, ext) {
if (!ext.present)
return callback(new Error('extension not available'));
@ -21,6 +21,6 @@ exports.requireExt = function(display, callback)
];
X.pack_stream.flush();
}
callback(ext);
callback(null, ext);
});
}

View file

@ -14,15 +14,15 @@
var x11 = require('..');
// TODO: move to templates
exports.requireExt = function(display, callback)
exports.requireExt = function(display, callback)
{
var X = display.client;
X.QueryExtension('Composite', function(err, ext) {
X.QueryExtension('Composite', function(err, ext) {
if (!ext.present)
return callback(new Error('extension not available'));
ext.Redirect = {
ext.Redirect = {
Automatic: 0,
Manual: 1
};
@ -33,7 +33,7 @@ exports.requireExt = function(display, callback)
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 0, 3, clientMaj, clientMin]);
X.replies[X.seq_num] = [
function(buf, opt) {
var res = buf.unpack('LL');
var res = buf.unpack('LL');
return res;
},
callback
@ -82,7 +82,7 @@ exports.requireExt = function(display, callback)
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 6, 3, window, pixmap]);
X.pack_stream.flush();
}
ext.GetOverlayWindow = function(window, callback)
{
X.seq_num++;
@ -96,19 +96,22 @@ exports.requireExt = function(display, callback)
];
X.pack_stream.flush();
}
ext.ReleaseOverlayWindow = function(window)
{
X.seq_num++;
X.pack_stream.pack('CCSL', [ext.majorOpcode, 8, 2, window]);
X.pack_stream.flush();
}
// currently version 0.4 TODO: bump up with coordinate translations
ext.QueryVersion(0, 4, function(err, vers) {
if (err)
return callback(err);
ext.major = vers[0];
ext.minor = vers[1];
callback(ext);
callback(null, ext);
});
});
}

View file

@ -3,19 +3,19 @@
var x11 = require('..');
// TODO: move to templates
exports.requireExt = function(display, callback)
exports.requireExt = function(display, callback)
{
var X = display.client;
X.QueryExtension('DAMAGE', function(err, ext) {
X.QueryExtension('DAMAGE', function(err, ext) {
if (!ext.present)
return callback(new Error('extension not available'));
ext.ReportLevel = {
ext.ReportLevel = {
RawRectangles: 0,
DeltaRectangles: 1,
BoundingBox: 2,
NonEmpty: 3
NonEmpty: 3
};
ext.QueryVersion = function(clientMaj, clientMin, callback)
@ -24,7 +24,7 @@ exports.requireExt = function(display, callback)
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 0, 3, clientMaj, clientMin]);
X.replies[X.seq_num] = [
function(buf, opt) {
var res = buf.unpack('LL');
var res = buf.unpack('LL');
return res;
},
callback
@ -59,18 +59,20 @@ exports.requireExt = function(display, callback)
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 4, 3, damage, region]);
X.pack_stream.flush();
}
ext.QueryVersion(1, 1, function(err, vers) {
if (err)
return callback(err);
ext.major = vers[0];
ext.minor = vers[1];
callback(ext);
callback(null, ext);
});
ext.events = {
DamageNotify: 0
}
X.eventParsers[ext.firstEvent + ext.events.DamageNotify] = function(type, seq, extra, code, raw)
X.eventParsers[ext.firstEvent + ext.events.DamageNotify] = function(type, seq, extra, code, raw)
{
var event = {};
event.level = code;
@ -80,16 +82,16 @@ exports.requireExt = function(display, callback)
event.damage = values[0];
event.time = values[1];
event.area = {
x: values[2],
y: values[3],
w: values[4],
h: values[5]
x: values[2],
y: values[3],
w: values[4],
h: values[5]
};
event.geometry = {
x: values[6],
y: values[7],
w: values[8],
h: values[9]
x: values[6],
y: values[7],
w: values[8],
h: values[9]
};
event.name = 'DamageNotify';
return event;

View file

@ -94,7 +94,7 @@ exports.requireExt = function(display, callback)
X.pack_stream.flush();
};
callback(ext);
callback(null, ext);
});
};

View file

@ -7,7 +7,7 @@ function parse_rectangle(buf, pos) {
if (!pos) {
pos = 0;
}
return {
x : buf[pos],
y : buf[pos + 1],
@ -16,10 +16,10 @@ function parse_rectangle(buf, pos) {
}
}
exports.requireExt = function(display, callback)
exports.requireExt = function(display, callback)
{
var X = display.client;
X.QueryExtension('XFIXES', function(err, ext) {
X.QueryExtension('XFIXES', function(err, ext) {
if (!ext.present)
return callback(new Error('extension not available'));
@ -30,7 +30,7 @@ exports.requireExt = function(display, callback)
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 0, 3, clientMaj, clientMin]);
X.replies[X.seq_num] = [
function(buf, opt) {
var res = buf.unpack('LL');
var res = buf.unpack('LL');
return res;
},
callback
@ -68,7 +68,7 @@ exports.requireExt = function(display, callback)
X.pack_stream.pack(format, args);
X.pack_stream.flush();
}
ext.CreateRegionFromWindow = function(region, wid, kind) {
X.seq_num ++;
X.pack_stream.pack('CCSLLCxxx', [ ext.majorOpcode, 7, 4, region, wid, kind ]);
@ -92,7 +92,7 @@ exports.requireExt = function(display, callback)
X.pack_stream.pack('CCSLss', [ ext.majorOpcode, 17, 3, region, dx, dy ]);
X.pack_stream.flush();
}
ext.FetchRegion = function(region, cb) {
X.seq_num ++;
X.pack_stream.pack('CCSL', [ ext.majorOpcode, 19, 2, region ]);
@ -110,7 +110,7 @@ exports.requireExt = function(display, callback)
for (var i = 0; i < n_rectangles; ++ i) {
reg.rectangles.push(parse_rectangle(res, 4 + (i << 2)));
}
return reg;
},
cb
@ -120,16 +120,18 @@ exports.requireExt = function(display, callback)
}
ext.QueryVersion(5, 0, function(err, vers) {
if (err)
return callback(err);
ext.major = vers[0];
ext.minor = vers[1];
callback(ext);
callback(null, ext);
});
ext.events = {
DamageNotify: 0
}
X.eventParsers[ext.firstEvent + ext.events.DamageNotify] = function(type, seq, extra, code, raw)
X.eventParsers[ext.firstEvent + ext.events.DamageNotify] = function(type, seq, extra, code, raw)
{
var event = {};
event.level = code;
@ -139,16 +141,16 @@ exports.requireExt = function(display, callback)
event.damage = values[0];
event.time = values[1];
event.area = {
x: values[2],
y: values[3],
w: values[4],
h: values[5]
x: values[2],
y: values[3],
w: values[4],
h: values[5]
};
event.geometry = {
x: values[6],
y: values[7],
w: values[8],
h: values[9]
x: values[6],
y: values[7],
w: values[8],
h: values[9]
};
event.name = 'DamageNotify';
return event;

View file

@ -319,7 +319,7 @@ exports.requireExt = function(display, callback)
};
});
callback(ext);
callback(null, ext);
});
}

View file

@ -3,15 +3,15 @@
var x11 = require('..');
// TODO: move to templates
exports.requireExt = function(display, callback)
exports.requireExt = function(display, callback)
{
var X = display.client;
X.QueryExtension('RANDR', function(err, ext) {
X.QueryExtension('RANDR', function(err, ext) {
if (!ext.present)
return callback(new Error('extension not available'));
//ext.ReportLevel = {
//ext.ReportLevel = {
//};
ext.QueryVersion = function(clientMaj, clientMin, callback)
@ -198,7 +198,7 @@ exports.requireExt = function(display, callback)
pos += res_modes[i + 11];
}
return resources;
},
cb
@ -223,7 +223,7 @@ exports.requireExt = function(display, callback)
height : res[4],
mode : res[5],
rotation : res[6],
rotations : res[7]
rotations : res[7]
};
pos += 24;
@ -239,7 +239,7 @@ exports.requireExt = function(display, callback)
X.pack_stream.flush();
},
X.eventParsers[ext.firstEvent + ext.events.RRScreenChangeNotify] = function(type, seq, extra, code, raw)
X.eventParsers[ext.firstEvent + ext.events.RRScreenChangeNotify] = function(type, seq, extra, code, raw)
{
var event = {};
event.raw = raw;
@ -263,6 +263,6 @@ exports.requireExt = function(display, callback)
return event;
};
callback(ext);
callback(null, ext);
});
}

View file

@ -530,6 +530,8 @@ exports.requireExt = function(display, callback)
// 11 - colormap or none
ext.QueryPictFormat(function(err, formats) {
if (err)
return callback(err);
for (var i=0; i < formats.formats.length; ++i) {
var f = formats.formats[i];
if (f[2] == 1 && f[10] == 1)
@ -542,7 +544,7 @@ exports.requireExt = function(display, callback)
if (f[2] == 8 && f[10] == 255)
ext.a8 = f[0];
}
callback(ext);
callback(null, ext);
});
[

View file

@ -3,10 +3,10 @@
var x11 = require('..');
// TODO: move to templates
exports.requireExt = function(display, callback)
exports.requireExt = function(display, callback)
{
var X = display.client;
X.QueryExtension('MIT-SCREEN-SAVER', function(err, ext) {
X.QueryExtension('MIT-SCREEN-SAVER', function(err, ext) {
if (!ext.present)
return callback(new Error('extension not available'));
@ -18,7 +18,7 @@ exports.requireExt = function(display, callback)
X.pack_stream.pack('CCSCCxx', [ext.majorOpcode, 0, 2, clientMaj, clientMin]);
X.replies[X.seq_num] = [
function(buf, opt) {
var res = buf.unpack('CC');
var res = buf.unpack('CC');
return res;
},
cb
@ -26,18 +26,18 @@ exports.requireExt = function(display, callback)
X.pack_stream.flush();
}
ext.State = {
ext.State = {
Off: 0,
On: 1,
Disabled: 2
};
ext.Kind = {
ext.Kind = {
Blanked: 0,
Internal: 1,
External: 2
};
ext.QueryInfo = function(drawable, callback)
{
X.seq_num++;
@ -51,7 +51,7 @@ exports.requireExt = function(display, callback)
info.until = res[1];
info.idle = res[2];
info.eventMask = res[3];
info.kind = res[4]
info.kind = res[4]
return info;
},
callback
@ -73,10 +73,11 @@ exports.requireExt = function(display, callback)
}
ext.QueryVersion(1, 1, function(err, vers) {
if (err)
return callback(err);
ext.major = vers[0];
ext.minor = vers[1];
callback(ext);
callback(null, ext);
});
ext.events = {
@ -89,7 +90,7 @@ exports.requireExt = function(display, callback)
Cycle: 2
}
X.eventParsers[ext.firstEvent + ext.events.ScreenSaverNotify] = function(type, seq, extra, code, raw)
X.eventParsers[ext.firstEvent + ext.events.ScreenSaverNotify] = function(type, seq, extra, code, raw)
{
var event = {};
event.state = code;

View file

@ -3,7 +3,7 @@
var x11 = require('..');
// TODO: move to templates
exports.requireExt = function(display, callback)
exports.requireExt = function(display, callback)
{
function captureStack()
{
@ -14,12 +14,12 @@ exports.requireExt = function(display, callback)
}
var X = display.client;
X.QueryExtension('SHAPE', function(err, ext) {
X.QueryExtension('SHAPE', function(err, ext) {
if (!ext.present)
return callback(new Error('extension not available'));
ext.Kind = {
ext.Kind = {
Bounding: 0,
Clip: 1,
Input: 2
@ -40,7 +40,7 @@ exports.requireExt = function(display, callback)
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 0, 1]);
X.replies[X.seq_num] = [
function(buf, opt) {
var res = buf.unpack('SS');
var res = buf.unpack('SS');
return res;
},
cb
@ -78,13 +78,13 @@ exports.requireExt = function(display, callback)
X.pack_stream.flush();
}
callback(ext);
callback(null, ext);
/*
ext.QueryVersion(function(err, version) {
ext.major = version[0];
ext.minor = version[1];
callback(ext);
callback(null, ext);
});
*/
});

View file

@ -3,10 +3,10 @@
var x11 = require('..');
// TODO: move to templates
exports.requireExt = function(display, callback)
exports.requireExt = function(display, callback)
{
var X = display.client;
X.QueryExtension('XC-MISC', function(err, ext) {
X.QueryExtension('XC-MISC', function(err, ext) {
if (!ext.present)
return callback(new Error('extension not available'));
@ -17,7 +17,7 @@ exports.requireExt = function(display, callback)
X.pack_stream.pack('CCSSS', [ext.majorOpcode, 0, 2, clientMaj, clientMin]);
X.replies[X.seq_num] = [
function(buf, opt) {
var res = buf.unpack('SS');
var res = buf.unpack('SS');
return res;
},
cb
@ -31,7 +31,7 @@ exports.requireExt = function(display, callback)
X.pack_stream.pack('CCS', [ext.majorOpcode, 1, 1]);
X.replies[X.seq_num] = [
function(buf, opt) {
var res = buf.unpack('LL');
var res = buf.unpack('LL');
return {
startId: res[0],
count: res[1]
@ -60,9 +60,11 @@ exports.requireExt = function(display, callback)
}
ext.QueryVersion(1, 1, function(err, vers) {
if (err)
return callback(err);
ext.major = vers[0];
ext.minor = vers[1];
callback(ext);
callback(null, ext);
});
});
}

View file

@ -2,10 +2,10 @@
var x11 = require('..');
// TODO: move to templates
exports.requireExt = function(display, callback)
exports.requireExt = function(display, callback)
{
var X = display.client;
X.QueryExtension('XTEST', function(err, ext) {
X.QueryExtension('XTEST', function(err, ext) {
if (!ext.present)
return callback(new Error('extension not available'));
@ -39,7 +39,7 @@ exports.requireExt = function(display, callback)
X.pack_stream.flush();
}
callback(ext);
callback(null, ext);
});
}

View file

@ -29,7 +29,7 @@ function XClient(stream, displayNum, screenNum, options)
// TODO: this is probably not used
this.core_requests = {};
this.ext_requests = {};
this.displayNum = displayNum;
this.screenNum = screenNum;
this.authHost = os.hostname();
@ -39,10 +39,10 @@ function XClient(stream, displayNum, screenNum, options)
// data received from stream is dispached to
// read requests set by calls to .unpack and .unpackTo
//stream.pipe(pack_stream);
// pack_stream write requests are buffered and
// flushed to stream as result of call to .flush
// TODO: listen for drain event and flush automatically
// TODO: listen for drain event and flush automatically
//pack_stream.pipe(stream);
var client = this;
pack_stream.on('data', function( data ) {
@ -55,7 +55,7 @@ function XClient(stream, displayNum, screenNum, options)
//console.error(hexy(data, {prefix: 'to unpacker '}));
//for (var i=0; i < data.length; ++i)
// console.log('>>> ' + data[i]);
pack_stream.write(data);
pack_stream.write(data);
});
stream.on('end', function() {
client.emit('end');
@ -67,7 +67,7 @@ function XClient(stream, displayNum, screenNum, options)
var cli = this;
if (cli.options.debug) {
this.seq_num_ = 0;
this.seq2stack = {}; // debug: map seq_num to stack at the moment request was issued
this.seq2stack = {}; // debug: map seq_num to stack at the moment request was issued
Object.defineProperty(cli, "seq_num", {
set : function(v) {
cli.seq_num_ = v;
@ -84,7 +84,7 @@ function XClient(stream, displayNum, screenNum, options)
this.seq_num = 0;
}
// in/out packets indexed by sequence ID
this.replies = {};
this.atoms = stdatoms;
@ -96,15 +96,15 @@ function XClient(stream, displayNum, screenNum, options)
return names;
})();
this.eventMask = em;
this.event_consumers = {}; // maps window id to eventemitter TODO: bad name
this.eventParsers = {};
this.errorParsers = {};
this.eventParsers = {};
this.errorParsers = {};
this.importRequestsFromTemplates(this, coreRequests);
this.startHandshake();
this._closing = false;
}
@ -143,20 +143,20 @@ XClient.prototype.importRequestsFromTemplates = function(target, reqs)
for (var r in reqs)
{
// r is request name
target[r] = (function(reqName) {
target[r] = (function(reqName) {
var reqFunc = function req_proxy() {
if (client._closing)
throw new Error('client is in closing state');
// simple overflow handling (this means that currently there is no way to have more than 65535 requests in the queue
// TODO: edge cases testing
// TODO: edge cases testing
if (client.seq_num == 65535)
client.seq_num = 0;
else
client.seq_num++;
// is it fast?
var args = Array.prototype.slice.call(req_proxy.arguments);
@ -185,20 +185,20 @@ XClient.prototype.importRequestsFromTemplates = function(target, reqs)
client.pending_atoms[client.seq_num] = value;
}
}
// call template with input arguments (not including callback which is last argument TODO currently with callback. won't hurt)
//reqPack = reqTemplate.call(args);
var reqPack = reqTemplate.apply(this, req_proxy.arguments);
var reqPack = reqTemplate.apply(this, req_proxy.arguments);
var format = reqPack[0];
var requestArguments = reqPack[1];
if (callback)
this.replies[this.seq_num] = [reqReplTemplate[1], callback];
client.pack_stream.pack(format, requestArguments);
var b = client.pack_stream.write_queue[0];
client.pack_stream.flush();
} else if (templateType == 'Array'){
if (reqName === 'GetAtomName') {
var atom = req_proxy.arguments[0];
@ -211,12 +211,12 @@ XClient.prototype.importRequestsFromTemplates = function(target, reqs)
client.pending_atoms[client.seq_num] = atom;
}
}
var format = reqTemplate[0];
var requestArguments = [];
for (var a = 0; a < reqTemplate[1].length; ++a)
requestArguments.push(reqTemplate[1][a]);
requestArguments.push(reqTemplate[1][a]);
for (var a in args)
requestArguments.push(args[a]);
@ -249,8 +249,8 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf)
var event = {}; // TODO: constructor & base functions
// Remove the most significant bit. See Chapter 1, Event Format section in X11 protocol
// specification
type = type & 0x7F;
event.type = type;
type = type & 0x7F;
event.type = type;
event.seq = seq;
var extUnpacker = this.eventParsers[type];
@ -265,7 +265,7 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf)
// TODO: use unpackTo???
event.name = [,,'KeyPress', 'KeyRelease', 'ButtonPress', 'ButtonRelease', 'MotionNotify'][type]
event.time = extra;
event.keycode = code;
event.keycode = code;
event.root = values[0];
event.wid = values[1];
event.child = values[2];
@ -352,13 +352,13 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf)
event.width = values[3]
event.height = values[4]
event.borderWidth = values[5];
//
//
// The value-mask indicates which components were specified in
// the request. The value-mask and the corresponding values are reported as given
// in the request. The remaining values are filled in from the current geometry of the
// window, except in the case of sibling and stack-mode, which are reported as None
// and Above (respectively) if not given in the request.
event.mask = values[6];
event.mask = values[6];
// 322, [ 12582925, 0, 0, 484, 316, 1, 12, 0
//console.log([extra, code, values]);
} else if (type == 28) {// PropertyNotify
@ -398,7 +398,7 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf)
event.type = raw.readUInt32LE(0);
var format = (code === 32) ? 'LLLLL' : (code === 16) ? 'SSSSSSSSSS' : 'CCCCCCCCCCCCCCCCCCCC';
event.data = raw.unpack(format, 4);
} else if (type == 34) {
} else if (type == 34) {
event.name = 'MappingNotify';
event.request = headerBuf[4];
event.firstKeyCode = headerBuf[5];
@ -421,7 +421,7 @@ XClient.prototype.expectReplyHeader = function()
var bad_value = res[3];
if (type == 0)
{
{
var error_code = res[1];
var error = new Error();
error.error = error_code;
@ -433,7 +433,7 @@ XClient.prototype.expectReplyHeader = function()
// unpack error packet (32 bytes for all error types, 8 of them in CCSL header)
client.pack_stream.get(24, function(buf) {
var res = buf.unpack('SC');
error.message = xerrors.errorText[error_code];
error.badParam = bad_value;
@ -444,7 +444,7 @@ XClient.prototype.expectReplyHeader = function()
if (extUnpacker) {
extUnpacker(error, error_code, seq_num, bad_value, buf);
}
var handler = client.replies[seq_num];
if (handler) {
var callback = handler[1];
@ -458,7 +458,7 @@ XClient.prototype.expectReplyHeader = function()
} else
client.emit('error', error);
client.expectReplyHeader();
} );
} );
return;
} else if (type > 1)
{
@ -466,20 +466,20 @@ XClient.prototype.expectReplyHeader = function()
var extra = res[3];
var code = res[1];
var ev = client.unpackEvent(type, seq_num, extra, code, buf, headerBuf);
// 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);
var ee = client.event_consumers[ev.wid];
if (ee) {
ee.emit('event', ev);
}
client.expectReplyHeader();
} );
} );
return;
}
@ -488,7 +488,7 @@ XClient.prototype.expectReplyHeader = function()
var bodylength = 24 + length_total*4; // 24 is rest if 32-bytes header
client.pack_stream.get( bodylength, function( data ) {
var handler = client.replies[seq_num];
if (handler) {
var unpack = handler[0];
@ -504,8 +504,8 @@ XClient.prototype.expectReplyHeader = function()
}
// wait for new packet from server
client.expectReplyHeader();
});
}
});
}
);
}
@ -514,7 +514,7 @@ XClient.prototype.startHandshake = function()
var client = this;
handshake.writeClientHello(this.pack_stream, this.displayNum, this.authHost);
handshake.readServerHello(this.pack_stream, function(display)
handshake.readServerHello(this.pack_stream, function(display)
{
// TODO: readServerHello can set error state in display
// emit error in that case
@ -522,7 +522,7 @@ XClient.prototype.startHandshake = function()
client.display = display;
display.client = client;
client.emit('connect', display);
});
});
}
XClient.prototype.require = function(extName, callback)
@ -558,7 +558,7 @@ module.exports.createClient = function(options, initCb)
var screenNum = displayMatch[3];
if (!screenNum)
screenNum = 0;
// open stream
var stream;
var socketPath;
@ -569,13 +569,13 @@ module.exports.createClient = function(options, initCb)
if (process.platform == 'darwin' || process.platform == 'mac')
{
// socket path on OSX is /tmp/launch-(some id)/org.x:0
if (display[0] == '/')
if (display[0] == '/')
{
socketPath = display;
}
}
} else if(host == '127.0.0.1') //TODO check if it's consistent with xlib (DISPLAY=127.0.0.1:0 -> local unix socket or port 6000?)
socketPath = '/tmp/.X11-unix/X' + displayNum;
}
}
//socketPath = '/tmp/.X11-unix/X' + displayNum;
if(socketPath)
{
@ -592,7 +592,9 @@ module.exports.createClient = function(options, initCb)
client.on('connect', function(display) {
// opt-in BigReq
if (!options.disableBigRequests) {
client.require('big-requests', function(BigReq) {
client.require('big-requests', function(err, BigReq) {
if (err)
return initCb(err)
BigReq.Enable(function(err, maxLen) {
display.max_request_length = maxLen;
cbCalled = true;

View file

@ -22,34 +22,35 @@ describe('ConfigureWindow', function() {
});
});
client.on('error', done);
client.on('error', function (err) {
console.error('Error : ', err);
});
});
it('should ResizeWindow correctly to 200x300 pixels', function(done) {
var self = this;
this.X.ResizeWindow(this.wid, 200, 300);
this.X.once('event', function(ev) {
ev.type.should.equal(22); /* ConfigureNotify */
ev.height.should.equal(300);
ev.width.should.equal(200);
done();
});
this.X.ResizeWindow(this.wid, 200, 300);
});
it('should MoveWindow correctly to x: 100, y: 150 pixels', function(done) {
var self = this;
this.X.MoveWindow(this.wid, 100, 150);
this.X.once('event', function(ev) {
ev.type.should.equal(22); /* ConfigureNotify */
ev.x.should.equal(100);
ev.y.should.equal(150);
done();
});
this.X.MoveWindow(this.wid, 100, 150);
});
it('should MoveResizeWindow correctly to x: 200, y: 250 and 500x100 pixels', function(done) {
var self = this;
this.X.MoveResizeWindow(this.wid, 200, 250, 500, 100);
this.X.once('event', function(ev) {
ev.type.should.equal(22); /* ConfigureNotify */
ev.x.should.equal(200);
@ -58,22 +59,23 @@ describe('ConfigureWindow', function() {
ev.width.should.equal(500);
done();
});
this.X.MoveResizeWindow(this.wid, 200, 250, 500, 100);
});
it('should RaiseWindow correctly', function(done) {
var self = this;
this.X.RaiseWindow(this.wid);
this.X.once('event', function(ev) {
ev.type.should.equal(22); /* ConfigureNotify */
ev.aboveSibling.should.equal(self.wid_helper);
done();
});
this.X.RaiseWindow(this.wid);
});
after(function(done) {
this.X.DestroyWindow(this.wid);
this.X.DestroyWindow(this.wid_helper);
this.X.terminate();
this.X.on('end', done);
this.X.terminate();
});
});

View file

@ -12,13 +12,10 @@ describe('DPMS extension', function() {
if (!err) {
display = dpy;
X = display.client;
X.require('dpms', function(ext) {
if (util.isError(ext)) {
done(ext);
} else {
dpms = ext;
done();
}
X.require('dpms', function(err, ext) {
should.not.exist(err);
dpms = ext;
done();
});
} else {
done(err);

View file

@ -11,8 +11,8 @@ describe('RANDR extension', function() {
self.X = dpy.client;
self.screen = dpy.screen[0];
self.root = self.screen.root;
self.X.require('randr', function(ext) {
util.isError(ext).should.equal(false);
self.X.require('randr', function(err, ext) {
err.should.equal(null);
self.randr = ext;
/* We HAVE to QueryVersion before using it. Otherwise it does not work as expected */
self.randr.QueryVersion(1, 2, done);

View file

@ -12,13 +12,10 @@ describe('XTEST extension', function() {
if (!err) {
display = dpy;
X = display.client;
X.require('xtest', function(ext) {
if (util.isError(ext)) {
done(ext);
} else {
xtest = ext;
done();
}
X.require('xtest', function(err, ext) {
should.not.exist(err);
xtest = ext;
done();
});
} else {
done(err);