From 39cbb155f72e385d557511001b8579d237ff02e0 Mon Sep 17 00:00:00 2001 From: Giorgio Bonvicini Date: Wed, 17 May 2017 00:16:23 +0200 Subject: [PATCH] First ideas about toggling between last desktops. This is a rapid jot down of the first ideas about enabling a hotkey to toggle between the current desktop and the last one. I am not really shure this is the most elegant way to do this, still, it seems to work ;) --- settings.ini | 1 + virtual-desktop-enhancer.ahk | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/settings.ini b/settings.ini index a0c99d5..60d0c82 100644 --- a/settings.ini +++ b/settings.ini @@ -38,6 +38,7 @@ NextTenDesktops= [KeyboardShortcutsIdentifiers] PreviousDesktop=Left NextDesktop=Right +LastDesktop=C Desktop1=1 Desktop2=2 Desktop3=3 diff --git a/virtual-desktop-enhancer.ahk b/virtual-desktop-enhancer.ahk index 077c8e1..eb40c08 100644 --- a/virtual-desktop-enhancer.ahk +++ b/virtual-desktop-enhancer.ahk @@ -75,6 +75,9 @@ global taskbarID=0 global previousDesktopNo=0 global doFocusAfterNextSwitch=0 global hasSwitchedDesktopsBefore=1 +global lastDesktopNumber := _GetCurrentDesktopNumber() +global lastDesktopChangeTime := A_TickCount +global timeForDesktopToBeActive := 1000 initialDesktopNo := _GetCurrentDesktopNumber() @@ -96,6 +99,7 @@ hkModifiersMoveAndSwitch := KeyboardShortcutsModifiersMoveWindowAndSwitchToDes hkModifiersPlusTen := KeyboardShortcutsModifiersNextTenDesktops hkIdentifierPrevious := KeyboardShortcutsIdentifiersPreviousDesktop hkIdentifierNext := KeyboardShortcutsIdentifiersNextDesktop +hkIdentifierLast := KeyboardShortcutsIdentifiersLastDesktop hkComboPinWin := KeyboardShortcutsCombinationsPinWindow hkComboUnpinWin := KeyboardShortcutsCombinationsUnpinWindow hkComboTogglePinWin := KeyboardShortcutsCombinationsTogglePinWindow @@ -174,12 +178,17 @@ if (!(GeneralUseNativePrevNextDesktopSwitchingIfConflicting && _IsPrevNextDeskto if (!(GeneralUseNativePrevNextDesktopSwitchingIfConflicting && _IsPrevNextDesktopSwitchingKeyboardShortcutConflicting(hkModifiersSwitch, hkIdentifierNext))) { setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersSwitch, hkIdentifierNext, "OnShiftRightPress", "[KeyboardShortcutsModifiers] SwitchDesktop, [KeyboardShortcutsIdentifiers] NextDesktop") } +if (!(GeneralUseNativePrevNextDesktopSwitchingIfConflicting && _IsPrevNextDesktopSwitchingKeyboardShortcutConflicting(hkModifiersSwitch, hkIdentifierLast))) { + setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersSwitch, hkIdentifierLast, "OnShiftLastPress", "[KeyboardShortcutsModifiers] SwitchDesktop, [KeyboardShortcutsIdentifiers] NextDesktop") +} setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersMove, hkIdentifierPrevious, "OnMoveLeftPress", "[KeyboardShortcutsModifiers] MoveWindowToDesktop, [KeyboardShortcutsIdentifiers] PreviousDesktop") setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersMove, hkIdentifierNext, "OnMoveRightPress", "[KeyboardShortcutsModifiers] MoveWindowToDesktop, [KeyboardShortcutsIdentifiers] NextDesktop") +setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersMove, hkIdentifierLast, "OnMoveLastPress", "[KeyboardShortcutsModifiers] MoveWindowToDesktop, [KeyboardShortcutsIdentifiers] LastDesktop") setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersMoveAndSwitch, hkIdentifierPrevious, "OnMoveAndShiftLeftPress", "[KeyboardShortcutsModifiers] MoveWindowAndSwitchToDesktop, [KeyboardShortcutsIdentifiers] PreviousDesktop") setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersMoveAndSwitch, hkIdentifierNext, "OnMoveAndShiftRightPress", "[KeyboardShortcutsModifiers] MoveWindowAndSwitchToDesktop, [KeyboardShortcutsIdentifiers] NextDesktop") +setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersMoveAndSwitch, hkIdentifierLast, "OnMoveAndShiftLastPress", "[KeyboardShortcutsModifiers] MoveWindowAndSwitchToDesktop, [KeyboardShortcutsIdentifiers] NextDesktop") setUpHotkeyWithCombo(hkComboPinWin, "OnPinWindowPress", "[KeyboardShortcutsCombinations] PinWindow") setUpHotkeyWithCombo(hkComboUnpinWin, "OnUnpinWindowPress", "[KeyboardShortcutsCombinations] UnpinWindow") @@ -232,6 +241,13 @@ OnShiftRightPress() { SwitchToDesktop(_GetNextDesktopNumber()) } +OnShiftLastPress() { + global lastDesktopNumber, lastDesktopChangeTime + tempDesktopNumber := _getCurrentDesktopNumber() + SwitchToDesktop(lastDesktopNumber) + lastDesktopNumber := tempDesktopNumber +} + OnMoveLeftPress() { MoveToDesktop(_GetPreviousDesktopNumber()) } @@ -240,6 +256,13 @@ OnMoveRightPress() { MoveToDesktop(_GetNextDesktopNumber()) } +OnMoveLastPress() { + global lastDesktopNumber, lastDesktopChangeTime + tempDesktopNumber := _getCurrentDesktopNumber() + MoveToDesktop(lastDesktopNumber) + lastDesktopNumber := tempDesktopNumber +} + OnMoveAndShiftLeftPress() { MoveAndSwitchToDesktop(_GetPreviousDesktopNumber()) } @@ -248,6 +271,13 @@ OnMoveAndShiftRightPress() { MoveAndSwitchToDesktop(_GetNextDesktopNumber()) } +OnMoveAndShiftLastPress() { + global lastDesktopNumber, lastDesktopChangeTime + tempDesktopNumber := _getCurrentDesktopNumber() + MoveAndSwitchToDesktop(lastDesktopNumber) + lastDesktopNumber := tempDesktopNumber +} + OnTaskbarScrollUp() { if (_IsCursorHoveringTaskbar()) { OnShiftLeftPress() @@ -434,6 +464,16 @@ _MoveCurrentWindowToDesktop(n:=1) { } _ChangeDesktop(n:=1) { + + ; If this desktop was active for more than 1000ms mark it as the last used desktop. + global lastDesktopChangeTime, lastDesktopNumber, timeForDesktopToBeActive + timeSinceLastDesktopChange := A_TickCount - lastDesktopChangeTime + lastDesktopChangeTime := A_TickCount + if (timeSinceLastDesktopChange > timeForDesktopToBeActive && n != lastDesktopNumber) { + lastDesktopNumber := _getCurrentDesktopNumber() + } + + ; Change desktop. if (n == 0) { n := 10 }