Skip to content

Commit f509f26

Browse files
committed
redid everyfin :P
1 parent a8d6f3d commit f509f26

File tree

14 files changed

+892
-1
lines changed

14 files changed

+892
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.vs
2-
Borderlesser\bin
2+
Borderlesser/bin
3+
Borderlesser/obj
4+
packages

Borderlesser.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28010.2046
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Borderlesser", "Borderlesser\Borderlesser.csproj", "{D9C02D14-F592-4B47-B2EC-05FD6842A85B}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{D9C02D14-F592-4B47-B2EC-05FD6842A85B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{D9C02D14-F592-4B47-B2EC-05FD6842A85B}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{D9C02D14-F592-4B47-B2EC-05FD6842A85B}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{D9C02D14-F592-4B47-B2EC-05FD6842A85B}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {3441DC98-44C9-4580-9B99-682A3C3D7047}
24+
EndGlobalSection
25+
EndGlobal

Borderlesser/App.xaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Application x:Class="Borderlesser.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:Borderlesser"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
10+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
11+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
12+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
13+
<!-- Accent and AppTheme setting -->
14+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Purple.xaml" />
15+
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
16+
</ResourceDictionary.MergedDictionaries>
17+
</ResourceDictionary>
18+
</Application.Resources>
19+
</Application>

Borderlesser/App.xaml.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace Borderlesser {
10+
/// <summary>
11+
/// Interaction logic for App.xaml
12+
/// </summary>
13+
public partial class App : Application {
14+
}
15+
}

Borderlesser/Borderlesser.csproj

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{D9C02D14-F592-4B47-B2EC-05FD6842A85B}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<RootNamespace>Borderlesser</RootNamespace>
10+
<AssemblyName>Borderlesser</AssemblyName>
11+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<WarningLevel>4</WarningLevel>
15+
<Deterministic>true</Deterministic>
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<PlatformTarget>AnyCPU</PlatformTarget>
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<PlatformTarget>AnyCPU</PlatformTarget>
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<Reference Include="ControlzEx, Version=3.0.2.4, Culture=neutral, processorArchitecture=MSIL">
38+
<HintPath>..\packages\ControlzEx.3.0.2.4\lib\net45\ControlzEx.dll</HintPath>
39+
</Reference>
40+
<Reference Include="MahApps.Metro, Version=1.6.5.1, Culture=neutral, processorArchitecture=MSIL">
41+
<HintPath>..\packages\MahApps.Metro.1.6.5\lib\net45\MahApps.Metro.dll</HintPath>
42+
</Reference>
43+
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
44+
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
45+
</Reference>
46+
<Reference Include="System" />
47+
<Reference Include="System.Data" />
48+
<Reference Include="System.Drawing" />
49+
<Reference Include="System.Windows.Forms" />
50+
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
51+
<HintPath>..\packages\ControlzEx.3.0.2.4\lib\net45\System.Windows.Interactivity.dll</HintPath>
52+
</Reference>
53+
<Reference Include="System.Xml" />
54+
<Reference Include="Microsoft.CSharp" />
55+
<Reference Include="System.Core" />
56+
<Reference Include="System.Xml.Linq" />
57+
<Reference Include="System.Data.DataSetExtensions" />
58+
<Reference Include="System.Net.Http" />
59+
<Reference Include="System.Xaml">
60+
<RequiredTargetFramework>4.0</RequiredTargetFramework>
61+
</Reference>
62+
<Reference Include="WindowsBase" />
63+
<Reference Include="PresentationCore" />
64+
<Reference Include="PresentationFramework" />
65+
</ItemGroup>
66+
<ItemGroup>
67+
<ApplicationDefinition Include="App.xaml">
68+
<Generator>MSBuild:Compile</Generator>
69+
<SubType>Designer</SubType>
70+
</ApplicationDefinition>
71+
<Compile Include="Main.cs" />
72+
<Compile Include="Config.cs" />
73+
<Compile Include="Hotkey.cs" />
74+
<Compile Include="Win32.cs" />
75+
<Page Include="MainWindow.xaml">
76+
<Generator>MSBuild:Compile</Generator>
77+
<SubType>Designer</SubType>
78+
</Page>
79+
<Compile Include="App.xaml.cs">
80+
<DependentUpon>App.xaml</DependentUpon>
81+
<SubType>Code</SubType>
82+
</Compile>
83+
<Compile Include="MainWindow.xaml.cs">
84+
<DependentUpon>MainWindow.xaml</DependentUpon>
85+
<SubType>Code</SubType>
86+
</Compile>
87+
</ItemGroup>
88+
<ItemGroup>
89+
<Compile Include="Properties\AssemblyInfo.cs">
90+
<SubType>Code</SubType>
91+
</Compile>
92+
<None Include="config.json">
93+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
94+
</None>
95+
<None Include="packages.config" />
96+
</ItemGroup>
97+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
98+
</Project>

Borderlesser/Config.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Newtonsoft.Json;
2+
using System.Windows.Forms;
3+
using System.Windows;
4+
using System.IO;
5+
6+
namespace Borderlesser {
7+
class Config {
8+
private const string CONFIG_PATH = "config.json";
9+
public static Config Instance;
10+
11+
public HotKeyModifiers HotKeyModifier { get; set; } = HotKeyModifiers.None;
12+
public Keys Hotkey { get; set; } = Keys.Insert;
13+
14+
public WindowStyles Styles { get; set; } = WindowStyles.WS_VISIBLE;
15+
public WindowStylesEx StylesEx { get; set; } = 0;
16+
17+
public bool Autostart { get; set; } = false;
18+
19+
public int ScreenWidth { get; set; } = (int)SystemParameters.PrimaryScreenWidth;
20+
public int ScreenHeigth { get; set; } = (int)SystemParameters.PrimaryScreenHeight;
21+
22+
public int FromX { get; set; } = 0;
23+
public int FromY { get; set; } = 0;
24+
25+
private string Serialize() {
26+
return JsonConvert.SerializeObject(this, Formatting.Indented);
27+
}
28+
29+
private static Config Deserilize(string json) {
30+
// return the default config
31+
if(string.IsNullOrEmpty(json)) return new Config();
32+
return JsonConvert.DeserializeObject<Config>(json);
33+
}
34+
35+
static Config() {
36+
try { Instance = Deserilize(File.ReadAllText(CONFIG_PATH)); }
37+
catch(IOException) {
38+
// create default config
39+
Instance = new Config();
40+
}
41+
}
42+
43+
public void WriteConfig() {
44+
File.WriteAllText(CONFIG_PATH, Serialize());
45+
}
46+
}
47+
}

Borderlesser/Hotkey.cs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System;
2+
using System.Windows.Interop;
3+
using System.Threading;
4+
using System.Windows;
5+
using System.Windows.Forms;
6+
7+
namespace Borderlesser {
8+
// stole this from here: https://www.pinvoke.net/default.aspx/user32/RegisterHotKey.html
9+
class Hotkey : IDisposable {
10+
public const int WM_HOTKEY = 0x312;
11+
12+
/// <summary>
13+
/// The unique ID to receive hotkey messages
14+
/// </summary>
15+
public short HotkeyID { get; private set; }
16+
17+
/// <summary>
18+
/// Handle to the window listening to hotkeys
19+
/// </summary>
20+
private readonly IntPtr m_windowHandle;
21+
22+
/// <summary>
23+
/// Callback for hot keys
24+
/// </summary>
25+
readonly Action m_onHotKeyPressed;
26+
27+
public Hotkey(Window handlerWindow, Action hotKeyHandler, Keys key, HotKeyModifiers modifiers) {
28+
m_onHotKeyPressed = hotKeyHandler;
29+
30+
// Create a unique Id for this class in this instance
31+
string atomName = Thread.CurrentThread.ManagedThreadId.ToString("X8") + GetType().FullName;
32+
HotkeyID = Win32.GlobalAddAtom(atomName);
33+
34+
// Set up the hook to listen for hot keys
35+
m_windowHandle = new WindowInteropHelper(handlerWindow).EnsureHandle();
36+
if (m_windowHandle == null) throw new ApplicationException(
37+
"Cannot find window handle. Try calling this on or after OnSourceInitialized()"
38+
);
39+
40+
HwndSource source = HwndSource.FromHwnd(m_windowHandle);
41+
source.AddHook(HwndHook);
42+
43+
ListenForHotKey(key, modifiers);
44+
}
45+
46+
/// <summary>
47+
/// Intermediate processing of hotkeys
48+
/// </summary>
49+
private IntPtr HwndHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) {
50+
if (msg == WM_HOTKEY) {
51+
if(wParam.ToInt32() == HotkeyID) {
52+
m_onHotKeyPressed?.Invoke();
53+
handled = true;
54+
}
55+
}
56+
return IntPtr.Zero;
57+
}
58+
59+
/// <summary>
60+
/// Tell what key you want to listen for.
61+
/// </summary>
62+
public void ListenForHotKey(Keys key, HotKeyModifiers modifiers) {
63+
Win32.UnregisterHotKey(m_windowHandle, HotkeyID);
64+
Win32.RegisterHotKey(m_windowHandle, HotkeyID, modifiers, (uint)key);
65+
}
66+
67+
/// <summary>
68+
/// Stop listening for hotkeys
69+
/// </summary>
70+
private void StopListening() {
71+
if (HotkeyID != 0) {
72+
Win32.UnregisterHotKey(m_windowHandle, HotkeyID);
73+
// clean up the atom list
74+
Win32.GlobalDeleteAtom(HotkeyID);
75+
HotkeyID = 0;
76+
}
77+
}
78+
79+
public void Dispose() {
80+
StopListening();
81+
}
82+
}
83+
}

Borderlesser/Main.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.IO;
3+
using System.Windows;
4+
using System.Runtime.InteropServices;
5+
using System.Windows.Forms;
6+
7+
namespace Borderlesser {
8+
class Main {
9+
private readonly Hotkey m_hotkey;
10+
11+
public Main(Window window) {
12+
m_hotkey = new Hotkey(window, MakeBorderless, Config.Instance.Hotkey, Config.Instance.HotKeyModifier);
13+
}
14+
15+
private void MakeBorderless() {
16+
HandleRef target = new HandleRef(this, Win32.GetForegroundWindow());
17+
18+
// set window style
19+
Win32.SetWindowLongPtr(target, WindowLongFlags.GWL_STYLE, new IntPtr((int)Config.Instance.Styles));
20+
// set window style ex
21+
Win32.SetWindowLongPtr(target, WindowLongFlags.GWL_EXSTYLE, new IntPtr((int)Config.Instance.StylesEx));
22+
23+
// make window full size
24+
Win32.SetWindowPos(
25+
target.Handle,
26+
new IntPtr((int)InserAfterFlags.HWND_TOPMOST),
27+
Config.Instance.FromX,
28+
Config.Instance.FromY,
29+
Config.Instance.ScreenWidth,
30+
Config.Instance.ScreenHeigth,
31+
SetWindowPosFlags.FrameChanged
32+
);
33+
}
34+
35+
public void SetAutostart(bool autostart) {
36+
Config.Instance.Autostart = autostart;
37+
var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(
38+
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
39+
40+
if (autostart) key.SetValue("Borderlesser", System.Windows.Forms.Application.ExecutablePath);
41+
else key.DeleteValue("Borderlesser");
42+
}
43+
44+
public void SetHotkey(Keys key, HotKeyModifiers mod) {
45+
Config.Instance.Hotkey = key;
46+
Config.Instance.HotKeyModifier = mod;
47+
48+
m_hotkey.ListenForHotKey(key, mod);
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)