mirror of
https://github.com/Stone-Red-Code/InvLock.git
synced 2026-09-04 09:06:13 +02:00
Add screen blur option
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
<Window x:Class="InvLock.BlurWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:InvLock"
|
||||
mc:Ignorable="d"
|
||||
Loaded="Window_Loaded"
|
||||
WindowStyle="None"
|
||||
MouseDown="Window_MouseDown"
|
||||
AllowsTransparency="True"
|
||||
Background="Black"
|
||||
Opacity="0"
|
||||
Title="BlurWindow" Height="450" Width="800">
|
||||
</Window>
|
||||
@@ -0,0 +1,26 @@
|
||||
using InvLock.Utilities;
|
||||
|
||||
using System.Windows;
|
||||
|
||||
namespace InvLock;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for BlurWindow.xaml
|
||||
/// </summary>
|
||||
public partial class BlurWindow : Window
|
||||
{
|
||||
public BlurWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
WindowsApi.EnableBlur(this);
|
||||
}
|
||||
|
||||
private void Window_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
||||
{
|
||||
DragMove();
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,9 @@ public partial class LockWindow : Window
|
||||
private readonly SimpleGlobalHook hook = new SimpleGlobalHook();
|
||||
private readonly Dictionary<KeyCode, DateTime> pressedKeys = [];
|
||||
private readonly Settings settings;
|
||||
private readonly List<BlurWindow> blurWindows = [];
|
||||
private List<IntPtr> windows = [];
|
||||
private Point lastMousePosition;
|
||||
private bool isOpen = true;
|
||||
private bool suppressInput = false;
|
||||
|
||||
@@ -120,11 +122,32 @@ public partial class LockWindow : Window
|
||||
MinimizeWindows();
|
||||
}
|
||||
|
||||
isOpen = true;
|
||||
suppressInput = true;
|
||||
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
lastMousePosition = WpfScreenHelper.MouseHelper.MousePosition;
|
||||
|
||||
if (settings.BlurScreen)
|
||||
{
|
||||
foreach (Rect bounds in WpfScreenHelper.Screen.AllScreens.Select(s => s.WpfBounds))
|
||||
{
|
||||
BlurWindow blurWindow = new()
|
||||
{
|
||||
Width = bounds.Width,
|
||||
Height = bounds.Height,
|
||||
Left = bounds.Left,
|
||||
Top = bounds.Top,
|
||||
};
|
||||
|
||||
blurWindows.Add(blurWindow);
|
||||
blurWindow.Show();
|
||||
}
|
||||
|
||||
_ = WindowsApi.SetCursorPosition(new Point(100000, 100000));
|
||||
}
|
||||
|
||||
isOpen = true;
|
||||
suppressInput = true;
|
||||
|
||||
_ = Activate();
|
||||
|
||||
textBlock.Text = settings.LockText;
|
||||
@@ -155,6 +178,9 @@ public partial class LockWindow : Window
|
||||
|
||||
isOpen = true;
|
||||
|
||||
_ = WindowsApi.SetCursorPosition(lastMousePosition);
|
||||
blurWindows.ForEach(w => w.Close());
|
||||
|
||||
textBlock.Text = settings.UnlockText;
|
||||
textBlock.Stroke = (Brush)FindResource("PaletteGreenBrush");
|
||||
|
||||
@@ -203,6 +229,9 @@ public partial class LockWindow : Window
|
||||
|
||||
isOpen = true;
|
||||
|
||||
_ = WindowsApi.SetCursorPosition(lastMousePosition);
|
||||
blurWindows.ForEach(w => w.Close());
|
||||
|
||||
_ = Activate();
|
||||
|
||||
await Task.Delay(500);
|
||||
|
||||
@@ -79,6 +79,20 @@
|
||||
</ComboBox>
|
||||
</ui:CardControl>
|
||||
|
||||
<ui:CardControl Margin="0,0,0,12" Icon="{ui:SymbolIcon Symbol=Clock24}" Height="75">
|
||||
<ui:CardControl.Header>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ui:TextBlock Grid.Row="0" FontTypography="Body" Text="Run at startup" />
|
||||
<ui:TextBlock Grid.Row="1" Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}" FontSize="12" Text="Start InvLock when you sign in to Windows" />
|
||||
</Grid>
|
||||
</ui:CardControl.Header>
|
||||
<ui:ToggleSwitch Grid.Column="1" IsChecked="{Binding IsAutoStartEnabled}" OffContent="Off" OnContent="On" />
|
||||
</ui:CardControl>
|
||||
|
||||
<ui:CardControl Margin="0,0,0,12" Icon="{ui:SymbolIcon Symbol=Window24}" Height="75">
|
||||
<ui:CardControl.Header>
|
||||
<ui:TextBlock Grid.Row="0" FontTypography="Body" Text="Show desktop while locked" />
|
||||
@@ -86,6 +100,13 @@
|
||||
<ui:ToggleSwitch Grid.Column="1" IsChecked="{Binding Settings.HideWindows}" OffContent="Off" OnContent="On" />
|
||||
</ui:CardControl>
|
||||
|
||||
<ui:CardControl Margin="0,0,0,12" Icon="{ui:SymbolIcon Symbol=Blur24}" Height="75">
|
||||
<ui:CardControl.Header>
|
||||
<ui:TextBlock Grid.Row="0" FontTypography="Body" Text="Blur screen while locked" />
|
||||
</ui:CardControl.Header>
|
||||
<ui:ToggleSwitch Grid.Column="1" IsChecked="{Binding Settings.BlurScreen}" OffContent="Off" OnContent="On" />
|
||||
</ui:CardControl>
|
||||
|
||||
<ui:CardControl Margin="0,0,0,12" Icon="{ui:SymbolIcon Symbol=WindowShield24}" Height="75">
|
||||
<ui:CardControl.Header>
|
||||
<ui:TextBlock Grid.Row="0" FontTypography="Body" Text="Use windows lock screen to unlock" />
|
||||
|
||||
@@ -17,6 +17,7 @@ public class Settings : INotifyPropertyChanged
|
||||
private static readonly string settingsPath = Path.Combine(App.ApplicationDataPath, "settings.json");
|
||||
private bool useWindowsLockScreen = true;
|
||||
private bool hideWindows = false;
|
||||
private bool blurScreen = false;
|
||||
private string lockText = "Lock Screen Active";
|
||||
private string theme = "Windows default";
|
||||
private HashSet<KeyCode> lockShortcut = [KeyCode.VcLeftControl, KeyCode.VcLeftShift, KeyCode.VcL];
|
||||
@@ -34,6 +35,16 @@ public class Settings : INotifyPropertyChanged
|
||||
}
|
||||
}
|
||||
|
||||
public bool BlurScreen
|
||||
{
|
||||
get => blurScreen;
|
||||
set
|
||||
{
|
||||
blurScreen = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public bool UseWindowsLockScreen
|
||||
{
|
||||
get => useWindowsLockScreen;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Interop;
|
||||
|
||||
namespace InvLock.Utilities;
|
||||
|
||||
@@ -70,12 +72,46 @@ public static class WindowsApi
|
||||
_ = ShowWindow(hWnd, show ? SW_SHOW : SW_HIDE);
|
||||
}
|
||||
|
||||
public static bool SetCursorPosition(Point point)
|
||||
{
|
||||
return SetCursorPos((int)point.X, (int)point.Y);
|
||||
}
|
||||
|
||||
public static void EnableBlur(Window window)
|
||||
{
|
||||
WindowInteropHelper windowHelper = new WindowInteropHelper(window);
|
||||
|
||||
AccentPolicy accent = new AccentPolicy
|
||||
{
|
||||
AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND
|
||||
};
|
||||
|
||||
int accentStructSize = Marshal.SizeOf(accent);
|
||||
|
||||
nint accentPtr = Marshal.AllocHGlobal(accentStructSize);
|
||||
Marshal.StructureToPtr(accent, accentPtr, false);
|
||||
|
||||
WindowCompositionAttributeData data = new WindowCompositionAttributeData
|
||||
{
|
||||
Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY,
|
||||
SizeOfData = accentStructSize,
|
||||
Data = accentPtr
|
||||
};
|
||||
|
||||
_ = SetWindowCompositionAttribute(windowHelper.Handle, ref data);
|
||||
|
||||
Marshal.FreeHGlobal(accentPtr);
|
||||
}
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
internal static extern bool LockWorkStation();
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
internal static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool EnumWindows(EnumWindowsProc enumFunc, int lParam);
|
||||
|
||||
@@ -102,4 +138,41 @@ public static class WindowsApi
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool IsIconic(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool SetCursorPos(int x, int y);
|
||||
|
||||
internal enum AccentState
|
||||
{
|
||||
ACCENT_DISABLED = 1,
|
||||
ACCENT_ENABLE_GRADIENT = 0,
|
||||
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
|
||||
ACCENT_ENABLE_BLURBEHIND = 3,
|
||||
ACCENT_INVALID_STATE = 4
|
||||
}
|
||||
|
||||
internal enum WindowCompositionAttribute
|
||||
{
|
||||
// ...
|
||||
WCA_ACCENT_POLICY = 19
|
||||
|
||||
// ...
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct AccentPolicy
|
||||
{
|
||||
public AccentState AccentState;
|
||||
public int AccentFlags;
|
||||
public int GradientColor;
|
||||
public int AnimationId;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct WindowCompositionAttributeData
|
||||
{
|
||||
public WindowCompositionAttribute Attribute;
|
||||
public IntPtr Data;
|
||||
public int SizeOfData;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user