 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
ahklerner
Joined: 26 Jun 2006 Posts: 1249 Location: USA
|
Posted: Sun Feb 10, 2008 10:34 pm Post subject: Virtual Desktop Manager - Proof of concept |
|
|
Another Proof of concept script. I posted this on the forum before, but inside another post. I have some optimizations to do sometime in future.
Have Fun.
NEW VERSION: 9 desktops
added support for running a label on desktop change as well as initial show of desktop.
use #and 1-9 to switch
| Code: | ;==============================================================================================
;Desktop Manager
#SingleInstance, Force
SetWinDelay, 0
SetBatchLines -1
OnExit RestoreAllWindows
DTM_NumberOfDesktops = 9
DTM_LastDesktop = 1
DTM_CurrentDesktop = 1
Loop % DTM_NumberOfDesktops > 9 ? 9 : DTM_NumberOfDesktops
HotKey, #%A_Index%, HotkeyShowDesktop
DTM_GetCurrentWindows()
Return
;**********************************************************************************
HotkeyShowDesktop:
Critical
StringRight, Desktop, A_ThisHotkey, 1
If (Desktop = DTM_CurrentDesktop)
Return
ShowDesktop(Desktop)
Return
;change this to the desktop #
;this label will run the first time the desktop is shown
Desktop2:
Run ::{450d8fba-ad25-11d0-98a8-0800361b1103} ; Open My Documents
Run ::{20d04fe0-3aea-1069-a2d8-08002b30309d} ; Open My Computer
return
;change this to the desktop #
;this label will run every time the desktop is shown
OnDesktop2:
ToolTip, Desktop %DTM_CurrentDesktop%
SetTimer, DTM_KillToolTip, -1000
return
DTM_KillToolTip:
ToolTip
return
RestoreAllWindows:
Critical
Gui +LastFound +ToolWindow -Caption +AlwaysOnTop
Gui, Color, White
WinSet, TransColor, White
Gui, Font, s48 bold
Gui, Add, Text, cLime, Restoring All Windows...
Gui, Show
Loop, %DTM_NumberOfDesktops%
DllCall("EndDeferWindowPos", "Uint", DTM_Desktop%A_Index%)
Sleep, 500
Gui Destroy
Send {LWin Up}
ExitApp
;**************************************************************************
;Author: NKRUZAN
;Language: AutoHotkey v1.0.47.04
;Creation Date: 02/14/2008 11:39
;Function Name: ShowDesktop()
;
;Syntax:
; ShowDesktop(DesktopID)
;Parameters:
;1) DesktopID =
;Return:
; Success =
; Failure =
;**************************************************************************
ShowDesktop(DesktopID) {
Global
Critical
HideDesktop(DTM_CurrentDesktop)
DTM_LastDesktop := DTM_CurrentDesktop
DTM_CurrentDesktop := DesktopID
Clipboard := DTM_Clipboard%DesktopID%
DTM_CurrentDesktop := DesktopID
DllCall("EndDeferWindowPos", "Uint", DTM_Desktop%DesktopID%)
Gui +LastFound +ToolWindow -Caption +AlwaysOnTop
Gui, Color, White
WinSet, TransColor, White
;WinSet, Trans, 150
Gui, Font, s48
Gui, Add, Text, cLime w600 Center, Desktop:
Gui, Font, s96 bold
Gui, Add, Text, cLime w600 Center, %DesktopID%
Gui, Show
Sleep, 500
Gui Destroy
; mod to run label on each window switch
if !(DTM_Desktop%DesktopID%HasBeenShown)
if IsLabel("Desktop" . DesktopID)
Gosub Desktop%DesktopID%
DTM_Desktop%DesktopID%HasBeenShown := true
if IsLabel("OnDesktop" . DesktopID)
Gosub OnDesktop%DesktopID%
}
;**************************************************************************
;Author: NKRUZAN
;Language: AutoHotkey v1.0.47.04
;Creation Date: 02/14/2008 11:39
;Function Name: HideDesktop()
;
;Syntax:
; HideDesktop(DesktopID)
;Parameters:
;1) DesktopID =
;Return:
; Success =
; Failure =
;**************************************************************************
HideDesktop(DesktopID) {
Global
Critical
DTM_GetCurrentWindows(DTM_Desktop%DesktopID%, HideGroup)
DTM_Clipboard%DesktopID% := ClipboardAll
DllCall("EndDeferWindowPos", "Uint", HideGroup)
}
;**************************************************************************
;Author: NKRUZAN
;Language: AutoHotkey v1.0.47.04
;Creation Date: 02/14/2008 11:38
;Function Name: DTM_GetCurrentWindows()
;
;Syntax:
; DTM_GetCurrentWindows(ByRef ShowGroup=0, ByRef HideGroup=0)
;Parameters:
;1) ByRef ShowGroup=0 =
;2) ByRef HideGroup=0 =
;Return:
; Success =
; Failure =
;**************************************************************************
DTM_GetCurrentWindows(ByRef ShowGroup=0, ByRef HideGroup=0) {
Static SelfPID
Critical
If !SelfPID {
Process, Exist
SelfPID := ErrorLevel
}
T := A_DetectHiddenWindows
DetectHiddenWindows, Off
WinGet, a, List
ShowGroup := DllCall("BeginDeferWindowPos", "Uint", a) ; Non-Tiled Windows
HideGroup := DllCall("BeginDeferWindowPos", "Uint", a) ; Non-Tiled Windows
WinGet, ActWindow, ID, A
ExemptWindows := "TPickSessionDlg,TForm,TFormMain,TBaseLoadErrorDlg,Shell_TrayWnd,DV2ControlHost,ZORRO"
ExemptWindows .= ",Progman,tooltips_class32,AutoHotkeyGUI,TForm4,AutoHotkeyGUI,TfrmDUGraph,TNMGraph,SysShadow"
Loop % a {
WinGetClass, WinClass, % "ahk_id " . a%A_Index%
WinGet, WinPID, PID, % "ahk_id " . a%A_Index%
If WinClass in %ExemptWindows%
Continue
If WinPID = %SelfPID%
Continue
ShowFlags := SWP_SHOWWINDOW := 0x40|SWP_NOSIZE := 0x1|SWP_NOMOVE := 0x2
ShowGroup := DllCall("DeferWindowPos", "Uint", ShowGroup, "Uint", a%A_Index%
, "Uint", 1, "int", _, "int", _, "int", _, "int", _, "Uint", ShowFlags)
HideGroup := DllCall("DeferWindowPos", "Uint", HideGroup, "Uint", a%A_Index%
, "Uint", 1, "int", _, "int", _, "int", _, "int", _
, "Uint", SWP_HIDEWINDOW := 0x80|SWP_NOACTIVATE := 0x10|SWP_NOSIZE := 0x1|SWP_NOMOVE := 0x2)
}
DetectHiddenWindows, %T%
}
|
Origional:
| Code: | DTM_NumberOfDesktops = 4
DTM_LastDesktop = 1
DTM_CurrentDesktop = 1
DTM_Desktop1 := DTM_Desktop2 := DTM_Desktop3 := DTM_Desktop4 := ""
DTM_Clipboard1 := DTM_Clipboard2 := DTM_Clipboard3 := DTM_Clipboard4 := ""
SetWinDelay, 0
OnExit RestoreAllWindows
Gui, +ToolWindow +AlwaysOnTop
Loop, %DTM_NumberOfDesktops%
Gui, Add, Button, h25 w25 gDTM_LoadDesktop ym, %A_Index%
Gui, Show
DTM_GetCurrentWindows()
Return
RestoreAllWindows:
Loop, %DTM_NumberOfDesktops% {
If (A_Index = DTM_CurrentDesktop)
Continue
a := DTM_Desktop%A_Index%
Loop, Parse, a, `,
WinShow, ahk_id %A_LoopField%
}
ExitApp
DTM_LoadDesktop:
If (A_GuiControl = DTM_CurrentDesktop)
Return
ShowDesktop(A_GuiControl)
Return
Esc::ExitApp
ShowDesktop(DesktopID) {
Global DTM_Desktop1, DTM_Desktop2, DTM_Desktop3, DTM_Desktop4
Global DTM_Clipboard1, DTM_Clipboard2, DTM_Clipboard3, DTM_Clipboard4
Global DTM_LastDesktop, DTM_CurrentDesktop
HideDesktop(DTM_CurrentDesktop)
DTM_LastDesktop := DTM_CurrentDesktop
DTM_CurrentDesktop := DesktopID
a := DTM_Desktop%DesktopID%
Clipboard := DTM_Clipboard%DesktopID%
Loop, Parse, a, `,
WinShow, ahk_id %A_LoopField%
DTM_CurrentDesktop := DesktopID
}
HideDesktop(DesktopID) {
Global DTM_Desktop1, DTM_Desktop2, DTM_Desktop3, DTM_Desktop4
Global DTM_Clipboard1, DTM_Clipboard2, DTM_Clipboard3, DTM_Clipboard4
DTM_Desktop%DesktopID% := a := DTM_GetCurrentWindows()
DTM_Clipboard%DesktopID% := ClipboardAll
Loop, Parse, a, `,
WinHide, ahk_id %A_LoopField%
}
DTM_GetWindowInfo(WindowList) {
Loop, Parse, WindowList, `,
{
WinGetTitle, Title, ahk_id %A_LoopField%
WinGetClass, Class, ahk_id %A_LoopField%
If (A_Index = WindowList)
Info .= A_Index . ") " . Title
Info .= A_Index . ") " . Title . "`n"
}
Return Info
}
DTM_GetCurrentWindows() {
Static SelfPID
If !SelfPID {
Process, Exist
SelfPID := ErrorLevel
}
T := A_DetectHiddenWindows
DetectHiddenWindows, Off
WinGet, a, List
;MsgBox % a
Loop % a {
WinGetClass, WinClass, % "ahk_id " . a%A_Index%
WinGet, WinPID, PID, % "ahk_id " . a%A_Index%
If WinClass in Shell_TrayWnd,Progman
Continue
If WinPID = %SelfPID%
Continue
WinList .= a%A_Index% . ","
}
StringTrimRight, WinList, WinList, 1
;MsgBox, % WinList
DetectHiddenWindows, %T%
Return WinList
}
|
_________________
ʞɔпɟ əɥʇ ʇɐɥʍ
Last edited by ahklerner on Mon Jul 14, 2008 2:37 am; edited 4 times in total |
|
| Back to top |
|
 |
ChalamiuS
Joined: 04 Jun 2006 Posts: 189
|
Posted: Mon Feb 11, 2008 9:34 am Post subject: |
|
|
Add this on the bottom to use hotkeys
| Code: |
#1::ShowDesktop(1)
#2::ShowDesktop(2)
#3::ShowDesktop(3)
#4::ShowDesktop(4)
|
_________________ IRC Mibbit
Last edited by ChalamiuS on Wed Feb 27, 2008 9:08 pm; edited 1 time in total |
|
| Back to top |
|
 |
Jero3n
Joined: 19 Jan 2007 Posts: 151
|
Posted: Mon Feb 11, 2008 1:34 pm Post subject: |
|
|
| Wow, this is really nice! |
|
| Back to top |
|
 |
adam_ Guest
|
Posted: Tue Feb 19, 2008 9:22 pm Post subject: |
|
|
| is it posible to exclude a process from being hidden on desktop switch? ie, if I want to see notepad in all desktops. thanks |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1249 Location: USA
|
Posted: Wed Feb 20, 2008 2:08 am Post subject: |
|
|
need to edit these lines:
| Code: | WinGetClass, WinClass, % "ahk_id " . a%A_Index%
WinGet, WinPID, PID, % "ahk_id " . a%A_Index%
If WinClass in Shell_TrayWnd,Progman
|
_________________
ʞɔпɟ əɥʇ ʇɐɥʍ |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1249 Location: USA
|
Posted: Sun Jul 13, 2008 10:21 pm Post subject: |
|
|
Updated first post with new version. _________________
ʞɔпɟ əɥʇ ʇɐɥʍ |
|
| Back to top |
|
 |
TotalBalance
Joined: 22 Jan 2007 Posts: 180 Location: CO, USA
|
Posted: Sun Jul 13, 2008 11:44 pm Post subject: |
|
|
Hi ahklerner,
This is a great POC. I've been on a quest for the best VD open source app, and this one's got great potential to lead the list. Nice job. Couple questions:
1) Couldn't seem to get the newest version to show Desktops (just pasted new code in place of original). Is there something special I need to do?
2) Unless I've missed something, can't save settings for each desktop. Only seems to remember per session, not after reboot. Is this because it's only a POC with this functionality planned or something other? _________________ Lars |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1249 Location: USA
|
Posted: Mon Jul 14, 2008 12:08 am Post subject: |
|
|
you should just need to press # and the number 1-9 (not on numpad)
maybe the upload screwed up, i will test it. _________________
ʞɔпɟ əɥʇ ʇɐɥʍ
Last edited by ahklerner on Mon Jul 14, 2008 12:12 am; edited 1 time in total |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1249 Location: USA
|
Posted: Mon Jul 14, 2008 12:11 am Post subject: |
|
|
it seems to work here.
I don't ever plan on adding "save session" type preferences. (where it will open your windows back up) _________________
ʞɔпɟ əɥʇ ʇɐɥʍ |
|
| Back to top |
|
 |
TotalBalance
Joined: 22 Jan 2007 Posts: 180 Location: CO, USA
|
Posted: Mon Jul 14, 2008 2:04 am Post subject: |
|
|
My bad, I didn't realize the Win-Num was the way to go. Looking for the numbered toolbar.
As for not remembering state, so be it, figured it wouldn't hurt to ask. As an FYI, it wasn't my intent to remember programs that had launched, just folders open in specific VDs.
But, now that I think about it, shouldn't be too hard to do. Not being of your AHK caliber, perhaps you could give me some pointers and I'll take a crack at it.
1. Start the script at PCstartup
1a. In my case, the opening VD would be populated with Google Gadgets and default desktop folders.
2. Via ahk Win+2 to second DV, open programs/folders for that screen. When fully loaded:
3. Repeat for Win+3, Win+4, etc as needed.
Might there be a better way to do this? _________________ Lars |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1249 Location: USA
|
Posted: Mon Jul 14, 2008 2:40 am Post subject: |
|
|
well, are you envisioning a hotkey thats like "remember this" or just have a list of programs that you want opened the first time the desktop is shown? the former would be more difficult imho, it would require some other scripts from forum to get the current path of the explorer window.. etc....
regardless, it did seem like a good idea after i thought abt it a bit.
i modified the ShowDesktop() func to run a specific label if it exists.
if you add labels like so to the script, well, you get the idea.
(Redownload the script in first post)
| Code: | ;change this to the desktop #
;this label will run the first time the desktop is shown
Desktop2:
Run ::{450d8fba-ad25-11d0-98a8-0800361b1103} ; Open My Documents
Run ::{20d04fe0-3aea-1069-a2d8-08002b30309d} ; Open My Computer
return
;change this to the desktop #
;this label will run every time the desktop is shown
OnDesktop2:
ToolTip, Desktop %DTM_CurrentDesktop%
SetTimer, DTM_KillToolTip, -1000
return
|
Happy coding, and thanks for the idea.  _________________
ʞɔпɟ əɥʇ ʇɐɥʍ |
|
| Back to top |
|
 |
TotalBalance
Joined: 22 Jan 2007 Posts: 180 Location: CO, USA
|
Posted: Mon Jul 14, 2008 3:00 am Post subject: |
|
|
Just tried it, very cool, will definately work for me.
Just one questions how do you find the GUIDs (if that's what they are) for each of the folders (e.g. My Computer, My Documents, etc)? _________________ Lars |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1249 Location: USA
|
Posted: Mon Jul 14, 2008 3:22 am Post subject: |
|
|
in the ahk help under CLSID _________________
ʞɔпɟ əɥʇ ʇɐɥʍ |
|
| Back to top |
|
 |
TotalBalance
Joined: 22 Jan 2007 Posts: 180 Location: CO, USA
|
Posted: Mon Jul 14, 2008 3:41 am Post subject: |
|
|
Gotcha. I should have been more specific, how would I open custom folders (e.g. My Utilities, My Key Docs, etc) or is this just the stuff usually used in AHK to open a folder or program (I guess I just liked your very "elegant" way you did it). _________________ Lars |
|
| Back to top |
|
 |
ahklerner
Joined: 26 Jun 2006 Posts: 1249 Location: USA
|
Posted: Mon Jul 14, 2008 3:49 am Post subject: |
|
|
is this what you mean?
| Code: | MyPath = %A_MyDocuments%\Autohotkey\Lib
Run explorer.exe %MyPath%
MyPath = C:\
Run explorer.exe %MyPath%
|
_________________
ʞɔпɟ əɥʇ ʇɐɥʍ |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|