GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: change output type to `WinExe`; attach console to parent process
Lars Bergerbb82d11dbd56
diff --git a/GlazeWM.App/GlazeWM.App.csproj b/GlazeWM.App/GlazeWM.App.csprojindex 9f11a87b..350e0f3c 100644--- a/GlazeWM.App/GlazeWM.App.csproj+++ b/GlazeWM.App/GlazeWM.App.csproj@@ -1,7 +1,7 @@<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup>- <OutputType>Exe</OutputType>+ <OutputType>WinExe</OutputType><TargetFramework>net7-windows10.0.17763.0</TargetFramework><DebugType>embedded</DebugType><ApplicationIcon>Resources\icon.ico</ApplicationIcon>diff --git a/GlazeWM.App/Program.cs b/GlazeWM.App/Program.csindex 5d6b3606..492a1f41 100644--- a/GlazeWM.App/Program.cs+++ b/GlazeWM.App/Program.cs@@ -22,6 +22,7 @@ using GlazeWM.Infrastructure.Utils;using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Logging;using Microsoft.Extensions.Logging.Console;+using static GlazeWM.Infrastructure.WindowsApi.WindowsApiService;//// TODO: Handle circular reference for that one workspace event.@@ -39,6 +40,10 @@ namespace GlazeWM.App[STAThread]public static async Task<int> Main(string[] args){+ // Allows reading and writing to the console. This is needed since the `OutputType`+ // is `WinExe` and not a console application.+ AttachConsoleToParentProcess();+bool isSingleInstance;using var _ = new Mutex(false, "Global\\" + AppGuid, out isSingleInstance);diff --git a/GlazeWM.Infrastructure/WindowsApi/WindowsApiService.cs b/GlazeWM.Infrastructure/WindowsApi/WindowsApiService.csindex b5828716..5a073c7e 100644--- a/GlazeWM.Infrastructure/WindowsApi/WindowsApiService.cs+++ b/GlazeWM.Infrastructure/WindowsApi/WindowsApiService.cs@@ -461,5 +461,14 @@ namespace GlazeWM.Infrastructure.WindowsApi[DllImport("dwmapi.dll")]public static extern int DwmSetWindowAttribute(IntPtr handle, uint attribute, ref uint value, uint size);++ [DllImport("kernel32.dll")]+ internal static extern bool AttachConsole(uint dwProcessId);++ public static bool AttachConsoleToParentProcess()+ {+ const uint AttachParentProcess = 0x0ffffffff;+ return AttachConsole(AttachParentProcess);+ }}}