Moved window-related functions to Window.ahk

... therewith revising Manager_findHung (bug in line 272: "If (A_Index =
ghostWnd)")
This commit is contained in:
joten 2015-01-25 18:07:51 +01:00
parent b8e3206b1a
commit c7b6c0a388
4 changed files with 205 additions and 221 deletions

View file

@ -247,3 +247,4 @@ Return
#Include Monitor.ahk #Include Monitor.ahk
#Include ResourceMonitor.ahk #Include ResourceMonitor.ahk
#Include View.ahk #Include View.ahk
#Include Window.ahk

View file

@ -229,56 +229,24 @@ Manager_cleanup()
;; SKAN: Crazy Scripting : Quick Launcher for Portable Apps (http://www.autohotkey.com/forum/topic22398.html) ;; SKAN: Crazy Scripting : Quick Launcher for Portable Apps (http://www.autohotkey.com/forum/topic22398.html)
} }
Manager_closeWindow() Manager_closeWindow() {
{ Local aView, aWndId, c
Local aWndId, aview, c0
WinGet, aWndId, ID, A WinGet, aWndId, ID, A
WinGetClass, aWndClass, ahk_id %aWndId% If Window_isProg(aWndId) {
WinGetTitle, aWndTitle, ahk_id %aWndId%
If Not (aWndClass = "AutoHotkeyGUI" And RegExMatch(aWndTitle, "bug.n_BAR_[0-9]+"))
{
;; Prior to closing, find the next window that should have focus. ;; Prior to closing, find the next window that should have focus.
;; If there is no such window, choose the bar on the same monitor. ;; If there is no such window, choose the bar on the same monitor.
aview := Monitor_#%Manager_aMonitor%_aView_#1 aView := Monitor_#%Manager_aMonitor%_aView_#1
wnds := View_#%Manager_aMonitor%_#%aview%_wndIds StringSplit, c, View_#%Manager_aMonitor%_#%aView%_wndIds, `;
StringSplit, c, wnds, `; If (c0 < 3) {
If (c0 < 3)
{
Manager_winActivate(0) Manager_winActivate(0)
} } Else {
Else
{
View_activateWindow(1) View_activateWindow(1)
} }
Manager_winClose(aWndId) Manager_winClose(aWndId)
} }
} }
;; Given a ghost window, try to find its body.
;; This is only known to work on Windows 7
Manager_findHung(ghostWnd)
{
Local expectedH, expectedTitle, expectedW, expectedX, expectedY, wndH, wndIds, wndTitle, wndW, wndX, wndY
WinGetTitle, expectedTitle, ahk_id %ghostWnd%
StringReplace, expectedTitle, expectedTitle, %Config_ghostWndSubString%,
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
}
Manager_getWindowInfo() Manager_getWindowInfo()
{ {
Local aWndClass, aWndHeight, aWndId, aWndMinMax, aWndProcessName, aWndStyle, aWndTitle, aWndWidth, aWndX, aWndY, rule, text, v Local aWndClass, aWndHeight, aWndId, aWndMinMax, aWndProcessName, aWndStyle, aWndTitle, aWndWidth, aWndX, aWndY, rule, text, v
@ -335,38 +303,6 @@ Manager_getWindowList()
Clipboard := text Clipboard := text
} }
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
}
;; 0 - Not hung
;; 1 - Hung
Manager_isHung(wndId)
{
Local detect_setting, result, WM_NULL
WM_NULL := 0
detect_setting := A_DetectHiddenWindows
DetectHiddenWindows, On
SendMessage, WM_NULL, , , , ahk_id %wndId%
result := ErrorLevel
DetectHiddenWindows, %detect_setting%
If result
Return 1
Else
Return 0
}
Manager_lockWorkStation() Manager_lockWorkStation()
{ {
Global Config_shellMsgDelay Global Config_shellMsgDelay
@ -1216,18 +1152,6 @@ Manager_initial_sync(doRestore)
} }
} }
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)
}
Manager_unmanage(wndId) { Manager_unmanage(wndId) {
Local a, aView, wndId0, wndIds Local a, aView, wndId0, wndIds
@ -1264,139 +1188,30 @@ Manager_unmanage(wndId) {
Return, a Return, a
} }
Manager_winActivate(wndId) Manager_winActivate(wndId) {
{ Local wndHeight, wndWidth, wndX, wndY
Local aWndId, wndHeight, wndWidth, wndX, wndY
If Config_mouseFollowsFocus If Config_mouseFollowsFocus {
{ If wndId {
If wndId
{
WinGetPos, wndX, wndY, wndWidth, wndHeight, ahk_id %wndId% WinGetPos, wndX, wndY, wndWidth, wndHeight, ahk_id %wndId%
DllCall("SetCursorPos", "Int", Round(wndX + wndWidth / 2), "Int", Round(wndY + wndHeight / 2)) DllCall("SetCursorPos", "Int", Round(wndX + wndWidth / 2), "Int", Round(wndY + wndHeight / 2))
} } Else
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)) DllCall("SetCursorPos", "Int", Round(Monitor_#%Manager_aMonitor%_x + Monitor_#%Manager_aMonitor%_width / 2), "Int", Round(Monitor_#%Manager_aMonitor%_y + Monitor_#%Manager_aMonitor%_height / 2))
} }
If wndId And Manager_isHung(wndId)
{
Debug_logMessage("DEBUG[2] Manager_winActivate: Potentially hung window " . wndId, 2)
Return 1
}
Else
{
Debug_logMessage("DEBUG[1] Activating window: " wndId, 1)
If Not wndId
{
If (A_OSVersion = "WIN_8")
WinGet, wndId, ID, ahk_class WorkerW
Else
WinGet, wndId, ID, Program Manager ahk_class Progman
Debug_logMessage("DEBUG[1] Activating Desktop: " wndId, 1)
}
WinActivate, ahk_id %wndId%
WinGet, aWndId, ID, A
If (wndId != aWndId)
Return 1
}
Bar_updateTitle()
Return 0
}
Manager_winClose(wndId) Debug_logMessage("DEBUG[1] Activating window: " wndId, 1)
{ If Not wndId {
If Manager_isHung(wndId) If (A_OSVersion = "WIN_8")
{ WinGet, wndId, ID, ahk_class WorkerW
Debug_logMessage("DEBUG[2] Manager_winClose: Potentially hung window " . wndId, 2) Else
Return 1 WinGet, wndId, ID, Program Manager ahk_class Progman
Debug_logMessage("DEBUG[1] Activating Desktop: " wndId, 1)
} }
Else
{ If Window_activate(wndId)
WinClose, ahk_id %wndId% Return, 1
Return 0 Else {
} Bar_updateTitle()
}
Manager_winHide(wndId)
{
If Manager_isHung(wndId)
{
Debug_logMessage("DEBUG[2] Manager_winHide: Potentially hung window " . wndId, 2)
Return 1
}
Else
{
WinHide, ahk_id %wndId%
Return 0
}
}
Manager_winMaximize(wndId)
{
If Manager_isHung(wndId)
{
Debug_logMessage("DEBUG[2] Manager_winMaximize: Potentially hung window " . wndId, 2)
Return 1
}
Else
{
WinMaximize, ahk_id %wndId%
Return 0
}
}
Manager_winMove(wndId, x, y, width, height)
{
If Manager_isHung(wndId)
{
Debug_logMessage("DEBUG[2] Manager_winMove: Potentially hung window " . wndId, 2)
Return 1
}
Else
{
WinGet, wndMin, MinMax, ahk_id %wndId%
If (wndMin = -1)
WinRestore, ahk_id %wndId%
}
WM_ENTERSIZEMOVE = 0x0231
WM_EXITSIZEMOVE = 0x0232
SendMessage, WM_ENTERSIZEMOVE, , , , ahk_id %wndId%
If ErrorLevel
{
Debug_logMessage("DEBUG[2] Manager_winMove: Potentially hung window " . wndId, 1)
Return 1
}
Else
{
WinMove, ahk_id %wndId%, , %x%, %y%, %width%, %height%
SendMessage, WM_EXITSIZEMOVE, , , , ahk_id %wndId%
}
}
Manager_winSet(type, value, wndId)
{
If Manager_isHung(wndId)
{
Debug_logMessage("DEBUG[2] Manager_winSet: Potentially hung window " . wndId, 2)
Return 1
}
Else
{
WinSet, %type%, %value%, ahk_id %wndId%
Return 0
}
}
Manager_winShow(wndId)
{
If Manager_isHung(wndId)
{
Debug_logMessage("DEBUG[2] Manager_winShow: Potentially hung window " . wndId, 2)
Return 1
}
Else
{
WinShow, ahk_id %wndId%
Return 0 Return 0
} }
} }

View file

@ -227,19 +227,14 @@ View_arrange_tile(m, v, x, y, w, h)
View_stackWindows("View_tiledWndId", mSplit + 1, stackLen, +1, axis3, x2, y2, w2, h2, gapW) View_stackWindows("View_tiledWndId", mSplit + 1, stackLen, +1, axis3, x2, y2, w2, h2, gapW)
} }
View_getActiveWindow(m, v) View_getActiveWindow(m, v) {
{ Local aWndId
Local aWndClass, aWndId, aWndTitle
WinGet, aWndId, ID, A WinGet, aWndId, ID, A
If WinExist("ahk_id" aWndId) And InStr(View_#%m%_#%v%_wndIds, aWndId ";") If WinExist("ahk_id" aWndId) And InStr(View_#%m%_#%v%_wndIds, aWndId ";") And Window_isProg(aWndId)
{ Return, aWndId
WinGetClass, aWndClass, ahk_id %aWndId% Else
WinGetTitle, aWndTitle, ahk_id %aWndId% Return, 0
If Not (aWndClass = "Progman") And Not (aWndClass = "WorkerW") And Not (aWndClass = "AutoHotkeyGui" And SubStr(aWndTitle, 1, 10) = "bug.n_BAR_") And Not (aWndClass = "DesktopBackgroundClass")
Return, aWndId
}
Return, 0
} }
View_getLayoutSymbol_tile(m, v, n) View_getLayoutSymbol_tile(m, v, n)

173
src/Window.ahk Normal file
View file

@ -0,0 +1,173 @@
/*
bug.n -- tiling window management
Copyright (c) 2010-2015 Joshua Fuhs, joten
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.
@license GNU General Public License version 3
../LICENSE.md or <http://www.gnu.org/licenses/>
@version 9.0.0
*/
;; Given a ghost window, try to find its body. This is only known to work on Windows 7
Manager_findHung(ghostWndId) {
Global Config_ghostWndSubString
WinGetTitle, ghostWndTitle, ahk_id %ghostWndId%
StringReplace, ghostWndTitle, ghostWndTitle, %Config_ghostWndSubString%,
WinGetPos, ghostWndX, ghostWndY, ghostWndW, ghostWndH, ahk_id %ghostWndId%
SetTitleMatchMode, 2
WinGet, wndId, List, %ghostWndTitle%
Loop, % wndId {
If (wndId%A_Index% = ghostWndId)
Continue
WinGetPos, wndX, wndY, wndW, wndH, % "ahk_id" wndId%A_Index%
If (wndX = ghostWndX) And (wndY = ghostWndY) And (wndW = ghostWndW) And (wndH = ghostWndH)
Return, wndId%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
}
;; 0 - Not hung
;; 1 - Hung
Manager_isHung(wndId) {
Local detectSetting, result, WM_NULL
WM_NULL = 0
detectSetting := A_DetectHiddenWindows
DetectHiddenWindows, On
SendMessage, WM_NULL, , , , ahk_id %wndId%
result := ErrorLevel
DetectHiddenWindows, %detectSetting%
If result
Return, 1
Else
Return, 0
}
Window_isProg(wndId) {
WinGetClass, wndClass, ahk_id %wndId%
WinGetTitle, wndTitle, ahk_id %wndId%
If Not (wndClass = "Progman") And Not (wndClass = "WorkerW") And Not (wndClass = "DesktopBackgroundClass")
And Not (wndClass = "AutoHotkeyGui" And SubStr(wndTitle, 1, 10) = "bug.n_BAR_")
Return, wndId
Else
Return, 0
}
Manager_winClose(wndId) {
If Manager_isHung(wndId) {
Debug_logMessage("DEBUG[2] Manager_winClose: Potentially hung window " . wndId, 2)
Return, 1
} Else {
WinClose, ahk_id %wndId%
Return, 0
}
}
Manager_winHide(wndId) {
If Manager_isHung(wndId) {
Debug_logMessage("DEBUG[2] Manager_winHide: Potentially hung window " . wndId, 2)
Return, 1
} Else {
WinHide, ahk_id %wndId%
Return, 0
}
}
Manager_winMaximize(wndId) {
If Manager_isHung(wndId) {
Debug_logMessage("DEBUG[2] Manager_winMaximize: Potentially hung window " . wndId, 2)
Return, 1
} Else {
WinMaximize, ahk_id %wndId%
Return, 0
}
}
Manager_winMove(wndId, x, y, width, height) {
If Manager_isHung(wndId) {
Debug_logMessage("DEBUG[2] Manager_winMove: Potentially hung window " . wndId, 2)
Return, 1
} Else {
WinGet, wndMin, MinMax, ahk_id %wndId%
If (wndMin = -1)
WinRestore, ahk_id %wndId%
}
WM_ENTERSIZEMOVE = 0x0231
WM_EXITSIZEMOVE = 0x0232
SendMessage, WM_ENTERSIZEMOVE, , , , ahk_id %wndId%
If ErrorLevel {
Debug_logMessage("DEBUG[2] Manager_winMove: Potentially hung window " . wndId, 1)
Return, 1
} Else {
WinMove, ahk_id %wndId%, , %x%, %y%, %width%, %height%
SendMessage, WM_EXITSIZEMOVE, , , , ahk_id %wndId%
Return, 0
}
}
Manager_winSet(type, value, wndId) {
If Manager_isHung(wndId) {
Debug_logMessage("DEBUG[2] Manager_winSet: Potentially hung window " . wndId, 2)
Return, 1
} Else {
WinSet, %type%, %value%, ahk_id %wndId%
Return, 0
}
}
Manager_winShow(wndId) {
If Manager_isHung(wndId) {
Debug_logMessage("DEBUG[2] Manager_winShow: Potentially hung window " . wndId, 2)
Return, 1
} Else {
WinShow, ahk_id %wndId%
Return, 0
}
}
Manager_toggleDecor(wndId = 0) {
Global
If (wndId = 0)
WinGet, wndId, ID, A
Manager_#%wndId%_isDecorated := Not Manager_#%wndId%_isDecorated
If Manager_#%wndId%_isDecorated
Manager_winSet("Style", "+0xC00000", wndId)
Else
Manager_winSet("Style", "-0xC00000", wndId)
}
Window_activate(wndId) {
If Manager_isHung(wndId) {
Debug_logMessage("DEBUG[2] Window_activate: Potentially hung window " . wndId, 2)
Return, 1
} Else {
WinActivate, ahk_id %wndId%
WinGet, aWndId, ID, A
If (wndId != aWndId)
Return, 1
Else
Return, 0
}
}