Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions App.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Application x:Class="RoundedWindowsEdges.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:RoundedWindowsEdges"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
<Application x:Class="RoundedWindowsEdges.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:RoundedWindowsEdges"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
138 changes: 69 additions & 69 deletions App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows;
using Forms = System.Windows.Forms;

namespace RoundedWindowsEdges
{
public partial class App : Application
{
private TrayIcon trayIcon;
private MainWindow[] mainWindows;

protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
AppConfig config = AppConfig.LoadConfig();
int screenCount = Forms.Screen.AllScreens.Length;
mainWindows = new MainWindow[screenCount];

for (int i = 0; i < screenCount; i++)
{
var screen = Forms.Screen.AllScreens[i];
var bounds = screen.Bounds;

var dpiScale = GetDpiScale(screen);
Debug.WriteLine($"Screen {i}: Bounds = {bounds}, DPI Scale = {dpiScale}");

var rect = new Rect(bounds.X, bounds.Y, bounds.Width, bounds.Height);

if (mainWindows[i] == null)
{
mainWindows[i] = new MainWindow(rect, config.CornerSize);
mainWindows[i].Show();
}
}

trayIcon = new TrayIcon(mainWindows[0]);
}

protected override void OnExit(ExitEventArgs e)
{
foreach (var window in mainWindows)
{
window.Close();
}

trayIcon.Dispose();
base.OnExit(e);
}

private double GetDpiScale(Forms.Screen screen)
{
using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
{
IntPtr desktop = g.GetHdc();
int dpiX = GetDeviceCaps(desktop, 88);
int dpiY = GetDeviceCaps(desktop, 90);
g.ReleaseHdc(desktop);

return dpiX / 96.0;
}
}

[DllImport("gdi32.dll")]
static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
}
}
using System;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows;
using Forms = System.Windows.Forms;
namespace RoundedWindowsEdges
{
public partial class App : Application
{
private TrayIcon trayIcon;
private MainWindow[] mainWindows;
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
AppConfig config = AppConfig.LoadConfig();
int screenCount = Forms.Screen.AllScreens.Length;
mainWindows = new MainWindow[screenCount];
for (int i = 0; i < screenCount; i++)
{
var screen = Forms.Screen.AllScreens[i];
var bounds = screen.Bounds;
var dpiScale = GetDpiScale(screen);
Debug.WriteLine($"Screen {i}: Bounds = {bounds}, DPI Scale = {dpiScale}");
var rect = new Rect(
bounds.X / dpiScale,
bounds.Y / dpiScale,
bounds.Width / dpiScale,
bounds.Height / dpiScale
);
int scaledCornerSize = (int)(config.CornerSize * dpiScale);
if (mainWindows[i] == null)
{
mainWindows[i] = new MainWindow(rect, scaledCornerSize);
mainWindows[i].Show();
}
}
trayIcon = new TrayIcon(mainWindows[0]);
}
protected override void OnExit(ExitEventArgs e)
{
foreach (var window in mainWindows)
{
window.Close();
}
trayIcon.Dispose();
base.OnExit(e);
}
private double GetDpiScale(Forms.Screen screen)
{
using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
{
IntPtr desktop = g.GetHdc();
int dpiX = GetDeviceCaps(desktop, 88);
int dpiY = GetDeviceCaps(desktop, 90);
g.ReleaseHdc(desktop);
return dpiX / 96.0;
}
}
[DllImport("gdi32.dll")]
static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
}
}
79 changes: 37 additions & 42 deletions AppConfig.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,37 @@
using System;
using System.IO;
using Newtonsoft.Json;

namespace RoundedWindowsEdges
{
public class AppConfig
{
public int CornerSize { get; set; } = 20;

private static readonly string configFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json");

public static AppConfig LoadConfig()
{
if (File.Exists(configFilePath))
{
try
{
string json = File.ReadAllText(configFilePath);
return JsonConvert.DeserializeObject<AppConfig>(json);
}
catch
{
return new AppConfig();
}
}
return new AppConfig();
}

public void SaveConfig()
{
try
{
string json = JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
File.WriteAllText(configFilePath, json);
}
catch
{
}
}
}
}
using System;
using System.IO;
using Newtonsoft.Json;

namespace RoundedWindowsEdges
{
public class AppConfig
{
public int CornerSize { get; set; } = 20;
private static readonly string configFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json");
public static AppConfig LoadConfig()
{
if (File.Exists(configFilePath))
{
try
{
string json = File.ReadAllText(configFilePath);
return JsonConvert.DeserializeObject<AppConfig>(json);
}
catch
{
return new AppConfig();
}
}
return new AppConfig();
}
public void SaveConfig()
{
try
{
string json = JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
File.WriteAllText(configFilePath, json);
}
catch{}
}
}
}
Loading