Skip to content

Commit d3c0cba

Browse files
committed
fix: Fix the resizing bug introduced by #648, see #797 for more details.
close #648, fix #797
1 parent bf58a45 commit d3c0cba

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

Ui/View/Host/ProtocolHosts/AxMsRdpClient09Host.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,12 @@ private void OnRdpClientLoginComplete(object? sender, EventArgs e)
189189
GridLoading.Visibility = Visibility.Collapsed;
190190
GridMessageBox.Visibility = Visibility.Collapsed;
191191
ParentWindowResize_StartWatch();
192-
_resizeEndTimer?.Stop();
193-
_resizeEndTimer?.Start();
194-
Task.Factory.StartNew(() =>
195-
{
196-
Thread.Sleep(5000);
197-
_resizeEndTimer?.Stop();
198-
});
192+
//_resizeEndTimer?.Start();
193+
//Task.Factory.StartNew(() =>
194+
//{
195+
// Thread.Sleep(5000);
196+
// _resizeEndTimer?.Stop();
197+
//});
199198
}
200199

201200

Ui/View/Host/ProtocolHosts/AxMsRdpClient09Host.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public sealed partial class AxMsRdpClient09Host : HostBase, IDisposable
7070
private int _retryCount = 0;
7171
private const int MAX_RETRY_COUNT = 20;
7272

73-
private readonly System.Timers.Timer _loginResizeTimer;
73+
private readonly System.Timers.Timer _loginResizeTimer; // timer for login resize, to fix the issue that the rdp client size is not correct when login
7474
private DateTime _lastLoginTime = DateTime.MinValue;
7575

7676

@@ -835,9 +835,9 @@ private void WindowSizeChanged(object sender, SizeChangedEventArgs e)
835835
_previousHeight = (uint)e.NewSize.Height;
836836
Execute.OnUIThreadSync(() =>
837837
{
838+
_loginResizeTimer.Stop();
838839
_resizeEndTimer.Stop();
839840
_resizeEndTimer.Start();
840-
_loginResizeTimer.Stop();
841841
});
842842
}
843843
}
@@ -902,7 +902,7 @@ private void ReSizeRdpToControlSize()
902902
{
903903
while (true)
904904
{
905-
// Window drag an drop resize only after mouse button release, 当拖动最大化的窗口时,需检测鼠标按键释放后再调整分辨率,详见:https://github.com/1Remote/1Remote/issues/553
905+
// Window drag and drop resize only after mouse button release, 当拖动最大化的窗口时,需检测鼠标按键释放后再调整分辨率,详见:https://github.com/1Remote/1Remote/issues/553
906906
var isPressed = false;
907907
Execute.OnUIThreadSync(() => { isPressed = Mouse.LeftButton == MouseButtonState.Pressed; });
908908
if (!isPressed)

Ui/View/Host/TabWindowView.xaml_timer.cs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ private void RunForIntegrate()
8989
_lastActivatedWindowHandle = nowActivatedWindowHandle;
9090
}
9191

92-
92+
/****
93+
* THE PURPOSE OF THIS FUNCTION IS TO:
94+
* - LET YOUR LOCAL DESKTOP WINDOW GET FOCUS WHEN YOU MOVE THE CURSOR OUT OF THE RDP WINDOW
95+
* - LET THE RDP WINDOW GET FOCUS WHEN YOU MOVE THE CURSOR INTO THE RDP WINDOW
96+
* - CAUTION: PAY ATTENTION TO THE RESIZE OF THE RDP WINDOW, IT MAY CAUSE THE CURSOR TO MOVE OUT OF THE RDP WINDOW, SO WE NEED TO CHECK IF THE LEFT MOUSE BUTTON IS PRESSED OR NOT
97+
***/
9398
#region RunForRdp
9499

95100
[StructLayout(LayoutKind.Sequential)]
@@ -129,32 +134,45 @@ private static bool IsMouseInside(Window window)
129134
}
130135

131136

132-
private int _rdpStage = 0; // 0 - not connected, 1 - RDP got focus, 2 - RDP lost focus desk got focus(focus can rollback to RDP), 3 - RDP lost focus desk lost focus (focus can not rollback to RDP)
137+
private int _rdpStage = 0; // flag: 0 - not connected, 1 - RDP got focus, 2 - RDP lost focus desk got focus(focus can rollback to RDP), 3 - RDP lost focus desk lost focus (focus can cannot rollback to RDP)
138+
133139
private void RunForRdp()
134140
{
135141
if (Vm?.SelectedItem?.Content?.ProtocolServer.Protocol != RDP.ProtocolName)
136142
return;
137143
if (Vm?.SelectedItem?.Content?.Status != ProtocolHosts.ProtocolHostStatus.Connected)
138144
return;
139145

146+
// Fix the resizing bug introduced by #648, see https://github.com/1Remote/1Remote/issues/797 for more details
147+
bool isMousePressed = System.Windows.Forms.Control.MouseButtons == MouseButtons.Left
148+
|| System.Windows.Forms.Control.MouseButtons == MouseButtons.Right
149+
|| System.Windows.Forms.Control.MouseButtons == MouseButtons.Middle;
150+
if (isMousePressed)
151+
{
152+
#if DEBUG
153+
SimpleLogHelper.Debug("Tab focus: Mouse is pressed, do nothing");
154+
#endif
155+
return;
156+
}
157+
140158
var nowActivatedWindowHandle = GetForegroundWindow();
141159
var desktopHandle = GetDesktopWindow();
142160

143161
#if DEBUG
144-
SimpleLogHelper.Debug($"tabHwnd = {_myHandle}, nowActivatedWindowHandle = {nowActivatedWindowHandle}, desktopHandle = {desktopHandle}");
162+
SimpleLogHelper.Debug($"Tab focus: tabHwnd = {_myHandle}, nowActivatedWindowHandle = {nowActivatedWindowHandle}, desktopHandle = {desktopHandle}");
145163
#endif
146164

147165
bool isMouseInside = IsMouseInside(this);
148166

149167
if (_rdpStage == 1 && !isMouseInside)
150168
{
151-
// 1 - RDP got focus AND mouse is not inside the tab window, then switch focus to desktop, user input will not be sent to RDP
169+
// 1 - RDP has focus AND mouse is not inside the tab window, then switch focus to desktop, user input will not be sent to RDP
152170
_rdpStage = 2;
153171
SetForegroundWindow(desktopHandle);
154172
}
155173
else if (_rdpStage == 2)
156174
{
157-
// if focus to other window, then stage = 3
175+
// if focus is on another window, then stage = 3
158176
if (nowActivatedWindowHandle != desktopHandle)
159177
{
160178
_rdpStage = 3;
@@ -168,14 +186,14 @@ private void RunForRdp()
168186
}
169187
else if (_rdpStage == 3)
170188
{
171-
// 3 - neither RDP nor local desk lost focus, can not rollback to RDP, do nothing
189+
// 3 - neither RDP nor local desktop has focus, cannot rollback to RDP, do nothing
172190
}
173191

174192
if (_rdpStage != 1 && isMouseInside && _myHandle == nowActivatedWindowHandle)
175193
{
176194
_rdpStage = 1;
177195
}
178-
}
196+
}
179197
#endregion
180198
}
181199
}

0 commit comments

Comments
 (0)