Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtual desktop Tasksbar icons #56

Open
anxxx opened this issue Sep 18, 2023 · 4 comments
Open

Virtual desktop Tasksbar icons #56

anxxx opened this issue Sep 18, 2023 · 4 comments

Comments

@anxxx
Copy link

anxxx commented Sep 18, 2023

I'm not sure if this is the right place or if anyone is interested but but I've made a small addition to FuPeiJiang's excellent code to switch the AutoHotkey icon to show the number of the virtual desktop on the taskbar.

Prerequisite is to show the AutoHotkey icon on the taskbar - this can be done in Settings > Personalisation > Taskbar.

You then need an icon that shows the number of each virtual desktop. I use six virtual desktops and have six icons stored in a folder referenced by the code). The icons are named 1.ico, 2.ico etc. Copies are attached
icons.zip.

I am sure there must be an easier way of running the code so would welcome any suggestions but I have added a function to obtain the desktop number:

+++++++++++++++++++
ChangeIcon() ;define function
{
Desktop := VD.getCurrentDesktopNum()
TraySetIcon("D:\Data\AutoHotkey2\icons" Desktop ".ico")
}
ChangeIcon ; call function
+++++++++++++++++++

And have then added the ChangeIcon function to each of the keyboard shortcuts. For example the Ctrl + Win +Numpad shortcut

++++++++++++++++++++
;#useful stuff

^#numpad1::
{
VD.goToDesktopNum(1)
ChangeIcon ; function added
}
^#numpad2::
{
VD.goToDesktopNum(2)
ChangeIcon ; function added
}

++++++++++++++++++
etc. etc.

I'm sure it must be possible to trigger the ChangeIcon function with every desktop change without the necessity for adding the code to each of the keyboard shortcuts but my AutoHotkey skills are rather limited.

@vlachig
Copy link

vlachig commented Sep 21, 2023

it must be possible to trigger the ChangeIcon function with every desktop change without the necessity for adding the code to each of the keyboard shortcut.

You don't need the ChangeIcon function, if you add
++++++++++++++++++++
Menu,TRAY, Icon, Path of the IconFile%desktopNum%.ico
++++++++++++++++++++
at the end of the function goToDesktopNum(desktopNum)
and your icon files are numbered.

@anxxx
Copy link
Author

anxxx commented Sep 26, 2023

You don't need the ChangeIcon function, if you add ++++++++++++++++++++ Menu,TRAY, Icon, Path of the IconFile%desktopNum%.ico ++++++++++++++++++++ at the end of the function goToDesktopNum(desktopNum) and your icon files are numbered.

Thanks vlachig

That sounds good but I can't get it to work. Could you possibly give me the exact line of code?

I had already tried
++++++++++++++++++++++
^#numpad1::VD.goToDesktopNum(1), TraySetIcon("D:\Data\AutoHotkey2\icons\1.ico")
++++++++++++++++++++++
which worked fine for VD.goToDesktopNum(1) etc.

but didn't work for moving to a relative desktop with the right and left arrow keys e.g.

#!left::VD.goToDesktopNum(VD.MoveWindowToRelativeDesktopNum("A", -1))

I am also not not sure that your suggestion would work for that either as as the desktop number is not specifically specified .

Thanks again

@vlachig
Copy link

vlachig commented Sep 26, 2023

In the file _VD.ahk search for the function goToDesktopNum(desktopNum) and replace it by this one:

    goToDesktopNum(desktopNum) { ; Lej77 https://github.com/Grabacr07/VirtualDesktop/pull/23#issuecomment-334918711
        firstWindowId:=this._getFirstWindowInVD(desktopNum)
        Gui VD_animation_gui:New, % "-Border -SysMenu +Owner -Caption +HwndVD_animation_gui_hwnd_tmp"
        VD_animation_gui_hwnd:=VD_animation_gui_hwnd_tmp+0
        IVirtualDesktop := this._GetDesktops_Obj().GetAt(desktopNum)
        GetId:=this._vtable(IVirtualDesktop, 4)
        VarSetCapacity(GUID_Desktop, 16)
        DllCall(GetId, "Ptr", IVirtualDesktop, "Ptr", &GUID_Desktop)
        DllCall(this.MoveWindowToDesktop, "Ptr", this.IVirtualDesktopManager, "Ptr", VD_animation_gui_hwnd, "Ptr", &GUID_Desktop)
        DllCall("ShowWindow","Ptr",VD_animation_gui_hwnd,"Int",4) ;after gui on current desktop owned by current process became active window, Show gui on different desktop owned by current process
        this._WinActivate_NewProcess(VD_animation_gui_hwnd)
        loop 20 {
            if (this.getCurrentDesktopNum()==desktopNum) { ; wildest hack ever..
                if (firstWindowId) {
                    DllCall("SetForegroundWindow","Ptr",firstWindowId)
                } else {
                    this._activateDesktopBackground()
                }
                break
            }
            Sleep 25
        }
        Gui VD_animation_gui:Destroy
	Menu,TRAY, Icon, D:\Data\AutoHotkey2\icons\%desktopNum%.ico
    }

@vlachig
Copy link

vlachig commented Sep 26, 2023

Another solution:

 ; === auto-execute section ===  (top of the script)

; ...
SetTimer Change_TRAY_Icon, 500
; ...

       RETURN   ; === end of auto-execute section ===

; ...

	Change_TRAY_Icon:
Nr := VD.getCurrentDesktopNum()
If (CurrentDesktopNr != Nr)
{	
	Menu,TRAY, Icon, D:\Data\AutoHotkey2\icons\%Nr%.ico
	CurrentDesktopNr := Nr
}
return

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants