mirror of
https://github.com/danbulant/node-x11
synced 2026-06-24 17:21:47 +00:00
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:
parent
3f1b8e5442
commit
243651b4d8
2 changed files with 153 additions and 7 deletions
|
|
@ -50,7 +50,8 @@ var valueMask = {
|
||||||
width: 0x000004,
|
width: 0x000004,
|
||||||
height: 0x000008,
|
height: 0x000008,
|
||||||
borderWidth: 0x000010,
|
borderWidth: 0x000010,
|
||||||
stackMode: 0x000020
|
sibling: 0x000020,
|
||||||
|
stackMode: 0x000040
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -223,30 +224,96 @@ module.exports = {
|
||||||
[ 'CxSL', [10, 2] ]
|
[ '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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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)];
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
// TODO: remove or leave as a convinient helper? this is actually a ConfigureWindow request
|
|
||||||
// with width and height argiments & arguments mask
|
|
||||||
ResizeWindow: [
|
ResizeWindow: [
|
||||||
function(win, width, height) {
|
function(win, width, height) {
|
||||||
return ['CxSLSxxSxxSxx', [12, 5, win, 12, width, height]];
|
return module.exports.ConfigureWindow[0](win, { width : width, height: height });
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
MoveWindow: [
|
MoveWindow: [
|
||||||
function(win, x, y) {
|
function(win, x, y) {
|
||||||
return ['CxSLSxxsxxsxx', [12, 5, win, 3, x, y]];
|
return module.exports.ConfigureWindow[0](win, { x : x, y: y });
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
MoveResizeWindow: [
|
MoveResizeWindow: [
|
||||||
function(win, x, y, width, height) {
|
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: [
|
RaiseWindow: [
|
||||||
function(win) {
|
function(win) {
|
||||||
return ['CxSLSxxCxxx', [12, 4, win, 64]];
|
return module.exports.ConfigureWindow[0](win, { stackMode : 0 });
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
|
||||||
79
test/configure-window.js
Normal file
79
test/configure-window.js
Normal 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);
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue