From 67ab171e40133cf5006280a9090215df92a4ee63 Mon Sep 17 00:00:00 2001 From: joten Date: Thu, 27 Sep 2012 22:32:27 +0200 Subject: [PATCH] replaced 1 "Tab" with 2 "Space" (+ adjusting some glitches) updated the copyright notice at the beginning of each script file --- .hgignore | 1 + src/Bar.ahk | 1342 ++++++++++++++++++++-------------------- src/Config.ahk | 818 ++++++++++++------------ src/Main.ahk | 231 ++++--- src/Manager.ahk | 1578 +++++++++++++++++++++++------------------------ src/Monitor.ahk | 536 ++++++++-------- src/View.ahk | 956 ++++++++++++++-------------- 7 files changed, 2728 insertions(+), 2734 deletions(-) diff --git a/.hgignore b/.hgignore index 5bcf0c4..894125d 100644 --- a/.hgignore +++ b/.hgignore @@ -1,3 +1,4 @@ syntax: glob src/Config.ini src/Config_test.ini +01_administration.org diff --git a/src/Bar.ahk b/src/Bar.ahk index 1c27ea4..6ca24be 100644 --- a/src/Bar.ahk +++ b/src/Bar.ahk @@ -1,757 +1,757 @@ -/** - * bug.n - tiling window management - * Copyright (c) 2010-2012 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 - */ +/* + 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 +*/ 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) = "%") { - StringTrimRight, wndWidth, Config_barWidth, 1 - wndWidth := Round(Monitor_#%m%_width * wndWidth / 100) - } Else - wndWidth := Config_barWidth - Monitor_#%m%_barWidth := wndWidth - titleWidth := wndWidth - h1 := Bar_ctrlHeight - x1 := 0 - x2 := wndWidth - 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 - Log_dbg_msg(6, "Bar_init(): Gui, " . GuiN . ": Default") - Gui, %GuiN%: Default - IfWinExist, %wndTitle% - Gui, Destroy - 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 { - 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, - If (w <= h1) - Gui, Add, Progress, x%x1% y%y1% w%w% h%h1% Background%Config_normBgColor1% Vertical vBar_#%m%_#%i%_tagged - Else - Gui, Add, Progress, x%x1% y%y1% w%w% h%h1% Background%Config_normBgColor1% vBar_#%m%_#%i%_tagged - Gui, Add, Text, x%x1% y%y2% w%w% h%h2% -Wrap Center BackgroundTrans vBar_#%m%_#%i%, %text% - titleWidth -= w - x1 += w - } - ; layout - i := Config_viewCount + 1 - text := " 1x9|=- " - w := Bar_getTextWidth(text) - 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 { - i := Config_viewCount + 7 - A_Index - w := 0 - 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, 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 { ; time - w := Bar_getTextWidth(" ??:?? ") - x2 -= w - titleWidth -= w - 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%y2% w%w% h%h2% BackgroundTrans Center vBar_#%m%_#%i%, ??:?? - } Else If (i = Config_viewCount + 4) And Config_readinAny() { ; any - text := Config_readinAny() - w := Bar_getTextWidth(text) - x2 -= w - titleWidth -= w - 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 { ; battery level - w := Bar_getTextWidth(" BAT: ???% ") - x2 -= w - titleWidth -= w - Gui, Add, Progress, x%x2% y%y1% w%w% h%h1% Background%Config_normBgColor2% c%Config_normFgColor3% vBar_#%m%_#%i%_tagged - Gui, Font, c%Config_normFgColor2% - 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 { - titleWidth := wndWidth - x1 := 0 - y1 += h1 - y2 += h1 - } - 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%, - - If (Config_horizontalBarPos = "left") - x1 := 0 - Else If (Config_horizontalBarPos = "right") - x1 := Monitor_#%m%_width - wndWidth - Else If (Config_horizontalBarPos = "center") - x1 := (Monitor_#%m%_width - wndWidth) / 2 - Else If (Config_horizontalBarPos => 0) - x1 := Config_horizontalBarPos - Else If (Config_horizontalBarPos < 0) - 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) { - trayWndId := WinExist("ahk_class Shell_TrayWnd") - DllCall("SetParent", "UInt", wndId, "UInt", trayWndId) - } 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) - offset := NumPut( wndId, offset+0) - offset := NumPut( appBarMsg, offset+0) - offset := NumPut( 1, offset+0) - offset := NumPut( x1, offset+0) - offset := NumPut( y1, offset+0) - 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) - ; SKAN: Crazy Scripting : Quick Launcher for Portable Apps (http://www.autohotkey.com/forum/topic22398.html) - } + Local appBarMsg, GuiN, h1, h2, i, text, titleWidth, trayWndId, w, wndId, wndTitle, wndWidth, x1, x2, y1, y2 + + 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 + titleWidth := wndWidth + h1 := Bar_ctrlHeight + x1 := 0 + x2 := wndWidth + 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 + Log_dbg_msg(6, "Bar_init(): Gui, " . GuiN . ": Default") + Gui, %GuiN%: Default + IfWinExist, %wndTitle% + Gui, Destroy + 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 { + 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, + If (w <= h1) + Gui, Add, Progress, x%x1% y%y1% w%w% h%h1% Background%Config_normBgColor1% Vertical vBar_#%m%_#%i%_tagged + Else + Gui, Add, Progress, x%x1% y%y1% w%w% h%h1% Background%Config_normBgColor1% vBar_#%m%_#%i%_tagged + Gui, Add, Text, x%x1% y%y2% w%w% h%h2% -Wrap Center BackgroundTrans vBar_#%m%_#%i%, %text% + titleWidth -= w + x1 += w + } + ; layout + i := Config_viewCount + 1 + text := " 1x9|=- " + w := Bar_getTextWidth(text) + 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 { + i := Config_viewCount + 7 - A_Index + w := 0 + 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, 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 { ; time + w := Bar_getTextWidth(" ??:?? ") + x2 -= w + titleWidth -= w + 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%y2% w%w% h%h2% BackgroundTrans Center vBar_#%m%_#%i%, ??:?? + } Else If (i = Config_viewCount + 4) And Config_readinAny() { ; any + text := Config_readinAny() + w := Bar_getTextWidth(text) + x2 -= w + titleWidth -= w + 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 { ; battery level + w := Bar_getTextWidth(" BAT: ???% ") + x2 -= w + titleWidth -= w + Gui, Add, Progress, x%x2% y%y1% w%w% h%h1% Background%Config_normBgColor2% c%Config_normFgColor3% vBar_#%m%_#%i%_tagged + Gui, Font, c%Config_normFgColor2% + 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 { + titleWidth := wndWidth + x1 := 0 + y1 += h1 + y2 += h1 + } + 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%, + + If (Config_horizontalBarPos = "left") + x1 := 0 + Else If (Config_horizontalBarPos = "right") + x1 := Monitor_#%m%_width - wndWidth + Else If (Config_horizontalBarPos = "center") + x1 := (Monitor_#%m%_width - wndWidth) / 2 + Else If (Config_horizontalBarPos => 0) + x1 := Config_horizontalBarPos + Else If (Config_horizontalBarPos < 0) + 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) { + trayWndId := WinExist("ahk_class Shell_TrayWnd") + DllCall("SetParent", "UInt", wndId, "UInt", trayWndId) + } Else { + appBarMsg := DllCall("RegisterWindowMessage", Str, "AppBarMsg") - Bar_hDrive := DllCall("CreateFile", "Str", "\\.\PhysicalDrive0", "UInt", 0, "UInt", 3, "UInt", 0, "UInt", 3, "UInt", 0, "UInt", 0) - Bar_getNetworkInterface() + ; appBarData: http://msdn2.microsoft.com/en-us/library/ms538008.aspx + VarSetCapacity(Bar_appBarData, 36, 0) + offset := NumPut( 36, Bar_appBarData) + offset := NumPut( wndId, offset+0) + offset := NumPut( appBarMsg, offset+0) + offset := NumPut( 1, offset+0) + offset := NumPut( x1, offset+0) + offset := NumPut( y1, offset+0) + 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) + ; SKAN: Crazy Scripting : Quick Launcher for Portable Apps (http://www.autohotkey.com/forum/topic22398.html) + } + + Bar_hDrive := DllCall("CreateFile", "Str", "\\.\PhysicalDrive0", "UInt", 0, "UInt", 3, "UInt", 0, "UInt", 3, "UInt", 0, "UInt", 0) + Bar_getNetworkInterface() } -Bar_initCmdGui() { - Global Bar_#0_#0, Bar_#0_#0H, Bar_#0_#0W, Bar_cmdGuiIsVisible, Config_fontName, Config_fontSize, Config_normBgColor1, Config_normFgColor1 - - Bar_cmdGuiIsVisible := False - wndTitle := "bug.n_BAR_0" - Gui, 99: Default - Gui, +LabelBar_cmdGui - IfWinExist, %wndTitle% - Gui, Destroy - Gui, +LastFound -Caption +ToolWindow +AlwaysOnTop - Gui, Color, Default - Gui, Font, s%Config_fontSize%, %Config_fontName% - Gui, Add, TreeView, x0 y0 r23 w300 Background%Config_normBgColor1% c%Config_normFgColor1% -ReadOnly vBar_#0_#0 gBar_cmdGuiEnter - GuiControl, -Redraw, Bar_#0_#0 - itemId10 := TV_Add("Window") - itemId11 := TV_Add("set tag", itemId10) - TV_Add("all", itemId11) - TV_Add("Press to enter a number.", itemId11) - itemId12 := TV_Add("toggle tag", itemId10) - TV_Add("Press to enter a number.", itemId12) - TV_Add("move to top", itemId10) - TV_Add("move up", itemId10) - TV_Add("move down", itemId10) - TV_Add("toggle floating", itemId10) - TV_Add("toggle decor", itemId10) - TV_Add("close", itemId10) - TV_Add("maximize", itemId10) - TV_Add("move by key", itemId10) - TV_Add("resize by key", itemId10) - TV_Add("activate next", itemId10) - TV_Add("activate prev", itemId10) - TV_Add("move to next monitor", itemId10) - TV_Add("move to prev monitor", itemId10) - itemId20 := TV_Add("Layout") - TV_Add("set last", itemId20) - TV_Add("set 1st (tile)", itemId20) - TV_Add("set 2nd (monocle)", itemId20) - TV_Add("set 3rd (floating)", itemId20) - TV_Add("rotate layout axis", itemId20) - TV_Add("rotate master axis", itemId20) - TV_Add("rotate stack axis", itemId20) - TV_Add("mirror tile layout", itemId20) - TV_Add("increase master X", itemId20) - TV_Add("decrease master X", itemId20) - TV_Add("increase master Y", itemId20) - TV_Add("decrease master Y", itemId20) - TV_Add("increase master factor", itemId20) - TV_Add("decrease master factor", itemId20) - itemId30 := TV_Add("View") - itemId31 := TV_Add("activate", itemId30) - TV_Add("last", itemId31) - TV_Add("Press to enter a number.", itemId31) - TV_Add("move to next monitor", itemId30) - TV_Add("move to prev monitor", itemId30) - itemId40 := TV_Add("Monitor") - TV_Add("toggle bar", itemId40) - TV_Add("toggle task bar", itemId40) - TV_Add("activate next", itemId40) - TV_Add("activate prev", itemId40) - ;itemId50 := TV_add("Log") - ; TV_Add("increment debug level", itemId50) - ; TV_Add("decrement debug level", itemId50) - ; TV_Add("log help info", itemId50) - ; TV_Add("log view window info", itemId50) - ; TV_Add("log managed window info", itemId50) - TV_Add("Reload") - TV_Add("Quit") - GuiControl, +Redraw, Bar_#0_#0 - Gui, Add, Button, Y0 Hidden Default gBar_cmdGuiEnter, OK - GuiControlGet, Bar_#0_#0, Pos - Gui, Show, Hide w%Bar_#0_#0W% h%Bar_#0_#0H%, %wndTitle% +Bar_initCmdGui() { + Global Bar_#0_#0, Bar_#0_#0H, Bar_#0_#0W, Bar_cmdGuiIsVisible, Config_fontName, Config_fontSize, Config_normBgColor1, Config_normFgColor1 + + Bar_cmdGuiIsVisible := False + wndTitle := "bug.n_BAR_0" + Gui, 99: Default + Gui, +LabelBar_cmdGui + IfWinExist, %wndTitle% + Gui, Destroy + Gui, +LastFound -Caption +ToolWindow +AlwaysOnTop + Gui, Color, Default + Gui, Font, s%Config_fontSize%, %Config_fontName% + Gui, Add, TreeView, x0 y0 r23 w300 Background%Config_normBgColor1% c%Config_normFgColor1% -ReadOnly vBar_#0_#0 gBar_cmdGuiEnter + GuiControl, -Redraw, Bar_#0_#0 + itemId10 := TV_Add("Window") + itemId11 := TV_Add("set tag", itemId10) + TV_Add("all", itemId11) + TV_Add("Press to enter a number.", itemId11) + itemId12 := TV_Add("toggle tag", itemId10) + TV_Add("Press to enter a number.", itemId12) + TV_Add("move to top", itemId10) + TV_Add("move up", itemId10) + TV_Add("move down", itemId10) + TV_Add("toggle floating", itemId10) + TV_Add("toggle decor", itemId10) + TV_Add("close", itemId10) + TV_Add("maximize", itemId10) + TV_Add("move by key", itemId10) + TV_Add("resize by key", itemId10) + TV_Add("activate next", itemId10) + TV_Add("activate prev", itemId10) + TV_Add("move to next monitor", itemId10) + TV_Add("move to prev monitor", itemId10) + itemId20 := TV_Add("Layout") + TV_Add("set last", itemId20) + TV_Add("set 1st (tile)", itemId20) + TV_Add("set 2nd (monocle)", itemId20) + TV_Add("set 3rd (floating)", itemId20) + TV_Add("rotate layout axis", itemId20) + TV_Add("rotate master axis", itemId20) + TV_Add("rotate stack axis", itemId20) + TV_Add("mirror tile layout", itemId20) + TV_Add("increase master X", itemId20) + TV_Add("decrease master X", itemId20) + TV_Add("increase master Y", itemId20) + TV_Add("decrease master Y", itemId20) + TV_Add("increase master factor", itemId20) + TV_Add("decrease master factor", itemId20) + itemId30 := TV_Add("View") + itemId31 := TV_Add("activate", itemId30) + TV_Add("last", itemId31) + TV_Add("Press to enter a number.", itemId31) + TV_Add("move to next monitor", itemId30) + TV_Add("move to prev monitor", itemId30) + itemId40 := TV_Add("Monitor") + TV_Add("toggle bar", itemId40) + TV_Add("toggle task bar", itemId40) + TV_Add("activate next", itemId40) + TV_Add("activate prev", itemId40) + ;itemId50 := TV_add("Log") + ; TV_Add("increment debug level", itemId50) + ; TV_Add("decrement debug level", itemId50) + ; TV_Add("log help info", itemId50) + ; TV_Add("log view window info", itemId50) + ; TV_Add("log managed window info", itemId50) + TV_Add("Reload") + TV_Add("Quit") + GuiControl, +Redraw, Bar_#0_#0 + Gui, Add, Button, Y0 Hidden Default gBar_cmdGuiEnter, OK + GuiControlGet, Bar_#0_#0, Pos + Gui, Show, Hide w%Bar_#0_#0W% h%Bar_#0_#0H%, %wndTitle% } Bar_cmdGuiEscape: - Bar_cmdGuiIsVisible := False - Gui, Cancel - WinActivate, ahk_id %Bar_aWndId% + Bar_cmdGuiIsVisible := False + Gui, Cancel + WinActivate, ahk_id %Bar_aWndId% Return Bar_cmdGuiEnter: - If (A_GuiControl = "OK") Or (A_GuiControl = "BAR_#0_#0" And A_GuiControlEvent = "DoubleClick") { - Bar_selItemId_#1 := TV_GetSelection() - If Not TV_GetChild(Bar_selItemId_#1) { - Bar_selItemId_#2 := TV_GetParent(Bar_selItemId_#1) - Bar_selItemId_#3 := TV_GetParent(Bar_selItemId_#2) - TV_GetText(Bar_command_#1, Bar_selItemId_#1) - TV_GetText(Bar_command_#2, Bar_selItemId_#2) - TV_GetText(Bar_command_#3, Bar_selItemId_#3) - } Else - Bar_command_#1 := "" - Bar_cmdGuiIsVisible := False - Gui, Cancel - WinActivate, ahk_id %Bar_aWndId% - Bar_evaluateCommand() - } + If (A_GuiControl = "OK") Or (A_GuiControl = "BAR_#0_#0" And A_GuiControlEvent = "DoubleClick") { + Bar_selItemId_#1 := TV_GetSelection() + If Not TV_GetChild(Bar_selItemId_#1) { + Bar_selItemId_#2 := TV_GetParent(Bar_selItemId_#1) + Bar_selItemId_#3 := TV_GetParent(Bar_selItemId_#2) + TV_GetText(Bar_command_#1, Bar_selItemId_#1) + TV_GetText(Bar_command_#2, Bar_selItemId_#2) + TV_GetText(Bar_command_#3, Bar_selItemId_#3) + } Else + Bar_command_#1 := "" + Bar_cmdGuiIsVisible := False + Gui, Cancel + WinActivate, ahk_id %Bar_aWndId% + Bar_evaluateCommand() + } Return Bar_evaluateCommand() { - Global Bar_command_#1, Bar_command_#2, Bar_command_#3, Config_viewCount - - If (Bar_command_#1) { - If (Bar_command_#2 = "Run") - Run, %Bar_command_#1% - Else If (Bar_command_#3 = "Window") { - If (Bar_command_#2 = "set tag") { - If (Bar_command_#1 = "all") - Monitor_setWindowTag(0) - Else If (RegExMatch(Bar_command_#1, "[0-9]+") And Bar_command_#1 <= Config_viewCount) - Monitor_setWindowTag(Bar_command_#1) - } Else If (Bar_command_#2 = "toggle tag") - If (RegExMatch(Bar_command_#1, "[0-9]+") And Bar_command_#1 <= Config_viewCount) - Monitor_toggleWindowTag(Bar_command_#1) - } Else If (Bar_command_#2 = "Window") { - If (Bar_command_#1 = "move to top") - View_shuffleWindow(0) - Else If (Bar_command_#1 = "move up") - View_shuffleWindow(-1) - Else If (Bar_command_#1 = "move down") - View_shuffleWindow(+1) - Else If (Bar_command_#1 = "toggle floating") - View_toggleFloating() - Else If (Bar_command_#1 = "toggle decor") - Manager_toggleDecor() - Else If (Bar_command_#1 = "close") - Manager_closeWindow() - Else If (Bar_command_#1 = "move by key") - Manager_moveWindow() - Else If (Bar_command_#1 = "resize by key") - Manager_sizeWindow() - Else If (Bar_command_#1 = "maximize") - Manager_maximizeWindow() - Else If (Bar_command_#1 = "activate next") - View_activateWindow(+1) - Else If (Bar_command_#1 = "activate prev") - View_activateWindow(-1) - Else If (Bar_command_#1 = "move to next monitor") - Manager_setWindowMonitor(+1) - Else If (Bar_command_#1 = "move to prev monitor") - Manager_setWindowMonitor(-1) - } Else If (Bar_command_#2 = "Layout") { - If (Bar_command_#1 = "set last") - View_setLayout(-1) - Else If (Bar_command_#1 = "set 1st (tile)") - View_setLayout(1) - Else If (Bar_command_#1 = "set 2nd (monocle)") - View_setLayout(2) - Else If (Bar_command_#1 = "set 3rd (floating)") - View_setLayout(3) - Else If (Bar_command_#1 = "rotate layout axis") - View_rotateLayoutAxis(1, +1) - Else If (Bar_command_#1 = "rotate master axis") - View_rotateLayoutAxis(2, +1) - Else If (Bar_command_#1 = "rotate stack axis") - View_rotateLayoutAxis(3, +1) - Else If (Bar_command_#1 = "mirror tile layout") - View_rotateLayoutAxis(1, +2) - Else If (Bar_command_#1 = "increase master X") - View_setMX(+1) - Else If (Bar_command_#1 = "decrease master X") - View_setMX(-1) - Else If (Bar_command_#1 = "increase master Y") - View_setMY(+1) - Else If (Bar_command_#1 = "decrease master Y") - View_setMY(-1) - Else If (Bar_command_#1 = "increase master factor") - View_setMFactor(+0.05) - Else If (Bar_command_#1 = "decrease master factor") - View_setMFactor(-0.05) - } Else If (Bar_command_#3 = "View") { - If (Bar_command_#2 = "activate") { - If (Bar_command_#1 = "last") - Monitor_activateView(-1) - Else If (RegExMatch(Bar_command_#1, "[0-9]+") And Bar_command_#1 <= Config_viewCount) - Monitor_activateView(Bar_command_#1) - } - } Else If (Bar_command_#2 = "View") { - If (Bar_command_#1 = "move to next monitor") - Manager_setViewMonitor(+1) - Else If (Bar_command_#1 = "move to prev monitor") - Manager_setViewMonitor(-1) - } Else If (Bar_command_#2 = "Monitor") { - If (Bar_command_#1 = "toggle bar") - Monitor_toggleBar() - Else If (Bar_command_#1 = "toggle task bar") - Monitor_toggleTaskBar() - Else If (Bar_command_#1 = "activate next") - Manager_activateMonitor(+1) - Else If (Bar_command_#1 = "activate prev") - Manager_activateMonitor(-1) - } Else If (Bar_command_#2 = "Log") { - If (Bar_command_#1 = "increment debug level") - Log_incDebugLevel() - If (Bar_command_#1 = "decrement debug level") - Log_decDebugLevel() - If (Bar_command_#1 = "log help info") - Manager_logHelp() - If (Bar_command_#1 = "log view window info") - Manager_logViewWindowList() - If (Bar_command_#1 = "log managed window info") - Manager_logManagedWindowList() - } Else If (Bar_command_#1 = "Reload") - Main_reload() - Else If (Bar_command_#1 = "Quit") - ExitApp - - Bar_command_#1 := "" - Bar_command_#2 := "" - Bar_command_#3 := "" - } + Global Bar_command_#1, Bar_command_#2, Bar_command_#3, Config_viewCount + + If (Bar_command_#1) { + If (Bar_command_#2 = "Run") + Run, %Bar_command_#1% + Else If (Bar_command_#3 = "Window") { + If (Bar_command_#2 = "set tag") { + If (Bar_command_#1 = "all") + Monitor_setWindowTag(0) + Else If (RegExMatch(Bar_command_#1, "[0-9]+") And Bar_command_#1 <= Config_viewCount) + Monitor_setWindowTag(Bar_command_#1) + } Else If (Bar_command_#2 = "toggle tag") + If (RegExMatch(Bar_command_#1, "[0-9]+") And Bar_command_#1 <= Config_viewCount) + Monitor_toggleWindowTag(Bar_command_#1) + } Else If (Bar_command_#2 = "Window") { + If (Bar_command_#1 = "move to top") + View_shuffleWindow(0) + Else If (Bar_command_#1 = "move up") + View_shuffleWindow(-1) + Else If (Bar_command_#1 = "move down") + View_shuffleWindow(+1) + Else If (Bar_command_#1 = "toggle floating") + View_toggleFloating() + Else If (Bar_command_#1 = "toggle decor") + Manager_toggleDecor() + Else If (Bar_command_#1 = "close") + Manager_closeWindow() + Else If (Bar_command_#1 = "move by key") + Manager_moveWindow() + Else If (Bar_command_#1 = "resize by key") + Manager_sizeWindow() + Else If (Bar_command_#1 = "maximize") + Manager_maximizeWindow() + Else If (Bar_command_#1 = "activate next") + View_activateWindow(+1) + Else If (Bar_command_#1 = "activate prev") + View_activateWindow(-1) + Else If (Bar_command_#1 = "move to next monitor") + Manager_setWindowMonitor(+1) + Else If (Bar_command_#1 = "move to prev monitor") + Manager_setWindowMonitor(-1) + } Else If (Bar_command_#2 = "Layout") { + If (Bar_command_#1 = "set last") + View_setLayout(-1) + Else If (Bar_command_#1 = "set 1st (tile)") + View_setLayout(1) + Else If (Bar_command_#1 = "set 2nd (monocle)") + View_setLayout(2) + Else If (Bar_command_#1 = "set 3rd (floating)") + View_setLayout(3) + Else If (Bar_command_#1 = "rotate layout axis") + View_rotateLayoutAxis(1, +1) + Else If (Bar_command_#1 = "rotate master axis") + View_rotateLayoutAxis(2, +1) + Else If (Bar_command_#1 = "rotate stack axis") + View_rotateLayoutAxis(3, +1) + Else If (Bar_command_#1 = "mirror tile layout") + View_rotateLayoutAxis(1, +2) + Else If (Bar_command_#1 = "increase master X") + View_setMX(+1) + Else If (Bar_command_#1 = "decrease master X") + View_setMX(-1) + Else If (Bar_command_#1 = "increase master Y") + View_setMY(+1) + Else If (Bar_command_#1 = "decrease master Y") + View_setMY(-1) + Else If (Bar_command_#1 = "increase master factor") + View_setMFactor(+0.05) + Else If (Bar_command_#1 = "decrease master factor") + View_setMFactor(-0.05) + } Else If (Bar_command_#3 = "View") { + If (Bar_command_#2 = "activate") { + If (Bar_command_#1 = "last") + Monitor_activateView(-1) + Else If (RegExMatch(Bar_command_#1, "[0-9]+") And Bar_command_#1 <= Config_viewCount) + Monitor_activateView(Bar_command_#1) + } + } Else If (Bar_command_#2 = "View") { + If (Bar_command_#1 = "move to next monitor") + Manager_setViewMonitor(+1) + Else If (Bar_command_#1 = "move to prev monitor") + Manager_setViewMonitor(-1) + } Else If (Bar_command_#2 = "Monitor") { + If (Bar_command_#1 = "toggle bar") + Monitor_toggleBar() + Else If (Bar_command_#1 = "toggle task bar") + Monitor_toggleTaskBar() + Else If (Bar_command_#1 = "activate next") + Manager_activateMonitor(+1) + Else If (Bar_command_#1 = "activate prev") + Manager_activateMonitor(-1) + } Else If (Bar_command_#2 = "Log") { + If (Bar_command_#1 = "increment debug level") + Log_incDebugLevel() + If (Bar_command_#1 = "decrement debug level") + Log_decDebugLevel() + If (Bar_command_#1 = "log help info") + Manager_logHelp() + If (Bar_command_#1 = "log view window info") + Manager_logViewWindowList() + If (Bar_command_#1 = "log managed window info") + Manager_logManagedWindowList() + } Else If (Bar_command_#1 = "Reload") + Main_reload() + Else If (Bar_command_#1 = "Quit") + ExitApp + + Bar_command_#1 := "" + Bar_command_#2 := "" + Bar_command_#3 := "" + } } 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) { - MsgBox 16, Power Status, Can't get the power status... - Return - } - acLineStatus := NumGet(powerStatus, 0, "Char") - batteryLifePercent := NumGet(powerStatus, 2, "Char") + VarSetCapacity(powerStatus, (1 + 1 + 1 + 1 + 4 + 4)) + success := DllCall("GetSystemPowerStatus", "UInt", &powerStatus) + If (ErrorLevel != 0 Or success = 0) { + MsgBox 16, Power Status, Can't get the power status... + Return + } + acLineStatus := NumGet(powerStatus, 0, "Char") + batteryLifePercent := NumGet(powerStatus, 2, "Char") - If acLineStatus = 0 - acLineStatus = off - Else If acLineStatus = 1 - acLineStatus = on - Else If acLineStatus = 255 - acLineStatus = ? + If acLineStatus = 0 + acLineStatus = off + Else If acLineStatus = 1 + acLineStatus = on + Else If acLineStatus = 255 + acLineStatus = ? - If batteryLifePercent = 255 - batteryLifePercent = ??? + If batteryLifePercent = 255 + batteryLifePercent = ??? } ; PhiLho: AC/Battery status (http://www.autohotkey.com/forum/topic7633.html) Bar_getDiskLoad(ByRef readLoad, ByRef writeLoad) { - Global Bar_hDrive - Static oldReadCount, oldWriteCount + Global Bar_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", Bar_hDrive, "UInt", 0x00070020, "UInt", 0, "UInt", 0, "UInt", &dp, "UInt", dpSize, "UIntP", nReturn, "UInt", 0) ; IOCTL_DISK_PERFORMANCE - dpSize := 5 * 8 + 4 + 4 + 4 + 4 + 8 + 4 + 8 * (A_IsUnicode ? 2 : 1) + 12 ; 88? - VarSetCapacity(dp, dpSize) - DllCall("DeviceIoControl", "UInt", Bar_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) - writeLoad := SubStr(" " Round((1 - 1 / (1 + newWriteCount - oldWriteCount)) * 100), -2) - oldReadCount := newReadCount - oldWriteCount := newWriteCount + newReadCount := NumGet(dp, 40) + newWriteCount := NumGet(dp, 44) + readLoad := SubStr(" " Round((1 - 1 / (1 + newReadCount - oldReadCount)) * 100), -2) + writeLoad := SubStr(" " Round((1 - 1 / (1 + newWriteCount - oldWriteCount)) * 100), -2) + oldReadCount := newReadCount + oldWriteCount := newWriteCount } ; 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) 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 { - 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") { - WinGetPos, , , , buttonH, Start ahk_class Button - WinGetPos, , , , barH, ahk_class Shell_TrayWnd - If (buttonH < barH) - Bar_height := buttonH - Else - Bar_height := barH - Bar_ctrlHeight := Bar_height - If Not Config_singleRowBar - Bar_ctrlHeight := Bar_height / 2 - } + 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 { + 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") { + WinGetPos, , , , buttonH, Start ahk_class Button + WinGetPos, , , , barH, ahk_class Shell_TrayWnd + If (buttonH < barH) + Bar_height := buttonH + Else + Bar_height := barH + Bar_ctrlHeight := Bar_height + If Not Config_singleRowBar + Bar_ctrlHeight := Bar_height / 2 + } } Bar_getMemoryUsage() { - VarSetCapacity(memoryStatus, 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4) - DllCall("kernel32.dll\GlobalMemoryStatus", "UInt", &memoryStatus) - Return, SubStr(" " Round(*(&memoryStatus + 4)), -2) ; LS byte is enough, 0..100 + VarSetCapacity(memoryStatus, 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4) + DllCall("kernel32.dll\GlobalMemoryStatus", "UInt", &memoryStatus) + Return, SubStr(" " Round(*(&memoryStatus + 4)), -2) ; LS byte is enough, 0..100 } ; fures: System + Network monitor - with net history graph (http://www.autohotkey.com/community/viewtopic.php?p=260329) Bar_getNetworkInterface() { - Global Bar_networkInterface, Bar_networkInterfaceTable - - DllCall("iphlpapi\GetNumberOfInterfaces", "UIntP", n) - nSize := 4 + 860 * n + 8 - VarSetCapacity(Bar_networkInterfaceTable, nSize) - If Not DllCall("iphlpapi\GetIfTable", "UInt", &Bar_networkInterfaceTable, "UIntP", nSize, "Int", False) { - Loop, 2 { - i := 0 - j := A_Index - Loop, % NumGet(Bar_networkInterfaceTable) { - If NumGet(Bar_networkInterfaceTable, 4 + 860 * (A_Index - 1) + 544) < 4 - || NumGet(Bar_networkInterfaceTable, 4 + 860 * (A_Index - 1) + 516) = 24 - Continue - i += 1 - dn_#%i%_#%j% := NumGet(Bar_networkInterfaceTable, 4 + 860 * (A_Index - 1) + 552) - up_#%i%_#%j% := NumGet(Bar_networkInterfaceTable, 4 + 860 * (A_Index - 1) + 576) - } - If (A_Index < 2) - RunWait, %Comspec% /c ping -n 1 127.0.0.1, , hide - } - - Loop, % i - If (dn_#%i%_#2 > dn_#%i%_1) { - Bar_networkInterface := i - Break - } + Global Bar_networkInterface, Bar_networkInterfaceTable + + DllCall("iphlpapi\GetNumberOfInterfaces", "UIntP", n) + nSize := 4 + 860 * n + 8 + VarSetCapacity(Bar_networkInterfaceTable, nSize) + If Not DllCall("iphlpapi\GetIfTable", "UInt", &Bar_networkInterfaceTable, "UIntP", nSize, "Int", False) { + Loop, 2 { + i := 0 + j := A_Index + Loop, % NumGet(Bar_networkInterfaceTable) { + If NumGet(Bar_networkInterfaceTable, 4 + 860 * (A_Index - 1) + 544) < 4 + || NumGet(Bar_networkInterfaceTable, 4 + 860 * (A_Index - 1) + 516) = 24 + Continue + i += 1 + dn_#%i%_#%j% := NumGet(Bar_networkInterfaceTable, 4 + 860 * (A_Index - 1) + 552) + up_#%i%_#%j% := NumGet(Bar_networkInterfaceTable, 4 + 860 * (A_Index - 1) + 576) + } + If (A_Index < 2) + RunWait, %Comspec% /c ping -n 1 127.0.0.1, , hide } + + Loop, % i + If (dn_#%i%_#2 > dn_#%i%_1) { + Bar_networkInterface := i + Break + } + } } ; fures: System + Network monitor - with net history graph (http://www.autohotkey.com/community/viewtopic.php?p=260329) Bar_getNetworkLoad(ByRef upLoad, ByRef dnLoad) { - Global Bar_networkInterface, Bar_networkInterfaceTable - Static dn_#0, t_#0, up_#0 - - DllCall("iphlpapi\GetIfEntry", "UInt", &Bar_networkInterfaceTable + 4 + 860 * (Bar_networkInterface - 1)) - dn_#1 := NumGet(Bar_networkInterfaceTable, 4 + 860 * (Bar_networkInterface - 1) + 552) ; Total Incoming Bytes - up_#1 := NumGet(Bar_networkInterfaceTable, 4 + 860 * (Bar_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 + Global Bar_networkInterface, Bar_networkInterfaceTable + Static dn_#0, t_#0, up_#0 + + DllCall("iphlpapi\GetIfEntry", "UInt", &Bar_networkInterfaceTable + 4 + 860 * (Bar_networkInterface - 1)) + dn_#1 := NumGet(Bar_networkInterfaceTable, 4 + 860 * (Bar_networkInterface - 1) + 552) ; Total Incoming Bytes + up_#1 := NumGet(Bar_networkInterfaceTable, 4 + 860 * (Bar_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) -Bar_getSystemTimes() { ; Total CPU Load - Static oldIdleTime, oldKrnlTime, oldUserTime - Static newIdleTime, newKrnlTime, newUserTime +Bar_getSystemTimes() { ; Total CPU Load + Static oldIdleTime, oldKrnlTime, oldUserTime + Static newIdleTime, newKrnlTime, newUserTime - oldIdleTime := newIdleTime - oldKrnlTime := newKrnlTime - oldUserTime := newUserTime + oldIdleTime := newIdleTime + oldKrnlTime := newKrnlTime + oldUserTime := newUserTime - DllCall("GetSystemTimes", "Int64P", newIdleTime, "Int64P", newKrnlTime, "Int64P", newUserTime) - sysTime := SubStr(" " . Round((1 - (newIdleTime - oldIdleTime) / (newKrnlTime - oldKrnlTime+newUserTime - oldUserTime)) * 100), -2) - Return, sysTime ; system time in percent + DllCall("GetSystemTimes", "Int64P", newIdleTime, "Int64P", newKrnlTime, "Int64P", newUserTime) + sysTime := SubStr(" " . Round((1 - (newIdleTime - oldIdleTime) / (newKrnlTime - oldKrnlTime+newUserTime - oldUserTime)) * 100), -2) + Return, sysTime ; system time in percent } ; Sean: CPU LoadTimes (http://www.autohotkey.com/forum/topic18913.html) Bar_getTextWidth(x, reverse=False) { - Global Config_fontSize - - If reverse { ; "reverse" calculates the number of characters to a given width. - w := x - i := w / (Config_fontSize - 1) - If (Config_fontSize = 7 Or (Config_fontSize > 8 And Config_fontSize < 13)) - i := w / (Config_fontSize - 2) - Else If (Config_fontSize > 12 And Config_fontSize < 18) - i := w / (Config_fontSize - 3) - Else If (Config_fontSize > 17) - i := w / (Config_fontSize - 4) - textWidth := i - } 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)) - textWidth := StrLen(x) * (Config_fontSize - 2) - Else If (Config_fontSize > 12 And Config_fontSize < 18) - textWidth := StrLen(x) * (Config_fontSize - 3) - Else If (Config_fontSize > 17) - textWidth := StrLen(x) * (Config_fontSize - 4) - } - - Return, textWidth + Global Config_fontSize + + If reverse { ; "reverse" calculates the number of characters to a given width. + w := x + i := w / (Config_fontSize - 1) + If (Config_fontSize = 7 Or (Config_fontSize > 8 And Config_fontSize < 13)) + i := w / (Config_fontSize - 2) + Else If (Config_fontSize > 12 And Config_fontSize < 18) + i := w / (Config_fontSize - 3) + Else If (Config_fontSize > 17) + i := w / (Config_fontSize - 4) + textWidth := i + } 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)) + textWidth := StrLen(x) * (Config_fontSize - 2) + Else If (Config_fontSize > 12 And Config_fontSize < 18) + textWidth := StrLen(x) * (Config_fontSize - 3) + Else If (Config_fontSize > 17) + textWidth := StrLen(x) * (Config_fontSize - 4) + } + + Return, textWidth } Bar_GuiClick: - Manager_winActivate(Bar_aWndId) - 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) - If (SubStr(A_GuiControl, -6) = "_layout") - View_setLayout(-1) - Else If (SubStr(A_GuiControl, -4) = "_view") - Monitor_activateView(SubStr(A_GuiControl, InStr(A_GuiControl, "_#", False, 0) + 2, 1)) - } + Manager_winActivate(Bar_aWndId) + 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) + If (SubStr(A_GuiControl, -6) = "_layout") + View_setLayout(-1) + Else If (SubStr(A_GuiControl, -4) = "_view") + Monitor_activateView(SubStr(A_GuiControl, InStr(A_GuiControl, "_#", False, 0) + 2, 1)) + } Return Bar_GuiContextMenu: - Manager_winActivate(Bar_aWndId) - If (A_GuiEvent = "RightClick") { - 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") { - 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) - Monitor_setWindowTag(SubStr(A_GuiControl, InStr(A_GuiControl, "_#", False, 0) + 2, 1)) - } - } + Manager_winActivate(Bar_aWndId) + If (A_GuiEvent = "RightClick") { + 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") { + 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) + Monitor_setWindowTag(SubStr(A_GuiControl, InStr(A_GuiControl, "_#", False, 0) + 2, 1)) + } + } Return Bar_loop: - Bar_updateStatus() + Bar_updateStatus() Return Bar_move(m) { - Local wndTitle, x, y - - x := Monitor_#%m%_barX - y := Monitor_#%m%_barY - - wndTitle := "bug.n_BAR_" m - WinMove, %wndTitle%, , %x%, %y% + Local wndTitle, x, y + + x := Monitor_#%m%_barX + y := Monitor_#%m%_barY + + wndTitle := "bug.n_BAR_" m + WinMove, %wndTitle%, , %x%, %y% } Bar_toggleCommandGui: - If Not Bar_cmdGuiIsVisible - 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) - Bar_toggleCommandGui() + If Not Bar_cmdGuiIsVisible + 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) + Bar_toggleCommandGui() Return Bar_toggleCommandGui() { - Local wndId, x, y - - Gui, 99: Default - If Bar_cmdGuiIsVisible { - Bar_cmdGuiIsVisible := False - Gui, Cancel - Manager_winActivate(Bar_aWndId) - } Else { - Bar_cmdGuiIsVisible := True - x := Monitor_#%Manager_aMonitor%_barX + Monitor_#%Manager_aMonitor%_barWidth - Bar_#0_#0W - If (Config_verticalBarPos = "top") Or (Config_verticalBarPos = "tray" And Not Manager_aMonitor = Manager_taskBarMonitor) - y := Monitor_#%Manager_aMonitor%_y - Else - y := Monitor_#%Manager_aMonitor%_y + Monitor_#%Manager_aMonitor%_height - Bar_#0_#0H - Gui, Show - WinMove, bug.n_BAR_0, , %x%, %y% - WinGet, wndId, ID, bug.n_BAR_0 - Manager_winActivate(wndId) - GuiControl, Focus, % Bar_#0_#0 - } + Local wndId, x, y + + Gui, 99: Default + If Bar_cmdGuiIsVisible { + Bar_cmdGuiIsVisible := False + Gui, Cancel + Manager_winActivate(Bar_aWndId) + } Else { + Bar_cmdGuiIsVisible := True + x := Monitor_#%Manager_aMonitor%_barX + Monitor_#%Manager_aMonitor%_barWidth - Bar_#0_#0W + If (Config_verticalBarPos = "top") Or (Config_verticalBarPos = "tray" And Not Manager_aMonitor = Manager_taskBarMonitor) + y := Monitor_#%Manager_aMonitor%_y + Else + y := Monitor_#%Manager_aMonitor%_y + Monitor_#%Manager_aMonitor%_height - Bar_#0_#0H + Gui, Show + WinMove, bug.n_BAR_0, , %x%, %y% + WinGet, wndId, ID, bug.n_BAR_0 + Manager_winActivate(wndId) + GuiControl, Focus, % Bar_#0_#0 + } } Bar_toggleVisibility(m) { - Local GuiN - - GuiN := (m - 1) + 1 - If Monitor_#%m%_showBar { - If Not (GuiN = 99) Or Bar_cmdGuiIsVisible - Gui, %GuiN%: Show - } Else - Gui, %GuiN%: Cancel + Local GuiN + + GuiN := (m - 1) + 1 + If Monitor_#%m%_showBar { + If Not (GuiN = 99) Or Bar_cmdGuiIsVisible + Gui, %GuiN%: Show + } Else + Gui, %GuiN%: Cancel } 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 + 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() { - Local anyContent, anyText, b1, b2, b3, GuiN, i, m - - Loop, % Manager_monitorCount { - m := A_Index - GuiN := (m - 1) + 1 - Log_dbg_msg(6, "Bar_updateStatus(): Gui, " . GuiN . ": Default") - Gui, %GuiN%: Default - If Config_readinBat { - Bar_getBatteryStatus(b1, b2) - b3 := SubStr(" " b1, -2) - i := Config_viewCount + 3 - 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") { ; 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 { - GuiControl, +Background%Config_normBgColor3% +c%Config_normFgColor3%, Bar_#%m%_#%i%_tagged - GuiControl, +c%Config_normFgColor2%, Bar_#%m%_#%i% - } - GuiControl, , Bar_#%m%_#%i%_tagged, %b3% - GuiControl, , Bar_#%m%_#%i%, % " BAT: " b3 "% " - } - anyText := Config_readinAny() - If anyText { - i := Config_viewCount + 4 - GuiControlGet, anyContent, , Bar_#%m%_#%i% - If Not (anyText = anyContent) - GuiControl, , Bar_#%m%_#%i%, % anyText - } - If Config_readinTime { - i := Config_viewCount + 5 - GuiControl, , Bar_#%m%_#%i%, % " " A_Hour ":" A_Min " " - } - } + Local anyContent, anyText, b1, b2, b3, GuiN, i, m + + Loop, % Manager_monitorCount { + m := A_Index + GuiN := (m - 1) + 1 + Log_dbg_msg(6, "Bar_updateStatus(): Gui, " . GuiN . ": Default") + Gui, %GuiN%: Default + If Config_readinBat { + Bar_getBatteryStatus(b1, b2) + b3 := SubStr(" " b1, -2) + i := Config_viewCount + 3 + 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") { ; 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 { + GuiControl, +Background%Config_normBgColor3% +c%Config_normFgColor3%, Bar_#%m%_#%i%_tagged + GuiControl, +c%Config_normFgColor2%, Bar_#%m%_#%i% + } + GuiControl, , Bar_#%m%_#%i%_tagged, %b3% + GuiControl, , Bar_#%m%_#%i%, % " BAT: " b3 "% " + } + anyText := Config_readinAny() + If anyText { + i := Config_viewCount + 4 + GuiControlGet, anyContent, , Bar_#%m%_#%i% + If Not (anyText = anyContent) + GuiControl, , Bar_#%m%_#%i%, % anyText + } + If Config_readinTime { + i := Config_viewCount + 5 + GuiControl, , Bar_#%m%_#%i%, % " " A_Hour ":" A_Min " " + } + } } Bar_updateTitle(debugMsg = "") { - Local aWndId, aWndTitle, content, GuiN, i, title - - If debugMsg - aWndTitle := debugMsg - Else { - WinGet, aWndId, ID, A - WinGetTitle, aWndTitle, ahk_id %aWndId% - If InStr(Bar_hideTitleWndIds, aWndId ";") Or (aWndTitle = "bug.n_BAR_0") - aWndTitle := "" - If Manager_#%aWndId%_isFloating - aWndTitle := "~ " aWndTitle - If (Manager_monitorCount > 1) - aWndTitle := "[" Manager_aMonitor "] " aWndTitle - } - title := " " . aWndTitle . " " - - 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 { - GuiN := (A_Index - 1) + 1 - Log_dbg_msg(6, "Bar_updateTitle(): Gui, " . GuiN . ": Default") - Gui, %GuiN%: Default - GuiControlGet, content, , Bar_#%A_Index%_#%i% - If (A_Index = Manager_aMonitor) { - If Not (content = title) - GuiControl, , Bar_#%A_Index%_#%i%, % title - } Else If Not (content = "") - GuiControl, , Bar_#%A_Index%_#%i%, - } - Bar_aWndId := aWndId + Local aWndId, aWndTitle, content, GuiN, i, title + + If debugMsg + aWndTitle := debugMsg + Else { + WinGet, aWndId, ID, A + WinGetTitle, aWndTitle, ahk_id %aWndId% + If InStr(Bar_hideTitleWndIds, aWndId ";") Or (aWndTitle = "bug.n_BAR_0") + aWndTitle := "" + If Manager_#%aWndId%_isFloating + aWndTitle := "~ " aWndTitle + If (Manager_monitorCount > 1) + aWndTitle := "[" Manager_aMonitor "] " aWndTitle + } + title := " " . aWndTitle . " " + + 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 { + GuiN := (A_Index - 1) + 1 + Log_dbg_msg(6, "Bar_updateTitle(): Gui, " . GuiN . ": Default") + Gui, %GuiN%: Default + GuiControlGet, content, , Bar_#%A_Index%_#%i% + If (A_Index = Manager_aMonitor) { + If Not (content = title) + GuiControl, , Bar_#%A_Index%_#%i%, % title + } Else If Not (content = "") + GuiControl, , Bar_#%A_Index%_#%i%, + } + Bar_aWndId := aWndId } ; Update the view portion of the status bar. Bar_updateView(m, v) { - Local IdsLen, ViewIdsLen - - GuiN := (m - 1) + 1 - Log_dbg_msg(6, "Bar_updateView(): m: " . m . "; Gui, " . GuiN . ": Default") - Gui, %GuiN%: Default - - IdsLen := StrLen(Manager_managedWndIds) - - 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 StrLen(View_#%m%_#%v%_wndIds) > 0 { - ; 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 { - ; 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% { - ViewIdsLen := StrLen( View_#%m%_#%A_Index%_wndIds ) - ; Update the percentage fill for the view. - GuiControl, , Bar_#%m%_#%A_Index%_tagged, % ViewIdsLen / IdsLen * 100 - ; Refresh the number on the bar. - GuiControl, , Bar_#%m%_#%A_Index%, % Config_viewNames_#%A_Index% - } + Local IdsLen, ViewIdsLen + + GuiN := (m - 1) + 1 + Log_dbg_msg(6, "Bar_updateView(): m: " . m . "; Gui, " . GuiN . ": Default") + Gui, %GuiN%: Default + + IdsLen := StrLen(Manager_managedWndIds) + + 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 StrLen(View_#%m%_#%v%_wndIds) > 0 { + ; 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 { + ; 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% { + ViewIdsLen := StrLen( View_#%m%_#%A_Index%_wndIds ) + ; Update the percentage fill for the view. + GuiControl, , Bar_#%m%_#%A_Index%_tagged, % ViewIdsLen / IdsLen * 100 + ; Refresh the number on the bar. + GuiControl, , Bar_#%m%_#%A_Index%, % Config_viewNames_#%A_Index% + } } diff --git a/src/Config.ahk b/src/Config.ahk index 9ba4435..886e1be 100644 --- a/src/Config.ahk +++ b/src/Config.ahk @@ -1,431 +1,431 @@ -/** - * bug.n - tiling window management - * Copyright (c) 2010-2012 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 - */ +/* + 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 +*/ Config_init() { - Local i, key, layout0, layout1, layout2, vNames0, vNames1, vNames2, vNames3, vNames4, vNames5, vNames6, vNames7, vNames8, vNames9 - - ; status bar - Config_showBar := True ; If false, the bar is hidden. It can be made visible or hidden by hotkey (see below). - Config_horizontalBarPos := "left" ; The horizontal position of the bar: "center", "left" or "right" side of the monitor or an offset in pixel (px) from the left (>= 0) or right (< 0). - Config_verticalBarPos := "top" ; The vertical position of the bar: "top" or "bottom" of the monitor, "tray" = sub-window of the task bar. - Config_barWidth := "100%" ; The width of the bar in pixel (px) or with a per cent sign (%) as a percentage. - Config_singleRowBar := True ; If false, the bar will have to rows, one for the window title and one for all other GUI controls. - Config_spaciousBar := False ; If true, the height of the bar will be set to a value equal to the height of an edit control, else it will be set to the text height. - Config_fontName := "Lucida Console" ; A monospace font is preferable for bug.n to calculate the correct width of the bar and its elements (sub-windows). - Config_fontSize := - Config_normBgColor := - Config_normFgColor := - Config_selBgColor := - Config_selFgColor := - Config_readinBat := False ; If true, the system battery status is read in and displayed in the status bar. This only makes sense, if you have a system battery (notebook). - Config_readinCpu := False ; If true, the current CPU load is read in and displayed in the status bar. - Config_readinDate := True ; If true, the current date is read in (format: "WW, DD. MMM. YYYY") and displayed in the status bar. - Config_readinDiskLoad := False ; If true, the current disk load (read and write) is read in and displayed in the status bar. - Config_readinMemoryUsage := False ; If true, the system memory usage is read in and displayed in the status bar. - Config_readinNetworkLoad := False ; If true, the current network load (up and down) is read in and displayed in the status bar. - Config_readinTime := True ; If true, the current time is read in (format: "HH:MM") and displayed in the status bar. - Config_readinInterval := 30000 ; Time in milliseconds after which the above status values are refreshed. - - ; Windows ui elements - Config_bbCompatibility := False ; If true, bug.n looks for BlackBox components (bbLeanBar, bbSlit and SystemBarEx) when calculating the work area. It is assumed that the virtual desktop functionality of BlackBox and NOT bug.n is used (=> Hiding and showing windows is detected and acted upon). - Config_borderWidth := 0 ; If > 0, the window border width is set to the integer value Config_borderWidth. - Config_borderPadding := -1 ; If >= 0, the window border padding is set to the integer value Config_borderPadding (only for Windows >= Vista). - Config_showTaskBar := False ; If false, the task bar is hidden. It can be made visible or hidden by hotkey (see below). - Config_showBorder := True ; If false, the window borders are hidden; therefor windows cannot be resized manually by dragging the border, even if using the according hotkey. - Config_selBorderColor := "" ; Border colour of the active window; format: 0x00BBGGRR (e. g. "0x006A240A", if = "", the system's window border colour is not changed). - ; Config_borderWidth, Config_borderPadding and Config_selBorderColor are especially usefull, if you are not allowed to set the design in the system settings. - ; window arrangement - Config_viewNames := "1;2;3;4;5;6;7;8;9" ; The names of the views separated by a semicolon. This variable sets the names of the views shown in the status bar and determines the nummber of views (Config_viewCount); the total number of names given, i. e. views, should not be exceeded in the hotkeys section below. - Config_layout_#1 := "[]=;tile" ; The layout symbol and arrange function (the first entry is set as the default layout, no layout function means floating behavior) - Config_layout_#2 := "[M];monocle" - Config_layout_#3 := "><>;" - Config_layoutCount := 3 ; Total number of layouts defined above. - Config_layoutAxis_#1 := 1 ; The layout axis: 1 = x, 2 = y; negative values mirror the layout, setting the master area to the right / bottom instead of left / top. - Config_layoutAxis_#2 := 2 ; The master axis: 1 = x (from left to right), 2 = y (from top to bottom), 3 = z (monocle). - Config_layoutAxis_#3 := 2 ; The stack axis: 1 = x (from left to right), 2 = y (from top to bottom), 3 = z (monocle). - Config_layoutGapWidth := 0 ; The default gap width in px (only even numbers) of the "tile" layout, i. e. the space between windows and around the layout. - Config_layoutMFactor := 0.6 ; The factor for the size of the master area, which is multiplied by the monitor size. - Config_mouseFollowsFocus := True ; If true, the mouse pointer is set over the focused window, if a window is activated by bug.n. - Config_onActiveHiddenWnds := "view" ; The action, which will be taken, if a window e. g. should be activated, but is not visible; "view": show the view accordng to the first tag of the window in question, "tag": add the window in question to the current visible view, "hide": hide the window again ignoring the activation. - Config_newWndPosition := "top" ; The position of a new window in a view; "top": at the beginning of the window list and the master area (default), "masterBottom": at the end of the master area, "stackTop": on top of the stack area, "bottom": at the end of the window list and the stack area. - Config_shellMsgDelay := 350 ; The time bug.n waits after a shell message (a window is opened, closed or the focus has been changed); if there are any problems recognizing, when windows are opened or closed, try to increase this number. - Config_syncMonitorViews := 0 ; The number of monitors (2 or more), for which views should be activated, when using the accordant hotkey. If set to 1, the views are activated for all monitors. If set to 0, views are activated independently (only on the active monitor). - Config_viewFollowsTagged := False ; If true and a window is tagged with a single tag, the view is correspondingly set to the tag. - - ; Config_rule_#i := ";;<window style (hexadecimal number or blank)>; - ; <is managed (1 = True or 0 = False)>; - ; <monitor (0 <= integer <= total number of monitors, 0 means the currently active monitor)>; - ; <tags (binary mask as integer >= 0, e. g. 17 for 1 and 5, 0 means the currently active tag)>; - ; <is floating (1 = True or 0 = False)>;<is decorated (1 = True or 0 = False)>;<hide title (1 = True or 0 = False)>" - ; (";" is not allowed as a character) - Config_rule_#1 := ".*;.*;;1;0;0;0;0;0" ; At first you may set a default rule (.*;.*;) for a default monitor, view and / or showing window title bars. - 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. - Config_rule_#3 := "SWT_Window0;.*;;1;0;0;0;0;0" ; Windows created by Java (SWT) e. g. Eclipse have the style WS_POPUP, but should excluded from the above rule. - Config_rule_#4 := "Xming;.*;;1;0;0;0;0;0" ; Xming windows have the style WS_POPUP, but should be excluded from the above rule. - Config_rule_#5 := "MsiDialog(No)?CloseClass;.*;;1;0;0;1;1;0" - Config_rule_#6 := "AdobeFlashPlayerInstaller;.*;;1;0;0;1;0;1" - Config_rule_#7 := "CalcFrame;.*;;1;0;0;1;1;0" - Config_rule_#8 := "_sp;_sp;;1;0;0;1;0;1" - Config_rule_#9 := "MozillaDialogClass;.*;;1;0;0;1;1;0" - Config_rule_#10 := "gdkWindowToplevel;GIMP-Start;;1;0;0;1;1;0" - Config_rule_#11 := "gdkWindowToplevel;GNU Image Manipulation Program;;1;0;0;1;1;0" - Config_rule_#12 := "gdkWindowToplevel;Werkzeugkasten;;1;0;0;1;1;0" - Config_rule_#13 := "gdkWindowToplevel;Ebenen, .* - Pinsel, Muster, .*;;1;0;0;1;1;0" - Config_rule_#14 := "gdkWindowToplevel;Toolbox;;1;0;0;1;1;0" - Config_rule_#15 := "gdkWindowToplevel;Layers, Channels, Paths, .*;;1;0;0;1;1;0" - Config_ruleCount := 15 ; This variable has to be set to the total number of active rules above. - - ; configuration management - Config_autoSaveSession := False ; Automatically save the current state of monitors, views, layouts (active view, layout, axes, mfact and msplit) to the configuration file (set below) when quitting bug.n. - 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_restore("Config") - Config_getSystemSettings() - Config_initColors() - Loop, % Config_layoutCount { - StringSplit, layout, Config_layout_#%A_Index%, `; - Config_layoutFunction_#%A_Index% := layout2 - Config_layoutSymbol_#%A_Index% := layout1 - } - StringSplit, vNames, Config_viewNames, `; - If vNames0 > 9 - Config_viewCount := 9 - Else - Config_viewCount := vNames0 - Loop, % Config_viewCount - Config_viewNames_#%A_Index% := vNames%A_Index% + Local i, key, layout0, layout1, layout2, vNames0, vNames1, vNames2, vNames3, vNames4, vNames5, vNames6, vNames7, vNames8, vNames9 + + ; status bar + Config_showBar := True ; If false, the bar is hidden. It can be made visible or hidden by hotkey (see below). + Config_horizontalBarPos := "left" ; The horizontal position of the bar: "center", "left" or "right" side of the monitor or an offset in pixel (px) from the left (>= 0) or right (< 0). + Config_verticalBarPos := "top" ; The vertical position of the bar: "top" or "bottom" of the monitor, "tray" = sub-window of the task bar. + Config_barWidth := "100%" ; The width of the bar in pixel (px) or with a per cent sign (%) as a percentage. + Config_singleRowBar := True ; If false, the bar will have to rows, one for the window title and one for all other GUI controls. + Config_spaciousBar := False ; If true, the height of the bar will be set to a value equal to the height of an edit control, else it will be set to the text height. + Config_fontName := "Lucida Console" ; A monospace font is preferable for bug.n to calculate the correct width of the bar and its elements (sub-windows). + Config_fontSize := + Config_normBgColor := + Config_normFgColor := + Config_selBgColor := + Config_selFgColor := + Config_readinBat := False ; If true, the system battery status is read in and displayed in the status bar. This only makes sense, if you have a system battery (notebook). + Config_readinCpu := False ; If true, the current CPU load is read in and displayed in the status bar. + Config_readinDate := True ; If true, the current date is read in (format: "WW, DD. MMM. YYYY") and displayed in the status bar. + Config_readinDiskLoad := False ; If true, the current disk load (read and write) is read in and displayed in the status bar. + Config_readinMemoryUsage := False ; If true, the system memory usage is read in and displayed in the status bar. + Config_readinNetworkLoad := False ; If true, the current network load (up and down) is read in and displayed in the status bar. + Config_readinTime := True ; If true, the current time is read in (format: "HH:MM") and displayed in the status bar. + Config_readinInterval := 30000 ; Time in milliseconds after which the above status values are refreshed. + + ; Windows ui elements + Config_bbCompatibility := False ; If true, bug.n looks for BlackBox components (bbLeanBar, bbSlit and SystemBarEx) when calculating the work area. It is assumed that the virtual desktop functionality of BlackBox and NOT bug.n is used (=> Hiding and showing windows is detected and acted upon). + Config_borderWidth := 0 ; If > 0, the window border width is set to the integer value Config_borderWidth. + Config_borderPadding := -1 ; If >= 0, the window border padding is set to the integer value Config_borderPadding (only for Windows >= Vista). + Config_showTaskBar := False ; If false, the task bar is hidden. It can be made visible or hidden by hotkey (see below). + Config_showBorder := True ; If false, the window borders are hidden; therefor windows cannot be resized manually by dragging the border, even if using the according hotkey. + Config_selBorderColor := "" ; Border colour of the active window; format: 0x00BBGGRR (e. g. "0x006A240A", if = "", the system's window border colour is not changed). + ; Config_borderWidth, Config_borderPadding and Config_selBorderColor are especially usefull, if you are not allowed to set the design in the system settings. + ; window arrangement + Config_viewNames := "1;2;3;4;5;6;7;8;9" ; The names of the views separated by a semicolon. This variable sets the names of the views shown in the status bar and determines the nummber of views (Config_viewCount); the total number of names given, i. e. views, should not be exceeded in the hotkeys section below. + Config_layout_#1 := "[]=;tile" ; The layout symbol and arrange function (the first entry is set as the default layout, no layout function means floating behavior) + Config_layout_#2 := "[M];monocle" + Config_layout_#3 := "><>;" + Config_layoutCount := 3 ; Total number of layouts defined above. + Config_layoutAxis_#1 := 1 ; The layout axis: 1 = x, 2 = y; negative values mirror the layout, setting the master area to the right / bottom instead of left / top. + Config_layoutAxis_#2 := 2 ; The master axis: 1 = x (from left to right), 2 = y (from top to bottom), 3 = z (monocle). + Config_layoutAxis_#3 := 2 ; The stack axis: 1 = x (from left to right), 2 = y (from top to bottom), 3 = z (monocle). + Config_layoutGapWidth := 0 ; The default gap width in px (only even numbers) of the "tile" layout, i. e. the space between windows and around the layout. + Config_layoutMFactor := 0.6 ; The factor for the size of the master area, which is multiplied by the monitor size. + Config_mouseFollowsFocus := True ; If true, the mouse pointer is set over the focused window, if a window is activated by bug.n. + Config_onActiveHiddenWnds := "view" ; The action, which will be taken, if a window e. g. should be activated, but is not visible; "view": show the view accordng to the first tag of the window in question, "tag": add the window in question to the current visible view, "hide": hide the window again ignoring the activation. + Config_newWndPosition := "top" ; The position of a new window in a view; "top": at the beginning of the window list and the master area (default), "masterBottom": at the end of the master area, "stackTop": on top of the stack area, "bottom": at the end of the window list and the stack area. + Config_shellMsgDelay := 350 ; The time bug.n waits after a shell message (a window is opened, closed or the focus has been changed); if there are any problems recognizing, when windows are opened or closed, try to increase this number. + Config_syncMonitorViews := 0 ; The number of monitors (2 or more), for which views should be activated, when using the accordant hotkey. If set to 1, the views are activated for all monitors. If set to 0, views are activated independently (only on the active monitor). + Config_viewFollowsTagged := False ; If true and a window is tagged with a single tag, the view is correspondingly set to the tag. + + ; Config_rule_#i := "<class (regular expression string)>;<title (regular expression string)>;<window style (hexadecimal number or blank)>; + ; <is managed (1 = True or 0 = False)>; + ; <monitor (0 <= integer <= total number of monitors, 0 means the currently active monitor)>; + ; <tags (binary mask as integer >= 0, e. g. 17 for 1 and 5, 0 means the currently active tag)>; + ; <is floating (1 = True or 0 = False)>;<is decorated (1 = True or 0 = False)>;<hide title (1 = True or 0 = False)>" + ; (";" is not allowed as a character) + Config_rule_#1 := ".*;.*;;1;0;0;0;0;0" ; At first you may set a default rule (.*;.*;) for a default monitor, view and / or showing window title bars. + 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. + Config_rule_#3 := "SWT_Window0;.*;;1;0;0;0;0;0" ; Windows created by Java (SWT) e. g. Eclipse have the style WS_POPUP, but should excluded from the above rule. + Config_rule_#4 := "Xming;.*;;1;0;0;0;0;0" ; Xming windows have the style WS_POPUP, but should be excluded from the above rule. + Config_rule_#5 := "MsiDialog(No)?CloseClass;.*;;1;0;0;1;1;0" + Config_rule_#6 := "AdobeFlashPlayerInstaller;.*;;1;0;0;1;0;1" + Config_rule_#7 := "CalcFrame;.*;;1;0;0;1;1;0" + Config_rule_#8 := "_sp;_sp;;1;0;0;1;0;1" + Config_rule_#9 := "MozillaDialogClass;.*;;1;0;0;1;1;0" + Config_rule_#10 := "gdkWindowToplevel;GIMP-Start;;1;0;0;1;1;0" + Config_rule_#11 := "gdkWindowToplevel;GNU Image Manipulation Program;;1;0;0;1;1;0" + Config_rule_#12 := "gdkWindowToplevel;Werkzeugkasten;;1;0;0;1;1;0" + Config_rule_#13 := "gdkWindowToplevel;Ebenen, .* - Pinsel, Muster, .*;;1;0;0;1;1;0" + Config_rule_#14 := "gdkWindowToplevel;Toolbox;;1;0;0;1;1;0" + Config_rule_#15 := "gdkWindowToplevel;Layers, Channels, Paths, .*;;1;0;0;1;1;0" + Config_ruleCount := 15 ; This variable has to be set to the total number of active rules above. + + ; configuration management + Config_autoSaveSession := False ; Automatically save the current state of monitors, views, layouts (active view, layout, axes, mfact and msplit) to the configuration file (set below) when quitting bug.n. + 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_restore("Config") + Config_getSystemSettings() + Config_initColors() + Loop, % Config_layoutCount { + StringSplit, layout, Config_layout_#%A_Index%, `; + Config_layoutFunction_#%A_Index% := layout2 + Config_layoutSymbol_#%A_Index% := layout1 + } + StringSplit, vNames, Config_viewNames, `; + If vNames0 > 9 + Config_viewCount := 9 + Else + Config_viewCount := vNames0 + Loop, % Config_viewCount + Config_viewNames_#%A_Index% := vNames%A_Index% } 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, `; + 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) { ; systemColor format: 0xBBGGRR - rr := SubStr(systemColor, 7, 2) - gg := SubStr(systemColor, 5, 2) - bb := SubStr(systemColor, 3, 2) - - Return, rr gg bb +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() { - Global Config_fontName, Config_fontSize, Config_normBgColor, Config_normFgColor, Config_selBgColor, Config_selFgColor - - 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 { - 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 { - Config_normBgColor := Config_convertSystemColor(DllCall("GetSysColor", "Int", 4)) ; COLOR_MENU - Config_normBgColor .= ";" Config_convertSystemColor(DllCall("GetSysColor", "Int", 3)) ; COLOR_INACTIVECAPTION - Config_normBgColor .= ";" Config_convertSystemColor(DllCall("GetSysColor", "Int", 28)) ; COLOR_GRADIENTINACTIVECAPTION - Config_normBgColor .= ";Red" - Config_normBgColor .= ";" Config_convertSystemColor(DllCall("GetSysColor", "Int", 28)) ; COLOR_GRADIENTINACTIVECAPTION - } - If Not Config_normFgColor { - Config_normFgColor := Config_convertSystemColor(DllCall("GetSysColor", "Int", 7)) ; COLOR_MENUTEXT - Config_normFgColor .= ";Default" - Config_normFgColor .= ";" Config_convertSystemColor(DllCall("GetSysColor", "Int", 3)) ; COLOR_INACTIVECAPTION - Config_normFgColor .= ";" Config_convertSystemColor(DllCall("GetSysColor", "Int", 19)) ; COLOR_INACTIVECAPTIONTEXT - Config_normFgColor .= ";" Config_convertSystemColor(DllCall("GetSysColor", "Int", 13)) ; COLOR_HIGHLIGHT - Config_normFgColor .= ";White" - Config_normFgColor .= ";Default" - Config_normFgColor .= ";" Config_convertSystemColor(DllCall("GetSysColor", "Int", 3)) ; COLOR_INACTIVECAPTION - } - If Not Config_selBgColor { - Config_selBgColor := Config_convertSystemColor(DllCall("GetSysColor", "Int", 27)) ; COLOR_GRADIENTACTIVECAPTION - } - If Not Config_selFgColor { - Config_selFgColor := Config_convertSystemColor(DllCall("GetSysColor", "Int", 9)) ; COLOR_CAPTIONTEXT - Config_selFgColor .= ";" Config_convertSystemColor(DllCall("GetSysColor", "Int", 2)) ; COLOR_ACTIVECAPTION - } - SetFormat, Integer, d + Global Config_fontName, Config_fontSize, Config_normBgColor, Config_normFgColor, Config_selBgColor, Config_selFgColor + + 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 { + 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 { + Config_normBgColor := Config_convertSystemColor(DllCall("GetSysColor", "Int", 4)) ; COLOR_MENU + Config_normBgColor .= ";" Config_convertSystemColor(DllCall("GetSysColor", "Int", 3)) ; COLOR_INACTIVECAPTION + Config_normBgColor .= ";" Config_convertSystemColor(DllCall("GetSysColor", "Int", 28)) ; COLOR_GRADIENTINACTIVECAPTION + Config_normBgColor .= ";Red" + Config_normBgColor .= ";" Config_convertSystemColor(DllCall("GetSysColor", "Int", 28)) ; COLOR_GRADIENTINACTIVECAPTION + } + If Not Config_normFgColor { + Config_normFgColor := Config_convertSystemColor(DllCall("GetSysColor", "Int", 7)) ; COLOR_MENUTEXT + Config_normFgColor .= ";Default" + Config_normFgColor .= ";" Config_convertSystemColor(DllCall("GetSysColor", "Int", 3)) ; COLOR_INACTIVECAPTION + Config_normFgColor .= ";" Config_convertSystemColor(DllCall("GetSysColor", "Int", 19)) ; COLOR_INACTIVECAPTIONTEXT + Config_normFgColor .= ";" Config_convertSystemColor(DllCall("GetSysColor", "Int", 13)) ; COLOR_HIGHLIGHT + Config_normFgColor .= ";White" + Config_normFgColor .= ";Default" + Config_normFgColor .= ";" Config_convertSystemColor(DllCall("GetSysColor", "Int", 3)) ; COLOR_INACTIVECAPTION + } + If Not Config_selBgColor { + Config_selBgColor := Config_convertSystemColor(DllCall("GetSysColor", "Int", 27)) ; COLOR_GRADIENTACTIVECAPTION + } + If Not Config_selFgColor { + Config_selFgColor := Config_convertSystemColor(DllCall("GetSysColor", "Int", 9)) ; COLOR_CAPTIONTEXT + Config_selFgColor .= ";" Config_convertSystemColor(DllCall("GetSysColor", "Int", 2)) ; COLOR_ACTIVECAPTION + } + SetFormat, Integer, d } Config_hotkeyLabel: - Config_redirectHotkey(A_ThisHotkey) + Config_redirectHotkey(A_ThisHotkey) Return -Config_readinAny() { ; Add information to the variable "text" in this function to display it in the status bar. - Global Config_readinCpu, Config_readinDate, Config_readinDiskLoad, Config_readinMemoryUsage, Config_readinNetworkLoad - - text := "" - If Config_readinCpu - text .= " CPU: " Bar_getSystemTimes() "% " - If Config_readinMemoryUsage { - If Config_readinCpu +Config_readinAny() { ; Add information to the variable "text" in this function to display it in the status bar. + Global Config_readinCpu, Config_readinDate, Config_readinDiskLoad, Config_readinMemoryUsage, Config_readinNetworkLoad + + text := "" + If Config_readinCpu + text .= " CPU: " Bar_getSystemTimes() "% " + If Config_readinMemoryUsage { + If Config_readinCpu text .= "|" - text .= " RAM: " Bar_getMemoryUsage() "% " + text .= " RAM: " Bar_getMemoryUsage() "% " } - If Config_readinDiskLoad { - If (Config_readinCpu Or Config_readinMemoryUsage) - text .= "|" - Bar_getDiskLoad(rLoad, wLoad) - text .= " Dr: " rLoad "% | Dw: " wLoad "% " - } - If Config_readinNetworkLoad { - If (Config_readinCpu Or Config_readinMemoryUsage Or Config_readinDiskLoad) - text .= "|" - Bar_getNetworkLoad(upLoad, dnLoad) - text .= " UP: " upLoad " KB/s | dn: " dnLoad " KB/s " - } - If Config_readinDate { - If (Config_readinCpu Or Config_readinMemoryUsage Or Config_readinDiskLoad Or Config_readinNetworkLoad) - text .= "|" - text .= " " A_DDD ", " A_DD ". " A_MMM ". " A_YYYY " " - } - - Return, text + If Config_readinDiskLoad { + If (Config_readinCpu Or Config_readinMemoryUsage) + text .= "|" + Bar_getDiskLoad(rLoad, wLoad) + text .= " Dr: " rLoad "% | Dw: " wLoad "% " + } + If Config_readinNetworkLoad { + If (Config_readinCpu Or Config_readinMemoryUsage Or Config_readinDiskLoad) + text .= "|" + Bar_getNetworkLoad(upLoad, dnLoad) + text .= " UP: " upLoad " KB/s | dn: " dnLoad " KB/s " + } + If Config_readinDate { + If (Config_readinCpu Or Config_readinMemoryUsage Or Config_readinDiskLoad Or Config_readinNetworkLoad) + text .= "|" + text .= " " A_DDD ", " A_DD ". " A_MMM ". " A_YYYY " " + } + + Return, text } Config_redirectHotkey(key) { - Local functionArgument0, functionArgument1, functionArgument2, functionArguments, functionName, i, j, parameter0, parameter1, parameter2, parameter3, parameters, type - - Loop, % Config_hotkeyCount - If (key = Config_hotkey_#%A_index%_key) { - type := SubStr(Config_hotkey_#%A_index%_command, 1, 5) - If (type = "Run, ") { - parameters := SubStr(Config_hotkey_#%A_index%_command, 6) - If InStr(parameters, ", ") { - StringSplit, parameter, parameters, `, - If (parameter0 = 2) { - StringTrimLeft, parameter2, parameter2, 1 - Run, %parameter1%, %parameter2% - } 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(Config_hotkey_#%A_index%_command, 6) - Else If (type = "Reloa") - Reload - Else If (Config_hotkey_#%A_Index%_command = "ExitApp") - ExitApp - Else { - i := InStr(Config_hotkey_#%A_index%_command, "(") - j := InStr(Config_hotkey_#%A_index%_command, ")", False, i) - If i And j { - functionName := SubStr(Config_hotkey_#%A_index%_command, 1, i - 1) - functionArguments := SubStr(Config_hotkey_#%A_index%_command, i + 1, j - (i + 1)) - StringSplit, functionArgument, functionArguments, `, - If (functionArgument0 < 2) - %functionName%(functionArguments) - Else If (functionArgument0 = 2) { - StringTrimLeft, functionArgument2, functionArgument2, 1 - %functionName%(functionArgument1, functionArgument2) - } - } - } - Break - } + Local functionArgument0, functionArgument1, functionArgument2, functionArguments, functionName, i, j, parameter0, parameter1, parameter2, parameter3, parameters, type + + Loop, % Config_hotkeyCount + If (key = Config_hotkey_#%A_index%_key) { + type := SubStr(Config_hotkey_#%A_index%_command, 1, 5) + If (type = "Run, ") { + parameters := SubStr(Config_hotkey_#%A_index%_command, 6) + If InStr(parameters, ", ") { + StringSplit, parameter, parameters, `, + If (parameter0 = 2) { + StringTrimLeft, parameter2, parameter2, 1 + Run, %parameter1%, %parameter2% + } 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(Config_hotkey_#%A_index%_command, 6) + Else If (type = "Reloa") + Reload + Else If (Config_hotkey_#%A_Index%_command = "ExitApp") + ExitApp + Else { + i := InStr(Config_hotkey_#%A_index%_command, "(") + j := InStr(Config_hotkey_#%A_index%_command, ")", False, i) + If i And j { + functionName := SubStr(Config_hotkey_#%A_index%_command, 1, i - 1) + functionArguments := SubStr(Config_hotkey_#%A_index%_command, i + 1, j - (i + 1)) + StringSplit, functionArgument, functionArguments, `, + If (functionArgument0 < 2) + %functionName%(functionArguments) + Else If (functionArgument0 = 2) { + StringTrimLeft, functionArgument2, functionArgument2, 1 + %functionName%(functionArgument1, functionArgument2) + } + } + } + Break + } } Config_restore(section, m = 0) { - Local cmd, i, key, type, val, var - - If FileExist(Config_filePath) { - If (section = "Config") { - Loop, READ, %Config_filePath% - If (SubStr(A_LoopReadLine, 1, 7) = "Config_") { - 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") { - i := InStr(val, "::") - key := SubStr(val, 1, i - 1) - cmd := SubStr(val, i + 2) - If Not cmd - Hotkey, %key%, Off - Else { - Config_hotkeyCount += 1 - Config_hotkey_#%Config_hotkeyCount%_key := key - Config_hotkey_#%Config_hotkeyCount%_command := cmd - Hotkey, %key%, Config_hotkeyLabel - } - } Else If (type = "Config_rule") { - i := 0 - If InStr(var, "Config_rule_#") - i := SubStr(var, 14) - If (i = 0 Or i > Config_ruleCount) { - Config_ruleCount += 1 - i := Config_ruleCount - } - var := "Config_rule_#" i - } - %var% := val - } - } Else If (section = "Monitor") { - Loop, READ, %Config_filePath% - If (SubStr(A_LoopReadLine, 1, 10 + StrLen(m)) = "Monitor_#" m "_" Or SubStr(A_LoopReadLine, 1, 8 + StrLen(m)) = "View_#" m "_#") { - i := InStr(A_LoopReadLine, "=") - var := SubStr(A_LoopReadLine, 1, i - 1) - val := SubStr(A_LoopReadLine, i + 1) - %var% := val - } - } - } + Local cmd, i, key, type, val, var + + If FileExist(Config_filePath) { + If (section = "Config") { + Loop, READ, %Config_filePath% + If (SubStr(A_LoopReadLine, 1, 7) = "Config_") { + 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") { + i := InStr(val, "::") + key := SubStr(val, 1, i - 1) + cmd := SubStr(val, i + 2) + If Not cmd + Hotkey, %key%, Off + Else { + Config_hotkeyCount += 1 + Config_hotkey_#%Config_hotkeyCount%_key := key + Config_hotkey_#%Config_hotkeyCount%_command := cmd + Hotkey, %key%, Config_hotkeyLabel + } + } Else If (type = "Config_rule") { + i := 0 + If InStr(var, "Config_rule_#") + i := SubStr(var, 14) + If (i = 0 Or i > Config_ruleCount) { + Config_ruleCount += 1 + i := Config_ruleCount + } + var := "Config_rule_#" i + } + %var% := val + } + } Else If (section = "Monitor") { + Loop, READ, %Config_filePath% + If (SubStr(A_LoopReadLine, 1, 10 + StrLen(m)) = "Monitor_#" m "_" Or SubStr(A_LoopReadLine, 1, 8 + StrLen(m)) = "View_#" m "_#") { + i := InStr(A_LoopReadLine, "=") + var := SubStr(A_LoopReadLine, 1, i - 1) + val := SubStr(A_LoopReadLine, i + 1) + %var% := val + } + } + } } Config_saveSession() { - Local m, text - - text := "; bug.n - tiling window management`n; @version " VERSION "`n`n" - If FileExist(Config_filePath) { - Loop, READ, %Config_filePath% - If (SubStr(A_LoopReadLine, 1, 7) = "Config_") - text .= A_LoopReadLine "`n" - text .= "`n" - } - FileDelete, %Config_filePath% - - Loop, % Manager_monitorCount { - m := A_Index - If Not (Monitor_#%m%_aView_#1 = 1) - text .= "Monitor_#" m "_aView_#1=" Monitor_#%m%_aView_#1 "`n" - If Not (Monitor_#%m%_aView_#2 = 1) - 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 { - If Not (View_#%m%_#%A_Index%_layout_#1 = 1) - text .= "View_#" m "_#" A_Index "_layout_#1=" View_#%m%_#%A_Index%_layout_#1 "`n" - If Not (View_#%m%_#%A_Index%_layout_#2 = 1) - text .= "View_#" m "_#" A_Index "_layout_#2=" View_#%m%_#%A_Index%_layout_#2 "`n" - If Not (View_#%m%_#%A_Index%_layoutAxis_#1 = Config_layoutAxis_#1) - text .= "View_#" m "_#" A_Index "_layoutAxis_#1=" View_#%m%_#%A_Index%_layoutAxis_#1 "`n" - If Not (View_#%m%_#%A_Index%_layoutAxis_#2 = Config_layoutAxis_#2) - text .= "View_#" m "_#" A_Index "_layoutAxis_#2=" View_#%m%_#%A_Index%_layoutAxis_#2 "`n" - If Not (View_#%m%_#%A_Index%_layoutAxis_#3 = Config_layoutAxis_#3) - text .= "View_#" m "_#" A_Index "_layoutAxis_#3=" View_#%m%_#%A_Index%_layoutAxis_#3 "`n" - If Not (View_#%m%_#%A_Index%_layoutGapWidth = Config_layoutGapWidth) - text .= "View_#" m "_#" A_Index "_layoutGapWidth=" View_#%m%_#%A_Index%_layoutGapWidth "`n" - If Not (View_#%m%_#%A_Index%_layoutMFact = Config_layoutMFactor) - text .= "View_#" m "_#" A_Index "_layoutMFact=" View_#%m%_#%A_Index%_layoutMFact "`n" - If Not (View_#%m%_#%A_Index%_layoutMX = 1) - text .= "View_#" m "_#" A_Index "_layoutMX=" View_#%m%_#%A_Index%_layoutMX "`n" - If Not (View_#%m%_#%A_Index%_layoutMY = 1) - text .= "View_#" m "_#" A_Index "_layoutMY=" View_#%m%_#%A_Index%_layoutMY "`n" - } - } - - FileAppend, %text%, %Config_filePath% + Local m, text + + text := "; bug.n - tiling window management`n; @version " VERSION "`n`n" + If FileExist(Config_filePath) { + Loop, READ, %Config_filePath% + If (SubStr(A_LoopReadLine, 1, 7) = "Config_") + text .= A_LoopReadLine "`n" + text .= "`n" + } + FileDelete, %Config_filePath% + + Loop, % Manager_monitorCount { + m := A_Index + If Not (Monitor_#%m%_aView_#1 = 1) + text .= "Monitor_#" m "_aView_#1=" Monitor_#%m%_aView_#1 "`n" + If Not (Monitor_#%m%_aView_#2 = 1) + 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 { + If Not (View_#%m%_#%A_Index%_layout_#1 = 1) + text .= "View_#" m "_#" A_Index "_layout_#1=" View_#%m%_#%A_Index%_layout_#1 "`n" + If Not (View_#%m%_#%A_Index%_layout_#2 = 1) + text .= "View_#" m "_#" A_Index "_layout_#2=" View_#%m%_#%A_Index%_layout_#2 "`n" + If Not (View_#%m%_#%A_Index%_layoutAxis_#1 = Config_layoutAxis_#1) + text .= "View_#" m "_#" A_Index "_layoutAxis_#1=" View_#%m%_#%A_Index%_layoutAxis_#1 "`n" + If Not (View_#%m%_#%A_Index%_layoutAxis_#2 = Config_layoutAxis_#2) + text .= "View_#" m "_#" A_Index "_layoutAxis_#2=" View_#%m%_#%A_Index%_layoutAxis_#2 "`n" + If Not (View_#%m%_#%A_Index%_layoutAxis_#3 = Config_layoutAxis_#3) + text .= "View_#" m "_#" A_Index "_layoutAxis_#3=" View_#%m%_#%A_Index%_layoutAxis_#3 "`n" + If Not (View_#%m%_#%A_Index%_layoutGapWidth = Config_layoutGapWidth) + text .= "View_#" m "_#" A_Index "_layoutGapWidth=" View_#%m%_#%A_Index%_layoutGapWidth "`n" + If Not (View_#%m%_#%A_Index%_layoutMFact = Config_layoutMFactor) + text .= "View_#" m "_#" A_Index "_layoutMFact=" View_#%m%_#%A_Index%_layoutMFact "`n" + If Not (View_#%m%_#%A_Index%_layoutMX = 1) + text .= "View_#" m "_#" A_Index "_layoutMX=" View_#%m%_#%A_Index%_layoutMX "`n" + If Not (View_#%m%_#%A_Index%_layoutMY = 1) + text .= "View_#" m "_#" A_Index "_layoutMY=" View_#%m%_#%A_Index%_layoutMY "`n" + } + } + + FileAppend, %text%, %Config_filePath% } /** - * key definitions + * key definitions * - * format: <modifier><key>::<function>(<argument>) - * modifier: ! = Alt (Mod1Mask), ^ = Ctrl (ControlMask), + = Shift (ShiftMask), # = LWin (Mod4Mask) + * format: <modifier><key>::<function>(<argument>) + * modifier: ! = Alt (Mod1Mask), ^ = Ctrl (ControlMask), + = Shift (ShiftMask), # = LWin (Mod4Mask) */ -#Down::View_activateWindow(+1) ; Activate the next window in the active view. -#Up::View_activateWindow(-1) ; Activate the previous window in the active view. -#+Down::View_shuffleWindow(+1) ; Move the active window to the next position in the window list of the view. -#+Up::View_shuffleWindow(-1) ; Move the active window to the previous position in the window list of the view. -#+Enter::View_shuffleWindow(0) ; Move the active window to the first position in the window list of the view. -#c::Manager_closeWindow() ; Close the active window. -#+d::Manager_toggleDecor() ; Show / Hide the title bar of the active window. -#+f::View_toggleFloating() ; Toggle the floating status of the active window (i. e. dis- / regard it when tiling). -#+m::Manager_moveWindow() ; Move the active window by key (only floating windows). -#+s::Manager_sizeWindow() ; Resize the active window by key (only floating windows). -#+x::Manager_maximizeWindow() ; Move and resize the active window to the size of the work area (only floating windows). -#i::Manager_getWindowInfo() ; Get information for the active window (id, title, class, process name, style, geometry, tags and floating state). -#+i::Manager_getWindowList() ; Get a window list for the active view (id, title and class). -#^i::Manager_logViewWindowList() ; Dump window information for the active view. -#+^i::Manager_logManagedWindowList() ; Dump window information for every managed window. -#^h::Manager_logHelp() ; Dump to the log an explanation of some of the other more cryptic log messages. -#^[::Log_decDebugLevel() ; Decrement the log debug level. -#^]::Log_incDebugLevel() ; Increment the log debug level. +#Down::View_activateWindow(+1) ; Activate the next window in the active view. +#Up::View_activateWindow(-1) ; Activate the previous window in the active view. +#+Down::View_shuffleWindow(+1) ; Move the active window to the next position in the window list of the view. +#+Up::View_shuffleWindow(-1) ; Move the active window to the previous position in the window list of the view. +#+Enter::View_shuffleWindow(0) ; Move the active window to the first position in the window list of the view. +#c::Manager_closeWindow() ; Close the active window. +#+d::Manager_toggleDecor() ; Show / Hide the title bar of the active window. +#+f::View_toggleFloating() ; Toggle the floating status of the active window (i. e. dis- / regard it when tiling). +#+m::Manager_moveWindow() ; Move the active window by key (only floating windows). +#+s::Manager_sizeWindow() ; Resize the active window by key (only floating windows). +#+x::Manager_maximizeWindow() ; Move and resize the active window to the size of the work area (only floating windows). +#i::Manager_getWindowInfo() ; Get information for the active window (id, title, class, process name, style, geometry, tags and floating state). +#+i::Manager_getWindowList() ; Get a window list for the active view (id, title and class). +#^i::Manager_logViewWindowList() ; Dump window information for the active view. +#+^i::Manager_logManagedWindowList() ; Dump window information for every managed window. +#^h::Manager_logHelp() ; Dump to the log an explanation of some of the other more cryptic log messages. +#^[::Log_decDebugLevel() ; Decrement the log debug level. +#^]::Log_incDebugLevel() ; Increment the log debug level. -#Tab::View_setLayout(-1) ; Set the previously set layout. You may also use View_setLayout(">") for setting the next layout in the layout array. -#f::View_setLayout(3) ; Set the 3rd defined layout (i. e. floating layout in the default configuration). -#m::View_setLayout(2) ; Set the 2nd defined layout (i. e. monocle layout in the default configuration). -#t::View_setLayout(1) ; Set the 1st defined layout (i. e. tile layout in the default configuration). -#Left::View_setMFactor(-0.05) ; Reduce the size of the master area in the active view (only for the "tile" layout). -#Right::View_setMFactor(+0.05) ; Enlarge the size of the master area in the active view (only for the "tile" layout). -#^t::View_rotateLayoutAxis(1, +1) ; Rotate the layout axis (i. e. 2 -> 1 = vertical layout, 1 -> 2 = horizontal layout, only for the "tile" layout). -#^Enter::View_rotateLayoutAxis(1, +2) ; Mirror the layout axis (i. e. -1 -> 1 / 1 -> -1 = master on the left / right side, -2 -> 2 / 2 -> -2 = master at top / bottom, only for the "tile" layout). -#^Tab::View_rotateLayoutAxis(2, +1) ; Rotate the master axis (i. e. 3 -> 1 = x-axis = horizontal stack, 1 -> 2 = y-axis = vertical stack, 2 -> 3 = z-axis = monocle, only for the "tile" layout). -#^+Tab::View_rotateLayoutAxis(3, +1) ; Rotate the stack axis (i. e. 3 -> 1 = x-axis = horizontal stack, 1 -> 2 = y-axis = vertical stack, 2 -> 3 = z-axis = monocle, only for the "tile" layout). -#^Up::View_setMY(+1) ; Increase the master Y dimension [1,9] (only for the "tile" layout). -#^Down::View_setMY(-1) ; Decrease the master Y dimension [1,9] (only for the "tile" layout). -#^Right::View_setMX(+1) ; Increase the master X dimension [1,9] (only for the "tile" layout). -#^Left::View_setMX(-1) ; Decrease the master X dimension [1,9] (only for the "tile" layout). -#+Left::View_setGapWidth(-2) ; Decrease the gap width by 2 px (only for the "tile" layout and even numbers; see the variable "Config_layoutGapWidth"). -#+Right::View_setGapWidth(+2) ; Increase the gap width by 2 px (only for the "tile" layout and even numbers; see the variable "Config_layoutGapWidth"). +#Tab::View_setLayout(-1) ; Set the previously set layout. You may also use View_setLayout(">") for setting the next layout in the layout array. +#f::View_setLayout(3) ; Set the 3rd defined layout (i. e. floating layout in the default configuration). +#m::View_setLayout(2) ; Set the 2nd defined layout (i. e. monocle layout in the default configuration). +#t::View_setLayout(1) ; Set the 1st defined layout (i. e. tile layout in the default configuration). +#Left::View_setMFactor(-0.05) ; Reduce the size of the master area in the active view (only for the "tile" layout). +#Right::View_setMFactor(+0.05) ; Enlarge the size of the master area in the active view (only for the "tile" layout). +#^t::View_rotateLayoutAxis(1, +1) ; Rotate the layout axis (i. e. 2 -> 1 = vertical layout, 1 -> 2 = horizontal layout, only for the "tile" layout). +#^Enter::View_rotateLayoutAxis(1, +2) ; Mirror the layout axis (i. e. -1 -> 1 / 1 -> -1 = master on the left / right side, -2 -> 2 / 2 -> -2 = master at top / bottom, only for the "tile" layout). +#^Tab::View_rotateLayoutAxis(2, +1) ; Rotate the master axis (i. e. 3 -> 1 = x-axis = horizontal stack, 1 -> 2 = y-axis = vertical stack, 2 -> 3 = z-axis = monocle, only for the "tile" layout). +#^+Tab::View_rotateLayoutAxis(3, +1) ; Rotate the stack axis (i. e. 3 -> 1 = x-axis = horizontal stack, 1 -> 2 = y-axis = vertical stack, 2 -> 3 = z-axis = monocle, only for the "tile" layout). +#^Up::View_setMY(+1) ; Increase the master Y dimension [1,9] (only for the "tile" layout). +#^Down::View_setMY(-1) ; Decrease the master Y dimension [1,9] (only for the "tile" layout). +#^Right::View_setMX(+1) ; Increase the master X dimension [1,9] (only for the "tile" layout). +#^Left::View_setMX(-1) ; Decrease the master X dimension [1,9] (only for the "tile" layout). +#+Left::View_setGapWidth(-2) ; Decrease the gap width by 2 px (only for the "tile" layout and even numbers; see the variable "Config_layoutGapWidth"). +#+Right::View_setGapWidth(+2) ; Increase the gap width by 2 px (only for the "tile" layout and even numbers; see the variable "Config_layoutGapWidth"). -#BackSpace::Monitor_activateView(-1) ; Activate the previously activated view. You may also use Monitor_activateView("<") or Monitor_activateView(">") for activating the previous or next adjacent view. -#+0::Monitor_setWindowTag(0) ; Tag the active window with all tags (1 ... Config_viewCount). You may also use Monitor_setWindowTag("<") or Monitor_setWindowTag(">") for setting the tag of the previous or next adjacent to the current view. -#1::Monitor_activateView(1) ; Activate the view (choose one out of 1 ... Config_viewCount). -#+1::Monitor_setWindowTag(1) ; Tag the active window (choose one tag out of 1 ... Config_viewCount). -#^1::Monitor_toggleWindowTag(1) ; Add / Remove the tag (1 ... Config_viewCount) for the active window, if it is not / is already set. +#BackSpace::Monitor_activateView(-1) ; Activate the previously activated view. You may also use Monitor_activateView("<") or Monitor_activateView(">") for activating the previous or next adjacent view. +#+0::Monitor_setWindowTag(0) ; Tag the active window with all tags (1 ... Config_viewCount). You may also use Monitor_setWindowTag("<") or Monitor_setWindowTag(">") for setting the tag of the previous or next adjacent to the current view. +#1::Monitor_activateView(1) ; Activate the view (choose one out of 1 ... Config_viewCount). +#+1::Monitor_setWindowTag(1) ; Tag the active window (choose one tag out of 1 ... Config_viewCount). +#^1::Monitor_toggleWindowTag(1) ; Add / Remove the tag (1 ... Config_viewCount) for the active window, if it is not / is already set. #2::Monitor_activateView(2) #+2::Monitor_setWindowTag(2) #^2::Monitor_toggleWindowTag(2) @@ -451,19 +451,19 @@ Config_saveSession() { #+9::Monitor_setWindowTag(9) #^9::Monitor_toggleWindowTag(9) -#.::Manager_activateMonitor(+1) ; Activate the next monitor in a multi-monitor environment. -#,::Manager_activateMonitor(-1) ; Activate the previous monitor in a multi-monitor environment. -#+.::Manager_setWindowMonitor(+1) ; Set the active window to the active view on the next monitor in a multi-monitor environment. -#+,::Manager_setWindowMonitor(-1) ; Set the active window to the active view on the previous monitor in a multi-monitor environment. -#^+.::Manager_setViewMonitor(+1) ; Set all windows of the active view on the active view of the next monitor in a multi-monitor environment. -#^+,::Manager_setViewMonitor(-1) ; Set all windows of the active view on the active view of the previous monitor in a multi-monitor environment. +#.::Manager_activateMonitor(+1) ; Activate the next monitor in a multi-monitor environment. +#,::Manager_activateMonitor(-1) ; Activate the previous monitor in a multi-monitor environment. +#+.::Manager_setWindowMonitor(+1) ; Set the active window to the active view on the next monitor in a multi-monitor environment. +#+,::Manager_setWindowMonitor(-1) ; Set the active window to the active view on the previous monitor in a multi-monitor environment. +#^+.::Manager_setViewMonitor(+1) ; Set all windows of the active view on the active view of the next monitor in a multi-monitor environment. +#^+,::Manager_setViewMonitor(-1) ; Set all windows of the active view on the active view of the previous monitor in a multi-monitor environment. -#+Space::Monitor_toggleBar() ; Hide / Show the bar (bug.n status bar) on the active monitor. -#Space::Monitor_toggleTaskBar() ; Hide / Show the task bar. -#y::Bar_toggleCommandGui() ; Open the command GUI for executing programmes or bug.n functions. -#^e::Run, edit %Config_filePath% ; Open the configuration file in the standard text editor. -#^s::Config_saveSession() ; Save the current state of monitors, views, layouts to the configuration file. -#^r::Main_reload() ; Reload bug.n (i. e. the configuration and its dependent settings) without deleting the window lists of bug.n and restoring windows. - ; It does not reset internal configuration variables, the tray icon or menu, hotkeys (unless set explicitly in Config.ini), individual window settings like Config_showBorder (since windows might be hidden) or hiding the title bar, the monitor count or views. - ; It does not reload functions. Changed rules are only applied to new windows. -#^q::ExitApp ; Quit bug.n, restore the default Windows UI and show all windows. +#+Space::Monitor_toggleBar() ; Hide / Show the bar (bug.n status bar) on the active monitor. +#Space::Monitor_toggleTaskBar() ; Hide / Show the task bar. +#y::Bar_toggleCommandGui() ; Open the command GUI for executing programmes or bug.n functions. +#^e::Run, edit %Config_filePath% ; Open the configuration file in the standard text editor. +#^s::Config_saveSession() ; Save the current state of monitors, views, layouts to the configuration file. +#^r::Main_reload() ; Reload bug.n (i. e. the configuration and its dependent settings) without deleting the window lists of bug.n and restoring windows. + ; It does not reset internal configuration variables, the tray icon or menu, hotkeys (unless set explicitly in Config.ini), individual window settings like Config_showBorder (since windows might be hidden) or hiding the title bar, the monitor count or views. + ; It does not reload functions. Changed rules are only applied to new windows. +#^q::ExitApp ; Quit bug.n, restore the default Windows UI and show all windows. diff --git a/src/Main.ahk b/src/Main.ahk index 96dffd4..2a90a00 100644 --- a/src/Main.ahk +++ b/src/Main.ahk @@ -1,24 +1,24 @@ -/** - * bug.n - tiling window management - * Copyright (c) 2010-2012 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 - */ +/* + 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 +*/ -NAME := "bug.n" +NAME := "bug.n" VERSION := "8.3.0" ; script settings @@ -32,119 +32,116 @@ SetWinDelay, 10 #WinActivateForce ; pseudo main function - - - EnvGet, appDir, APPDATA - bugnDir := appDir . "\bug.n" - IfNotExist, %bugnDir% - FileCreateDir, %bugnDir% - FileGetAttrib, attrib, %bugnDir% - IfNotInString, attrib, D - { - MsgBox, The file path '%appDir%' already exists and is not a directory. Aborting. - Return - } - logFile := bugnDir . "\bugn_log.txt" - Log_init(logFile, False) - - - Log_msg("====== Initializing ======") - If 0 = 1 - Config_filePath = %1% - 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, Exit, Main_quit - - Manager_init() -Return ; end of the auto-execute section + EnvGet, appDir, APPDATA + bugnDir := appDir . "\bug.n" + IfNotExist, %bugnDir% + FileCreateDir, %bugnDir% + FileGetAttrib, attrib, %bugnDir% + IfNotInString, attrib, D + { + MsgBox, The file path '%appDir%' already exists and is not a directory. Aborting. + Return + } + logFile := bugnDir . "\bugn_log.txt" + Log_init(logFile, False) + + Log_msg("====== Initializing ======") + If 0 = 1 + Config_filePath = %1% + 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, Exit, Main_quit + + Manager_init() +Return ; end of the auto-execute section /** - * function & label definitions + * function & label definitions */ -Main_cleanup: ; The labels with "ExitApp" or "Return" at the end and hotkeys have to be after the auto-execute section. - Log_msg("====== Cleaning up ======") - If Config_autoSaveSession - Config_saveSession() - Manager_cleanup() - DllCall("CloseHandle", "UInt", Bar_hDrive) ; used in Bar_getDiskLoad +Main_cleanup: ; The labels with "ExitApp" or "Return" at the end and hotkeys have to be after the auto-execute section. + Log_msg("====== Cleaning up ======") + If Config_autoSaveSession + Config_saveSession() + Manager_cleanup() + DllCall("CloseHandle", "UInt", Bar_hDrive) ; used in Bar_getDiskLoad ExitApp Main_help: - Run, explore %A_ScriptDir%\docs + Run, explore %A_ScriptDir%\docs Return Main_quit: - ExitApp + ExitApp Return 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) { - ncmSize := VarSetCapacity(ncm, 4 * (A_OSVersion = WIN_VISTA ? 11 : 10) + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), 0) - NumPut(ncmSize, ncm, 0, "UInt") - DllCall("SystemParametersInfo", "UInt", 0x0029, "UInt", ncmSize, "UInt", &ncm, "UInt", 0) - If (Config_borderWidth > 0) - NumPut(Manager_borderWidth, ncm, 4, "Int") - If (Config_borderPadding >= 0 And A_OSVersion = WIN_VISTA) - NumPut(Manager_borderPadding, ncm, 40 + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), "Int") - DllCall("SystemParametersInfo", "UInt", 0x002a, "UInt", ncmSize, "UInt", &ncm, "UInt", 0) - } - DllCall("Shell32.dll\SHAppBarMessage", "UInt", (ABM_REMOVE := 0x1), "UInt", &Bar_appBarData) - ; SKAN: Crazy Scripting : Quick Launcher for Portable Apps (http://www.autohotkey.com/forum/topic22398.html) + 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) { + ncmSize := VarSetCapacity(ncm, 4 * (A_OSVersion = WIN_VISTA ? 11 : 10) + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), 0) + NumPut(ncmSize, ncm, 0, "UInt") + DllCall("SystemParametersInfo", "UInt", 0x0029, "UInt", ncmSize, "UInt", &ncm, "UInt", 0) + If (Config_borderWidth > 0) + NumPut(Manager_borderWidth, ncm, 4, "Int") + If (Config_borderPadding >= 0 And A_OSVersion = WIN_VISTA) + NumPut(Manager_borderPadding, ncm, 40 + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), "Int") + DllCall("SystemParametersInfo", "UInt", 0x002a, "UInt", ncmSize, "UInt", &ncm, "UInt", 0) + } + DllCall("Shell32.dll\SHAppBarMessage", "UInt", (ABM_REMOVE := 0x1), "UInt", &Bar_appBarData) + ; SKAN: Crazy Scripting : Quick Launcher for Portable Apps (http://www.autohotkey.com/forum/topic22398.html) - Config_init() - ; Windows UI - If Config_selBorderColor { - SetFormat, Integer, hex - Manager_normBorderColor := DllCall("GetSysColor", "Int", 10) - SetFormat, Integer, d - DllCall("SetSysColors", "Int", 1, "Int*", 10, "UInt*", Config_selBorderColor) - } - If (Config_borderWidth > 0) Or (Config_borderPadding >= 0 And A_OSVersion = WIN_VISTA) { - ncmSize := VarSetCapacity(ncm, 4 * (A_OSVersion = WIN_VISTA ? 11 : 10) + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), 0) - NumPut(ncmSize, ncm, 0, "UInt") - DllCall("SystemParametersInfo", "UInt", 0x0029, "UInt", ncmSize, "UInt", &ncm, "UInt", 0) - Manager_borderWidth := NumGet(ncm, 4, "Int") - Manager_borderPadding := NumGet(ncm, 40 + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), "Int") - If (Config_borderWidth > 0) - NumPut(Config_borderWidth, ncm, 4, "Int") - If (Config_borderPadding >= 0 And A_OSVersion = WIN_VISTA) - NumPut(Config_borderPadding, ncm, 40 + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), "Int") - DllCall("SystemParametersInfo", "UInt", 0x002a, "UInt", ncmSize, "UInt", &ncm, "UInt", 0) - } - Bar_getHeight() - Loop, % Manager_monitorCount { - Monitor_getWorkArea(A_Index) - Bar_init(A_Index) - } - Bar_initCmdGui() - If Not (Manager_showTaskBar = Config_showTaskBar) - Monitor_toggleTaskBar() - Bar_updateStatus() - Bar_updateTitle() - Loop, % Manager_monitorCount { - i := A_Index - Loop, % Config_viewCount - Bar_updateView(i, A_Index) - View_arrange(i, Monitor_#%i%_aView_#1) - } - Manager_registerShellHook() - SetTimer, Bar_loop, %Config_readinInterval% + Config_init() + ; Windows UI + If Config_selBorderColor { + SetFormat, Integer, hex + Manager_normBorderColor := DllCall("GetSysColor", "Int", 10) + SetFormat, Integer, d + DllCall("SetSysColors", "Int", 1, "Int*", 10, "UInt*", Config_selBorderColor) + } + If (Config_borderWidth > 0) Or (Config_borderPadding >= 0 And A_OSVersion = WIN_VISTA) { + ncmSize := VarSetCapacity(ncm, 4 * (A_OSVersion = WIN_VISTA ? 11 : 10) + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), 0) + NumPut(ncmSize, ncm, 0, "UInt") + DllCall("SystemParametersInfo", "UInt", 0x0029, "UInt", ncmSize, "UInt", &ncm, "UInt", 0) + Manager_borderWidth := NumGet(ncm, 4, "Int") + Manager_borderPadding := NumGet(ncm, 40 + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), "Int") + If (Config_borderWidth > 0) + NumPut(Config_borderWidth, ncm, 4, "Int") + If (Config_borderPadding >= 0 And A_OSVersion = WIN_VISTA) + NumPut(Config_borderPadding, ncm, 40 + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), "Int") + DllCall("SystemParametersInfo", "UInt", 0x002a, "UInt", ncmSize, "UInt", &ncm, "UInt", 0) + } + Bar_getHeight() + Loop, % Manager_monitorCount { + Monitor_getWorkArea(A_Index) + Bar_init(A_Index) + } + Bar_initCmdGui() + If Not (Manager_showTaskBar = Config_showTaskBar) + Monitor_toggleTaskBar() + Bar_updateStatus() + Bar_updateTitle() + Loop, % Manager_monitorCount { + i := A_Index + Loop, % Config_viewCount + Bar_updateView(i, A_Index) + View_arrange(i, Monitor_#%i%_aView_#1) + } + Manager_registerShellHook() + SetTimer, Bar_loop, %Config_readinInterval% } Main_toggleBar: - Monitor_toggleBar() + Monitor_toggleBar() Return #Include Log.ahk diff --git a/src/Manager.ahk b/src/Manager.ahk index 8af7559..0052ef8 100644 --- a/src/Manager.ahk +++ b/src/Manager.ahk @@ -1,235 +1,235 @@ -/** - * bug.n - tiling window management - * Copyright (c) 2010-2012 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 - */ +/* + 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 +*/ Manager_init() { - Local ncm, ncmSize - - ; Windows UI - If Config_selBorderColor { - SetFormat, Integer, hex - Manager_normBorderColor := DllCall("GetSysColor", "Int", 10) - SetFormat, Integer, d - DllCall("SetSysColors", "Int", 1, "Int*", 10, "UInt*", Config_selBorderColor) - } - If (Config_borderWidth > 0) Or (Config_borderPadding >= 0 And A_OSVersion = WIN_VISTA) { - ncmSize := VarSetCapacity(ncm, 4 * (A_OSVersion = WIN_VISTA ? 11 : 10) + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), 0) - NumPut(ncmSize, ncm, 0, "UInt") - DllCall("SystemParametersInfo", "UInt", 0x0029, "UInt", ncmSize, "UInt", &ncm, "UInt", 0) - Manager_borderWidth := NumGet(ncm, 4, "Int") - Manager_borderPadding := NumGet(ncm, 40 + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), "Int") - If (Config_borderWidth > 0) - NumPut(Config_borderWidth, ncm, 4, "Int") - If (Config_borderPadding >= 0 And A_OSVersion = WIN_VISTA) - NumPut(Config_borderPadding, ncm, 40 + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), "Int") - DllCall("SystemParametersInfo", "UInt", 0x002a, "UInt", ncmSize, "UInt", &ncm, "UInt", 0) - } - - Bar_getHeight() - Manager_aMonitor := 1 - Manager_taskBarMonitor := "" - Manager_showTaskBar := True - SysGet, Manager_monitorCount, MonitorCount - Loop, % Manager_monitorCount - Monitor_init(A_Index) - 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 { - View_arrange(A_Index, Monitor_#%A_Index%_aView_#1) - Bar_updateView(A_Index, Monitor_#%A_Index%_aView_#1) - } - - Manager_registerShellHook() - SetTimer, Bar_loop, %Config_readinInterval% + Local ncm, ncmSize + + ; Windows UI + If Config_selBorderColor { + SetFormat, Integer, hex + Manager_normBorderColor := DllCall("GetSysColor", "Int", 10) + SetFormat, Integer, d + DllCall("SetSysColors", "Int", 1, "Int*", 10, "UInt*", Config_selBorderColor) + } + If (Config_borderWidth > 0) Or (Config_borderPadding >= 0 And A_OSVersion = WIN_VISTA) { + ncmSize := VarSetCapacity(ncm, 4 * (A_OSVersion = WIN_VISTA ? 11 : 10) + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), 0) + NumPut(ncmSize, ncm, 0, "UInt") + DllCall("SystemParametersInfo", "UInt", 0x0029, "UInt", ncmSize, "UInt", &ncm, "UInt", 0) + Manager_borderWidth := NumGet(ncm, 4, "Int") + Manager_borderPadding := NumGet(ncm, 40 + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), "Int") + If (Config_borderWidth > 0) + NumPut(Config_borderWidth, ncm, 4, "Int") + If (Config_borderPadding >= 0 And A_OSVersion = WIN_VISTA) + NumPut(Config_borderPadding, ncm, 40 + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), "Int") + DllCall("SystemParametersInfo", "UInt", 0x002a, "UInt", ncmSize, "UInt", &ncm, "UInt", 0) + } + + Bar_getHeight() + Manager_aMonitor := 1 + Manager_taskBarMonitor := "" + Manager_showTaskBar := True + SysGet, Manager_monitorCount, MonitorCount + Loop, % Manager_monitorCount + Monitor_init(A_Index) + 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 { + View_arrange(A_Index, Monitor_#%A_Index%_aView_#1) + Bar_updateView(A_Index, Monitor_#%A_Index%_aView_#1) + } + + Manager_registerShellHook() + SetTimer, Bar_loop, %Config_readinInterval% } Manager_activateMonitor(d) { - Local aView, aWndClass, aWndHeight, aWndId, aWndWidth, aWndX, aWndY, v, wndId - - If (Manager_monitorCount > 1) { - aView := Monitor_#%Manager_aMonitor%_aView_#1 - WinGet, aWndId, ID, A - If WinExist("ahk_id" aWndId) { - WinGetClass, aWndClass, ahk_id %aWndId% - If Not (aWndClass = "Progman") And Not (aWndClass = "AutoHotkeyGui") And Not (aWndClass = "DesktopBackgroundClass") { - WinGetPos, aWndX, aWndY, aWndWidth, aWndHeight, ahk_id %aWndId% - 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 View_#%Manager_aMonitor%_#%v%_wndIds - wndId := SubStr(View_#%Manager_aMonitor%_#%v%_wndIds, 1, InStr(View_#%Manager_aMonitor%_#%v%_wndIds, ";")-1) - Else - wndId := 0 - } - Manager_winActivate(wndId) - } + Local aView, aWndClass, aWndHeight, aWndId, aWndWidth, aWndX, aWndY, v, wndId + + If (Manager_monitorCount > 1) { + aView := Monitor_#%Manager_aMonitor%_aView_#1 + WinGet, aWndId, ID, A + If WinExist("ahk_id" aWndId) { + WinGetClass, aWndClass, ahk_id %aWndId% + If Not (aWndClass = "Progman") And Not (aWndClass = "AutoHotkeyGui") And Not (aWndClass = "DesktopBackgroundClass") { + WinGetPos, aWndX, aWndY, aWndWidth, aWndHeight, ahk_id %aWndId% + 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 View_#%Manager_aMonitor%_#%v%_wndIds + wndId := SubStr(View_#%Manager_aMonitor%_#%v%_wndIds, 1, InStr(View_#%Manager_aMonitor%_#%v%_wndIds, ";")-1) + Else + wndId := 0 + } + Manager_winActivate(wndId) + } } Manager_applyRules(wndId, ByRef isManaged, ByRef m, ByRef tags, ByRef isFloating, ByRef isDecorated, ByRef hideTitle) { - Local mouseX, mouseY, wndClass, wndHeight, wndStyle, wndTitle, wndWidth, wndX, wndY - Local rule0, rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule8, rule9 - - isManaged := True - m := 0 - tags := 0 - isFloating := False - isDecorated := False - hideTitle := False - - 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) { - Loop, % Config_ruleCount { - StringSplit, rule, Config_rule_#%A_index%, `; - If RegExMatch(wndClass . ";" . wndTitle, rule1 . ";" . rule2) And (rule3 = "" Or wndStyle & rule3) { ; The last matching rule is returned. - isManaged := rule4 - m := rule5 - tags := rule6 - isFloating := rule7 - isDecorated := rule8 - hideTitle := rule9 - } - } - } Else { - isManaged := False - If wndTitle - hideTitle := True - } + Local mouseX, mouseY, wndClass, wndHeight, wndStyle, wndTitle, wndWidth, wndX, wndY + Local rule0, rule1, rule2, rule3, rule4, rule5, rule6, rule7, rule8, rule9 + + isManaged := True + m := 0 + tags := 0 + isFloating := False + isDecorated := False + hideTitle := False + + 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) { + Loop, % Config_ruleCount { + StringSplit, rule, Config_rule_#%A_index%, `; + If RegExMatch(wndClass . ";" . wndTitle, rule1 . ";" . rule2) And (rule3 = "" Or wndStyle & rule3) { ; The last matching rule is returned. + isManaged := rule4 + m := rule5 + tags := rule6 + isFloating := rule7 + isDecorated := rule8 + hideTitle := rule9 + } + } + } Else { + isManaged := False + If wndTitle + hideTitle := True + } } Manager_cleanup() { - Local aWndId, m, ncmSize, ncm, wndIds - - WinGet, aWndId, ID, A - - ; 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) { - ncmSize := VarSetCapacity(ncm, 4 * (A_OSVersion = WIN_VISTA ? 11 : 10) + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), 0) - NumPut(ncmSize, ncm, 0, "UInt") - DllCall("SystemParametersInfo", "UInt", 0x0029, "UInt", ncmSize, "UInt", &ncm, "UInt", 0) - If (Config_borderWidth > 0) - NumPut(Manager_borderWidth, ncm, 4, "Int") - If (Config_borderPadding >= 0 And A_OSVersion = WIN_VISTA) - NumPut(Manager_borderPadding, ncm, 40 + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), "Int") - DllCall("SystemParametersInfo", "UInt", 0x002a, "UInt", ncmSize, "UInt", &ncm, "UInt", 0) - } - - ; Show borders and title bars. - StringTrimRight, wndIds, Manager_managedWndIds, 1 - Manager_hideShow := True - Loop, PARSE, wndIds, `; - { - Manager_winShow(A_LoopField) - If Not Config_showBorder - 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 { - m := A_Index - Monitor_#%m%_showBar := False - Monitor_getWorkArea(m) - 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) + Local aWndId, m, ncmSize, ncm, wndIds + + WinGet, aWndId, ID, A + + ; 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) { + ncmSize := VarSetCapacity(ncm, 4 * (A_OSVersion = WIN_VISTA ? 11 : 10) + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), 0) + NumPut(ncmSize, ncm, 0, "UInt") + DllCall("SystemParametersInfo", "UInt", 0x0029, "UInt", ncmSize, "UInt", &ncm, "UInt", 0) + If (Config_borderWidth > 0) + NumPut(Manager_borderWidth, ncm, 4, "Int") + If (Config_borderPadding >= 0 And A_OSVersion = WIN_VISTA) + NumPut(Manager_borderPadding, ncm, 40 + 5 * (28 + 32 * (A_IsUnicode ? 2 : 1)), "Int") + DllCall("SystemParametersInfo", "UInt", 0x002a, "UInt", ncmSize, "UInt", &ncm, "UInt", 0) + } + + ; Show borders and title bars. + StringTrimRight, wndIds, Manager_managedWndIds, 1 + Manager_hideShow := True + Loop, PARSE, wndIds, `; + { + Manager_winShow(A_LoopField) + If Not Config_showBorder + 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 { + m := A_Index + Monitor_#%m%_showBar := False + Monitor_getWorkArea(m) + 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() { - WinGet, aWndId, ID, A - WinGetClass, aWndClass, ahk_id %aWndId% - WinGetTitle, aWndTitle, ahk_id %aWndId% - If Not (aWndClass = "AutoHotkeyGUI" And RegExMatch(aWndTitle, "bug.n_BAR_[0-9]+")) - Manager_winClose(aWndId) + WinGet, aWndId, ID, A + WinGetClass, aWndClass, ahk_id %aWndId% + WinGetTitle, aWndTitle, ahk_id %aWndId% + If Not (aWndClass = "AutoHotkeyGUI" And RegExMatch(aWndTitle, "bug.n_BAR_[0-9]+")) + Manager_winClose(aWndId) } 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% - WinGet, aWndProcessName, ProcessName, ahk_id %aWndId% - WinGet, aWndStyle, Style, ahk_id %aWndId% - WinGetPos, aWndX, aWndY, aWndWidth, aWndHeight, ahk_id %aWndId% - text := "ID: " aWndId "`nclass:`t" aWndClass "`ntitle:`t" aWndTitle - If InStr(Bar_hiddenWndIds, aWndId) - text .= " (hidden)" - text .= "`nprocess:`t" aWndProcessName "`nstyle:`t" aWndStyle "`nmetrics:`tx: " aWndX ", y: " aWndY ", width: " aWndWidth ", height: " aWndHeight "`ntags:`t" Manager_#%aWndId%_tags - If Manager_#%aWndId%_isFloating - text .= " (floating)" - MsgBox, 260, bug.n: Window Information, % text "`n`nCopy text to clipboard?" - IfMsgBox Yes - Clipboard := text + 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% + WinGet, aWndProcessName, ProcessName, ahk_id %aWndId% + WinGet, aWndStyle, Style, ahk_id %aWndId% + WinGetPos, aWndX, aWndY, aWndWidth, aWndHeight, ahk_id %aWndId% + text := "ID: " aWndId "`nclass:`t" aWndClass "`ntitle:`t" aWndTitle + If InStr(Bar_hiddenWndIds, aWndId) + text .= " (hidden)" + text .= "`nprocess:`t" aWndProcessName "`nstyle:`t" aWndStyle "`nmetrics:`tx: " aWndX ", y: " aWndY ", width: " aWndWidth ", height: " aWndHeight "`ntags:`t" Manager_#%aWndId%_tags + If Manager_#%aWndId%_isFloating + text .= " (floating)" + MsgBox, 260, bug.n: Window Information, % text "`n`nCopy text to clipboard?" + IfMsgBox Yes + Clipboard := text } 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, `; - { - 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 + 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, `; + { + 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_logViewLayout() { @@ -237,128 +237,128 @@ Manager_logViewLayout() { } Manager_logWindowInfo( w ) { - Local v, wndId, isWinFocus, isBugnActive, isFloating, isHidden, isDecorated, isResponsive, isGhost, wndTitle, wndProc, wndClass, wndStyle, wndX, wndY, wndW, wndH, detect_state - - detect_state := A_DetectHiddenWindows - DetectHiddenWindows, On - WinGet, wndId, ID, A - If wndId = %w% - isWinFocus := "*" - Else - isWinFocus := " " - v := Monitor_#%Manager_aMonitor%_aView_#1 - If View_#%Manager_aMonitor%_#%v%_aWndId = %w% - isBugnActive := "*" - Else - isBugnActive := " " - WinGetTitle, wndTitle, ahk_id %w% - WinGetClass, wndClass, ahk_id %w% - WinGet, wndProc, ProcessName, ahk_id %w% - If InStr(Bar_hiddenWndIds, w) - isHidden := "*" - Else - isHidden := " " - If Manager_#%w%_isFloating - isFloating := "*" - Else - isFloating := " " - If Manager_#%w%_isDecorated - isDecorated := "*" - Else - isDecorated := " " - WinGet, wndStyle, Style, ahk_id %w% - WinGetPos, wndX, wndY, wndW, wndH, ahk_id %w% - - If Manager_isGhost(w) - isGhost := "*" - Else - isGhost := " " - - DetectHiddenWindows, %detect_state% - - ; Intentionally don't detect hidden windows here to see what Manager_hungTest does - If Manager_isHung(w) - isResponsive := " " - Else - isResponsive := "*" - - - Log_bare(w . "`t" . isHidden . " " isWinFocus . " " . isBugnActive . " " . isFloating . " " . isDecorated . " " . isResponsive . " " . isGhost . " " . Manager_#%w%_monitor . "`t" . Manager_#%w%_tags . "`t" . wndX . "`t" . wndY . "`t" . wndW . "`t" . wndH . "`t" . wndStyle . "`t" . wndProc . " / " . wndClass . " / " . wndTitle) + Local v, wndId, isWinFocus, isBugnActive, isFloating, isHidden, isDecorated, isResponsive, isGhost, wndTitle, wndProc, wndClass, wndStyle, wndX, wndY, wndW, wndH, detect_state + + detect_state := A_DetectHiddenWindows + DetectHiddenWindows, On + WinGet, wndId, ID, A + If wndId = %w% + isWinFocus := "*" + Else + isWinFocus := " " + v := Monitor_#%Manager_aMonitor%_aView_#1 + If View_#%Manager_aMonitor%_#%v%_aWndId = %w% + isBugnActive := "*" + Else + isBugnActive := " " + WinGetTitle, wndTitle, ahk_id %w% + WinGetClass, wndClass, ahk_id %w% + WinGet, wndProc, ProcessName, ahk_id %w% + If InStr(Bar_hiddenWndIds, w) + isHidden := "*" + Else + isHidden := " " + If Manager_#%w%_isFloating + isFloating := "*" + Else + isFloating := " " + If Manager_#%w%_isDecorated + isDecorated := "*" + Else + isDecorated := " " + WinGet, wndStyle, Style, ahk_id %w% + WinGetPos, wndX, wndY, wndW, wndH, ahk_id %w% + + If Manager_isGhost(w) + isGhost := "*" + Else + isGhost := " " + + DetectHiddenWindows, %detect_state% + + ; Intentionally don't detect hidden windows here to see what Manager_hungTest does + If Manager_isHung(w) + isResponsive := " " + Else + isResponsive := "*" + + + Log_bare(w . "`t" . isHidden . " " isWinFocus . " " . isBugnActive . " " . isFloating . " " . isDecorated . " " . isResponsive . " " . isGhost . " " . Manager_#%w%_monitor . "`t" . Manager_#%w%_tags . "`t" . wndX . "`t" . wndY . "`t" . wndW . "`t" . wndH . "`t" . wndStyle . "`t" . wndProc . " / " . wndClass . " / " . wndTitle) } Manager_logHeader() { - Log_bare( "ID`t`tH W A F D R G M`tTags`tX`tY`tW`tH`tStyle`t`tProc / Class / Title") + Log_bare( "ID`t`tH W A F D R G M`tTags`tX`tY`tW`tH`tStyle`t`tProc / Class / Title") } Manager_logViewWindowList() { - Local text, v, aWndId, wndIds, aWndTitle - - v := Monitor_#%Manager_aMonitor%_aView_#1 - Log_msg( "Window dump for active view (" . Manager_aMonitor . ", " . v . ")" ) - Manager_logHeader() - - StringTrimRight, wndIds, View_#%Manager_aMonitor%_#%v%_wndIds, 1 - Loop, PARSE, wndIds, `; - { - Manager_logWindowInfo( A_LoopField ) - } + Local text, v, aWndId, wndIds, aWndTitle + + v := Monitor_#%Manager_aMonitor%_aView_#1 + Log_msg( "Window dump for active view (" . Manager_aMonitor . ", " . v . ")" ) + Manager_logHeader() + + StringTrimRight, wndIds, View_#%Manager_aMonitor%_#%v%_wndIds, 1 + Loop, PARSE, wndIds, `; + { + Manager_logWindowInfo( A_LoopField ) + } } Manager_logManagedWindowList() { - Local wndIds - - Log_msg( "Window dump for manager" ) - Manager_logHeader() - - StringTrimRight, wndIds, Manager_managedWndIds, 1 - Loop, PARSE, wndIds, `; - { - Manager_logWindowInfo( A_LoopField) - } + Local wndIds + + Log_msg( "Window dump for manager" ) + Manager_logHeader() + + StringTrimRight, wndIds, Manager_managedWndIds, 1 + Loop, PARSE, wndIds, `; + { + Manager_logWindowInfo( A_LoopField) + } } Manager_logHelp() { - Log_msg("Help Display") - Log_bare("Window list columns") - Log_bare(" ID - Windows ID. Unique, OS-assigned ID") - Log_bare(" H - Hidden. Whether bug.n thinks this window is hidden.") - Log_bare(" W - Windows active. This window is active according to Windows.") - Log_bare(" A - View active. This window is active according to bug.n.") - Log_bare(" F - Floating. This window should not be positioned and resized by the layout.") - Log_bare(" D - Decorated. Does the window have a title bar?") - Log_bare(" R - Responsive. Is responding to messages?") - Log_bare(" G - Ghost. Is this window a ghost of another hung window?") - Log_bare(" M - Monitor number.") - Log_bare(" Tags - Bit-mask of the views in which the window is active.") - Log_bare(" X - Windows X position.") - Log_bare(" Y - Windows Y position.") - Log_bare(" W - Windows width.") - Log_bare(" H - Windows height.") - Log_bare(" Style - Windows style.") - Log_bare(" Proc / Class / Title - Process/Class/Title of the window.") + Log_msg("Help Display") + Log_bare("Window list columns") + Log_bare(" ID - Windows ID. Unique, OS-assigned ID") + Log_bare(" H - Hidden. Whether bug.n thinks this window is hidden.") + Log_bare(" W - Windows active. This window is active according to Windows.") + Log_bare(" A - View active. This window is active according to bug.n.") + Log_bare(" F - Floating. This window should not be positioned and resized by the layout.") + Log_bare(" D - Decorated. Does the window have a title bar?") + Log_bare(" R - Responsive. Is responding to messages?") + Log_bare(" G - Ghost. Is this window a ghost of another hung window?") + Log_bare(" M - Monitor number.") + Log_bare(" Tags - Bit-mask of the views in which the window is active.") + Log_bare(" X - Windows X position.") + Log_bare(" Y - Windows Y position.") + Log_bare(" W - Windows width.") + Log_bare(" H - Windows height.") + Log_bare(" Style - Windows style.") + Log_bare(" Proc / Class / Title - Process/Class/Title of the window.") } Manager_lockWorkStation() { - Global Config_shellMsgDelay - - RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, 0 - Sleep, % Config_shellMsgDelay - DllCall("LockWorkStation") - Sleep, % 4 * Config_shellMsgDelay - RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, 1 + Global Config_shellMsgDelay + + RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, 0 + Sleep, % Config_shellMsgDelay + DllCall("LockWorkStation") + Sleep, % 4 * Config_shellMsgDelay + RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\System, DisableLockWorkstation, 1 } ; 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) { - index += increment - If (index > upperBound) - index := lowerBound - If (index < lowerBound) - index := upperBound - If (upperBound = 0) - index := 0 - - Return, index + index += increment + If (index > upperBound) + index := lowerBound + If (index < lowerBound) + index := upperBound + If (upperBound = 0) + index := 0 + + Return, index } ; Accept a window to be added to the system for management. @@ -367,123 +367,123 @@ Manager_loop(index, increment, lowerBound, upperBound) { ; pv - Preferred view ; wndId - Window to add to the manager. Manager_manage(pm, pv, wndId) { - Local a, c0, hideTitle, i, isDecorated, isFloating, isManaged, l, m, n, replace, search, tags, body + Local a, c0, hideTitle, i, isDecorated, isFloating, isManaged, l, m, n, replace, search, tags, body Local wndControlList0, wndId0, wndIds, wndX, wndY, wndWidth, wndHeight, wndProcessName - - If Not InStr(Manager_allWndIds, wndId ";") - Manager_allWndIds .= wndId ";" - - body := 0 - If Manager_isGhost( wndId ) { - Log_dbg_msg(2, "A window has given up the ghost (Ghost wndId: " . wndId . ")") - ; Ghosts need special attention. - ; Say a quick prayer and try to reattach it to its body. - body := Manager_findHung( wndId ) - If body { - isManaged := InStr(Manager_managedWndIds, body ";") - m := Manager_#%body%_monitor - tags := Manager_#%body%_tags - isDecorated := Manager_#%body%_isDecorated - isFloating := Manager_#%body%_isFloating - hideTitle := InStr(Bar_hideTitleWndIds, body ";") - } - Else { - Log_dbg_msg(1, "No body could be found for ghost wndId: " . wndId) - } - } - - ; Apply rules if the window is either a normal window or a ghost without a body. - If ( body = 0 ) { - Manager_applyRules(wndId, isManaged, m, tags, isFloating, isDecorated, hideTitle) - - If (m = 0) - m := pm - If (m < 0) - m := 1 - If (m > Manager_monitorCount) ; If the specified monitor is out of scope, set it to the max. monitor. - m := Manager_monitorCount - If (tags = 0) - tags := 1 << (pv - 1) - } - - WinGet, wndProcessName, ProcessName, ahk_id %wndId% - If (wndProcessName = "chrome.exe") { - WinGet, wndControlList, ControlList, ahk_id %wndId% - StringSplit, c, wndControlList, `n - If (c0 <= 1) - isManaged := False - } - - If isManaged { - Monitor_moveWindow(m, wndId) + + If Not InStr(Manager_allWndIds, wndId ";") + Manager_allWndIds .= wndId ";" + + body := 0 + If Manager_isGhost( wndId ) { + Log_dbg_msg(2, "A window has given up the ghost (Ghost wndId: " . wndId . ")") + ; Ghosts need special attention. + ; Say a quick prayer and try to reattach it to its body. + body := Manager_findHung( wndId ) + If body { + isManaged := InStr(Manager_managedWndIds, body ";") + m := Manager_#%body%_monitor + tags := Manager_#%body%_tags + isDecorated := Manager_#%body%_isDecorated + isFloating := Manager_#%body%_isFloating + hideTitle := InStr(Bar_hideTitleWndIds, body ";") + } + Else { + Log_dbg_msg(1, "No body could be found for ghost wndId: " . wndId) + } + } + + ; Apply rules if the window is either a normal window or a ghost without a body. + If ( body = 0 ) { + Manager_applyRules(wndId, isManaged, m, tags, isFloating, isDecorated, hideTitle) + + If (m = 0) + m := pm + If (m < 0) + m := 1 + If (m > Manager_monitorCount) ; If the specified monitor is out of scope, set it to the max. monitor. + m := Manager_monitorCount + If (tags = 0) + tags := 1 << (pv - 1) + } + + WinGet, wndProcessName, ProcessName, ahk_id %wndId% + If (wndProcessName = "chrome.exe") { + WinGet, wndControlList, ControlList, ahk_id %wndId% + StringSplit, c, wndControlList, `n + If (c0 <= 1) + isManaged := False + } + + If isManaged { + Monitor_moveWindow(m, wndId) - Manager_managedWndIds .= wndId ";" - Manager_#%wndId%_monitor := m - Manager_#%wndId%_tags := tags - Manager_#%wndId%_isDecorated := isDecorated - Manager_#%wndId%_isFloating := isFloating - - Loop, % Config_viewCount - If (Manager_#%wndId%_tags & 1 << A_Index - 1) { - If (body) { - ; Try to position near the body. - View_ghostWnd(m, A_Index, body, wndId) - } - Else { - View_addWnd(m, A_Index, wndId) - } - } - - 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 { - Manager_aMonitor := m - Manager_winActivate(wndId) - } Else { - Manager_hideShow := True - Manager_winHide(wndId) - Manager_hideShow := False - } - } - - If hideTitle And Not InStr(Bar_hideTitleWndIds, wndId) - Bar_hideTitleWndIds .= wndId . ";" - Else If Not hideTitle - StringReplace, Bar_hideTitleWndIds, Bar_hideTitleWndIds, %wndId%`;, - - Return, a + Manager_managedWndIds .= wndId ";" + Manager_#%wndId%_monitor := m + Manager_#%wndId%_tags := tags + Manager_#%wndId%_isDecorated := isDecorated + Manager_#%wndId%_isFloating := isFloating + + Loop, % Config_viewCount + If (Manager_#%wndId%_tags & 1 << A_Index - 1) { + If (body) { + ; Try to position near the body. + View_ghostWnd(m, A_Index, body, wndId) + } + Else { + View_addWnd(m, A_Index, wndId) + } + } + + 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 { + Manager_aMonitor := m + Manager_winActivate(wndId) + } Else { + Manager_hideShow := True + Manager_winHide(wndId) + Manager_hideShow := False + } + } + + If hideTitle And Not InStr(Bar_hideTitleWndIds, wndId) + Bar_hideTitleWndIds .= wndId . ";" + Else If Not hideTitle + StringReplace, Bar_hideTitleWndIds, Bar_hideTitleWndIds, %wndId%`;, + + Return, a } 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) + 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() { - 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% + 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% } HSHELL_WINDOWCREATED := 1 @@ -526,431 +526,427 @@ WINDOW_NOTICE := 32774 ; in the case of some applications, 32774 works for others ; 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 - - Log_dbg_msg(2, "Manager_onShellMessage( wParam: " . wParam . ", lParam: " . lParam . " )") - - 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") { - MouseGetPos, x, y - m := Monitor_get(x, y) - If m - Manager_aMonitor := m - Bar_updateTitle() - } - - If ( wParam = HSHELL_WINDOWREPLACED ) { - ; This shouldn't need a redraw because the window was supposedly replaced. - Manager_unmanage(lParam) - } - - If ( wParam = 14 ) { - ; Window recovered from being hung. Maybe force a redraw. - } - - 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 (wParam = 4 Or wParam = 32772) - If Not wndClass And Not (wParam = 2) { - WinGetClass, wndClass, ahk_id %lParam% - If wndClass { - If (wndClass = "Emacs") - Sleep, % 12 * Config_shellMsgDelay - } Else - Sleep, %Config_shellMsgDelay% - } - - isChanged := Manager_sync(wndIds) - If wndIds - isChanged := False + 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 + + Log_dbg_msg(2, "Manager_onShellMessage( wParam: " . wParam . ", lParam: " . lParam . " )") + + 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") { + MouseGetPos, x, y + m := Monitor_get(x, y) + If m + Manager_aMonitor := m + Bar_updateTitle() + } + + If ( wParam = HSHELL_WINDOWREPLACED ) { + ; This shouldn't need a redraw because the window was supposedly replaced. + Manager_unmanage(lParam) + } + + If ( wParam = 14 ) { + ; Window recovered from being hung. Maybe force a redraw. + } + + 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 (wParam = 4 Or wParam = 32772) + If Not wndClass And Not (wParam = 2) { + WinGetClass, wndClass, ahk_id %lParam% + If wndClass { + If (wndClass = "Emacs") + Sleep, % 12 * Config_shellMsgDelay + } Else + Sleep, %Config_shellMsgDelay% + } + + isChanged := Manager_sync(wndIds) + If wndIds + isChanged := False - If a Or isChanged { - View_arrange(Manager_aMonitor, Monitor_#%Manager_aMonitor%_aView_#1) - Bar_updateView(Manager_aMonitor, Monitor_#%Manager_aMonitor%_aView_#1) - } - - If (Manager_monitorCount > 1) { - WinGetPos, aWndX, aWndY, aWndWidth, aWndHeight, ahk_id %aWndId% - m := Monitor_get(aWndX + aWndWidth / 2, aWndY + aWndHeight / 2) - If m - Manager_aMonitor := m - } - - If wndIds { - If (Config_onActiveHiddenWnds = "view") { - wndId := SubStr(wndIds, 1, InStr(wndIds, ";") - 1) - Loop, % Config_viewCount - If (Manager_#%wndId%_tags & 1 << A_Index - 1) { - Log_dbg_msg(3, "Switching views because " . wndId . " is considered hidden and active") - Manager_aMonitor := Manager_#%wndId%_monitor - Monitor_activateView(A_Index) - Break - } - } Else { - StringTrimRight, wndIds, wndIds, 1 - StringSplit, wndId, wndIds, `; - ; Otherwise re-hide them. - If (Config_onActiveHiddenWnds = "hide") { - Loop, % wndId0 - Manager_winHide(wndId%A_Index%) - } Else If (Config_onActiveHiddenWnds = "tag") { - ; Or tag all of them for the current view. - t := Monitor_#%Manager_aMonitor%_aView_#1 - Loop, % wndId0 { - wndId := wndId%A_Index% - View_#%Manager_aMonitor%_#%t%_wndIds := wndId ";" View_#%Manager_aMonitor%_#%t%_wndIds - View_#%Manager_aMonitor%_#%t%_aWndId := wndId - Manager_#%wndId%_tags += 1 << t - 1 - } - Bar_updateView(Manager_aMonitor, t) - View_arrange(Manager_aMonitor, t) - } - } - } - - Bar_updateTitle() - } + If a Or isChanged { + View_arrange(Manager_aMonitor, Monitor_#%Manager_aMonitor%_aView_#1) + Bar_updateView(Manager_aMonitor, Monitor_#%Manager_aMonitor%_aView_#1) + } + + If (Manager_monitorCount > 1) { + WinGetPos, aWndX, aWndY, aWndWidth, aWndHeight, ahk_id %aWndId% + m := Monitor_get(aWndX + aWndWidth / 2, aWndY + aWndHeight / 2) + If m + Manager_aMonitor := m + } + + If wndIds { + If (Config_onActiveHiddenWnds = "view") { + wndId := SubStr(wndIds, 1, InStr(wndIds, ";") - 1) + Loop, % Config_viewCount + If (Manager_#%wndId%_tags & 1 << A_Index - 1) { + Log_dbg_msg(3, "Switching views because " . wndId . " is considered hidden and active") + Manager_aMonitor := Manager_#%wndId%_monitor + Monitor_activateView(A_Index) + Break + } + } Else { + StringTrimRight, wndIds, wndIds, 1 + StringSplit, wndId, wndIds, `; + ; Otherwise re-hide them. + If (Config_onActiveHiddenWnds = "hide") { + Loop, % wndId0 + Manager_winHide(wndId%A_Index%) + } Else If (Config_onActiveHiddenWnds = "tag") { + ; Or tag all of them for the current view. + t := Monitor_#%Manager_aMonitor%_aView_#1 + Loop, % wndId0 { + wndId := wndId%A_Index% + View_#%Manager_aMonitor%_#%t%_wndIds := wndId ";" View_#%Manager_aMonitor%_#%t%_wndIds + View_#%Manager_aMonitor%_#%t%_aWndId := wndId + Manager_#%wndId%_tags += 1 << t - 1 + } + Bar_updateView(Manager_aMonitor, t) + View_arrange(Manager_aMonitor, t) + } + } + } + + Bar_updateTitle() + } } Manager_registerShellHook() { - Gui, +LastFound - hWnd := WinExist() - DllCall("RegisterShellHookWindow", "UInt", hWnd) ; Minimum operating systems: Windows 2000 (http://msdn.microsoft.com/en-us/library/ms644989(VS.85).aspx) - msgNum := DllCall("RegisterWindowMessage", "Str", "SHELLHOOK") - OnMessage(msgNum, "Manager_onShellMessage") + Gui, +LastFound + hWnd := WinExist() + DllCall("RegisterShellHookWindow", "UInt", hWnd) ; Minimum operating systems: Windows 2000 (http://msdn.microsoft.com/en-us/library/ms644989(VS.85).aspx) + msgNum := DllCall("RegisterWindowMessage", "Str", "SHELLHOOK") + OnMessage(msgNum, "Manager_onShellMessage") } ; SKAN: How to Hook on to Shell to receive its messages? (http://www.autohotkey.com/forum/viewtopic.php?p=123323#123323) Manager_setViewMonitor(d) { - Local aView, m, v, wndIds - - 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 { - 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 { - 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 - Bar_updateView(Manager_aMonitor, A_Index) - - Manager_aMonitor := m - View_arrange(m, v) - Bar_updateTitle() - Bar_updateView(m, v) - } - } + Local aView, m, v, wndIds + + 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 { + 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 { + 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 + Bar_updateView(Manager_aMonitor, A_Index) + + Manager_aMonitor := m + View_arrange(m, v) + Bar_updateTitle() + Bar_updateView(m, v) + } + } } Manager_setWindowMonitor(d) { - Local aWndId, v - - WinGet, aWndId, ID, A - If (Manager_monitorCount > 1 And InStr(Manager_managedWndIds, aWndId ";")) { - Loop, % Config_viewCount { - 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 - Manager_#%aWndId%_tags := 1 << v - 1 - View_#%Manager_aMonitor%_#%v%_wndIds := aWndId ";" View_#%Manager_aMonitor%_#%v%_wndIds - View_#%Manager_aMonitor%_#%v%_aWndId := aWndId - View_arrange(Manager_aMonitor, v) - Bar_updateTitle() - Bar_updateView(Manager_aMonitor, v) - } + Local aWndId, v + + WinGet, aWndId, ID, A + If (Manager_monitorCount > 1 And InStr(Manager_managedWndIds, aWndId ";")) { + Loop, % Config_viewCount { + 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 + Manager_#%aWndId%_tags := 1 << v - 1 + View_#%Manager_aMonitor%_#%v%_wndIds := aWndId ";" View_#%Manager_aMonitor%_#%v%_wndIds + View_#%Manager_aMonitor%_#%v%_aWndId := aWndId + View_arrange(Manager_aMonitor, v) + Bar_updateTitle() + Bar_updateView(Manager_aMonitor, v) + } } 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% + 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% } Manager_sync(ByRef wndIds = "") { - Local a, flag, shownWndIds, v, visibleWndIds, wndId - - 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 { - If Not InStr(shownWndIds, 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%) { - ; 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. - wndIds .= wndId%A_Index% ";" - } - } - visibleWndIds := visibleWndIds wndId%A_Index% ";" - } - - ; 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) { - flag := Manager_unmanage(A_LoopField) - If flag - a := flag - } - } - - Return, a + Local a, flag, shownWndIds, v, visibleWndIds, wndId + + 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 { + If Not InStr(shownWndIds, 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%) { + ; 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. + wndIds .= wndId%A_Index% ";" + } + } + visibleWndIds := visibleWndIds wndId%A_Index% ";" + } + + ; 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) { + flag := Manager_unmanage(A_LoopField) + If flag + a := flag + } + } + + Return, a } ; No windows are known to the system yet. ; Try to do something smart with the initial layout. 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 - Manager_initial_sync_m#%A_Index%_wndList := List_new() - - ; check all visible windows against the known windows - WinGet, wndId, List, , , - Loop, % wndId { - ; 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 - List_append(Manager_initial_sync_m#%m%_wndList, wndId%A_index%) - - ; @todo: What percentage of the monitor area is it occupying? (Suggest layout) - ; @todo: What part of the monitor is it on? (Ordering of windows) - } + 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 + Manager_initial_sync_m#%A_Index%_wndList := List_new() + + ; check all visible windows against the known windows + WinGet, wndId, List, , , + Loop, % wndId { + ; 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 + List_append(Manager_initial_sync_m#%m%_wndList, wndId%A_index%) + + ; @todo: What percentage of the monitor area is it occupying? (Suggest layout) + ; @todo: What part of the monitor is it on? (Ordering of windows) + } - Loop, % Manager_monitorCount { - m := A_Index - len := List_toArray(Manager_initial_sync_m#%m%_wndList, "Manager_initial_sync_tmpArray") - Loop, % len - Manager_manage(m, 1, Manager_initial_sync_tmpArray%A_Index%) - } + Loop, % Manager_monitorCount { + m := A_Index + len := List_toArray(Manager_initial_sync_m#%m%_wndList, "Manager_initial_sync_tmpArray") + Loop, % len + Manager_manage(m, 1, Manager_initial_sync_tmpArray%A_Index%) + } } Manager_toggleDecor() { - Local aWndId - - WinGet, aWndId, ID, A - Manager_#%aWndId%_isDecorated := Not Manager_#%aWndId%_isDecorated - If Manager_#%aWndId%_isDecorated - Manager_winSet("Style", "+0xC00000", aWndId) - Else - Manager_winSet("Style", "-0xC00000", aWndId) + Local aWndId + + WinGet, aWndId, ID, A + Manager_#%aWndId%_isDecorated := Not Manager_#%aWndId%_isDecorated + If Manager_#%aWndId%_isDecorated + Manager_winSet("Style", "+0xC00000", aWndId) + Else + Manager_winSet("Style", "-0xC00000", aWndId) } Manager_unmanage(wndId) { - Local a - - a := Manager_#%wndId%_tags & 1 << Monitor_#%Manager_aMonitor%_aView_#1 - 1 - Loop, % Config_viewCount - If (Manager_#%wndId%_tags & 1 << A_Index - 1) { - View_delWnd( Manager_aMonitor, A_Index, wndId ) - Bar_updateView(Manager_aMonitor, A_Index) - } - Manager_#%wndId%_monitor := - Manager_#%wndId%_tags := - Manager_#%wndId%_isDecorated := - Manager_#%wndId%_isFloating := - StringReplace, Bar_hideTitleWndIds, Bar_hideTitleWndIds, %wndId%`;, - StringReplace, Manager_allWndIds, Manager_allWndIds, %wndId%`;, - StringReplace, Manager_managedWndIds, Manager_managedWndIds, %wndId%`;, , All - - Return, a + Local a + + a := Manager_#%wndId%_tags & 1 << Monitor_#%Manager_aMonitor%_aView_#1 - 1 + Loop, % Config_viewCount + If (Manager_#%wndId%_tags & 1 << A_Index - 1) { + View_delWnd( Manager_aMonitor, A_Index, wndId ) + Bar_updateView(Manager_aMonitor, A_Index) + } + Manager_#%wndId%_monitor := + Manager_#%wndId%_tags := + Manager_#%wndId%_isDecorated := + Manager_#%wndId%_isFloating := + StringReplace, Bar_hideTitleWndIds, Bar_hideTitleWndIds, %wndId%`;, + StringReplace, Manager_allWndIds, Manager_allWndIds, %wndId%`;, + StringReplace, Manager_managedWndIds, Manager_managedWndIds, %wndId%`;, , All + + Return, a } Manager_winActivate(wndId) { - Local wndHeight, wndWidth, wndX, wndY, newWnd - - If Config_mouseFollowsFocus { - 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 Manager_isHung(wndId) { - Log_dbg_msg(2, "Manager_winActivate: Potentially hung window " . wndId) - Return 1 - } - Else { - WinActivate, ahk_id %wndId% - WinGet, newWin, ID, A - If (wndId != newWin) - Return 1 - } - Bar_updateTitle() - Return 0 + Local wndHeight, wndWidth, wndX, wndY, newWnd + + If Config_mouseFollowsFocus { + 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 Manager_isHung(wndId) { + Log_dbg_msg(2, "Manager_winActivate: Potentially hung window " . wndId) + Return 1 + } + Else { + WinActivate, ahk_id %wndId% + WinGet, newWin, ID, A + If (wndId != newWin) + Return 1 + } + Bar_updateTitle() + Return 0 } Manager_winMove(wndId, x, y, width, height) { - If Manager_isHung(wndId) { - Log_dbg_msg(2, "Manager_winMove: Potentially hung window " . wndId) - Return 1 - } - Else - WinRestore, ahk_id %wndId% - WM_ENTERSIZEMOVE = 0x0231 - WM_EXITSIZEMOVE = 0x0232 - SendMessage, WM_ENTERSIZEMOVE, , , , ahk_id %wndId% - If ErrorLevel { - Log_dbg_msg(2, "Manager_winMove: Potentially hung window " . wndId) - Return 1 - } - Else { - WinMove, ahk_id %wndId%, , %x%, %y%, %width%, %height% - SendMessage, WM_EXITSIZEMOVE, , , , ahk_id %wndId% - } + If Manager_isHung(wndId) { + Log_dbg_msg(2, "Manager_winMove: Potentially hung window " . wndId) + Return 1 + } + Else + WinRestore, ahk_id %wndId% + WM_ENTERSIZEMOVE = 0x0231 + WM_EXITSIZEMOVE = 0x0232 + SendMessage, WM_ENTERSIZEMOVE, , , , ahk_id %wndId% + If ErrorLevel { + Log_dbg_msg(2, "Manager_winMove: Potentially hung window " . wndId) + Return 1 + } + Else { + WinMove, ahk_id %wndId%, , %x%, %y%, %width%, %height% + SendMessage, WM_EXITSIZEMOVE, , , , ahk_id %wndId% + } } Manager_winHide(wndId) { - - If Manager_isHung(wndId) { - Log_dbg_msg(2, "Manager_winHide: Potentially hung window " . wndId) - Return 1 - } - Else { - WinHide, ahk_id %wndId% - Return 0 - } + If Manager_isHung(wndId) { + Log_dbg_msg(2, "Manager_winHide: Potentially hung window " . wndId) + Return 1 + } + Else { + WinHide, ahk_id %wndId% + Return 0 + } } Manager_winShow(wndId) { - - If Manager_isHung(wndId) { - Log_dbg_msg(2, "Manager_winShow: Potentially hung window " . wndId) - Return 1 - } - Else { - WinShow, ahk_id %wndId% - Return 0 - } + If Manager_isHung(wndId) { + Log_dbg_msg(2, "Manager_winShow: Potentially hung window " . wndId) + Return 1 + } + Else { + WinShow, ahk_id %wndId% + Return 0 + } } Manager_winClose(wndId) { - - If Manager_isHung(wndId) { - Log_dbg_msg(2, "Manager_winClose: Potentially hung window " . wndId) - Return 1 - } - Else { - WinClose, ahk_id %wndId% - Return 0 - } + If Manager_isHung(wndId) { + Log_dbg_msg(2, "Manager_winClose: Potentially hung window " . wndId) + Return 1 + } + Else { + WinClose, ahk_id %wndId% + Return 0 + } } Manager_winSet(type, value, wndId) { - - If Manager_isHung(wndId) { - Log_dbg_msg(2, "Manager_winSet: Potentially hung window " . wndId) - Return 1 - } - Else { - WinSet, %type%, %value%, ahk_id %wndId% - Return 0 - } + If Manager_isHung(wndId) { + Log_dbg_msg(2, "Manager_winSet: Potentially hung window " . wndId) + Return 1 + } + Else { + WinSet, %type%, %value%, ahk_id %wndId% + Return 0 + } } ; 0 - Not hung ; 1 - Hung Manager_isHung(wndId) { - Local result, detect_setting, 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 + Local result, detect_setting, 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 } ; Given a ghost window, try to find its body. ; This is only known to work on Windows 7 Manager_findHung( ghostWnd ) { - Local expectedTitle, expectedX, expectedY, expectedW, expectedH, wndTitle, wndX, wndY, wndW, wndH, wndIds - ;Log_dbg_msg(3, "Manager_findHung(" . ghostWnd . ")") - WinGetTitle, expectedTitle, ahk_id %ghostWnd% - StringReplace, expectedTitle, expectedTitle, " (Not Responding)", "" - WinGetPos, expectedX, expectedY, expectedW, expectedH, ahk_id %ghostWnd% - - SetTitleMatchMode, 2 - WinGet, wndIds, List, %expectedTitle% - Loop, % wndIds { - If (A_Index = ghostWnd) - Continue - WinGetPos, wndX, wndY, wndW, wndH, % "ahk_id" wndIDs%A_Index% + Local expectedTitle, expectedX, expectedY, expectedW, expectedH, wndTitle, wndX, wndY, wndW, wndH, wndIds + ;Log_dbg_msg(3, "Manager_findHung(" . ghostWnd . ")") + WinGetTitle, expectedTitle, ahk_id %ghostWnd% + StringReplace, expectedTitle, expectedTitle, " (Not Responding)", "" + WinGetPos, expectedX, expectedY, expectedW, expectedH, ahk_id %ghostWnd% + + SetTitleMatchMode, 2 + WinGet, wndIds, List, %expectedTitle% + 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 + If (wndX = expectedX) And (wndY = expectedY) And (wndW = expectedW) And (wndH = expectedH) + Return wndIds%A_Index% + } + Return 0 } 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 - Return 0 -} \ No newline at end of file + Local wndClass, wndProc + + WinGet, wndProc, ProcessName, ahk_id %wndId% + WinGetClass, wndClass, ahk_id %wndId% + + If (wndProc = "dwm.exe") And (wndClass = "Ghost") + Return 1 + Else + Return 0 +} diff --git a/src/Monitor.ahk b/src/Monitor.ahk index 02c878a..e1b995d 100644 --- a/src/Monitor.ahk +++ b/src/Monitor.ahk @@ -1,295 +1,295 @@ -/** - * bug.n - tiling window management - * Copyright (c) 2010-2012 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 - */ +/* + 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 +*/ Monitor_init(m) { - Global - - Monitor_#%m%_aView_#1 := 1 - Monitor_#%m%_aView_#2 := 1 - Monitor_#%m%_showBar := Config_showBar - Loop, % Config_viewCount - View_init(m, A_Index) - Config_restore("Monitor", m) - Monitor_getWorkArea(m) - Bar_init(m) + Global + + Monitor_#%m%_aView_#1 := 1 + Monitor_#%m%_aView_#2 := 1 + Monitor_#%m%_showBar := Config_showBar + Loop, % Config_viewCount + View_init(m, A_Index) + Config_restore("Monitor", m) + Monitor_getWorkArea(m) + Bar_init(m) } Monitor_activateView(v) { - Local aView, aWndClass, aWndId, aWndTitle, 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) - - Log_dbg_msg(1, "Monitor_activateView(" . v . ") Manager_aMonitor: " . Manager_aMonitor . "; wndIds: " . View_#%m%_#%aView%_wndIds) - - If (v <= 0) Or (v > Config_viewCount) Or Manager_hideShow - Return - ; Re-arrange the windows on the view. - If (v = Monitor_#%Manager_aMonitor%_aView_#1) { - View_arrange(Manager_aMonitor, v) - Return - } - - aView := Monitor_#%Manager_aMonitor%_aView_#1 - WinGet, aWndId, ID, A - If WinExist("ahk_id" aWndId) And InStr(View_#%Manager_aMonitor%_#%aView%_wndIds, aWndId ";") { - WinGetClass, aWndClass, ahk_id %aWndId% - WinGetTitle, aWndTitle, ahk_id %aWndId% - If Not (aWndClass = "Progman") And Not (aWndClass = "AutoHotkeyGui" And SubStr(aWndTitle, 1, 10) = "bug.n_BAR_") And Not (aWndClass = "DesktopBackgroundClass") - View_#%Manager_aMonitor%_#%aView%_aWndId := aWndId - } - - n := 1 - If (Config_syncMonitorViews > 0) - n := Manager_monitorCount - Loop, % n { - If (n = 1) - m := Manager_aMonitor - Else - m := A_Index - - Monitor_#%m%_aView_#2 := aView - Monitor_#%m%_aView_#1 := v - - Manager_hideShow := True - ; Most of the operations here are dispersed to multiple _different_ windows. - ; Delays in this part of the code are extremely noticeable and the users - ; do a lot of view switching. - SetWinDelay, 0 - StringTrimRight, wndIds, View_#%m%_#%aView%_wndIds, 1 - Loop, PARSE, wndIds, `; - If Not (Manager_#%A_LoopField%_tags & (1 << v - 1)) - Manager_winHide(A_LoopField) - SetWinDelay, 10 - DetectHiddenWindows, On - View_arrange(m, v) - DetectHiddenWindows, Off - StringTrimRight, wndIds, View_#%m%_#%v%_wndIds, 1 - SetWinDelay, 0 - Loop, PARSE, wndIds, `; - 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 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) + Local aView, aWndClass, aWndId, aWndTitle, 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) + + Log_dbg_msg(1, "Monitor_activateView(" . v . ") Manager_aMonitor: " . Manager_aMonitor . "; wndIds: " . View_#%m%_#%aView%_wndIds) + + If (v <= 0) Or (v > Config_viewCount) Or Manager_hideShow + Return + ; Re-arrange the windows on the view. + If (v = Monitor_#%Manager_aMonitor%_aView_#1) { + View_arrange(Manager_aMonitor, v) + Return + } + + aView := Monitor_#%Manager_aMonitor%_aView_#1 + WinGet, aWndId, ID, A + If WinExist("ahk_id" aWndId) And InStr(View_#%Manager_aMonitor%_#%aView%_wndIds, aWndId ";") { + WinGetClass, aWndClass, ahk_id %aWndId% + WinGetTitle, aWndTitle, ahk_id %aWndId% + If Not (aWndClass = "Progman") And Not (aWndClass = "AutoHotkeyGui" And SubStr(aWndTitle, 1, 10) = "bug.n_BAR_") And Not (aWndClass = "DesktopBackgroundClass") + View_#%Manager_aMonitor%_#%aView%_aWndId := aWndId + } + + n := 1 + If (Config_syncMonitorViews > 0) + n := Manager_monitorCount + Loop, % n { + If (n = 1) + m := Manager_aMonitor + Else + m := A_Index + + Monitor_#%m%_aView_#2 := aView + Monitor_#%m%_aView_#1 := v + + Manager_hideShow := True + ; Most of the operations here are dispersed to multiple _different_ windows. + ; Delays in this part of the code are extremely noticeable and the users + ; do a lot of view switching. + SetWinDelay, 0 + StringTrimRight, wndIds, View_#%m%_#%aView%_wndIds, 1 + Loop, PARSE, wndIds, `; + If Not (Manager_#%A_LoopField%_tags & (1 << v - 1)) + Manager_winHide(A_LoopField) + SetWinDelay, 10 + DetectHiddenWindows, On + View_arrange(m, v) + DetectHiddenWindows, Off + StringTrimRight, wndIds, View_#%m%_#%v%_wndIds, 1 + SetWinDelay, 0 + Loop, PARSE, wndIds, `; + 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 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) { - Local m - - m := 0 - Loop, % Manager_monitorCount ; Check if the window is on this monitor. - If (x >= Monitor_#%A_Index%_x && x <= Monitor_#%A_Index%_x+Monitor_#%A_Index%_width && y >= Monitor_#%A_Index%_y && y <= Monitor_#%A_Index%_y+Monitor_#%A_Index%_height) { - m := A_Index - Break - } - - Return, m + Local m + + m := 0 + Loop, % Manager_monitorCount ; Check if the window is on this monitor. + If (x >= Monitor_#%A_Index%_x && x <= Monitor_#%A_Index%_x+Monitor_#%A_Index%_width && y >= Monitor_#%A_Index%_y && y <= Monitor_#%A_Index%_y+Monitor_#%A_Index%_height) { + m := A_Index + Break + } + + Return, 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 { - 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 (A_LoopField = "Shell_TrayWnd") - Manager_taskBarMonitor := m - - If (wndHeight < wndWidth) { ; Horizontal - If (wndY <= monitorTop) { ; Top - wndHeight += wndY - monitorTop - monitorTop += wndHeight - } Else { ; Bottom - wndHeight := monitorBottom - wndY - monitorBottom -= wndHeight - } - } Else { ; Vertical - If (wndX <= monitorLeft) { ; Left - wndWidth += wndX - monitorLeft += wndWidth - } Else { ; Right - wndWidth := monitorRight - wndX - monitorRight -= wndWidth - } - } - } - } - } - If Monitor_#%m%_showBar { - If (Config_verticalBarPos = "top" Or (Config_verticalBarPos = "tray" And Not m = Manager_taskBarMonitor)) { - bTop := monitorTop - monitorTop += Bar_height - } Else If (Config_verticalBarPos = "bottom") { - bTop := monitorBottom - Bar_height - monitorBottom -= Bar_height - } - } - - Monitor_#%m%_height := monitorBottom - monitorTop - Monitor_#%m%_width := monitorRight - monitorLeft - Monitor_#%m%_x := monitorLeft - Monitor_#%m%_y := monitorTop - Monitor_#%m%_barY := bTop + 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 { + 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 (A_LoopField = "Shell_TrayWnd") + Manager_taskBarMonitor := m + + If (wndHeight < wndWidth) { ; Horizontal + If (wndY <= monitorTop) { ; Top + wndHeight += wndY - monitorTop + monitorTop += wndHeight + } Else { ; Bottom + wndHeight := monitorBottom - wndY + monitorBottom -= wndHeight + } + } Else { ; Vertical + If (wndX <= monitorLeft) { ; Left + wndWidth += wndX + monitorLeft += wndWidth + } Else { ; Right + wndWidth := monitorRight - wndX + monitorRight -= wndWidth + } + } + } + } + } + If Monitor_#%m%_showBar { + If (Config_verticalBarPos = "top" Or (Config_verticalBarPos = "tray" And Not m = Manager_taskBarMonitor)) { + bTop := monitorTop + monitorTop += Bar_height + } Else If (Config_verticalBarPos = "bottom") { + bTop := monitorBottom - Bar_height + monitorBottom -= Bar_height + } + } + + Monitor_#%m%_height := monitorBottom - monitorTop + Monitor_#%m%_width := monitorRight - monitorLeft + Monitor_#%m%_x := monitorLeft + Monitor_#%m%_y := monitorTop + Monitor_#%m%_barY := bTop } Monitor_moveWindow(m, wndId) { - Global - - Manager_#%wndId%_monitor := m + Global + + Manager_#%wndId%_monitor := m } 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 (t = 0) { - Loop, % Config_viewCount - If Not (Manager_#%aWndId%_tags & (1 << A_Index - 1)) { - View_#%Manager_aMonitor%_#%A_Index%_wndIds := aWndId ";" View_#%Manager_aMonitor%_#%A_Index%_wndIds - View_#%Manager_aMonitor%_#%A_Index%_aWndId := aWndId - Bar_updateView(Manager_aMonitor, A_Index) - Manager_#%aWndId%_tags += 1 << A_Index - 1 - } - } Else { - Loop, % Config_viewCount - If Not (A_index = t) { - 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) { - Manager_hideShow := True - wndId := SubStr(View_#%Manager_aMonitor%_#%aView%_wndIds, 1, InStr(View_#%Manager_aMonitor%_#%aView%_wndIds, ";")-1) - Manager_winActivate(wndId) - Manager_hideShow := False - If Config_viewFollowsTagged - Monitor_activateView(t) - Else { - Manager_hideShow := True - Manager_winHide(aWndId) - Manager_hideShow := False - View_arrange(Manager_aMonitor, aView) - Bar_updateView(Manager_aMonitor, 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 (t = 0) { + Loop, % Config_viewCount + If Not (Manager_#%aWndId%_tags & (1 << A_Index - 1)) { + View_#%Manager_aMonitor%_#%A_Index%_wndIds := aWndId ";" View_#%Manager_aMonitor%_#%A_Index%_wndIds + View_#%Manager_aMonitor%_#%A_Index%_aWndId := aWndId + Bar_updateView(Manager_aMonitor, A_Index) + Manager_#%aWndId%_tags += 1 << A_Index - 1 + } + } Else { + Loop, % Config_viewCount + If Not (A_index = t) { + 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) { + Manager_hideShow := True + wndId := SubStr(View_#%Manager_aMonitor%_#%aView%_wndIds, 1, InStr(View_#%Manager_aMonitor%_#%aView%_wndIds, ";")-1) + Manager_winActivate(wndId) + Manager_hideShow := False + If Config_viewFollowsTagged + Monitor_activateView(t) + Else { + Manager_hideShow := True + Manager_winHide(aWndId) + Manager_hideShow := False + View_arrange(Manager_aMonitor, aView) + Bar_updateView(Manager_aMonitor, t) + } + } + } + } } Monitor_toggleBar() { - Global - - Monitor_#%Manager_aMonitor%_showBar := Not Monitor_#%Manager_aMonitor%_showBar - Bar_toggleVisibility(Manager_aMonitor) - Monitor_getWorkArea(Manager_aMonitor) - View_arrange(Manager_aMonitor, Monitor_#%Manager_aMonitor%_aView_#1) - Manager_winActivate(Bar_aWndId) + Global + + Monitor_#%Manager_aMonitor%_showBar := Not Monitor_#%Manager_aMonitor%_showBar + Bar_toggleVisibility(Manager_aMonitor) + Monitor_getWorkArea(Manager_aMonitor) + View_arrange(Manager_aMonitor, Monitor_#%Manager_aMonitor%_aView_#1) + Manager_winActivate(Bar_aWndId) } Monitor_toggleTaskBar() { - Local m - - m := Manager_aMonitor - If (m = Manager_taskBarMonitor) { - Manager_showTaskBar := Not Manager_showTaskBar - Manager_hideShow := True - If Not Manager_showTaskBar { - WinHide, Start ahk_class Button - WinHide, ahk_class Shell_TrayWnd - } Else { - WinShow, Start ahk_class Button - WinShow, ahk_class Shell_TrayWnd - } - Manager_hideShow := False - Monitor_getWorkArea(m) - Bar_move(m) - View_arrange(m, Monitor_#%m%_aView_#1) - } + Local m + + m := Manager_aMonitor + If (m = Manager_taskBarMonitor) { + Manager_showTaskBar := Not Manager_showTaskBar + Manager_hideShow := True + If Not Manager_showTaskBar { + WinHide, Start ahk_class Button + WinHide, ahk_class Shell_TrayWnd + } Else { + WinShow, Start ahk_class Button + WinShow, ahk_class Shell_TrayWnd + } + Manager_hideShow := False + Monitor_getWorkArea(m) + Bar_move(m) + View_arrange(m, Monitor_#%m%_aView_#1) + } } Monitor_toggleWindowTag(t) { - Local aWndId, wndId - - WinGet, aWndId, ID, A - If (InStr(Manager_managedWndIds, aWndId ";") And t >= 0 And t <= Config_viewCount) { - If (Manager_#%aWndId%_tags & (1 << t - 1)) { - If Not ((Manager_#%aWndId%_tags - (1 << t - 1)) = 0) { - Manager_#%aWndId%_tags -= 1 << t - 1 - StringReplace, View_#%Manager_aMonitor%_#%t%_wndIds, View_#%Manager_aMonitor%_#%t%_wndIds, %aWndId%`;, - Bar_updateView(Manager_aMonitor, t) - If (t = Monitor_#%Manager_aMonitor%_aView_#1) { - Manager_hideShow := True - Manager_winHide(aWndId) - Manager_hideShow := False - wndId := SubStr(View_#%Manager_aMonitor%_#%t%_wndIds, 1, InStr(View_#%Manager_aMonitor%_#%t%_wndIds, ";")-1) - Manager_winActivate(wndId) - View_arrange(Manager_aMonitor, t) - } - } - } Else { - View_#%Manager_aMonitor%_#%t%_wndIds := aWndId ";" View_#%Manager_aMonitor%_#%t%_wndIds - View_#%Manager_aMonitor%_#%t%_aWndId := aWndId - Bar_updateView(Manager_aMonitor, t) - Manager_#%aWndId%_tags += 1 << t - 1 - } - } + Local aWndId, wndId + + WinGet, aWndId, ID, A + If (InStr(Manager_managedWndIds, aWndId ";") And t >= 0 And t <= Config_viewCount) { + If (Manager_#%aWndId%_tags & (1 << t - 1)) { + If Not ((Manager_#%aWndId%_tags - (1 << t - 1)) = 0) { + Manager_#%aWndId%_tags -= 1 << t - 1 + StringReplace, View_#%Manager_aMonitor%_#%t%_wndIds, View_#%Manager_aMonitor%_#%t%_wndIds, %aWndId%`;, + Bar_updateView(Manager_aMonitor, t) + If (t = Monitor_#%Manager_aMonitor%_aView_#1) { + Manager_hideShow := True + Manager_winHide(aWndId) + Manager_hideShow := False + wndId := SubStr(View_#%Manager_aMonitor%_#%t%_wndIds, 1, InStr(View_#%Manager_aMonitor%_#%t%_wndIds, ";")-1) + Manager_winActivate(wndId) + View_arrange(Manager_aMonitor, t) + } + } + } Else { + View_#%Manager_aMonitor%_#%t%_wndIds := aWndId ";" View_#%Manager_aMonitor%_#%t%_wndIds + View_#%Manager_aMonitor%_#%t%_aWndId := aWndId + Bar_updateView(Manager_aMonitor, t) + Manager_#%aWndId%_tags += 1 << t - 1 + } + } } diff --git a/src/View.ahk b/src/View.ahk index 0d3f650..37adbe4 100644 --- a/src/View.ahk +++ b/src/View.ahk @@ -1,396 +1,396 @@ -/** - * bug.n - tiling window management - * Copyright (c) 2010-2012 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 - */ +/* + 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 +*/ View_init(m, v) { - Global - - View_#%m%_#%v%_aWndId := 0 - View_#%m%_#%v%_layout_#1 := 1 - View_#%m%_#%v%_layout_#2 := 1 - View_#%m%_#%v%_layoutAxis_#1 := Config_layoutAxis_#1 - View_#%m%_#%v%_layoutAxis_#2 := Config_layoutAxis_#2 - View_#%m%_#%v%_layoutAxis_#3 := Config_layoutAxis_#3 - View_#%m%_#%v%_layoutGapWidth := Config_layoutGapWidth - View_#%m%_#%v%_layoutMFact := Config_layoutMFactor - View_#%m%_#%v%_layoutMX := 1 - View_#%m%_#%v%_layoutMY := 1 - View_#%m%_#%v%_layoutSymbol := Config_layoutSymbol_#1 - View_#%m%_#%v%_wndIds := "" + Global + + View_#%m%_#%v%_aWndId := 0 + View_#%m%_#%v%_layout_#1 := 1 + View_#%m%_#%v%_layout_#2 := 1 + View_#%m%_#%v%_layoutAxis_#1 := Config_layoutAxis_#1 + View_#%m%_#%v%_layoutAxis_#2 := Config_layoutAxis_#2 + View_#%m%_#%v%_layoutAxis_#3 := Config_layoutAxis_#3 + View_#%m%_#%v%_layoutGapWidth := Config_layoutGapWidth + View_#%m%_#%v%_layoutMFact := Config_layoutMFactor + View_#%m%_#%v%_layoutMX := 1 + View_#%m%_#%v%_layoutMY := 1 + View_#%m%_#%v%_layoutSymbol := Config_layoutSymbol_#1 + View_#%m%_#%v%_wndIds := "" } View_activateWindow(d) { - Local aWndId, i, j, v, wndId, wndId0, wndIds, failure, direction - - Log_dbg_msg(1, "View_activateWindow(" . d . ")") - - If (d = 0) - Return - - WinGet, aWndId, ID, A - Log_dbg_bare(2, "Active Windows ID: " . aWndId) - v := Monitor_#%Manager_aMonitor%_aView_#1 - Log_dbg_bare(2, "View (" . v . ") wndIds: " . View_#%Manager_aMonitor%_#%v%_wndIds) - StringTrimRight, wndIds, View_#%Manager_aMonitor%_#%v%_wndIds, 1 - StringSplit, wndId, wndIds, `; - Log_dbg_bare(2, "wndId count: " . wndId0) - If (wndId0 > 1) { - If Manager_#%aWndId%_isFloating - Manager_winSet("Bottom", "", aWndId) - Loop, % wndId0 - If (wndId%A_Index% = aWndId) { - i := A_Index - Break - } - If (d > 0) - direction = 1 - Else - direction = -1 - Log_dbg_bare(2, "Current wndId index: " . i) - j := Manager_loop(i, d, 1, wndId0) - Loop, % wndId0 { - Log_dbg_bare(2, "Next wndId index: " . j) - wndId := wndId%j% - Manager_winSet("AlwaysOnTop", "On", wndId) - Manager_winSet("AlwaysOnTop", "Off", wndId) - ; This is a lot of extra work in case there are hung windows on the screen. - ; We still want to be able to cycle through them. - failure := Manager_winActivate(wndId) - If Not failure { - Break - } - - j := Manager_loop(j, direction, 1, wndId0) - } - - } + Local aWndId, i, j, v, wndId, wndId0, wndIds, failure, direction + + Log_dbg_msg(1, "View_activateWindow(" . d . ")") + + If (d = 0) + Return + + WinGet, aWndId, ID, A + Log_dbg_bare(2, "Active Windows ID: " . aWndId) + v := Monitor_#%Manager_aMonitor%_aView_#1 + Log_dbg_bare(2, "View (" . v . ") wndIds: " . View_#%Manager_aMonitor%_#%v%_wndIds) + StringTrimRight, wndIds, View_#%Manager_aMonitor%_#%v%_wndIds, 1 + StringSplit, wndId, wndIds, `; + Log_dbg_bare(2, "wndId count: " . wndId0) + If (wndId0 > 1) { + If Manager_#%aWndId%_isFloating + Manager_winSet("Bottom", "", aWndId) + Loop, % wndId0 + If (wndId%A_Index% = aWndId) { + i := A_Index + Break + } + If (d > 0) + direction = 1 + Else + direction = -1 + Log_dbg_bare(2, "Current wndId index: " . i) + j := Manager_loop(i, d, 1, wndId0) + Loop, % wndId0 { + Log_dbg_bare(2, "Next wndId index: " . j) + wndId := wndId%j% + Manager_winSet("AlwaysOnTop", "On", wndId) + Manager_winSet("AlwaysOnTop", "Off", wndId) + ; This is a lot of extra work in case there are hung windows on the screen. + ; We still want to be able to cycle through them. + failure := Manager_winActivate(wndId) + If Not failure { + Break + } + + j := Manager_loop(j, direction, 1, wndId0) + } + + } } View_updateLayout(m, v) { - Local fn, l, wndIds - l := View_#%m%_#%v%_layout_#1 - fn := Config_layoutFunction_#%l% - View_updateLayout_%fn%(m, v) + Local fn, l, wndIds + l := View_#%m%_#%v%_layout_#1 + fn := Config_layoutFunction_#%l% + View_updateLayout_%fn%(m, v) } ; Add a window to the view in question. View_addWnd(m, v, wndId) { - Local l, msplit, i, wndIds, n - - l := View_#%m%_#%v%_layout_#1 - If (Config_layoutFunction_#%l% = "tile") And ((Config_newWndPosition = "masterBottom") Or (Config_newWndPosition = "stackTop")) { - n := View_getTiledWndIds(m, v, wndIds) - msplit := View_#%m%_#%v%_layoutMX * View_#%m%_#%v%_layoutMY - 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) ) { - View_#%m%_#%v%_wndIds .= wndId ";" - } - Else { - If (Config_newWndPosition="masterBottom") - i := msplit - 1 - Else - i := msplit - StringSplit, wndId, wndIds, `; - search := wndId%i% ";" - replace := search wndId ";" - StringReplace, View_#%m%_#%v%_wndIds, View_#%m%_#%v%_wndIds, %search%, %replace% - } - } - Else If (Config_newWndPosition = "bottom") - View_#%m%_#%v%_wndIds .= wndId ";" - Else - View_#%m%_#%v%_wndIds := wndId ";" View_#%m%_#%v%_wndIds + Local l, msplit, i, wndIds, n + + l := View_#%m%_#%v%_layout_#1 + If (Config_layoutFunction_#%l% = "tile") And ((Config_newWndPosition = "masterBottom") Or (Config_newWndPosition = "stackTop")) { + n := View_getTiledWndIds(m, v, wndIds) + msplit := View_#%m%_#%v%_layoutMX * View_#%m%_#%v%_layoutMY + 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) ) { + View_#%m%_#%v%_wndIds .= wndId ";" + } + Else { + If (Config_newWndPosition="masterBottom") + i := msplit - 1 + Else + i := msplit + StringSplit, wndId, wndIds, `; + search := wndId%i% ";" + replace := search wndId ";" + StringReplace, View_#%m%_#%v%_wndIds, View_#%m%_#%v%_wndIds, %search%, %replace% + } + } + Else If (Config_newWndPosition = "bottom") + View_#%m%_#%v%_wndIds .= wndId ";" + Else + View_#%m%_#%v%_wndIds := wndId ";" View_#%m%_#%v%_wndIds } View_ghostWnd(m, v, bodyWndId, ghostWndId) { - Local search, replace - - search := bodyWndId ";" - replace := search ghostWndId ";" - StringReplace, View_#%m%_#%v%_wndIds, View_#%m%_#%v%_wndIds, %search%, %replace% + Local search, replace + + search := bodyWndId ";" + replace := search ghostWndId ";" + StringReplace, View_#%m%_#%v%_wndIds, View_#%m%_#%v%_wndIds, %search%, %replace% } ; Remove a window from the view in question. View_delWnd(m, v, wndId) { - StringReplace, View_#%m%_#%v%_wndIds, View_#%m%_#%v%_wndIds, %wndId%`;, + StringReplace, View_#%m%_#%v%_wndIds, View_#%m%_#%v%_wndIds, %wndId%`;, } View_arrange(m, v) { - Local fn, l, wndIds - Log_dbg_msg(1, "View_arrange(" . m . ", " . v . ")") - ; All window actions are performed on independent windows. A delay won't help. - SetWinDelay, 0 - l := View_#%m%_#%v%_layout_#1 - fn := Config_layoutFunction_#%l% - View_getTiledWndIds(m, v, wndIds) - View_arrange_%fn%(m, v, wndIds) - View_updateLayout(m, v) - Bar_updateLayout(m) - SetWinDelay, 10 + Local fn, l, wndIds + Log_dbg_msg(1, "View_arrange(" . m . ", " . v . ")") + ; All window actions are performed on independent windows. A delay won't help. + SetWinDelay, 0 + l := View_#%m%_#%v%_layout_#1 + fn := Config_layoutFunction_#%l% + View_getTiledWndIds(m, v, wndIds) + View_arrange_%fn%(m, v, wndIds) + View_updateLayout(m, v) + Bar_updateLayout(m) + SetWinDelay, 10 } View_getTiledWndIds(m, v, ByRef tiledWndIds) { - Local n, 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) { - n += 1 - tiledWndIds .= A_LoopField ";" - } - } - - Return, n + Local n, 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) { + n += 1 + tiledWndIds .= A_LoopField ";" + } + } + + Return, n } View_updateLayout_(m, v) { - View_#%m%_#%v%_layoutSymbol := "><>" + View_#%m%_#%v%_layoutSymbol := "><>" } View_arrange_(m, v) { - ; Place-holder + ; Place-holder } View_updateLayout_monocle(m, v) { - Local wndIds, wndId, wndId0 - StringTrimRight, wndIds, View_#%m%_#%v%_wndIds, 1 - StringSplit, wndId, wndIds, `; - View_#%m%_#%v%_layoutSymbol := "[" wndId0 "]" + Local wndIds, wndId, wndId0 + StringTrimRight, wndIds, View_#%m%_#%v%_wndIds, 1 + StringSplit, wndId, wndIds, `; + View_#%m%_#%v%_layoutSymbol := "[" wndId0 "]" } View_arrange_monocle(m, v, wndIds) { - Local gw - - gw := View_#%m%_#%v%_layoutGapWidth - - StringTrimRight, wndIds, wndIds, 1 - StringSplit, View_arrange_monocle_wndId, wndIds, `; - View_draw_stack("View_arrange_monocle_wndId", 1, View_arrange_monocle_wndId0, 0, Monitor_#%m%_x, Monitor_#%m%_y, Monitor_#%m%_width, Monitor_#%m%_height, gw/2) + Local gw + + gw := View_#%m%_#%v%_layoutGapWidth + + StringTrimRight, wndIds, wndIds, 1 + StringSplit, View_arrange_monocle_wndId, wndIds, `; + View_draw_stack("View_arrange_monocle_wndId", 1, View_arrange_monocle_wndId0, 0, Monitor_#%m%_x, Monitor_#%m%_y, Monitor_#%m%_width, Monitor_#%m%_height, gw/2) } View_rotateLayoutAxis(i, d) { - Local f, l, v, n, tmp - - 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 (i = 1) { - If (d = +2) - View_#%Manager_aMonitor%_#%v%_layoutAxis_#%i% *= -1 - 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 { - 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 axis doesn't change, there's no need to adjust (Not (n = View_#%Manager_aMonitor%_#%v%_layoutAxis_#%i%)) - ; 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)) { - tmp := View_#%Manager_aMonitor%_#%v%_layoutMX - View_#%Manager_aMonitor%_#%v%_layoutMX := View_#%Manager_aMonitor%_#%v%_layoutMY - View_#%Manager_aMonitor%_#%v%_layoutMY := tmp - } - View_#%Manager_aMonitor%_#%v%_layoutAxis_#%i% := n - } - View_arrange(Manager_aMonitor, v) - } + Local f, l, v, n, tmp + + 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 (i = 1) { + If (d = +2) + View_#%Manager_aMonitor%_#%v%_layoutAxis_#%i% *= -1 + 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 { + 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 axis doesn't change, there's no need to adjust (Not (n = View_#%Manager_aMonitor%_#%v%_layoutAxis_#%i%)) + ; 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)) { + tmp := View_#%Manager_aMonitor%_#%v%_layoutMX + View_#%Manager_aMonitor%_#%v%_layoutMX := View_#%Manager_aMonitor%_#%v%_layoutMY + View_#%Manager_aMonitor%_#%v%_layoutMY := tmp + } + View_#%Manager_aMonitor%_#%v%_layoutAxis_#%i% := n + } + View_arrange(Manager_aMonitor, v) + } } 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") { + Local l, v, w + + v := Monitor_#%Manager_aMonitor%_aView_#1 + l := View_#%Manager_aMonitor%_#%v%_layout_#1 + If (Config_layoutFunction_#%l% = "tile") { 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) { - View_#%Manager_aMonitor%_#%v%_layoutGapWidth := w - View_arrange(Manager_aMonitor, v) - } - } + If (w < Monitor_#%Manager_aMonitor%_height And w < Monitor_#%Manager_aMonitor%_width) { + View_#%Manager_aMonitor%_#%v%_layoutGapWidth := w + View_arrange(Manager_aMonitor, v) + } + } } 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 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 - } - View_arrange(Manager_aMonitor, v) - } + 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 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 + } + View_arrange(Manager_aMonitor, v) + } } 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") { - mfact := View_#%Manager_aMonitor%_#%v%_layoutMFact + d - If (mfact >= 0.05 And mfact <= 0.95) { - View_#%Manager_aMonitor%_#%v%_layoutMFact := mfact - View_arrange(Manager_aMonitor, v) - } - } + Local l, mfact, v + + v := Monitor_#%Manager_aMonitor%_aView_#1 + l := View_#%Manager_aMonitor%_#%v%_layout_#1 + If (Config_layoutFunction_#%l% = "tile") { + mfact := View_#%Manager_aMonitor%_#%v%_layoutMFact + d + If (mfact >= 0.05 And mfact <= 0.95) { + View_#%Manager_aMonitor%_#%v%_layoutMFact := mfact + View_arrange(Manager_aMonitor, v) + } + } } View_setMX(d) { - Local l, n, m, v - - m := Manager_aMonitor - v := Monitor_#%m%_aView_#1 - l := View_#%m%_#%v%_layout_#1 - If Not (Config_layoutFunction_#%l% = "tile") - Return - - n := View_#%m%_#%v%_layoutMX + d - If (n >= 1) And (n <= 9) { - View_#%m%_#%v%_layoutMX := n - View_arrange(m, v) - } + Local l, n, m, v + + m := Manager_aMonitor + v := Monitor_#%m%_aView_#1 + l := View_#%m%_#%v%_layout_#1 + If Not (Config_layoutFunction_#%l% = "tile") + Return + + n := View_#%m%_#%v%_layoutMX + d + If (n >= 1) And (n <= 9) { + View_#%m%_#%v%_layoutMX := n + View_arrange(m, v) + } } View_setMY(d) { - Local l, n, m, v - - m := Manager_aMonitor - v := Monitor_#%m%_aView_#1 - l := View_#%m%_#%v%_layout_#1 - If Not (Config_layoutFunction_#%l% = "tile") - Return - - n := View_#%m%_#%v%_layoutMY + d - If (n >= 1) And (n <= 9) { - View_#%m%_#%v%_layoutMY := n - View_arrange(m, v) - } + Local l, n, m, v + + m := Manager_aMonitor + v := Monitor_#%m%_aView_#1 + l := View_#%m%_#%v%_layout_#1 + If Not (Config_layoutFunction_#%l% = "tile") + Return + + n := View_#%m%_#%v%_layoutMY + d + If (n >= 1) And (n <= 9) { + View_#%m%_#%v%_layoutMY := n + View_arrange(m, v) + } } View_shuffleWindow(d) { - Local aWndHeight, aWndId, aWndWidth, aWndX, aWndY, i, j, l, search, v, wndId0, wndIds - - 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 ";")) { - View_getTiledWndIds(Manager_aMonitor, v, wndIds) - StringTrimRight, wndIds, wndIds, 1 - StringSplit, wndId, wndIds, `; - If (wndId0 > 1) { - Loop, % wndId0 - If (wndId%A_Index% = aWndId) { - i := A_Index - Break - } - If (d = 0 And i = 1) - j := 2 - Else - j := Manager_loop(i, d, 1, wndId0) - If (j > 0 And j <= wndId0) { - If (j = i) { - StringReplace, View_#%Manager_aMonitor%_#%v%_wndIds, View_#%Manager_aMonitor%_#%v%_wndIds, %aWndId%`;, - View_#%Manager_aMonitor%_#%v%_wndIds := aWndId ";" View_#%Manager_aMonitor%_#%v%_wndIds - } Else { - search := wndId%j% - StringReplace, View_#%Manager_aMonitor%_#%v%_wndIds, View_#%Manager_aMonitor%_#%v%_wndIds, %aWndId%, SEARCH - StringReplace, View_#%Manager_aMonitor%_#%v%_wndIds, View_#%Manager_aMonitor%_#%v%_wndIds, %search%, %aWndId% - StringReplace, View_#%Manager_aMonitor%_#%v%_wndIds, View_#%Manager_aMonitor%_#%v%_wndIds, SEARCH, %search% - } - View_arrange(Manager_aMonitor, v) - - If Config_mouseFollowsFocus { - WinGetPos, aWndX, aWndY, aWndWidth, aWndHeight, ahk_id %aWndId% - DllCall("SetCursorPos", "Int", Round(aWndX + aWndWidth / 2), "Int", Round(aWndY + aWndHeight / 2)) - } - } - } - } + Local aWndHeight, aWndId, aWndWidth, aWndX, aWndY, i, j, l, search, v, wndId0, wndIds + + 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 ";")) { + View_getTiledWndIds(Manager_aMonitor, v, wndIds) + StringTrimRight, wndIds, wndIds, 1 + StringSplit, wndId, wndIds, `; + If (wndId0 > 1) { + Loop, % wndId0 + If (wndId%A_Index% = aWndId) { + i := A_Index + Break + } + If (d = 0 And i = 1) + j := 2 + Else + j := Manager_loop(i, d, 1, wndId0) + If (j > 0 And j <= wndId0) { + If (j = i) { + StringReplace, View_#%Manager_aMonitor%_#%v%_wndIds, View_#%Manager_aMonitor%_#%v%_wndIds, %aWndId%`;, + View_#%Manager_aMonitor%_#%v%_wndIds := aWndId ";" View_#%Manager_aMonitor%_#%v%_wndIds + } Else { + search := wndId%j% + StringReplace, View_#%Manager_aMonitor%_#%v%_wndIds, View_#%Manager_aMonitor%_#%v%_wndIds, %aWndId%, SEARCH + StringReplace, View_#%Manager_aMonitor%_#%v%_wndIds, View_#%Manager_aMonitor%_#%v%_wndIds, %search%, %aWndId% + StringReplace, View_#%Manager_aMonitor%_#%v%_wndIds, View_#%Manager_aMonitor%_#%v%_wndIds, SEARCH, %search% + } + View_arrange(Manager_aMonitor, v) + + If Config_mouseFollowsFocus { + WinGetPos, aWndX, aWndY, aWndWidth, aWndHeight, ahk_id %aWndId% + DllCall("SetCursorPos", "Int", Round(aWndX + aWndWidth / 2), "Int", Round(aWndY + aWndHeight / 2)) + } + } + } + } } View_updateLayout_tile(m, v) { - Local axis1, axis2, axis3, mp, ms, sym1, sym3, master_div, master_dim, master_sym, stack_sym - - ; Main axis - ; 1 - vertical divider, master left - ; 2 - horizontal divider, master top - ; -1 - vertical divider, master right - ; -2 - horizontal divider, master bottom - axis1 := View_#%m%_#%v%_layoutAxis_#1 - ; Master axis - ; 1 - vertical divider - ; 2 - horizontal divider - ; 3 - monocle - axis2 := View_#%m%_#%v%_layoutAxis_#2 - ; Stack axis - ; 1 - vertical divider - ; 2 - horizontal divider - ; 3 - monocle - axis3 := View_#%m%_#%v%_layoutAxis_#3 - mx := View_#%m%_#%v%_layoutMX - my := View_#%m%_#%v%_layoutMY - - If ( Abs(axis1) = 1 ) - master_div := "|" - Else - master_div := "=" - - If ( axis2 = 1 ) { - master_sym := "|" - master_dim := mx . "x" . my - } - Else If ( axis2 = 2 ) { - master_sym := "-" - master_dim := mx . "x" . my - } - Else - master_sym := "[" . (mx * my) . "]" - - If ( axis3 = 1 ) - stack_sym := "|" - Else If ( axis3 = 2 ) - stack_sym := "-" - Else - stack_sym := "o" - - If ( axis1 > 0 ) - View_#%m%_#%v%_layoutSymbol := master_dim . master_sym . master_div . stack_sym - Else - View_#%m%_#%v%_layoutSymbol := stack_sym . master_div . master_sym . master_dim + Local axis1, axis2, axis3, mp, ms, sym1, sym3, master_div, master_dim, master_sym, stack_sym + + ; Main axis + ; 1 - vertical divider, master left + ; 2 - horizontal divider, master top + ; -1 - vertical divider, master right + ; -2 - horizontal divider, master bottom + axis1 := View_#%m%_#%v%_layoutAxis_#1 + ; Master axis + ; 1 - vertical divider + ; 2 - horizontal divider + ; 3 - monocle + axis2 := View_#%m%_#%v%_layoutAxis_#2 + ; Stack axis + ; 1 - vertical divider + ; 2 - horizontal divider + ; 3 - monocle + axis3 := View_#%m%_#%v%_layoutAxis_#3 + mx := View_#%m%_#%v%_layoutMX + my := View_#%m%_#%v%_layoutMY + + If ( Abs(axis1) = 1 ) + master_div := "|" + Else + master_div := "=" + + If ( axis2 = 1 ) { + master_sym := "|" + master_dim := mx . "x" . my + } + Else If ( axis2 = 2 ) { + master_sym := "-" + master_dim := mx . "x" . my + } + Else + master_sym := "[" . (mx * my) . "]" + + If ( axis3 = 1 ) + stack_sym := "|" + Else If ( axis3 = 2 ) + stack_sym := "-" + Else + stack_sym := "o" + + If ( axis1 > 0 ) + View_#%m%_#%v%_layoutSymbol := master_dim . master_sym . master_div . stack_sym + Else + View_#%m%_#%v%_layoutSymbol := stack_sym . master_div . master_sym . master_dim } ; Stack a bunch of windows on top of each other. @@ -406,24 +406,24 @@ View_updateLayout_tile(m, v) { ; h - View height ; margin - Number of pixels to put between the windows. View_draw_stack( arrName, off, len, dir, x, y, w, h, margin ) { - Local base, inc - If (dir = 0) { - base := off - inc := 1 - } - Else { - base := off + len - 1 - inc := -1 - } - x += margin - y += margin - w -= 2 * margin - h -= 2 * margin - - Loop, % len { - Manager_winMove(%arrName%%base%, x, y, w, h) - base += inc - } + Local base, inc + If (dir = 0) { + base := off + inc := 1 + } + Else { + base := off + len - 1 + inc := -1 + } + x += margin + y += margin + w -= 2 * margin + h -= 2 * margin + + Loop, % len { + Manager_winMove(%arrName%%base%, x, y, w, h) + base += inc + } } ; Draw a row of windows. @@ -440,154 +440,154 @@ View_draw_stack( arrName, off, len, dir, x, y, w, h, margin ) { ; h - View height ; margin - Number of pixels to put between the windows. View_draw_row( arrName, off, len, dir, axis, x, y, w, h, margin ) { - Local base, inc, x_inc, y_inc, wHeight, wWidth - ;Log_bare("View_draw_row(" . arrName . ", " . off . ", " . len . ", " . dir . ", " . axis . ", " . x . ", " . y . ", " . w . ", " . h . ", " . margin . ")") - If (dir = 0) { - ; Left-to-right and top-to-bottom, depending on axis - base := off - inc := 1 - } - Else { - ; Right-to-left and bottom-to-top, depending on axis - base := off + len - 1 - inc := -1 - } - If (axis = 0) { - ; Create row along X - x_inc := w / len - y_inc := 0 - wWidth := x_inc - 2 * margin - wHeight := h - 2 * margin - } - Else { - ; Create row along Y - x_inc := 0 - y_inc := h / len - wWidth := w - 2 * margin - wHeight := y_inc - 2 * margin - } - - ; Set original positions with respect to the margins. - x += margin - y += margin - - Loop, % len { - Manager_winMove(%arrName%%base%, x, y, wWidth, wHeight) - x += x_inc - y += y_inc - base += inc - } + Local base, inc, x_inc, y_inc, wHeight, wWidth + ;Log_bare("View_draw_row(" . arrName . ", " . off . ", " . len . ", " . dir . ", " . axis . ", " . x . ", " . y . ", " . w . ", " . h . ", " . margin . ")") + If (dir = 0) { + ; Left-to-right and top-to-bottom, depending on axis + base := off + inc := 1 + } + Else { + ; Right-to-left and bottom-to-top, depending on axis + base := off + len - 1 + inc := -1 + } + If (axis = 0) { + ; Create row along X + x_inc := w / len + y_inc := 0 + wWidth := x_inc - 2 * margin + wHeight := h - 2 * margin + } + Else { + ; Create row along Y + x_inc := 0 + y_inc := h / len + wWidth := w - 2 * margin + wHeight := y_inc - 2 * margin + } + + ; Set original positions with respect to the margins. + x += margin + y += margin + + Loop, % len { + Manager_winMove(%arrName%%base%, x, y, wWidth, wHeight) + x += x_inc + y += y_inc + base += inc + } } View_arrange_tile_action(arrName, off, len, bugn_axis, x, y, w, h, m) { - ; 161 is a magic number determined somewhere. Maybe make this configurable. - ; Same with 2*Bar_height. - If (bugn_axis = 3 Or (bugn_axis = 1 And w/len < 161) Or (bugn_axis = 2 And h/len < (2*Bar_height))) - View_draw_stack(arrName, off, len, 0, x, y, w, h, m) - Else - View_draw_row(arrName, off, len, 0, bugn_axis - 1, x, y, w, h, m) + ; 161 is a magic number determined somewhere. Maybe make this configurable. + ; Same with 2*Bar_height. + If (bugn_axis = 3 Or (bugn_axis = 1 And w/len < 161) Or (bugn_axis = 2 And h/len < (2*Bar_height))) + View_draw_stack(arrName, off, len, 0, x, y, w, h, m) + Else + View_draw_row(arrName, off, len, 0, bugn_axis - 1, x, y, w, h, m) } View_split_region(axis, split_point, x, y, w, h, ByRef x1, ByRef y1, ByRef w1, ByRef h1, ByRef x2, ByRef y2, ByRef w2, ByRef h2) { - x1 := x - y1 := y - If(axis = 0) { - w1 := w * split_point - w2 := w - w1 - h1 := h - h2 := h - x2 := x + w1 - y2 := y - } - Else - { - w1 := w - w2 := w - h1 := h * split_point - h2 := h - h1 - x2 := x - y2 := y + h1 - } + x1 := x + y1 := y + If(axis = 0) { + w1 := w * split_point + w2 := w - w1 + h1 := h + h2 := h + x2 := x + w1 + y2 := y + } + Else + { + w1 := w + w2 := w + h1 := h * split_point + h2 := h - h1 + x2 := x + y2 := y + h1 + } } View_arrange_tile(m, v, wndIds) { - Local axis1, axis2, axis3, gapW_2, h1, h2, i, mfact, mp, ms, mx2, my2, mw2, mh2, msplit, n1, n2, w1, w2, x1, x2, y1, y2, flipped, stack_len, secondary_areas, areas_remaining, draw_windows - - StringTrimRight, wndIds, wndIds, 1 - StringSplit, View_arrange_tile_wndId, wndIds, `; - Log_dbg_msg(1, "View_arrange_tile: (" . View_arrange_tile_wndId0 . ") " . wndIds) - If (View_arrange_tile_wndId0 = 0) - Return + Local axis1, axis2, axis3, gapW_2, h1, h2, i, mfact, mp, ms, mx2, my2, mw2, mh2, msplit, n1, n2, w1, w2, x1, x2, y1, y2, flipped, stack_len, secondary_areas, areas_remaining, draw_windows + + StringTrimRight, wndIds, wndIds, 1 + StringSplit, View_arrange_tile_wndId, wndIds, `; + Log_dbg_msg(1, "View_arrange_tile: (" . View_arrange_tile_wndId0 . ") " . wndIds) + If (View_arrange_tile_wndId0 = 0) + Return - axis1 := Abs(View_#%m%_#%v%_layoutAxis_#1) - axis2 := View_#%m%_#%v%_layoutAxis_#2 - axis3 := View_#%m%_#%v%_layoutAxis_#3 - flipped := View_#%m%_#%v%_layoutAxis_#1 < 0 - gapW_2 := View_#%m%_#%v%_layoutGapWidth/2 - mfact := View_#%m%_#%v%_layoutMFact - dimAligned := (axis2 = 1) ? View_#%m%_#%v%_layoutMX : View_#%m%_#%v%_layoutMY - dimOrtho := (axis2 = 1) ? View_#%m%_#%v%_layoutMY : View_#%m%_#%v%_layoutMX - msplit := dimAligned * dimOrtho + axis1 := Abs(View_#%m%_#%v%_layoutAxis_#1) + axis2 := View_#%m%_#%v%_layoutAxis_#2 + axis3 := View_#%m%_#%v%_layoutAxis_#3 + flipped := View_#%m%_#%v%_layoutAxis_#1 < 0 + gapW_2 := View_#%m%_#%v%_layoutGapWidth/2 + mfact := View_#%m%_#%v%_layoutMFact + dimAligned := (axis2 = 1) ? View_#%m%_#%v%_layoutMX : View_#%m%_#%v%_layoutMY + dimOrtho := (axis2 = 1) ? View_#%m%_#%v%_layoutMY : View_#%m%_#%v%_layoutMX + msplit := dimAligned * dimOrtho - If (msplit > View_arrange_tile_wndId0) { - msplit := View_arrange_tile_wndId0 - } - - ; master and stack area - If( View_arrange_tile_wndId0 > msplit) { - If( flipped = 0) - View_split_region( axis1 - 1, mfact, Monitor_#%m%_x, Monitor_#%m%_y, Monitor_#%m%_width, Monitor_#%m%_height, x1, y1, w1, h1, x2, y2, w2, h2) - Else - View_split_region( axis1 - 1, 1 - mfact, Monitor_#%m%_x, Monitor_#%m%_y, Monitor_#%m%_width, Monitor_#%m%_height, x2, y2, w2, h2, x1, y1, w1, h1) - } - Else { - x1 := Monitor_#%m%_x - y1 := Monitor_#%m%_y - w1 := Monitor_#%m%_width - h1 := Monitor_#%m%_height - } - - ; master - ; Number - If( axis2 = 3 ) - { - View_draw_stack("View_arrange_tile_wndId", 1, msplit, 0, x1, y1, w1, h1, gapW_2) - } - Else - { - secondary_areas := Ceil(msplit / dimAligned) - areas_remaining := secondary_areas - windows_remaining := msplit - ;Log_bare("msplit: " . msplit . "; layoutMX/Y: " . dimAligned . "; secondary_areas: " . secondary_areas . "; areas_remaining: " . areas_remaining . "; windows_remaining: " . windows_remaining) - Loop, % secondary_areas { - View_split_region(Not (axis2 - 1), (1/areas_remaining), x1, y1, w1, h1, mx1, my1, mw1, mh1, x1, y1, w1, h1) - draw_windows := dimAligned - If (windows_remaining < dimAligned) { - draw_windows := windows_remaining - } - View_draw_row("View_arrange_tile_wndId", msplit - windows_remaining + 1, draw_windows, 0, axis2 - 1, mx1, my1, mw1, mh1, gapW_2) - windows_remaining -= draw_windows - areas_remaining -= 1 - } - } - - ; stack - If (View_arrange_tile_wndId0 <= msplit) - Return - - stack_len := View_arrange_tile_wndId0 - msplit - View_arrange_tile_action("View_arrange_tile_wndId", msplit + 1, stack_len, axis3, x2, y2, w2, h2, gapW_2) + If (msplit > View_arrange_tile_wndId0) { + msplit := View_arrange_tile_wndId0 + } + + ; master and stack area + If( View_arrange_tile_wndId0 > msplit) { + If( flipped = 0) + View_split_region( axis1 - 1, mfact, Monitor_#%m%_x, Monitor_#%m%_y, Monitor_#%m%_width, Monitor_#%m%_height, x1, y1, w1, h1, x2, y2, w2, h2) + Else + View_split_region( axis1 - 1, 1 - mfact, Monitor_#%m%_x, Monitor_#%m%_y, Monitor_#%m%_width, Monitor_#%m%_height, x2, y2, w2, h2, x1, y1, w1, h1) + } + Else { + x1 := Monitor_#%m%_x + y1 := Monitor_#%m%_y + w1 := Monitor_#%m%_width + h1 := Monitor_#%m%_height + } + + ; master + ; Number + If( axis2 = 3 ) + { + View_draw_stack("View_arrange_tile_wndId", 1, msplit, 0, x1, y1, w1, h1, gapW_2) + } + Else + { + secondary_areas := Ceil(msplit / dimAligned) + areas_remaining := secondary_areas + windows_remaining := msplit + ;Log_bare("msplit: " . msplit . "; layoutMX/Y: " . dimAligned . "; secondary_areas: " . secondary_areas . "; areas_remaining: " . areas_remaining . "; windows_remaining: " . windows_remaining) + Loop, % secondary_areas { + View_split_region(Not (axis2 - 1), (1/areas_remaining), x1, y1, w1, h1, mx1, my1, mw1, mh1, x1, y1, w1, h1) + draw_windows := dimAligned + If (windows_remaining < dimAligned) { + draw_windows := windows_remaining + } + View_draw_row("View_arrange_tile_wndId", msplit - windows_remaining + 1, draw_windows, 0, axis2 - 1, mx1, my1, mw1, mh1, gapW_2) + windows_remaining -= draw_windows + areas_remaining -= 1 + } + } + + ; stack + If (View_arrange_tile_wndId0 <= msplit) + Return + + stack_len := View_arrange_tile_wndId0 - msplit + View_arrange_tile_action("View_arrange_tile_wndId", msplit + 1, stack_len, axis3, x2, y2, w2, h2, gapW_2) } 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 ";")) { - Manager_#%aWndId%_isFloating := Not Manager_#%aWndId%_isFloating - View_arrange(Manager_aMonitor, v) - Bar_updateTitle() - } + 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 ";")) { + Manager_#%aWndId%_isFloating := Not Manager_#%aWndId%_isFloating + View_arrange(Manager_aMonitor, v) + Bar_updateTitle() + } }