Add ConfigureWindow core request

- Update requests based on ConfigureWindow to use the new implementation.
- Add sibling field in valueMask.ConfigureWindow.
- Add new tests.
This commit is contained in:
Santiago Gimeno 2013-02-21 10:32:38 +01:00
parent 3f1b8e5442
commit 243651b4d8
2 changed files with 153 additions and 7 deletions

View file

@ -50,7 +50,8 @@ var valueMask = {
width: 0x000004,
height: 0x000008,
borderWidth: 0x000010,
stackMode: 0x000020
sibling: 0x000020,
stackMode: 0x000040
}
};
@ -223,30 +224,96 @@ module.exports = {
[ 'CxSL', [10, 2] ]
],
ConfigureWindow: [
/*
* options : {
* x : x_value,
* y : y_value,
* width : width_value,
* height : height_value,
* borderWidth : borderWidth_value,
* sibling : sibling_value
* }
*/
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;
}
// TODO: remove or leave as a convinient helper? this is actually a ConfigureWindow request
// with width and height argiments & arguments mask
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)];
}
],
ResizeWindow: [
function(win, width, height) {
return ['CxSLSxxSxxSxx', [12, 5, win, 12, width, height]];
return module.exports.ConfigureWindow[0](win, { width : width, height: height });
}
],
MoveWindow: [
function(win, x, y) {
return ['CxSLSxxsxxsxx', [12, 5, win, 3, x, y]];
return module.exports.ConfigureWindow[0](win, { x : x, y: y });
}
],
MoveResizeWindow: [
function(win, x, y, width, height) {
return ['CxSLSxxsxxsxxSxxSxx', [12, 7, win, 15, x, y, width, height]];
return module.exports.ConfigureWindow[0](win, { x : x, y: y, width : width, height: height });
}
],
RaiseWindow: [
function(win) {
return ['CxSLSxxCxxx', [12, 4, win, 64]];
return module.exports.ConfigureWindow[0](win, { stackMode : 0 });
}
],

79
test/configure-window.js Normal file
View file

@ -0,0 +1,79 @@
var x11 = require('../lib');
var should = require('should');
var assert = require('assert');
var util = require('util');
describe('ConfigureWindow', function() {
before(function(done) {
var self = this;
var client = x11.createClient(function(err, dpy) {
should.not.exist(err);
self.X = dpy.client;
self.wid = self.X.AllocID();
self.wid_helper = self.X.AllocID();
self.X.CreateWindow(self.wid, dpy.screen[0].root, 0, 0, 1, 1); // 1x1 pixel window
self.X.CreateWindow(self.wid_helper, dpy.screen[0].root, 0, 0, 1, 1); // 1x1 pixel window
self.X.QueryTree(dpy.screen[0].root, function(err, list) {
should.not.exist(err);
list.children.indexOf(self.wid).should.not.equal(-1);
list.children.indexOf(self.wid_helper).should.not.equal(-1);
self.X.ChangeWindowAttributes(self.wid, { eventMask: x11.eventMask.StructureNotify });
done();
});
});
client.on('error', done);
});
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();
});
});
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();
});
});
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);
ev.y.should.equal(250);
ev.height.should.equal(100);
ev.width.should.equal(500);
done();
});
});
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();
});
});
after(function(done) {
this.X.DestroyWindow(this.wid);
this.X.DestroyWindow(this.wid_helper);
this.X.terminate();
this.X.on('end', done);
});
});