mirror of
https://github.com/danbulant/node-x11
synced 2026-05-20 21:09:10 +00:00
rfb client and rfb gui split into two files
This commit is contained in:
parent
4a8202fa49
commit
5efa66ef34
2 changed files with 131 additions and 151 deletions
|
|
@ -13,6 +13,11 @@ var hexy = require('./hexy').hexy;
|
|||
|
||||
// constants
|
||||
var rfb = require('./constants');
|
||||
for (var key in rfb)
|
||||
{
|
||||
module.exports[key] = rfb[key];
|
||||
}
|
||||
|
||||
|
||||
function RfbClient(stream, params)
|
||||
{
|
||||
|
|
@ -629,154 +634,4 @@ function createConnection(params)
|
|||
|
||||
return new RfbClient(stream, params);
|
||||
}
|
||||
|
||||
var host = process.argv[2];
|
||||
var port = process.argv[3];
|
||||
var password = process.argv[4]
|
||||
if (!host)
|
||||
host = '127.0.0.1';
|
||||
if (!port)
|
||||
port = 5900;
|
||||
|
||||
var opts = {};
|
||||
opts.host = host;
|
||||
opts.port = port;
|
||||
opts.password = password;
|
||||
opts.rfbfile = process.argv[5];
|
||||
//opts.rfbFileOut = process.argv[5];
|
||||
|
||||
clog(opts);
|
||||
|
||||
|
||||
var x11 = require('../../lib/x11');
|
||||
var xclient = x11.createClient();
|
||||
|
||||
var r = createConnection(opts);
|
||||
r.on('connect', function() {
|
||||
console.log('======================== here');
|
||||
startUI();
|
||||
});
|
||||
console.log('added CONNECT handler');
|
||||
|
||||
|
||||
|
||||
function startUI()
|
||||
{
|
||||
|
||||
var Exposure = x11.eventMask.Exposure;
|
||||
var PointerMotion = x11.eventMask.PointerMotion;
|
||||
var ButtonPress = x11.eventMask.ButtonPress;
|
||||
var ButtonRelease = x11.eventMask.ButtonRelease;
|
||||
var KeyPress = x11.eventMask.KeyPress;
|
||||
var KeyRelease = x11.eventMask.KeyRelease;
|
||||
|
||||
|
||||
xclient.on('connect', function(display) {
|
||||
|
||||
var X = display.client;
|
||||
X.require('big-requests', function(BigReq) {
|
||||
BigReq.Enable(function(maxLen) {
|
||||
|
||||
var keycode2keysym = [];
|
||||
var min = display.min_keycode;
|
||||
var max = display.max_keycode;
|
||||
X.GetKeyboardMapping(min, max-min, function(list) {
|
||||
for (var i=0; i < list.length; ++i)
|
||||
{
|
||||
var keycode = i + min;
|
||||
var keysyms = list[i];
|
||||
keycode2keysym[keycode] = keysyms;
|
||||
}
|
||||
|
||||
|
||||
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,
|
||||
10, 10, r.width, r.height,
|
||||
1, 1, 0,
|
||||
{
|
||||
backgroundPixel: white, eventMask: Exposure|PointerMotion|ButtonPress|ButtonRelease|KeyPress|KeyRelease
|
||||
}
|
||||
);
|
||||
X.MapWindow(wid);
|
||||
console.log('AAAAAAAAAAAAAAAAAAAA');
|
||||
|
||||
var gc = X.AllocID();
|
||||
X.CreateGC(gc, wid, { foreground: black, background: white } );
|
||||
X.ChangeProperty(0, wid, X.atoms.WM_NAME, X.atoms.STRING, 8, r.title);
|
||||
|
||||
|
||||
//var pixmap1 = X.AllocID();
|
||||
//X.CreatePixmap(pixmap1, wid, 32, 128, 128);
|
||||
//var pic = X.AllocID();
|
||||
//Render.CreatePicture(pic, pixmap1, Render.rgba32);
|
||||
|
||||
|
||||
//var pic1 = X.AllocID();
|
||||
//Render.CreatePicture(pic1, wid, Render.rgb24);
|
||||
var buttonsState = 0;
|
||||
|
||||
X.on('error', function(err) {
|
||||
clog(err);
|
||||
});
|
||||
|
||||
X.on('event', function(ev) {
|
||||
//clog(ev);
|
||||
if (ev.type == 12) // expose
|
||||
{
|
||||
//X.PutImage(2, wid, gc, 128, 128, 0, 0, 0, 24, bitmap);
|
||||
|
||||
} else if (ev.type == 6) { // mousemove
|
||||
r.pointerEvent(ev.x, ev.y, buttonsState);
|
||||
} else if (ev.type == 4 || ev.type == 5) { // mousedown
|
||||
var buttonBit = 1 << (ev.keycode - 1);
|
||||
// set button bit
|
||||
if (ev.type == 4)
|
||||
buttonsState |= buttonBit;
|
||||
else
|
||||
buttonsState &= ~buttonBit;
|
||||
r.pointerEvent(ev.x, ev.y, buttonsState);
|
||||
} else if (ev.type == 2 || ev.type == 3) {
|
||||
//clog(keycode2keysym[ev.keycode]);
|
||||
var shift = ev.buttons & 1;
|
||||
//clog(shift);
|
||||
var keysym = keycode2keysym[ev.keycode][shift];
|
||||
var isDown = (ev.type == 2) ? 1 : 0;
|
||||
r.keyEvent(keysym, isDown);
|
||||
}
|
||||
});
|
||||
|
||||
r.on('resize', function(rect)
|
||||
{
|
||||
X.ResizeWindow(wid, rect.width, rect.height);
|
||||
});
|
||||
|
||||
console.log('listening rect events');
|
||||
r.on('rect', function(rect) {
|
||||
//clog('========= in handler');
|
||||
//clog(rect);
|
||||
if (rect.encoding == rfb.encodings.raw) {
|
||||
// format, drawable, gc, width, height, dstX, dstY, leftPad, depth, data
|
||||
X.PutImage(2, wid, gc, rect.width, rect.height, rect.x, rect.y, 0, 24, rect.buffer);
|
||||
} else if (rect.encoding == rfb.encodings.copyRect) {
|
||||
X.CopyArea(wid, wid, gc, rect.src.x, rect.src.y, rect.x, rect.y, rect.width, rect.height);
|
||||
} else if (rect.encoding == rfb.encodings.hextile)
|
||||
{
|
||||
clog('hextile rec!!!');
|
||||
clog(rect);
|
||||
rect.on('tile', function(tile) {
|
||||
clog(tile);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
exports.createConnection = createConnection;
|
||||
|
|
|
|||
125
examples/vncviewer/vncgui.js
Normal file
125
examples/vncviewer/vncgui.js
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
"use strict";
|
||||
|
||||
var rfb = require('./rfbclient');
|
||||
var x11 = require('../../lib/x11');
|
||||
|
||||
// TODO: use optimist for args parsing
|
||||
var host = process.argv[2];
|
||||
var port = process.argv[3];
|
||||
var password = process.argv[4]
|
||||
if (!host)
|
||||
host = '127.0.0.1';
|
||||
if (!port)
|
||||
port = 5900;
|
||||
|
||||
var opts = {};
|
||||
opts.host = host;
|
||||
opts.port = port;
|
||||
opts.password = password;
|
||||
opts.rfbfile = process.argv[5];
|
||||
//opts.rfbFileOut = process.argv[5];
|
||||
|
||||
|
||||
|
||||
|
||||
var Exposure = x11.eventMask.Exposure;
|
||||
var PointerMotion = x11.eventMask.PointerMotion;
|
||||
var ButtonPress = x11.eventMask.ButtonPress;
|
||||
var ButtonRelease = x11.eventMask.ButtonRelease;
|
||||
var KeyPress = x11.eventMask.KeyPress;
|
||||
var KeyRelease = x11.eventMask.KeyRelease;
|
||||
|
||||
x11.createClient(function(display) {
|
||||
var X = display.client;
|
||||
X.require('big-requests', function(BigReq) {
|
||||
BigReq.Enable(function(err, maxLen) {
|
||||
var keycode2keysym = [];
|
||||
var min = display.min_keycode;
|
||||
var max = display.max_keycode;
|
||||
X.GetKeyboardMapping(min, max-min, function(err, list) {
|
||||
for (var i=0; i < list.length; ++i)
|
||||
{
|
||||
var keycode = i + min;
|
||||
var keysyms = list[i];
|
||||
keycode2keysym[keycode] = keysyms;
|
||||
}
|
||||
|
||||
|
||||
var root = display.screen[0].root;
|
||||
var white = display.screen[0].white_pixel;
|
||||
var black = display.screen[0].black_pixel;
|
||||
|
||||
var r = rfb.createConnection(opts);
|
||||
r.on('connect', function() {
|
||||
|
||||
var wid = X.AllocID();
|
||||
X.CreateWindow(wid, root, 0, 0, r.width, r.height);
|
||||
X.ChangeWindowAttributes(wid, {
|
||||
backgroundPixel: black,
|
||||
eventMask: Exposure|PointerMotion|ButtonPress|ButtonRelease|KeyPress|KeyRelease
|
||||
});
|
||||
X.ChangeProperty(0, wid, X.atoms.WM_NAME, X.atoms.STRING, 8, r.title);
|
||||
X.MapWindow(wid);
|
||||
|
||||
var gc = X.AllocID();
|
||||
X.CreateGC(gc, wid, { foreground: black, background: white } );
|
||||
|
||||
//var pixbuf = X.AllocID();
|
||||
//X.CreatePixmap(pixbuf, wid, 32, r.width, r.height);
|
||||
//var pic = X.AllocID();
|
||||
//Render.CreatePicture(pic, pixbuf, Render.rgba32);
|
||||
|
||||
var buttonsState = 0;
|
||||
X.on('error', function(err) {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
X.on('event', function(ev) {
|
||||
if (ev.type == 12) // expose
|
||||
{
|
||||
// TODO: update only expose rect
|
||||
//X.PutImage(2, wid, gc, 128, 128, 0, 0, 0, 24, bitmap);
|
||||
} else if (ev.type == 6) { // mousemove
|
||||
r.pointerEvent(ev.x, ev.y, buttonsState);
|
||||
} else if (ev.type == 4 || ev.type == 5) { // mousedown
|
||||
var buttonBit = 1 << (ev.keycode - 1);
|
||||
// set button bit
|
||||
if (ev.type == 4)
|
||||
buttonsState |= buttonBit;
|
||||
else
|
||||
buttonsState &= ~buttonBit;
|
||||
r.pointerEvent(ev.x, ev.y, buttonsState);
|
||||
} else if (ev.type == 2 || ev.type == 3) {
|
||||
var shift = ev.buttons & 1;
|
||||
var keysym = keycode2keysym[ev.keycode][shift];
|
||||
var isDown = (ev.type == 2) ? 1 : 0;
|
||||
r.keyEvent(keysym, isDown);
|
||||
}
|
||||
});
|
||||
|
||||
r.on('resize', function(rect)
|
||||
{
|
||||
X.ResizeWindow(wid, rect.width, rect.height);
|
||||
});
|
||||
r.on('rect', function(rect) {
|
||||
if (rect.encoding == rfb.encodings.raw) {
|
||||
// format, drawable, gc, width, height, dstX, dstY, leftPad, depth, data
|
||||
X.PutImage(2, wid, gc, rect.width, rect.height, rect.x, rect.y, 0, 24, rect.buffer);
|
||||
} else if (rect.encoding == rfb.encodings.copyRect) {
|
||||
X.CopyArea(wid, wid, gc, rect.src.x, rect.src.y, rect.x, rect.y, rect.width, rect.height);
|
||||
} else if (rect.encoding == rfb.encodings.hextile) {
|
||||
console.log('hextile rec! (currently not fully supported');
|
||||
console.log(rect);
|
||||
rect.on('tile', function(tile) {
|
||||
console.log(tile);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}); // r.on('connect)
|
||||
}); // GetKeyboardMapping
|
||||
}); // BigReq.Enable
|
||||
|
||||
}); // require('big-requests
|
||||
|
||||
}); // x11.createClient
|
||||
Loading…
Reference in a new issue