diff --git a/WinJump/Core/WinJumpManager.cs b/WinJump/Core/WinJumpManager.cs index f4d37b1..86f5d97 100644 --- a/WinJump/Core/WinJumpManager.cs +++ b/WinJump/Core/WinJumpManager.cs @@ -263,24 +263,26 @@ public void JumpTo(uint index, uint fallback) { } public void JumpTo(uint index) { - - var allowJump = true; + // If the desktop is the same as the current one, ignore + if (index == api.GetCurrentDesktop()) + { + return; + } + WrapCall(() => { - // If the desktop is the same as the current one or doesn't exist, don't allow the jump - if(api.GetCurrentDesktop() == index) { - allowJump = false; - } - else if(index >= api.GetDesktopCount()) + // If the desktop doesn't exist, + // CHANGED -> don't allow the jump + // NOW -> navigate to the last available desktop + int desktopCount = api.GetDesktopCount(); + if (index >= desktopCount) { - allowJump = false; + index = (uint)desktopCount - 1; } }); - if(allowJump) { - WrapCall(() => { - api.JumpToDesktop((int) index); - }, true); - } + WrapCall(() => { + api.JumpToDesktop((int)index); + }, true); } public void JumpToNoHack(uint index) { @@ -332,10 +334,13 @@ private bool WrapCall(Action action, bool performWindowFocusHack = false) { GetWindowThreadProcessId(GetForegroundWindow(), out uint foregroundThreadID); uint currentThreadID = GetCurrentThreadId(); - if(desktopThreadId != 0 && foregroundThreadID != 0 && foregroundThreadID != currentThreadID) { + // && foregroundThreadID != currentThreadID + if (desktopThreadId != 0 && foregroundThreadID != 0) { AttachThreadInput(desktopThreadId, currentThreadID, true); AttachThreadInput(foregroundThreadID, currentThreadID, true); + SetForegroundWindow(hwnd); + AttachThreadInput(foregroundThreadID, currentThreadID, false); AttachThreadInput(desktopThreadId, currentThreadID, false); }