From 520be559e8b9741e519f67a0e524f401366b68bc Mon Sep 17 00:00:00 2001 From: Michael J M Thomson Date: Fri, 29 May 2015 11:17:34 +1000 Subject: [PATCH 1/3] Add function Rectangles. Fix function Mask --- lib/ext/shape.js | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/lib/ext/shape.js b/lib/ext/shape.js index f328c11..e9df1aa 100644 --- a/lib/ext/shape.js +++ b/lib/ext/shape.js @@ -21,7 +21,7 @@ exports.requireExt = function(display, callback) ext.Kind = { Bounding: 0, - Clip: 1, + Clip: 1, Input: 2 }; @@ -31,12 +31,19 @@ exports.requireExt = function(display, callback) Intersect: 2, Subtract: 3, Invert: 4 - } + }; + + ext.Ordering = { + Unsorted: 0, + YSorted: 1, + YXSorted: 2, + YXBanded: 3 + }; ext.QueryVersion = function(cb) { X.seq_num++; - captureStack(); +// captureStack(); X.pack_stream.pack('CCSLL', [ext.majorOpcode, 0, 1]); X.replies[X.seq_num] = [ function(buf, opt) { @@ -48,18 +55,36 @@ exports.requireExt = function(display, callback) X.pack_stream.flush(); } + // Accepts rectangles as [[x, y, width, height]] + ext.Rectangles = function( op, kind, window, x, y, rectangles, ordering /* = Ordering.Unsorted */ ) + { + if (ordering === undefined) + ordering = ext.Ordering.Unsorted; + + var length = 4 + rectangles.length * 2; + + X.seq_num++; +// captureStack(); + X.pack_stream.pack('CCSCCCxLss', [ext.majorOpcode, 1, length, op, kind, ordering, window, x, y]); + for (var i = 0; i < rectangles.length; ++i) { + var r = rectangles[i]; + X.pack_stream.pack('ssSS', r); + } + X.pack_stream.flush(); + } + ext.Mask = function( op, kind, window, x, y, bitmap ) { X.seq_num++; - captureStack(); - X.pack_stream.pack('CCSCCxxLssL', [ext.majorOpcode, 2, 5, op, kind, x, y, bitmap]); +// captureStack(); + X.pack_stream.pack('CCSCCxxLssL', [ext.majorOpcode, 2, 5, op, kind, window, x, y, bitmap]); X.pack_stream.flush(); } ext.SelectInput = function( window, enable ) { X.seq_num++; - captureStack(); +// captureStack(); X.pack_stream.pack('CCSLCxxx', [ext.majorOpcode, 6, 3, window, enable ]); X.pack_stream.flush(); } @@ -67,7 +92,7 @@ exports.requireExt = function(display, callback) ext.InputSelected = function( window, cb ) { X.seq_num++; - captureStack(); +// captureStack(); X.pack_stream.pack('CCSL', [ext.majorOpcode, 7, 2, window ]); X.replies[X.seq_num] = [ function(buf, opt) { From fafa42e6e67b62e84c385521eeab152f7b5bf932 Mon Sep 17 00:00:00 2001 From: Michael J M Thomson Date: Fri, 29 May 2015 14:28:05 +1000 Subject: [PATCH 2/3] Add Shape Rectangles test. Fix Shape Mask test --- examples/smoketest/shape-rectangles.js | 25 +++++++++++++++++++++++++ examples/smoketest/shapetest.js | 14 +++++++------- 2 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 examples/smoketest/shape-rectangles.js diff --git a/examples/smoketest/shape-rectangles.js b/examples/smoketest/shape-rectangles.js new file mode 100644 index 0000000..4fb29a5 --- /dev/null +++ b/examples/smoketest/shape-rectangles.js @@ -0,0 +1,25 @@ +var x11 = require('../../lib'); + +var Expose = 12; + +x11.createClient(function(err, display) { + var X = display.client; + var root = display.screen[0].root; + X.require('shape', function(err, Shape) { + var win = X.AllocID(); + var black = display.screen[0].black_pixel; + X.CreateWindow(win, root, 0, 0, 200, 200, 0, undefined, X.InputOutput, undefined, + { backgroundPixel: black }); + X.MapWindow(win); + + Shape.Rectangles(Shape.Op.Set, Shape.Kind.Bounding, win, + 0, 0, [ + [40, 40, 40, 40], [120, 40, 40, 40], + [0, 120, 20, 20], [180, 120, 20, 20], + [20, 140, 30, 20], [150, 140, 30, 20], + [50, 160, 100, 20] + ]); + }); + X.on('error', function(err) { console.log(err); }); + +}); diff --git a/examples/smoketest/shapetest.js b/examples/smoketest/shapetest.js index 31ba286..1ceba00 100644 --- a/examples/smoketest/shapetest.js +++ b/examples/smoketest/shapetest.js @@ -6,17 +6,17 @@ x11.createClient(function(err, display) { X.require('shape', function(err, Shape) { var win = X.AllocID(); X.CreateWindow(win, root, 0, 0, 200, 200); - var gc = X.AllocID(); - X.CreateGC(gc, win); - //X.MapWindow(win); + X.MapWindow(win); Shape.SelectInput(win, 1); Shape.InputSelected(win, function(err, isSelected) { console.log("IsSelected: " + isSelected); }); - //var pid = X.AllocID(); - //X.CreatePixmap(pid, win, 2, 200, 200); - //X.PolyText8(pid, gc, 0, 0, ['Hello, Node.JS!', ' Hello, world!']); - //Shape.Mask(Shape.Op.Set, Shape.Kind.Input, win, 0, 0, pid); + var pid = X.AllocID(); + X.CreatePixmap(pid, win, 1, 200, 200); + var gc = X.AllocID(); + X.CreateGC(gc, win); + X.PolyText8(pid, gc, 0, 0, ['Hello, Node.JS!', ' Hello, world!']); + Shape.Mask(Shape.Op.Set, Shape.Kind.Input, win, 0, 0, pid); X.on('event', function(ev) { console.log(ev); From 749b877d9901ede5748104deabcd4571e3a7301b Mon Sep 17 00:00:00 2001 From: Michael J M Thomson Date: Fri, 29 May 2015 16:15:03 +1000 Subject: [PATCH 3/3] Added Shape rectangles example. Fixed shape mask test --- examples/smoketest/shape-rectangles.js | 9 +++------ examples/smoketest/shapetest.js | 17 +++++++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/examples/smoketest/shape-rectangles.js b/examples/smoketest/shape-rectangles.js index 4fb29a5..38c02d4 100644 --- a/examples/smoketest/shape-rectangles.js +++ b/examples/smoketest/shape-rectangles.js @@ -7,13 +7,10 @@ x11.createClient(function(err, display) { var root = display.screen[0].root; X.require('shape', function(err, Shape) { var win = X.AllocID(); - var black = display.screen[0].black_pixel; - X.CreateWindow(win, root, 0, 0, 200, 200, 0, undefined, X.InputOutput, undefined, - { backgroundPixel: black }); + X.CreateWindow(win, root, 0, 0, 200, 200); + X.ChangeWindowAttributes(win, { backgroundPixel: display.screen[0].black_pixel }); X.MapWindow(win); - - Shape.Rectangles(Shape.Op.Set, Shape.Kind.Bounding, win, - 0, 0, [ + Shape.Rectangles(Shape.Op.Set, Shape.Kind.Bounding, win, 0, 0, [ [40, 40, 40, 40], [120, 40, 40, 40], [0, 120, 20, 20], [180, 120, 20, 20], [20, 140, 30, 20], [150, 140, 30, 20], diff --git a/examples/smoketest/shapetest.js b/examples/smoketest/shapetest.js index 1ceba00..7784165 100644 --- a/examples/smoketest/shapetest.js +++ b/examples/smoketest/shapetest.js @@ -6,17 +6,22 @@ x11.createClient(function(err, display) { X.require('shape', function(err, Shape) { var win = X.AllocID(); X.CreateWindow(win, root, 0, 0, 200, 200); + X.ChangeWindowAttributes(win, { backgroundPixel: display.screen[0].white_pixel }); X.MapWindow(win); - Shape.SelectInput(win, 1); + X.ClearArea(win, 0, 0, 200, 200, false); + + Shape.SelectInput(win, true); Shape.InputSelected(win, function(err, isSelected) { console.log("IsSelected: " + isSelected); }); - var pid = X.AllocID(); - X.CreatePixmap(pid, win, 1, 200, 200); + + var bitmap = X.AllocID(); + X.CreatePixmap(bitmap, win, 1, 200, 200); var gc = X.AllocID(); - X.CreateGC(gc, win); - X.PolyText8(pid, gc, 0, 0, ['Hello, Node.JS!', ' Hello, world!']); - Shape.Mask(Shape.Op.Set, Shape.Kind.Input, win, 0, 0, pid); + X.CreateGC(gc, bitmap, { foreground: 1 }); +// X.PolyText8(bitmap, gc, 0, 0, ['Hello, Node.JS!', ' Hello, world!']); + X.PolyFillArc(bitmap, gc, [0, 0, 200, 200, 0, 360 * 64]); + Shape.Mask(Shape.Op.Set, Shape.Kind.Bounding, win, 0, 0, bitmap); X.on('event', function(ev) { console.log(ev);