2012-11-26 23:52:18 +00:00
|
|
|
/*
|
|
|
|
bug.n -- tiling window management
|
2015-01-25 12:07:37 +00:00
|
|
|
Copyright (c) 2010-2015 Joshua Fuhs, joten
|
2012-12-05 12:39:51 +00:00
|
|
|
|
2012-11-26 23:52:18 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-01-25 12:07:37 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2012-11-26 23:52:18 +00:00
|
|
|
GNU General Public License for more details.
|
2012-12-05 12:39:51 +00:00
|
|
|
|
2015-01-25 12:07:37 +00:00
|
|
|
@license GNU General Public License version 3
|
|
|
|
../LICENSE.md or <http://www.gnu.org/licenses/>
|
2012-12-05 12:39:51 +00:00
|
|
|
|
2015-01-25 13:04:17 +00:00
|
|
|
@version 9.0.0
|
2012-11-26 23:52:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
NAME := "bug.n"
|
2015-01-25 13:04:17 +00:00
|
|
|
VERSION := "9.0.0"
|
2011-07-27 17:43:34 +00:00
|
|
|
|
2012-11-26 23:52:18 +00:00
|
|
|
;; Script settings
|
2011-07-27 17:43:34 +00:00
|
|
|
OnExit, Main_cleanup
|
|
|
|
SetBatchLines, -1
|
|
|
|
SetTitleMatchMode, 3
|
|
|
|
SetTitleMatchMode, fast
|
|
|
|
SetWinDelay, 10
|
|
|
|
#NoEnv
|
|
|
|
#SingleInstance force
|
|
|
|
#WinActivateForce
|
|
|
|
|
2012-11-26 23:52:18 +00:00
|
|
|
;; Pseudo main function
|
|
|
|
If 0 = 1
|
2012-12-05 12:50:30 +00:00
|
|
|
Main_appDir = %1%
|
2012-11-26 23:52:18 +00:00
|
|
|
|
|
|
|
Main_setup()
|
2012-12-05 12:39:51 +00:00
|
|
|
|
2012-11-27 03:13:38 +00:00
|
|
|
Debug_initLog(Main_appDir "\log.txt", 0, False)
|
|
|
|
|
2013-05-19 20:07:09 +00:00
|
|
|
Debug_logMessage("====== Initializing ======", 0)
|
2012-11-27 03:13:38 +00:00
|
|
|
Config_filePath := Main_appDir "\Config.ini"
|
2012-11-26 23:52:18 +00:00
|
|
|
Config_init()
|
2012-12-05 12:39:51 +00:00
|
|
|
|
2012-11-26 23:52:18 +00:00
|
|
|
Menu, Tray, Tip, %NAME% %VERSION%
|
2012-12-05 15:24:11 +00:00
|
|
|
IfExist %A_ScriptDir%\logo.ico
|
|
|
|
Menu, Tray, Icon, %A_ScriptDir%\logo.ico
|
2012-11-26 23:52:18 +00:00
|
|
|
Menu, Tray, NoStandard
|
|
|
|
Menu, Tray, Add, Toggle bar, Main_toggleBar
|
|
|
|
Menu, Tray, Add, Help, Main_help
|
2012-12-05 12:39:51 +00:00
|
|
|
Menu, Tray, Add,
|
2012-11-26 23:52:18 +00:00
|
|
|
Menu, Tray, Add, Exit, Main_quit
|
2012-12-05 12:39:51 +00:00
|
|
|
|
2012-11-26 23:52:18 +00:00
|
|
|
ResourceMonitor_init()
|
|
|
|
Manager_init()
|
2012-11-27 03:13:38 +00:00
|
|
|
Debug_logMessage("====== Running ======", 0)
|
2012-11-26 23:52:18 +00:00
|
|
|
Return ;; end of the auto-execute section
|
|
|
|
|
|
|
|
;; Function & label definitions
|
|
|
|
Main_cleanup:
|
2012-11-27 03:13:38 +00:00
|
|
|
Debug_logMessage("====== Cleaning up ======", 0)
|
2012-12-05 23:55:38 +00:00
|
|
|
;; Config_autoSaveSession as False is deprecated.
|
|
|
|
If Not (Config_autoSaveSession = "off") And Not (Config_autoSaveSession = "False")
|
|
|
|
Manager_saveState()
|
2012-11-26 23:52:18 +00:00
|
|
|
Manager_cleanup()
|
|
|
|
ResourceMonitor_cleanup()
|
2012-11-27 03:13:38 +00:00
|
|
|
Debug_logMessage("====== Exiting bug.n ======", 0)
|
2011-07-27 17:43:34 +00:00
|
|
|
ExitApp
|
2012-12-05 12:39:51 +00:00
|
|
|
|
|
|
|
Main_evalCommand(command)
|
2012-11-26 23:52:18 +00:00
|
|
|
{
|
|
|
|
type := SubStr(command, 1, 5)
|
2012-12-05 12:39:51 +00:00
|
|
|
If (type = "Run, ")
|
2012-11-26 23:52:18 +00:00
|
|
|
{
|
|
|
|
parameters := SubStr(command, 6)
|
2012-12-05 12:39:51 +00:00
|
|
|
If InStr(parameters, ", ")
|
2012-11-26 23:52:18 +00:00
|
|
|
{
|
|
|
|
StringSplit, parameter, parameters, `,
|
2012-12-05 12:39:51 +00:00
|
|
|
If (parameter0 = 2)
|
2012-11-26 23:52:18 +00:00
|
|
|
{
|
|
|
|
StringTrimLeft, parameter2, parameter2, 1
|
|
|
|
Run, %parameter1%, %parameter2%
|
2012-12-05 12:39:51 +00:00
|
|
|
}
|
|
|
|
Else If (parameter0 > 2)
|
2012-11-26 23:52:18 +00:00
|
|
|
{
|
|
|
|
StringTrimLeft, parameter2, parameter2, 1
|
|
|
|
StringTrimLeft, parameter3, parameter3, 1
|
|
|
|
Run, %parameter1%, %parameter2%, %parameter3%
|
|
|
|
}
|
2012-12-05 12:39:51 +00:00
|
|
|
}
|
2012-11-26 23:52:18 +00:00
|
|
|
Else
|
|
|
|
Run, %parameters%
|
2012-12-05 12:39:51 +00:00
|
|
|
}
|
2012-11-26 23:52:18 +00:00
|
|
|
Else If (type = "Send ")
|
|
|
|
Send % SubStr(command, 6)
|
|
|
|
Else If (command = "Reload")
|
|
|
|
Reload
|
|
|
|
Else If (command = "ExitApp")
|
|
|
|
ExitApp
|
2012-12-05 12:39:51 +00:00
|
|
|
Else
|
2012-11-26 23:52:18 +00:00
|
|
|
{
|
|
|
|
i := InStr(command, "(")
|
|
|
|
j := InStr(command, ")", False, i)
|
2012-12-05 12:39:51 +00:00
|
|
|
If i And j
|
2012-11-26 23:52:18 +00:00
|
|
|
{
|
|
|
|
functionName := SubStr(command, 1, i - 1)
|
|
|
|
functionArguments := SubStr(command, i + 1, j - (i + 1))
|
|
|
|
StringSplit, functionArgument, functionArguments, `,
|
|
|
|
If (functionArgument0 < 2)
|
|
|
|
%functionName%(functionArguments)
|
2012-12-05 12:39:51 +00:00
|
|
|
Else If (functionArgument0 = 2)
|
2012-11-26 23:52:18 +00:00
|
|
|
{
|
|
|
|
StringTrimLeft, functionArgument2, functionArgument2, 1
|
|
|
|
%functionName%(functionArgument1, functionArgument2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-07-27 17:43:34 +00:00
|
|
|
|
|
|
|
Main_help:
|
2014-03-09 17:31:37 +00:00
|
|
|
Run, explore %Main_docDir%
|
2011-07-27 17:43:34 +00:00
|
|
|
Return
|
|
|
|
|
|
|
|
Main_quit:
|
2012-11-26 23:52:18 +00:00
|
|
|
ExitApp
|
2011-07-27 17:43:34 +00:00
|
|
|
Return
|
|
|
|
|
2012-11-25 13:56:35 +00:00
|
|
|
; Create bug.n-specific directories.
|
|
|
|
Main_makeDir(dirName) {
|
2012-11-26 23:52:18 +00:00
|
|
|
IfNotExist, %dirName%
|
|
|
|
{
|
|
|
|
FileCreateDir, %dirName%
|
2012-12-05 12:39:51 +00:00
|
|
|
If ErrorLevel
|
2012-11-26 23:52:18 +00:00
|
|
|
{
|
|
|
|
MsgBox, Error (%ErrorLevel%) when creating '%dirName%'. Aborting.
|
|
|
|
ExitApp
|
|
|
|
}
|
|
|
|
}
|
2012-12-05 12:39:51 +00:00
|
|
|
Else
|
2012-11-26 23:52:18 +00:00
|
|
|
{
|
|
|
|
FileGetAttrib, attrib, %dirName%
|
2012-12-05 12:39:51 +00:00
|
|
|
IfNotInString, attrib, D
|
2012-11-26 23:52:18 +00:00
|
|
|
{
|
|
|
|
MsgBox, The file path '%dirName%' already exists and is not a directory. Aborting.
|
|
|
|
ExitApp
|
|
|
|
}
|
|
|
|
}
|
2012-11-25 13:56:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Main_setup() {
|
2012-11-26 23:52:18 +00:00
|
|
|
Local winAppDir
|
|
|
|
|
2014-03-09 17:31:37 +00:00
|
|
|
Main_docDir := A_ScriptDir
|
|
|
|
If (SubStr(A_ScriptDir, -3) = "\src")
|
|
|
|
Main_docDir .= "\.."
|
|
|
|
Main_docDir .= "\doc"
|
|
|
|
|
2012-11-26 23:52:18 +00:00
|
|
|
Main_logFile := ""
|
|
|
|
Main_dataDir := ""
|
|
|
|
Main_autoLayout := ""
|
|
|
|
Main_autoWindowState := ""
|
|
|
|
|
|
|
|
EnvGet, winAppDir, APPDATA
|
|
|
|
|
2012-12-05 15:24:11 +00:00
|
|
|
If (Main_appDir = "")
|
2012-12-05 12:50:30 +00:00
|
|
|
Main_appDir := winAppDir . "\bug.n"
|
2012-11-26 23:52:18 +00:00
|
|
|
Main_logFile := Main_appDir . "\bugn_log.txt"
|
|
|
|
Main_dataDir := Main_appDir . "\data"
|
|
|
|
Main_autoLayout := Main_dataDir . "\_Layout.ini"
|
|
|
|
Main_autoWindowState := Main_dataDir . "\_WindowState.ini"
|
2012-12-05 12:39:51 +00:00
|
|
|
|
2012-11-26 23:52:18 +00:00
|
|
|
Main_makeDir(Main_appDir)
|
|
|
|
Main_makeDir(Main_dataDir)
|
2012-11-25 13:56:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-05 12:39:51 +00:00
|
|
|
Main_reload()
|
2012-11-26 23:52:18 +00:00
|
|
|
{
|
|
|
|
Local i, ncm, ncmSize
|
2012-12-05 12:39:51 +00:00
|
|
|
|
2012-11-26 23:52:18 +00:00
|
|
|
;; Reset border color, padding and witdh.
|
|
|
|
If Config_selBorderColor
|
|
|
|
DllCall("SetSysColors", "Int", 1, "Int*", 10, "UInt*", Manager_normBorderColor)
|
2012-12-05 12:39:51 +00:00
|
|
|
If (Config_borderWidth > 0) Or (Config_borderPadding >= 0 And A_OSVersion = WIN_VISTA)
|
2012-11-26 23:52:18 +00:00
|
|
|
{
|
|
|
|
ncmSize := VarSetCapacity(ncm, 4 * (A_OSVersion = WIN_VISTA ? 11 : 10) + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), 0)
|
|
|
|
NumPut(ncmSize, ncm, 0, "UInt")
|
|
|
|
DllCall("SystemParametersInfo", "UInt", 0x0029, "UInt", ncmSize, "UInt", &ncm, "UInt", 0)
|
|
|
|
If (Config_borderWidth > 0)
|
|
|
|
NumPut(Manager_borderWidth, ncm, 4, "Int")
|
|
|
|
If (Config_borderPadding >= 0 And A_OSVersion = WIN_VISTA)
|
|
|
|
NumPut(Manager_borderPadding, ncm, 40 + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), "Int")
|
|
|
|
DllCall("SystemParametersInfo", "UInt", 0x002a, "UInt", ncmSize, "UInt", &ncm, "UInt", 0)
|
|
|
|
}
|
|
|
|
DllCall("Shell32.dll\SHAppBarMessage", "UInt", (ABM_REMOVE := 0x1), "UInt", &Bar_appBarData)
|
|
|
|
;; SKAN: Crazy Scripting : Quick Launcher for Portable Apps (http://www.autohotkey.com/forum/topic22398.html)
|
2012-12-05 12:39:51 +00:00
|
|
|
|
2012-11-26 23:52:18 +00:00
|
|
|
Config_init()
|
|
|
|
; Windows UI
|
|
|
|
If Config_selBorderColor {
|
|
|
|
SetFormat, Integer, hex
|
|
|
|
Manager_normBorderColor := DllCall("GetSysColor", "Int", 10)
|
|
|
|
SetFormat, Integer, d
|
|
|
|
DllCall("SetSysColors", "Int", 1, "Int*", 10, "UInt*", Config_selBorderColor)
|
|
|
|
}
|
|
|
|
If (Config_borderWidth > 0) Or (Config_borderPadding >= 0 And A_OSVersion = WIN_VISTA) {
|
|
|
|
ncmSize := VarSetCapacity(ncm, 4 * (A_OSVersion = WIN_VISTA ? 11 : 10) + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), 0)
|
|
|
|
NumPut(ncmSize, ncm, 0, "UInt")
|
|
|
|
DllCall("SystemParametersInfo", "UInt", 0x0029, "UInt", ncmSize, "UInt", &ncm, "UInt", 0)
|
|
|
|
Manager_borderWidth := NumGet(ncm, 4, "Int")
|
|
|
|
Manager_borderPadding := NumGet(ncm, 40 + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), "Int")
|
|
|
|
If (Config_borderWidth > 0)
|
|
|
|
NumPut(Config_borderWidth, ncm, 4, "Int")
|
|
|
|
If (Config_borderPadding >= 0 And A_OSVersion = WIN_VISTA)
|
|
|
|
NumPut(Config_borderPadding, ncm, 40 + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), "Int")
|
|
|
|
DllCall("SystemParametersInfo", "UInt", 0x002a, "UInt", ncmSize, "UInt", &ncm, "UInt", 0)
|
|
|
|
}
|
|
|
|
Bar_getHeight()
|
2012-12-05 12:39:51 +00:00
|
|
|
Loop, % Manager_monitorCount
|
2012-11-26 23:52:18 +00:00
|
|
|
{
|
|
|
|
Monitor_getWorkArea(A_Index)
|
|
|
|
Bar_init(A_Index)
|
|
|
|
}
|
|
|
|
Bar_initCmdGui()
|
|
|
|
If Not (Manager_showTaskBar = Config_showTaskBar)
|
|
|
|
Monitor_toggleTaskBar()
|
|
|
|
Bar_updateStatus()
|
|
|
|
Bar_updateTitle()
|
2012-12-05 12:39:51 +00:00
|
|
|
Loop, % Manager_monitorCount
|
2012-11-26 23:52:18 +00:00
|
|
|
{
|
|
|
|
i := A_Index
|
2012-12-05 12:39:51 +00:00
|
|
|
Loop, % Config_viewCount
|
2012-11-26 23:52:18 +00:00
|
|
|
{
|
|
|
|
Bar_updateView(i, A_Index)
|
|
|
|
}
|
|
|
|
View_arrange(i, Monitor_#%i%_aView_#1)
|
|
|
|
}
|
|
|
|
Manager_registerShellHook()
|
|
|
|
SetTimer, Bar_loop, %Config_readinInterval%
|
2011-12-05 21:20:38 +00:00
|
|
|
}
|
|
|
|
|
2011-07-27 17:43:34 +00:00
|
|
|
Main_toggleBar:
|
2012-11-26 23:52:18 +00:00
|
|
|
Monitor_toggleBar()
|
2011-07-27 17:43:34 +00:00
|
|
|
Return
|
|
|
|
|
|
|
|
#Include Bar.ahk
|
|
|
|
#Include Config.ahk
|
2012-09-28 15:46:17 +00:00
|
|
|
#Include Debug.ahk
|
2011-07-27 17:43:34 +00:00
|
|
|
#Include Manager.ahk
|
|
|
|
#Include Monitor.ahk
|
2012-11-26 23:52:18 +00:00
|
|
|
#Include ResourceMonitor.ahk
|
2011-07-27 17:43:34 +00:00
|
|
|
#Include View.ahk
|