Skip to content

Instantly share code, notes, and snippets.

@kanaka
Created April 29, 2011 19:09
Show Gist options
  • Save kanaka/948826 to your computer and use it in GitHub Desktop.
Save kanaka/948826 to your computer and use it in GitHub Desktop.
noVNC scale option to include/ui.js
This is buggy so not yet committed. It nominally works, but the
alignment of the canvas element relative to the status bar can be
funky.
diff --git a/include/ui.js b/include/ui.js
index 3e30420..0f93404 100644
--- a/include/ui.js
+++ b/include/ui.js
@@ -16,7 +16,7 @@ settingsOpen : false,
// Render default UI and initialize settings menu
load: function(target) {
- var html = '', i, sheet, sheets, llevels;
+ var html = '', i, val, sheet, sheets, llevels;
/* Populate the 'target' DOM element with default UI */
if (!target) {
@@ -74,6 +74,14 @@ load: function(target) {
html += ' type="input"> Connect Timeout (s)</li>';
html += ' <hr>';
+ // Scale selection dropdown
+ html += ' <li><select id="VNC_scale">';
+ for (i = 10; i >= 1; i -= 1) {
+ val = (i/10).toFixed(1);
+ html += '<option value="' + val + '">' + val + '</option>';
+ }
+ html += ' </select> Scale</li>';
+
// Stylesheet selection dropdown
html += ' <li><select id="VNC_stylesheet" name="vncStyle">';
html += ' <option value="default">default</option>';
@@ -124,8 +132,10 @@ load: function(target) {
// Settings with immediate effects
UI.initSetting('logging', 'warn');
WebUtil.init_logging(UI.getSetting('logging'));
- UI.initSetting('stylesheet', 'default');
+ UI.initSetting('scale', 1.0);
+
+ UI.initSetting('stylesheet', 'default');
WebUtil.selectStylesheet(null); // call twice to get around webkit bug
WebUtil.selectStylesheet(UI.getSetting('stylesheet'));
@@ -140,8 +150,10 @@ load: function(target) {
UI.initSetting('connectTimeout', 2);
UI.rfb = RFB({'target': $D('VNC_canvas'),
- 'updateState': UI.updateState,
- 'clipboardReceive': UI.clipReceive});
+ 'onUpdateState': UI.updateState,
+ 'onClipboard': UI.clipReceive});
+
+ UI.settingsApply();
// Unfocus clipboard when over the VNC area
$D('VNC_screen').onmousemove = function () {
@@ -242,6 +254,7 @@ clickSettingsMenu: function() {
UI.updateSetting('shared');
UI.updateSetting('connectTimeout');
UI.updateSetting('stylesheet');
+ UI.updateSetting('scale');
UI.updateSetting('logging');
UI.openSettingsMenu();
@@ -278,6 +291,7 @@ settingsDisabled: function(disabled, rfb) {
// Save/apply settings when 'Apply' button is pressed
settingsApply: function() {
+ var scale = UI.getSetting('scale');
//Util.Debug(">> settingsApply");
UI.saveSetting('encrypt');
UI.saveSetting('true_color');
@@ -286,10 +300,16 @@ settingsApply: function() {
}
UI.saveSetting('shared');
UI.saveSetting('connectTimeout');
+ UI.saveSetting('scale');
UI.saveSetting('stylesheet');
UI.saveSetting('logging');
// Settings with immediate (non-connected related) effect
+ if (UI.rfb) {
+ Util.Debug("scale: " + scale);
+ UI.rfb.get_canvas().set_scale(UI.getSetting('scale'));
+ UI.rfb.get_mouse().set_scale(UI.getSetting('scale'));
+ }
WebUtil.selectStylesheet(UI.getSetting('stylesheet'));
WebUtil.init_logging(UI.getSetting('logging'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment