From 7c86cedcabdd0a85bd0e9d923de989f4c08cbc54 Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Sat, 6 Dec 2014 23:11:11 +0100 Subject: [PATCH] events: fix ConfigureRequest parsing - Add test that would fail without this change. --- lib/xcore.js | 16 +++++++----- test/configure-request.js | 55 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 test/configure-request.js diff --git a/lib/xcore.js b/lib/xcore.js index 557270f..6df8e7d 100644 --- a/lib/xcore.js +++ b/lib/xcore.js @@ -344,15 +344,17 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf) event.borderWidth = values[6]; event.overrideRedirect = values[7]; } else if (type == 23) { - var values = raw.unpack('LLLssSSS'); - event.name = 'ConfigureRequest' + var values = raw.unpack('LLssSSSS'); + event.name = 'ConfigureRequest'; + event.stackMode = code; event.parent = extra; event.wid = values[0]; - event.x = values[1] - event.y = values[2] - event.width = values[3] - event.height = values[4] - event.borderWidth = values[5]; + event.sibling = values[1]; + event.x = values[2] + event.y = values[3] + event.width = values[4] + event.height = values[5] + event.borderWidth = values[6]; // // The value-mask indicates which components were specified in // the request. The value-mask and the corresponding values are reported as given diff --git a/test/configure-request.js b/test/configure-request.js new file mode 100644 index 0000000..8715e57 --- /dev/null +++ b/test/configure-request.js @@ -0,0 +1,55 @@ +var x11 = require('../lib'); +var should = require('should'); + +describe('ConfigureRequest', function() { + before(function(done) { + var self = this; + var client = x11.createClient(function(err, dpy) { + should.not.exist(err); + 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 + self.X.QueryTree(self.root, function(err, list) { + should.not.exist(err); + list.children.indexOf(self.wid).should.not.equal(-1); + done(); + }); + }); + + client.on('error', function (err) { + console.error('Error : ', err); + }); + }); + + it('should be emitted to the WM if this.wid is configured by a client', function(done) { + var self = this; + 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); + ev.width.should.equal(200); + ev.height.should.equal(300); + ev.wid.should.equal(self.wid); + done(); + }); + + var X = dpy.client; + X.MoveResizeWindow(self.wid, 0, 20, 200, 300); + }); + + client.on('error', done); + }); + + after(function(done) { + this.X.DestroyWindow(this.wid); + this.X.on('end', done); + this.X.terminate(); + }); +});