Files
SpdUp/Views/WidgetWindow.xaml.cs
T
Phil-icyou 19ba425e79 Initial commit: SpdUp Windows Gaming Booster v1.0.0
- .NET 8 WPF app with full MVVM architecture
- One-click boost: CPU, RAM, GPU, network, services, timer resolution
- Real-time system monitor (LibreHardwareMonitor)
- Auto game detection (30+ games)
- RAM optimizer with kernel-level cleanup
- Network optimizer (TCP registry tweaks)
- Service manager, process manager, shader cache cleaner
- Desktop widget overlay
- Debug log viewer
- Custom dark gaming theme with trans pride colors
- 84 unit tests (xUnit)
- Inno Setup installer script
- Landing page website
2026-03-08 17:34:45 +01:00

84 lines
2.6 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Input;
using System.Windows.Interop;
using SpdUp.ViewModels;
namespace SpdUp.Views;
/// <summary>
/// Floating desktop widget borderless, transparent, always-on-top.
/// </summary>
public partial class WidgetWindow : Window
{
private bool _expanded;
// ── Win32 click-through support ───────────────────────────────────
private const int GWL_EXSTYLE = -20;
private const int WS_EX_TRANSPARENT = 0x00000020;
private const int WS_EX_TOOLWINDOW = 0x00000080;
[DllImport("user32.dll")]
private static extern int GetWindowLong(IntPtr hwnd, int index);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle);
public WidgetWindow(MainViewModel vm)
{
InitializeComponent();
DataContext = vm;
// Restore position from settings
Left = vm.Settings.WidgetOpacity > 0 ? 100 : 100; // default
Top = 100;
Loaded += (_, _) =>
{
// Make it a tool window (no taskbar entry)
var hwnd = new WindowInteropHelper(this).Handle;
var exStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
SetWindowLong(hwnd, GWL_EXSTYLE, exStyle | WS_EX_TOOLWINDOW);
Opacity = vm.Settings.WidgetOpacity;
if (!vm.Settings.WidgetCompactMode)
ToggleExpand();
};
}
private void Widget_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
DragMove();
}
private void Widget_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
ToggleExpand();
}
private void Toggle_Click(object sender, RoutedEventArgs e) => ToggleExpand();
private void Close_Click(object sender, RoutedEventArgs e) => Close();
private void ToggleExpand()
{
_expanded = !_expanded;
ExpandedPanel.Visibility = _expanded ? Visibility.Visible : Visibility.Collapsed;
}
/// <summary>
/// Enable click-through: all mouse events pass through to windows below.
/// </summary>
public void SetClickThrough(bool enable)
{
var hwnd = new WindowInteropHelper(this).Handle;
var exStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
if (enable)
SetWindowLong(hwnd, GWL_EXSTYLE, exStyle | WS_EX_TRANSPARENT);
else
SetWindowLong(hwnd, GWL_EXSTYLE, exStyle & ~WS_EX_TRANSPARENT);
}
}