diff --git a/lib/x11/xcore.js b/lib/x11/xcore.js index 8f3ccc1..4fc29bf 100644 --- a/lib/x11/xcore.js +++ b/lib/x11/xcore.js @@ -206,11 +206,12 @@ XClient.prototype.expectReplyHeader = function() // if (error_code == 14) { var res = buf.unpack('LSC'); - error.badPparam = res[0]; // id: GC, WinID, Font, Atom etc; Value + error.badParam = res[0]; // id: GC, WinID, Font, Atom etc; Value error.minorOpcode = res[1]; error.majorOpcode = res[2]; } - client.emit('error', error); + console.log(error); + //client.emit('error', error); client.expectReplyHeader(); } ); return; @@ -220,7 +221,6 @@ XClient.prototype.expectReplyHeader = function() var extra = res[3]; var ev = client.unpackEvent(type, seq_num, extra, buf); client.emit('event', ev); - console.log(ev); var ee = client.event_consumers[ev.wid]; if (ee) { ee.emit('event', ev); diff --git a/test/polypoint.js b/test/polypoint.js index 83f731b..11370bd 100644 --- a/test/polypoint.js +++ b/test/polypoint.js @@ -5,7 +5,6 @@ var Exposure = x11.eventMask.Exposure; var PointerMotion = x11.eventMask.PointerMotion; var pts = []; - xclient.on('connect', function(display) { var X = this; var root = display.screen[0].root; diff --git a/test/testwnd.js b/test/testwnd.js index 5097fe9..d519a33 100644 --- a/test/testwnd.js +++ b/test/testwnd.js @@ -5,33 +5,21 @@ var width = 700; var height = 500; var xclient = x11.createClient(); +var pts = []; + xclient.on('connect', function(display) { - var white = xclient.display.screen[0].white_pixel; - var black = xclient.display.screen[0].black_pixel; - var mainwnd = new Window(xclient, 0, 0, width, height, white); - mainwnd.on('mousemove', function(ev) { - console.log(ev.x, ev.y); + var mainwnd = new Window(xclient, 0, 0, width, height); + mainwnd.on('mousemove', function(ev) + { + pts.push(ev.x); + pts.push(ev.y); + this.gc.drawText(ev.x, ev.y, 'Hello, NodeJS!'); + }); + mainwnd.on('expose', function(ev) { + for (var i=0; i < pts.length/2 ; ++i) + ev.gc.drawText(pts[i], pts[i+1], 'Hello, NodeJS!'); }); - var ch = new Window(mainwnd, 10, 10, 50, 70, black); - ch.on('mousemove', function(ev) { - console.log(ev); - //ch.unmap(); - //setTimeout( function() { ch.map() }, 500); - }); - mainwnd.map(); - /* - for (var x = 0; x < width; x += 20) { - for (var y = 0; y < width; y += 20) { - // TODO: wnd.createChild() ? - var ch = new Window(mainwnd, x + 1, y + 1, 18, 18, 0, black); - //ch.map(); - ch.on('mousemove', function(ev) { - ch.unmap(); - setTimeout( function() { ch.map() }, 500); - }); - } - } - */ + }); diff --git a/test/wndwrap.js b/test/wndwrap.js index f0cb058..8b61315 100644 --- a/test/wndwrap.js +++ b/test/wndwrap.js @@ -1,7 +1,35 @@ +var x11 = require('../lib/x11'); +var Exposure = x11.eventMask.Exposure; +var PointerMotion = x11.eventMask.PointerMotion; + var EventEmitter = require('events').EventEmitter; var util = require('util'); // util.inherits -function Window(parent, x, y, w, h, bg) +function GraphicContext(win) +{ + this.win = win; + this.xclient = win.xclient; + this.id = this.xclient.AllocID(); + win.xclient.CreateGC(this.id, win.id); +} + +GraphicContext.prototype.polyLine = function(points) +{ + this.xclient.PolyLine(0, this.win.id, this.id, points); +} + +GraphicContext.prototype.noop = function() +{ + //testing triggering gc creation +} + +GraphicContext.prototype.drawText = function(x, y, text) +{ + //console.log([0, this.win.id, this.id, x, y, [text]]); + this.xclient.PolyText8(this.win.id, this.id, x, y, [text]); +} + +function Window(parent, x, y, w, h) { if (parent.constructor && parent.constructor.name == 'XClient') { @@ -27,7 +55,8 @@ function Window(parent, x, y, w, h, bg) this.y = y; this.w = w; this.h = h; - this.bg = bg; + this.black = this.xclient.display.screen[0].black_pixel; + this.white = this.xclient.display.screen[0].white_pixel; this.id = this.xclient.AllocID(); var borderWidth = 1; @@ -37,25 +66,38 @@ function Window(parent, x, y, w, h, bg) this.id, this.parent.id, this.x, this.y, this.w, this.h, borderWidth, _class, visual, { - backgroundPixel: this.bg, - eventMask: 0x00000040 + backgroundPixel: this.white, + eventMask: Exposure|PointerMotion } ); - //this.map(); + //this.map(); var wnd = this; eventType2eventName = { - 6: 'mousemove' + 6: 'mousemove', + 12: 'expose' }; var ee = new EventEmitter(); this.xclient.event_consumers[wnd.id] = ee; // TODO: do we need to have wnd as EventEmitter AND EventEmitter stored in event_consumers ? ee.on('event', function( ev ) - { + { + if (ev.type == 12) //Expose + ev.gc = wnd.gc; + wnd.emit(eventType2eventName[ev.type], ev); // convert to mousemove? (ev is already event-spacific) }); // TODO: track delete events and remove wmd from consumers list + + this.__defineGetter__('gc', function() + { + if (!this._gc) + { + this._gc = new GraphicContext(this); + } + return this._gc; + }); } util.inherits(Window, EventEmitter); @@ -67,4 +109,4 @@ Window.prototype.unmap = function() { this.xclient.UnmapWindow(this.id); } -module.exports = Window; +module.exports = Window; \ No newline at end of file