Revised Manager_resetMonitorConfiguration() ...

... possibly fixing issue #66
+ replaced Monitor_moveWindow with its one-line-content
+ fixed some naming issues of variables
This commit is contained in:
joten 2016-01-04 20:55:18 +01:00
parent 245608b1af
commit 80b6b8163c
3 changed files with 95 additions and 30 deletions

View file

@ -308,7 +308,7 @@ Manager__setWinProperties(wndId, isManaged, m, tags, isDecorated, isFloating, hi
If Not InStr(Manager_managedWndIds, wndId ";") If Not InStr(Manager_managedWndIds, wndId ";")
Manager_managedWndIds .= wndId ";" Manager_managedWndIds .= wndId ";"
Monitor_moveWindow(m, wndId) Window_#%wndId%_monitor := m
Window_#%wndId%_tags := tags Window_#%wndId%_tags := tags
Window_#%wndId%_isDecorated := isDecorated Window_#%wndId%_isDecorated := isDecorated
Window_#%wndId%_isFloating := isFloating Window_#%wndId%_isFloating := isFloating
@ -659,43 +659,55 @@ Manager_registerShellHook() {
;; SKAN: How to Hook on to Shell to receive its messages? (http://www.autohotkey.com/forum/viewtopic.php?p=123323#123323) ;; SKAN: How to Hook on to Shell to receive its messages? (http://www.autohotkey.com/forum/viewtopic.php?p=123323#123323)
Manager_resetMonitorConfiguration() { Manager_resetMonitorConfiguration() {
Local GuiN, hWnd, i, m, wndClass, wndIds, wndTitle Local GuiN, hWnd, i, j, m, mPrimary, wndClass, wndIds, wndTitle
m := Manager_monitorCount m := Manager_monitorCount
SysGet, Manager_monitorCount, MonitorCount SysGet, Manager_monitorCount, MonitorCount
If (Manager_monitorCount < m) { If (Manager_monitorCount < m) {
Loop, % m - Manager_monitorCount { ;; A monitor has been disconnected. Which one?
i := Manager_monitorCount + A_Index i := Monitor_find(-1, m)
GuiN := (i - 1) + 1 If (i > 0) {
SysGet, mPrimary, MonitorPrimary
GuiN := (m - 1) + 1
Gui, %GuiN%: Destroy Gui, %GuiN%: Destroy
Loop, % Config_viewCount { Loop, % Config_viewCount {
If View_#%i%_#%A_Index%_wndIds { If View_#%i%_#%A_Index%_wndIds {
View_#1_#%A_Index%_wndIds := View_#%i%_#%A_Index%_wndIds View_#1_#%A_Index%_wndIds View_#%mPrimary%_#%A_Index%_wndIds .= View_#%i%_#%A_Index%_wndIds
StringTrimRight, wndIds, View_#%i%_#%A_Index%_wndIds, 1 StringTrimRight, wndIds, View_#%i%_#%A_Index%_wndIds, 1
Loop, PARSE, wndIds, `; Loop, PARSE, wndIds, `;
{ {
Loop, % Config_viewCount { Window_#%A_LoopField%_monitor := mPrimary
StringReplace, View_#%i%_#%A_Index%_wndIds, View_#%i%_#%A_Index%_wndIds, %A_LoopField%`;,
View_setActiveWindow(i, A_Index, 0)
} }
Monitor_moveWindow(1, A_LoopField) If (Manager_aMonitor = i)
} Manager_aMonitor := mPrimary
;; Manually set the active monitor.
Manager_aMonitor := 1
} }
} }
Loop, % m - i {
j := i + A_Index
Monitor_moveToIndex(j, j - 1)
Monitor_getWorkArea(j - 1)
Bar_init(j - 1)
}
} }
m := Manager_monitorCount
} Else If (Manager_monitorCount > m) { } Else If (Manager_monitorCount > m) {
Loop, % Manager_monitorCount - m ;; A monitor has been connected. Where has it been put?
Monitor_init(m + A_Index, True) i := Monitor_find(+1, Manager_monitorCount)
If (i > 0) {
Loop, % Manager_monitorCount - i {
j := Manager_monitorCount - A_Index
Monitor_moveToIndex(j, j + 1)
Monitor_getWorkArea(j + 1)
Bar_init(j + 1)
} }
Loop, % m { Monitor_init(i, True)
}
} Else {
;; Has the resolution of a monitor been changed?
Loop, % Manager_monitorCount {
Monitor_getWorkArea(A_Index) Monitor_getWorkArea(A_Index)
Bar_init(A_Index) Bar_init(A_Index)
} }
}
Manager_saveState() Manager_saveState()
Loop, % Manager_monitorCount { Loop, % Manager_monitorCount {
View_arrange(A_Index, Monitor_#%A_Index%_aView_#1) View_arrange(A_Index, Monitor_#%A_Index%_aView_#1)
@ -953,8 +965,7 @@ Manager_setViewMonitor(i, d = 0) {
StringReplace, View_#%Manager_aMonitor%_#%A_Index%_wndIds, View_#%Manager_aMonitor%_#%A_Index%_wndIds, %A_LoopField%`;, StringReplace, View_#%Manager_aMonitor%_#%A_Index%_wndIds, View_#%Manager_aMonitor%_#%A_Index%_wndIds, %A_LoopField%`;,
View_setActiveWindow(Manager_aMonitor, A_Index, 0) View_setActiveWindow(Manager_aMonitor, A_Index, 0)
} }
Window_#%A_LoopField%_monitor := i
Monitor_moveWindow(i, A_LoopField)
Window_#%A_LoopField%_tags := 1 << v - 1 Window_#%A_LoopField%_tags := 1 << v - 1
} }
View_arrange(Manager_aMonitor, aView) View_arrange(Manager_aMonitor, aView)
@ -1015,7 +1026,7 @@ Manager_setWindowMonitor(i, d = 0) {
If (i = 0) If (i = 0)
i := Manager_aMonitor i := Manager_aMonitor
Manager_aMonitor := Manager_loop(i, d, 1, Manager_monitorCount) Manager_aMonitor := Manager_loop(i, d, 1, Manager_monitorCount)
Monitor_moveWindow(Manager_aMonitor, aWndId) Window_#%aWndId%_monitor := Manager_aMonitor
v := Monitor_#%Manager_aMonitor%_aView_#1 v := Monitor_#%Manager_aMonitor%_aView_#1
Window_#%aWndId%_tags := 1 << v - 1 Window_#%aWndId%_tags := 1 << v - 1
View_#%Manager_aMonitor%_#%v%_wndIds := aWndId ";" View_#%Manager_aMonitor%_#%v%_wndIds View_#%Manager_aMonitor%_#%v%_wndIds := aWndId ";" View_#%Manager_aMonitor%_#%v%_wndIds

View file

@ -21,13 +21,14 @@ Monitor_init(m, doRestore) {
Monitor_#%m%_showBar := Config_showBar Monitor_#%m%_showBar := Config_showBar
Monitor_#%m%_showTaskBar := Config_showTaskBar Monitor_#%m%_showTaskBar := Config_showTaskBar
Monitor_#%m%_taskBarClass := "" Monitor_#%m%_taskBarClass := ""
Monitor_%m%_taskBarPos := "" Monitor_#%m%_taskBarPos := ""
Loop, % Config_viewCount Loop, % Config_viewCount
View_init(m, A_Index) View_init(m, A_Index)
If doRestore If doRestore
Config_restoreLayout(Main_autoLayout, m) Config_restoreLayout(Main_autoLayout, m)
Else Else
Config_restoreLayout(Config_filePath, m) Config_restoreLayout(Config_filePath, m)
SysGet, Monitor_#%m%_name, MonitorName, %m%
Monitor_getWorkArea(m) Monitor_getWorkArea(m)
Bar_init(m) Bar_init(m)
} }
@ -102,6 +103,19 @@ Monitor_activateView(i, d = 0) {
Manager_winActivate(wndId) Manager_winActivate(wndId)
} }
Monitor_find(d, n) {
Local mName
If (d < 0 Or d > 0) {
Loop, % n {
SysGet, mName, MonitorName, %A_Index%
If Not (mName = Monitor_#%A_Index%_name)
Return, A_Index
}
}
Return, 0
}
Monitor_get(x, y) Monitor_get(x, y)
{ {
Local m Local m
@ -148,7 +162,7 @@ Monitor_getWorkArea(m) {
wndHeight += wndY - monitorTop wndHeight += wndY - monitorTop
monitorTop += wndHeight monitorTop += wndHeight
If (A_LoopField = "Shell_TrayWnd") Or (A_LoopField = "Shell_SecondaryTrayWnd") If (A_LoopField = "Shell_TrayWnd") Or (A_LoopField = "Shell_SecondaryTrayWnd")
Monitor_%m%_taskBarPos := "top" Monitor_#%m%_taskBarPos := "top"
} Else { } Else {
;; Bottom ;; Bottom
wndHeight := monitorBottom - wndY wndHeight := monitorBottom - wndY
@ -190,11 +204,23 @@ Monitor_getWorkArea(m) {
Monitor_setWorkArea(monitorLeft, monitorTop, monitorRight, monitorBottom) Monitor_setWorkArea(monitorLeft, monitorTop, monitorRight, monitorBottom)
} }
Monitor_moveWindow(m, wndId) Monitor_moveToIndex(m, n) {
{
Global Global
Window_#%wndId%_monitor := m Monitor_#%n%_aView_#1 := Monitor_#%m%_aView_#1
Monitor_#%n%_aView_#2 := Monitor_#%m%_aView_#2
Monitor_#%n%_name := Monitor_#%m%_name
Monitor_#%n%_showBar := Monitor_#%m%_showBar
Monitor_#%n%_showTaskBar := Monitor_#%m%_showTaskBar
Monitor_#%n%_taskBarClass := Monitor_#%m%_taskBarClass
Monitor_#%n%_taskBarPos := Monitor_#%m%_taskBarPos
Monitor_#%n%_height := Monitor_#%m%_height
Monitor_#%n%_width := Monitor_#%m%_width
Monitor_#%n%_x := Monitor_#%m%_x
Monitor_#%n%_y := Monitor_#%m%_y
Monitor_#%n%_barY := Monitor_#%m%_barY
Loop, % Config_viewCount
View_moveToIndex(m, A_Index, n, A_Index)
} }
Monitor_setWindowTag(i, d = 0) { Monitor_setWindowTag(i, d = 0) {

View file

@ -203,6 +203,34 @@ View_ghostWindow(m, v, bodyWndId, ghostWndId)
StringReplace, View_#%m%_#%v%_wndIds, View_#%m%_#%v%_wndIds, %search%, %replace% StringReplace, View_#%m%_#%v%_wndIds, View_#%m%_#%v%_wndIds, %search%, %replace%
} }
View_moveToIndex(m, v, n, w) {
Local wndIds
View_#%n%_#%w%_area_#0 := View_#%m%_#%v%_area_#0
View_#%n%_#%w%_aWndIds := View_#%m%_#%v%_aWndIds
View_#%n%_#%w%_layout_#1 := View_#%m%_#%v%_layout_#1
View_#%n%_#%w%_layout_#2 := View_#%m%_#%v%_layout_#2
View_#%n%_#%w%_layoutAxis_#1 := View_#%m%_#%v%_layoutAxis_#1
View_#%n%_#%w%_layoutAxis_#2 := View_#%m%_#%v%_layoutAxis_#2
View_#%n%_#%w%_layoutAxis_#3 := View_#%m%_#%v%_layoutAxis_#3
View_#%n%_#%w%_layoutGapWidth := View_#%m%_#%v%_layoutGapWidth
View_#%n%_#%w%_layoutMFact := View_#%m%_#%v%_layoutMFact
View_#%n%_#%w%_layoutMX := View_#%m%_#%v%_layoutMX
View_#%n%_#%w%_layoutMY := View_#%m%_#%v%_layoutMY
View_#%n%_#%w%_layoutSymbol := View_#%m%_#%v%_layoutSymbol
View_#%n%_#%w%_margins := View_#%m%_#%v%_margins
View_#%n%_#%w%_showStackArea := View_#%m%_#%v%_showStackArea
View_#%n%_#%w%_wndIds := View_#%m%_#%v%_wndIds
StringSplit, View_#%n%_#%w%_margin, View_#%n%_#%w%_margin, `;
StringTrimRight, wndIds, View_#%n%_#%w%_wndIds, 1
Loop, PARSE, wndIds, `;
{
Window_#%A_LoopField%_monitor := n
Window_#%A_LoopField%_tags -= 1 << v - 1
Window_#%A_LoopField%_tags += 1 << w - 1
}
}
; @TODO: Theoretically, something is wrong here. From the hotkeys this should be manual tiling, but the function says otherwise. ; @TODO: Theoretically, something is wrong here. From the hotkeys this should be manual tiling, but the function says otherwise.
View_moveWindow(i=0, d=0) { View_moveWindow(i=0, d=0) {
Local aWndId, m, v Local aWndId, m, v