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

Commit

Permalink
Added custom desktop names. Added tooltips. Added switching desktops …
Browse files Browse the repository at this point in the history
…by scrolling over the taskbar.
  • Loading branch information
sdias committed Sep 5, 2016
1 parent 2c9ee80 commit 43ab8ab
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 13 deletions.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,60 @@ Also note that any number of desktops are supported, just add a line for each ne
999=C:\Wallpapers\End of the world.jpg
</pre>

### Desktop Names

In a similar manner to wallpapers, you can also set a custom name for each desktop.

<pre>
[DesktopNames]
1=Work
2=Games
3=Movies
4=Presentations
5=
6=
7=
8=
9=
10=
15=No idea
</pre>

Note that the desktop's name will be visible in the tooltip of the tray icon and also in the larger tooltip that appears momentarily when you switch desktops.
If a desktop's name is not set, "Desktop <number>" will be displayed.
Again, like wallpapers, any number of desktops are supported by this feature.

### Tooltips

If you enable tooltips, every time you switch desktops a tooltip will appear letting you know the name of the desktop you switched to.

You can customize the appearance of this tooltip:

| Setting | Description | Valid Values |
| --------------- | ----------------------------------------------------------------------------------------- | ---------------------------------------------- |
| Enabled | If tooltips should be shown. | 1 (Yes), 0 (No). |
| Centered | If the tooltips should appear at the center of the screen, or in the bottom right corner. | 1 (center), 0 (corner). |
| FontSize | The size of the font. | Any reasonable number. |
| FontColor | The color of the font. | Any hexadecimal number (from 0x0 to 0xFFFFFF). |
| FontInBold | If the font should be in bold. | 1 (Yes), 0 (No). |
| BackgroundColor | The color of the background. | Any hexadecimal number (from 0x0 to 0xFFFFFF). |
| Lifespan | The time in milliseconds for which each tooltip will be displayed. | Any reasonable number. |

As an example, you have the default configuration:

<pre>
[Tooltips]
Enabled=1
Centered=1
FontSize=11
FontColor=0xFFFFFF
FontInBold=1
BackgroundColor=0x1F1F1F
Lifespan=750
</pre>

It draws tooltips at the center of the screen, in a white, bold and small font, with a dark background, and they are displayed for 750 milliseconds.

### Keyboard Shortcuts

There are three functions: switching to another desktop, moving the current window to another desktop, and moving the current window to another desktop and then switch to that desktop.
Expand Down Expand Up @@ -142,6 +196,8 @@ You can also set what is the default desktop using the "[General] DefaultDesktop

Thanks to Ciantic (Jari Pennanen) for his library and sample AHK script, which can be found [here](https://github.com/Ciantic/VirtualDesktopAccessor).

Thanks to engunneer for his AHK library, which can be found [here](http://www.autohotkey.com/board/topic/21510-toaster-popups/#entry140824).

Thanks to the creator of the ReadINI AHK library, found [here](https://autohotkey.com/board/topic/33506-read-ini-file-in-one-go/).

Thanks to the artists that created the packed wallpapers, whom I lost track of. Sorry.
Expand Down
21 changes: 21 additions & 0 deletions settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ MoveAndSwitch=LAlt, Shift
Previous=Left
Next=Right

[Tooltips]
Enabled=1
Centered=1
FontSize=11
FontColor=0xFFFFFF
FontInBold=1
BackgroundColor=0x1F1F1F
Lifespan=750

[Wallpapers]
1=
2=
Expand All @@ -18,4 +27,16 @@ Next=Right
7=
8=
9=
10=

[DesktopNames]
1=
2=
3=
4=
5=
6=
7=
8=
9=
10=
59 changes: 59 additions & 0 deletions tooltip.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
; Credits to engunneer (http://www.autohotkey.com/board/topic/21510-toaster-popups/#entry140824)

Toast(params:=0) {

message := params.message ? params.message : ""
lifespan := params.lifespan ? params.lifespan : 1500
position := params.position ? params.position : 0
doWait := params.doWait ? params.doWait : 0
fontSize := params.fontSize ? params.fontSize : 11
fontWeight := params.fontWeight ? params.fontWeight : 700
fontColor := params.fontColor ? params.fontColor : "0xFFFFFF"
backgroundColor := params.backgroundColor ? params.backgroundColor : "0x1F1F1F"

Global TP_GUI_ID
DetectHiddenWindows, On
SysGet, Workspace, MonitorWorkArea
Gui, 89:Destroy
Gui, 89:-Caption +ToolWindow +LastFound +AlwaysOnTop
Gui, 89:Color, %backgroundColor%
Gui, 89:Font, s%fontSize% c%fontColor% w%fontWeight%, Segoe UI
Gui, 89:Add, Text, xp+25 yp+20 gTP_Fade, %message%
Gui, 89:Show, Hide
TP_GUI_ID := WinExist()
WinGetPos, GUIX, GUIY, GUIWidth, GUIHeight, ahk_id %TP_GUI_ID%

GUIWidth += 20
GUIHeight += 15

if (position==0) {
NewX := WorkSpaceRight-GUIWidth
NewY := WorkspaceBottom-GUIHeight-12
}
else {
NewX := (WorkSpaceRight-GUIWidth)/2
NewY := (WorkspaceBottom-GUIHeight)/2
}

Gui, 89:Show, Hide x%NewX% y%NewY% w%GUIWidth% h%GUIHeight%

DllCall("AnimateWindow","UInt",TP_GUI_ID,"Int",1,"UInt","0x00080000") ; TOAST!
if (lifespan) {
SetTimer, TP_Fade, % lifespan
if(doWait == 1) {
Sleep % lifespan
}
}
Return
}

TP_Wait() {
Global TP_GUI_ID
WinWaitClose, ahk_id %TP_GUI_ID%
}

TP_Fade() {
DllCall("AnimateWindow","UInt",TP_GUI_ID,"Int",100,"UInt","0x00090000") ; Fade out when clicked
Gui, 89:Destroy
Return
}
101 changes: 88 additions & 13 deletions virtual-desktop-enhancer.ahk
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#SingleInstance, force
#WinActivateForce
; Credits to: https://github.com/Ciantic/VirtualDesktopAccessor
; Credits to Ciantic: https://github.com/Ciantic/VirtualDesktopAccessor

#Include, read-ini.ahk
#Include, tooltip.ahk

; ======================================================================
; Setup
Expand All @@ -24,7 +25,7 @@ global MoveWindowToDesktopNumberProc := DllCall("GetProcAddress", Ptr, hVirtualD

DllCall(RegisterPostMessageHookProc, Int, hwnd, Int, 0x1400 + 30)
OnMessage(0x1400 + 30, "VWMess")
VWMess(wParam, lParam, msg, hwnd) {
VWMess(wParam, lParam, msg, hwnd) {
OnDesktopSwitch(lParam + 1)
}

Expand All @@ -41,6 +42,14 @@ Menu, Tray, Click, 1

ReadIni("settings.ini")

TooltipsEnabled := (TooltipsEnabled != "" and TooltipsEnabled ~= "^[01]$") ? TooltipsEnabled : 1
TooltipsLifespan := (TooltipsLifespan != "" and TooltipsLifespan ~= "^\d+$") ? TooltipsLifespan : 750
TooltipsCentered := (TooltipsCentered != "" and TooltipsCentered ~= "^[01]$") ? TooltipsCentered : 1
TooltipsFontSize := (TooltipsFontSize != "" and TooltipsFontSize ~= "^\d+$") ? TooltipsFontSize : 11
TooltipsFontInBold := (TooltipsFontInBold != "" and TooltipsFontInBold ~= "^[01]$") ? (TooltipsFontInBold ? 700 : 400) : 700
TooltipsFontColor := (TooltipsFontColor != "" and TooltipsFontColor ~= "^0x[0-9A-Fa-f]{1,6}$") ? TooltipsFontColor : "0xFFFFFF"
TooltipsBackgroundColor := (TooltipsBackgroundColor != "" and TooltipsBackgroundColor ~= "^0x[0-9A-Fa-f]{1,6}$") ? TooltipsBackgroundColor : "0x1F1F1F"

SwitchToDesktop(GeneralDefaultDesktop)
; Update everything again, if the default desktop matches the current one
OnDesktopSwitch(GeneralDefaultDesktop)
Expand Down Expand Up @@ -133,6 +142,25 @@ if (!areSwitchModsValid || !areMoveModsValid || !areMoveAndSwitchModsValid || !a
Exit
}

Hotkey, % "~WheelUp", OnTaskbarScrollUp
Hotkey, % "~WheelDown", OnTaskbarScrollDown

; ======================================================================
; Event Handlers
; ======================================================================

OnTaskbarScrollUp() {
if (IsCursorHoveringTaskbar()) {
OnShiftLeftPress()
}
}

OnTaskbarScrollDown() {
if (IsCursorHoveringTaskbar()) {
OnShiftRightPress()
}
}

OnShiftNumberedPress() {
SwitchToDesktop(substr(A_ThisHotkey, 0, 1))
}
Expand Down Expand Up @@ -169,10 +197,30 @@ OnMoveAndShiftRightPress() {
MoveAndSwitchToDesktop(_GetNextDesktopNumber())
}

OnDesktopSwitch(n:=1) {
global TooltipsEnabled
if (TooltipsEnabled) {
_ShowTooltip(n)
}
_ChangeAppearance(n)
_ChangeBackground(n)
_Focus()
}

; ======================================================================
; Functions
; ======================================================================

global taskbarID=0

IsCursorHoveringTaskbar() {
MouseGetPos,,, mouseHoveringID
if (!taskbarID) {
WinGet, taskbarID, ID, ahk_class Shell_TrayWnd
}
return (mouseHoveringID == taskbarID)
}

SwitchToDesktop(n:=1) {
_ChangeDesktop(n)
}
Expand All @@ -191,12 +239,6 @@ OpenDesktopManager() {
Send #{Tab}
}

OnDesktopSwitch(n:=1) {
_ChangeAppearance(n)
_ChangeBackground(n)
_Focus()
}

Reload() {
Reload
}
Expand All @@ -205,24 +247,35 @@ Exit() {
ExitApp
}

_GetDesktopName(n:=1) {
if (n == 0) {
n := 10
}
name := DesktopNames%n%
if (!name) {
name := "Desktop " . n
}
return name
}

_GetNextDesktopNumber() {
i := _GetCurrentDesktopNumber()
i := (i = _GetNumberOfDesktops() ? 1 : i + 1)
Return i
return i
}

_GetPreviousDesktopNumber() {
i := _GetCurrentDesktopNumber()
i := (i = 1 ? _GetNumberOfDesktops() : i - 1)
Return i
return i
}

_GetCurrentDesktopNumber() {
Return DllCall(GetCurrentDesktopNumberProc) + 1
return DllCall(GetCurrentDesktopNumberProc) + 1
}

_GetNumberOfDesktops() {
Return DllCall(GetDesktopCountProc)
return DllCall(GetDesktopCountProc)
}

_MoveCurrentWindowToDesktop(n:=1) {
Expand Down Expand Up @@ -265,7 +318,7 @@ _ChangeBackground(n:=1) {
}

_ChangeAppearance(n:=1) {
Menu, Tray, Tip, Desktop %n%
Menu, Tray, Tip, % _GetDesktopName(n)
if (FileExist("./icons/" . n ".ico")) {
Menu, Tray, Icon, icons/%n%.ico
}
Expand All @@ -277,4 +330,26 @@ _ChangeAppearance(n:=1) {
_Focus() {
WinActivate, ahk_class Shell_TrayWnd
SendEvent !{Esc}
}

_ShowTooltip(n:=1) {
if (n == 0) {
n := 10
}
global TooltipsEnabled
global TooltipsLifespan
global TooltipsCentered
global TooltipsFontSize
global TooltipsFontInBold
global TooltipsFontColor
global TooltipsBackgroundColor
params := {}
params.message := _GetDesktopName(n)
params.lifespan := TooltipsLifespan
params.position := TooltipsCentered
params.fontSize := TooltipsFontSize
params.fontWeight := TooltipsFontInBold
params.fontColor := TooltipsFontColor
params.backgroundColor := TooltipsBackgroundColor
Toast(params)
}
Binary file modified virtual-desktop-enhancer.exe
Binary file not shown.

0 comments on commit 43ab8ab

Please sign in to comment.