Skip to content
Open
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
33 changes: 19 additions & 14 deletions WinJump/Core/WinJumpManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down