pmb6tz/windows-desktop-switcher

switchDesktopToLastOpened() doesn't always work correctly

EdwinVanRooij opened this issue · 3 comments

I'm using the default key binding: CapsLock & tab::switchDesktopToLastOpened().

Steps to reproduce:

  • Start the script
  • Go to desktop 2 through CapsLock & 2::switchDesktopByNumber(2)
  • Go to desktop 1 through CapsLock & 1::switchDesktopByNumber(1)
  • <I receive a message from a colleague, clicking it automatically switches me to that desktop which is at desktop 2>
  • Execute switchDesktopToLastOpened()
  • Result: nothing happens.

Now it's not hard to see what's happening here, the variable LastOpenedDesktop is only set in _switchDesktopToTarget (LastOpenedDesktop := CurrentDesktop). Because of this, any other way of moving to another desktop will not register into the variable LastOpenedDesktop, thus leaving value 2 in LastOpenedDesktop, even though I'm currently at desktop 2 and 1 was my previous desktop.

tl;dr: this program assumes it is in complete control over switching desktops, leading to broken functionality

I've thought about this for a while, but I haven't been able to come up with a clean solution.

Update:
For anyone else experiencing this bug, I have found a way to "deal" with it.
It's not a solution, but rather something to deal with it in most cases.
I added a check to the script, it checks whether I'm currently on the LastOpenedDesktop. If I am, but I pressed the shortcut to switchDesktopToLastOpened(), it will always move me to desktop number 1 (hard coded).

99% of the times I'm experiencing this bug, I want to go from some desktop where I got through messaging (which is usually at desktop 2), back to my working desktop (which is desktop 1).

I am experiencing this bug, any solution ?

I think switching desktop by clicking the notify icon of status bar is not recorded by switchDesktopByNumber, so it can not restore to last opened desktop.