mirror of
https://github.com/danbulant/node-x11
synced 2026-07-05 03:00:42 +00:00
SHAPE extension
This commit is contained in:
parent
1a82cc2141
commit
b0931f1feb
2 changed files with 118 additions and 0 deletions
91
lib/x11/ext/shape.js
Normal file
91
lib/x11/ext/shape.js
Normal file
|
|
@ -0,0 +1,91 @@
|
||||||
|
// http://www.x.org/releases/X11R7.6/doc/xextproto/shape.pdf
|
||||||
|
|
||||||
|
var x11 = require('..');
|
||||||
|
// TODO: move to templates
|
||||||
|
|
||||||
|
exports.requireExt = function(display, callback)
|
||||||
|
{
|
||||||
|
function captureStack()
|
||||||
|
{
|
||||||
|
var err = new Error;
|
||||||
|
//err.name = reqName;
|
||||||
|
Error.captureStackTrace(err, arguments.callee);
|
||||||
|
display.client.seq2stack[display.client.seq_num] = err.stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
var X = display.client;
|
||||||
|
X.QueryExtension('SHAPE', function(err, ext) {
|
||||||
|
|
||||||
|
if (!ext.present)
|
||||||
|
callback(new Error('extension not available'));
|
||||||
|
|
||||||
|
ext.Kind = {
|
||||||
|
Bounding: 0,
|
||||||
|
Clip: 1,
|
||||||
|
Input: 2
|
||||||
|
};
|
||||||
|
|
||||||
|
ext.Op = {
|
||||||
|
Set: 0,
|
||||||
|
Union: 1,
|
||||||
|
Intersect: 2,
|
||||||
|
Subtract: 3,
|
||||||
|
Invert: 4
|
||||||
|
}
|
||||||
|
|
||||||
|
ext.QueryVersion = function(cb)
|
||||||
|
{
|
||||||
|
X.seq_num++;
|
||||||
|
captureStack();
|
||||||
|
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 0, 1]);
|
||||||
|
X.replies[X.seq_num] = [
|
||||||
|
function(buf, opt) {
|
||||||
|
var res = buf.unpack('SS');
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
cb
|
||||||
|
];
|
||||||
|
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]);
|
||||||
|
X.pack_stream.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
ext.SelectInput = function( window, enable )
|
||||||
|
{
|
||||||
|
X.seq_num++;
|
||||||
|
captureStack();
|
||||||
|
X.pack_stream.pack('CCSLCxxx', [ext.majorOpcode, 6, 3, window, enable ]);
|
||||||
|
X.pack_stream.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
ext.InputSelected = function( window, cb )
|
||||||
|
{
|
||||||
|
X.seq_num++;
|
||||||
|
captureStack();
|
||||||
|
X.pack_stream.pack('CCSL', [ext.majorOpcode, 7, 2, window ]);
|
||||||
|
X.replies[X.seq_num] = [
|
||||||
|
function(buf, opt) {
|
||||||
|
return opt;
|
||||||
|
},
|
||||||
|
cb
|
||||||
|
];
|
||||||
|
X.pack_stream.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(ext);
|
||||||
|
|
||||||
|
/*
|
||||||
|
ext.QueryVersion(function(err, version) {
|
||||||
|
ext.major = version[0];
|
||||||
|
ext.minor = version[1];
|
||||||
|
callback(ext);
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
});
|
||||||
|
}
|
||||||
27
test/shapetest.js
Normal file
27
test/shapetest.js
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
var x11 = require('../lib/x11');
|
||||||
|
|
||||||
|
x11.createClient(function(display) {
|
||||||
|
var X = display.client;
|
||||||
|
var root = display.screen[0].root;
|
||||||
|
X.require('shape', function(Shape) {
|
||||||
|
var win = X.AllocID();
|
||||||
|
X.CreateWindow(win, root, 0, 0, 200, 200);
|
||||||
|
var gc = X.AllocID();
|
||||||
|
X.CreateGC(gc, 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);
|
||||||
|
|
||||||
|
X.on('event', function(ev) {
|
||||||
|
console.log(ev);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
X.on('error', function(err) { console.log(err); });
|
||||||
|
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue