From d1091c5e0c14eb50b170742cd4a5baf74a940a1d Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Thu, 24 Feb 2022 14:21:14 -0800 Subject: [PATCH] Desktop Setting Improvements. --- KVMControl.cs | 1 + KVMSettingsForm.Designer.cs | 19 +++++++++---- KVMSettingsForm.cs | 30 ++++++++++++-------- KVMSettingsForm.resx | 56 ++++++++++++++++++++++++++++--------- KVMViewer.cs | 45 +++++++++++++++++++++++++++++ MainForm.cs | 6 ++++ 6 files changed, 128 insertions(+), 29 deletions(-) diff --git a/KVMControl.cs b/KVMControl.cs index e20d9d9..6efff18 100644 --- a/KVMControl.cs +++ b/KVMControl.cs @@ -40,6 +40,7 @@ namespace MeshCentralRouter private bool swamMouseButtons = false; private bool remoteKeyboardMap = false; private bool autoSendClipboard = false; + public bool AutoReconnect = false; private double scalefactor = 1; public List displays = new List(); public ushort currentDisp = 0; diff --git a/KVMSettingsForm.Designer.cs b/KVMSettingsForm.Designer.cs index 1189f0d..7c06c66 100644 --- a/KVMSettingsForm.Designer.cs +++ b/KVMSettingsForm.Designer.cs @@ -32,6 +32,7 @@ this.cancelButton = new System.Windows.Forms.Button(); this.okButton = new System.Windows.Forms.Button(); this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.autoSendClipboardCheckBox = new System.Windows.Forms.CheckBox(); this.remoteKeyboardMapCheckBox = new System.Windows.Forms.CheckBox(); this.swapMouseButtonsCheckBox = new System.Windows.Forms.CheckBox(); this.frameRateComboBox = new System.Windows.Forms.ComboBox(); @@ -42,7 +43,7 @@ this.label3 = new System.Windows.Forms.Label(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.label4 = new System.Windows.Forms.Label(); - this.autoSendClipboardCheckBox = new System.Windows.Forms.CheckBox(); + this.autoReconnectCheckBox = new System.Windows.Forms.CheckBox(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.SuspendLayout(); @@ -65,6 +66,7 @@ // groupBox1 // resources.ApplyResources(this.groupBox1, "groupBox1"); + this.groupBox1.Controls.Add(this.autoReconnectCheckBox); this.groupBox1.Controls.Add(this.autoSendClipboardCheckBox); this.groupBox1.Controls.Add(this.remoteKeyboardMapCheckBox); this.groupBox1.Controls.Add(this.swapMouseButtonsCheckBox); @@ -77,6 +79,12 @@ this.groupBox1.Name = "groupBox1"; this.groupBox1.TabStop = false; // + // autoSendClipboardCheckBox + // + resources.ApplyResources(this.autoSendClipboardCheckBox, "autoSendClipboardCheckBox"); + this.autoSendClipboardCheckBox.Name = "autoSendClipboardCheckBox"; + this.autoSendClipboardCheckBox.UseVisualStyleBackColor = true; + // // remoteKeyboardMapCheckBox // resources.ApplyResources(this.remoteKeyboardMapCheckBox, "remoteKeyboardMapCheckBox"); @@ -137,11 +145,11 @@ resources.ApplyResources(this.label4, "label4"); this.label4.Name = "label4"; // - // autoSendClipboardCheckBox + // autoReconnectCheckBox // - resources.ApplyResources(this.autoSendClipboardCheckBox, "autoSendClipboardCheckBox"); - this.autoSendClipboardCheckBox.Name = "autoSendClipboardCheckBox"; - this.autoSendClipboardCheckBox.UseVisualStyleBackColor = true; + resources.ApplyResources(this.autoReconnectCheckBox, "autoReconnectCheckBox"); + this.autoReconnectCheckBox.Name = "autoReconnectCheckBox"; + this.autoReconnectCheckBox.UseVisualStyleBackColor = true; // // KVMSettingsForm // @@ -182,5 +190,6 @@ private System.Windows.Forms.CheckBox swapMouseButtonsCheckBox; private System.Windows.Forms.CheckBox remoteKeyboardMapCheckBox; private System.Windows.Forms.CheckBox autoSendClipboardCheckBox; + private System.Windows.Forms.CheckBox autoReconnectCheckBox; } } \ No newline at end of file diff --git a/KVMSettingsForm.cs b/KVMSettingsForm.cs index 033dccd..15871a4 100644 --- a/KVMSettingsForm.cs +++ b/KVMSettingsForm.cs @@ -25,6 +25,7 @@ namespace MeshCentralRouter { InitializeComponent(); Translate.TranslateControl(this); + qualityComboBox.Items.Add(new DropListItem(100, "100%")); qualityComboBox.Items.Add(new DropListItem(90, "90%")); qualityComboBox.Items.Add(new DropListItem(80, "80%")); qualityComboBox.Items.Add(new DropListItem(70, "70%")); @@ -76,17 +77,18 @@ namespace MeshCentralRouter get { return ((DropListItem)qualityComboBox.SelectedItem).value; } set { - if (value >= 90) { qualityComboBox.SelectedIndex = 0; return; } - if (value >= 80) { qualityComboBox.SelectedIndex = 1; return; } - if (value >= 70) { qualityComboBox.SelectedIndex = 2; return; } - if (value >= 60) { qualityComboBox.SelectedIndex = 3; return; } - if (value >= 50) { qualityComboBox.SelectedIndex = 4; return; } - if (value >= 40) { qualityComboBox.SelectedIndex = 5; return; } - if (value >= 30) { qualityComboBox.SelectedIndex = 6; return; } - if (value >= 20) { qualityComboBox.SelectedIndex = 7; return; } - if (value >= 10) { qualityComboBox.SelectedIndex = 8; return; } - if (value >= 5) { qualityComboBox.SelectedIndex = 9; return; } - qualityComboBox.SelectedIndex = 10; + if (value >= 100) { qualityComboBox.SelectedIndex = 0; return; } + if (value >= 90) { qualityComboBox.SelectedIndex = 1; return; } + if (value >= 80) { qualityComboBox.SelectedIndex = 2; return; } + if (value >= 70) { qualityComboBox.SelectedIndex = 3; return; } + if (value >= 60) { qualityComboBox.SelectedIndex = 4; return; } + if (value >= 50) { qualityComboBox.SelectedIndex = 5; return; } + if (value >= 40) { qualityComboBox.SelectedIndex = 6; return; } + if (value >= 30) { qualityComboBox.SelectedIndex = 7; return; } + if (value >= 20) { qualityComboBox.SelectedIndex = 8; return; } + if (value >= 10) { qualityComboBox.SelectedIndex = 9; return; } + if (value >= 5) { qualityComboBox.SelectedIndex = 10; return; } + qualityComboBox.SelectedIndex = 11; } } @@ -135,6 +137,12 @@ namespace MeshCentralRouter set { autoSendClipboardCheckBox.Checked = value; } } + public bool AutoReconnect + { + get { return autoReconnectCheckBox.Checked; } + set { autoReconnectCheckBox.Checked = value; } + } + private void okButton_Click(object sender, EventArgs e) { DialogResult = System.Windows.Forms.DialogResult.OK; diff --git a/KVMSettingsForm.resx b/KVMSettingsForm.resx index 11be2d7..f19b9d2 100644 --- a/KVMSettingsForm.resx +++ b/KVMSettingsForm.resx @@ -123,7 +123,7 @@ - 312, 254 + 312, 276 75, 23 @@ -151,7 +151,7 @@ Bottom, Right - 231, 254 + 231, 276 75, 23 @@ -177,6 +177,36 @@ Top, Bottom, Left, Right + + True + + + NoControl + + + 128, 174 + + + 144, 17 + + + 10 + + + Automatically Reconnect + + + autoReconnectCheckBox + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 0 + True @@ -205,7 +235,7 @@ groupBox1 - 0 + 1 True @@ -235,7 +265,7 @@ groupBox1 - 1 + 2 True @@ -262,7 +292,7 @@ groupBox1 - 2 + 3 Top, Left, Right @@ -286,7 +316,7 @@ groupBox1 - 3 + 4 True @@ -313,7 +343,7 @@ groupBox1 - 4 + 5 Top, Left, Right @@ -337,7 +367,7 @@ groupBox1 - 5 + 6 True @@ -364,7 +394,7 @@ groupBox1 - 6 + 7 Top, Left, Right @@ -391,7 +421,7 @@ groupBox1 - 7 + 8 True @@ -418,13 +448,13 @@ groupBox1 - 8 + 9 12, 68 - 375, 180 + 375, 202 2 @@ -502,7 +532,7 @@ 6, 13 - 399, 289 + 399, 311 diff --git a/KVMViewer.cs b/KVMViewer.cs index 249f39a..2f5976f 100644 --- a/KVMViewer.cs +++ b/KVMViewer.cs @@ -43,6 +43,8 @@ namespace MeshCentralRouter public string lang = Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName; private bool splitMode = false; private KVMViewerExtra[] extraDisplays = null; + private System.Windows.Forms.Timer delayedConnectionTimer = null; + private bool localAutoReconnect = true; // Stats public long bytesIn = 0; @@ -84,7 +86,19 @@ namespace MeshCentralRouter mainToolTip.SetToolTip(clipInboundButton, Translate.T(Properties.Resources.PullClipboardFromRemoteDevice, lang)); mainToolTip.SetToolTip(zoomButton, Translate.T(Properties.Resources.ToggleZoomToFitMode, lang)); mainToolTip.SetToolTip(statsButton, Translate.T(Properties.Resources.DisplayConnectionStatistics, lang)); + + // Load remote desktop settings + int CompressionLevel = 60; + try { CompressionLevel = int.Parse(Settings.GetRegValue("kvmCompression", "60")); } catch (Exception) { } + int ScalingLevel = 1024; + try { ScalingLevel = int.Parse(Settings.GetRegValue("kvmScaling", "1024")); } catch (Exception) { } + int FrameRate = 100; + try { FrameRate = int.Parse(Settings.GetRegValue("kvmFrameRate", "100")); } catch (Exception) { } + kvmControl.SetCompressionParams(CompressionLevel, ScalingLevel, FrameRate); + kvmControl.SwamMouseButtons = Settings.GetRegValue("kvmSwamMouseButtons", "0").Equals("1"); + kvmControl.RemoteKeyboardMap = Settings.GetRegValue("kvmSwamMouseButtons", "0").Equals("1"); kvmControl.AutoSendClipboard = Settings.GetRegValue("kvmAutoClipboard", "0").Equals("1"); + kvmControl.AutoReconnect = Settings.GetRegValue("kvmAutoReconnect", "0").Equals("1"); } private void KvmControl_ScreenAreaUpdated(Bitmap desktop, Rectangle r) @@ -117,6 +131,25 @@ namespace MeshCentralRouter } } + public void TryAutoConnect() + { + if ((localAutoReconnect == false) || (kvmControl.AutoReconnect == false)) return; + if ((state == 0) && (wc == null) && (delayedConnectionTimer == null)) { + // Hold half a second before trying to connect + delayedConnectionTimer = new System.Windows.Forms.Timer(this.components); + delayedConnectionTimer.Tick += new EventHandler(updateTimerTick); + delayedConnectionTimer.Interval = 500; + delayedConnectionTimer.Enabled = true; + } + } + + private void updateTimerTick(object sender, EventArgs e) + { + delayedConnectionTimer.Dispose(); + delayedConnectionTimer = null; + if ((state == 0) && (wc == null)) { MenuItemConnect_Click(this, null); } + } + private void KvmControl_DesktopSizeChanged(object sender, EventArgs e) { kvmControl.Visible = true; @@ -318,6 +351,7 @@ namespace MeshCentralRouter wc.Dispose(); wc = null; UpdateStatus(); + localAutoReconnect = false; } else { @@ -325,6 +359,7 @@ namespace MeshCentralRouter if (sender != null) { consentFlags = 0; } MenuItemConnect_Click(null, null); kvmControl.AttachKeyboard(); + localAutoReconnect = true; } displayMessage(null); } @@ -434,11 +469,21 @@ namespace MeshCentralRouter form.SwamMouseButtons = kvmControl.SwamMouseButtons; form.RemoteKeyboardMap = kvmControl.RemoteKeyboardMap; form.AutoSendClipboard = kvmControl.AutoSendClipboard; + form.AutoReconnect = kvmControl.AutoReconnect; if (form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { kvmControl.SetCompressionParams(form.Compression, form.Scaling, form.FrameRate); kvmControl.SwamMouseButtons = form.SwamMouseButtons; kvmControl.RemoteKeyboardMap = form.RemoteKeyboardMap; + kvmControl.AutoReconnect = form.AutoReconnect; + + Settings.SetRegValue("kvmCompression", kvmControl.CompressionLevel.ToString()); + Settings.SetRegValue("kvmScaling", kvmControl.ScalingLevel.ToString()); + Settings.SetRegValue("kvmFrameRate", kvmControl.FrameRate.ToString()); + Settings.SetRegValue("kvmSwamMouseButtons", kvmControl.SwamMouseButtons ? "1" : "0"); + Settings.SetRegValue("kvmRemoteKeyboardMap", kvmControl.RemoteKeyboardMap ? "1" : "0"); + Settings.SetRegValue("kvmAutoReconnect", kvmControl.AutoReconnect ? "1" : "0"); + if (kvmControl.AutoSendClipboard != form.AutoSendClipboard) { kvmControl.AutoSendClipboard = form.AutoSendClipboard; diff --git a/MainForm.cs b/MainForm.cs index 60524d3..f2f66eb 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -647,6 +647,12 @@ namespace MeshCentralRouter // Setup any automatic mappings if ((fullRefresh == true) && (mappingsToSetup != null)) { setupMappings(); } + + // Reconnect any auto-reconnect nodes + foreach (NodeClass node in meshcentral.nodes.Values) + { + if (((node.conn & 1) != 0) && (node.desktopViewer != null)) { node.desktopViewer.TryAutoConnect(); } + } } private void updateDeviceList()