mirror of
https://github.com/danbulant/node-x11
synced 2026-05-24 12:35:39 +00:00
CreateGC request
This commit is contained in:
parent
8e5758238f
commit
e62bc74750
2 changed files with 116 additions and 22 deletions
|
|
@ -1,24 +1,82 @@
|
||||||
var valueMask = {
|
var valueMask = {
|
||||||
backgroundPixmap: 0x00000001,
|
CreateWindow: {
|
||||||
backgroundPixel : 0x00000002,
|
backgroundPixmap: 0x00000001,
|
||||||
borderPixmap : 0x00000004,
|
backgroundPixel : 0x00000002,
|
||||||
borderPixel : 0x00000008,
|
borderPixmap : 0x00000004,
|
||||||
bitGrawity : 0x00000010,
|
borderPixel : 0x00000008,
|
||||||
winGravity : 0x00000020,
|
bitGrawity : 0x00000010,
|
||||||
backingStore : 0x00000040,
|
winGravity : 0x00000020,
|
||||||
backingPlanes : 0x00000080,
|
backingStore : 0x00000040,
|
||||||
backingPixel : 0x00000100,
|
backingPlanes : 0x00000080,
|
||||||
overrideRedirect: 0x00000200,
|
backingPixel : 0x00000100,
|
||||||
saveUnder : 0x00000400,
|
overrideRedirect: 0x00000200,
|
||||||
eventMask : 0x00000800,
|
saveUnder : 0x00000400,
|
||||||
doNotPropagateMask: 0x00001000,
|
eventMask : 0x00000800,
|
||||||
colormap : 0x00002000,
|
doNotPropagateMask: 0x00001000,
|
||||||
cursor : 0x00004000
|
colormap : 0x00002000,
|
||||||
|
cursor : 0x00004000
|
||||||
|
},
|
||||||
|
CreateGC: {
|
||||||
|
'function' : 0x00000001, // TODO: alias? _function?
|
||||||
|
planeMask : 0x00000002,
|
||||||
|
foreground : 0x00000004,
|
||||||
|
background : 0x00000008,
|
||||||
|
lineWidth : 0x00000010,
|
||||||
|
lineStyle : 0x00000020,
|
||||||
|
capStyle : 0x00000040,
|
||||||
|
joinStyle : 0x00000080,
|
||||||
|
fillStyle : 0x00000100,
|
||||||
|
fillRule : 0x00000200,
|
||||||
|
tile : 0x00000400,
|
||||||
|
stipple : 0x00000800,
|
||||||
|
tileStippleXOrigin: 0x00001000,
|
||||||
|
tileStippleYOrigin: 0x00002000,
|
||||||
|
font : 0x00004000,
|
||||||
|
subwindowMode: 0x00008000,
|
||||||
|
graphicsExposures: 0x00010000,
|
||||||
|
clipXOrigin : 0x00020000,
|
||||||
|
clipYOrigin : 0x00040000,
|
||||||
|
clipMask : 0x00080000,
|
||||||
|
dashOffset : 0x00100000,
|
||||||
|
dashes : 0x00200000,
|
||||||
|
arcMode : 0x00400000
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var valueMaskNames = {};
|
var valueMaskName = {};
|
||||||
for (var m in valueMask) {
|
for (var req in valueMask) {
|
||||||
valueMaskNames[valueMask[m]] = m;
|
var masks = valueMask[req];
|
||||||
|
var names = valueMaskName[req] = {};
|
||||||
|
for (var m in masks)
|
||||||
|
names[masks[m]] = m;
|
||||||
|
}
|
||||||
|
|
||||||
|
function packValueMask(reqname, values)
|
||||||
|
{
|
||||||
|
var bitmask = 0;
|
||||||
|
var masksList = [];
|
||||||
|
var reqValueMask = valueMask[reqname];
|
||||||
|
var reqValueMaskName = valueMaskName[reqname];
|
||||||
|
|
||||||
|
if (!reqValueMask)
|
||||||
|
throw new Error(reqname + ': no value mask description');
|
||||||
|
|
||||||
|
for (var v in values)
|
||||||
|
{
|
||||||
|
var valueBit = reqValueMask[v];
|
||||||
|
if (!valueBit)
|
||||||
|
throw new Error('CreateWindow: incorrect value param ' + v);
|
||||||
|
masksList.push(valueBit);
|
||||||
|
bitmask |= valueBit;
|
||||||
|
}
|
||||||
|
masksList.sort();
|
||||||
|
var args = [];
|
||||||
|
for (m in masksList)
|
||||||
|
{
|
||||||
|
valueName = reqValueMaskName[masksList[m]];
|
||||||
|
args.push( values[valueName] );
|
||||||
|
}
|
||||||
|
return [bitmask, args]
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -51,7 +109,7 @@ module.exports = {
|
||||||
// TODO: ??? there is depth field in xproto, but xlib just sets it to zero
|
// TODO: ??? there is depth field in xproto, but xlib just sets it to zero
|
||||||
var depth = 0;
|
var depth = 0;
|
||||||
|
|
||||||
var packetLength = 8 + Object.keys(values).length;
|
var packetLength = 8 + (values ? Object.keys(values).length : 0);
|
||||||
// TODO: should be CCSLLssSSSSLL - x,y are signed
|
// TODO: should be CCSLLssSSSSLL - x,y are signed
|
||||||
var format = 'CCSLLSSSSSSLL';
|
var format = 'CCSLLSSSSSSLL';
|
||||||
|
|
||||||
|
|
@ -65,10 +123,12 @@ module.exports = {
|
||||||
// bitmask (bytes #24 to #31 in the packet) - 32 bit indicating what adittional arguments we supply
|
// bitmask (bytes #24 to #31 in the packet) - 32 bit indicating what adittional arguments we supply
|
||||||
// values list (bytes #32 .. #32+4*num_values) in order of corresponding bits
|
// values list (bytes #32 .. #32+4*num_values) in order of corresponding bits
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: replace with packValueMask
|
||||||
var masksList = [];
|
var masksList = [];
|
||||||
for (var v in values)
|
for (var v in values)
|
||||||
{
|
{
|
||||||
var valueBit = valueMask[v];
|
var valueBit = valueMask['CreateWindow'][v];
|
||||||
if (!valueBit)
|
if (!valueBit)
|
||||||
{
|
{
|
||||||
throw new Error('CreateWindow: incorrect value param ' + v);
|
throw new Error('CreateWindow: incorrect value param ' + v);
|
||||||
|
|
@ -85,7 +145,7 @@ module.exports = {
|
||||||
// TODO: maybe it's better just to scan all 32 bits anstead of sorting parameters we are actually have?
|
// TODO: maybe it's better just to scan all 32 bits anstead of sorting parameters we are actually have?
|
||||||
for (m in masksList)
|
for (m in masksList)
|
||||||
{
|
{
|
||||||
valueName = valueMaskNames[masksList[m]];
|
valueName = valueMaskName['CreateWindow'][masksList[m]];
|
||||||
args.push( values[valueName] );
|
args.push( values[valueName] );
|
||||||
}
|
}
|
||||||
return [format, args];
|
return [format, args];
|
||||||
|
|
@ -100,5 +160,23 @@ module.exports = {
|
||||||
|
|
||||||
UnmapWindow: [
|
UnmapWindow: [
|
||||||
[ 'CxSL', [10, 2] ]
|
[ 'CxSL', [10, 2] ]
|
||||||
|
],
|
||||||
|
|
||||||
|
// opcode 55
|
||||||
|
CreateGC: [
|
||||||
|
function(cid, drawable, values) {
|
||||||
|
var format = 'CxSLL';
|
||||||
|
var packetLength = 8 + (values ? Object.keys(values).length : 0);
|
||||||
|
var args = [55, packetLength, cid, drawable];
|
||||||
|
var vals = packValueMask('CreateGC', values);
|
||||||
|
args.push(vals[0]); // values bitmask
|
||||||
|
var valArr = vals[1];
|
||||||
|
for (v in valArr)
|
||||||
|
{
|
||||||
|
format += 'L'; // TODO: we know format string length in advance and += inefficient for string
|
||||||
|
args.push(valArr[v]);
|
||||||
|
}
|
||||||
|
return [format, args];
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
16
test/creategc.js
Normal file
16
test/creategc.js
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
var x11 = require('../lib/x11');
|
||||||
|
|
||||||
|
var xclient = x11.createClient();
|
||||||
|
var mapped = true;
|
||||||
|
xclient.on('connect', function(display) {
|
||||||
|
var X = this;
|
||||||
|
var root = display.screen[0].root;
|
||||||
|
var wid = X.AllocID();
|
||||||
|
|
||||||
|
X.CreateWindow(wid, root, 10, 10, 400, 300, 1, 1, 0, { backgroundPixel: 0, eventMask: 0x00000040 });
|
||||||
|
X.MapWindow(wid);
|
||||||
|
|
||||||
|
var cid = X.AllocID();
|
||||||
|
X.CreateGC(cid, wid);
|
||||||
|
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue