AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Multiple virtual desktops
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
viciouskinid



Joined: 23 Jun 2007
Posts: 136

PostPosted: Thu Feb 28, 2008 2:30 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Guest






PostPosted: Thu Feb 28, 2008 8:23 pm    Post subject: Reply with quote

got problems with moving windows to other desktops. computer hangs.
Back to top
viciouskinid



Joined: 23 Jun 2007
Posts: 136

PostPosted: Fri Feb 29, 2008 6:07 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
girl_interrupted
Guest





PostPosted: Thu Apr 24, 2008 5:11 pm    Post subject: Reply with quote

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 Razz
Back to top
Guest






PostPosted: Mon Sep 08, 2008 3:30 pm    Post subject: Reply with quote

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
Back to top
Guest






PostPosted: Mon Sep 08, 2008 4:34 pm    Post subject: Reply with quote

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
Back to top
poser101
Guest





PostPosted: Thu Mar 12, 2009 4:10 pm    Post subject: Reply with quote

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
}
}
Back to top
Emiel
Guest





PostPosted: Thu Jun 25, 2009 10:50 am    Post subject: Reply with quote

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

Back to top
small_c0d3r



Joined: 29 Nov 2009
Posts: 18
Location: Queensland

PostPosted: Thu Mar 04, 2010 7:51 am    Post subject: Reply with quote

how would you go about using a shortcut to make a window remain within all desktops
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3
Page 3 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group