mirror of
https://github.com/danbulant/node-x11
synced 2026-05-23 06:19:01 +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,
|
||||
ColormapChange: 0x00800000,
|
||||
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.height = values[3];
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ xclient.on('connect', function(display) {
|
|||
{
|
||||
pts.push(ev.x);
|
||||
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.on('expose', function(ev) {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ var Exposure = x11.eventMask.Exposure;
|
|||
var PointerMotion = x11.eventMask.PointerMotion;
|
||||
var ButtonPress = x11.eventMask.ButtonPress;
|
||||
var ButtonRelease = x11.eventMask.ButtonRelease;
|
||||
var SubstructureNotify = x11.eventMask.SubstructureNotify;
|
||||
var StructureNotify = x11.eventMask.StructureNotify;
|
||||
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var util = require('util'); // util.inherits
|
||||
|
|
@ -12,7 +14,8 @@ function GraphicContext(win)
|
|||
this.win = win;
|
||||
this.xclient = win.xclient;
|
||||
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)
|
||||
|
|
@ -51,6 +54,12 @@ GraphicContext.prototype.points = function(points, opts)
|
|||
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)
|
||||
{
|
||||
if (parent.constructor && parent.constructor.name == 'XClient')
|
||||
|
|
@ -89,7 +98,7 @@ function Window(parent, x, y, w, h)
|
|||
borderWidth, _class, visual,
|
||||
{
|
||||
backgroundPixel: this.white,
|
||||
eventMask: Exposure|PointerMotion|ButtonPress|ButtonRelease
|
||||
eventMask: Exposure|PointerMotion|ButtonPress|ButtonRelease|SubstructureNotify|StructureNotify
|
||||
}
|
||||
);
|
||||
|
||||
|
|
@ -98,8 +107,10 @@ function Window(parent, x, y, w, h)
|
|||
eventType2eventName = {
|
||||
4: 'mousedown',
|
||||
5: 'mouseup',
|
||||
6: 'mousemove',
|
||||
12: 'expose'
|
||||
6: 'mousemove',
|
||||
12: 'expose',
|
||||
16: 'create',
|
||||
19: 'map'
|
||||
};
|
||||
|
||||
var ee = new EventEmitter();
|
||||
|
|
@ -162,4 +173,23 @@ Window.prototype.getProperty = function(name, cb) {
|
|||
return this;
|
||||
}
|
||||
|
||||
module.exports = Window;
|
||||
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;
|
||||
Loading…
Reference in a new issue