Merge pull request #74 from sidorares/fix_create_window

Fix CreateWindow and CreateGC attributes encoding
This commit is contained in:
Andrey Sidorov 2014-12-10 09:01:57 +11:00
commit c54f073b14
4 changed files with 82 additions and 24 deletions

View file

@ -24,15 +24,15 @@ var valueMask = {
},
bitGravity : {
mask: 0x00000010,
format: 'C'
format: 'Cxxx'
},
winGravity : {
mask: 0x00000020,
format: 'C'
format: 'Cxxx'
},
backingStore : {
mask: 0x00000040,
format: 'C'
format: 'Cxxx'
},
backingPlanes : {
mask: 0x00000080,
@ -44,11 +44,11 @@ var valueMask = {
},
overrideRedirect : {
mask: 0x00000200,
format: 'C'
format: 'Cxxx'
},
saveUnder : {
mask: 0x00000400,
format: 'C'
format: 'Cxxx'
},
eventMask : {
mask: 0x00000800,
@ -70,7 +70,7 @@ var valueMask = {
CreateGC: {
'function' : { // TODO: alias? _function?
mask: 0x00000001,
format: 'C'
format: 'Cxxx'
},
planeMask : {
mask: 0x00000002,
@ -86,27 +86,27 @@ var valueMask = {
},
lineWidth : {
mask: 0x00000010,
format: 'S'
format: 'Sxx'
},
lineStyle : {
mask: 0x00000020,
format: 'C'
format: 'Cxxx'
},
capStyle : {
mask: 0x00000040,
format: 'C'
format: 'Cxxx'
},
joinStyle : {
mask: 0x00000080,
format: 'C'
format: 'Cxxx'
},
fillStyle : {
mask: 0x00000100,
format: 'C'
format: 'Cxxx'
},
fillRule : {
mask: 0x00000200,
format: 'C'
format: 'Cxxx'
},
tile : {
mask: 0x00000400,
@ -118,11 +118,11 @@ var valueMask = {
},
tileStippleXOrigin : {
mask: 0x00001000,
format: 's'
format: 'sxx'
},
tileStippleYOrigin : {
mask: 0x00002000,
format: 's'
format: 'sxx'
},
font : {
mask: 0x00004000,
@ -130,19 +130,19 @@ var valueMask = {
},
subwindowMode : {
mask: 0x00008000,
format: 'C'
format: 'Cxxx'
},
graphicsExposures : {
mask: 0x00010000,
format: 'C'
format: 'Cxxx'
},
clipXOrigin : {
mask: 0x00020000,
format: 'S'
format: 'Sxx'
},
clipYOrigin : {
mask: 0x00040000,
format: 'S'
format: 'Sxx'
},
clipMask : {
mask: 0x00080000,
@ -150,15 +150,15 @@ var valueMask = {
},
dashOffset : {
mask: 0x00100000,
format: 'S'
format: 'Sxx'
},
dashes : {
mask: 0x00200000,
format: 'C'
format: 'Cxxx'
},
arcMode : {
mask: 0x00400000,
format: 'C'
format: 'Cxxx'
}
},
ConfigureWindow: {
@ -221,7 +221,12 @@ function packValueMask(reqname, values)
masksList.push(valueBit);
bitmask |= valueBit;
}
masksList.sort();
/* numeric sort */
masksList.sort(function(a, b) {
return a - b;
});
var args = [];
for (m in masksList)
{

View file

@ -9,7 +9,6 @@ describe('ConfigureRequest', function() {
self.X = dpy.client;
self.root = dpy.screen[0].root;
self.wid = self.X.AllocID();
self.wid_helper = self.X.AllocID();
/* self.X acts like a WM */
self.X.ChangeWindowAttributes(self.root, { eventMask: x11.eventMask.SubstructureRedirect });
self.X.CreateWindow(self.wid, self.root, 0, 0, 1, 1); // 1x1 pixel window
@ -30,7 +29,6 @@ describe('ConfigureRequest', function() {
var client = x11.createClient(function(err, dpy) {
should.not.exist(err);
self.X.once('event', function(ev) {
console.log(ev);
ev.name.should.equal('ConfigureRequest');
ev.x.should.equal(0);
ev.y.should.equal(20);

View file

@ -48,4 +48,13 @@ describe('CreateWindow request', function() {
});
});
it('should work with any kind of attributes too', function(done) {
var wid = X.AllocID();
X.CreateWindow(wid, display.screen[0].root, 0, 0, 1, 1, 0, 0, 0, 0, { overrideRedirect : true }); // 1x1 pixel window
X.QueryTree(display.screen[0].root, function(err, list) {
should.not.exist(err);
list.children.should.containEql(wid);
done();
});
});
});

46
test/createGC.js Normal file
View file

@ -0,0 +1,46 @@
var x11 = require('../lib');
var should = require('should');
describe('CreateGC', function() {
before(function(done) {
var self = this;
this.client = x11.createClient(function(err, dpy) {
should.not.exist(err);
self.X = dpy.client;
self.root = dpy.screen[0].root;
self.white = dpy.screen[0].white_pixel;
self.black = dpy.screen[0].black_pixel;
self.wid = self.X.AllocID();
self.X.CreateWindow(self.wid, self.root, 0, 0, 1, 1); // 1x1 pixel window
self.X.MapWindow(self.wid);
self.X.QueryTree(self.root, function(err, list) {
should.not.exist(err);
list.children.indexOf(self.wid).should.not.equal(-1);
done();
});
});
});
it('should create a Graphic Context correctly', function() {
var self = this;
this.client.on('error', function(err) {
should.not.exist(err);
});
this.gc = this.X.AllocID();
this.X.CreateGC(this.gc,
this.wid,
{
foreground: this.black,
background: this.white,
lineStyle : 0
}
);
});
after(function(done) {
this.X.DestroyWindow(this.wid);
this.X.on('end', done);
this.X.terminate();
});
});