From 4adbf9e89801ae230aab2599d66a9059ead9c680 Mon Sep 17 00:00:00 2001 From: Will Davies Date: Thu, 15 Dec 2022 09:39:22 -0600 Subject: [PATCH] Figured out a better way to reset active Window --- WinJump/Program.cs | 9 +- WinJump/WinJump.csproj | 197 +++++++++++++++++++++++++---------------- 2 files changed, 123 insertions(+), 83 deletions(-) diff --git a/WinJump/Program.cs b/WinJump/Program.cs index e7f07c5..0f87827 100644 --- a/WinJump/Program.cs +++ b/WinJump/Program.cs @@ -11,7 +11,7 @@ internal static class Program { private static extern bool SetForegroundWindow(IntPtr hWnd); [DllImport("user32.dll")] - private static extern IntPtr GetForegroundWindow(); + private static extern IntPtr GetTopWindow(); [STAThread] public static void Main() { @@ -50,7 +50,6 @@ public static void Main() { // Credit https://stackoverflow.com/a/21684059/4779937 private sealed class STAThread : IDisposable { - private readonly IntPtr[] LastActiveWindows = new IntPtr[10]; private readonly VirtualDesktopWrapper vdw = VirtualDesktopManager.Create(); public STAThread() { @@ -74,12 +73,12 @@ public void JumpTo(int index) { if (ctx == null) throw new ObjectDisposedException("STAThread"); ctx.Send((_) => { - LastActiveWindows[vdw.GetDesktop()] = GetForegroundWindow(); vdw.JumpTo(index); // Give it just a little time to let the desktop settle Thread.Sleep(10); - if (LastActiveWindows[index] != IntPtr.Zero) { - SetForegroundWindow(LastActiveWindows[index]); + IntPtr ptr = GetTopWindow(); + if (ptr != IntPtr.Zero) { + SetForegroundWindow(ptr); } }, null); } diff --git a/WinJump/WinJump.csproj b/WinJump/WinJump.csproj index a4fb242..02196ca 100644 --- a/WinJump/WinJump.csproj +++ b/WinJump/WinJump.csproj @@ -1,81 +1,122 @@  - - - Debug - AnyCPU - {22774C1D-A813-493F-AB33-AE3A4049FADC} - WinExe - WinJump - WinJump - v4.8.1 - 512 - true - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - ResXFileCodeGenerator - Resources.Designer.cs - Designer - - - True - Resources.resx - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - True - Settings.settings - True - - - - - - - - {153091d1-8af0-4609-aa38-db01f11d0c4a} - VirtualDesktop - - - + + + Debug + AnyCPU + {22774C1D-A813-493F-AB33-AE3A4049FADC} + WinExe + WinJump + WinJump + v4.8.1 + 512 + true + true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + 6E443FEB1DE02B78AE4ABD396B5C71FCE97FA254 + + + WinJump_TemporaryKey.pfx + + + true + + + true + + + + + + + + + + + + + + + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + + {153091d1-8af0-4609-aa38-db01f11d0c4a} + VirtualDesktop + + + + + False + Microsoft .NET Framework 4.8.1 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + \ No newline at end of file