mirror of
https://github.com/tuxdotrs/highminded.git
synced 2025-08-23 08:01:03 +05:30
feat: initial commit
This commit is contained in:
53
ui/windows/MainWindow.axaml
Normal file
53
ui/windows/MainWindow.axaml
Normal file
@@ -0,0 +1,53 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
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:iconPacks="https://github.com/MahApps/IconPacks.Avalonia"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="highminded.ui.windows.MainWindow"
|
||||
Title="highminded"
|
||||
Height="600"
|
||||
Width="800"
|
||||
ShowInTaskbar="False"
|
||||
ShowActivated="True"
|
||||
Topmost="True"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
SystemDecorations="None"
|
||||
TransparencyLevelHint="Transparent"
|
||||
Background="Transparent"
|
||||
Foreground="#fff"
|
||||
TransparencyBackgroundFallback="Transparent"
|
||||
FontSize="16">
|
||||
<Grid RowDefinitions="Auto,*" Margin="5" RowSpacing="10">
|
||||
<Border Grid.Row="0" CornerRadius="5" Background="Black" Opacity="0.8" PointerPressed="OnPointerPressed">
|
||||
<Grid ColumnDefinitions="*,Auto" Margin="15 10">
|
||||
<TextBlock Grid.Column="0" VerticalAlignment="Center" Margin="5">High Minded</TextBlock>
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center">
|
||||
<Border Background="Black" BorderBrush="#19ffffff" BorderThickness="2" CornerRadius="5"
|
||||
Margin="0 0 10 0">
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
Spacing="5" Margin="10 0">
|
||||
<TextBlock FontSize="12" Text="Hide:" />
|
||||
<TextBlock FontSize="12" Text="CTRL + \" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
<Button Name="ChatBtn" Background="Transparent" Click="ChatBtnClick">
|
||||
<iconPacks:PackIconLucide Grid.Column="1" Kind="Brain" Height="16" Width="16" />
|
||||
</Button>
|
||||
<Button Name="SettingsBtn" Background="Transparent" Click="SettingBtnClick">
|
||||
<iconPacks:PackIconLucide Grid.Column="1" Kind="Settings" Height="16" Width="16" />
|
||||
</Button>
|
||||
<Button Name="HideBtn" Background="Transparent">
|
||||
<iconPacks:PackIconLucide Grid.Column="1" Kind="X" Height="13" Width="13" />
|
||||
</Button>
|
||||
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<Border Grid.Row="1" CornerRadius="5" Background="Black" Opacity="0.8">
|
||||
<UserControl Name="UControl" />
|
||||
</Border>
|
||||
</Grid>
|
||||
</Window>
|
167
ui/windows/MainWindow.axaml.cs
Normal file
167
ui/windows/MainWindow.axaml.cs
Normal file
@@ -0,0 +1,167 @@
|
||||
using Avalonia.Controls;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Threading;
|
||||
using highminded.ui.controls;
|
||||
using SharpHook;
|
||||
using SharpHook.Data;
|
||||
|
||||
namespace highminded.ui.windows;
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
// MacOS
|
||||
private const string ObjCRuntime = "/usr/lib/libobjc.dylib";
|
||||
|
||||
[DllImport(ObjCRuntime, EntryPoint = "objc_msgSend")]
|
||||
private static extern void ObjcMsgSendInt(nint receiver, nint selector, int value);
|
||||
|
||||
[DllImport(ObjCRuntime, EntryPoint = "sel_registerName")]
|
||||
private static extern nint RegisterName(string name);
|
||||
|
||||
// Windows
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool SetWindowDisplayAffinity(IntPtr hWnd, uint dwAffinity);
|
||||
|
||||
// Controls
|
||||
private readonly ChatUserControl _chatUserControl = new ChatUserControl();
|
||||
private readonly SettingsUserControl _settingsUserControl = new SettingsUserControl();
|
||||
|
||||
// Hotkey
|
||||
private readonly TaskPoolGlobalHook _hook = new TaskPoolGlobalHook();
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
UControl.Content = _chatUserControl;
|
||||
ChatBtnActive();
|
||||
HideOverlay();
|
||||
// Global Hotkey
|
||||
_hook.KeyPressed += OnKeyPressed;
|
||||
_hook.RunAsync();
|
||||
}
|
||||
|
||||
private void OnPointerPressed(object? sender, PointerPressedEventArgs e)
|
||||
{
|
||||
BeginMoveDrag(e);
|
||||
}
|
||||
|
||||
private void ChatBtnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
UControl.Content = _chatUserControl;
|
||||
ChatBtnActive();
|
||||
}
|
||||
|
||||
private void SettingBtnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
UControl.Content = _settingsUserControl;
|
||||
SettingsBtnActive();
|
||||
}
|
||||
|
||||
private void ChatBtnActive()
|
||||
{
|
||||
ChatBtn.Background = new SolidColorBrush(Color.FromArgb(25, 255, 255, 255));
|
||||
SettingsBtn.Background = new SolidColorBrush(Colors.Transparent);
|
||||
}
|
||||
|
||||
private void SettingsBtnActive()
|
||||
{
|
||||
ChatBtn.Background = new SolidColorBrush(Colors.Transparent);
|
||||
SettingsBtn.Background = new SolidColorBrush(Color.FromArgb(25, 255, 255, 255));
|
||||
}
|
||||
|
||||
private void OnKeyPressed(object? sender, KeyboardHookEventArgs e)
|
||||
{
|
||||
bool hasCtrl = (e.RawEvent.Mask & EventMask.Ctrl) != EventMask.None;
|
||||
bool hasAlt = (e.RawEvent.Mask & EventMask.Alt) != EventMask.None;
|
||||
bool hasShift = (e.RawEvent.Mask & EventMask.Shift) != EventMask.None;
|
||||
bool hasH = e.Data.KeyCode == KeyCode.VcH;
|
||||
bool hasBackslash = e.Data.KeyCode == KeyCode.VcBackslash;
|
||||
|
||||
if (hasCtrl && hasShift && hasAlt && hasH)
|
||||
{
|
||||
ShowOverlay();
|
||||
}
|
||||
|
||||
if (hasShift && hasBackslash)
|
||||
{
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
if (WindowState == WindowState.Minimized || !IsVisible)
|
||||
{
|
||||
Show();
|
||||
WindowState = WindowState.Normal;
|
||||
Activate();
|
||||
Topmost = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowOverlay()
|
||||
{
|
||||
var handle = TryGetPlatformHandle();
|
||||
|
||||
if (handle is null || handle.Handle == IntPtr.Zero)
|
||||
{
|
||||
Console.WriteLine("Invalid window handle.");
|
||||
return;
|
||||
}
|
||||
|
||||
var hwnd = handle.Handle;
|
||||
|
||||
switch (handle.HandleDescriptor)
|
||||
{
|
||||
case "HWND":
|
||||
{
|
||||
const uint include = 0x00000000;
|
||||
SetWindowDisplayAffinity(hwnd, include);
|
||||
break;
|
||||
}
|
||||
case "NSWindow":
|
||||
{
|
||||
const int include = 2;
|
||||
var sharingTypeSelector = RegisterName("setSharingType:");
|
||||
ObjcMsgSendInt(hwnd, sharingTypeSelector, include);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void HideOverlay()
|
||||
{
|
||||
var handle = TryGetPlatformHandle();
|
||||
|
||||
if (handle is null || handle.Handle == IntPtr.Zero)
|
||||
{
|
||||
Console.WriteLine("Invalid window handle.");
|
||||
return;
|
||||
}
|
||||
|
||||
var hwnd = handle.Handle;
|
||||
|
||||
switch (handle.HandleDescriptor)
|
||||
{
|
||||
case "HWND":
|
||||
{
|
||||
const uint exclude = 0x00000011;
|
||||
SetWindowDisplayAffinity(hwnd, exclude);
|
||||
break;
|
||||
}
|
||||
case "NSWindow":
|
||||
{
|
||||
const int exclude = 0;
|
||||
var sharingTypeSelector = RegisterName("setSharingType:");
|
||||
ObjcMsgSendInt(hwnd, sharingTypeSelector, exclude);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user