diff --git a/App.xaml b/App.xaml index 9c356f6..c9f2a0a 100644 --- a/App.xaml +++ b/App.xaml @@ -1,9 +1,9 @@ - - - - - + + + + + diff --git a/App.xaml.cs b/App.xaml.cs index 2b45468..244958a 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -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); + } +} diff --git a/AppConfig.cs b/AppConfig.cs index d1e587e..1179f95 100644 --- a/AppConfig.cs +++ b/AppConfig.cs @@ -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(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(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{} + } + } +} diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index a921742..3ebb529 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -1,114 +1,109 @@ -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Windows; -using System.Windows.Interop; - -namespace RoundedWindowsEdges -{ - public partial class MainWindow : Window - { - public const int WS_EX_TRANSPARENT = 0x00000020; - public const int GWL_EXSTYLE = (-20); - public const int WS_EX_TOOLWINDOW = 0x00000080; - - [DllImport("user32.dll")] - public static extern int GetWindowLong(IntPtr hwnd, int index); - - [DllImport("user32.dll")] - public static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle); - - private AppConfig config; - private int currentCornerSize; - - public MainWindow() - { - InitializeComponent(); - DataContext = this; - } - - public MainWindow(Rect screenBounds, int cornerSize) : this() - { - InitializeForScreen(screenBounds, cornerSize); - LoadConfig(); - } - - private void InitializeForScreen(Rect screenBounds, int cornerSize) - { - this.CornerSize = cornerSize; - this.Left = screenBounds.Left; - this.Top = screenBounds.Top; - this.Width = screenBounds.Width; - this.Height = screenBounds.Height; - - Debug.WriteLine($"Window initialized: Left = {this.Left}, Top = {this.Top}, Width = {this.Width}, Height = {this.Height}"); - } - - public int CornerSize { get; set; } - - protected override void OnSourceInitialized(EventArgs e) - { - base.OnSourceInitialized(e); - IntPtr hwnd = new WindowInteropHelper(this).Handle; - int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE); - SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW); - } - - private void WndRoundedWindowsEdges_Closing(object sender, System.ComponentModel.CancelEventArgs e) - { - e.Cancel = true; - this.Hide(); // Hide instead of cancelling close to ensure cleanup - } - - private void WndRoundedWindowsEdges_Loaded(object sender, RoutedEventArgs e) - { - Point location = this.PointToScreen(new Point(0, 0)); - this.WindowStartupLocation = WindowStartupLocation.Manual; - } - - private void WndRoundedWindowsEdges_LostFocus(object sender, RoutedEventArgs e) - { - this.Activate(); - this.Topmost = true; - this.Topmost = false; - this.Focus(); - } - - public void ChangeCornerSize(int size) - { - Debug.WriteLine("ChangeCornerSize method called"); - imgCornerTL.Width = size; - imgCornerTL.Height = size; - imgCornerTR.Width = size; - imgCornerTR.Height = size; - imgCornerBR.Width = size; - imgCornerBR.Height = size; - imgCornerBL.Width = size; - imgCornerBL.Height = size; - - Debug.WriteLine($"Changing corner size to {size}"); - Debug.WriteLine($"imgCornerTL: {imgCornerTL.Visibility}, {imgCornerTL.Width}, {imgCornerTL.Height}"); - Debug.WriteLine($"imgCornerTR: {imgCornerTR.Visibility}, {imgCornerTR.Width}, {imgCornerTR.Height}"); - Debug.WriteLine($"imgCornerBR: {imgCornerBR.Visibility}, {imgCornerBR.Width}, {imgCornerBR.Height}"); - Debug.WriteLine($"imgCornerBL: {imgCornerBL.Visibility}, {imgCornerBL.Width}, {imgCornerBL.Height}"); - - // Save the new size to the config file - config.CornerSize = size; - config.SaveConfig(); - - currentCornerSize = size; - } - - private void LoadConfig() - { - Debug.WriteLine("LoadConfig method called"); - config = AppConfig.LoadConfig(); - ChangeCornerSize(config.CornerSize); - } - - public int GetCornerSize() - { - return currentCornerSize; - } - } -} +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; +using System.Windows; +using System.Windows.Interop; + +namespace RoundedWindowsEdges +{ + public partial class MainWindow : Window + { + public const int WS_EX_TRANSPARENT = 0x00000020; + public const int GWL_EXSTYLE = (-20); + public const int WS_EX_TOOLWINDOW = 0x00000080; + + [DllImport("user32.dll")] + public static extern int GetWindowLong(IntPtr hwnd, int index); + + [DllImport("user32.dll")] + public static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle); + + private AppConfig config; + private int currentCornerSize; + + public MainWindow() + { + InitializeComponent(); + DataContext = this; + } + + public MainWindow(Rect screenBounds, int cornerSize) : this() + { + InitializeForScreen(screenBounds, cornerSize); + LoadConfig(); + } + + private void InitializeForScreen(Rect screenBounds, int cornerSize) + { + this.CornerSize = cornerSize; + this.Left = screenBounds.Left; + this.Top = screenBounds.Top; + this.Width = screenBounds.Width; + this.Height = screenBounds.Height; + Debug.WriteLine($"Window initialized: Left = {this.Left}, Top = {this.Top}, Width = {this.Width}, Height = {this.Height}"); + } + + public int CornerSize { get; set; } + + protected override void OnSourceInitialized(EventArgs e) + { + base.OnSourceInitialized(e); + IntPtr hwnd = new WindowInteropHelper(this).Handle; + int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE); + SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW); + } + + private void WndRoundedWindowsEdges_Closing(object sender, System.ComponentModel.CancelEventArgs e) + { + e.Cancel = true; + this.Hide(); + } + + private void WndRoundedWindowsEdges_Loaded(object sender, RoutedEventArgs e) + { + Point location = this.PointToScreen(new Point(0, 0)); + this.WindowStartupLocation = WindowStartupLocation.Manual; + } + + private void WndRoundedWindowsEdges_LostFocus(object sender, RoutedEventArgs e) + { + this.Activate(); + this.Topmost = true; + this.Topmost = false; + this.Focus(); + } + + public void ChangeCornerSize(int size) + { + Debug.WriteLine("ChangeCornerSize method called"); + imgCornerTL.Width = size; + imgCornerTL.Height = size; + imgCornerTR.Width = size; + imgCornerTR.Height = size; + imgCornerBR.Width = size; + imgCornerBR.Height = size; + imgCornerBL.Width = size; + imgCornerBL.Height = size; + Debug.WriteLine($"Changing corner size to {size}"); + Debug.WriteLine($"imgCornerTL: {imgCornerTL.Visibility}, {imgCornerTL.Width}, {imgCornerTL.Height}"); + Debug.WriteLine($"imgCornerTR: {imgCornerTR.Visibility}, {imgCornerTR.Width}, {imgCornerTR.Height}"); + Debug.WriteLine($"imgCornerBR: {imgCornerBR.Visibility}, {imgCornerBR.Width}, {imgCornerBR.Height}"); + Debug.WriteLine($"imgCornerBL: {imgCornerBL.Visibility}, {imgCornerBL.Width}, {imgCornerBL.Height}"); + config.CornerSize = size; + config.SaveConfig(); + currentCornerSize = size; + } + + private void LoadConfig() + { + Debug.WriteLine("LoadConfig method called"); + config = AppConfig.LoadConfig(); + ChangeCornerSize(config.CornerSize); + } + + public int GetCornerSize() + { + return currentCornerSize; + } + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 622b362..3559212 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -1,55 +1,20 @@ -using System.Reflection; -using System.Resources; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Windows; - -// Les informations générales relatives à un assembly dépendent de -// l'ensemble d'attributs suivant. Pour modifier les informations -// associées à un assembly. -[assembly: AssemblyTitle("RoundedWindowsEdges")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("RoundedWindowsEdges")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly -// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de -// COM, affectez la valeur True à l'attribut ComVisible sur ce type. -[assembly: ComVisible(false)] - -//Pour commencer à générer des applications localisables, définissez -//CultureUtiliséePourCoder dans votre fichier .csproj -//dans . Par exemple, si vous utilisez le français -//dans vos fichiers sources, définissez à fr-FR. Puis, supprimez les marques de commentaire de -//l'attribut NeutralResourceLanguage ci-dessous. Mettez à jour "fr-FR" dans -//la ligne ci-après pour qu'elle corresponde au paramètre UICulture du fichier projet. - -//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] - - -[assembly: ThemeInfo( - ResourceDictionaryLocation.None, //où se trouvent les dictionnaires de ressources spécifiques à un thème - //(utilisé si une ressource est introuvable dans la page, - // ou dictionnaires de ressources de l'application) - ResourceDictionaryLocation.SourceAssembly //où se trouve le dictionnaire de ressources générique - //(utilisé si une ressource est introuvable dans la page, - // dans l'application ou dans l'un des dictionnaires de ressources spécifiques à un thème) -)] - - -// Les informations de version pour un assembly se composent des quatre valeurs suivantes : -// -// Version principale -// Version secondaire -// Numéro de build -// Révision -// -// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut -// en utilisant '*', comme indiqué ci-dessous : -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.0.0")] -[assembly: AssemblyFileVersion("2.0.0.0")] +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; +[assembly: AssemblyTitle("RoundedWindowsEdges")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("RoundedWindowsEdges")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: ComVisible(false)] +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, + ResourceDictionaryLocation.SourceAssembly +)] +[assembly: AssemblyVersion("2.0.0.0")] +[assembly: AssemblyFileVersion("2.0.0.0")] diff --git a/README.md b/README.md index 63422bc..846852b 100644 --- a/README.md +++ b/README.md @@ -1,140 +1,140 @@ -# Rounded Windows Edges - -Rounded Windows Edges is a Windows utility that enhances your user interface by adding customizable rounded corners to all application windows across multiple monitors. This application is designed to provide a modern and aesthetically pleasing look to your desktop environment. - - -![Screenshot](https://github.com/mauriciobellon/rounded-windows-edges/blob/main/rounded_windows_edges.png?raw=true) - - -## Table of Contents - -- [Features](#features) -- [Prerequisites](#prerequisites) -- [Installation](#installation) -- [Usage](#usage) -- [Configuration](#configuration) -- [Development](#development) - - [Code Structure](#code-structure) - - [Building and Running](#building-and-running) - - [Contributing](#contributing) -- [License](#license) -- [Acknowledgements](#acknowledgements) -- [Contact](#contact) - -## Features - -- Automatically detects all connected monitors and applies rounded corners to windows. -- Configurable corner size. -- Runs in the background with a system tray icon for easy access. -- Persistent configuration settings. -- Supports high DPI displays. -- Minimal performance impact. - -## Prerequisites - -- Windows operating system -- .NET Framework -- Visual Studio (for building from source) - -## Installation - -1. Clone the repository: - - ```sh - git clone https://github.com/mauriciobellon/rounded-windows-edges.git - ``` - -2. Open the solution in Visual Studio. - -3. Restore the required NuGet packages. - -4. Build the solution. - -## Usage - -1. Run the application after building it. - -2. The application will automatically detect all connected monitors and apply rounded corners to windows. - -3. Use the tray icon to: - - Open settings and configure the corner size. - - Exit the application. - -## Development - -### Code Structure - -- `App.xaml.cs`: The main application file that initializes the application and sets up the main windows and tray icon. -- `MainWindow.xaml.cs`: Manages the main window for each screen, applying the rounded corners and handling window events. -- `AppConfig.cs`: Handles the loading and saving of configuration settings. -- `TrayIcon.cs`: Manages the system tray icon and context menu. - -### Building and Running - -1. Clone the repository: - - ```sh - git clone https://github.com/mauriciobellon/rounded-windows-edges.git - ``` - -2. Open the solution in Visual Studio. - -3. Restore the required NuGet packages. - -4. Build the solution. - -5. Run the application. - -### Contributing - -1. Fork the repository. - -2. Create a new branch: - - ```sh - git checkout -b feature/your-feature - ``` - -3. Make your changes and commit them: - - ```sh - git commit -m 'Add some feature' - ``` - -4. Push to the branch: - - ```sh - git push origin feature/your-feature - ``` - -5. Open a pull request to the main repository. - -## To Do - -- [x] Add Icon Tray -- [x] Add Settings on Icons Tray -- [x] Add Autostart -- [x] Add support for multiple monitors -- [x] Add support for high DPI displays -- [x] Persistent configuration -- [x] Works with Fullscreen apps -- [x] Create Installation Package -- [ ] Add Screenshot to Readme -- [ ] FEATURE: Autorun after Installation -- [ ] ISSUE: Config only applies changes on app restart -- [ ] ISSUE: Scaled UI not been calculated correctly - -## License - -This project is licensed under the GNU General Public License v3.0. See the [LICENSE](LICENSE) file for details. - -## Acknowledgements - -- Inspired by [BeezBeez/Windows-RoundedScreen](https://github.com/BeezBeez/Windows-RoundedScreen). -- Uses [Newtonsoft.Json](https://www.newtonsoft.com/json) for JSON serialization and deserialization. - -## Contact - -For any questions or suggestions, feel free to open an issue or contact the maintainer: - -- GitHub: [mauriciobellon](https://github.com/mauriciobellon) +# Rounded Windows Edges + +Rounded Windows Edges is a Windows utility that enhances your user interface by adding customizable rounded corners to all application windows across multiple monitors. This application is designed to provide a modern and aesthetically pleasing look to your desktop environment. + + +![Screenshot](https://github.com/mauriciobellon/rounded-windows-edges/blob/main/rounded_windows_edges.png?raw=true) + + +## Table of Contents + +- [Features](#features) +- [Prerequisites](#prerequisites) +- [Installation](#installation) +- [Usage](#usage) +- [Configuration](#configuration) +- [Development](#development) + - [Code Structure](#code-structure) + - [Building and Running](#building-and-running) + - [Contributing](#contributing) +- [License](#license) +- [Acknowledgements](#acknowledgements) +- [Contact](#contact) + +## Features + +- Automatically detects all connected monitors and applies rounded corners to windows. +- Configurable corner size. +- Runs in the background with a system tray icon for easy access. +- Persistent configuration settings. +- Supports high DPI displays. +- Minimal performance impact. + +## Prerequisites + +- Windows operating system +- .NET Framework +- Visual Studio (for building from source) + +## Installation + +1. Clone the repository: + + ```sh + git clone https://github.com/mauriciobellon/rounded-windows-edges.git + ``` + +2. Open the solution in Visual Studio. + +3. Restore the required NuGet packages. + +4. Build the solution. + +## Usage + +1. Run the application after building it. + +2. The application will automatically detect all connected monitors and apply rounded corners to windows. + +3. Use the tray icon to: + - Open settings and configure the corner size. + - Exit the application. + +## Development + +### Code Structure + +- `App.xaml.cs`: The main application file that initializes the application and sets up the main windows and tray icon. +- `MainWindow.xaml.cs`: Manages the main window for each screen, applying the rounded corners and handling window events. +- `AppConfig.cs`: Handles the loading and saving of configuration settings. +- `TrayIcon.cs`: Manages the system tray icon and context menu. + +### Building and Running + +1. Clone the repository: + + ```sh + git clone https://github.com/mauriciobellon/rounded-windows-edges.git + ``` + +2. Open the solution in Visual Studio. + +3. Restore the required NuGet packages. + +4. Build the solution. + +5. Run the application. + +### Contributing + +1. Fork the repository. + +2. Create a new branch: + + ```sh + git checkout -b feature/your-feature + ``` + +3. Make your changes and commit them: + + ```sh + git commit -m 'Add some feature' + ``` + +4. Push to the branch: + + ```sh + git push origin feature/your-feature + ``` + +5. Open a pull request to the main repository. + +## To Do + +- [x] Add Icon Tray +- [x] Add Settings on Icons Tray +- [x] Add Autostart +- [x] Add support for multiple monitors +- [x] Add support for most DPI scalings +- [x] Persistent configuration +- [x] Works with Fullscreen apps +- [x] Create Installation Package +- [x] Calculated Scaled UI +- [x] Add Screenshot to Readme +- [ ] FEATURE: Autorun after Installation +- [ ] ISSUE: Config only applies changes on app restart + +## License + +This project is licensed under the GNU General Public License v3.0. See the [LICENSE](LICENSE) file for details. + +## Acknowledgements + +- Inspired by [BeezBeez/Windows-RoundedScreen](https://github.com/BeezBeez/Windows-RoundedScreen). +- Uses [Newtonsoft.Json](https://www.newtonsoft.com/json) for JSON serialization and deserialization. + +## Contact + +For any questions or suggestions, feel free to open an issue or contact the maintainer: + +- GitHub: [mauriciobellon](https://github.com/mauriciobellon) diff --git a/TrayIcon.cs b/TrayIcon.cs index cb1a059..95ef84f 100644 --- a/TrayIcon.cs +++ b/TrayIcon.cs @@ -1,109 +1,94 @@ -using System; -using System.Diagnostics; -using System.Drawing; -using System.Windows.Forms; -using Microsoft.Win32; - -namespace RoundedWindowsEdges -{ - public class TrayIcon : IDisposable - { - private NotifyIcon notifyIcon; - private MainWindow mainWindow; - - private ToolStripMenuItem smallCornersItem; - private ToolStripMenuItem mediumCornersItem; - private ToolStripMenuItem largeCornersItem; - private ToolStripMenuItem autoStartItem; - - public TrayIcon(MainWindow mainWindow) - { - this.mainWindow = mainWindow; - notifyIcon = new NotifyIcon - { - Icon = Properties.Resources.AppIcon, - Visible = true, - Text = "Rounded Screen" - }; - - var contextMenu = new ContextMenuStrip(); - smallCornersItem = new ToolStripMenuItem("Small Corners", null, (sender, e) => ChangeCornerSize(10)); - mediumCornersItem = new ToolStripMenuItem("Medium Corners", null, (sender, e) => ChangeCornerSize(20)); - largeCornersItem = new ToolStripMenuItem("Large Corners", null, (sender, e) => ChangeCornerSize(30)); - - autoStartItem = new ToolStripMenuItem("Auto Start", null, ToggleAutoStart) - { - Checked = IsAutoStartEnabled() - }; - - contextMenu.Items.Add(smallCornersItem); - contextMenu.Items.Add(mediumCornersItem); - contextMenu.Items.Add(largeCornersItem); - contextMenu.Items.Add(autoStartItem); - contextMenu.Items.Add("Exit", null, OnExit); - - notifyIcon.ContextMenuStrip = contextMenu; - - UpdateCornerSizeCheck(mainWindow.GetCornerSize()); - } - - private void ChangeCornerSize(int size) - { - mainWindow.ChangeCornerSize(size); - UpdateCornerSizeCheck(size); - } - - private void UpdateCornerSizeCheck(int size) - { - smallCornersItem.Checked = (size == 10); - mediumCornersItem.Checked = (size == 20); - largeCornersItem.Checked = (size == 30); - } - - private void ToggleAutoStart(object sender, EventArgs e) - { - var menuItem = sender as ToolStripMenuItem; - if (menuItem != null) - { - if (menuItem.Checked) - { - DisableAutoStart(); - menuItem.Checked = false; - } - else - { - EnableAutoStart(); - menuItem.Checked = true; - } - } - } - - private bool IsAutoStartEnabled() - { - RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); - return rk.GetValue("RoundedWindowsEdges") != null; - } - - private void EnableAutoStart() - { - RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); - rk.SetValue("RoundedWindowsEdges", Process.GetCurrentProcess().MainModule.FileName); - } - - private void DisableAutoStart() - { - RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); - rk.DeleteValue("RoundedWindowsEdges", false); - } - - private void OnExit(object sender, EventArgs e) - { - System.Windows.Application.Current.Shutdown(); - } - - public void Dispose() - { - notifyIcon.Dispose(); - } - } -} +using System; +using System.Diagnostics; +using System.Drawing; +using System.Windows.Forms; +using Microsoft.Win32; + +namespace RoundedWindowsEdges +{ + public class TrayIcon : IDisposable + { + private NotifyIcon notifyIcon; + private MainWindow mainWindow; + private ToolStripMenuItem smallCornersItem; + private ToolStripMenuItem mediumCornersItem; + private ToolStripMenuItem largeCornersItem; + private ToolStripMenuItem autoStartItem; + public TrayIcon(MainWindow mainWindow) + { + this.mainWindow = mainWindow; + notifyIcon = new NotifyIcon + { + Icon = Properties.Resources.AppIcon, + Visible = true, + Text = "Rounded Screen" + }; + var contextMenu = new ContextMenuStrip(); + smallCornersItem = new ToolStripMenuItem("Small Corners", null, (sender, e) => ChangeCornerSize(10)); + mediumCornersItem = new ToolStripMenuItem("Medium Corners", null, (sender, e) => ChangeCornerSize(20)); + largeCornersItem = new ToolStripMenuItem("Large Corners", null, (sender, e) => ChangeCornerSize(30)); + autoStartItem = new ToolStripMenuItem("Auto Start", null, ToggleAutoStart) + { + Checked = IsAutoStartEnabled() + }; + contextMenu.Items.Add(smallCornersItem); + contextMenu.Items.Add(mediumCornersItem); + contextMenu.Items.Add(largeCornersItem); + contextMenu.Items.Add(autoStartItem); + contextMenu.Items.Add("Exit", null, OnExit); + notifyIcon.ContextMenuStrip = contextMenu; + UpdateCornerSizeCheck(mainWindow.GetCornerSize()); + } + private void ChangeCornerSize(int size) + { + mainWindow.ChangeCornerSize(size); + UpdateCornerSizeCheck(size); + } + private void UpdateCornerSizeCheck(int size) + { + smallCornersItem.Checked = (size == 10); + mediumCornersItem.Checked = (size == 20); + largeCornersItem.Checked = (size == 30); + } + private void ToggleAutoStart(object sender, EventArgs e) + { + var menuItem = sender as ToolStripMenuItem; + if (menuItem != null) + { + if (menuItem.Checked) + { + DisableAutoStart(); + menuItem.Checked = false; + } + else + { + EnableAutoStart(); + menuItem.Checked = true; + } + } + } + private bool IsAutoStartEnabled() + { + RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); + return rk.GetValue("RoundedWindowsEdges") != null; + } + private void EnableAutoStart() + { + RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); + rk.SetValue("RoundedWindowsEdges", Process.GetCurrentProcess().MainModule.FileName); + } + private void DisableAutoStart() + { + RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); + rk.DeleteValue("RoundedWindowsEdges", false); + } + private void OnExit(object sender, EventArgs e) + { + System.Windows.Application.Current.Shutdown(); + } + public void Dispose() + { + notifyIcon.Dispose(); + } + } +}