From 8049e70debf4a45a878e2b9d2a3fe481c72ea106 Mon Sep 17 00:00:00 2001 From: Andrew Start Date: Fri, 4 Aug 2017 11:45:41 -0400 Subject: [PATCH 1/2] Fix ChangeGC. --- lib/corereqs.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/corereqs.js b/lib/corereqs.js index bb20e7c..83f4922 100644 --- a/lib/corereqs.js +++ b/lib/corereqs.js @@ -765,13 +765,9 @@ var templates = { var vals = packValueMask('CreateGC', values); var packetLength = 3 + (values ? vals[2].length : 0); var args = [56, packetLength, cid]; - args.push(vals[0]); // values bitmask - var valArr = vals[1]; - for (var v in valArr) - { - format += 'L'; // TODO: we know format string length in advance and += inefficient for string - args.push(valArr[v]); - } + format += vals[0] + args.push(vals[1]); // values bitmask + args = args.concat(vals[2]) return [format, args]; } ], From da262fcb8d12a45bad930cfdf070a0b14e85cdc8 Mon Sep 17 00:00:00 2001 From: Andrew Start Date: Fri, 4 Aug 2017 12:05:05 -0400 Subject: [PATCH 2/2] Add test for ChangeGC. --- test/changeGC.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 test/changeGC.js diff --git a/test/changeGC.js b/test/changeGC.js new file mode 100644 index 0000000..23f997d --- /dev/null +++ b/test/changeGC.js @@ -0,0 +1,54 @@ +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 + } + ); + + this.X.ChangeGC(this.gc, + { + foreground: 0xffff00, + background: 0x0000ff, + lineStyle : 2 + } + ); + }); + + after(function(done) { + this.X.DestroyWindow(this.wid); + this.X.on('end', done); + this.X.terminate(); + }); +});