From ef47899c5dca89cbd39d0c114200d10087d7eade Mon Sep 17 00:00:00 2001 From: Joshua Fuhs Date: Sun, 24 Jun 2012 18:04:41 -0400 Subject: [PATCH] Initialize monitors a little more intelligently by associating currently opened windows with the monitor on which they appear. --- src/Main.ahk | 1 + src/Manager.ahk | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/Main.ahk b/src/Main.ahk index c854fb4..3487259 100644 --- a/src/Main.ahk +++ b/src/Main.ahk @@ -133,6 +133,7 @@ Main_toggleBar: Return #Include Log.ahk +#Include List.ahk #Include Bar.ahk #Include Config.ahk #Include Manager.ahk diff --git a/src/Manager.ahk b/src/Manager.ahk index 0530b96..beb465d 100644 --- a/src/Manager.ahk +++ b/src/Manager.ahk @@ -57,7 +57,7 @@ Manager_init() { Bar_hideTitleWndIds := "" Manager_allWndIds := "" Manager_managedWndIds := "" - Manager_sync() + Manager_initial_sync() Bar_updateStatus() Bar_updateTitle() @@ -601,6 +601,46 @@ Manager_sync(ByRef wndIds = "") { Return, a } +; No windows are known to the system yet. +; Try to do something smart with the initial layout. +Manager_initial_sync() { + Local wndId0, wnd, wndX, wndY, wndW, wndH, x, y, m, len + + ; Initialize lists + ; Note that these variables make this function non-reentrant. + Loop, % Manager_monitorCount + Manager_initial_sync_m#%A_Index%_wndList := List_new() + + ; check all visible windows against the known windows + WinGet, wndId, List, , , + Loop, % wndId { + ; Based on some analysis here, determine which monitors and layouts would best + ; serve existing windows. Do not override configuration settings. + + ; Which monitor is it on? + + wnd := wndId%A_Index% + WinGetPos, wndX, wndY, wndW, wndH, ahk_id %wnd% + + x := wndX + wndW/2 + y := wndY + wndH/2 + + m := Monitor_get(x, y) + If m > 0 + List_append(Manager_initial_sync_m#%m%_wndList, wndId%A_index%) + + ; @todo: What percentage of the monitor area is it occupying? (Suggest layout) + ; @todo: What part of the monitor is it on? (Ordering of windows) + } + + Loop, % Manager_monitorCount { + m := A_Index + len := List_toArray(Manager_initial_sync_m#%m%_wndList, "Manager_initial_sync_tmpArray") + Loop, % len + Manager_manage(m, 1, Manager_initial_sync_tmpArray%A_Index%) + } +} + Manager_toggleDecor() { Local aWndId