Skip to content

Commit

Permalink
fix: ClassIsland#358 修复概率丢失置顶属性的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
HelloWRC committed Sep 30, 2024
1 parent 27a6c9f commit f20bdb3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
2 changes: 2 additions & 0 deletions ClassIsland.Core/Helpers/Native/NativeWindowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ namespace ClassIsland.Core.Helpers.Native;

public static class NativeWindowHelper
{

#region 常量
public static readonly IntPtr HFILE_ERROR = new IntPtr(-1);
public static readonly HWND HWND_TOPMOST = new(-1);
public static readonly HWND HWND_BOTTOM = (HWND)new IntPtr(1);

public const int OF_READWRITE = 2;
Expand Down
2 changes: 2 additions & 0 deletions ClassIsland.Core/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ EVENT_SYSTEM_MOVESIZEEND
EVENT_SYSTEM_MINIMIZEEND
EVENT_OBJECT_LOCATIONCHANGE
EVENT_OBJECT_FOCUS
EVENT_OBJECT_REORDER
RAWINPUTDEVICE
RawInputDeviceFlags
RAWHID
Expand All @@ -69,3 +70,4 @@ RAWINPUTHEADER
WM_SETTINGCHANGE
HWND_BROADCAST
SMTO_ABORTIFHUNG
WM_WINDOWPOSCHANGED
41 changes: 38 additions & 3 deletions ClassIsland/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Threading;

using Windows.Win32.UI.Accessibility;
using ClassIsland.Controls.NotificationEffects;
using ClassIsland.Core;
using ClassIsland.Core.Abstractions.Services;
Expand Down Expand Up @@ -123,6 +123,7 @@ private Stopwatch UserPrefrenceUpdateStopwatch

private IUriNavigationService UriNavigationService { get; }
public IRulesetService RulesetService { get; }
public IWindowRuleService WindowRuleService { get; }

public static readonly DependencyProperty BackgroundWidthProperty = DependencyProperty.Register(
nameof(BackgroundWidth), typeof(double), typeof(MainWindow), new PropertyMetadata(0.0));
Expand All @@ -145,7 +146,8 @@ public MainWindow(SettingsService settingsService,
IComponentsService componentsService,
ILessonsService lessonsService,
IUriNavigationService uriNavigationService,
IRulesetService rulesetService)
IRulesetService rulesetService,
IWindowRuleService windowRuleService)
{
Logger = logger;
SpeechService = speechService;
Expand All @@ -160,6 +162,7 @@ public MainWindow(SettingsService settingsService,
LessonsService = lessonsService;
UriNavigationService = uriNavigationService;
RulesetService = rulesetService;
WindowRuleService = windowRuleService;

SettingsService.PropertyChanged += (sender, args) =>
{
Expand Down Expand Up @@ -445,6 +448,7 @@ protected override void OnContentRendered(EventArgs e)
TaskBarIconService.MainTaskBarIcon.LeftClickCommand = TrayIconLeftClickedCommand;
TaskBarIconService.MainTaskBarIcon.TrayLeftMouseUp += MainTaskBarIconOnTrayLeftMouseUp;
ViewModel.OverlayRemainTimePercents = 0.5;
WindowRuleService.ForegroundWindowChanged += WindowRuleServiceOnForegroundWindowChanged;
DiagnosticService.EndStartup();
if (ViewModel.Settings.IsSplashEnabled)
{
Expand Down Expand Up @@ -517,6 +521,30 @@ protected override void OnContentRendered(EventArgs e)
#endif
}

private void WindowRuleServiceOnForegroundWindowChanged(HWINEVENTHOOK hwineventhook, uint @event, HWND hwnd, int idobject, int idchild, uint ideventthread, uint dwmseventtime)
{
//if (@event is not (EVENT_SYSTEM_FOREGROUND))
//{
// return;
//}

//ReCheckTopmostState();
}

private void ReCheckTopmostState()
{
var handle = new WindowInteropHelper(this).Handle;
if (ViewModel.IsNotificationWindowExplicitShowed || ViewModel.Settings.WindowLayer == 1)
{

SetWindowPos((HWND)handle, NativeWindowHelper.HWND_TOPMOST, 0, 0, 0, 0,
SET_WINDOW_POS_FLAGS.SWP_NOSIZE | SET_WINDOW_POS_FLAGS.SWP_NOMOVE | SET_WINDOW_POS_FLAGS.SWP_NOACTIVATE | SET_WINDOW_POS_FLAGS.SWP_NOSENDCHANGING);
//Topmost = true;

}

}

private void InitializeRawInputHandler()
{
var handle = new WindowInteropHelper(this).Handle;
Expand All @@ -528,6 +556,7 @@ private void InitializeRawInputHandler()
RawInputUpdateStopWatch.Start();
var hWndSource = HwndSource.FromHwnd(handle);
hWndSource?.AddHook(ProcWnd);

}

private void ProcessMousePos(object? sender, EventArgs e)
Expand All @@ -537,7 +566,7 @@ private void ProcessMousePos(object? sender, EventArgs e)

private IntPtr ProcWnd(IntPtr hwnd, int msg, IntPtr param, IntPtr lParam, ref bool handled)
{
if (msg == 0x00FF)
if (msg == 0x00FF) // WM_INPUT
{
if (RawInputUpdateStopWatch.ElapsedMilliseconds < 20)
{
Expand Down Expand Up @@ -578,6 +607,12 @@ private IntPtr ProcWnd(IntPtr hwnd, int msg, IntPtr param, IntPtr lParam, ref bo

}

if (msg == 0x0047) // WM_WINDOWPOSCHANGED
{
Logger.LogTrace("ZORDER changed");
ReCheckTopmostState();
}

return nint.Zero;
}

Expand Down

0 comments on commit f20bdb3

Please sign in to comment.