AutoHotkey Community

It is currently May 26th, 2012, 6:23 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 51 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject:
PostPosted: February 28th, 2008, 2:30 am 
Offline

Joined: June 23rd, 2007, 2:44 am
Posts: 136
I have modified the code a bit. My coding isnt that great. If someone likes what i have done It would be great if they could work the bugs out of it.

http://www.autohotkey.net/~viciouskinid/MultiDesk_files.zip


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 28th, 2008, 8:23 pm 
got problems with moving windows to other desktops. computer hangs.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 29th, 2008, 6:07 am 
Offline

Joined: June 23rd, 2007, 2:44 am
Posts: 136
My other code was really messy. Here is some better work.

http://www.autohotkey.net/~viciouskinid/OrderdDesk.rar

If anyone wants to have a go at debugging it that would be appreciated. The main issue is that occasionally it makes the desktop icons and taskbar disappear. I cant fix it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 24th, 2008, 5:11 pm 
I think what this misses is a "gather windows" command. which is, move all windows from other worskpaces to current workspace. I don't know how to do it though :P


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 8th, 2008, 3:30 pm 
I really like this autohotkeyscript and mode some modifications to version Christian Schüler's v1.11 :

Added support for MultiMonTaskbar (a taskbar on a second physical screen)
Added storing of active window per virtual desktop
Added Traytips to inform the user what happened

Code:
; DesktopSwitch
;
; AutoHotkey Version: 1.0.40.00 (that's at least the version I'm using)
; Language:       English
; Platform:       Win9x/NT/XP
; Author:         Christian Schüler <c_schueler@gmx.at>
; last changes:   08. Sep. 2008
;
; Script Function:
;
; A small tool for switching between multiple virtual desktops.
; Use Alt-F<desktop index> (e.g. Alt-F2) to switch between desktops and
; Quit the script and all windows on all virtual desktops will be soon
; Currently, 4 desktops are supported, because more will start to confuse me...
;
; Version history:
;
; v1.12, 08 sept 2008 Emiel Witteman
; Code cleanup, removed some redundant code from previous versions.
; Added support for MultiMonTaskbar (a taskbar on a second physical screen)
; Added storing of active window per virtual desktop
; Added Traytips to inform the user what happened
;
; v1.11, 22. Nov. 2005
; Fixed bug: windows are now corrrectly activated after switching/sending
;
; v1.1, 05. Nov. 2005
; Added feature: pressing Ctrl/Alt-<index> sends the active window to the desktop <index>.
;
; v1.0, 04. Nov. 2005
; It works!
; Switching can be done using Alt-<desktop index>, e.g. Alt-1. Pressing
; Alt-0 will exit the script and show all windows from all virtual desktops
; at once.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Auto timers, usefull when debugging  ;
; turn off or set high to save cpu     ;
; when debug is done                   ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SetTimer,AutoReloadScript,1000

; ***** initialization *****
#WinActivateForce
SetBatchLines, -1   ; maximize script speed!
SetWinDelay, -1
OnExit, CleanUp     ; clean up in case of error (otherwise some windows will get lost)

numDesktops := 4    ; maximum number of desktops
curDesktop := 1     ; index number of current desktop

; ***** hotkeys *****
!f1::SwitchToDesktop(1)
!f2::SwitchToDesktop(2)
!f3::SwitchToDesktop(3)
!f4::SwitchToDesktop(4)

^!f1::SendActiveToDesktop(1)
^!f2::SendActiveToDesktop(2)
^!f3::SendActiveToDesktop(3)
^!f4::SendActiveToDesktop(4)

;!0::ExitApp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; AutoScriptReload/Suspend ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
AutoReloadScript:
   FileGetAttrib,attribs,%A_ScriptFullPath%
   IfInString,attribs,A
   {
      FileSetAttrib,-A,%A_ScriptFullPath%
      TrayTip, %A_ScriptName%, updated AutoHotkey script
      SetTimer, AutoReloadScriptTrayTip, 2000
   }
return
AutoReloadScriptTrayTip:
    SetTimer, AutoReloadScriptTrayTip, Off
    TrayTip
    Reload
return


; ***** functions *****

; switch to the desktop with the given index number
SwitchToDesktop(newDesktop)
{
   global

   if (curDesktop <> newDesktop)
   {
      GetCurrentWindows(curDesktop)
      ShowHideWindows(curDesktop, false)
      ShowHideWindows(newDesktop, true)
      activate_window := % active_id%newDesktop%
      WinActivate, ahk_id %activate_window%
      TrayTip, DesktopSwitch, Switching to desktop %newDesktop%
      curDesktop := newDesktop
   }
   return
}

; sends the given window from the current desktop to the given desktop
SendToDesktop(windowID, newDesktop)
{
   global
   RemoveWindowID(curDesktop, windowID)

   ; add window to destination desktop
   windows%newDesktop% += 1
   i := windows%newDesktop%

   windows%newDesktop%%i% := windowID
   
   WinHide, ahk_id %windowID%
   TrayTip, DesktopSwitch, Window send to desktop %newDesktop%

   Send, {ALT DOWN}{TAB}{ALT UP}   ; activate the right window
}

; sends the currently active window to the given desktop
SendActiveToDesktop(newDesktop)
{
   WinGet, id, ID, A
   SendToDesktop(id, newDesktop)
}

; removes the given window id from the desktop <desktopIdx>
RemoveWindowID(desktopIdx, ID)
{
   global   
   Loop, % windows%desktopIdx%
   {
      if (windows%desktopIdx%%A_Index% = ID)
      {
         RemoveWindowID_byIndex(desktopIdx, A_Index)
         Break
      }
   }
}

; this removes the window id at index <ID_idx> from desktop number <desktopIdx>
RemoveWindowID_byIndex(desktopIdx, ID_idx)
{
   global
   Loop, % windows%desktopIdx% - ID_idx
   {
      idx1 := % A_Index + ID_idx - 1
      idx2 := % A_Index + ID_idx
      windows%desktopIdx%%idx1% := windows%desktopIdx%%idx2%
   }
   windows%desktopIdx% -= 1
}

; this builds a list of all currently visible windows in stores it in desktop <index>
GetCurrentWindows(index)
{
   global
   WinGet, active_id%index%, ID, A                      ; get the current active window
   WinGet, windows%index%, List,,, Program Manager      ; get list of all visible windows

   ; remove windows which we want to see on all virtual desktops
   Loop, % windows%index%
   {
      id := % windows%index%%A_Index%
      WinGetClass, windowClass, ahk_id %id%
      if windowClass = Shell_TrayWnd    ; remove task bar window id
         RemoveWindowID_byIndex(index, A_Index)
      else if windowClass = #32770      ; Emiel: we also want multimontaskbar on all virtual desktops
         RemoveWindowID_byIndex(index, A_Index)
   }
}

; if show=true then shows windows of desktop %index%, otherwise hides them
ShowHideWindows(index, show)
{
   global

   Loop, % windows%index%
   {
      id := % windows%index%%A_Index%
      if show
         WinShow, ahk_id %id%
      else
         WinHide, ahk_id %id%
   }
}

; show all windows from all desktops on exit
CleanUp:
Loop, %numDesktops%
   ShowHideWindows(A_Index, true)
ExitApp


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 8th, 2008, 4:34 pm 
Squashed some nasty array housekeeping bugs which explained the faulty hide/show of some windows.

Can some array expert conform this is the correct way to erase a two demensional array?
Code:
   emptyString =
   StringSplit, windows%index%, emptyString


This version seems to working fine now:
Code:
; DesktopSwitch
;
; AutoHotkey Version: 1.0.40.00 (that's at least the version I'm using)
; Language:       English
; Platform:       Win9x/NT/XP
; Author:         Christian Schüler <c_schueler@gmx.at>
; last changes:   08. Sep. 2008
;
; Script Function:
;
; A small tool for switching between multiple virtual desktops.
; Use Alt-F<desktop index> (e.g. Alt-F2) to switch between desktops and
; Quit the script and all windows on all virtual desktops will be soon
; Currently, 4 desktops are supported, because more will start to confuse me...
;
; Version history:
;
; v1.13, 08 sept 2008 Emiel Witteman
; Fixed bugs in array housekeeping, explained the faulty hide/show of some windows
;
; v1.12, 08 sept 2008 Emiel Witteman
; Code cleanup, removed some redundant code from previous versions.
; Added support for MultiMonTaskbar (a taskbar on a second physical screen)
; Added storing of active window per virtual desktop
; Added Traytips to inform the user what happened
;
; v1.11, 22. Nov. 2005
; Fixed bug: windows are now corrrectly activated after switching/sending
;
; v1.1, 05. Nov. 2005
; Added feature: pressing Ctrl/Alt-<index> sends the active window to the desktop <index>.
;
; v1.0, 04. Nov. 2005
; It works!
; Switching can be done using Alt-<desktop index>, e.g. Alt-1. Pressing
; Alt-0 will exit the script and show all windows from all virtual desktops
; at once.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Auto timers, usefull when debugging  ;
; turn off or set high to save cpu     ;
; when debug is done                   ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SetTimer,AutoReloadScript,1000

; ***** initialization *****
#WinActivateForce
SetBatchLines, -1   ; maximize script speed!
SetWinDelay, -1
OnExit, CleanUp     ; clean up in case of error (otherwise some windows will get lost)

numDesktops := 4    ; maximum number of desktops
curDesktop := 1     ; index number of current desktop

; ***** hotkeys *****
!f1::SwitchToDesktop(1)
!f2::SwitchToDesktop(2)
!f3::SwitchToDesktop(3)
!f4::SwitchToDesktop(4)

^!f1::SendActiveToDesktop(1)
^!f2::SendActiveToDesktop(2)
^!f3::SendActiveToDesktop(3)
^!f4::SendActiveToDesktop(4)

;!0::ExitApp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; AutoScriptReload/Suspend ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
AutoReloadScript:
   FileGetAttrib,attribs,%A_ScriptFullPath%
   IfInString,attribs,A
   {
      FileSetAttrib,-A,%A_ScriptFullPath%
      TrayTip, %A_ScriptName%, updated AutoHotkey script
      SetTimer, AutoReloadScriptTrayTip, 2000
   }
return
AutoReloadScriptTrayTip:
    SetTimer, AutoReloadScriptTrayTip, Off
    TrayTip
    Reload
return


; ***** functions *****

; switch to the desktop with the given index number
SwitchToDesktop(newDesktop)
{
   global

   if (curDesktop <> newDesktop)
   {
      GetCurrentWindows(curDesktop)
      ShowHideWindows(curDesktop, false)
      ShowHideWindows(newDesktop, true)
      activate_window := % active_id%newDesktop%
      WinActivate, ahk_id %activate_window%
      TrayTip, DesktopSwitch, Switching to desktop %newDesktop%
      curDesktop := newDesktop
   }
   return
}

; sends the given window from the current desktop to the given desktop
SendToDesktop(windowID, newDesktop)
{
   global
   RemoveWindowID(curDesktop, windowID)

   ; add window to destination desktop
   windows%newDesktop% += 1
   i := windows%newDesktop%

   windows%newDesktop%%i% := windowID
   
   WinHide, ahk_id %windowID%
   TrayTip, DesktopSwitch, Window send to desktop %newDesktop%

   Send, {ALT DOWN}{TAB}{ALT UP}   ; activate the right window
}

; sends the currently active window to the given desktop
SendActiveToDesktop(newDesktop)
{
   WinGet, id, ID, A
   SendToDesktop(id, newDesktop)
}

; removes the given window id from the desktop <desktopIdx>
RemoveWindowID(desktopIdx, ID)
{
   global   
   Loop, % windows%desktopIdx%
   {
      if (windows%desktopIdx%%A_Index% = ID)
      {
         windows%desktopIdx%%A_Index%=      ;Emiel: just empty the array element, array will be emptied by next switch anyway
         Break
      }
   }
}

; this builds a list of all currently visible windows in stores it in desktop <index>
GetCurrentWindows(index)
{
   global
   WinGet, active_id%index%, ID, A                      ; get the current active window
   emptyString =
   StringSplit, windows%index%, emptyString             ; Emiel: delete the entire windows_index_ array
   WinGet, windows%index%, List,,, Program Manager      ; get list of all visible windows

   ; remove windows which we want to see on all virtual desktops
   Loop, % windows%index%
   {
      id := % windows%index%%A_Index%
      WinGetClass, windowClass, ahk_id %id%
      if windowClass = Shell_TrayWnd     ; remove task bar window id
           windows%index%%A_Index%=      ; Emiel: just empty the array element, array will be emptied by next switch anyway
      if windowClass = #32770            ; Emiel: we also want multimontaskbar on all virtual desktops
           windows%index%%A_Index%=      ; Emiel: just empty the array element, array will be emptied by next switch anyway
   }
}

; if show=true then shows windows of desktop %index%, otherwise hides them
ShowHideWindows(index, show)
{
   global

   Loop, % windows%index%
   {
      id := % windows%index%%A_Index%
      if show
         WinShow, ahk_id %id%
      else
         WinHide, ahk_id %id%
   }
}

; show all windows from all desktops on exit
CleanUp:
Loop, %numDesktops%
   ShowHideWindows(A_Index, true)
ExitApp


BTW my previous post can be deleted


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2009, 4:10 pm 
I fixed the bug where the window disappears if you send it to its current desktop. (e.g. sending Window X in Desktop 1 to Desktop 1 resulted in Window X disappearing forever)

Replace this section with the updated code:

; sends the given window from the current desktop to the given desktop
SendToDesktop(windowID, newDesktop)
{
global

if (CurDesktop <> newDesktop)
{
RemoveWindowID(curDesktop, windowID)

; add window to destination desktop
windows%newDesktop% += 1
i := windows%newDesktop%

windows%newDesktop%%i% := windowID

WinHide, ahk_id %windowID%
TrayTip, DesktopSwitch, Window send to desktop %newDesktop%

Send, {ALT DOWN}{TAB}{ALT UP} ; activate the right window
}
}


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 25th, 2009, 10:50 am 
The full code with the fix mentioned in the previous post by poser101

Code:
; DesktopSwitch
;
; AutoHotkey Version: 1.0.40.00 (that's at least the version I'm using)
; Language:       English
; Platform:       Win9x/NT/XP
; Author:         Christian Schüler <c_schueler@gmx.at>
; last changes:   25. jun. 2009
;
; Script Function:
;
; A small tool for switching between multiple virtual desktops.
; Use Alt-F<desktop index> (e.g. Alt-F2) to switch between desktops and
; Quit the script and all windows on all virtual desktops will be soon
; Currently, 4 desktops are supported, because more will start to confuse me...
;
; Version history:
;
; v1.14, 25 jun 2009 Emiel Witteman
; Fixed bug window disappearing when sending it to the current desktop

; v1.13, 08 sept 2008 Emiel Witteman
; Fixed bugs in array housekeeping, explained the faulty hide/show of some windows
;
; v1.12, 08 sept 2008 Emiel Witteman
; Code cleanup, removed some redundant code from previous versions.
; Added support for MultiMonTaskbar (a taskbar on a second physical screen)
; Added storing of active window per virtual desktop
; Added Traytips to inform the user what happened
;
; v1.11, 22. Nov. 2005
; Fixed bug: windows are now corrrectly activated after switching/sending
;
; v1.1, 05. Nov. 2005
; Added feature: pressing Ctrl/Alt-<index> sends the active window to the desktop <index>.
;
; v1.0, 04. Nov. 2005
; It works!
; Switching can be done using Alt-<desktop index>, e.g. Alt-1. Pressing
; Alt-0 will exit the script and show all windows from all virtual desktops
; at once.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Auto timers, usefull when debugging  ;
; turn off or set high to save cpu     ;
; when debug is done                   ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SetTimer,AutoReloadScript,1000

; ***** initialization *****
#WinActivateForce
SetBatchLines, -1   ; maximize script speed!
SetWinDelay, -1
OnExit, CleanUp     ; clean up in case of error (otherwise some windows will get lost)

numDesktops := 4    ; maximum number of desktops
curDesktop := 1     ; index number of current desktop

; ***** hotkeys *****
!f1::SwitchToDesktop(1)
!f2::SwitchToDesktop(2)
!f3::SwitchToDesktop(3)
!f4::SwitchToDesktop(4)

^!f1::SendActiveToDesktop(1)
^!f2::SendActiveToDesktop(2)
^!f3::SendActiveToDesktop(3)
^!f4::SendActiveToDesktop(4)

;!0::ExitApp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; AutoScriptReload/Suspend ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
AutoReloadScript:
   FileGetAttrib,attribs,%A_ScriptFullPath%
   IfInString,attribs,A
   {
      FileSetAttrib,-A,%A_ScriptFullPath%
      TrayTip, %A_ScriptName%, updated AutoHotkey script
      SetTimer, AutoReloadScriptTrayTip, 2000
   }
return
AutoReloadScriptTrayTip:
    SetTimer, AutoReloadScriptTrayTip, Off
    TrayTip
    Reload
return


; ***** functions *****

; switch to the desktop with the given index number
SwitchToDesktop(newDesktop)
{
   global

   if (curDesktop <> newDesktop)
   {
      GetCurrentWindows(curDesktop)
      ShowHideWindows(curDesktop, false)
      ShowHideWindows(newDesktop, true)
      activate_window := % active_id%newDesktop%
      WinActivate, ahk_id %activate_window%
      TrayTip, DesktopSwitch, Switching to desktop %newDesktop%
      curDesktop := newDesktop
   }
   return
}

; sends the given window from the current desktop to the given desktop
SendToDesktop(windowID, newDesktop)
{
   global
   if (curDesktop <> newDesktop)
   {
   RemoveWindowID(curDesktop, windowID)

   ; add window to destination desktop
   windows%newDesktop% += 1
   i := windows%newDesktop%

   windows%newDesktop%%i% := windowID
   
   WinHide, ahk_id %windowID%
   TrayTip, DesktopSwitch, Window send to desktop %newDesktop%

   Send, {ALT DOWN}{TAB}{ALT UP}   ; activate the right window
   }
}

; sends the currently active window to the given desktop
SendActiveToDesktop(newDesktop)
{
   WinGet, id, ID, A
   SendToDesktop(id, newDesktop)
}

; removes the given window id from the desktop <desktopIdx>
RemoveWindowID(desktopIdx, ID)
{
   global   
   Loop, % windows%desktopIdx%
   {
      if (windows%desktopIdx%%A_Index% = ID)
      {
         windows%desktopIdx%%A_Index%=      ;Emiel: just empty the array element, array will be emptied by next switch anyway
         Break
      }
   }
}

; this builds a list of all currently visible windows in stores it in desktop <index>
GetCurrentWindows(index)
{
   global
   WinGet, active_id%index%, ID, A                      ; get the current active window
   emptyString =
   StringSplit, windows%index%, emptyString             ; Emiel: delete the entire windows_index_ array
   WinGet, windows%index%, List,,, Program Manager      ; get list of all visible windows

   ; remove windows which we want to see on all virtual desktops
   Loop, % windows%index%
   {
      id := % windows%index%%A_Index%
      WinGetClass, windowClass, ahk_id %id%
      if windowClass = Shell_TrayWnd     ; remove task bar window id
           windows%index%%A_Index%=      ; Emiel: just empty the array element, array will be emptied by next switch anyway
      if windowClass = #32770            ; Emiel: we also want multimontaskbar on all virtual desktops
           windows%index%%A_Index%=      ; Emiel: just empty the array element, array will be emptied by next switch anyway
      if windowClass = cygwin/x X rl-xosview-XOsview-0   ; Emiel: xosviews e.d.
           windows%index%%A_Index%=     
      if windowClass = cygwin/x X rl-xosview-XOsview-1   ; Emiel: xosviews e.d.
           windows%index%%A_Index%=     
      if windowClass = MozillaUIWindowClass              ; Mozilla thunderbird
      {
        WinGet, ExStyle, ExStyle, ahk_id %id%
          if (ExStyle & 0x8)  ; 0x8 is WS_EX_TOPMOST.    ; Alleen de mailboxalertmelding!
           windows%index%%A_Index%=     
      }
   }
}

; if show=true then shows windows of desktop %index%, otherwise hides them
ShowHideWindows(index, show)
{
   global

   Loop, % windows%index%
   {
      id := % windows%index%%A_Index%
      if show
         WinShow, ahk_id %id%
      else
         WinHide, ahk_id %id%
   }
}

; show all windows from all desktops on exit
CleanUp:
Loop, %numDesktops%
   ShowHideWindows(A_Index, true)
ExitApp



Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2010, 7:51 am 
Offline

Joined: November 29th, 2009, 7:53 am
Posts: 46
Location: Queensland
how would you go about using a shortcut to make a window remain within all desktops


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 8th, 2010, 8:31 am 
Offline

Joined: November 29th, 2009, 7:53 am
Posts: 46
Location: Queensland
can you make it run on startup
would be very handy


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 8th, 2010, 3:19 pm 
Offline

Joined: October 6th, 2009, 2:01 am
Posts: 58
seems like a good idea to make sure it's only running one instance. simple i know, but probably good for stability.

_________________
<ellipsis>...</ellipsis>


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 7th, 2010, 9:39 am 
Offline

Joined: October 23rd, 2009, 8:26 am
Posts: 1
Thanks ~,i really like this scrip~ :lol:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 16th, 2010, 7:00 am 
I realize this is an old thread, but I just found it...

When using Windows XP I found that it allowed me to switch faster than Windows could handle it, causing windows to be lost, tray tips to be frozen, etc.

To solve this problem I merely added a lock mechanism and timer between window switches to give Windows an appropriate time to switch.

Code:
; ---- Snip
USE_PAUSE = 4000
lock = 0

#1::
   if(lock = 0)
   {
      lock = 1
      SwitchToDesktop(1)
      sleep, %USE_PAUSE%
      lock = 0
   }
return

#2::
   if(lock = 0)
   {
      lock = 1
      SwitchToDesktop(2)
      sleep, %USE_PAUSE%
      lock = 0
   }
return
; ---- Snip


I'm about to share this script with other non-tech user and I don't want them to mess their systems up from crazy behaviour. This should curb that behaviour.

Cheers,

John


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 19th, 2010, 11:33 pm 
Another update:

Fixed the mutual exclusion lock to properly unlock after execution, instead of waiting for a period and then unlocking.

Fixed two bugs where the Program Manager and the task bar can be sent to another window.

Code:
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Auto timers, usefull when debugging  ;
; turn off or set high to save cpu     ;
; when debug is done                   ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SetTimer,AutoReloadScript,1000

; ***** initialization *****
#WinActivateForce
SetBatchLines, -1         ; maximize script speed!
SetWinDelay, -1
OnExit, CleanUp           ; clean up in case of error (otherwise some windows will get lost)

numDesktops := 4          ; maximum number of desktops
curDesktop := 1           ; index number of current desktop
USE_PAUSE = 1000         ; Tray Tip Pause Length
lock = 0               ; lock to prevent running both hotkeys at same time

; ***** hotkeys *****
#1::
   if(lock = 0)
   {
      lock = 1
      SwitchToDesktop(1)
   }
return

#2::
   if(lock = 0)
   {
      lock = 1
      SwitchToDesktop(2)      
   }
return

#3::
   if(lock = 0)
   {
      lock = 1
      SwitchToDesktop(3)      
   }
return

#4::
   if(lock = 0)
   {
      lock = 1
      SwitchToDesktop(4)      
   }
return

^!1::
   if(lock = 0)
   {
      lock = 1
      SendActiveToDesktop(1)      
   }
return

^!2::
   if(lock = 0)
   {
      lock = 1
      SendActiveToDesktop(2)
   }
return

^!3::
   if(lock = 0)
   {
      lock = 1
      SendActiveToDesktop(3)
   }
return

^!4::
   if(lock = 0)
   {
      lock = 1
      SendActiveToDesktop(4)            
   }
return

#0::goto, cleanup

;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; AutoScriptReload/Suspend ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
AutoReloadScript:
   FileGetAttrib,attribs,%A_ScriptFullPath%
   IfInString,attribs,A
   {
      FileSetAttrib,-A,%A_ScriptFullPath%
      TrayTip, %A_ScriptName%, updated AutoHotkey script
      SetTimer, AutoReloadScriptTrayTip, 2000
   }
return
AutoReloadScriptTrayTip:
    SetTimer, AutoReloadScriptTrayTip, Off
    TrayTip
    Reload
return

; ***** functions *****

; switch to the desktop with the given index number
SwitchToDesktop(newDesktop)
{
   global

   if (curDesktop <> newDesktop)
   {
      GetCurrentWindows(curDesktop)
      ShowHideWindows(curDesktop, false)
      ShowHideWindows(newDesktop, true)
      activate_window := % active_id%newDesktop%
      WinActivate, ahk_id %activate_window%
      TrayTip, DesktopSwitch, Switching to desktop %newDesktop%    
      curDesktop := newDesktop
   }
   
   SetTimer, RemoveTrayTip, %USE_PAUSE%
   sleep, 1000
   lock = 0
   
   return
}

; sends the given window from the current desktop to the given desktop
SendToDesktop(windowID, newDesktop)
{
   global
   if (curDesktop <> newDesktop)
   {
   RemoveWindowID(curDesktop, windowID)

   ; add window to destination desktop
   windows%newDesktop% += 1
   i := windows%newDesktop%

   windows%newDesktop%%i% := windowID
   
   WinHide, ahk_id %windowID%
   TrayTip, DesktopSwitch, Window send to desktop %newDesktop%   
   Send, {ALT DOWN}{TAB}{ALT UP}   ; activate the right window
   }
   
   SetTimer, RemoveTrayTip, %USE_PAUSE%
}

; sends the currently active window to the given desktop
SendActiveToDesktop(newDesktop)
{

   global

   WinGet, id, ID, A
   
   WinGetActiveTitle, curWin   
   
   sleep, 200            
   
   ; If Window Does not have a title, do not send it
   if( (curWin = "") || (curWin = "Program Manager"))
   {
      lock = 0
      sleep, 1000
      return      
   }
   
   SendToDesktop(id, newDesktop)
   sleep, 1000
   lock = 0
}

; removes the given window id from the desktop <desktopIdx>
RemoveWindowID(desktopIdx, ID)
{
   global   
   Loop, % windows%desktopIdx%
   {
      if (windows%desktopIdx%%A_Index% = ID)
      {
         windows%desktopIdx%%A_Index%=      ;Emiel: just empty the array element, array will be emptied by next switch anyway
         Break
      }
   }
}

; this builds a list of all currently visible windows in stores it in desktop <index>
GetCurrentWindows(index)
{
   global
   WinGet, active_id%index%, ID, A                      ; get the current active window
   emptyString =
   StringSplit, windows%index%, emptyString             ; delete the entire windows_index_ array
   WinGet, windows%index%, List,,, Program Manager      ; get list of all visible windows

   ; remove windows which we want to see on all virtual desktops
   Loop, % windows%index%
   {
      id := % windows%index%%A_Index%
      WinGetClass, windowClass, ahk_id %id%
      if windowClass = Shell_TrayWnd     ; remove task bar window id
           windows%index%%A_Index%=      ; just empty the array element, array will be emptied by next switch anyway
      if windowClass = #32770            ; we also want multimontaskbar on all virtual desktops
           windows%index%%A_Index%=      ; just empty the array element, array will be emptied by next switch anyway
      if windowClass = cygwin/x X rl-xosview-XOsview-0   ; xosviews e.d.
           windows%index%%A_Index%=     
      if windowClass = cygwin/x X rl-xosview-XOsview-1   ; xosviews e.d.
           windows%index%%A_Index%=     
      if windowClass = MozillaUIWindowClass              ; Mozilla thunderbird
      {
        WinGet, ExStyle, ExStyle, ahk_id %id%
          if (ExStyle & 0x8)  ; 0x8 is WS_EX_TOPMOST.
           windows%index%%A_Index%=     
      }
   }
}

; if show=true then shows windows of desktop %index%, otherwise hides them
ShowHideWindows(index, show)
{
   global

   Loop, % windows%index%
   {
      id := % windows%index%%A_Index%
      if show
         WinShow, ahk_id %id%
      else
         WinHide, ahk_id %id%
   }
}

; show all windows from all desktops on exit
CleanUp:
Loop, %numDesktops%
   ShowHideWindows(A_Index, true)
ExitApp

RemoveTrayTip:
SetTimer, RemoveTrayTip, Off
TrayTip
return


Only bugs left that I can see is the shadow of hidden windows that stick around sometimes when switching windows. For example, the tooltip shadow will sometimes remain after switching, or the start menu shadow will remain if open during a switch.

If anyone has a suggestion on how to fix this last bug, then let me know.

Best,

John


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 20th, 2010, 10:03 pm 
And my last update, I promise...

Code:
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Auto timers, usefull when debugging  ;
; turn off or set high to save cpu     ;
; when debug is done                   ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SetTimer,AutoReloadScript,1000

; ***** initialization *****
#WinActivateForce
#NoTrayIcon
SetBatchLines, -1         ; maximize script speed!
SetWinDelay, -1
OnExit, CleanUp           ; clean up in case of error (otherwise some windows will get lost)

numDesktops := 4          ; maximum number of desktops
curDesktop := 1           ; index number of current desktop
USE_PAUSE = 1000         ; Tray Tip Pause Length
lock = 0               ; lock to prevent running both hotkeys at same time

; ***** hotkeys *****
#1::
   if(lock = 0)
   {
      lock = 1
      SwitchToDesktop(1)
   }
return

#2::
   if(lock = 0)
   {
      lock = 1
      SwitchToDesktop(2)      
   }
return

#3::
   if(lock = 0)
   {
      lock = 1
      SwitchToDesktop(3)      
   }
return

#4::
   if(lock = 0)
   {
      lock = 1
      SwitchToDesktop(4)      
   }
return

^!1::
   if(lock = 0)
   {
      lock = 1
      SendActiveToDesktop(1)      
   }
return

^!2::
   if(lock = 0)
   {
      lock = 1
      SendActiveToDesktop(2)
   }
return

^!3::
   if(lock = 0)
   {
      lock = 1
      SendActiveToDesktop(3)
   }
return

^!4::
   if(lock = 0)
   {
      lock = 1
      SendActiveToDesktop(4)            
   }
return

#0::goto, cleanup

;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; AutoScriptReload/Suspend ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
AutoReloadScript:
   FileGetAttrib,attribs,%A_ScriptFullPath%
   IfInString,attribs,A
   {
      FileSetAttrib,-A,%A_ScriptFullPath%
      ToolTip, %A_ScriptName% updated AutoHotkey script, -1000, -1000
      SetTimer, AutoReloadScriptToolTip, 2000
   }
return
AutoReloadScriptToolTip:
    SetTimer, AutoReloadScriptToolTip, Off
    ToolTip
    Reload
return

; ***** functions *****

; switch to the desktop with the given index number
SwitchToDesktop(newDesktop)
{
   global

   WinGetActiveTitle, curWin   
   
   sleep, 200            
   
   ; Removes the chance of getting Start Menu Shadow Frozen on Screen
   if(curWin = "")
      WinActivate, Program Manager
      
   ; Removes the chance of getting Tray or Tooltip shadows frozen on screen
   ToolTip
   TrayTip
      
   sleep, 200
   
   if (curDesktop <> newDesktop)
   {
      GetCurrentWindows(curDesktop)
      ShowHideWindows(curDesktop, false)
      ShowHideWindows(newDesktop, true)
      activate_window := % active_id%newDesktop%
      WinActivate, ahk_id %activate_window%
      ToolTip,  Switching to desktop %newDesktop%, -1000, -1000
      curDesktop := newDesktop
   }
   
   SetTimer, RemoveToolTip, %USE_PAUSE%
   sleep, 1000
   lock = 0
   
   return
}

; sends the given window from the current desktop to the given desktop
SendToDesktop(windowID, newDesktop)
{
   global
   if (curDesktop <> newDesktop)
   {
   RemoveWindowID(curDesktop, windowID)

   ; add window to destination desktop
   windows%newDesktop% += 1
   i := windows%newDesktop%

   windows%newDesktop%%i% := windowID
   
   WinHide, ahk_id %windowID%
   ToolTip, Window sent to desktop %newDesktop%, -1000, -1000
   Send, {ALT DOWN}{TAB}{ALT UP}   ; activate the right window
   }
   
   SetTimer, RemoveToolTip, %USE_PAUSE%
}

; sends the currently active window to the given desktop
SendActiveToDesktop(newDesktop)
{

   global

   WinGet, id, ID, A
   
   WinGetActiveTitle, curWin   
   
   sleep, 200            
   
   ; If Window Does not have a title, do not send it
   if( (curWin = "") || (curWin = "Program Manager"))
   {
      lock = 0
      sleep, 1000
      return      
   }
   
   SendToDesktop(id, newDesktop)
   sleep, 1000
   lock = 0
}

; removes the given window id from the desktop <desktopIdx>
RemoveWindowID(desktopIdx, ID)
{
   global   
   Loop, % windows%desktopIdx%
   {
      if (windows%desktopIdx%%A_Index% = ID)
      {
         windows%desktopIdx%%A_Index%=      ;Emiel: just empty the array element, array will be emptied by next switch anyway
         Break
      }
   }
}

; this builds a list of all currently visible windows in stores it in desktop <index>
GetCurrentWindows(index)
{
   global
   WinGet, active_id%index%, ID, A                      ; get the current active window
   emptyString =
   StringSplit, windows%index%, emptyString             ; delete the entire windows_index_ array
   WinGet, windows%index%, List,,, Program Manager      ; get list of all visible windows

   ; remove windows which we want to see on all virtual desktops
   Loop, % windows%index%
   {
      id := % windows%index%%A_Index%
      WinGetClass, windowClass, ahk_id %id%
      if windowClass = Shell_TrayWnd     ; remove task bar window id
           windows%index%%A_Index%=      ; just empty the array element, array will be emptied by next switch anyway
      if windowClass = #32770            ; we also want multimontaskbar on all virtual desktops
           windows%index%%A_Index%=      ; just empty the array element, array will be emptied by next switch anyway
      if windowClass = cygwin/x X rl-xosview-XOsview-0   ; xosviews e.d.
           windows%index%%A_Index%=     
      if windowClass = cygwin/x X rl-xosview-XOsview-1   ; xosviews e.d.
           windows%index%%A_Index%=     
      if windowClass = MozillaUIWindowClass              ; Mozilla thunderbird
      {
        WinGet, ExStyle, ExStyle, ahk_id %id%
          if (ExStyle & 0x8)  ; 0x8 is WS_EX_TOPMOST.
           windows%index%%A_Index%=     
      }
   }
}

; if show=true then shows windows of desktop %index%, otherwise hides them
ShowHideWindows(index, show)
{
   global

   Loop, % windows%index%
   {
      id := % windows%index%%A_Index%
      if show
         WinShow, ahk_id %id%
      else
         WinHide, ahk_id %id%
   }
}

; show all windows from all desktops on exit
CleanUp:
Loop, %numDesktops%
   ShowHideWindows(A_Index, true)
ExitApp

RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return


Fixes at least two possible sources of the shadow bug. If the start menu is open, then it activates the desktop before hiding windows. If tooltip or traytips are open, then it closes them.

Cheers,

John


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 51 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Stigg and 17 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group