refurbished 'Monitor.ahk'
This commit is contained in:
parent
eb27dc22dd
commit
a1ace64721
1 changed files with 109 additions and 55 deletions
164
src/Monitor.ahk
164
src/Monitor.ahk
|
@ -18,20 +18,24 @@
|
|||
@version 8.3.0
|
||||
*/
|
||||
|
||||
Monitor_init(m) {
|
||||
Monitor_init(m)
|
||||
{
|
||||
Global
|
||||
|
||||
Monitor_#%m%_aView_#1 := 1
|
||||
Monitor_#%m%_aView_#2 := 1
|
||||
Monitor_#%m%_showBar := Config_showBar
|
||||
Loop, % Config_viewCount
|
||||
Loop, % Config_viewCount
|
||||
{
|
||||
View_init(m, A_Index)
|
||||
}
|
||||
Config_restore("Monitor", m)
|
||||
Monitor_getWorkArea(m)
|
||||
Bar_init(m)
|
||||
}
|
||||
|
||||
Monitor_activateView(v) {
|
||||
Monitor_activateView(v)
|
||||
{
|
||||
Local aView, aWndClass, aWndId, aWndTitle, m, n, wndId, wndIds
|
||||
|
||||
If (v = -1)
|
||||
|
@ -42,18 +46,19 @@ Monitor_activateView(v) {
|
|||
v := Manager_loop(Monitor_#%Manager_aMonitor%_aView_#1, -1, 1, Config_viewCount)
|
||||
|
||||
Debug_logMessage("DEBUG[1] Monitor_activateView(" . v . ") Manager_aMonitor: " . Manager_aMonitor . "; wndIds: " . View_#%m%_#%aView%_wndIds, 1)
|
||||
|
||||
If (v <= 0) Or (v > Config_viewCount) Or Manager_hideShow
|
||||
Return
|
||||
; Re-arrange the windows on the view.
|
||||
If (v = Monitor_#%Manager_aMonitor%_aView_#1) {
|
||||
;; Re-arrange the windows on the active view.
|
||||
If (v = Monitor_#%Manager_aMonitor%_aView_#1)
|
||||
{
|
||||
View_arrange(Manager_aMonitor, v)
|
||||
Return
|
||||
}
|
||||
|
||||
aView := Monitor_#%Manager_aMonitor%_aView_#1
|
||||
WinGet, aWndId, ID, A
|
||||
If WinExist("ahk_id" aWndId) And InStr(View_#%Manager_aMonitor%_#%aView%_wndIds, aWndId ";") {
|
||||
If WinExist("ahk_id" aWndId) And InStr(View_#%Manager_aMonitor%_#%aView%_wndIds, aWndId ";")
|
||||
{
|
||||
WinGetClass, aWndClass, ahk_id %aWndId%
|
||||
WinGetTitle, aWndTitle, ahk_id %aWndId%
|
||||
If Not (aWndClass = "Progman") And Not (aWndClass = "AutoHotkeyGui" And SubStr(aWndTitle, 1, 10) = "bug.n_BAR_") And Not (aWndClass = "DesktopBackgroundClass")
|
||||
|
@ -65,32 +70,33 @@ Monitor_activateView(v) {
|
|||
n := Manager_monitorCount
|
||||
Else If (n < 1)
|
||||
n := 1
|
||||
Loop, % n {
|
||||
Loop, % n
|
||||
{
|
||||
If (n = 1)
|
||||
m := Manager_aMonitor
|
||||
Else
|
||||
m := A_Index
|
||||
|
||||
Monitor_#%m%_aView_#2 := aView
|
||||
Monitor_#%m%_aView_#1 := v
|
||||
|
||||
Monitor_#%m%_aView_#1 := v
|
||||
Manager_hideShow := True
|
||||
; Most of the operations here are dispersed to multiple _different_ windows.
|
||||
; Delays in this part of the code are extremely noticeable and the users
|
||||
; do a lot of view switching.
|
||||
SetWinDelay, 0
|
||||
StringTrimRight, wndIds, View_#%m%_#%aView%_wndIds, 1
|
||||
Loop, PARSE, wndIds, `;
|
||||
Loop, PARSE, wndIds, `;
|
||||
{
|
||||
If Not (Manager_#%A_LoopField%_tags & (1 << v - 1))
|
||||
Manager_winHide(A_LoopField)
|
||||
}
|
||||
SetWinDelay, 10
|
||||
DetectHiddenWindows, On
|
||||
View_arrange(m, v)
|
||||
DetectHiddenWindows, Off
|
||||
StringTrimRight, wndIds, View_#%m%_#%v%_wndIds, 1
|
||||
SetWinDelay, 0
|
||||
Loop, PARSE, wndIds, `;
|
||||
Loop, PARSE, wndIds, `;
|
||||
{
|
||||
Manager_winShow(A_LoopField)
|
||||
}
|
||||
SetWinDelay, 10
|
||||
Manager_hideShow := False
|
||||
|
||||
|
@ -99,30 +105,38 @@ Monitor_activateView(v) {
|
|||
}
|
||||
|
||||
wndId := View_#%Manager_aMonitor%_#%v%_aWndId
|
||||
If Not (wndId And WinExist("ahk_id" wndId)) {
|
||||
If View_#%Manager_aMonitor%_#%v%_wndIds {
|
||||
If Not (wndId And WinExist("ahk_id" wndId))
|
||||
{
|
||||
If View_#%Manager_aMonitor%_#%v%_wndIds
|
||||
{
|
||||
wndId := SubStr(View_#%Manager_aMonitor%_#%v%_wndIds, 1, InStr(View_#%Manager_aMonitor%_#%v%_wndIds, ";")-1)
|
||||
View_#%Manager_aMonitor%_#%v%_aWndId := wndId
|
||||
} Else
|
||||
}
|
||||
Else
|
||||
wndId := 0
|
||||
}
|
||||
Manager_winActivate(wndId)
|
||||
}
|
||||
|
||||
Monitor_get(x, y) {
|
||||
Monitor_get(x, y)
|
||||
{
|
||||
Local m
|
||||
|
||||
m := 0
|
||||
Loop, % Manager_monitorCount ; Check if the window is on this monitor.
|
||||
If (x >= Monitor_#%A_Index%_x && x <= Monitor_#%A_Index%_x+Monitor_#%A_Index%_width && y >= Monitor_#%A_Index%_y && y <= Monitor_#%A_Index%_y+Monitor_#%A_Index%_height) {
|
||||
Loop, % Manager_monitorCount
|
||||
{ ;; Check if the window is on this monitor.
|
||||
If (x >= Monitor_#%A_Index%_x && x <= Monitor_#%A_Index%_x+Monitor_#%A_Index%_width && y >= Monitor_#%A_Index%_y && y <= Monitor_#%A_Index%_y+Monitor_#%A_Index%_height)
|
||||
{
|
||||
m := A_Index
|
||||
Break
|
||||
}
|
||||
}
|
||||
|
||||
Return, m
|
||||
}
|
||||
|
||||
Monitor_getWorkArea(m) {
|
||||
Monitor_getWorkArea(m)
|
||||
{
|
||||
Local bTop, x, y
|
||||
Local monitor, monitorBottom, monitorLeft, monitorRight, monitorTop
|
||||
Local wndClasses, wndHeight, wndId, wndWidth, wndX, wndY
|
||||
|
@ -135,29 +149,40 @@ Monitor_getWorkArea(m) {
|
|||
Loop, PARSE, wndClasses, `;
|
||||
{
|
||||
wndId := WinExist("ahk_class " A_LoopField)
|
||||
If wndId {
|
||||
If wndId
|
||||
{
|
||||
WinGetPos, wndX, wndY, wndWidth, wndHeight, ahk_id %wndId%
|
||||
x := wndX + wndWidth / 2
|
||||
y := wndY + wndHeight / 2
|
||||
If (x >= monitorLeft && x <= monitorRight && y >= monitorTop && y <= monitorBottom) {
|
||||
If (x >= monitorLeft && x <= monitorRight && y >= monitorTop && y <= monitorBottom)
|
||||
{
|
||||
If (A_LoopField = "Shell_TrayWnd")
|
||||
Manager_taskBarMonitor := m
|
||||
|
||||
If (wndHeight < wndWidth) { ; Horizontal
|
||||
If (wndY <= monitorTop) { ; Top
|
||||
If (wndHeight < wndWidth)
|
||||
{ ;; Horizontal
|
||||
If (wndY <= monitorTop)
|
||||
{ ;; Top
|
||||
wndHeight += wndY - monitorTop
|
||||
monitorTop += wndHeight
|
||||
If (A_LoopField = "Shell_TrayWnd")
|
||||
Manager_taskBarPos := "top"
|
||||
} Else { ; Bottom
|
||||
}
|
||||
Else
|
||||
{ ;; Bottom
|
||||
wndHeight := monitorBottom - wndY
|
||||
monitorBottom -= wndHeight
|
||||
}
|
||||
} Else { ; Vertical
|
||||
If (wndX <= monitorLeft) { ; Left
|
||||
}
|
||||
Else
|
||||
{ ;; Vertical
|
||||
If (wndX <= monitorLeft)
|
||||
{ ;; Left
|
||||
wndWidth += wndX
|
||||
monitorLeft += wndWidth
|
||||
} Else { ; Right
|
||||
}
|
||||
Else
|
||||
{ ;; Right
|
||||
wndWidth := monitorRight - wndX
|
||||
monitorRight -= wndWidth
|
||||
}
|
||||
|
@ -166,11 +191,15 @@ Monitor_getWorkArea(m) {
|
|||
}
|
||||
}
|
||||
bTop := 0
|
||||
If Monitor_#%m%_showBar {
|
||||
If (Config_verticalBarPos = "top" Or (Config_verticalBarPos = "tray" And Not m = Manager_taskBarMonitor)) {
|
||||
If Monitor_#%m%_showBar
|
||||
{
|
||||
If (Config_verticalBarPos = "top" Or (Config_verticalBarPos = "tray" And Not m = Manager_taskBarMonitor))
|
||||
{
|
||||
bTop := monitorTop
|
||||
monitorTop += Bar_height
|
||||
} Else If (Config_verticalBarPos = "bottom") {
|
||||
}
|
||||
Else If (Config_verticalBarPos = "bottom")
|
||||
{
|
||||
bTop := monitorBottom - Bar_height
|
||||
monitorBottom -= Bar_height
|
||||
}
|
||||
|
@ -185,7 +214,6 @@ Monitor_getWorkArea(m) {
|
|||
|
||||
Monitor_moveWindow(m, wndId)
|
||||
{
|
||||
Global
|
||||
Local fX, fY, monitor, wndHeight, wndWidth, wndX, wndY
|
||||
|
||||
Manager_#%wndId%_monitor := m
|
||||
|
@ -205,7 +233,8 @@ Monitor_moveWindow(m, wndId)
|
|||
}
|
||||
}
|
||||
|
||||
Monitor_setWindowTag(t) {
|
||||
Monitor_setWindowTag(t)
|
||||
{
|
||||
Local aView, aWndId, wndId
|
||||
|
||||
If (t = ">")
|
||||
|
@ -214,22 +243,32 @@ Monitor_setWindowTag(t) {
|
|||
t := Manager_loop(Monitor_#%Manager_aMonitor%_aView_#1, -1, 1, Config_viewCount)
|
||||
|
||||
WinGet, aWndId, ID, A
|
||||
If (InStr(Manager_managedWndIds, aWndId ";") And t >= 0 And t <= Config_viewCount) {
|
||||
If (t = 0) {
|
||||
Loop, % Config_viewCount
|
||||
If Not (Manager_#%aWndId%_tags & (1 << A_Index - 1)) {
|
||||
If (InStr(Manager_managedWndIds, aWndId ";") And t >= 0 And t <= Config_viewCount)
|
||||
{
|
||||
If (t = 0)
|
||||
{
|
||||
Loop, % Config_viewCount
|
||||
{
|
||||
If Not (Manager_#%aWndId%_tags & (1 << A_Index - 1))
|
||||
{
|
||||
View_#%Manager_aMonitor%_#%A_Index%_wndIds := aWndId ";" View_#%Manager_aMonitor%_#%A_Index%_wndIds
|
||||
View_#%Manager_aMonitor%_#%A_Index%_aWndId := aWndId
|
||||
Bar_updateView(Manager_aMonitor, A_Index)
|
||||
Manager_#%aWndId%_tags += 1 << A_Index - 1
|
||||
}
|
||||
} Else {
|
||||
Loop, % Config_viewCount
|
||||
If Not (A_index = t) {
|
||||
}
|
||||
}
|
||||
Else
|
||||
{
|
||||
Loop, % Config_viewCount
|
||||
{
|
||||
If Not (A_index = t)
|
||||
{
|
||||
StringReplace, View_#%Manager_aMonitor%_#%A_Index%_wndIds, View_#%Manager_aMonitor%_#%A_Index%_wndIds, %aWndId%`;,
|
||||
View_#%Manager_aMonitor%_#%A_Index%_aWndId := 0
|
||||
Bar_updateView(Manager_aMonitor, A_Index)
|
||||
}
|
||||
}
|
||||
|
||||
If Not (Manager_#%aWndId%_tags & (1 << t - 1))
|
||||
View_#%Manager_aMonitor%_#%t%_wndIds := aWndId ";" View_#%Manager_aMonitor%_#%t%_wndIds
|
||||
|
@ -237,14 +276,16 @@ Monitor_setWindowTag(t) {
|
|||
Manager_#%aWndId%_tags := 1 << t - 1
|
||||
|
||||
aView := Monitor_#%Manager_aMonitor%_aView_#1
|
||||
If Not (t = aView) {
|
||||
If Not (t = aView)
|
||||
{
|
||||
Manager_hideShow := True
|
||||
wndId := SubStr(View_#%Manager_aMonitor%_#%aView%_wndIds, 1, InStr(View_#%Manager_aMonitor%_#%aView%_wndIds, ";")-1)
|
||||
Manager_winActivate(wndId)
|
||||
Manager_hideShow := False
|
||||
If Config_viewFollowsTagged
|
||||
Monitor_activateView(t)
|
||||
Else {
|
||||
Else
|
||||
{
|
||||
Manager_hideShow := True
|
||||
Manager_winHide(aWndId)
|
||||
Manager_hideShow := False
|
||||
|
@ -256,7 +297,8 @@ Monitor_setWindowTag(t) {
|
|||
}
|
||||
}
|
||||
|
||||
Monitor_toggleBar() {
|
||||
Monitor_toggleBar()
|
||||
{
|
||||
Global
|
||||
|
||||
Monitor_#%Manager_aMonitor%_showBar := Not Monitor_#%Manager_aMonitor%_showBar
|
||||
|
@ -266,17 +308,22 @@ Monitor_toggleBar() {
|
|||
Manager_winActivate(Bar_aWndId)
|
||||
}
|
||||
|
||||
Monitor_toggleTaskBar() {
|
||||
Monitor_toggleTaskBar()
|
||||
{
|
||||
Local m
|
||||
|
||||
m := Manager_aMonitor
|
||||
If (m = Manager_taskBarMonitor) {
|
||||
If (m = Manager_taskBarMonitor)
|
||||
{
|
||||
Manager_showTaskBar := Not Manager_showTaskBar
|
||||
Manager_hideShow := True
|
||||
If Not Manager_showTaskBar {
|
||||
If Not Manager_showTaskBar
|
||||
{
|
||||
WinHide, Start ahk_class Button
|
||||
WinHide, ahk_class Shell_TrayWnd
|
||||
} Else {
|
||||
}
|
||||
Else
|
||||
{
|
||||
WinShow, Start ahk_class Button
|
||||
WinShow, ahk_class Shell_TrayWnd
|
||||
}
|
||||
|
@ -287,17 +334,22 @@ Monitor_toggleTaskBar() {
|
|||
}
|
||||
}
|
||||
|
||||
Monitor_toggleWindowTag(t) {
|
||||
Monitor_toggleWindowTag(t)
|
||||
{
|
||||
Local aWndId, wndId
|
||||
|
||||
WinGet, aWndId, ID, A
|
||||
If (InStr(Manager_managedWndIds, aWndId ";") And t >= 0 And t <= Config_viewCount) {
|
||||
If (Manager_#%aWndId%_tags & (1 << t - 1)) {
|
||||
If Not ((Manager_#%aWndId%_tags - (1 << t - 1)) = 0) {
|
||||
If (InStr(Manager_managedWndIds, aWndId ";") And t >= 0 And t <= Config_viewCount)
|
||||
{
|
||||
If (Manager_#%aWndId%_tags & (1 << t - 1))
|
||||
{
|
||||
If Not ((Manager_#%aWndId%_tags - (1 << t - 1)) = 0)
|
||||
{
|
||||
Manager_#%aWndId%_tags -= 1 << t - 1
|
||||
StringReplace, View_#%Manager_aMonitor%_#%t%_wndIds, View_#%Manager_aMonitor%_#%t%_wndIds, %aWndId%`;,
|
||||
Bar_updateView(Manager_aMonitor, t)
|
||||
If (t = Monitor_#%Manager_aMonitor%_aView_#1) {
|
||||
If (t = Monitor_#%Manager_aMonitor%_aView_#1)
|
||||
{
|
||||
Manager_hideShow := True
|
||||
Manager_winHide(aWndId)
|
||||
Manager_hideShow := False
|
||||
|
@ -306,7 +358,9 @@ Monitor_toggleWindowTag(t) {
|
|||
View_arrange(Manager_aMonitor, t)
|
||||
}
|
||||
}
|
||||
} Else {
|
||||
}
|
||||
Else
|
||||
{
|
||||
View_#%Manager_aMonitor%_#%t%_wndIds := aWndId ";" View_#%Manager_aMonitor%_#%t%_wndIds
|
||||
View_#%Manager_aMonitor%_#%t%_aWndId := aWndId
|
||||
Bar_updateView(Manager_aMonitor, t)
|
||||
|
|
Loading…
Reference in a new issue