re-written and moved Log.ahk to Debug.ahk (to be extended)

This commit is contained in:
joten 2012-09-28 17:46:17 +02:00
parent aa7ddae698
commit 590017c0b0
8 changed files with 119 additions and 59 deletions

View File

@ -1,4 +1,4 @@
syntax: glob
src/Config.ini
src/Config_test.ini
01_administration.org
syntax: regexp
.*[cC]onfig.*\.ini

View File

@ -38,7 +38,7 @@ Bar_init(m) {
; Create the GUI window
wndTitle := "bug.n_BAR_" m
GuiN := (m - 1) + 1
Log_dbg_msg(6, "Bar_init(): Gui, " . GuiN . ": Default")
Debug_logMessage("DEBUG[6] Bar_init(): Gui, " . GuiN . ": Default", 6)
Gui, %GuiN%: Default
IfWinExist, %wndTitle%
Gui, Destroy
@ -364,9 +364,9 @@ Bar_evaluateCommand() {
Manager_activateMonitor(-1)
} Else If (Bar_command_#2 = "Log") {
If (Bar_command_#1 = "increment debug level")
Log_incDebugLevel()
Debug_setLogLevel(+1)
If (Bar_command_#1 = "decrement debug level")
Log_decDebugLevel()
Debug_setLogLevel(-1)
If (Bar_command_#1 = "log help info")
Manager_logHelp()
If (Bar_command_#1 = "log view window info")
@ -652,7 +652,7 @@ Bar_updateStatus() {
Loop, % Manager_monitorCount {
m := A_Index
GuiN := (m - 1) + 1
Log_dbg_msg(6, "Bar_updateStatus(): Gui, " . GuiN . ": Default")
Debug_logMessage("DEBUG[6] Bar_updateStatus(): Gui, " . GuiN . ": Default", 6)
Gui, %GuiN%: Default
If Config_readinBat {
Bar_getBatteryStatus(b1, b2)
@ -711,7 +711,7 @@ Bar_updateTitle(debugMsg = "") {
i := Config_viewCount + 2
Loop, % Manager_monitorCount {
GuiN := (A_Index - 1) + 1
Log_dbg_msg(6, "Bar_updateTitle(): Gui, " . GuiN . ": Default")
Debug_logMessage("DEBUG[6] Bar_updateTitle(): Gui, " . GuiN . ": Default", 6)
Gui, %GuiN%: Default
GuiControlGet, content, , Bar_#%A_Index%_#%i%
If (A_Index = Manager_aMonitor) {
@ -728,7 +728,7 @@ Bar_updateView(m, v) {
Local IdsLen, ViewIdsLen
GuiN := (m - 1) + 1
Log_dbg_msg(6, "Bar_updateView(): m: " . m . "; Gui, " . GuiN . ": Default")
Debug_logMessage("DEBUG[6] Bar_updateView(): m: " . m . "; Gui, " . GuiN . ": Default", 6)
Gui, %GuiN%: Default
IdsLen := StrLen(Manager_managedWndIds)

View File

@ -398,8 +398,8 @@ Config_saveSession() {
#^i::Manager_logViewWindowList() ; Dump window information for the active view.
#+^i::Manager_logManagedWindowList() ; Dump window information for every managed window.
#^h::Manager_logHelp() ; Dump to the log an explanation of some of the other more cryptic log messages.
#^[::Log_decDebugLevel() ; Decrement the log debug level.
#^]::Log_incDebugLevel() ; Increment the log debug level.
#^l::Debug_setLogLevel(-1) ; Decrement the log debug level.
#^+l::Debug_setLogLevel(+1) ; Increment the log debug level.
#Tab::View_setLayout(-1) ; Set the previously set layout. You may also use View_setLayout(">") for setting the next layout in the layout array.
#f::View_setLayout(3) ; Set the 3rd defined layout (i. e. floating layout in the default configuration).

63
src/Debug.ahk Normal file
View File

@ -0,0 +1,63 @@
/*
bug.n -- tiling window management
Copyright (c) 2010-2012 Joshua Fuhs, joten
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@version 8.3.0
*/
Debug_initLog(filename, level = 0, truncateFile = True)
{
Global Debug_logFilename, Debug_logLevel
Debug_logFilename := filename
Debug_logLevel := level
If truncateFile
If FileExist(Debug_logFilename)
FileDelete, %Debug_logFilename%
Debug_logMessage("Log initialized.", 0)
}
Debug_logMessage(text, level = 1, includeTimestamp = True)
{
Global Debug_logFilename, Debug_logLevel
If Debug_logLevel >= level
{
If includeTimestamp
{
FormatTime, time, , yyyy-MM-dd HH:mm:ss
text := time " " text
}
Else
text := " " text
FileAppend, %text%`r`n, %Debug_logFilename%
}
}
Debug_setLogLevel(d)
{
Global Debug_logLevel
i := Debug_logLevel + d
If i >= 0
{
Debug_logLevel := i
If i = 0
Debug_logMessage("Logging disabled.")
Else
Debug_logMessage("Log level set to " i ".")
}
}

View File

@ -36,8 +36,7 @@ SetWinDelay, 10
Main_dataDir = %1%
Else
Main_dataDir = %A_ScriptDir% ;; %A_ScriptDir% is the directory, in which 'Main.ahk' or the executable of bug.n is saved.
Log_init(Main_dataDir "\log.txt", False)
Log_msg("====== Initializing ======")
Debug_initLog(Main_dataDir "\log.txt", 0, False)
Config_filePath := Main_dataDir "\config.ini"
Config_init()
@ -57,11 +56,12 @@ Return ; end of the auto-execute section
* function & label definitions
*/
Main_cleanup: ; The labels with "ExitApp" or "Return" at the end and hotkeys have to be after the auto-execute section.
Log_msg("====== Cleaning up ======")
Debug_logMessage("Cleaning up", 0)
If Config_autoSaveSession
Config_saveSession()
Manager_cleanup()
DllCall("CloseHandle", "UInt", Bar_hDrive) ; used in Bar_getDiskLoad
Debug_logMessage("Exiting bug.n", 0)
ExitApp
Main_help:
@ -135,9 +135,9 @@ Main_toggleBar:
Monitor_toggleBar()
Return
#Include Log.ahk
#Include Bar.ahk
#Include Config.ahk
#Include Debug.ahk
#Include Manager.ahk
#Include Monitor.ahk
#Include View.ahk

View File

@ -283,18 +283,18 @@ Manager_logWindowInfo( w ) {
isResponsive := "*"
Log_bare(w . "`t" . isHidden . " " isWinFocus . " " . isBugnActive . " " . isFloating . " " . isDecorated . " " . isResponsive . " " . isGhost . " " . Manager_#%w%_monitor . "`t" . Manager_#%w%_tags . "`t" . wndX . "`t" . wndY . "`t" . wndW . "`t" . wndH . "`t" . wndStyle . "`t" . wndProc . " / " . wndClass . " / " . wndTitle)
Debug_logMessage(w . "`t" . isHidden . " " isWinFocus . " " . isBugnActive . " " . isFloating . " " . isDecorated . " " . isResponsive . " " . isGhost . " " . Manager_#%w%_monitor . "`t" . Manager_#%w%_tags . "`t" . wndX . "`t" . wndY . "`t" . wndW . "`t" . wndH . "`t" . wndStyle . "`t" . wndProc . " / " . wndClass . " / " . wndTitle, 0, False)
}
Manager_logHeader() {
Log_bare( "ID`t`tH W A F D R G M`tTags`tX`tY`tW`tH`tStyle`t`tProc / Class / Title")
Debug_logMessage( "ID`t`tH W A F D R G M`tTags`tX`tY`tW`tH`tStyle`t`tProc / Class / Title", 0, False)
}
Manager_logViewWindowList() {
Local text, v, aWndId, wndIds, aWndTitle
v := Monitor_#%Manager_aMonitor%_aView_#1
Log_msg( "Window dump for active view (" . Manager_aMonitor . ", " . v . ")" )
Debug_logMessage( "Window dump for active view (" . Manager_aMonitor . ", " . v . ")" )
Manager_logHeader()
StringTrimRight, wndIds, View_#%Manager_aMonitor%_#%v%_wndIds, 1
@ -307,7 +307,7 @@ Manager_logViewWindowList() {
Manager_logManagedWindowList() {
Local wndIds
Log_msg( "Window dump for manager" )
Debug_logMessage( "Window dump for manager" )
Manager_logHeader()
StringTrimRight, wndIds, Manager_managedWndIds, 1
@ -318,24 +318,24 @@ Manager_logManagedWindowList() {
}
Manager_logHelp() {
Log_msg("Help Display")
Log_bare("Window list columns")
Log_bare(" ID - Windows ID. Unique, OS-assigned ID")
Log_bare(" H - Hidden. Whether bug.n thinks this window is hidden.")
Log_bare(" W - Windows active. This window is active according to Windows.")
Log_bare(" A - View active. This window is active according to bug.n.")
Log_bare(" F - Floating. This window should not be positioned and resized by the layout.")
Log_bare(" D - Decorated. Does the window have a title bar?")
Log_bare(" R - Responsive. Is responding to messages?")
Log_bare(" G - Ghost. Is this window a ghost of another hung window?")
Log_bare(" M - Monitor number.")
Log_bare(" Tags - Bit-mask of the views in which the window is active.")
Log_bare(" X - Windows X position.")
Log_bare(" Y - Windows Y position.")
Log_bare(" W - Windows width.")
Log_bare(" H - Windows height.")
Log_bare(" Style - Windows style.")
Log_bare(" Proc / Class / Title - Process/Class/Title of the window.")
Debug_logMessage("Help Display")
Debug_logMessage("Window list columns", 0)
Debug_logMessage(" ID - Windows ID. Unique, OS-assigned ID", 0)
Debug_logMessage(" H - Hidden. Whether bug.n thinks this window is hidden.", 0)
Debug_logMessage(" W - Windows active. This window is active according to Windows.", 0)
Debug_logMessage(" A - View active. This window is active according to bug.n.", 0)
Debug_logMessage(" F - Floating. This window should not be positioned and resized by the layout.", 0)
Debug_logMessage(" D - Decorated. Does the window have a title bar?", 0)
Debug_logMessage(" R - Responsive. Is responding to messages?", 0)
Debug_logMessage(" G - Ghost. Is this window a ghost of another hung window?", 0)
Debug_logMessage(" M - Monitor number.", 0)
Debug_logMessage(" Tags - Bit-mask of the views in which the window is active.", 0)
Debug_logMessage(" X - Windows X position.", 0)
Debug_logMessage(" Y - Windows Y position.", 0)
Debug_logMessage(" W - Windows width.", 0)
Debug_logMessage(" H - Windows height.", 0)
Debug_logMessage(" Style - Windows style.", 0)
Debug_logMessage(" Proc / Class / Title - Process/Class/Title of the window.", 0)
}
Manager_lockWorkStation() {
@ -375,7 +375,7 @@ Manager_manage(pm, pv, wndId) {
body := 0
If Manager_isGhost( wndId ) {
Log_dbg_msg(2, "A window has given up the ghost (Ghost wndId: " . wndId . ")")
Debug_logMessage("DEBUG[2] A window has given up the ghost (Ghost wndId: " . wndId . ")", 2)
; Ghosts need special attention.
; Say a quick prayer and try to reattach it to its body.
body := Manager_findHung( wndId )
@ -388,7 +388,7 @@ Manager_manage(pm, pv, wndId) {
hideTitle := InStr(Bar_hideTitleWndIds, body ";")
}
Else {
Log_dbg_msg(1, "No body could be found for ghost wndId: " . wndId)
Debug_logMessage("DEBUG[1] No body could be found for ghost wndId: " . wndId, 1)
}
}
@ -532,7 +532,7 @@ Manager_onShellMessage(wParam, lParam) {
lParam := lParam+0
SetFormat, Integer, d
Log_dbg_msg(2, "Manager_onShellMessage( wParam: " . wParam . ", lParam: " . lParam . " )")
Debug_logMessage("DEBUG[2] Manager_onShellMessage( wParam: " . wParam . ", lParam: " . lParam . " )", 2)
WinGetClass, wndClass, ahk_id %lParam%
WinGetTitle, wndTitle, ahk_id %lParam%
@ -590,7 +590,7 @@ Manager_onShellMessage(wParam, lParam) {
wndId := SubStr(wndIds, 1, InStr(wndIds, ";") - 1)
Loop, % Config_viewCount
If (Manager_#%wndId%_tags & 1 << A_Index - 1) {
Log_dbg_msg(3, "Switching views because " . wndId . " is considered hidden and active")
Debug_logMessage("DEBUG[3] Switching views because " . wndId . " is considered hidden and active", 3)
Manager_aMonitor := Manager_#%wndId%_monitor
Monitor_activateView(A_Index)
Break
@ -825,7 +825,7 @@ Manager_winActivate(wndId) {
DllCall("SetCursorPos", "Int", Round(Monitor_#%Manager_aMonitor%_x + Monitor_#%Manager_aMonitor%_width / 2), "Int", Round(Monitor_#%Manager_aMonitor%_y + Monitor_#%Manager_aMonitor%_height / 2))
}
If Manager_isHung(wndId) {
Log_dbg_msg(2, "Manager_winActivate: Potentially hung window " . wndId)
Debug_logMessage("DEBUG[2] Manager_winActivate: Potentially hung window " . wndId, 2)
Return 1
}
Else {
@ -840,7 +840,7 @@ Manager_winActivate(wndId) {
Manager_winMove(wndId, x, y, width, height) {
If Manager_isHung(wndId) {
Log_dbg_msg(2, "Manager_winMove: Potentially hung window " . wndId)
Debug_logMessage("DEBUG[2] Manager_winMove: Potentially hung window " . wndId, 2)
Return 1
}
Else
@ -849,7 +849,7 @@ Manager_winMove(wndId, x, y, width, height) {
WM_EXITSIZEMOVE = 0x0232
SendMessage, WM_ENTERSIZEMOVE, , , , ahk_id %wndId%
If ErrorLevel {
Log_dbg_msg(2, "Manager_winMove: Potentially hung window " . wndId)
Debug_logMessage("DEBUG[2] Manager_winMove: Potentially hung window " . wndId, 1)
Return 1
}
Else {
@ -860,7 +860,7 @@ Manager_winMove(wndId, x, y, width, height) {
Manager_winHide(wndId) {
If Manager_isHung(wndId) {
Log_dbg_msg(2, "Manager_winHide: Potentially hung window " . wndId)
Debug_logMessage("DEBUG[2] Manager_winHide: Potentially hung window " . wndId, 2)
Return 1
}
Else {
@ -871,7 +871,7 @@ Manager_winHide(wndId) {
Manager_winShow(wndId) {
If Manager_isHung(wndId) {
Log_dbg_msg(2, "Manager_winShow: Potentially hung window " . wndId)
Debug_logMessage("DEBUG[2] Manager_winShow: Potentially hung window " . wndId, 2)
Return 1
}
Else {
@ -882,7 +882,7 @@ Manager_winShow(wndId) {
Manager_winClose(wndId) {
If Manager_isHung(wndId) {
Log_dbg_msg(2, "Manager_winClose: Potentially hung window " . wndId)
Debug_logMessage("DEBUG[2] Manager_winClose: Potentially hung window " . wndId, 2)
Return 1
}
Else {
@ -893,7 +893,7 @@ Manager_winClose(wndId) {
Manager_winSet(type, value, wndId) {
If Manager_isHung(wndId) {
Log_dbg_msg(2, "Manager_winSet: Potentially hung window " . wndId)
Debug_logMessage("DEBUG[2] Manager_winSet: Potentially hung window " . wndId, 2)
Return 1
}
Else {
@ -923,7 +923,6 @@ Manager_isHung(wndId) {
; This is only known to work on Windows 7
Manager_findHung( ghostWnd ) {
Local expectedTitle, expectedX, expectedY, expectedW, expectedH, wndTitle, wndX, wndY, wndW, wndH, wndIds
;Log_dbg_msg(3, "Manager_findHung(" . ghostWnd . ")")
WinGetTitle, expectedTitle, ahk_id %ghostWnd%
StringReplace, expectedTitle, expectedTitle, " (Not Responding)", ""
WinGetPos, expectedX, expectedY, expectedW, expectedH, ahk_id %ghostWnd%

View File

@ -41,7 +41,7 @@ Monitor_activateView(v) {
Else If (v = "<")
v := Manager_loop(Monitor_#%Manager_aMonitor%_aView_#1, -1, 1, Config_viewCount)
Log_dbg_msg(1, "Monitor_activateView(" . v . ") Manager_aMonitor: " . Manager_aMonitor . "; wndIds: " . View_#%m%_#%aView%_wndIds)
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

View File

@ -38,18 +38,18 @@ View_init(m, v) {
View_activateWindow(d) {
Local aWndId, i, j, v, wndId, wndId0, wndIds, failure, direction
Log_dbg_msg(1, "View_activateWindow(" . d . ")")
Debug_logMessage("DEBUG[1] View_activateWindow(" . d . ")", 1)
If (d = 0)
Return
WinGet, aWndId, ID, A
Log_dbg_bare(2, "Active Windows ID: " . aWndId)
Debug_logMessage("DEBUG[2] Active Windows ID: " . aWndId, 2, False)
v := Monitor_#%Manager_aMonitor%_aView_#1
Log_dbg_bare(2, "View (" . v . ") wndIds: " . View_#%Manager_aMonitor%_#%v%_wndIds)
Debug_logMessage("DEBUG[2] View (" . v . ") wndIds: " . View_#%Manager_aMonitor%_#%v%_wndIds, 2, False)
StringTrimRight, wndIds, View_#%Manager_aMonitor%_#%v%_wndIds, 1
StringSplit, wndId, wndIds, `;
Log_dbg_bare(2, "wndId count: " . wndId0)
Debug_logMessage("DEBUG[2] wndId count: " . wndId0, 2, False)
If (wndId0 > 1) {
If Manager_#%aWndId%_isFloating
Manager_winSet("Bottom", "", aWndId)
@ -62,10 +62,10 @@ View_activateWindow(d) {
direction = 1
Else
direction = -1
Log_dbg_bare(2, "Current wndId index: " . i)
Debug_logMessage("DEBUG[2] Current wndId index: " . i, 2, False)
j := Manager_loop(i, d, 1, wndId0)
Loop, % wndId0 {
Log_dbg_bare(2, "Next wndId index: " . j)
Debug_logMessage("DEBUG[2] Next wndId index: " . j, 2, False)
wndId := wndId%j%
Manager_winSet("AlwaysOnTop", "On", wndId)
Manager_winSet("AlwaysOnTop", "Off", wndId)
@ -135,7 +135,7 @@ View_delWnd(m, v, wndId) {
View_arrange(m, v) {
Local fn, l, wndIds
Log_dbg_msg(1, "View_arrange(" . m . ", " . v . ")")
Debug_logMessage("DEBUG[1] View_arrange(" . m . ", " . v . ")", 1)
; All window actions are performed on independent windows. A delay won't help.
SetWinDelay, 0
l := View_#%m%_#%v%_layout_#1
@ -441,7 +441,6 @@ View_draw_stack( arrName, off, len, dir, x, y, w, h, margin ) {
; margin - Number of pixels to put between the windows.
View_draw_row( arrName, off, len, dir, axis, x, y, w, h, margin ) {
Local base, inc, x_inc, y_inc, wHeight, wWidth
;Log_bare("View_draw_row(" . arrName . ", " . off . ", " . len . ", " . dir . ", " . axis . ", " . x . ", " . y . ", " . w . ", " . h . ", " . margin . ")")
If (dir = 0) {
; Left-to-right and top-to-bottom, depending on axis
base := off
@ -515,7 +514,7 @@ View_arrange_tile(m, v, wndIds) {
StringTrimRight, wndIds, wndIds, 1
StringSplit, View_arrange_tile_wndId, wndIds, `;
Log_dbg_msg(1, "View_arrange_tile: (" . View_arrange_tile_wndId0 . ") " . wndIds)
Debug_logMessage("DEBUG[1] View_arrange_tile: (" . View_arrange_tile_wndId0 . ") " . wndIds, 1)
If (View_arrange_tile_wndId0 = 0)
Return
@ -558,7 +557,6 @@ View_arrange_tile(m, v, wndIds) {
secondary_areas := Ceil(msplit / dimAligned)
areas_remaining := secondary_areas
windows_remaining := msplit
;Log_bare("msplit: " . msplit . "; layoutMX/Y: " . dimAligned . "; secondary_areas: " . secondary_areas . "; areas_remaining: " . areas_remaining . "; windows_remaining: " . windows_remaining)
Loop, % secondary_areas {
View_split_region(Not (axis2 - 1), (1/areas_remaining), x1, y1, w1, h1, mx1, my1, mw1, mh1, x1, y1, w1, h1)
draw_windows := dimAligned