Skip to content

Commit e628ab7

Browse files
committed
fix: Fix the incorrect behavior of the right-click menu in the tab header. fix #645
1 parent 3bdaada commit e628ab7

File tree

6 files changed

+42
-17
lines changed

6 files changed

+42
-17
lines changed

Installer/Package.appxmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<Identity
1313
Name="16536Shawn.V.Workshop.PRemoteM"
1414
Publisher="CN=72AC6E85-B8C4-48F8-A07B-9A985863E628"
15-
Version="1.0.97.0" />
15+
Version="1.0.98.0" />
1616

1717
<Properties>
1818
<DisplayName>1Remote</DisplayName>

Ui/Utils/RdpFile/MsRdpClientNonScriptableWrapper.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
42
using System.Runtime.InteropServices;
5-
using System.Text;
6-
using System.Threading.Tasks;
7-
using System.Windows.Interop;
83

94
namespace _1RM.Utils.RdpFile
105
{

Ui/View/Host/TabWindowView.xaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
controls:MouseMiddleClick.MouseMiddleDownParameter="{Binding Content.ConnectionId}"
9595
VerticalAlignment="Bottom">
9696
<Grid.ContextMenu>
97-
<ContextMenu ItemsSource="{Binding Content.MenuItems}" StaysOpen="False">
97+
<ContextMenu ItemsSource="{Binding Content.MenuItems}">
9898
<ContextMenu.Style>
9999
<Style TargetType="{x:Type ContextMenu}">
100100
<Setter Property="OverridesDefaultStyle" Value="True" />
@@ -756,7 +756,9 @@
756756
SelectionChanged="TabablzControl_OnSelectionChanged"
757757
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
758758
ItemsSource="{Binding Items}"
759-
HeaderMemberPath="DisplayName">
759+
HeaderMemberPath="DisplayName"
760+
PreviewMouseLeftButtonDown="TabablzControl_OnPreviewMouseLeftButtonDown"
761+
>
760762
<!-- important for docking -->
761763
<dragablz:TabablzControl.InterTabController>
762764
<dragablz:InterTabController InterTabClient="{Binding InterTabClient}" />

Ui/View/Host/TabWindowView.xaml.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,5 +221,27 @@ public override void WinTitleBar_OnPreviewMouseDown(object sender, MouseButtonEv
221221
}
222222
base.WinTitleBar_OnPreviewMouseDown(sender, e);
223223
}
224+
225+
226+
227+
private void TabablzControl_OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
228+
{
229+
var t = sender.GetType();
230+
SimpleLogHelper.Warning(t);
231+
232+
// focus to be on the integrated exe after clicking on the WPF window.
233+
RunForIntegrate();
234+
}
235+
236+
public override void WinTitleBar_OnPreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
237+
{
238+
var isDragging = _isDragging;
239+
base.WinTitleBar_OnPreviewMouseMove(sender, e);
240+
if (isDragging && !_isDragging)
241+
{
242+
// focus to be on the integrated exe after drag on the WPF window.
243+
RunForIntegrate();
244+
}
245+
}
224246
}
225247
}

Ui/View/Host/TabWindowView.xaml_timer.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.Windows;
55
using System.Windows.Forms;
6+
using System.Windows.Input;
67
using _1RM.Model.Protocol;
78
using _1RM.Service;
89
using _1RM.View.Host.ProtocolHosts;
@@ -44,7 +45,7 @@ private void Timer4CheckForegroundWindowOnElapsed(object? sender, ElapsedEventAr
4445
try
4546
{
4647
RunForRdpV2();
47-
RunForIntegrate();
48+
RunForIntegrate(true);
4849
}
4950
catch (Exception ex)
5051
{
@@ -66,8 +67,12 @@ private void Timer4CheckForegroundWindowOnElapsed(object? sender, ElapsedEventAr
6667
[DllImport("user32.dll")]
6768
private static extern bool SetForegroundWindow(IntPtr hWnd);
6869

69-
70-
private void RunForIntegrate()
70+
/// <summary>
71+
/// 0. Record the current ActivatedWindowHandle every time
72+
/// 1. If the current ActivatedWindowHandle is the integrated exe, move the Tab to the foreground one time (BringWindowToTop(_myHandle);, achieving that after clicking the integrated exe, the tab is brought to the front and not obscured by other programs.
73+
/// 2. If isTimer is False and the current focus is on the Tab, then set the focus on the integrated exe. (To ensure that the focus is not lost after clicking on the tab label)
74+
/// </summary>
75+
private void RunForIntegrate(bool isTimer = false)
7176
{
7277
if (Vm?.SelectedItem?.Content?.GetProtocolHostType() != ProtocolHostType.Integrate)
7378
return;
@@ -77,17 +82,18 @@ private void RunForIntegrate()
7782

7883
var nowActivatedWindowHandle = GetForegroundWindow();
7984

85+
//SimpleLogHelper.Debug($"TabWindowView: isTimer = {isTimer}, nowActivatedWindowHandle = {nowActivatedWindowHandle}, _lastActivatedWindowHandle = {_lastActivatedWindowHandle}, _myHandle = {_myHandle}");
8086
// bring Tab window to top, when the host content is Integrate.
81-
if (nowActivatedWindowHandle == hWnd && nowActivatedWindowHandle != _lastActivatedWindowHandle)
87+
if (nowActivatedWindowHandle == hWnd && _lastActivatedWindowHandle != hWnd)
8288
{
83-
SimpleLogHelper.Debug($@"TabWindowView: _lastActivatedWindowHandle = ({_lastActivatedWindowHandle})
84-
TabWindowView: nowActivatedWindowHandle = ({nowActivatedWindowHandle}), hWnd = {hWnd}
85-
TabWindowView: BringWindowToTop({_myHandle})");
89+
SimpleLogHelper.Debug($@"TabWindowView: BringWindowToTop({_myHandle})");
8690
BringWindowToTop(_myHandle);
8791
}
8892
// focus content when tab is focused and host is Integrate and left mouse is not pressed
89-
else if (nowActivatedWindowHandle == _myHandle && System.Windows.Forms.Control.MouseButtons != MouseButtons.Left)
93+
else if (!isTimer
94+
&& nowActivatedWindowHandle == _myHandle)
9095
{
96+
SimpleLogHelper.Debug($@"TabWindowView: Vm?.SelectedItem?.Content?.FocusOnMe()");
9197
Vm?.SelectedItem?.Content?.FocusOnMe();
9298
}
9399
_lastActivatedWindowHandle = nowActivatedWindowHandle;

0 commit comments

Comments
 (0)