mirror of
https://github.com/danbulant/node-x11
synced 2026-05-21 13:29:13 +00:00
extra depth argunebt in CreateWindow
This commit is contained in:
parent
4a1964febb
commit
f2c3090e9a
7 changed files with 213 additions and 77 deletions
|
|
@ -30,11 +30,11 @@ x11.createClient(function(display)
|
|||
{
|
||||
X.require('render', function(Render) {
|
||||
X.Render = Render;
|
||||
BigReq.Enable(function(maxLen)
|
||||
BigReq.Enable(function(err, maxLen)
|
||||
{
|
||||
var min = display.min_keycode;
|
||||
var max = display.max_keycode;
|
||||
X.GetKeyboardMapping(min, max-min, function(list)
|
||||
X.GetKeyboardMapping(min, max-min, function(err, list)
|
||||
{
|
||||
// map keycode to key name
|
||||
for (var i=0; i < list.length; ++i)
|
||||
|
|
@ -64,7 +64,7 @@ function main(X)
|
|||
X.CreateWindow(
|
||||
win, root,
|
||||
0, 0, kbdImg.width, kbdImg.height,
|
||||
1, 1, 0,
|
||||
0, 0, 0, 0,
|
||||
{
|
||||
backgroundPixel: white, eventMask: Exposure|KeyPress|ButtonPress
|
||||
}
|
||||
|
|
@ -75,7 +75,7 @@ function main(X)
|
|||
X.CreateWindow(
|
||||
win1, root,
|
||||
0, 0, kbdImg.width, kbdImg.height,
|
||||
1, 1, 0,
|
||||
0, 0, 0, 0,
|
||||
{
|
||||
backgroundPixel: white, eventMask: Exposure|KeyPress|ButtonPress
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,21 +14,23 @@ var last_frames = 0;
|
|||
|
||||
x11.createClient(function(display)
|
||||
{
|
||||
|
||||
console.log('111111');
|
||||
var X = display.client;
|
||||
X.InternAtom(false, 'test', function() {
|
||||
});
|
||||
X.require('big-requests', function(BigReq)
|
||||
{
|
||||
X.require('render', function(Render) {
|
||||
X.Render = Render;
|
||||
BigReq.Enable(function(maxLen)
|
||||
{
|
||||
|
||||
BigReq.Enable(function(err, maxLen)
|
||||
{
|
||||
|
||||
console.log('222222');
|
||||
|
||||
var root = display.screen[0].root;
|
||||
var white = display.screen[0].white_pixel;
|
||||
var black = display.screen[0].black_pixel;
|
||||
|
||||
var win, picWin, piclogoi, logo;
|
||||
var win, picWin, piclogoi, pic;
|
||||
|
||||
|
||||
function showpic(path)
|
||||
|
|
@ -36,10 +38,9 @@ x11.createClient(function(display)
|
|||
|
||||
console.log(path);
|
||||
|
||||
logo = require('./node-png').readPng(path);
|
||||
//console.log(logo);
|
||||
pic = require('./node-png').readPng(path);
|
||||
/*
|
||||
var d = logo.data; var l = logo.data.length;
|
||||
var d = pic.data; var l = pic.data.length;
|
||||
for (var p=0; p < l; p+=4)
|
||||
{
|
||||
b = d[p];
|
||||
|
|
@ -48,88 +49,41 @@ x11.createClient(function(display)
|
|||
}
|
||||
*/
|
||||
|
||||
console.log(pic);
|
||||
win = X.AllocID();
|
||||
X.CreateWindow(
|
||||
win, root,
|
||||
0, 0, logo.width, logo.height,
|
||||
1, 0, 1, 0,
|
||||
0, 0, pic.width, pic.height,
|
||||
0, 0, 0, 0,
|
||||
{
|
||||
backgroundPixel: white, eventMask: Exposure|KeyPress|ButtonPress|PointerMotion
|
||||
}
|
||||
);
|
||||
X.MapWindow(win);
|
||||
|
||||
var gc = X.AllocID();
|
||||
X.CreateGC(gc, win);
|
||||
X.gc = X.AllocID();
|
||||
X.CreateGC(X.gc, win);
|
||||
|
||||
//var pixmaplogo = X.AllocID();
|
||||
//X.CreatePixmap(pixmaplogo, win, 32, logo.width, logo.height);
|
||||
//X.PolyFillRectangle(pixmaplogo, gc, [0, 0, 1000, 1000]);
|
||||
//X.PutImage(2, pixmaplogo, gc, logo.width, logo.height, 0, 0, 0, 24, logo.data);
|
||||
|
||||
|
||||
var lastdelta = 0;
|
||||
|
||||
if (interv) clearInterval(interv);
|
||||
interv = setInterval(function() {
|
||||
//console.log('sending!');
|
||||
if (lastdelta > 100)
|
||||
{
|
||||
lastdelta -= 10;
|
||||
} else {
|
||||
var n = +new Date();
|
||||
console.log(logo.data.length/(logo.width*logo.height));
|
||||
|
||||
|
||||
|
||||
console.log("here");
|
||||
X.PutImage(2, win, gc, logo.width, logo.height, 0, 0, 0, 24, logo.data);
|
||||
total_frames++;
|
||||
X.GetAtomName(1, function(name) {
|
||||
lastdelta = +new Date() - n;
|
||||
//console.log(lastdelta);
|
||||
});
|
||||
}
|
||||
}, 200);
|
||||
//X.PutImage(2, win, X.gc, pic.width, pic.height, 0, 0, 0, 24, pic.data);
|
||||
//piclogo = X.AllocID();
|
||||
//Render.CreatePicture(piclogo, pixmaplogo, Render.rgb24);
|
||||
|
||||
//picWin = X.AllocID();
|
||||
//Render.CreatePicture(picWin, win, Render.rgb24);
|
||||
|
||||
}
|
||||
|
||||
var idx = 10070;
|
||||
showpic('./node-logo.png');
|
||||
//showpic('./pnggrad8rgb.png');
|
||||
//var files = require('fs').readFileSync('./qqq').toString().split('\n');
|
||||
|
||||
showpic(process.argv[2]);
|
||||
|
||||
|
||||
X.on('event', function(ev) {
|
||||
if (ev.type == 12) // expose
|
||||
{
|
||||
//X.PutImage(2, win, gc, logo.width, logo.height, 0, 0, 0, 24, logo.data);
|
||||
X.PutImage(2, win, X.gc, pic.width, pic.height, 0, 0, 0, 24, pic.data);
|
||||
//Render.Composite(3, piclogo, 0, picWin, 0, 0, 0, 0, 0, 0, logo.width, logo.height);
|
||||
}
|
||||
if (ev.type == 2)
|
||||
{
|
||||
switch(ev.keycode)
|
||||
{
|
||||
case 131:
|
||||
idx -= 10; break;
|
||||
case 132:
|
||||
idx += 10; break;
|
||||
case 133:
|
||||
idx -= 1; break;
|
||||
case 134:
|
||||
idx += 1; break;
|
||||
}
|
||||
console.log(idx);
|
||||
if (idx < 0) idx = 0;
|
||||
X.DestroyWindow(win);
|
||||
showpic(files[idx]);
|
||||
}
|
||||
});
|
||||
|
||||
X.on('error', function(err) {
|
||||
console.log(err);
|
||||
});
|
||||
|
|
@ -138,8 +92,3 @@ X.on('error', function(err) {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
//setInterval(function() {
|
||||
// console.log(total_frames - last_frames);
|
||||
// last_frames = total_frames;
|
||||
//}, 1000);
|
||||
|
|
|
|||
15
examples/simple/creategc.js
Normal file
15
examples/simple/creategc.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
var x11 = require('../lib/x11');
|
||||
|
||||
var PointerMotion = x11.eventMask.PointerMotion;
|
||||
x11.createClient(function(display) {
|
||||
var X = display.client;
|
||||
var root = display.screen[0].root;
|
||||
var white = display.screen[0].white_pixel;
|
||||
var black = display.screen[0].black_pixel;
|
||||
|
||||
var wid = X.AllocID();
|
||||
X.CreateWindow(wid, root, 0, 0, 400, 300, 0, 0, 0, 0, { backgroundPixel: white, eventMask: PointerMotion });
|
||||
var gc = X.AllocID();
|
||||
X.CreateGC(gc, wid);
|
||||
X.MapWindow(wid);
|
||||
});
|
||||
30
examples/simple/getprop.js
Normal file
30
examples/simple/getprop.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// ChangeProperty/GetProperty / PropertyChange event example
|
||||
|
||||
var x11 = require('../../lib/x11');
|
||||
var PropertyChange = x11.eventMask.PropertyChange;
|
||||
|
||||
x11.createClient(function(display) {
|
||||
var X = display.client;
|
||||
var root = display.screen[0].root;
|
||||
var wid = X.AllocID();
|
||||
X.CreateWindow(wid, root, 0, 0, 400, 300, 0, 0, 0, 0, { eventMask: PropertyChange });
|
||||
X.MapWindow(wid);
|
||||
|
||||
// mode: 0 replace, 1 prepend, 2 append
|
||||
// mode, wid, name, type, format, data
|
||||
X.ChangeProperty(0, wid, X.atoms.WM_NAME, X.atoms.STRING, 8, 'Hello, NodeJS');
|
||||
var interval = setInterval(function() {
|
||||
X.ChangeProperty(0, wid, X.atoms.WM_NAME, X.atoms.STRING, 8, 'Hello, NodeJS ' + new Date());
|
||||
}, 1000);
|
||||
|
||||
X.on('event', function(ev) {
|
||||
X.GetProperty(0, wid, X.atoms.WM_NAME, X.atoms.STRING, 0, 10000000, function(err, prop) {
|
||||
if (prop.type == X.atoms.STRING)
|
||||
prop.data = prop.data.toString();
|
||||
console.log(prop.data);
|
||||
});
|
||||
});
|
||||
X.on('end', function() {
|
||||
clearInterval(interval);
|
||||
});
|
||||
});
|
||||
122
examples/simple/gradients.js
Normal file
122
examples/simple/gradients.js
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
// this will be eventually moved to lib/node-x11/extensions
|
||||
|
||||
var x11 = require('../../lib/x11');
|
||||
|
||||
// adding XRender functions manually from
|
||||
// http://cgit.freedesktop.org/xcb/proto/tree/src/render.xml?id=HEAD
|
||||
// and http://www.x.org/releases/X11R7.6/doc/renderproto/renderproto.txt
|
||||
// TODO: move to templates
|
||||
x11.createClient(
|
||||
function(display) {
|
||||
var X = display.client;
|
||||
X.require('render', function(Render) {
|
||||
|
||||
var root = display.screen[0].root;
|
||||
var win = X.AllocID();
|
||||
var white = display.screen[0].white_pixel;
|
||||
var black = display.screen[0].black_pixel;
|
||||
X.CreateWindow(win, root, 0, 0, 500, 500, 0, 0, 0, 0,
|
||||
{
|
||||
backgroundPixel: white,
|
||||
eventMask: x11.eventMask.Exposure | x11.eventMask.ButtonPress | x11.eventMask.PointerMotion
|
||||
});
|
||||
X.MapWindow(win);
|
||||
|
||||
var picture = X.AllocID();
|
||||
Render.CreatePicture(picture, win, Render.rgb24, { polyEdge: 1, polyMode: 0 } );
|
||||
var pixmap = X.AllocID();
|
||||
X.CreatePixmap(pixmap, win, 32, 2500, 2500);
|
||||
var pix_pict = X.AllocID();
|
||||
Render.CreatePicture(pix_pict, pixmap, Render.rgba32, { polyEdge: 1, polyMode: 0 });
|
||||
|
||||
var pic_grad = X.AllocID();
|
||||
Render.LinearGradient(pic_grad, [0,0], [1000,100],
|
||||
//RenderRadialGradient(pic_grad, [0,0], [1000,100], 10, 1000,
|
||||
//RenderConicalGradient(pic_grad, [250,250], 360,
|
||||
[
|
||||
[0, [0,0,0,0x3000 ] ],
|
||||
[0.1, [0xfff, 0, 0xffff, 0x1000] ] ,
|
||||
[0.25, [0xffff, 0, 0xfff, 0x3000] ] ,
|
||||
[0.5, [0xffff, 0, 0xffff, 0x4000] ] ,
|
||||
[1, [0xffff, 0xffff, 0, 0x8000] ]
|
||||
]);
|
||||
|
||||
var pic_grad1 = X.AllocID();
|
||||
|
||||
Render.ConicalGradient(pic_grad1, [250,250], 10,
|
||||
[
|
||||
[0, [0,0,0,0x5000 ] ],
|
||||
[0.1, [0xfff, 0, 0xffff, 0x3000] ] ,
|
||||
[0.25, [0xffff, 0, 0xfff, 0x2000] ] ,
|
||||
[0.5, [0xffff, 0, 0xffff, 0x1000] ] ,
|
||||
[1, [0xffff, 0xffff, 0, 0x8000] ]
|
||||
]);
|
||||
|
||||
var pic_grad2 = X.AllocID();
|
||||
Render.RadialGradient(pic_grad2, [250,250], [250,250], 0, 250,
|
||||
[
|
||||
[0, [0,0,0,0x5000 ] ],
|
||||
[0.99, [0xffff, 0xffff, 0, 0xffff] ],
|
||||
[1, [0xffff, 0xffff, 0, 0x0] ]
|
||||
]);
|
||||
|
||||
var pixmap1 = X.AllocID();
|
||||
X.CreatePixmap(pixmap1, win, 32, 2500, 2500);
|
||||
var pix_pict1 = X.AllocID();
|
||||
Render.CreatePicture(pix_pict1, pixmap1, Render.rgba32, { polyEdge: 1, polyMode: 0 });
|
||||
Render.Composite(3, pic_grad2, 0, pix_pict1, 0, 0, 0, 0, 0, 0, 2500, 2500);
|
||||
|
||||
var pixmap2 = X.AllocID();
|
||||
X.CreatePixmap(pixmap2, win, 32, 2500, 2500);
|
||||
var pix_pict2 = X.AllocID();
|
||||
Render.CreatePicture(pix_pict2, pixmap2, Render.rgba32, { polyEdge: 1, polyMode: 0 });
|
||||
for(var i=0; i < 100; ++i)
|
||||
{
|
||||
var pts = [];
|
||||
for (var coord = 0; coord < 6; coord++)
|
||||
pts.push(Math.random()*500);
|
||||
Render.Triangles(3, pic_grad, Math.random()*2500, Math.random()*2500, pix_pict2, 0, pts);
|
||||
}
|
||||
|
||||
function update()
|
||||
{
|
||||
Render.FillRectangles(1, pix_pict, [0xffff, 0xffff, 0xffff, 0xffff], [0, 0, 2500, 2500]);
|
||||
Render.Composite(3, pix_pict2, 0, pix_pict, 0, 0, 0, 0, X.x1, X.y1, 2500, 2500);
|
||||
//Render.Composite(3, pic_grad, 0, pix_pict, 0, 0, 0, 0, 0, 0, 500, 500);
|
||||
Render.Composite(3, pix_pict1, 0, pix_pict, 0, 0, 0, 0, X.x2, X.y2, 2500, 2500);
|
||||
}
|
||||
|
||||
function draw()
|
||||
{
|
||||
Render.Composite(3, pix_pict, 0, picture, 0, 0, 0, 0, 0, 0, 2500, 2500);
|
||||
}
|
||||
|
||||
X.x1 = X.y1 = X.x2 = X.y2 = 0;
|
||||
update();
|
||||
draw();
|
||||
|
||||
X.on('event', function(ev) {
|
||||
if (ev.type == 4)
|
||||
{
|
||||
if (ev.keycode == 4)
|
||||
X.x1 += 10;
|
||||
else
|
||||
X.x1 -= 10;
|
||||
update();
|
||||
draw();
|
||||
} else if (ev.type == 6) // mouse move
|
||||
{
|
||||
X.x2 = ev.x - 250;
|
||||
X.y2 = ev.y - 250;
|
||||
update();
|
||||
draw();
|
||||
} else {
|
||||
draw();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
).on('error', function(err) {
|
||||
console.log(['error! : ', err]);
|
||||
});
|
||||
15
examples/simple/resizewindow.js
Normal file
15
examples/simple/resizewindow.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
var x11 = require('../../lib/x11');
|
||||
x11.createClient(function(display) {
|
||||
var X = display.client;
|
||||
var root = display.screen[0].root;
|
||||
var wid = X.AllocID();
|
||||
X.CreateWindow(wid, root, 10, 10, 400, 300);
|
||||
X.MapWindow(wid);
|
||||
setInterval( function() {
|
||||
X.ResizeWindow(wid, 800, 200);
|
||||
}, 1200);
|
||||
var interval = setInterval( function() {
|
||||
X.ResizeWindow(wid, 400, 300);
|
||||
}, 510);
|
||||
X.on('end', function() { clearInterval(interval)});
|
||||
});
|
||||
|
|
@ -66,7 +66,12 @@ XServerClientConnection.prototype.checkAuth = function(authType, authData)
|
|||
// ignore check for now;
|
||||
// protocol page 140: add code for reject & ask additional info
|
||||
console.log([authType, authData]);
|
||||
console.log('Not YET');
|
||||
|
||||
// auth ok: reply with list of screens, visuals, root window info etc
|
||||
var stream = serv.pack_stream;
|
||||
|
||||
stream.write('Cxxxxxp
|
||||
[2, reason,
|
||||
//serv.pack_stream.unpack('C', function(isShared) {
|
||||
// console.log([isShared]);
|
||||
// serv.writeServerInit();
|
||||
|
|
@ -86,6 +91,6 @@ module.exports.createServer = function(listenport, params) {
|
|||
return new XServer(s, params);
|
||||
}
|
||||
|
||||
module.exports.createServer(6001) ;
|
||||
module.exports.createServer(6002) ;
|
||||
//function(client) {
|
||||
//});
|
||||
|
|
|
|||
Loading…
Reference in a new issue