From ea41d7ae00fcc4ae62aacf3969a5194c809ff336 Mon Sep 17 00:00:00 2001 From: joten Date: Wed, 5 Dec 2012 13:39:51 +0100 Subject: [PATCH 1/5] updated version number (my text editor might also have deleted unnecessary space) --- src/Bar.ahk | 212 ++++++++--------- src/Config.ahk | 126 +++++----- src/Debug.ahk | 48 ++-- src/Main.ahk | 66 ++--- src/Manager.ahk | 516 ++++++++++++++++++++-------------------- src/Monitor.ahk | 168 ++++++------- src/ResourceMonitor.ahk | 58 ++--- src/View.ahk | 244 +++++++++---------- src/doc/changes.t2t | 3 +- 9 files changed, 721 insertions(+), 720 deletions(-) diff --git a/src/Bar.ahk b/src/Bar.ahk index 48b5a18..bd290ca 100644 --- a/src/Bar.ahk +++ b/src/Bar.ahk @@ -1,32 +1,32 @@ /* 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 . - - @version 8.3.0 + + @version 8.4.0 */ -Bar_init(m) +Bar_init(m) { Local appBarMsg, GuiN, h1, h2, i, text, titleWidth, trayWndId, w, wndId, wndTitle, wndWidth, x1, x2, y1, y2 - - If (SubStr(Config_barWidth, 0) = "%") + + If (SubStr(Config_barWidth, 0) = "%") { StringTrimRight, wndWidth, Config_barWidth, 1 wndWidth := Round(Monitor_#%m%_width * wndWidth / 100) - } + } Else wndWidth := Config_barWidth Monitor_#%m%_barWidth := wndWidth @@ -37,7 +37,7 @@ Bar_init(m) y1 := 0 y2 := (Bar_ctrlHeight - Bar_textHeight) / 2 h2 := Bar_ctrlHeight - 2 * y2 - + ;; Create the GUI window wndTitle := "bug.n_BAR_" m GuiN := (m - 1) + 1 @@ -47,14 +47,14 @@ Bar_init(m) Gui, +AlwaysOnTop -Caption +LabelBar_Gui +LastFound +ToolWindow Gui, Color, %Config_normBgColor1% Gui, Font, c%Config_normFgColor1% s%Config_fontSize%, %Config_fontName% - + ;; Tags - Loop, % Config_viewCount + Loop, % Config_viewCount { i := A_Index text := " " Config_viewNames_#%i% " " w := Bar_getTextWidth(text) - Gui, Add, Text, x%x1% y%y1% w%w% h%h1% BackgroundTrans vBar_#%m%_#%i%_view gBar_GuiClick, + Gui, Add, Text, x%x1% y%y1% w%w% h%h1% BackgroundTrans vBar_#%m%_#%i%_view gBar_GuiClick, If (w <= h1) Gui, Add, Progress, x%x1% y%y1% w%w% h%h1% Background%Config_normBgColor1% Vertical vBar_#%m%_#%i%_tagged Else @@ -67,41 +67,41 @@ Bar_init(m) i := Config_viewCount + 1 text := " ?????? " w := Bar_getTextWidth(text) - Gui, Add, Text, x%x1% y%y1% w%w% h%h1% BackgroundTrans vBar_#%m%_#%i%_layout gBar_GuiClick, + Gui, Add, Text, x%x1% y%y1% w%w% h%h1% BackgroundTrans vBar_#%m%_#%i%_layout gBar_GuiClick, Gui, Add, Progress, x%x1% y%y1% w%w% h%h1% Background%Config_normBgColor2% Gui, Font, c%Config_normFgColor2% Gui, Add, Text, x%x1% y%y2% w%w% h%h2% -Wrap Center BackgroundTrans vBar_#%m%_#%i%, %text% titleWidth -= w x1 += w - + ;; The x-position and width of the sub-windows right of the window title are set from the right. - Loop, 4 + Loop, 4 { i := Config_viewCount + 7 - A_Index w := 0 - If (i = Config_viewCount + 6) + If (i = Config_viewCount + 6) { ;; Command gui Gui, -Disabled w := Bar_getTextWidth(" ?? ") x2 -= w titleWidth -= w - Gui, Add, Text, x%x2% y%y1% w%w% h%h1% BackgroundTrans vBar_#%m%_#%i% gBar_toggleCommandGui, + Gui, Add, Text, x%x2% y%y1% w%w% h%h1% BackgroundTrans vBar_#%m%_#%i% gBar_toggleCommandGui, Gui, Add, Progress, x%x2% y%y1% w%w% h%h1% Background%Config_normBgColor2% Gui, Add, Text, x%x2% y%y2% w%w% h%h2% Center BackgroundTrans, #! - } - Else If (i = Config_viewCount + 5) And Config_readinTime + } + Else If (i = Config_viewCount + 5) And Config_readinTime { ;; Time w := Bar_getTextWidth(" ??:?? ") x2 -= w titleWidth -= w - If Config_readinAny() Or Config_readinBat + If Config_readinAny() Or Config_readinBat { Gui, Font, c%Config_normFgColor1% - Gui, Add, Text, x%x2% y%y1% w%w% h%h1%, + Gui, Add, Text, x%x2% y%y1% w%w% h%h1%, } Gui, Add, Text, x%x2% y%y2% w%w% h%h2% BackgroundTrans Center vBar_#%m%_#%i%, ??:?? - } - Else If (i = Config_viewCount + 4) And Config_readinAny() + } + Else If (i = Config_viewCount + 4) And Config_readinAny() { ;; Any text := Config_readinAny() w := Bar_getTextWidth(text) @@ -110,8 +110,8 @@ Bar_init(m) Gui, Add, Progress, x%x2% y%y1% w%w% h%h1% Background%Config_normBgColor2% Gui, Font, c%Config_normFgColor2% Gui, Add, Text, x%x2% y%y2% w%w% h%h2% Center BackgroundTrans vBar_#%m%_#%i%, %text% - } - Else If (i = Config_viewCount + 3) And Config_readinBat + } + Else If (i = Config_viewCount + 3) And Config_readinBat { ;; Battery level w := Bar_getTextWidth(" BAT: ???% ") x2 -= w @@ -121,10 +121,10 @@ Bar_init(m) Gui, Add, Text, x%x2% y%y2% w%w% h%h2% BackgroundTrans Center vBar_#%m%_#%i%, BAT: ???`% } } - + ;; Window title (remaining space) - Gui, Add, Text, x%x1% y%y1% w%titleWidth% h%h1%, - If Not Config_singleRowBar + Gui, Add, Text, x%x1% y%y1% w%titleWidth% h%h1%, + If Not Config_singleRowBar { titleWidth := wndWidth x1 := 0 @@ -133,9 +133,9 @@ Bar_init(m) } i := Config_viewCount + 2 Gui, Font, c%Config_normFgColor1% - Gui, Add, Text, x%x1% y%y1% w%titleWidth% h%h1%, - Gui, Add, Text, x%x1% y%y2% w%titleWidth% h%h2% BackgroundTrans Center vBar_#%m%_#%i%, - + Gui, Add, Text, x%x1% y%y1% w%titleWidth% h%h1%, + Gui, Add, Text, x%x1% y%y2% w%titleWidth% h%h2% BackgroundTrans Center vBar_#%m%_#%i%, + If (Config_horizontalBarPos = "left") x1 := 0 Else If (Config_horizontalBarPos = "right") @@ -148,25 +148,25 @@ Bar_init(m) x1 := Monitor_#%m%_width - wndWidth + Config_horizontalBarPos If Not (Config_verticalBarPos = "tray" And m = Manager_taskBarMonitor) x1 += Monitor_#%m%_x - + Bar_#%m%_titleWidth := titleWidth Monitor_#%m%_barX := x1 y1 := Monitor_#%m%_barY - + If Monitor_#%m%_showBar Gui, Show, NoActivate x%x1% y%y1% w%wndWidth% h%Bar_height%, %wndTitle% Else Gui, Show, NoActivate Hide x%x1% y%y1% w%wndWidth% h%Bar_height%, %wndTitle% wndId := WinExist(wndTitle) - If (Config_verticalBarPos = "tray" And m = Manager_taskBarMonitor) + If (Config_verticalBarPos = "tray" And m = Manager_taskBarMonitor) { trayWndId := WinExist("ahk_class Shell_TrayWnd") DllCall("SetParent", "UInt", wndId, "UInt", trayWndId) - } - Else + } + Else { appBarMsg := DllCall("RegisterWindowMessage", Str, "AppBarMsg") - + ;; appBarData: http://msdn2.microsoft.com/en-us/library/ms538008.aspx VarSetCapacity(Bar_appBarData, 36, 0) offset := NumPut( 36, Bar_appBarData) @@ -178,7 +178,7 @@ Bar_init(m) offset := NumPut( wndWidth, offset+0) offset := NumPut(Bar_height, offset+0) offset := NumPut( 1, offset+0) - + DllCall("Shell32.dll\SHAppBarMessage", "UInt", (ABM_NEW := 0x0) , "UInt", &Bar_appBarData) DllCall("Shell32.dll\SHAppBarMessage", "UInt", (ABM_QUERYPOS := 0x2), "UInt", &Bar_appBarData) DllCall("Shell32.dll\SHAppBarMessage", "UInt", (ABM_SETPOS := 0x3) , "UInt", &Bar_appBarData) @@ -186,10 +186,10 @@ Bar_init(m) } } -Bar_initCmdGui() +Bar_initCmdGui() { Global Bar_#0_#0, Bar_#0_#0H, Bar_#0_#0W, Bar_cmdGuiIsVisible, Config_barCommands, Config_fontName, Config_fontSize, Config_normBgColor1, Config_normFgColor1 - + Bar_cmdGuiIsVisible := False wndTitle := "bug.n_BAR_0" Gui, 99: Default @@ -214,7 +214,7 @@ Bar_cmdGuiEscape: Return Bar_cmdGuiEnter: - If (A_GuiControl = "OK") Or (A_GuiControl = "Bar_#0_#0" And A_GuiControlEvent = "DoubleClick") + If (A_GuiControl = "OK") Or (A_GuiControl = "Bar_#0_#0" And A_GuiControlEvent = "DoubleClick") { Gui, Submit, NoHide Bar_cmdGuiIsVisible := False @@ -225,11 +225,11 @@ Bar_cmdGuiEnter: } Return -Bar_getBatteryStatus(ByRef batteryLifePercent, ByRef acLineStatus) +Bar_getBatteryStatus(ByRef batteryLifePercent, ByRef acLineStatus) { VarSetCapacity(powerStatus, (1 + 1 + 1 + 1 + 4 + 4)) success := DllCall("GetSystemPowerStatus", "UInt", &powerStatus) - If (ErrorLevel != 0 Or success = 0) + If (ErrorLevel != 0 Or success = 0) { MsgBox 16, Power Status, Can't get the power status... Return @@ -249,31 +249,31 @@ Bar_getBatteryStatus(ByRef batteryLifePercent, ByRef acLineStatus) } ;; PhiLho: AC/Battery status (http://www.autohotkey.com/forum/topic7633.html) -Bar_getHeight() +Bar_getHeight() { Global Bar_#0_#1, Bar_#0_#1H, Bar_#0_#2, Bar_#0_#2H, Bar_ctrlHeight, Bar_height, Bar_textHeight Global Config_fontName, Config_fontSize, Config_singleRowBar, Config_spaciousBar, Config_verticalBarPos - + wndTitle := "bug.n_BAR_0" Gui, 99: Default Gui, Font, s%Config_fontSize%, %Config_fontName% Gui, Add, Text, x0 y0 vBar_#0_#1, | GuiControlGet, Bar_#0_#1, Pos Bar_textHeight := Bar_#0_#1H - If Config_spaciousBar + If Config_spaciousBar { Gui, Add, ComboBox, r9 x0 y0 vBar_#0_#2, | GuiControlGet, Bar_#0_#2, Pos Bar_ctrlHeight := Bar_#0_#2H - } + } Else Bar_ctrlHeight := Bar_textHeight Gui, Destroy - + Bar_height := Bar_ctrlHeight If Not Config_singleRowBar Bar_height *= 2 - If (Config_verticalBarPos = "tray") + If (Config_verticalBarPos = "tray") { WinGetPos, , , , buttonH, Start ahk_class Button WinGetPos, , , , barH, ahk_class Shell_TrayWnd @@ -287,11 +287,11 @@ Bar_getHeight() } } -Bar_getTextWidth(x, reverse=False) +Bar_getTextWidth(x, reverse=False) { Global Config_fontSize - - If reverse + + If reverse { ;; 'reverse' calculates the number of characters to a given width. w := x i := w / (Config_fontSize - 1) @@ -302,8 +302,8 @@ Bar_getTextWidth(x, reverse=False) Else If (Config_fontSize > 17) i := w / (Config_fontSize - 4) textWidth := i - } - Else + } + Else { ;; 'else' calculates the width to a given string. textWidth := StrLen(x) * (Config_fontSize - 1) If (Config_fontSize = 7 Or (Config_fontSize > 8 And Config_fontSize < 13)) @@ -313,13 +313,13 @@ Bar_getTextWidth(x, reverse=False) Else If (Config_fontSize > 17) textWidth := StrLen(x) * (Config_fontSize - 4) } - + Return, textWidth } Bar_GuiClick: Manager_winActivate(Bar_aWndId) - If (A_GuiEvent = "Normal") + If (A_GuiEvent = "Normal") { If Not (SubStr(A_GuiControl, 6, InStr(A_GuiControl, "_#", False, 0) - 6) = Manager_aMonitor) Manager_activateMonitor(SubStr(A_GuiControl, 6, InStr(A_GuiControl, "_#", False, 0) - 6) - Manager_aMonitor) @@ -332,15 +332,15 @@ Return Bar_GuiContextMenu: Manager_winActivate(Bar_aWndId) - If (A_GuiEvent = "RightClick") + If (A_GuiEvent = "RightClick") { - If (SubStr(A_GuiControl, -6) = "_layout") + If (SubStr(A_GuiControl, -6) = "_layout") { If Not (SubStr(A_GuiControl, 6, InStr(A_GuiControl, "_#", False, 0) - 6) = Manager_aMonitor) Manager_activateMonitor(SubStr(A_GuiControl, 6, InStr(A_GuiControl, "_#", False, 0) - 6) - Manager_aMonitor) View_setLayout(">") - } - Else If (SubStr(A_GuiControl, -4) = "_view") + } + Else If (SubStr(A_GuiControl, -4) = "_view") { If Not (SubStr(A_GuiControl, 6, InStr(A_GuiControl, "_#", False, 0) - 6) = Manager_aMonitor) Manager_setWindowMonitor(SubStr(A_GuiControl, 6, InStr(A_GuiControl, "_#", False, 0) - 6) - Manager_aMonitor) @@ -353,13 +353,13 @@ Bar_loop: Bar_updateStatus() Return -Bar_move(m) +Bar_move(m) { Local wndTitle, x, y - + x := Monitor_#%m%_barX y := Monitor_#%m%_barY - + wndTitle := "bug.n_BAR_" m WinMove, %wndTitle%, , %x%, %y% } @@ -371,18 +371,18 @@ Bar_toggleCommandGui: Bar_toggleCommandGui() Return -Bar_toggleCommandGui() +Bar_toggleCommandGui() { Local wndId, x, y - + Gui, 99: Default - If Bar_cmdGuiIsVisible + If Bar_cmdGuiIsVisible { Bar_cmdGuiIsVisible := False Gui, Cancel Manager_winActivate(Bar_aWndId) - } - Else + } + Else { Bar_cmdGuiIsVisible := True x := Monitor_#%Manager_aMonitor%_barX + Monitor_#%Manager_aMonitor%_barWidth - Bar_#0_#0W @@ -396,56 +396,56 @@ Bar_toggleCommandGui() } } -Bar_toggleVisibility(m) +Bar_toggleVisibility(m) { Local GuiN - + GuiN := (m - 1) + 1 - If Monitor_#%m%_showBar + If Monitor_#%m%_showBar { If Not (GuiN = 99) Or Bar_cmdGuiIsVisible Gui, %GuiN%: Show - } + } Else Gui, %GuiN%: Cancel } -Bar_updateLayout(m) +Bar_updateLayout(m) { Local aView, GuiN, i - + aView := Monitor_#%m%_aView_#1 i := Config_viewCount + 1 GuiN := (m - 1) + 1 GuiControl, %GuiN%: , Bar_#%m%_#%i%, % View_#%m%_#%aView%_layoutSymbol } -Bar_updateStatus() +Bar_updateStatus() { Local anyContent, anyText, b1, b2, b3, GuiN, i, m - - Loop, % Manager_monitorCount + + Loop, % Manager_monitorCount { m := A_Index GuiN := (m - 1) + 1 Debug_logMessage("DEBUG[6] Bar_updateStatus(): Gui, " . GuiN . ": Default", 6) Gui, %GuiN%: Default - If Config_readinBat + If Config_readinBat { Bar_getBatteryStatus(b1, b2) b3 := SubStr(" " b1, -2) i := Config_viewCount + 3 - If (b1 < 10) And (b2 = "off") + If (b1 < 10) And (b2 = "off") { ;; Change the color, if the battery level is below 10% GuiControl, +Background%Config_normBgColor4% +c%Config_normBgColor2%, Bar_#%m%_#%i%_tagged GuiControl, +c%Config_selFgColor6%, Bar_#%m%_#%i% - } - Else If (b2 = "off") + } + Else If (b2 = "off") { ;; Change the color, if the pc is not plugged in GuiControl, +Background%Config_normBgColor2% +c%Config_normFgColor5%, Bar_#%m%_#%i%_tagged GuiControl, +c%Config_normFgColor4%, Bar_#%m%_#%i% - } - Else + } + Else { GuiControl, +Background%Config_normBgColor3% +c%Config_normFgColor3%, Bar_#%m%_#%i%_tagged GuiControl, +c%Config_normFgColor2%, Bar_#%m%_#%i% @@ -454,14 +454,14 @@ Bar_updateStatus() GuiControl, , Bar_#%m%_#%i%, % " BAT: " b3 "% " } anyText := Config_readinAny() - If anyText + If anyText { i := Config_viewCount + 4 GuiControlGet, anyContent, , Bar_#%m%_#%i% If Not (anyText = anyContent) GuiControl, , Bar_#%m%_#%i%, % anyText } - If Config_readinTime + If Config_readinTime { i := Config_viewCount + 5 GuiControl, , Bar_#%m%_#%i%, % " " A_Hour ":" A_Min " " @@ -469,13 +469,13 @@ Bar_updateStatus() } } -Bar_updateTitle(debugMsg = "") +Bar_updateTitle(debugMsg = "") { Local aWndId, aWndTitle, content, GuiN, i, title - + If debugMsg aWndTitle := debugMsg - Else + Else { WinGet, aWndId, ID, A WinGetTitle, aWndTitle, ahk_id %aWndId% @@ -487,59 +487,59 @@ Bar_updateTitle(debugMsg = "") aWndTitle := "[" Manager_aMonitor "] " aWndTitle } title := " " . aWndTitle . " " - - If (Bar_getTextWidth(title) > Bar_#%Manager_aMonitor%_titleWidth) + + If (Bar_getTextWidth(title) > Bar_#%Manager_aMonitor%_titleWidth) { ;; Shorten the window title if its length exceeds the width of the bar i := Bar_getTextWidth(Bar_#%Manager_aMonitor%_titleWidth, True) - 6 StringLeft, title, aWndTitle, i title := " " . title . " ... " } - + i := Config_viewCount + 2 - Loop, % Manager_monitorCount + Loop, % Manager_monitorCount { GuiN := (A_Index - 1) + 1 Debug_logMessage("DEBUG[6] Bar_updateTitle(): Gui, " . GuiN . ": Default", 6) Gui, %GuiN%: Default GuiControlGet, content, , Bar_#%A_Index%_#%i% - If (A_Index = Manager_aMonitor) + If (A_Index = Manager_aMonitor) { If Not (content = title) GuiControl, , Bar_#%A_Index%_#%i%, % title } Else If Not (content = "") - GuiControl, , Bar_#%A_Index%_#%i%, + GuiControl, , Bar_#%A_Index%_#%i%, } Bar_aWndId := aWndId } -Bar_updateView(m, v) +Bar_updateView(m, v) { Local managedWndId0, wndId0, wndIds - + GuiN := (m - 1) + 1 Gui, %GuiN%: Default Debug_logMessage("DEBUG[6] Bar_updateView(): m: " . m . "; Gui, " . GuiN . ": Default", 6) - + StringTrimRight, wndIds, Manager_managedWndIds, 1 StringSplit, managedWndId, wndIds, `; - - If (v = Monitor_#%m%_aView_#1) + + If (v = Monitor_#%m%_aView_#1) { ;; Set foreground/background colors if the view is the current view. GuiControl, +Background%Config_selBgColor1% +c%Config_selFgColor2%, Bar_#%m%_#%v%_tagged GuiControl, +c%Config_selFgColor1%, Bar_#%m%_#%v% - } - Else If wndId0 + } + Else If wndId0 { ;; Set foreground/background colors if the view contains windows. GuiControl, +Background%Config_normBgColor5% +c%Config_normFgColor8%, Bar_#%m%_#%v%_tagged GuiControl, +c%Config_normFgColor7%, Bar_#%m%_#%v% - } - Else + } + Else { ;; Set foreground/background colors if the view is empty. GuiControl, +Background%Config_normBgColor1% +c%Config_normFgColor8%, Bar_#%m%_#%v%_tagged GuiControl, +c%Config_normFgColor1%, Bar_#%m%_#%v% } - - Loop, %Config_viewCount% + + Loop, %Config_viewCount% { StringTrimRight, wndIds, View_#%m%_#%A_Index%_wndIds, 1 StringSplit, wndId, wndIds, `; diff --git a/src/Config.ahk b/src/Config.ahk index 997c30f..dee2be5 100644 --- a/src/Config.ahk +++ b/src/Config.ahk @@ -1,27 +1,27 @@ /* 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 . - - @version 8.3.0 + + @version 8.4.0 */ -Config_init() +Config_init() { Local i, key, layout0, layout1, layout2, vNames0, vNames1, vNames2, vNames3, vNames4, vNames5, vNames6, vNames7, vNames8, vNames9 - + ;; Status bar Config_showBar := True Config_horizontalBarPos := "left" @@ -30,11 +30,11 @@ Config_init() Config_singleRowBar := True Config_spaciousBar := False Config_fontName := "Lucida Console" - Config_fontSize := - Config_normBgColor := - Config_normFgColor := - Config_selBgColor := - Config_selFgColor := + Config_fontSize := + Config_normBgColor := + Config_normFgColor := + Config_selBgColor := + Config_selFgColor := Config_barCommands := "Run, explore doc;Monitor_toggleBar();Main_reload();Reload;ExitApp" Config_readinBat := False Config_readinCpu := False @@ -44,7 +44,7 @@ Config_init() Config_readinNetworkLoad := False Config_readinTime := True Config_readinInterval := 30000 - + ;; Windows ui elements Config_bbCompatibility := False Config_borderWidth := 0 @@ -52,7 +52,7 @@ Config_init() Config_showTaskBar := False Config_showBorder := True Config_selBorderColor := "" - + ;; Window arrangement Config_viewNames := "1;2;3;4;5;6;7;8;9" Config_layout_#1 := "[]=;tile" @@ -72,7 +72,7 @@ Config_init() Config_shellMsgDelay := 350 Config_syncMonitorViews := 0 Config_viewFollowsTagged := False - + ;; Config_rule_# := ';;<style>;<is managed>;<m>;<tags>;<is floating>;<is decorated>;<hide title>;<action>' Config_rule_#1 := ".*;.*;;1;0;0;0;0;0;" ;; default rule Config_rule_#2 := ".*;.*;0x80000000;0;0;0;1;1;1;" ;; Pop-up windows (style WS_POPUP=0x80000000) will not be managed, are floating and the titles are hidden. @@ -87,18 +87,18 @@ Config_init() Config_rule_#11 := "MozillaWindowClass;.* - Mozilla Firefox;;1;0;0;0;1;0;Maximize" Config_rule_#12 := "Chrome_WidgetWin_1;.*;;1;0;0;0;1;0;Maximize" Config_ruleCount := 12 ;; This variable has to be set to the total number of active rules above. - + ;; Configuration management Config_autoSaveSession := False ; @todo: To be removed? If Not Config_filePath ; The file path, to which the configuration and session is saved. This target directory must be writable by the user (%A_ScriptDir% is the diretory, in which "Main.ahk" or the executable of bug.n is saved). Config_filePath := A_ScriptDir "\Config.ini" Config_maintenanceInterval := 5000 - + Config_restoreConfig(Config_filePath) Config_getSystemSettings() Config_initColors() - Loop, % Config_layoutCount + Loop, % Config_layoutCount { StringSplit, layout, Config_layout_#%A_Index%, `; Config_layoutFunction_#%A_Index% := layout2 @@ -115,76 +115,76 @@ Config_init() } } -Config_initColors() +Config_initColors() { Global - + StringReplace, Config_normBgColor, Config_normBgColor, `;0`;, `;000000`;, All Config_normBgColor := RegExReplace(Config_normBgColor, "^0;", "000000;") Config_normBgColor := RegExReplace(Config_normBgColor, ";0$", ";000000") StringSplit, Config_normBgColor, Config_normBgColor, `; - + StringReplace, Config_normFgColor, Config_normFgColor, `;0`;, `;000000`;, All Config_normFgColor := RegExReplace(Config_normFgColor, "^0;", "000000;") Config_normFgColor := RegExReplace(Config_normFgColor, ";0$", ";000000") StringSplit, Config_normFgColor, Config_normFgColor, `; - + StringReplace, Config_selBgColor, Config_selBgColor, `;0`;, `;000000`;, All Config_selBgColor := RegExReplace(Config_selBgColor, "^0;", "000000;") Config_selBgColor := RegExReplace(Config_selBgColor, ";0$", ";000000") StringSplit, Config_selBgColor, Config_selBgColor, `; - + StringReplace, Config_selFgColor, Config_selFgColor, `;0`;, `;000000`;, All Config_selFgColor := RegExReplace(Config_selFgColor, "^0;", "000000;") Config_selFgColor := RegExReplace(Config_selFgColor, ";0$", ";000000") StringSplit, Config_selFgColor, Config_selFgColor, `; } -Config_convertSystemColor(systemColor) +Config_convertSystemColor(systemColor) { ;; systemColor format: 0xBBGGRR rr := SubStr(systemColor, 7, 2) gg := SubStr(systemColor, 5, 2) bb := SubStr(systemColor, 3, 2) - + Return, rr gg bb } -Config_getSystemSettings() +Config_getSystemSettings() { Global Config_fontName, Config_fontSize, Config_normBgColor, Config_normFgColor, Config_selBgColor, Config_selFgColor - - If Not Config_fontName + + If Not Config_fontName { 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) - + VarSetCapacity(lf, 28 + 32 * (A_IsUnicode ? 2 : 1), 0) DllCall("RtlMoveMemory", "Str", lf, "UInt", &ncm + 24, "UInt", 28 + 32 * (A_IsUnicode ? 2 : 1)) VarSetCapacity(Config_fontName, 32 * (A_IsUnicode ? 2 : 1), 0) DllCall("RtlMoveMemory", "Str", Config_fontName, "UInt", &lf + 28, "UInt", 32 * (A_IsUnicode ? 2 : 1)) ;; maestrith: Script Writer (http://www.autohotkey.net/~maestrith/Script Writer/) } - If Not Config_fontSize + If Not Config_fontSize { 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) - + lfSize := VarSetCapacity(lf, 28 + 32 * (A_IsUnicode ? 2 : 1), 0) NumPut(lfSize, lf, 0, "UInt") DllCall("RtlMoveMemory", "Str", lf, "UInt", &ncm + 24, "UInt", 28 + 32 * (A_IsUnicode ? 2 : 1)) - + lfHeightSize := VarSetCapacity(lfHeight, 4, 0) NumPut(lfHeightSize, lfHeight, 0, "Int") lfHeight := NumGet(lf, 0, "Int") - + lfPixelsY := DllCall("GetDeviceCaps", "UInt", DllCall("GetDC", "UInt", 0), "UInt", 90) ;; LOGPIXELSY Config_fontSize := -DllCall("MulDiv", "Int", lfHeight, "Int", 72, "Int", lfPixelsY) ;; maestrith: Script Writer (http://www.autohotkey.net/~maestrith/Script Writer/) } SetFormat, Integer, hex - If Not Config_normBgColor + If Not Config_normBgColor { Config_normBgColor := Config_convertSystemColor(DllCall("GetSysColor", "Int", 4)) ;; COLOR_MENU Config_normBgColor .= ";" Config_convertSystemColor(DllCall("GetSysColor", "Int", 3)) ;; COLOR_INACTIVECAPTION @@ -192,7 +192,7 @@ Config_getSystemSettings() Config_normBgColor .= ";Red" Config_normBgColor .= ";" Config_convertSystemColor(DllCall("GetSysColor", "Int", 28)) ;; COLOR_GRADIENTINACTIVECAPTION } - If Not Config_normFgColor + If Not Config_normFgColor { Config_normFgColor := Config_convertSystemColor(DllCall("GetSysColor", "Int", 7)) ;; COLOR_MENUTEXT Config_normFgColor .= ";Default" @@ -203,11 +203,11 @@ Config_getSystemSettings() Config_normFgColor .= ";Default" Config_normFgColor .= ";" Config_convertSystemColor(DllCall("GetSysColor", "Int", 3)) ;; COLOR_INACTIVECAPTION } - If Not Config_selBgColor + If Not Config_selBgColor { Config_selBgColor := Config_convertSystemColor(DllCall("GetSysColor", "Int", 27)) ;; COLOR_GRADIENTACTIVECAPTION } - If Not Config_selFgColor + If Not Config_selFgColor { Config_selFgColor := Config_convertSystemColor(DllCall("GetSysColor", "Int", 9)) ;; COLOR_CAPTIONTEXT Config_selFgColor .= ";" Config_convertSystemColor(DllCall("GetSysColor", "Int", 2)) ;; COLOR_ACTIVECAPTION @@ -219,25 +219,25 @@ Config_hotkeyLabel: Config_redirectHotkey(A_ThisHotkey) Return -Config_readinAny() +Config_readinAny() { ;; Add information to the variable 'text' in this function to display it in the status bar. Global Config_readinDate - + text := "" text .= ResourceMonitor_getText() If Config_readinDate text .= " " A_DDD ", " A_DD ". " A_MMM ". " A_YYYY " " - + Return, text } -Config_redirectHotkey(key) +Config_redirectHotkey(key) { Global - + Loop, % Config_hotkeyCount { - If (key = Config_hotkey_#%A_index%_key) + If (key = Config_hotkey_#%A_index%_key) { Main_evalCommand(Config_hotkey_#%A_index%_command) Break @@ -245,13 +245,13 @@ Config_redirectHotkey(key) } } -Config_restoreLayout(filename, m) +Config_restoreLayout(filename, m) { Local i, var, val If Not FileExist(filename) Return - + Loop, READ, %filename% If (SubStr(A_LoopReadLine, 1, 10 + StrLen(m)) = "Monitor_#" m "_" Or SubStr(A_LoopReadLine, 1, 8 + StrLen(m)) = "View_#" m "_#") { i := InStr(A_LoopReadLine, "=") @@ -261,22 +261,22 @@ Config_restoreLayout(filename, m) } } -Config_restoreConfig(filename) +Config_restoreConfig(filename) { Local cmd, i, key, type, val, var - + If Not FileExist(filename) Return - + Loop, READ, %filename% - If (SubStr(A_LoopReadLine, 1, 7) = "Config_") + If (SubStr(A_LoopReadLine, 1, 7) = "Config_") { ;Log_msg("Processing line: " . A_LoopReadLine) i := InStr(A_LoopReadLine, "=") var := SubStr(A_LoopReadLine, 1, i - 1) val := SubStr(A_LoopReadLine, i + 1) type := SubStr(var, 1, 13) - If (type = "Config_hotkey") + If (type = "Config_hotkey") { Debug_logMessage("Processing configured hotkey: " . A_LoopReadLine, 0) i := InStr(val, "::") @@ -284,7 +284,7 @@ Config_restoreConfig(filename) cmd := SubStr(val, i + 2) If Not cmd Hotkey, %key%, Off - Else + Else { Debug_logMessage(" Hotkey: " . key . " -> " . cmd, 0) Config_hotkeyCount += 1 @@ -293,12 +293,12 @@ Config_restoreConfig(filename) Hotkey, %key%, Config_hotkeyLabel } } - Else If (type = "Config_rule") + Else If (type = "Config_rule") { i := 0 If InStr(var, "Config_rule_#") i := SubStr(var, 14) - If (i = 0 Or i > Config_ruleCount) + If (i = 0 Or i > Config_ruleCount) { Config_ruleCount += 1 i := Config_ruleCount @@ -309,20 +309,20 @@ Config_restoreConfig(filename) } } -Config_UI_saveSession() +Config_UI_saveSession() { Config_saveSession(Config_filePath, Config_filePath) } -Config_saveSession(original, target) +Config_saveSession(original, target) { Local m, text, tmpfilename - + tmpfilename := target . ".tmp" FileDelete, %tmpfilename% - + text := "; bug.n - tiling window management`n; @version " VERSION "`n`n" - If FileExist(original) + If FileExist(original) { Loop, READ, %original% { @@ -331,8 +331,8 @@ Config_saveSession(original, target) } text .= "`n" } - - Loop, % Manager_monitorCount + + Loop, % Manager_monitorCount { m := A_Index If Not (Monitor_#%m%_aView_#1 = 1) @@ -341,7 +341,7 @@ Config_saveSession(original, target) text .= "Monitor_#" m "_aView_#2=" Monitor_#%m%_aView_#2 "`n" If Not (Monitor_#%m%_showBar = Config_showBar) text .= "Monitor_#" m "_showBar=" Monitor_#%m%_showBar "`n" - Loop, % Config_viewCount + Loop, % Config_viewCount { If Not (View_#%m%_#%A_Index%_layout_#1 = 1) text .= "View_#" m "_#" A_Index "_layout_#1=" View_#%m%_#%A_Index%_layout_#1 "`n" @@ -363,11 +363,11 @@ Config_saveSession(original, target) text .= "View_#" m "_#" A_Index "_layoutMY=" View_#%m%_#%A_Index%_layoutMY "`n" } } - + ;; The FileMove below is an all-or-nothing replacement of the file. ;; We don't want to leave this half-finished. FileAppend, %text%, %tmpfilename% - If ErrorLevel + If ErrorLevel { If FileExist(tmpfilename) FileDelete, %tmpfilename% diff --git a/src/Debug.ahk b/src/Debug.ahk index 4ce748d..54f0758 100644 --- a/src/Debug.ahk +++ b/src/Debug.ahk @@ -1,27 +1,27 @@ /* 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 + + @version 8.4.0 */ -Debug_initLog(filename, level = 0, truncateFile = True) +Debug_initLog(filename, level = 0, truncateFile = True) { Global Debug_logFilename, Debug_logLevel - + Debug_logFilename := filename Debug_logLevel := level If truncateFile @@ -29,7 +29,7 @@ Debug_initLog(filename, level = 0, truncateFile = True) FileDelete, %Debug_logFilename% } -Debug_logHelp() +Debug_logHelp() { Debug_logMessage("Help Display", 0) Debug_logMessage("Window list columns", 0, False) @@ -51,13 +51,13 @@ Debug_logHelp() Debug_logMessage(" Proc / Class / Title - Process/Class/Title of the window.", 0, False) } -Debug_logManagedWindowList() +Debug_logManagedWindowList() { Local wndIds - + Debug_logMessage("Window dump for manager") Debug_logMessage("ID`t`tH W A F D R G M`tTags`tX`tY`tW`tH`tStyle`t`tProc / Class / Title", 0, False) - + StringTrimRight, wndIds, Manager_managedWndIds, 1 Loop, PARSE, wndIds, `; { @@ -65,13 +65,13 @@ Debug_logManagedWindowList() } } -Debug_logMessage(text, level = 1, includeTimestamp = True) +Debug_logMessage(text, level = 1, includeTimestamp = True) { Global Debug_logFilename, Debug_logLevel - + If (Debug_logLevel >= level) { - If includeTimestamp + If includeTimestamp { FormatTime, time, , yyyy-MM-dd HH:mm:ss text := time " " text @@ -82,14 +82,14 @@ Debug_logMessage(text, level = 1, includeTimestamp = True) } } -Debug_logViewWindowList() +Debug_logViewWindowList() { Local v, wndIds - + v := Monitor_#%Manager_aMonitor%_aView_#1 Debug_logMessage("Window dump for active view (" . Manager_aMonitor . ", " . v . ")") Debug_logMessage("ID`t`tH W A F D R G M`tTags`tX`tY`tW`tH`tStyle`t`tProc / Class / Title", 0, False) - + StringTrimRight, wndIds, View_#%Manager_aMonitor%_#%v%_wndIds, 1 Loop, PARSE, wndIds, `; { @@ -97,12 +97,12 @@ Debug_logViewWindowList() } } -Debug_logWindowInfo(wndId) +Debug_logWindowInfo(wndId) { Local aWndId, detect_state, text, v Local isBugnActive, isDecorated, isFloating, isGhost, isHidden, isResponsive, isWinFocus Local wndClass, wndH, wndProc, wndStyle, wndTitle, wndW, wndX, wndY - + detect_state := A_DetectHiddenWindows DetectHiddenWindows, On WinGet, aWndId, ID, A @@ -120,7 +120,7 @@ Debug_logWindowInfo(wndId) WinGet, wndProc, ProcessName, ahk_id %wndId% If InStr(Bar_hiddenWndIds, wndId) isHidden := "*" - Else + Else isHidden := " " If Manager_#%wndId%_isFloating isFloating := "*" @@ -137,13 +137,13 @@ Debug_logWindowInfo(wndId) Else isGhost := " " DetectHiddenWindows, %detect_state% - + ;; Intentionally don't detect hidden windows here to see what Manager_hungTest does If Manager_isHung(wndId) isResponsive := " " Else isResponsive := "*" - + text := wndId "`t" text .= isHidden " " isWinFocus " " isBugnActive " " isFloating " " isDecorated " " isResponsive " " isGhost " " text .= Manager_#%wndId%_monitor "`t" Manager_#%wndId%_tags "`t" @@ -151,10 +151,10 @@ Debug_logWindowInfo(wndId) Debug_logMessage(text , 0, False) } -Debug_setLogLevel(d) +Debug_setLogLevel(d) { Global Debug_logLevel - + i := Debug_logLevel + d If (i >= 0) { diff --git a/src/Main.ahk b/src/Main.ahk index d2a6b1a..522dc56 100644 --- a/src/Main.ahk +++ b/src/Main.ahk @@ -1,25 +1,25 @@ /* 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 + + @version 8.4.0 */ NAME := "bug.n" -VERSION := "8.3.0" +VERSION := "8.4.0" ;; Script settings OnExit, Main_cleanup @@ -38,22 +38,22 @@ SetWinDelay, 10 Main_dataDir = %A_ScriptDir% Main_setup() - + Debug_initLog(Main_appDir "\log.txt", 0, False) Debug_logMessage("====== Initializing ======") Config_filePath := Main_appDir "\Config.ini" Config_init() - + Menu, Tray, Tip, %NAME% %VERSION% IfExist %A_ScriptDir%\images\kfm.ico Menu, Tray, Icon, %A_ScriptDir%\images\kfm.ico Menu, Tray, NoStandard Menu, Tray, Add, Toggle bar, Main_toggleBar Menu, Tray, Add, Help, Main_help - Menu, Tray, Add, + Menu, Tray, Add, Menu, Tray, Add, Exit, Main_quit - + ResourceMonitor_init() Manager_init() Debug_logMessage("====== Running ======", 0) @@ -68,49 +68,49 @@ Main_cleanup: ResourceMonitor_cleanup() Debug_logMessage("====== Exiting bug.n ======", 0) ExitApp - -Main_evalCommand(command) + +Main_evalCommand(command) { type := SubStr(command, 1, 5) - If (type = "Run, ") + If (type = "Run, ") { parameters := SubStr(command, 6) - If InStr(parameters, ", ") + If InStr(parameters, ", ") { StringSplit, parameter, parameters, `, - If (parameter0 = 2) + If (parameter0 = 2) { StringTrimLeft, parameter2, parameter2, 1 Run, %parameter1%, %parameter2% - } - Else If (parameter0 > 2) + } + Else If (parameter0 > 2) { StringTrimLeft, parameter2, parameter2, 1 StringTrimLeft, parameter3, parameter3, 1 Run, %parameter1%, %parameter2%, %parameter3% } - } + } Else Run, %parameters% - } + } Else If (type = "Send ") Send % SubStr(command, 6) Else If (command = "Reload") Reload Else If (command = "ExitApp") ExitApp - Else + Else { i := InStr(command, "(") j := InStr(command, ")", False, i) - If i And j + If i And j { functionName := SubStr(command, 1, i - 1) functionArguments := SubStr(command, i + 1, j - (i + 1)) StringSplit, functionArgument, functionArguments, `, If (functionArgument0 < 2) %functionName%(functionArguments) - Else If (functionArgument0 = 2) + Else If (functionArgument0 = 2) { StringTrimLeft, functionArgument2, functionArgument2, 1 %functionName%(functionArgument1, functionArgument2) @@ -132,16 +132,16 @@ Main_makeDir(dirName) { IfNotExist, %dirName% { FileCreateDir, %dirName% - If ErrorLevel + If ErrorLevel { MsgBox, Error (%ErrorLevel%) when creating '%dirName%'. Aborting. ExitApp } } - Else + Else { FileGetAttrib, attrib, %dirName% - IfNotInString, attrib, D + IfNotInString, attrib, D { MsgBox, The file path '%dirName%' already exists and is not a directory. Aborting. ExitApp @@ -166,20 +166,20 @@ Main_setup() { Main_dataDir := Main_appDir . "\data" Main_autoLayout := Main_dataDir . "\_Layout.ini" Main_autoWindowState := Main_dataDir . "\_WindowState.ini" - + Main_makeDir(Main_appDir) Main_makeDir(Main_dataDir) } -Main_reload() +Main_reload() { Local i, ncm, ncmSize - + ;; Reset border color, padding and witdh. If Config_selBorderColor DllCall("SetSysColors", "Int", 1, "Int*", 10, "UInt*", Manager_normBorderColor) - If (Config_borderWidth > 0) Or (Config_borderPadding >= 0 And A_OSVersion = WIN_VISTA) + 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") @@ -192,7 +192,7 @@ Main_reload() } 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) - + Config_init() ; Windows UI If Config_selBorderColor { @@ -214,7 +214,7 @@ Main_reload() DllCall("SystemParametersInfo", "UInt", 0x002a, "UInt", ncmSize, "UInt", &ncm, "UInt", 0) } Bar_getHeight() - Loop, % Manager_monitorCount + Loop, % Manager_monitorCount { Monitor_getWorkArea(A_Index) Bar_init(A_Index) @@ -224,10 +224,10 @@ Main_reload() Monitor_toggleTaskBar() Bar_updateStatus() Bar_updateTitle() - Loop, % Manager_monitorCount + Loop, % Manager_monitorCount { i := A_Index - Loop, % Config_viewCount + Loop, % Config_viewCount { Bar_updateView(i, A_Index) } diff --git a/src/Manager.ahk b/src/Manager.ahk index 9b6fa38..81ecb97 100644 --- a/src/Manager.ahk +++ b/src/Manager.ahk @@ -1,32 +1,32 @@ /* 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 + + @version 8.4.0 */ -Manager_init() +Manager_init() { Global - + Manager_setWindowBorder() Bar_getHeight() ; axes, dimensions, percentage, flipped, gapWidth Manager_layoutDirty := 0 - ; New/closed windows, active changed, + ; New/closed windows, active changed, Manager_windowsDirty := 0 Manager_aMonitor := 1 Manager_taskBarMonitor := "" @@ -39,22 +39,22 @@ Manager_init() Bar_initCmdGui() If Not Config_showTaskBar Monitor_toggleTaskBar() - + Manager_focus := False Manager_hideShow := False Bar_hideTitleWndIds := "" Manager_allWndIds := "" Manager_managedWndIds := "" Manager_initial_sync() - + Bar_updateStatus() Bar_updateTitle() - Loop, % Manager_monitorCount + Loop, % Manager_monitorCount { View_arrange(A_Index, Monitor_#%A_Index%_aView_#1) Bar_updateView(A_Index, Monitor_#%A_Index%_aView_#1) } - + Manager_registerShellHook() SetTimer, Manager_maintenance_label, %Config_maintenanceInterval% SetTimer, Bar_loop, %Config_readinInterval% @@ -63,7 +63,7 @@ Manager_init() ; Asynchronous management of various WM properties. ; We want to make sure that we can recover the layout and windows in the event of ; unexpected problems. -; Periodically check for changes to these things and save them somewhere (not over +; Periodically check for changes to these things and save them somewhere (not over ; user-defined files). Manager_maintenance_label: @@ -73,7 +73,7 @@ Return Manager_maintenance() { Local tmp ;Debug_logMessage("Manager_maintenance", 2) - + ; @todo: Check for changes to the layout. ;If Manager_layoutDirty { ;Debug_logMessage("Saving layout state: " . Main_autoLayout, 0) @@ -91,11 +91,11 @@ Manager_maintenance() { ;} } -Manager_activateMonitor(d) +Manager_activateMonitor(d) { Local aView, aWndHeight, aWndId, aWndWidth, aWndX, aWndY, v, wndId - - If (Manager_monitorCount > 1) + + If (Manager_monitorCount > 1) { aView := Monitor_#%Manager_aMonitor%_aView_#1 aWndId := View_getActiveWindow(Manager_aMonitor, aView) @@ -105,11 +105,11 @@ Manager_activateMonitor(d) If (Monitor_get(aWndX + aWndWidth / 2, aWndY + aWndHeight / 2) = Manager_aMonitor) View_#%Manager_aMonitor%_#%aView%_aWndId := aWndId } - + Manager_aMonitor := Manager_loop(Manager_aMonitor, d, 1, Manager_monitorCount) v := Monitor_#%Manager_aMonitor%_aView_#1 wndId := View_#%Manager_aMonitor%_#%v%_aWndId - If Not (wndId And WinExist("ahk_id" wndId)) + 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) @@ -121,11 +121,11 @@ Manager_activateMonitor(d) } } -Manager_applyRules(wndId, ByRef isManaged, ByRef m, ByRef tags, ByRef isFloating, ByRef isDecorated, ByRef hideTitle, ByRef action) +Manager_applyRules(wndId, ByRef isManaged, ByRef m, ByRef tags, ByRef isFloating, ByRef isDecorated, ByRef hideTitle, ByRef action) { Local mouseX, mouseY, wndClass, wndHeight, wndStyle, wndTitle, wndWidth, wndX, wndY Local rule0, rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule8, rule9, rule10 - + isManaged := True m := 0 tags := 0 @@ -133,17 +133,17 @@ Manager_applyRules(wndId, ByRef isManaged, ByRef m, ByRef tags, ByRef isFloating isDecorated := False hideTitle := False action := "" - + WinGetClass, wndClass, ahk_id %wndId% WinGetTitle, wndTitle, ahk_id %wndId% WinGetPos, wndX, wndY, wndWidth, wndHeight, ahk_id %wndId% WinGet, wndStyle, Style, ahk_id %wndId% - If wndClass And wndTitle And Not (wndX < -4999) And Not (wndY < -4999) + If wndClass And wndTitle And Not (wndX < -4999) And Not (wndY < -4999) { - Loop, % Config_ruleCount + Loop, % Config_ruleCount { StringSplit, rule, Config_rule_#%A_index%, `; - If RegExMatch(wndClass . ";" . wndTitle, rule1 . ";" . rule2) And (rule3 = "" Or wndStyle & rule3) + If RegExMatch(wndClass . ";" . wndTitle, rule1 . ";" . rule2) And (rule3 = "" Or wndStyle & rule3) { ;; The last matching rule is returned. isManaged := rule4 m := rule5 @@ -154,8 +154,8 @@ Manager_applyRules(wndId, ByRef isManaged, ByRef m, ByRef tags, ByRef isFloating action := rule10 } } - } - Else + } + Else { isManaged := False If wndTitle @@ -163,14 +163,14 @@ Manager_applyRules(wndId, ByRef isManaged, ByRef m, ByRef tags, ByRef isFloating } } -Manager_cleanup() +Manager_cleanup() { Local aWndId, m, ncmSize, ncm, wndIds - + WinGet, aWndId, ID, A - + Manager_resetWindowBorder() - + ;; Show borders and title bars. StringTrimRight, wndIds, Manager_managedWndIds, 1 Manager_hideShow := True @@ -181,32 +181,32 @@ Manager_cleanup() Manager_winSet("Style", "+0x40000", A_LoopField) Manager_winSet("Style", "+0xC00000", A_LoopField) } - + ;; Show the task bar. WinShow, Start ahk_class Button WinShow, ahk_class Shell_TrayWnd Manager_hideShow := False - + ;; Reset windows position and size. Manager_showTaskBar := True - Loop, % Manager_monitorCount + Loop, % Manager_monitorCount { m := A_Index Monitor_#%m%_showBar := False Monitor_getWorkArea(m) - Loop, % Config_viewCount + Loop, % Config_viewCount { View_arrange(m, A_Index) } } Manager_winSet("AlwaysOnTop", "On", aWndId) Manager_winSet("AlwaysOnTop", "Off", aWndId) - + 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) } -Manager_closeWindow() +Manager_closeWindow() { Local aWndId, aview, c0 WinGet, aWndId, ID, A @@ -234,32 +234,32 @@ Manager_closeWindow() ;; Given a ghost window, try to find its body. ;; This is only known to work on Windows 7 -Manager_findHung(ghostWnd) +Manager_findHung(ghostWnd) { Local expectedH, expectedTitle, expectedW, expectedX, expectedY, wndH, wndIds, wndTitle, wndW, wndX, wndY - + WinGetTitle, expectedTitle, ahk_id %ghostWnd% - StringReplace, expectedTitle, expectedTitle, %Config_ghostWndSubString%, + StringReplace, expectedTitle, expectedTitle, %Config_ghostWndSubString%, WinGetPos, expectedX, expectedY, expectedW, expectedH, ahk_id %ghostWnd% - + SetTitleMatchMode, 2 WinGet, wndIds, List, %expectedTitle% - Loop, % wndIds + Loop, % wndIds { If (A_Index = ghostWnd) Continue WinGetPos, wndX, wndY, wndW, wndH, % "ahk_id" wndIDs%A_Index% - + If (wndX = expectedX) And (wndY = expectedY) And (wndW = expectedW) And (wndH = expectedH) Return wndIds%A_Index% } Return 0 } -Manager_getWindowInfo() +Manager_getWindowInfo() { Local text, v, aWndClass, aWndHeight, aWndId, aWndProcessName, aWndStyle, aWndTitle, aWndWidth, aWndX, aWndY - + WinGet, aWndId, ID, A WinGetClass, aWndClass, ahk_id %aWndId% WinGetTitle, aWndTitle, ahk_id %aWndId% @@ -277,15 +277,15 @@ Manager_getWindowInfo() Clipboard := text } -Manager_getWindowList() +Manager_getWindowList() { Local text, v, aWndId, wndIds, aWndTitle - + v := Monitor_#%Manager_aMonitor%_aView_#1 aWndId := View_#%Manager_aMonitor%_#%v%_aWndId WinGetTitle, aWndTitle, ahk_id %aWndId% text := "Active Window`n" aWndId ":`t" aWndTitle - + StringTrimRight, wndIds, View_#%Manager_aMonitor%_#%v%_wndIds, 1 text .= "`n`nWindow List" Loop, PARSE, wndIds, `; @@ -293,19 +293,19 @@ Manager_getWindowList() WinGetTitle, wndTitle, ahk_id %A_LoopField% text .= "`n" A_LoopField ":`t" wndTitle } - + MsgBox, 260, bug.n: Window List, % text "`n`nCopy text to clipboard?" IfMsgBox Yes Clipboard := text } -Manager_isGhost(wndId) +Manager_isGhost(wndId) { Local wndClass, wndProc - + WinGet, wndProc, ProcessName, ahk_id %wndId% WinGetClass, wndClass, ahk_id %wndId% - + If (wndProc = "dwm.exe") And (wndClass = "Ghost") Return 1 Else @@ -314,27 +314,27 @@ Manager_isGhost(wndId) ;; 0 - Not hung ;; 1 - Hung -Manager_isHung(wndId) +Manager_isHung(wndId) { Local detect_setting, result, WM_NULL - + WM_NULL := 0 detect_setting := A_DetectHiddenWindows DetectHiddenWindows, On SendMessage, WM_NULL, , , , ahk_id %wndId% result := ErrorLevel DetectHiddenWindows, %detect_setting% - + If result Return 1 Else Return 0 } -Manager_lockWorkStation() +Manager_lockWorkStation() { Global Config_shellMsgDelay - + RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, 0 Sleep, % Config_shellMsgDelay DllCall("LockWorkStation") @@ -343,7 +343,7 @@ Manager_lockWorkStation() } ;; Unambiguous: Re-use WIN+L as a hotkey in bug.n (http://www.autohotkey.com/community/viewtopic.php?p=500903&sid=eb3c7a119259b4015ff045ef80b94a81#p500903) -Manager_loop(index, increment, lowerBound, upperBound) +Manager_loop(index, increment, lowerBound, upperBound) { index += increment If (index > upperBound) @@ -352,37 +352,37 @@ Manager_loop(index, increment, lowerBound, upperBound) index := upperBound If (upperBound = 0) index := 0 - + Return, index } -Manager__setWinProperties(wndId, isManaged, m, tags, isDecorated, isFloating, hideTitle ) +Manager__setWinProperties(wndId, isManaged, m, tags, isDecorated, isFloating, hideTitle ) { Local a If Not Instr(Manager_allWndIds, wndId ";") Manager_allWndIds .= wndId ";" - If (isManaged) + If (isManaged) { Manager_managedWndIds .= wndId ";" Monitor_moveWindow(m, wndId) Manager_#%wndId%_tags := tags Manager_#%wndId%_isDecorated := isDecorated Manager_#%wndId%_isFloating := isFloating - + If Not Config_showBorder Manager_winSet("Style", "-0x40000", wndId) If Not Manager_#%wndId%_isDecorated Manager_winSet("Style", "-0xC00000", wndId) a := Manager_#%wndId%_tags & (1 << (Monitor_#%m%_aView_#1 - 1)) - If a + If a { Manager_aMonitor := m Manager_winActivate(wndId) - } - Else + } + Else { Manager_hideShow := True Manager_winHide(wndId) @@ -391,27 +391,27 @@ Manager__setWinProperties(wndId, isManaged, m, tags, isDecorated, isFloating, hi } If hideTitle Bar_hideTitleWndIds .= wndId . ";" - + Return, a } ;; Accept a window to be added to the system for management. ;; Provide a monitor and view preference, but don't override the config. -Manager_manage(preferredMonitor, preferredView, wndId) +Manager_manage(preferredMonitor, preferredView, wndId) { Local a, action, c0, hideTitle, i, isDecorated, isFloating, isManaged, l, m, n, replace, search, tags, body Local wndControlList0, wndId0, wndIds, wndX, wndY, wndWidth, wndHeight, wndProcessName - + ; Manage any window only once. If InStr(Manager_managedWndIds, wndId ";") Return - + body := 0 - If Manager_isGhost(wndId) + If Manager_isGhost(wndId) { Debug_logMessage("DEBUG[2] A window has given up the ghost (Ghost wndId: " . wndId . ")", 2) body := Manager_findHung(wndId) - If body + If body { isManaged := InStr(Manager_managedWndIds, body ";") m := Manager_#%body%_monitor @@ -421,14 +421,14 @@ Manager_manage(preferredMonitor, preferredView, wndId) hideTitle := InStr(Bar_hideTitleWndIds, body ";") action := "" } - Else + Else { Debug_logMessage("DEBUG[1] No body could be found for ghost wndId: " . wndId, 1) } } - + ;; Apply rules if the window is either a normal window or a ghost without a body. - If (body = 0) + If (body = 0) { Manager_applyRules(wndId, isManaged, m, tags, isFloating, isDecorated, hideTitle, action) If (m = 0) @@ -440,19 +440,19 @@ Manager_manage(preferredMonitor, preferredView, wndId) If (tags = 0) tags := 1 << (preferredView - 1) } - + ; @todo: Remove this application-specific code. WinGet, wndProcessName, ProcessName, ahk_id %wndId% - If (wndProcessName = "chrome.exe") + If (wndProcessName = "chrome.exe") { WinGet, wndControlList, ControlList, ahk_id %wndId% StringSplit, c, wndControlList, `n If (c0 <= 1) isManaged := False } - + a := Manager__setWinProperties( wndId, isManaged, m, tags, isDecorated, isFloating, hideTitle) - + ; Do view placement. If isManaged { Loop, % Config_viewCount @@ -461,39 +461,39 @@ Manager_manage(preferredMonitor, preferredView, wndId) ; Try to position near the body. View_ghostWindow(m, A_Index, body, wndId) } - Else + Else View_addWindow(m, A_Index, wndId) } } - + Return, a } -Manager_maximizeWindow() +Manager_maximizeWindow() { Local aWndId, l, v - + WinGet, aWndId, ID, A v := Monitor_#%Manager_aMonitor%_aView_#1 l := View_#%Manager_aMonitor%_#%v%_layout_#1 If Not Manager_#%aWndId%_isFloating And Not (Config_layoutFunction_#%l% = "") View_toggleFloating() Manager_winSet("Top", "", aWndId) - + Manager_winMove(aWndId, Monitor_#%Manager_aMonitor%_x, Monitor_#%Manager_aMonitor%_y, Monitor_#%Manager_aMonitor%_width, Monitor_#%Manager_aMonitor%_height) } -Manager_moveWindow() +Manager_moveWindow() { Local aWndId, l, SC_MOVE, v, WM_SYSCOMMAND - + WinGet, aWndId, ID, A v := Monitor_#%Manager_aMonitor%_aView_#1 l := View_#%Manager_aMonitor%_#%v%_layout_#1 If Not Manager_#%aWndId%_isFloating And Not (Config_layoutFunction_#%l% = "") View_toggleFloating() Manager_winSet("Top", "", aWndId) - + WM_SYSCOMMAND = 0x112 SC_MOVE = 0xF010 SendMessage, WM_SYSCOMMAND, SC_MOVE, , , ahk_id %aWndId% @@ -505,7 +505,7 @@ HSHELL_WINDOWDESTROYED := 2 HSHELL_WINDOWACTIVATED := 4 ;; At least title change. HSHELL_REDRAW := 6 -;; The following two are seen when a hung window recovers. +;; The following two are seen when a hung window recovers. ;; lParam notes the ghost process HSHELL_WINDOWREPLACED := 13 ;; lParam notes the recovered process @@ -522,10 +522,10 @@ WINDOW_NOTICE := 32774 4 - Window activated via mouse, alt+tab, or hotkey (sometimes 32772, but always one of them) 6 - Window title change (ID of redrawn window) 13 - Hung window recovers and replaces ghost window (ghost window ID is provided) - 14 - Hung window recovered (ID of previously hung window) + 14 - Hung window recovered (ID of previously hung window) 32772 - Window activated via mouse, alt+tab, or hotkey (sometimes 4, but always one of them) 32774 - Window is flashing due to some event, one message for each flash - + Indications of: New windows cmd/shell may be starting a new window on message 6 @@ -539,27 +539,27 @@ WINDOW_NOTICE := 32774 Focus change 4 or 32772 always catch this Window event - 6 indicates when title changes which can be used + 6 indicates when title changes which can be used in the case of some applications, 32774 works for others Windows events can't always be caught. */ Manager_onShellMessage(wParam, lParam) { Local a, isChanged, aWndClass, aWndHeight, aWndId, aWndTitle, aWndWidth, aWndX, aWndY, m, t, wndClass, wndId, wndIds, wndPName, wndTitle, x, y - + SetFormat, Integer, hex lParam := lParam+0 SetFormat, Integer, d - + Debug_logMessage("DEBUG[2] Manager_onShellMessage( wParam: " . wParam . ", lParam: " . lParam . " )", 2) - + WinGetClass, wndClass, ahk_id %lParam% WinGetTitle, wndTitle, ahk_id %lParam% WinGet, wndPName, ProcessName, ahk_id %lParam% - + WinGet, aWndId, ID, A WinGetClass, aWndClass, ahk_id %aWndId% WinGetTitle, aWndTitle, ahk_id %aWndId% - If ((wParam = 4 Or wParam = 32772) And lParam = 0 And aWndClass = "Progman" And aWndTitle = "Program Manager") + If ((wParam = 4 Or wParam = 32772) And lParam = 0 And aWndClass = "Progman" And aWndTitle = "Program Manager") { MouseGetPos, x, y m := Monitor_get(x, y) @@ -567,41 +567,41 @@ Manager_onShellMessage(wParam, lParam) { Manager_aMonitor := m Bar_updateTitle() } - - If (wParam = HSHELL_WINDOWREPLACED) + + If (wParam = HSHELL_WINDOWREPLACED) { ;; This shouldn't need a redraw because the window was supposedly replaced. Manager_unmanage(lParam) } -; If (wParam = 14) +; If (wParam = 14) ; { ;; Window recovered from being hung. Maybe force a redraw. ; } - + ;; @todo: There are two problems with the use of Manager_hideShow: ;; 1) If Manager_hideShow is set when we hit this block, we won't take some actions that should eventually be taken. ;; This _may_ explain why some windows never get picked up when spamming Win+e - ;; 2) There is a race condition between the time that Manager_hideShow is checked and any other action which we are - ;; trying to protect against. If another process (hotkey) enters a hideShow block after Manager_hideShow has + ;; 2) There is a race condition between the time that Manager_hideShow is checked and any other action which we are + ;; trying to protect against. If another process (hotkey) enters a hideShow block after Manager_hideShow has ;; been checked here, bad things could happen. I've personally observed that windows may be permanently hidden. ;; Look into the use of AHK synchronization primitives. - If (wParam = 1 Or wParam = 2 Or wParam = 4 Or wParam = 6 Or wParam = 32772) And lParam And Not Manager_hideShow And Not Manager_focus + If (wParam = 1 Or wParam = 2 Or wParam = 4 Or wParam = 6 Or wParam = 32772) And lParam And Not Manager_hideShow And Not Manager_focus { If Not wndClass And Not (wParam = 2 Or wParam = 4 Or wParam = 32772) { Sleep, %Config_shellMsgDelay% WinGetClass, wndClass, ahk_id %lParam% } - + isChanged := Manager_sync(wndIds) If wndIds isChanged := False - - If isChanged + + If isChanged { View_arrange(Manager_aMonitor, Monitor_#%Manager_aMonitor%_aView_#1) Bar_updateView(Manager_aMonitor, Monitor_#%Manager_aMonitor%_aView_#1) } - - If (Manager_monitorCount > 1) + + If (Manager_monitorCount > 1) { WinGet, aWndId, ID, A WinGetPos, aWndX, aWndY, aWndWidth, aWndHeight, ahk_id %aWndId% @@ -610,15 +610,15 @@ Manager_onShellMessage(wParam, lParam) { If m Manager_aMonitor := m } - - If wndIds + + If wndIds { ;; If there are new (unrecognized) windows, which are hidden ... - If (Config_onActiveHiddenWnds = "view") + If (Config_onActiveHiddenWnds = "view") { ;; ... change the view to show the first hidden window wndId := SubStr(wndIds, 1, InStr(wndIds, ";") - 1) Loop, % Config_viewCount { - If (Manager_#%wndId%_tags & 1 << A_Index - 1) + If (Manager_#%wndId%_tags & 1 << A_Index - 1) { Debug_logMessage("DEBUG[3] Switching views because " . wndId . " is considered hidden and active", 3) Manager_aMonitor := Manager_#%wndId%_monitor @@ -626,23 +626,23 @@ Manager_onShellMessage(wParam, lParam) { Break } } - } - Else + } + Else { ;; ... re-hide them StringTrimRight, wndIds, wndIds, 1 StringSplit, wndId, wndIds, `; - If (Config_onActiveHiddenWnds = "hide") + If (Config_onActiveHiddenWnds = "hide") { - Loop, % wndId0 + Loop, % wndId0 { Manager_winHide(wndId%A_Index%) } - } - Else If (Config_onActiveHiddenWnds = "tag") + } + Else If (Config_onActiveHiddenWnds = "tag") { ;; ... or tag all of them for the current view. t := Monitor_#%Manager_aMonitor%_aView_#1 - Loop, % wndId0 + Loop, % wndId0 { wndId := wndId%A_Index% View_#%Manager_aMonitor%_#%t%_wndIds := wndId ";" View_#%Manager_aMonitor%_#%t%_wndIds @@ -654,12 +654,12 @@ Manager_onShellMessage(wParam, lParam) { } } } - + Bar_updateTitle() } } -Manager_registerShellHook() +Manager_registerShellHook() { Gui, +LastFound hWnd := WinExist() @@ -669,13 +669,13 @@ Manager_registerShellHook() } ;; SKAN: How to Hook on to Shell to receive its messages? (http://www.autohotkey.com/forum/viewtopic.php?p=123323#123323) -Manager_resetWindowBorder() +Manager_resetWindowBorder() { Local ncm, ncmSize - + If Config_selBorderColor DllCall("SetSysColors", "Int", 1, "Int*", 10, "UInt*", Manager_normBorderColor) - If (Config_borderWidth > 0) Or (Config_borderPadding >= 0 And A_OSVersion = WIN_VISTA) + 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") @@ -688,37 +688,37 @@ Manager_resetWindowBorder() } } -Manager_setViewMonitor(d) +Manager_setViewMonitor(d) { Local aView, aWndId, m, v, wndIds - - If (Manager_monitorCount > 1) + + If (Manager_monitorCount > 1) { m := Manager_loop(Manager_aMonitor, d, 1, Manager_monitorCount) v := Monitor_#%m%_aView_#1 aView := Monitor_#%Manager_aMonitor%_aView_#1 - If View_#%Manager_aMonitor%_#%aView%_wndIds + If View_#%Manager_aMonitor%_#%aView%_wndIds { View_#%m%_#%v%_wndIds := View_#%Manager_aMonitor%_#%aView%_wndIds View_#%m%_#%v%_wndIds - + StringTrimRight, wndIds, View_#%Manager_aMonitor%_#%aView%_wndIds, 1 Loop, PARSE, wndIds, `; { - Loop, % Config_viewCount + Loop, % Config_viewCount { - 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_#%Manager_aMonitor%_#%A_Index%_aWndId := 0 } - + Monitor_moveWindow(m, A_LoopField) Manager_#%A_LoopField%_tags := 1 << v - 1 } View_arrange(Manager_aMonitor, aView) - Loop, % Config_viewCount + Loop, % Config_viewCount { Bar_updateView(Manager_aMonitor, A_Index) } - + Manager_aMonitor := m View_arrange(m, v) WinGet, aWndId, ID, A @@ -728,18 +728,18 @@ Manager_setViewMonitor(d) } } -Manager_setWindowBorder() +Manager_setWindowBorder() { Local ncm, ncmSize - - If Config_selBorderColor + + 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) + 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") @@ -754,22 +754,22 @@ Manager_setWindowBorder() } } -Manager_setWindowMonitor(d) +Manager_setWindowMonitor(d) { Local aWndId, v - + WinGet, aWndId, ID, A - If (Manager_monitorCount > 1 And InStr(Manager_managedWndIds, aWndId ";")) + If (Manager_monitorCount > 1 And InStr(Manager_managedWndIds, aWndId ";")) { - Loop, % Config_viewCount + Loop, % Config_viewCount { - StringReplace, View_#%Manager_aMonitor%_#%A_Index%_wndIds, View_#%Manager_aMonitor%_#%A_Index%_wndIds, %aWndId%`;, + StringReplace, View_#%Manager_aMonitor%_#%A_Index%_wndIds, View_#%Manager_aMonitor%_#%A_Index%_wndIds, %aWndId%`;, If (aWndId = View_#%Manager_aMonitor%_#%A_Index%_aWndId) View_#%Manager_aMonitor%_#%A_Index%_aWndId := 0 Bar_updateView(Manager_aMonitor, A_Index) } View_arrange(Manager_aMonitor, Monitor_#%Manager_aMonitor%_aView_#1) - + Manager_aMonitor := Manager_loop(Manager_aMonitor, d, 1, Manager_monitorCount) Monitor_moveWindow(Manager_aMonitor, aWndId) v := Monitor_#%Manager_aMonitor%_aView_#1 @@ -782,17 +782,17 @@ Manager_setWindowMonitor(d) } } -Manager_sizeWindow() +Manager_sizeWindow() { Local aWndId, l, SC_SIZE, v, WM_SYSCOMMAND - + WinGet, aWndId, ID, A v := Monitor_#%Manager_aMonitor%_aView_#1 l := View_#%Manager_aMonitor%_#%v%_layout_#1 If Not Manager_#%aWndId%_isFloating And Not (Config_layoutFunction_#%l% = "") View_toggleFloating() Manager_winSet("Top", "", aWndId) - + WM_SYSCOMMAND = 0x112 SC_SIZE = 0xF000 SendMessage, WM_SYSCOMMAND, SC_SIZE, , , ahk_id %aWndId% @@ -800,28 +800,28 @@ Manager_sizeWindow() ;; @todo: This constantly tries to re-add windows that are never going to be manageable. ;; Manager_manage should probably ignore all windows that are already in Manager_allWndIds. -Manager_sync(ByRef wndIds = "") +Manager_sync(ByRef wndIds = "") { Local a, flag, shownWndIds, v, visibleWndIds, wndId - - Loop, % Manager_monitorCount + + Loop, % Manager_monitorCount { v := Monitor_#%A_Index%_aView_#1 shownWndIds .= View_#%A_Index%_#%v%_wndIds } ;; Check all visible windows against the known windows - WinGet, wndId, List, , , - Loop, % wndId + WinGet, wndId, List, , , + Loop, % wndId { - If Not InStr(shownWndIds, wndId%A_Index% ";") + If Not InStr(shownWndIds, wndId%A_Index% ";") { - If Not InStr(Manager_managedWndIds, wndId%A_Index% ";") + If Not InStr(Manager_managedWndIds, wndId%A_Index% ";") { flag := Manager_manage(Manager_aMonitor, Monitor_#%Manager_aMonitor%_aView_#1, wndId%A_Index%) If flag a := flag - } - Else If Not Manager_isHung(wndId%A_Index%) + } + Else If Not Manager_isHung(wndId%A_Index%) { ;; This is a window that is already managed but was brought into focus by something. ;; Maybe it would be useful to do something with it. @@ -830,74 +830,74 @@ Manager_sync(ByRef wndIds = "") } visibleWndIds := visibleWndIds wndId%A_Index% ";" } - + ;; @todo-future: Find out why this unmanage code exists and if it's still needed. ;; check, if a window, that is known to be visible, is actually not visible StringTrimRight, shownWndIds, shownWndIds, 1 Loop, PARSE, shownWndIds, `; { - If Not InStr(visibleWndIds, A_LoopField) + If Not InStr(visibleWndIds, A_LoopField) { flag := Manager_unmanage(A_LoopField) If flag a := flag } } - + Return, a } -Manager_saveWindowState(filename, nm, nv) +Manager_saveWindowState(filename, nm, nv) { Local allWndId, allWndIds, process, title, text, monitor, wndId, view, isManaged, isTitleHidden - + text := "; bug.n - tiling window management`n; @version " VERSION "`n`n" - + tmpfname := filename . ".tmp" FileDelete, %tmpfname% - + ; Dump window ID and process name. If these two don't match an existing process, we won't try ; to recover that window. StringTrimRight, allWndIds, Manager_allWndIds, 1 StringSplit, allWndId, allWndIds, `; DetectHiddenWindows, On - Loop, % allWndId0 + Loop, % allWndId0 { wndId := allWndId%A_Index% WinGet, process, ProcessName, ahk_id %wndId% ; Include title for informative reasons. WinGetTitle, title, ahk_id %wndId% - + ; wndId;process;Tags;Floating;Decorated;HideTitle;Managed;Title - - If ( InStr(Manager_managedWndIds, wndId . ";") > 0 ) + + If ( InStr(Manager_managedWndIds, wndId . ";") > 0 ) { isManaged := 1 } - else + else { isManaged := 0 } - - If ( InStr(Bar_hideTitleWndIds, wndId . ";") > 0 ) + + If ( InStr(Bar_hideTitleWndIds, wndId . ";") > 0 ) isTitleHidden := 1 Else isTitleHidden := 0 - + text .= "Window " . wndId . ";" . process . ";" . Manager_#%wndId%_monitor . ";" . Manager_#%wndId%_tags . ";" . Manager_#%wndId%_isFloating . ";" . Manager_#%wndId%_isDecorated . ";" . isTitleHidden . ";" . isManaged . ";" . title . "`n" } DetectHiddenWindows, Off text .= "`n" - + ;; Dump window arrangements on every view. If some views or monitors have disappeared, leave their ;; corresponding windows alone. - - Loop, % nm + + Loop, % nm { monitor := A_Index - Loop, % nv + Loop, % nv { view := A_Index ;; Dump all view window lists @@ -906,7 +906,7 @@ Manager_saveWindowState(filename, nm, nv) } FileAppend, %text%, %tmpfname% - If ErrorLevel + If ErrorLevel { If FileExist(tmpfname) FileDelete, %tmpfname% @@ -918,23 +918,23 @@ Manager_saveWindowState(filename, nm, nv) ;; Restore previously saved window state. ;; If the state is completely different, this function won't do much. However, if restoring from a crash ;; or simply restarting bug.n, it should completely recover the window state. -Manager__restoreWindowState(filename) +Manager__restoreWindowState(filename) { Local vidx, widx, i, j, m, v, candidate_set, view_set, excluded_view_set, view_m0, view_v0, view_list0, wnds0, items0, wndProc, view_var, isManaged, isFloating, isDecorated, hideTitle - + If Not FileExist(filename) Return - + widx := 1 vidx := 1 - + view_set := "" excluded_view_set := "" - + ;; Read all interesting things from the file. Loop, READ, %filename% { - If (SubStr(A_LoopReadLine, 1, 5) = "View_") + If (SubStr(A_LoopReadLine, 1, 5) = "View_") { i := InStr(A_LoopReadLine, "#") j := InStr(A_LoopReadLine, "_", false, i) @@ -942,11 +942,11 @@ Manager__restoreWindowState(filename) i := InStr(A_LoopReadLine, "#", false, j) j := InStr(A_LoopReadLine, "_", false, i) v := SubStr(A_LoopReadLine, i + 1, j - i - 1) - + i := InStr(A_LoopReadLine, "=", j + 1) - - - If (m <= Manager_monitorCount) And ( v <= Config_viewCount ) + + + If (m <= Manager_monitorCount) And ( v <= Config_viewCount ) { view_list%vidx% := SubStr(A_LoopReadLine, i + 1) view_m%vidx% := m @@ -954,7 +954,7 @@ Manager__restoreWindowState(filename) view_set := view_set . view_list%vidx% vidx := vidx + 1 } - Else + Else { excluded_view_set := excluded_view_set . view_list%vidx% Debug_logMessage("View (" . m . ", " . v . ") is no longer available (" . vidx . ")", 0) @@ -965,49 +965,49 @@ Manager__restoreWindowState(filename) widx := widx + 1 } } - + ;Debug_logMessage("view_set: " . view_set, 1) ;Debug_logMessage("excluded_view_set: " . excluded_view_set, 1) - + candidate_set := "" - + ; Scan through all defined windows. Create a candidate set of windows based on whether the properties of existing windows match. - Loop, % (widx - 1) + Loop, % (widx - 1) { StringSplit, items, wnds%A_Index%, `; - If ( items0 < 9 ) + If ( items0 < 9 ) { Debug_logMessage("Window '" . wnds%A_Index% . "' could not be processed due to parse error", 0) Continue } - + i := 1 i := items%i% j := 2 - - + + DetectHiddenWindows, On WinGet, wndProc, ProcessName, ahk_id %i% DetectHiddenWindows, Off - If Not ( items%j% = wndProc ) + If Not ( items%j% = wndProc ) { Debug_logMessage("Window ahk_id " . i . " process '" . wndProc . "' doesn't match expected '" . items%j% . "', forgetting this window", 0) Continue } - + j := 8 isManaged := items%j% - + ; If Managed If ( items%j% ) { - If ( InStr(view_set, i) = 0) + If ( InStr(view_set, i) = 0) { - If ( InStr(excluded_view_set, i) ) + If ( InStr(excluded_view_set, i) ) { Debug_logMessage("Window ahk_id " . i . " is being ignored because it no longer belongs to an active view", 0) } - Else + Else { Debug_logMessage("Window ahk_id " . i . " is being ignored because it doesn't exist in any views", 0) } @@ -1016,7 +1016,7 @@ Manager__restoreWindowState(filename) } ; Set up the window. - + j := 3 m := items%j% j := 4 @@ -1027,21 +1027,21 @@ Manager__restoreWindowState(filename) isDecorated := items%j% j := 7 hideTitle := items%j% - + Manager__setWinProperties(i, isManaged, m, v, isDecorated, isFloating, hideTitle ) ;Manager_winHide(i) - + candidate_set := candidate_set . i . ";" } - + ;Debug_logMessage("candidate_set: " . candidate_set, 1) - + ; Set up all views. Must filter the window list by those from the candidate set. - Loop, % (vidx - 1) + Loop, % (vidx - 1) { StringSplit, items, view_list%A_Index%, `; view_set := "" - Loop, % items0 - 1 + Loop, % items0 - 1 { If ( InStr(candidate_set, items%A_Index% ) > 0 ) view_set := view_set . items%A_Index% . ";" @@ -1055,57 +1055,57 @@ Manager__restoreWindowState(filename) ; No windows are known to the system yet. ; Try to do something smart with the initial layout. -Manager_initial_sync() +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 + Loop, % Manager_monitorCount { Manager_initial_sync_m#%A_Index%_wndList := "" } - + ;; Use saved window placement settings to first determine ;; which monitor/view a window should be attached to. Manager__restoreWindowState(Main_autoWindowState) - + ;; Check all remaining visible windows against the known windows - WinGet, wndId, List, , , - Loop, % wndId + WinGet, wndId, List, , , + Loop, % wndId { - ;; Based on some analysis here, determine which monitors and layouts would best + ;; 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 Manager_initial_sync_m#%m%_wndList .= wndId%A_Index% ";" - + } - Loop, % Manager_monitorCount + Loop, % Manager_monitorCount { m := A_Index StringTrimRight, wndIds, Manager_initial_sync_m#%m%_wndList, 1 StringSplit, wndId, wndIds, `; - Loop, % wndId0 + Loop, % wndId0 { Manager_manage(m, 1, wndId%A_Index%) } } } -Manager_toggleDecor() +Manager_toggleDecor() { Local aWndId - + WinGet, aWndId, ID, A Manager_#%aWndId%_isDecorated := Not Manager_#%aWndId%_isDecorated If Manager_#%aWndId%_isDecorated @@ -1114,18 +1114,18 @@ Manager_toggleDecor() Manager_winSet("Style", "-0xC00000", aWndId) } -Manager_unmanage(wndId) +Manager_unmanage(wndId) { Local a - + ;; Do our best to make sure that any unmanaged windows are left visible. Manager_winShow(wndId) a := Manager_#%wndId%_tags & 1 << Monitor_#%Manager_aMonitor%_aView_#1 - 1 - Loop, % Config_viewCount + Loop, % Config_viewCount { - If (Manager_#%wndId%_tags & 1 << A_Index - 1) + If (Manager_#%wndId%_tags & 1 << A_Index - 1) { - StringReplace, View_#%Manager_aMonitor%_#%A_Index%_wndIds, View_#%Manager_aMonitor%_#%A_Index%_wndIds, %wndId%`;, + StringReplace, View_#%Manager_aMonitor%_#%A_Index%_wndIds, View_#%Manager_aMonitor%_#%A_Index%_wndIds, %wndId%`;, Bar_updateView(Manager_aMonitor, A_Index) } } @@ -1133,33 +1133,33 @@ Manager_unmanage(wndId) Manager_#%wndId%_tags := Manager_#%wndId%_isDecorated := Manager_#%wndId%_isFloating := - StringReplace, Bar_hideTitleWndIds, Bar_hideTitleWndIds, %wndId%`;, - StringReplace, Manager_allWndIds, Manager_allWndIds, %wndId%`;, + StringReplace, Bar_hideTitleWndIds, Bar_hideTitleWndIds, %wndId%`;, + StringReplace, Manager_allWndIds, Manager_allWndIds, %wndId%`;, StringReplace, Manager_managedWndIds, Manager_managedWndIds, %wndId%`;, , All - + Return, a } -Manager_winActivate(wndId) +Manager_winActivate(wndId) { Local aWndId, wndHeight, wndWidth, wndX, wndY - - If Config_mouseFollowsFocus + + If Config_mouseFollowsFocus { - If wndId + If wndId { WinGetPos, wndX, wndY, wndWidth, wndHeight, ahk_id %wndId% DllCall("SetCursorPos", "Int", Round(wndX + wndWidth / 2), "Int", Round(wndY + wndHeight / 2)) - } + } Else 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 wndId And Manager_isHung(wndId) + If wndId And Manager_isHung(wndId) { Debug_logMessage("DEBUG[2] Manager_winActivate: Potentially hung window " . wndId, 2) Return 1 } - Else + Else { Debug_logMessage("DEBUG[1] Activating window: " wndId, 1) If Not wndId @@ -1176,56 +1176,56 @@ Manager_winActivate(wndId) Return 0 } -Manager_winClose(wndId) +Manager_winClose(wndId) { - If Manager_isHung(wndId) + If Manager_isHung(wndId) { Debug_logMessage("DEBUG[2] Manager_winClose: Potentially hung window " . wndId, 2) Return 1 } - Else + Else { WinClose, ahk_id %wndId% Return 0 } } -Manager_winHide(wndId) +Manager_winHide(wndId) { - If Manager_isHung(wndId) + If Manager_isHung(wndId) { Debug_logMessage("DEBUG[2] Manager_winHide: Potentially hung window " . wndId, 2) Return 1 } - Else + Else { WinHide, ahk_id %wndId% Return 0 } } -Manager_winMaximize(wndId) +Manager_winMaximize(wndId) { - If Manager_isHung(wndId) + If Manager_isHung(wndId) { Debug_logMessage("DEBUG[2] Manager_winMaximize: Potentially hung window " . wndId, 2) Return 1 } - Else + Else { WinMaximize, ahk_id %wndId% Return 0 } } -Manager_winMove(wndId, x, y, width, height) +Manager_winMove(wndId, x, y, width, height) { - If Manager_isHung(wndId) + If Manager_isHung(wndId) { Debug_logMessage("DEBUG[2] Manager_winMove: Potentially hung window " . wndId, 2) Return 1 } - Else + Else { WinGet, wndMin, MinMax, ahk_id %wndId% If (wndMin = -1) @@ -1234,40 +1234,40 @@ Manager_winMove(wndId, x, y, width, height) WM_ENTERSIZEMOVE = 0x0231 WM_EXITSIZEMOVE = 0x0232 SendMessage, WM_ENTERSIZEMOVE, , , , ahk_id %wndId% - If ErrorLevel + If ErrorLevel { Debug_logMessage("DEBUG[2] Manager_winMove: Potentially hung window " . wndId, 1) Return 1 } - Else + Else { WinMove, ahk_id %wndId%, , %x%, %y%, %width%, %height% SendMessage, WM_EXITSIZEMOVE, , , , ahk_id %wndId% } } -Manager_winSet(type, value, wndId) +Manager_winSet(type, value, wndId) { - If Manager_isHung(wndId) + If Manager_isHung(wndId) { Debug_logMessage("DEBUG[2] Manager_winSet: Potentially hung window " . wndId, 2) Return 1 } - Else + Else { WinSet, %type%, %value%, ahk_id %wndId% Return 0 } } -Manager_winShow(wndId) +Manager_winShow(wndId) { - If Manager_isHung(wndId) + If Manager_isHung(wndId) { Debug_logMessage("DEBUG[2] Manager_winShow: Potentially hung window " . wndId, 2) Return 1 } - Else + Else { WinShow, ahk_id %wndId% Return 0 diff --git a/src/Monitor.ahk b/src/Monitor.ahk index 6da6bfb..4342626 100644 --- a/src/Monitor.ahk +++ b/src/Monitor.ahk @@ -1,31 +1,31 @@ /* 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 + + @version 8.4.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) } @@ -34,50 +34,50 @@ Monitor_init(m) Bar_init(m) } -Monitor_activateView(v) +Monitor_activateView(v) { Local aView, aWndId, m, n, wndId, wndIds - + If (v = -1) v := Monitor_#%Manager_aMonitor%_aView_#2 Else If (v = ">") v := Manager_loop(Monitor_#%Manager_aMonitor%_aView_#1, +1, 1, Config_viewCount) Else If (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_#%Manager_aMonitor%_#%v%_wndIds, 1) If (v <= 0) Or (v > Config_viewCount) Or Manager_hideShow Return ;; Re-arrange the windows on the active view. - If (v = Monitor_#%Manager_aMonitor%_aView_#1) + If (v = Monitor_#%Manager_aMonitor%_aView_#1) { View_arrange(Manager_aMonitor, v) Return } - + aView := Monitor_#%Manager_aMonitor%_aView_#1 aWndId := View_getActiveWindow(Manager_aMonitor, aView) If aWndId View_#%Manager_aMonitor%_#%aView%_aWndId := aWndId - + n := Config_syncMonitorViews If (n = 1) 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 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) @@ -88,95 +88,95 @@ Monitor_activateView(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 - + Bar_updateView(m, aView) Bar_updateView(m, v) } - + wndId := View_#%Manager_aMonitor%_#%v%_aWndId - If Not (wndId And WinExist("ahk_id" wndId)) + If Not (wndId And WinExist("ahk_id" wndId)) { - If View_#%Manager_aMonitor%_#%v%_wndIds + 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 wndId := 0 } Manager_winActivate(wndId) } -Monitor_get(x, y) +Monitor_get(x, y) { Local m - + m := 0 - Loop, % Manager_monitorCount + 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) + 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 - + SysGet, monitor, Monitor, %m% - + wndClasses := "Shell_TrayWnd" If Config_bbCompatibility wndClasses .= ";bbLeanBar;bbSlit;BBToolbar;SystemBarEx" 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) + + If (wndHeight < wndWidth) { ;; Horizontal - If (wndY <= monitorTop) + If (wndY <= monitorTop) { ;; Top wndHeight += wndY - monitorTop monitorTop += wndHeight If (A_LoopField = "Shell_TrayWnd") Manager_taskBarPos := "top" - } - Else + } + Else { ;; Bottom wndHeight := monitorBottom - wndY monitorBottom -= wndHeight } - } - Else + } + Else { ;; Vertical - If (wndX <= monitorLeft) + If (wndX <= monitorLeft) { ;; Left wndWidth += wndX monitorLeft += wndWidth - } - Else + } + Else { ;; Right wndWidth := monitorRight - wndX monitorRight -= wndWidth @@ -186,20 +186,20 @@ Monitor_getWorkArea(m) } } bTop := 0 - If Monitor_#%m%_showBar + If Monitor_#%m%_showBar { - If (Config_verticalBarPos = "top" Or (Config_verticalBarPos = "tray" And Not m = Manager_taskBarMonitor)) + 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 } } - + Monitor_#%m%_height := monitorBottom - monitorTop Monitor_#%m%_width := monitorRight - monitorLeft Monitor_#%m%_x := monitorLeft @@ -207,30 +207,30 @@ Monitor_getWorkArea(m) Monitor_#%m%_barY := bTop } -Monitor_moveWindow(m, wndId) +Monitor_moveWindow(m, wndId) { Global - + Manager_#%wndId%_monitor := m } -Monitor_setWindowTag(t) +Monitor_setWindowTag(t) { Local aView, aWndId, wndId - + If (t = ">") t := Manager_loop(Monitor_#%Manager_aMonitor%_aView_#1, +1, 1, Config_viewCount) Else If (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 (InStr(Manager_managedWndIds, aWndId ";") And t >= 0 And t <= Config_viewCount) { - If (t = 0) + If (t = 0) { - Loop, % Config_viewCount + Loop, % Config_viewCount { - If Not (Manager_#%aWndId%_tags & (1 << A_Index - 1)) + 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 @@ -238,26 +238,26 @@ Monitor_setWindowTag(t) Manager_#%aWndId%_tags += 1 << A_Index - 1 } } - } - Else + } + Else { - Loop, % Config_viewCount + Loop, % Config_viewCount { - If Not (A_index = t) + If Not (A_index = t) { - StringReplace, View_#%Manager_aMonitor%_#%A_Index%_wndIds, View_#%Manager_aMonitor%_#%A_Index%_wndIds, %aWndId%`;, + 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 View_#%Manager_aMonitor%_#%t%_aWndId := aWndId 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) @@ -265,7 +265,7 @@ Monitor_setWindowTag(t) Manager_hideShow := False If Config_viewFollowsTagged Monitor_activateView(t) - Else + Else { Manager_hideShow := True Manager_winHide(aWndId) @@ -278,10 +278,10 @@ Monitor_setWindowTag(t) } } -Monitor_toggleBar() +Monitor_toggleBar() { Global - + Monitor_#%Manager_aMonitor%_showBar := Not Monitor_#%Manager_aMonitor%_showBar Bar_toggleVisibility(Manager_aMonitor) Monitor_getWorkArea(Manager_aMonitor) @@ -289,21 +289,21 @@ 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 @@ -315,21 +315,21 @@ 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 (InStr(Manager_managedWndIds, aWndId ";") And t >= 0 And t <= Config_viewCount) { - If (Manager_#%aWndId%_tags & (1 << t - 1)) + If (Manager_#%aWndId%_tags & (1 << t - 1)) { - If Not ((Manager_#%aWndId%_tags - (1 << t - 1)) = 0) + 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%`;, + 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) @@ -339,8 +339,8 @@ 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 diff --git a/src/ResourceMonitor.ahk b/src/ResourceMonitor.ahk index fb6467e..43101f8 100644 --- a/src/ResourceMonitor.ahk +++ b/src/ResourceMonitor.ahk @@ -1,55 +1,55 @@ /* 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 + + @version 8.4.0 */ -ResourceMonitor_init() +ResourceMonitor_init() { ResourceMonitor_hDrive := DllCall("CreateFile", "Str", "\\.\PhysicalDrive0", "UInt", 0, "UInt", 3, "UInt", 0, "UInt", 3, "UInt", 0, "UInt", 0) ResourceMonitor_getNetworkInterface() } -ResourceMonitor_cleanup() +ResourceMonitor_cleanup() { DllCall("CloseHandle", "UInt", ResourceMonitor_hDrive) ;; used in ResourceMonitor_getDiskLoad } -ResourceMonitor_getText() +ResourceMonitor_getText() { Global Config_readinCpu, Config_readinDate, Config_readinDiskLoad, Config_readinMemoryUsage, Config_readinNetworkLoad - + text := "" If Config_readinCpu text .= " CPU: " ResourceMonitor_getSystemTimes() "% " - If Config_readinMemoryUsage + If Config_readinMemoryUsage { If Config_readinCpu text .= "|" text .= " RAM: " ResourceMonitor_getMemoryUsage() "% " } - If Config_readinDiskLoad + If Config_readinDiskLoad { If (Config_readinCpu Or Config_readinMemoryUsage) text .= "|" ResourceMonitor_getDiskLoad(rLoad, wLoad) text .= " Dr: " rLoad "% | Dw: " wLoad "% " } - If Config_readinNetworkLoad + If Config_readinNetworkLoad { If (Config_readinCpu Or Config_readinMemoryUsage Or Config_readinDiskLoad) text .= "|" @@ -58,19 +58,19 @@ ResourceMonitor_getText() } If Config_readinDate And (Config_readinCpu Or Config_readinMemoryUsage Or Config_readinDiskLoad Or Config_readinNetworkLoad) text .= "|" - + Return, text } -ResourceMonitor_getDiskLoad(ByRef readLoad, ByRef writeLoad) +ResourceMonitor_getDiskLoad(ByRef readLoad, ByRef writeLoad) { Global ResourceMonitor_hDrive Static oldReadCount, oldWriteCount - + dpSize := 5 * 8 + 4 + 4 + 4 + 4 + 8 + 4 + 8 * (A_IsUnicode ? 2 : 1) + 12 ;; 88? VarSetCapacity(dp, dpSize) DllCall("DeviceIoControl", "UInt", ResourceMonitor_hDrive, "UInt", 0x00070020, "UInt", 0, "UInt", 0, "UInt", &dp, "UInt", dpSize, "UIntP", nReturn, "UInt", 0) ;; IOCTL_DISK_PERFORMANCE - + newReadCount := NumGet(dp, 40) newWriteCount := NumGet(dp, 44) readLoad := SubStr(" " Round((1 - 1 / (1 + newReadCount - oldReadCount)) * 100), -2) @@ -81,7 +81,7 @@ ResourceMonitor_getDiskLoad(ByRef readLoad, ByRef writeLoad) ;; fures: System + Network monitor - with net history graph (http://www.autohotkey.com/community/viewtopic.php?p=260329) ;; SKAN: HDD Activity Monitoring LED (http://www.autohotkey.com/community/viewtopic.php?p=113890&sid=64d9824fdf252697ff4d5026faba91f8#p113890) -ResourceMonitor_getMemoryUsage() +ResourceMonitor_getMemoryUsage() { VarSetCapacity(memoryStatus, 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4) DllCall("kernel32.dll\GlobalMemoryStatus", "UInt", &memoryStatus) @@ -89,20 +89,20 @@ ResourceMonitor_getMemoryUsage() } ;; fures: System + Network monitor - with net history graph (http://www.autohotkey.com/community/viewtopic.php?p=260329) -ResourceMonitor_getNetworkInterface() +ResourceMonitor_getNetworkInterface() { Global ResourceMonitor_networkInterface, ResourceMonitor_networkInterfaceTable - + DllCall("iphlpapi\GetNumberOfInterfaces", "UIntP", n) nSize := 4 + 860 * n + 8 VarSetCapacity(ResourceMonitor_networkInterfaceTable, nSize) - If Not DllCall("iphlpapi\GetIfTable", "UInt", &ResourceMonitor_networkInterfaceTable, "UIntP", nSize, "Int", False) + If Not DllCall("iphlpapi\GetIfTable", "UInt", &ResourceMonitor_networkInterfaceTable, "UIntP", nSize, "Int", False) { - Loop, 2 + Loop, 2 { i := 0 j := A_Index - Loop, % NumGet(ResourceMonitor_networkInterfaceTable) + Loop, % NumGet(ResourceMonitor_networkInterfaceTable) { If NumGet(ResourceMonitor_networkInterfaceTable, 4 + 860 * (A_Index - 1) + 544) < 4 || NumGet(ResourceMonitor_networkInterfaceTable, 4 + 860 * (A_Index - 1) + 516) = 24 @@ -114,10 +114,10 @@ ResourceMonitor_getNetworkInterface() If (A_Index < 2) RunWait, %Comspec% /c ping -n 1 127.0.0.1, , hide } - + Loop, % i { - If (dn_#%i%_#2 > dn_#%i%_1) + If (dn_#%i%_#2 > dn_#%i%_1) { ResourceMonitor_networkInterface := i Break @@ -127,27 +127,27 @@ ResourceMonitor_getNetworkInterface() } ;; fures: System + Network monitor - with net history graph (http://www.autohotkey.com/community/viewtopic.php?p=260329) -ResourceMonitor_getNetworkLoad(ByRef upLoad, ByRef dnLoad) +ResourceMonitor_getNetworkLoad(ByRef upLoad, ByRef dnLoad) { Global ResourceMonitor_networkInterface, ResourceMonitor_networkInterfaceTable Static dn_#0, t_#0, up_#0 - + DllCall("iphlpapi\GetIfEntry", "UInt", &ResourceMonitor_networkInterfaceTable + 4 + 860 * (ResourceMonitor_networkInterface - 1)) dn_#1 := NumGet(ResourceMonitor_networkInterfaceTable, 4 + 860 * (ResourceMonitor_networkInterface - 1) + 552) ;; Total Incoming Bytes up_#1 := NumGet(ResourceMonitor_networkInterfaceTable, 4 + 860 * (ResourceMonitor_networkInterface - 1) + 576) ;; Total Outgoing Bytes tDiff := (A_TickCount - t_#0) / 1000 t_#0 := A_TickCount - + dnLoad := SubStr(" " Round((dn_#1 - dn_#0) / 1024 / tDiff), -3) upLoad := SubStr(" " Round((up_#1 - up_#0) / 1024 / tDiff), -3) - + dn_#0 := dn_#1 up_#0 := up_#1 } ;; fures: System + Network monitor - with net history graph (http://www.autohotkey.com/community/viewtopic.php?p=260329) ;; Sean: Network Download/Upload Meter (http://www.autohotkey.com/community/viewtopic.php?t=18033) -ResourceMonitor_getSystemTimes() +ResourceMonitor_getSystemTimes() { ;; Total CPU Load Static oldIdleTime, oldKrnlTime, oldUserTime Static newIdleTime, newKrnlTime, newUserTime diff --git a/src/View.ahk b/src/View.ahk index 9b66e6b..c90b63e 100644 --- a/src/View.ahk +++ b/src/View.ahk @@ -1,27 +1,27 @@ /* 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 + + @version 8.4.0 */ -View_init(m, v) +View_init(m, v) { Global - + View_#%m%_#%v%_aWndId := 0 View_#%m%_#%v%_layout_#1 := 1 View_#%m%_#%v%_layout_#2 := 1 @@ -38,14 +38,14 @@ View_init(m, v) View_#%m%_#%v%_wndIds := "" } -View_activateWindow(d) +View_activateWindow(d) { Local aWndId, direction, failure, i, j, v, wndId, wndId0, wndIds - + Debug_logMessage("DEBUG[1] View_activateWindow(" . d . ")", 1) If (d = 0) Return - + WinGet, aWndId, ID, A Debug_logMessage("DEBUG[2] Active Windows ID: " . aWndId, 2, False) v := Monitor_#%Manager_aMonitor%_aView_#1 @@ -53,55 +53,55 @@ View_activateWindow(d) StringTrimRight, wndIds, View_#%Manager_aMonitor%_#%v%_wndIds, 1 StringSplit, wndId, wndIds, `; Debug_logMessage("DEBUG[2] wndId count: " . wndId0, 2, False) - If (wndId0 > 1) + If (wndId0 > 1) { If Manager_#%aWndId%_isFloating Manager_winSet("Bottom", "", aWndId) - Loop, % wndId0 + Loop, % wndId0 { - If (wndId%A_Index% = aWndId) + If (wndId%A_Index% = aWndId) { i := A_Index Break } } Debug_logMessage("DEBUG[2] Current wndId index: " . i, 2, False) - - If (d > 0) + + If (d > 0) direction = 1 Else direction = -1 j := Manager_loop(i, d, 1, wndId0) - Loop, % wndId0 + Loop, % wndId0 { Debug_logMessage("DEBUG[2] Next wndId index: " . j, 2, False) wndId := wndId%j% Manager_winSet("AlwaysOnTop", "On", wndId) Manager_winSet("AlwaysOnTop", "Off", wndId) - + ;; If there are hung windows on the screen, we still want to be able to cycle through them. failure := Manager_winActivate(wndId) - If Not failure + If Not failure Break j := Manager_loop(j, direction, 1, wndId0) } } } -View_addWindow(m, v, wndId) +View_addWindow(m, v, wndId) { Local i, l, mSplit, n, replace, search - + l := View_#%m%_#%v%_layout_#1 - If (Config_layoutFunction_#%l% = "tile") And ((Config_newWndPosition = "masterBottom") Or (Config_newWndPosition = "stackTop")) + If (Config_layoutFunction_#%l% = "tile") And ((Config_newWndPosition = "masterBottom") Or (Config_newWndPosition = "stackTop")) { n := View_getTiledWndIds(m, v) mSplit := View_#%m%_#%v%_layoutMX * View_#%m%_#%v%_layoutMY - If (mSplit = 1 And Config_newWndPosition = "masterBottom") + If (mSplit = 1 And Config_newWndPosition = "masterBottom") View_#%m%_#%v%_wndIds := wndId ";" . View_#%m%_#%v%_wndIds - Else If ((Config_newWndPosition = "masterBottom" And n < mSplit) Or (Config_newWndPosition = "stackTop" And n <= mSplit)) + Else If ((Config_newWndPosition = "masterBottom" And n < mSplit) Or (Config_newWndPosition = "stackTop" And n <= mSplit)) View_#%m%_#%v%_wndIds .= wndId ";" - Else + Else { If (Config_newWndPosition = "masterBottom") i := mSplit - 1 @@ -118,21 +118,21 @@ View_addWindow(m, v, wndId) View_#%m%_#%v%_wndIds := wndId ";" View_#%m%_#%v%_wndIds } -View_arrange(m, v) +View_arrange(m, v) { Local fn, h, l, w, x, y Debug_logMessage("DEBUG[1] View_arrange(" . m . ", " . v . ")", 1) - + l := View_#%m%_#%v%_layout_#1 fn := Config_layoutFunction_#%l% - If fn + If fn { x := Monitor_#%m%_x + View_#%m%_#%v%_layoutGapWidth + View_#%m%_#%v%_margin4 y := Monitor_#%m%_y + View_#%m%_#%v%_layoutGapWidth + View_#%m%_#%v%_margin1 w := Monitor_#%m%_width - 2 * View_#%m%_#%v%_layoutGapWidth - View_#%m%_#%v%_margin4 - View_#%m%_#%v%_margin2 h := Monitor_#%m%_height - 2 * View_#%m%_#%v%_layoutGapWidth - View_#%m%_#%v%_margin1 - View_#%m%_#%v%_margin3 - + ;; All window actions are performed on independent windows. A delay won't help. SetWinDelay, 0 View_getTiledWndIds(m, v) @@ -141,30 +141,30 @@ View_arrange(m, v) } Else ;; floating layout (no 'View_arrange_', following is 'View_getLayoutSymbol_')' View_#%m%_#%v%_layoutSymbol := Config_layoutSymbol_#%l% - + Bar_updateLayout(m) } -View_arrange_monocle(m, v, x, y, w, h) +View_arrange_monocle(m, v, x, y, w, h) { Global - + ;; 'View_getLayoutSymbol_monocle' View_#%m%_#%v%_layoutSymbol := "[" View_tiledWndId0 "]" ;; 'View_arrange_monocle' View_stackWindows("View_tiledWndId", 1, View_tiledWndId0, +1, 3, x, y, w, h, 0) } -View_arrange_tile(m, v, x, y, w, h) +View_arrange_tile(m, v, x, y, w, h) { Local axis1, axis2, axis3, flipped, gapW, h1, h2, mFact, mSplit, mWndCount, mXSet, mYActual, mYSet, stackLen, subAreaCount, subAreaWndCount, subH1, subW1, subX1, subY1, w1, w2, x1, x2, y1, y2 - + View_#%m%_#%v%_layoutSymbol := View_getLayoutSymbol_tile(m, v, View_tiledWndId0) - + Debug_logMessage("DEBUG[1] View_arrange_tile: (" . View_tiledWndId0 . ") ", 1) If (View_tiledWndId0 = 0) Return - + axis1 := Abs(View_#%m%_#%v%_layoutAxis_#1) axis2 := View_#%m%_#%v%_layoutAxis_#2 axis3 := View_#%m%_#%v%_layoutAxis_#3 @@ -176,20 +176,20 @@ View_arrange_tile(m, v, x, y, w, h) mSplit := mXSet * mYSet If (mSplit > View_tiledWndId0) mSplit := View_tiledWndId0 - + ;; Areas (master and stack) x1 := x y1 := y w1 := w h1 := h - If (View_tiledWndId0 > mSplit) + If (View_tiledWndId0 > mSplit) { ;; There is a stack area. If flipped View_splitArea(axis1 - 1, 1 - mFact, x1, y1, w1, h1, gapW, x2, y2, w2, h2, x1, y1, w1, h1) Else View_splitArea(axis1 - 1, mFact, x1, y1, w1, h1, gapW, x1, y1, w1, h1, x2, y2, w2, h2) } - + ;; Master If (axis2 = 3) View_stackWindows("View_tiledWndId", 1, mSplit, +1, 3, x1, y1, w1, h1, 0) @@ -198,7 +198,7 @@ View_arrange_tile(m, v, x, y, w, h) mYActual := Ceil(mSplit / mXSet) subAreaCount := mYActual mWndCount := mSplit - Loop, % mYActual + Loop, % mYActual { View_splitArea(Not (axis2 - 1), 1 / subAreaCount, x1, y1, w1, h1, gapW, subX1, subY1, subW1, subH1, x1, y1, w1, h1) subAreaWndCount := mXSet @@ -209,16 +209,16 @@ View_arrange_tile(m, v, x, y, w, h) subAreaCount -= 1 } } - + ;; Stack - If (View_tiledWndId0 <= mSplit) + If (View_tiledWndId0 <= mSplit) Return - + stackLen := View_tiledWndId0 - mSplit ;; 161 is the minimal width of an Windows-Explorer window, below which it cannot be resized. - ;; The minimal height is 243, but this seems too high for being a limit here; + ;; The minimal height is 243, but this seems too high for being a limit here; ;; therefor '2 * Bar_height' is used for the minimal height of a window. - If (axis3 = 3 Or (axis3 = 1 And (w2 - (stackLen - 1) * gapW) / stackLen < 161) Or (axis3 = 2 And (h2 - (stackLen - 1) * gapW) / stackLen < 2 * Bar_height)) + If (axis3 = 3 Or (axis3 = 1 And (w2 - (stackLen - 1) * gapW) / stackLen < 161) Or (axis3 = 2 And (h2 - (stackLen - 1) * gapW) / stackLen < 2 * Bar_height)) View_stackWindows("View_tiledWndId", mSplit + 1, stackLen, +1, 3, x2, y2, w2, h2, 0) Else View_stackWindows("View_tiledWndId", mSplit + 1, stackLen, +1, axis3, x2, y2, w2, h2, gapW) @@ -227,9 +227,9 @@ View_arrange_tile(m, v, x, y, w, h) View_getActiveWindow(m, v) { Local aWndClass, aWndId, aWndTitle - + WinGet, aWndId, ID, A - If WinExist("ahk_id" aWndId) And InStr(View_#%m%_#%v%_wndIds, aWndId ";") + If WinExist("ahk_id" aWndId) And InStr(View_#%m%_#%v%_wndIds, aWndId ";") { WinGetClass, aWndClass, ahk_id %aWndId% WinGetTitle, aWndTitle, ahk_id %aWndId% @@ -239,10 +239,10 @@ View_getActiveWindow(m, v) Return, 0 } -View_getLayoutSymbol_tile(m, v, n) +View_getLayoutSymbol_tile(m, v, n) { Local axis1, axis2, axis3, masterDim, masterDiv, mx, my, stackSym - + ;; Main axis ;; 1 - vertical divider, master left ;; 2 - horizontal divider, master top @@ -261,39 +261,39 @@ View_getLayoutSymbol_tile(m, v, n) axis3 := View_#%m%_#%v%_layoutAxis_#3 mx := View_#%m%_#%v%_layoutMX my := View_#%m%_#%v%_layoutMY - - If (Abs(axis1) = 1) + + If (Abs(axis1) = 1) masterDiv := "|" - Else + Else masterDiv := "-" - If (axis2 = 1) + If (axis2 = 1) masterDim := mx . "x" . my - Else If (axis2 = 2) + Else If (axis2 = 2) masterDim := mx . "x" . my - Else + Else masterDim := "[" . (mx * my) . "]" - + If (axis3 = 1) stackSym := "|" Else If (axis3 = 2) stackSym := "=" Else stackSym := n - (mx * my) - + If (axis1 > 0) Return, masterDim . masterDiv . stackSym Else Return, stackSym . masterDiv . masterDim } -View_getTiledWndIds(m, v) +View_getTiledWndIds(m, v) { Local n, tiledWndIds, wndIds - + StringTrimRight, wndIds, View_#%m%_#%v%_wndIds, 1 Loop, PARSE, wndIds, `; { - If Not Manager_#%A_LoopField%_isFloating And WinExist("ahk_id " A_LoopField) and Not Manager_isHung(A_LoopField) + If Not Manager_#%A_LoopField%_isFloating And WinExist("ahk_id " A_LoopField) and Not Manager_isHung(A_LoopField) { n += 1 tiledWndIds .= A_LoopField ";" @@ -301,44 +301,44 @@ View_getTiledWndIds(m, v) } StringTrimRight, tiledWndIds, tiledWndIds, 1 StringSplit, View_tiledWndId, tiledWndIds, `; - + Return, n } -View_ghostWindow(m, v, bodyWndId, ghostWndId) +View_ghostWindow(m, v, bodyWndId, ghostWndId) { Local search, replace - + search := bodyWndId ";" replace := search ghostWndId ";" StringReplace, View_#%m%_#%v%_wndIds, View_#%m%_#%v%_wndIds, %search%, %replace% } -View_rotateLayoutAxis(i, d) +View_rotateLayoutAxis(i, d) { Local f, l, n, tmp, v - + v := Monitor_#%Manager_aMonitor%_aView_#1 l := View_#%Manager_aMonitor%_#%v%_layout_#1 - If (Config_layoutFunction_#%l% = "tile") And (i = 1 Or i = 2 Or i = 3) + If (Config_layoutFunction_#%l% = "tile") And (i = 1 Or i = 2 Or i = 3) { - If (i = 1) + If (i = 1) { If (d = +2) View_#%Manager_aMonitor%_#%v%_layoutAxis_#%i% *= -1 - Else + Else { f := View_#%Manager_aMonitor%_#%v%_layoutAxis_#%i% / Abs(View_#%Manager_aMonitor%_#%v%_layoutAxis_#%i%) View_#%Manager_aMonitor%_#%v%_layoutAxis_#%i% := f * Manager_loop(Abs(View_#%Manager_aMonitor%_#%v%_layoutAxis_#%i%), d, 1, 2) } - } - Else + } + Else { n := Manager_loop(View_#%Manager_aMonitor%_#%v%_layoutAxis_#%i%, d, 1, 3) ;; When we rotate the axis, we may need to swap the X and Y dimensions. ;; We only need to check this when the master axis changes (i = 2) ;; If the original axis was 1 (X) or the new axis is 1 (X) (Y and Z are defined to be the same) - If (i = 2) And Not (n = View_#%Manager_aMonitor%_#%v%_layoutAxis_#%i%) And (n = 1 Or View_#%Manager_aMonitor%_#%v%_layoutAxis_#%i% = 1) + If (i = 2) And Not (n = View_#%Manager_aMonitor%_#%v%_layoutAxis_#%i%) And (n = 1 Or View_#%Manager_aMonitor%_#%v%_layoutAxis_#%i% = 1) { tmp := View_#%Manager_aMonitor%_#%v%_layoutMX View_#%Manager_aMonitor%_#%v%_layoutMX := View_#%Manager_aMonitor%_#%v%_layoutMY @@ -350,20 +350,20 @@ View_rotateLayoutAxis(i, d) } } -View_setGapWidth(d) +View_setGapWidth(d) { Local l, v, w - + v := Monitor_#%Manager_aMonitor%_aView_#1 l := View_#%Manager_aMonitor%_#%v%_layout_#1 - If (Config_layoutFunction_#%l% = "tile" Or Config_layoutFunction_#%l% = "monocle") + If (Config_layoutFunction_#%l% = "tile" Or Config_layoutFunction_#%l% = "monocle") { If (d < 0) d := Floor(d / 2) * 2 Else d := Ceil(d / 2) * 2 w := View_#%Manager_aMonitor%_#%v%_layoutGapWidth + d - If (w < Monitor_#%Manager_aMonitor%_height And w < Monitor_#%Manager_aMonitor%_width) + If (w < Monitor_#%Manager_aMonitor%_height And w < Monitor_#%Manager_aMonitor%_width) { View_#%Manager_aMonitor%_#%v%_layoutGapWidth := w View_arrange(Manager_aMonitor, v) @@ -371,18 +371,18 @@ View_setGapWidth(d) } } -View_setLayout(l) +View_setLayout(l) { Local v - + v := Monitor_#%Manager_aMonitor%_aView_#1 If (l = -1) l := View_#%Manager_aMonitor%_#%v%_layout_#2 If (l = ">") l := Manager_loop(View_#%Manager_aMonitor%_#%v%_layout_#1, +1, 1, Config_layoutCount) - If (l > 0) And (l <= Config_layoutCount) + If (l > 0) And (l <= Config_layoutCount) { - If Not (l = View_#%Manager_aMonitor%_#%v%_layout_#1) + If Not (l = View_#%Manager_aMonitor%_#%v%_layout_#1) { View_#%Manager_aMonitor%_#%v%_layout_#2 := View_#%Manager_aMonitor%_#%v%_layout_#1 View_#%Manager_aMonitor%_#%v%_layout_#1 := l @@ -391,20 +391,20 @@ View_setLayout(l) } } -View_setMFactor(d) +View_setMFactor(d) { Local l, mFact, v - + v := Monitor_#%Manager_aMonitor%_aView_#1 l := View_#%Manager_aMonitor%_#%v%_layout_#1 - If (Config_layoutFunction_#%l% = "tile") + If (Config_layoutFunction_#%l% = "tile") { mFact := 0 If (d >= 1.05) mFact := d Else mFact := View_#%Manager_aMonitor%_#%v%_layoutMFact + d - If (mFact >= 0.05 And mFact <= 0.95) + If (mFact >= 0.05 And mFact <= 0.95) { View_#%Manager_aMonitor%_#%v%_layoutMFact := mFact View_arrange(Manager_aMonitor, v) @@ -412,55 +412,55 @@ View_setMFactor(d) } } -View_setMX(d) +View_setMX(d) { Local l, n, v - + v := Monitor_#%Manager_aMonitor%_aView_#1 l := View_#%Manager_aMonitor%_#%v%_layout_#1 If Not (Config_layoutFunction_#%l% = "tile") Return - + n := View_#%Manager_aMonitor%_#%v%_layoutMX + d - If (n >= 1) And (n <= 9) + If (n >= 1) And (n <= 9) { View_#%Manager_aMonitor%_#%v%_layoutMX := n View_arrange(Manager_aMonitor, v) } } -View_setMY(d) +View_setMY(d) { Local l, n, v - + v := Monitor_#%Manager_aMonitor%_aView_#1 l := View_#%Manager_aMonitor%_#%v%_layout_#1 If Not (Config_layoutFunction_#%l% = "tile") Return - + n := View_#%Manager_aMonitor%_#%v%_layoutMY + d - If (n >= 1) And (n <= 9) + If (n >= 1) And (n <= 9) { View_#%Manager_aMonitor%_#%v%_layoutMY := n View_arrange(Manager_aMonitor, v) } } -View_shuffleWindow(d) +View_shuffleWindow(d) { Local aWndHeight, aWndId, aWndWidth, aWndX, aWndY, i, j, l, search, v - + WinGet, aWndId, ID, A v := Monitor_#%Manager_aMonitor%_aView_#1 l := View_#%Manager_aMonitor%_#%v%_layout_#1 - If (Config_layoutFunction_#%l% = "tile" And InStr(Manager_managedWndIds, aWndId ";")) + If (Config_layoutFunction_#%l% = "tile" And InStr(Manager_managedWndIds, aWndId ";")) { View_getTiledWndIds(Manager_aMonitor, v) - If (View_tiledWndId0 > 1) + If (View_tiledWndId0 > 1) { - Loop, % View_tiledWndId0 + Loop, % View_tiledWndId0 { - If (View_tiledWndId%A_Index% = aWndId) + If (View_tiledWndId%A_Index% = aWndId) { i := A_Index Break @@ -470,14 +470,14 @@ View_shuffleWindow(d) j := 2 Else j := Manager_loop(i, d, 1, View_tiledWndId0) - If (j > 0 And j <= View_tiledWndId0) + If (j > 0 And j <= View_tiledWndId0) { - If (j = i) + If (j = i) { - StringReplace, View_#%Manager_aMonitor%_#%v%_wndIds, View_#%Manager_aMonitor%_#%v%_wndIds, %aWndId%`;, + StringReplace, View_#%Manager_aMonitor%_#%v%_wndIds, View_#%Manager_aMonitor%_#%v%_wndIds, %aWndId%`;, View_#%Manager_aMonitor%_#%v%_wndIds := aWndId ";" View_#%Manager_aMonitor%_#%v%_wndIds - } - Else + } + Else { search := View_tiledWndId%j% StringReplace, View_#%Manager_aMonitor%_#%v%_wndIds, View_#%Manager_aMonitor%_#%v%_wndIds, %aWndId%, SEARCH @@ -485,8 +485,8 @@ View_shuffleWindow(d) StringReplace, View_#%Manager_aMonitor%_#%v%_wndIds, View_#%Manager_aMonitor%_#%v%_wndIds, SEARCH, %search% } View_arrange(Manager_aMonitor, v) - - If Config_mouseFollowsFocus + + If Config_mouseFollowsFocus { WinGetPos, aWndX, aWndY, aWndWidth, aWndHeight, ahk_id %aWndId% DllCall("SetCursorPos", "Int", Round(aWndX + aWndWidth / 2), "Int", Round(aWndY + aWndHeight / 2)) @@ -496,11 +496,11 @@ View_shuffleWindow(d) } } -View_splitArea(axis, splitRatio, x, y, w, h, gapW, ByRef x1, ByRef y1, ByRef w1, ByRef h1, ByRef x2, ByRef y2, ByRef w2, ByRef h2) +View_splitArea(axis, splitRatio, x, y, w, h, gapW, ByRef x1, ByRef y1, ByRef w1, ByRef h1, ByRef x2, ByRef y2, ByRef w2, ByRef h2) { x1 := x y1 := y - If (splitRatio = 1) + If (splitRatio = 1) { w1 := w w2 := 0 @@ -509,7 +509,7 @@ View_splitArea(axis, splitRatio, x, y, w, h, gapW, ByRef x1, ByRef y1, ByRef w1, x2 := x + w1 y2 := y + h1 } - Else If (axis = 0) + Else If (axis = 0) { w1 := w * splitRatio - gapW / 2 w2 := w - w1 - gapW @@ -546,32 +546,32 @@ View_splitArea(axis, splitRatio, x, y, w, h, gapW, ByRef x1, ByRef y1, ByRef w1, View_stackWindows(arrayName, startPos, len, d, axis, x, y, w, h, padding) { Local dx, dy, i, wndH, wndW, wndX, wndY - + ;; d = +1: Left-to-right and top-to-bottom, depending on axis i := startPos ;; d = -1: Right-to-left and bottom-to-top, depending on axis - If (d < 0) + If (d < 0) i += len - 1 - + wndX := x wndY := y wndW := w wndH := h dx := 0 dy := 0 - If (axis = 1) + If (axis = 1) { wndW := (w - (len - 1) * padding) / len dx := wndW + padding } - Else If (axis = 2) + Else If (axis = 2) { wndH := (h - (len - 1) * padding) / len dy := wndH + padding } ;; Else (axis = 3) and nothing to do - - Loop, % len + + Loop, % len { Manager_winMove(%arrayName%%i%, wndX, wndY, wndW, wndH) i += d @@ -580,14 +580,14 @@ View_stackWindows(arrayName, startPos, len, d, axis, x, y, w, h, padding) } } -View_toggleFloating() +View_toggleFloating() { Local aWndId, l, v - + WinGet, aWndId, ID, A v := Monitor_#%Manager_aMonitor%_aView_#1 l := View_#%Manager_aMonitor%_#%v%_layout_#1 - If (Config_layoutFunction_#%l% And InStr(Manager_managedWndIds, aWndId ";")) + If (Config_layoutFunction_#%l% And InStr(Manager_managedWndIds, aWndId ";")) { Manager_#%aWndId%_isFloating := Not Manager_#%aWndId%_isFloating View_arrange(Manager_aMonitor, v) @@ -595,18 +595,18 @@ View_toggleFloating() } } -View_toggleMargins() +View_toggleMargins() { Local v - + Debug_logMessage("DEBUG[3] View_toggleMargins(" . View_#%Manager_aMonitor%_#%v%_margin1 . ", " . View_#%Manager_aMonitor%_#%v%_margin2 . ", " . View_#%Manager_aMonitor%_#%v%_margin3 . ", " . View_#%Manager_aMonitor%_#%v%_margin4 . ")", 3) - - If Not (Config_viewMargins = "0;0;0;0") + + If Not (Config_viewMargins = "0;0;0;0") { v := Monitor_#%Manager_aMonitor%_aView_#1 - If (View_#%Manager_aMonitor%_#%v%_margins = "0;0;0;0") + If (View_#%Manager_aMonitor%_#%v%_margins = "0;0;0;0") View_#%Manager_aMonitor%_#%v%_margins := Config_viewMargins - Else + Else View_#%Manager_aMonitor%_#%v%_margins := "0;0;0;0" StringSplit, View_#%Manager_aMonitor%_#%v%_margin, View_#%Manager_aMonitor%_#%v%_margins, `; View_arrange(Manager_aMonitor, v) diff --git a/src/doc/changes.t2t b/src/doc/changes.t2t index eab955c..92d1e11 100644 --- a/src/doc/changes.t2t +++ b/src/doc/changes.t2t @@ -10,7 +10,8 @@ (~) changed (+) added -=?????= + +=8.4.0= (+) Session auto-save and restore. Layout and Window information is stored periodically so that it may be recovered after a restart. From c3e342a7defb80e594c5ff5f541be64d919e7f04 Mon Sep 17 00:00:00 2001 From: joten <devnull@localhost> Date: Wed, 5 Dec 2012 13:50:30 +0100 Subject: [PATCH 2/5] fixed the processing of the command-line argument setting Main_appDir/Main_dataDir --- .hgignore | 1 + src/Main.ahk | 8 +++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.hgignore b/.hgignore index 8487de8..27d4456 100644 --- a/.hgignore +++ b/.hgignore @@ -4,3 +4,4 @@ src/log.txt syntax: regexp .*[cC]onfig.*\.ini .+\.\w{3}~ +src/data/_.*.ini diff --git a/src/Main.ahk b/src/Main.ahk index 522dc56..89d6d20 100644 --- a/src/Main.ahk +++ b/src/Main.ahk @@ -33,9 +33,7 @@ SetWinDelay, 10 ;; Pseudo main function If 0 = 1 - Main_dataDir = %1% - Else - Main_dataDir = %A_ScriptDir% + Main_appDir = %1% Main_setup() @@ -153,7 +151,6 @@ Main_makeDir(dirName) { Main_setup() { Local winAppDir - Main_appDir := "" Main_logFile := "" Main_dataDir := "" Main_autoLayout := "" @@ -161,7 +158,8 @@ Main_setup() { EnvGet, winAppDir, APPDATA - Main_appDir := winAppDir . "\bug.n" + If Main_appDir = "" + Main_appDir := winAppDir . "\bug.n" Main_logFile := Main_appDir . "\bugn_log.txt" Main_dataDir := Main_appDir . "\data" Main_autoLayout := Main_dataDir . "\_Layout.ini" From 00191220795ef470fefe35be4d7e4fde2b25e428 Mon Sep 17 00:00:00 2001 From: joten <devnull@localhost> Date: Wed, 5 Dec 2012 14:12:09 +0100 Subject: [PATCH 3/5] updated documentation (doc\help.t2t) --- src/doc/help.t2t | 68 ++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/src/doc/help.t2t b/src/doc/help.t2t index 8a8bdcb..c81022d 100644 --- a/src/doc/help.t2t +++ b/src/doc/help.t2t @@ -38,32 +38,37 @@ window management of Microsoft Windows are as follows: available screen estate. -Additionally bug.n increases the available screen estate by freeing up -the space occupied by -- the Microsoft Windows Taskbar +Additionally bug.n can increase the available screen estate by freeing +up the space occupied by +- the Microsoft Windows Taskbar and - the title bar for every single window by hiding and replacing all with a single slim status bar (but bug.n is not a shell replacement). -This status bar may show the following: -- system information - - time - - date - - CPU usage - - battery level +This status bar shows the following: - active window title -- layout - - []= (tile) - - [M] (monocle) - - ><> (floating) +- layout, e. g. + - 1x1|= (tile) + - [0] (monocle) + - ><> (floating) - up to nine views indicating - the active view - how many windows are tagged with and shown on the view with the same number +Additionally it can show the following system information: +- time +- date +- CPU usage +- memory usage +- disk load +- network load +- battery level + + === Layouts === There are three layouts. @@ -74,7 +79,8 @@ There are three layouts. - the dimensions of the master area (1x1 ... 2x3 ... 9x9) - the stacking direction of the master and stacking area (from left to right, from top to bottom or monocle) - - the position of the master area (left, top, right or bottom) + - the position of the master area (left, top, right or bottom) and + accordingly the position of the stacking area - the witdh or height of the master area (depending on its position) + **monocle**''<BR>'' All windows are maximized and only one is shown at any time. @@ -109,10 +115,13 @@ read and write access. This is the only requirement for using bug.n (at least for saving the bug.n configuration file). Apart from that you may copy bug.n to any directory. If you want to save it to a directory, to which you do not have write -access, you will have to run bug.n with a parameter indicating the file -path to the configuration file (<file path to the bug.n executable> -<file path to the session file>), e. g. -"C:\Program Files\bugn\bugn.exe C:\Users\joten\bugn.ini". +access and do not want to use the default directory for application data +(APPDATA, e. g. C:\Users\joten\AppData\Roaming\bug.n), you will have to +run bug.n with a parameter indicating the file path to that application +data directory, which i. a. contains the configuration file (config.ini) +(<file path to the bug.n executable> <file path to the data directory>), +e. g. +"C:\Program Files\bugn\bugn.exe D:\projects\bugn". === Microsoft Windows Vista / 7 and UAC === @@ -132,35 +141,37 @@ file properties. Customization can be done - with configuration variables for - - the appearance of the bug.n status bar (font, colour and content) + - the appearance of the bug.n status bar (position, size, font, + colour and content) - controlling Windows UI elements (border width and colour, hiding elements) - default values (number of tags, layouts, runtime and session management) - - rules controlling specific windows (i. a. exclusions) + - rules controlling specific windows (i. a. excluding windows from + tiling window management) - for hotkeys (the key bindings for the bug.n functions) The available configuration variables are listed in %%LINK_configuration.''<BR>'' -To change these, first create a session file by using the hotkey +To change these, first create a configuration file by using the hotkey "WIN+CTRL+S". The file is either saved in the directory you specified with the parameter to the executable, or in the same directory where the executable is saved. You may then edit the file with a text editor ("WIN+CTRL+E" opens the file for editing) and add a new line for each configuration variable with its value (format: <variable>=<value>, use no quotation marks, 1 for true and 0 for false), e. g. -"Config_showBar=0". You will have to quit and run bug.n again for the -changes to take effect.''<BR>'' -You may find a sample configuration file (Config_example.ini) in the +"Config_showBar=0". You will have to reload bug.n for the changes to +take effect.''<BR>'' +You may find a sample configuration file (config_example.ini) in the main directory of bug.n. == Usage == bug.n is mostly controlled with hotkeys. The available hotkeys are -listed in %%LINK_hotkeys. A list of all functions is available through -the command GUI. For a quick help there are the following hotkeys: +listed in %%LINK_hotkeys. For a quick help there are the following +hotkeys: - WIN+Y: Show the command GUI. - WIN+Space: Show / Hide the Windows Taskbar. - WIN+CTRL+Q: Quit bug.n and restore all windows and Windows UI @@ -176,8 +187,9 @@ The following functions can also be controlled with the mouse: layout to the last used. - With a right-click on the layout symbol you can set the layout to the next in the list. -- A function can be selected from a list in the command GUI, which is - accessible by cklickig on "#!" on the right end of the status bar. +- A function can be selected from a list or entered in the command GUI, + which is accessible by cklickig on "#!" on the right end of the status + bar. ''<BR>'' From 8f2961b1af1515983fbc2d0dec1a7f3d1eb59347 Mon Sep 17 00:00:00 2001 From: joten <devnull@localhost> Date: Wed, 5 Dec 2012 16:08:29 +0100 Subject: [PATCH 4/5] re-implemented 'rule-based single-window-action' --- src/Manager.ahk | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Manager.ahk b/src/Manager.ahk index 81ecb97..5d9017e 100644 --- a/src/Manager.ahk +++ b/src/Manager.ahk @@ -356,7 +356,7 @@ Manager_loop(index, increment, lowerBound, upperBound) Return, index } -Manager__setWinProperties(wndId, isManaged, m, tags, isDecorated, isFloating, hideTitle ) +Manager__setWinProperties(wndId, isManaged, m, tags, isDecorated, isFloating, hideTitle, action = "") { Local a @@ -365,6 +365,9 @@ Manager__setWinProperties(wndId, isManaged, m, tags, isDecorated, isFloating, hi If (isManaged) { + If (action = "Close" Or action = "Maximize") + Manager_win%action%(wndId) + Manager_managedWndIds .= wndId ";" Monitor_moveWindow(m, wndId) Manager_#%wndId%_tags := tags @@ -451,7 +454,7 @@ Manager_manage(preferredMonitor, preferredView, wndId) isManaged := False } - a := Manager__setWinProperties( wndId, isManaged, m, tags, isDecorated, isFloating, hideTitle) + a := Manager__setWinProperties( wndId, isManaged, m, tags, isDecorated, isFloating, hideTitle, action) ; Do view placement. If isManaged { From 9a14d225e0e072fb4a6220562badea7839308eee Mon Sep 17 00:00:00 2001 From: joten <devnull@localhost> Date: Wed, 5 Dec 2012 16:24:11 +0100 Subject: [PATCH 5/5] fixed bug, which I introduced with rev. 150 fixed regression bug regarding the tray icon --- src/Main.ahk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Main.ahk b/src/Main.ahk index 89d6d20..f88b3f9 100644 --- a/src/Main.ahk +++ b/src/Main.ahk @@ -44,8 +44,8 @@ SetWinDelay, 10 Config_init() Menu, Tray, Tip, %NAME% %VERSION% - IfExist %A_ScriptDir%\images\kfm.ico - Menu, Tray, Icon, %A_ScriptDir%\images\kfm.ico + IfExist %A_ScriptDir%\logo.ico + Menu, Tray, Icon, %A_ScriptDir%\logo.ico Menu, Tray, NoStandard Menu, Tray, Add, Toggle bar, Main_toggleBar Menu, Tray, Add, Help, Main_help @@ -158,7 +158,7 @@ Main_setup() { EnvGet, winAppDir, APPDATA - If Main_appDir = "" + If (Main_appDir = "") Main_appDir := winAppDir . "\bug.n" Main_logFile := Main_appDir . "\bugn_log.txt" Main_dataDir := Main_appDir . "\data"