node-x11/test/wndwrap.js
2011-07-15 09:51:47 +10:00

56 lines
1.4 KiB
JavaScript

var EventEmitter = require('events').EventEmitter;
var util = require('util'); // util.inherits
function Window(parent, x, y, w, h, bg)
{
if (parent.constructor && parent.constructor.name == 'XClient')
{
this.xclient = parent;
if (!this.xclient.rootWindow)
{
// quick hack
var rootWnd = {
id: this.xclient.display.screen[0].root,
xclient: this.xclient
};
rootWnd.parent = null;
this.parent = this.xclient.rootWnd;
this.xclient.rootWindow = rootWnd;
}
this.parent = this.xclient.rootWindow;
} else {
this.parent = parent;
this.xclient = parent.xclient;
}
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.bg = bg;
this.id = this.xclient.AllocID();
this.xclient.CreateWindow(
this.id, this.parent.id, this.x, this.y, this.w, this.h, 1, 1, 0, { backgroundPixel: this.bg, eventMask: 0x00000040 }
);
this.map();
// very ineffitient this way! :)
var wnd = this;
this.xclient.on('event', function(ev)
{
if (ev.type == 6 && ev.wid == wnd.id)
{
wnd.emit('mousemove', ev);
}
});
}
util.inherits(Window, EventEmitter);
Window.prototype.map = function() {
this.xclient.MapWindow(this.id);
}
Window.prototype.unmap = function() {
this.xclient.UnapWindow(this.id);
}
module.exports = Window;