Skip to content
This repository has been archived by the owner on Dec 23, 2018. It is now read-only.

Commit

Permalink
Merge pull request #66 from sdias/change-desktop-names
Browse files Browse the repository at this point in the history
Added a function to change desktop names at runtime as proposed by @achim-t in #60.

The names are reset to the default values contained in `settings.ini` when the program is restarted.

Default hotkey for this feature is `Win + F2`.

This closes #60.
  • Loading branch information
GioBonvi authored Jul 1, 2017
2 parents efd9942 + 883bfb3 commit 8b7ed82
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ The following actions are not executed in the context of a virtual desktop and t
- Unpin the currently visible app
- Toggle pin on the currently visible window
- Toggle pin on the currently visible app
- Change the current desktop name

For each of these actions, you can set a combination of zero or more modifiers (as before), as well as a regular key.
For example: if you want to set up a keyboard shortcut to be able to pin the current window, you just need to set up that combination (for example, `Win, Ctrl, Q`).
Expand Down Expand Up @@ -228,6 +229,7 @@ _Combination_ keys' settings follow the same rules as [modifier keys' settings](
| PinApp | Pin all of the windows of the currently opened app. |
| UnpinWindow | Unpin the current window. |
| UnpinApp | Unpin all of the windows of the currently opened app. |
| ChangeDesktopName | Change the name of the current desktop with a popup prompt. |

### Example configurations

Expand Down Expand Up @@ -257,6 +259,7 @@ UnpinWindow=
UnpinApp=
; "SC029" is the key below your "Esc" key
OpenDesktopManager=LAlt, SC029
ChangeDesktopName=Win, F2
```

The following shortcuts are available:
Expand Down
1 change: 1 addition & 0 deletions settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ UnpinWindow=
UnpinApp=
; "SC029" is the key below your "Esc" key
OpenDesktopManager=LAlt, SC029
ChangeDesktopName=Win, F2

[KeyboardShortcutsModifiers]
SwitchDesktop=Win, Ctrl
Expand Down
33 changes: 33 additions & 0 deletions virtual-desktop-enhancer.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ global previousDesktopNo=0
global doFocusAfterNextSwitch=0
global hasSwitchedDesktopsBefore=1

global changeDesktopNamesPopupTitle := "Windows 10 Virtual Desktop Enhancer"
global changeDesktopNamesPopupText := "Change the desktop name of desktop #{:d}"

initialDesktopNo := _GetCurrentDesktopNumber()

SwitchToDesktop(GeneralDefaultDesktop)
Expand Down Expand Up @@ -104,6 +107,7 @@ hkComboPinApp := KeyboardShortcutsCombinationsPinApp
hkComboUnpinApp := KeyboardShortcutsCombinationsUnpinApp
hkComboTogglePinApp := KeyboardShortcutsCombinationsTogglePinApp
hkComboOpenDesktopManager := KeyboardShortcutsCombinationsOpenDesktopManager
hkComboChangeDesktopName := KeyboardShortcutsCombinationsChangeDesktopName

arrayS := Object(), arrayR := Object()
arrayS.Insert("\s*|,"), arrayR.Insert("")
Expand All @@ -126,6 +130,7 @@ for index in arrayS {
hkComboUnpinApp := RegExReplace(hkComboUnpinApp, arrayS[index], arrayR[index])
hkComboTogglePinApp := RegExReplace(hkComboTogglePinApp, arrayS[index], arrayR[index])
hkComboOpenDesktopManager := RegExReplace(hkComboOpenDesktopManager, arrayS[index], arrayR[index])
hkComboChangeDesktopName := RegExReplace(hkComboChangeDesktopName, arrayS[index], arrayR[index])
}

; Setup key bindings dynamically
Expand Down Expand Up @@ -192,6 +197,8 @@ setUpHotkeyWithCombo(hkComboTogglePinApp, "OnTogglePinAppPress", "[KeyboardShort

setUpHotkeyWithCombo(hkComboOpenDesktopManager, "OpenDesktopManager", "[KeyboardShortcutsCombinations] OpenDesktopManager")

setUpHotkeyWithCombo(hkComboChangeDesktopName, "ChangeDesktopName", "[KeyboardShortcutsCombinations] ChangeDesktopName")

if (GeneralTaskbarScrollSwitching) {
Hotkey, ~WheelUp, OnTaskbarScrollUp
Hotkey, ~WheelDown, OnTaskbarScrollDown
Expand Down Expand Up @@ -354,6 +361,20 @@ OpenDesktopManager() {
Send #{Tab}
}

; Let the user change desktop names with a prompt, without having to edit the 'settings.ini'
; file and reload the program.
; The changes are temprorary (names will be overwritten by the default values of
; 'settings.ini' when the program will be restarted.
ChangeDesktopName() {
currentDesktopNumber := _GetCurrentDesktopNumber()
currentDesktopName := _GetDesktopName(currentDesktopNumber)
InputBox, newDesktopName, % changeDesktopNamesPopupTitle, % Format(changeDesktopNamesPopupText, _GetCurrentDesktopNumber()), , , , , , , , %currentDesktopName%
; If the user choose "Cancel" ErrorLevel is set to 1.
if (ErrorLevel == 0) {
_SetDesktopName(currentDesktopNumber, newDesktopName)
}
}

Reload() {
Reload
}
Expand Down Expand Up @@ -402,6 +423,18 @@ _GetDesktopName(n:=1) {
return name
}

; Set the name of the nth desktop to the value of a given string.
_SetDesktopName(n:=1, name:=0) {
if (n == 0) {
n := 10
}
if (!name) {
; Default value: "Desktop N".
name := "Desktop " %n%
}
DesktopNames%n% := name
}

_GetNextDesktopNumber() {
i := _GetCurrentDesktopNumber()
if (GeneralDesktopWrapping == 1) {
Expand Down

0 comments on commit 8b7ed82

Please sign in to comment.