From 243651b4d8f19ad35d0f282c8c84c8482c6597ec Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Thu, 21 Feb 2013 10:32:38 +0100 Subject: [PATCH] Add ConfigureWindow core request - Update requests based on ConfigureWindow to use the new implementation. - Add sibling field in valueMask.ConfigureWindow. - Add new tests. --- lib/corereqs.js | 81 ++++++++++++++++++++++++++++++++++++---- test/configure-window.js | 79 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+), 7 deletions(-) create mode 100644 test/configure-window.js diff --git a/lib/corereqs.js b/lib/corereqs.js index 28f884f..1addd8f 100644 --- a/lib/corereqs.js +++ b/lib/corereqs.js @@ -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 }); } ], diff --git a/test/configure-window.js b/test/configure-window.js new file mode 100644 index 0000000..cc6c9f7 --- /dev/null +++ b/test/configure-window.js @@ -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); + }); +});