diff --git a/include/display.js b/include/display.js index 4f37cd14..12bf150d 100644 --- a/include/display.js +++ b/include/display.js @@ -23,7 +23,7 @@ var that = {}, // Public API methods // Predefine function variables (jslint) imageDataCreate, imageDataGet, rgbxImageData, cmapImageData, - rgbxImageFill, cmapImageFill, setFillColor, rescale, flush, + rgbxImageFill, cmapImageFill, setFillColor, rescale, rescaleAuto, flush, // The full frame buffer (logical canvas) size fb_width = 0, @@ -232,13 +232,52 @@ rescale = function(factor) { if (conf.scale === factor) { //Util.Debug("Display already scaled to '" + factor + "'"); + UI.message("Display already scaled to '" + factor + "'"); return; } - conf.scale = factor; x = c.width - c.width * factor; y = c.height - c.height * factor; c.style[tp] = "scale(" + conf.scale + ") translate(-" + x + "px, -" + y + "px)"; + UI.message("scale: "+conf.scale+", x: "+x+", y: "+y); +}; + +rescaleAuto = function() { + var c, tp, x, y, xFactor, yFactor, factor, + properties = ['transform', 'WebkitTransform', 'MozTransform', null]; + + c = conf.target; + tp = properties.shift(); + while (tp) { + if (typeof c.style[tp] !== 'undefined') { + break; + } + tp = properties.shift(); + } + + if (tp === null) { + Util.Debug("No scaling support"); + return; + } + + xFactor=viewport.w/fb_width; + yFactor=viewport.h/fb_height; + UI.message("xFactor: "+xFactor+", yFactor: "+yFactor+", viewport.h: "+viewport.h+", fb_height: "+fb_height); + + if (xFactor > 1.0) {xFactor = 1.0;} + else if (xFactor < 0.1) {xFactor = 0.1;} + + if (yFactor > 1.0) {yFactor = 1.0;} + else if (yFactor < 0.1) {yFactor = 0.1;} + + /* Rescale screen to whichever factor that is smaller (so we get to see the whole screen). */ + factor=xFactor fb_width) { + cw = fb_width; + } + if (ch > fb_height) { + ch = fb_height; + } + if ((cw !== v.w) || (ch !== v.h)) { + v.w = cw; + v.h = ch; + UI.message("new viewport: " + v.w + "," + v.h); + + c = conf.target; + c.width = v.w; + c.height = v.h; + + rescaleAuto(); + that.refresh(); + } + UI.message("framebuffer: "+fb_width+","+fb_height+"; viewport: "+v.w+","+v.h); +}; +/* Test graphics (repeating pattern). */ +that.drawArea = function(x, y, w, h) { + UI.message("draw "+x+","+y+" ("+w+","+h+")"); + var imgData = ctx.createImageData(w, h), + data = imgData.data, pixel, realX, realY; + + for (var i = 0; i < w; i++) { + realX = viewport.x + x + i; + for (var j = 0; j < h; j++) { + realY = viewport.y + y + j; + pixel = (j * w * 4 + i * 4); + data[pixel + 0] = ((realX * realY) / 13) % 256; + data[pixel + 1] = ((realX * realY) + 392) % 256; + data[pixel + 2] = ((realX + realY) + 256) % 256; + data[pixel + 3] = 255; + } + } + //UI.message("i: " + i + ", j: " + j + ", pixel: " + pixel); + ctx.putImageData(imgData, x, y); +}; + +/* Screen refresh. */ +that.refresh = function() { + if (UI.rfb) {UI.rfb.refresh();} + + UI.message('screen refreshed.'); + Util.Debug('screen refreshed.'); +}; + +that.clear = function() { if (conf.logo) { that.resize(conf.logo.width, conf.logo.height); that.viewportChange(0, 0, conf.logo.width, conf.logo.height); diff --git a/include/plain.css b/include/plain.css index fa768fac..e2ec35dc 100644 --- a/include/plain.css +++ b/include/plain.css @@ -80,10 +80,11 @@ } /* Do not set width/height for VNC_screen or VNC_canvas or incorrect - * scaling will occur. Canvas resizes to remote VNC settings */ + * scaling will occur. Canvas resizes to client browser size (viewport). */ #VNC_screen { text-align: center; - display: table; + /* display: table; */ + display: block; } #VNC_canvas { background: #eee; diff --git a/include/rfb.js b/include/rfb.js index 0d48a4bc..ef88518a 100644 --- a/include/rfb.js +++ b/include/rfb.js @@ -132,6 +132,7 @@ Util.conf_defaults(conf, that, defaults, [ ['connectTimeout', 'rw', 'int', def_con_timeout, 'Time (s) to wait for connection'], ['disconnectTimeout', 'rw', 'int', 3, 'Time (s) to wait for disconnection'], + ['refreshTimeout', 'rw', 'int', 2, 'Time (s) to wait for a refresh'], ['check_rate', 'rw', 'int', 217, 'Timing (ms) of send/receive check'], ['fbu_req_rate', 'rw', 'int', 1413, 'Timing (ms) of frameBufferUpdate requests'], @@ -428,7 +429,6 @@ updateState = function(state, statusMsg) { case 'connect': - connTimer = setTimeout(function () { fail("Connect timeout"); }, conf.connectTimeout * 1000); @@ -441,7 +441,8 @@ updateState = function(state, statusMsg) { case 'disconnect': - + rfb_password=''; + if (! test_mode) { disconnTimer = setTimeout(function () { fail("Disconnect timeout"); @@ -449,7 +450,8 @@ updateState = function(state, statusMsg) { } print_stats(); - + display.clear(); + // WebSocket.onclose transitions to 'disconnected' break; @@ -1527,6 +1529,17 @@ that.sendPassword = function(passwd) { setTimeout(init_msg, 1); }; +that.refresh = function() { + // Refresh only when already connected, i.e. don't refresh during disconnected or loaded states. + if (rfb_state!='loaded' && rfb_password.length>0) { + updateState('connect','refreshing...'); + setTimeout(function () { + if (rfb_state!=='normal') {that.refresh();} + }, conf.refreshTimeout * 1000); + } + UI.message('state: '+rfb_state); +}; + that.sendCtrlAltDel = function() { if (rfb_state !== "normal") { return false; } Util.Info("Sending Ctrl-Alt-Del"); diff --git a/include/ui.js b/include/ui.js index f3388ebd..24e193a6 100644 --- a/include/ui.js +++ b/include/ui.js @@ -10,13 +10,31 @@ /*jslint white: false, browser: true */ /*global window, $D, Util, WebUtil, RFB, Display */ +var msg_cnt = 0, iterations, + //fb_width = 800, + //fb_height = 768, + fb_width=1920, + fb_height=1200, + viewport = {'x': 0, 'y': 0, 'w' : 0, 'h' : 0 }, + cleanRect = {}, + penDown = false, doMove = false, + inMove = false, lastPos = {}, + canvas, ctx, keyboard, mouse; + +var newline = "\n"; + + var UI = { settingsOpen : false, // Render default UI and initialize settings menu load: function(target) { - var html = '', i, sheet, sheets, llevels; + if (Util.Engine.trident) { + var newline = "
\n"; + } + + var html = '', i, val, sheet, sheets, llevels; /* Populate the 'target' DOM element with default UI */ if (!target) { @@ -39,17 +57,18 @@ load: function(target) { target.innerHTML = html; return; } - - html += '
'; - html += '