; Hide-and-Drop ; (c) Pierre Dragicevic ; http://liihs.irit.fr/dragice/foldndrop ; ; This script requires WinBatch to run (http://www.winbatch.com/download.html) #DefineFunction IsMouseOutSide(win) if !WinExist(win) then return @TRUE xy=MouseInfo(2) x=ItemExtract(1,xy," ") y=ItemExtract(2,xy," ") winbox = WinPlaceGet(@NORMAL, win) wx = ItemExtract(1,winbox," ")+1 wy = ItemExtract(2,winbox," ")+1 wx2 = ItemExtract(3,winbox," ")+1 wy2 = ItemExtract(4,winbox," ")+1 Return !(x>=wx && x<=wx2 && y>=wy && y<=wy2) #EndFunction #DefineFunction WhileMousePressed() buttons = MouseInfo(4) while buttons != 0 TimeDelay(0) buttons = MouseInfo(4) endwhile #EndFunction #DefineFunction WhileMouseReleased() buttons = MouseInfo(4) while buttons == 0 TimeDelay(0) buttons = MouseInfo(4) endwhile return buttons #EndFunction #DefineFunction MoveWindowAway(win, amount) if !WinExist(win) then return "0, 0, @NORESIZE, @NORESIZE" xy=MouseInfo(2) x=ItemExtract(1,xy," ") y=ItemExtract(2,xy," ") winbox = WinPlaceGet(@NORMAL, win) wx = ItemExtract(1,winbox," ")+1 wy = ItemExtract(2,winbox," ")+1 wx2 = ItemExtract(3,winbox," ")+1 wy2 = ItemExtract(4,winbox," ")+1 d0 = abs(x-wx) d1 = abs(x-wx2) d2 = abs(y-wy) d3 = abs(y-wy2) dmin = min(d0, d1, d2, d3) Switch dmin case d0 ; Move to the right WinPlace(wx+amount, wy+amount*0.5*(d3-d2)/(wy2-wy), @NORESIZE, @NORESIZE, win) break case d1 ; Move to the left WinPlace(wx-amount, wy+amount*0.5*(d3-d2)/(wy2-wy), @NORESIZE, @NORESIZE, win) break case d2 ; Move to the bottom WinPlace(wx+amount*0.5*(d1-d0)/(wx2-wx), wy+amount, @NORESIZE, @NORESIZE, win) break case dmin ; Move to the top WinPlace(wx+amount*0.5*(d1-d0)/(wx2-wx), wy-amount, @NORESIZE, @NORESIZE, win) break EndSwitch Return "%wx%, %wy%, @NORESIZE, @NORESIZE" #EndFunction #DefineFunction IsBehind(win2, win1) if (win1 == win2) then return @FALSE winorder_count = 0 allwins = WinItemize() w = " " i = 0 while w!="" && w!=win1 && w!=win2 i = i + 1 w = ItemExtract(i, allwins, @TAB) endwhile return w==win1 #EndFunction Display(4, "", strcat("Hide n' Drop Launched.", @CRLF, @CRLF, "(to quit, right-click on the WinBatch task)")) hiddenWins = "" oldWinsPos = "" :reset TimeDelay(0) ; redisplay hidden windows i = 0 w = " " p = " " while w!="" i = i + 1 w = ItemExtract(i, hiddenWins, @TAB) p = ItemExtract(i, oldWinsPos, @TAB) if (w != "" && WinExist(w)) then WinPlace(%p%, w) WinShow(w) endif endwhile hiddenWins = "" ; wait button press buttons = WhileMouseReleased() :restart start_win = MouseInfo(1) ;if start_win == "Program Manager" then Goto restart ;if WinState(start_win) != @NORMAL then Goto restart cur_win = start_win old_curwin = cur_win :restart_immediately start_winbox = WinPlaceGet(@NORMAL, start_win) ; wait picking another window or mouse release while buttons != 0 && cur_win == start_win yield() buttons = MouseInfo(4) cur_win = MouseInfo(1) endwhile if buttons == 0 then Goto reset if !WinExist(cur_win) then Goto restart ; Don't handle menu mouse-enter if !IsBehind(cur_win, start_win) then Goto restart ; Don't handle drags to toplevel windows if WinPlaceGet(@NORMAL, start_win) != start_winbox then ; Ignore all if windows has changed position or has been resized WhileMousePressed() goto reset endif ; move window amount = 10 oldWinPos = MoveWindowAway(start_win, amount) ;st = WinState(start_win) ;Display(2, "", "WIN STATE [%st%]") count=0 next_win = cur_win while buttons != 0 && next_win == cur_win && count < 3 TimeDelay(0) amount = amount * 0.3 MoveWindowAway(start_win, amount) count = count+1 buttons = MouseInfo(4) next_win = MouseInfo(1) endwhile if buttons == 0 then ; move window to its original place WinPlace(%oldWinPos%, start_win) Goto reset endif if count >= 5 then ; move window to its original place WinPlace(%oldWinPos%, start_win) Goto restart endif if next_win != start_win then ; move window to its original place WinPlace(%oldWinPos%, start_win) start_win = cur_win cur_win = next_win Goto restart_immediately endif ; Hide window and add to buffer ; move window to its original place ;WinPlace(%oldWinPos%, start_win) WinHide(start_win) if (hiddenWins == "") then hiddenWins = start_win oldWinsPos = oldWinPos else hiddenWins = strcat(start_win, @TAB, hiddenWins) oldWinsPos = strcat(oldWinPos, @TAB, oldWinsPos) endif Goto restart