Skip to content

Commit

Permalink
Fix issue when trying to jump to active window or non existent virtua…
Browse files Browse the repository at this point in the history
…l desktop
  • Loading branch information
Mr-Badger committed Aug 2, 2024
1 parent da392d5 commit 6ca1d3e
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 2 deletions.
6 changes: 6 additions & 0 deletions WinJump/Core/VirtualDesktopDefinitions/IVirtualDesktopAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public interface IVirtualDesktopAPI : IDisposable {
/// <returns>0-indexed, where '0' is the first desktop</returns>
int GetCurrentDesktop();

/// <summary>
/// Returns how many virtual desktops there are.
/// </summary>
/// <returns>Virtual desktop count</returns>
public int GetDesktopCount();

/// <summary>
/// Jumps to the virtual desktop.
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions WinJump/Core/VirtualDesktopDefinitions/Windows10_17763.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public int GetCurrentDesktop() {
return DesktopManager.GetCurrentDesktopNum();
}

public int GetDesktopCount() {
return DesktopManager.GetDesktopCount();
}

public void JumpToDesktop(int index) {
DesktopManager.SwitchDesktop(index);
}
Expand Down Expand Up @@ -110,6 +114,10 @@ internal static int GetCurrentDesktopNum() {
return GetIndex(vd);
}

internal static int GetDesktopCount() {
return VirtualDesktopManagerInternal.GetCount();
}

internal static void MoveCurrentlyFocusedToDesktop(int index) {
int processId;
IntPtr hWnd = GetForegroundWindow();
Expand Down
8 changes: 8 additions & 0 deletions WinJump/Core/VirtualDesktopDefinitions/Windows11_22000.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public int GetCurrentDesktop() {
return DesktopManager.GetCurrentDesktopNum();
}

public int GetDesktopCount() {
return DesktopManager.GetDesktopCount();
}

public void JumpToDesktop(int index) {
DesktopManager.SwitchDesktop(index);
}
Expand Down Expand Up @@ -110,6 +114,10 @@ internal static int GetCurrentDesktopNum() {
return GetIndex(vd);
}

internal static int GetDesktopCount() {
return VirtualDesktopManagerInternal.GetCount(IntPtr.Zero);
}

internal static void MoveCurrentlyFocusedToDesktop(int index) {
int processId;
IntPtr hWnd = GetForegroundWindow();
Expand Down
8 changes: 8 additions & 0 deletions WinJump/Core/VirtualDesktopDefinitions/Windows11_22621.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public int GetCurrentDesktop() {
return DesktopManager.GetCurrentDesktopNum();
}

public int GetDesktopCount() {
return DesktopManager.GetDesktopCount();
}

public void JumpToDesktop(int index) {
DesktopManager.SwitchDesktop(index);
}
Expand Down Expand Up @@ -107,6 +111,10 @@ internal static int GetCurrentDesktopNum() {

return GetIndex(vd);
}

internal static int GetDesktopCount() {
return VirtualDesktopManagerInternal.GetCount(IntPtr.Zero);
}

internal static void MoveCurrentlyFocusedToDesktop(int index) {
int processId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public int GetCurrentDesktop() {
return DesktopManager.GetCurrentDesktopNum();
}

public int GetDesktopCount() {
return DesktopManager.GetDesktopCount();
}

public void JumpToDesktop(int index) {
DesktopManager.SwitchDesktop(index);
}
Expand Down Expand Up @@ -110,6 +114,10 @@ internal static int GetCurrentDesktopNum() {
return GetIndex(vd);
}

internal static int GetDesktopCount() {
return VirtualDesktopManagerInternal.GetCount();
}

internal static void MoveCurrentlyFocusedToDesktop(int index) {
int processId;
IntPtr hWnd = GetForegroundWindow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public int GetCurrentDesktop() {
return DesktopManager.GetCurrentDesktopNum();
}

public int GetDesktopCount() {
return DesktopManager.GetDesktopCount();
}

public void JumpToDesktop(int index) {
DesktopManager.SwitchDesktop(index);
}
Expand Down Expand Up @@ -110,6 +114,10 @@ internal static int GetCurrentDesktopNum() {
return GetIndex(vd);
}

internal static int GetDesktopCount() {
return VirtualDesktopManagerInternal.GetCount();
}

internal static void MoveCurrentlyFocusedToDesktop(int index) {
int processId;
IntPtr hWnd = GetForegroundWindow();
Expand Down
19 changes: 17 additions & 2 deletions WinJump/Core/WinJumpManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,24 @@ public void JumpTo(uint index, uint fallback) {
}

public void JumpTo(uint index) {

var allowJump = true;
WrapCall(() => {
api.JumpToDesktop((int) index);
}, true);
// 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())
{
allowJump = false;
}
});

if(allowJump) {
WrapCall(() => {
api.JumpToDesktop((int) index);
}, true);
}
}

public void JumpToNoHack(uint index) {
Expand Down

0 comments on commit 6ca1d3e

Please sign in to comment.