mirror of
https://github.com/danbulant/node-x11
synced 2026-05-24 12:35:39 +00:00
pixmap pupport in Window class
This commit is contained in:
parent
be8a5c76d5
commit
6cf8937e2a
4 changed files with 47 additions and 7 deletions
|
|
@ -24,5 +24,5 @@ module.exports.eventMask = {
|
||||||
PropertyChange: 0x00400000,
|
PropertyChange: 0x00400000,
|
||||||
ColormapChange: 0x00800000,
|
ColormapChange: 0x00800000,
|
||||||
OwnerGrabButton: 0x01000000
|
OwnerGrabButton: 0x01000000
|
||||||
// add more names for common masks combinations
|
// TODO: add more names for common masks combinations
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -185,6 +185,16 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw)
|
||||||
event.width = values[2];
|
event.width = values[2];
|
||||||
event.height = values[3];
|
event.height = values[3];
|
||||||
event.count = values[4]; // TODO: ???
|
event.count = values[4]; // TODO: ???
|
||||||
|
} else if (type == 16) { // CreateNotify
|
||||||
|
var values = raw.unpack('LLSSSSS');
|
||||||
|
event.parent = extra;
|
||||||
|
event.wid = values[0];
|
||||||
|
// x, y, width, height, border
|
||||||
|
console.log(event);
|
||||||
|
} else if (type == 19) { // MapNotify
|
||||||
|
var values = raw.unpack('LLC');
|
||||||
|
//event.wid = extra;
|
||||||
|
event.wid = values[0];
|
||||||
}
|
}
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ xclient.on('connect', function(display) {
|
||||||
{
|
{
|
||||||
pts.push(ev.x);
|
pts.push(ev.x);
|
||||||
pts.push(ev.y);
|
pts.push(ev.y);
|
||||||
this.gc.drawText(ev.x, ev.y, 'Hello, NodeJS!');
|
this.gc.text(ev.x, ev.y, 'Hello, NodeJS!');
|
||||||
mainwnd.title = ev.x + ' ' + ev.y;
|
mainwnd.title = ev.x + ' ' + ev.y;
|
||||||
});
|
});
|
||||||
mainwnd.on('expose', function(ev) {
|
mainwnd.on('expose', function(ev) {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ var Exposure = x11.eventMask.Exposure;
|
||||||
var PointerMotion = x11.eventMask.PointerMotion;
|
var PointerMotion = x11.eventMask.PointerMotion;
|
||||||
var ButtonPress = x11.eventMask.ButtonPress;
|
var ButtonPress = x11.eventMask.ButtonPress;
|
||||||
var ButtonRelease = x11.eventMask.ButtonRelease;
|
var ButtonRelease = x11.eventMask.ButtonRelease;
|
||||||
|
var SubstructureNotify = x11.eventMask.SubstructureNotify;
|
||||||
|
var StructureNotify = x11.eventMask.StructureNotify;
|
||||||
|
|
||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
var util = require('util'); // util.inherits
|
var util = require('util'); // util.inherits
|
||||||
|
|
@ -12,7 +14,8 @@ function GraphicContext(win)
|
||||||
this.win = win;
|
this.win = win;
|
||||||
this.xclient = win.xclient;
|
this.xclient = win.xclient;
|
||||||
this.id = this.xclient.AllocID();
|
this.id = this.xclient.AllocID();
|
||||||
win.xclient.CreateGC(this.id, win.id);
|
var screen = this.xclient.display.screen[0];
|
||||||
|
win.xclient.CreateGC(this.id, win.id, { foreground: screen.black_pixel, background: screen.white_pixel});
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicContext.prototype.polyLine = function(points)
|
GraphicContext.prototype.polyLine = function(points)
|
||||||
|
|
@ -51,6 +54,12 @@ GraphicContext.prototype.points = function(points, opts)
|
||||||
this.xclient.PolyPoint(coordinateMode, this.win.id, this.id, points);
|
this.xclient.PolyPoint(coordinateMode, this.win.id, this.id, points);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GraphicContext.prototype.copy = function(srcDrawable, srcX, srcY, dstX, dstY, width, height)
|
||||||
|
{
|
||||||
|
// CopyArea: srcDrawable, dstDrawable, gc, srcX, srcY, dstX, dstY, width, height
|
||||||
|
this.xclient.CopyArea(srcDrawable.id, this.win.id, this.id, srcX, srcY, dstX, dstY, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
function Window(parent, x, y, w, h)
|
function Window(parent, x, y, w, h)
|
||||||
{
|
{
|
||||||
if (parent.constructor && parent.constructor.name == 'XClient')
|
if (parent.constructor && parent.constructor.name == 'XClient')
|
||||||
|
|
@ -89,7 +98,7 @@ function Window(parent, x, y, w, h)
|
||||||
borderWidth, _class, visual,
|
borderWidth, _class, visual,
|
||||||
{
|
{
|
||||||
backgroundPixel: this.white,
|
backgroundPixel: this.white,
|
||||||
eventMask: Exposure|PointerMotion|ButtonPress|ButtonRelease
|
eventMask: Exposure|PointerMotion|ButtonPress|ButtonRelease|SubstructureNotify|StructureNotify
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -99,7 +108,9 @@ function Window(parent, x, y, w, h)
|
||||||
4: 'mousedown',
|
4: 'mousedown',
|
||||||
5: 'mouseup',
|
5: 'mouseup',
|
||||||
6: 'mousemove',
|
6: 'mousemove',
|
||||||
12: 'expose'
|
12: 'expose',
|
||||||
|
16: 'create',
|
||||||
|
19: 'map'
|
||||||
};
|
};
|
||||||
|
|
||||||
var ee = new EventEmitter();
|
var ee = new EventEmitter();
|
||||||
|
|
@ -162,4 +173,23 @@ Window.prototype.getProperty = function(name, cb) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Window.prototype.createPixmap = function(width, height)
|
||||||
|
{
|
||||||
|
var pid = this.xclient.AllocID();
|
||||||
|
// function(depth, pid, drawable, width, height) {
|
||||||
|
this.xclient.CreatePixmap( this.xclient.display.screen[0].root_depth, pid, this.id, width, height);
|
||||||
|
var pixmap = {};
|
||||||
|
pixmap.id = pid;
|
||||||
|
pixmap.__defineGetter__('gc', function()
|
||||||
|
{
|
||||||
|
if (!this._gc)
|
||||||
|
{
|
||||||
|
this._gc = new GraphicContext(this);
|
||||||
|
}
|
||||||
|
return this._gc;
|
||||||
|
});
|
||||||
|
pixmap.xclient = this.xclient;
|
||||||
|
return pixmap;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Window;
|
module.exports = Window;
|
||||||
Loading…
Reference in a new issue