Skip to content

Commit

Permalink
Fixed bugs regarding shell message handling
Browse files Browse the repository at this point in the history
  • Loading branch information
joten committed Apr 27, 2019
1 parent 2d7cae6 commit b3f7dd9
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 13 deletions.
18 changes: 18 additions & 0 deletions doc/development/bug-n-shell-message-handling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Observations

| Application | Message Number | Class | Special Property | Comment |
| -------------- | --------------:| ------------------------ | ---------------- | ----------------------------------------------------------------- |
| Notepad | 16 | `Notepad`, `IME` | hidden | first hidden, later not; additionaly associated with class `IME` |
| Explorer | none | `CabinetWClass` | | WorkerW is triggered |
| Calculator | 16, 1, 2 | `ApplicationFrameWindow` | cloaked, hidden | first hidden, later not |
| GitHub Desktop | 16, 1 | `Chrome_WidgetWin_1` | | additional hidden window with class `Chrome_WidgetWin_0` |

Windows, which do not get deleted, when closing the application:
* hidden Notepad window
* additional GitHub window

The calculator window is immediately deleted.

# Conclusion

Especially Explorer windows are not recognized via shell messages, which match the window. Therefor shell messages can only be used as a trigger, but newly created/ deleted windows have to be detected in comparison to a list of known windows.
1 change: 1 addition & 0 deletions src/Bar.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ Bar_getHeight()
If Not Config_singleRowBar
Bar_ctrlHeight := Bar_height / 2
}
Bar_height := 30
}

Bar_getTextWidth(x, reverse=False)
Expand Down
1 change: 1 addition & 0 deletions src/Main.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ SetWinDelay, 10

;; Pseudo main function
logger := New Logging()
mgr := ""
Main_appDir := ""
If 0 = 1
Main_appDir = %1%
Expand Down
7 changes: 5 additions & 2 deletions src/Manager.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ class Manager {
If (this.resolveAppCall(condition)) {
logger.info((IsObject(wnd) ? "Window " . wnd.id . " m" : "M") . "atched rule " . i . " for message number " . msgNum . ".", "Manager.applyRules")
For j, action in rule.actions {
logger.info("Acting" . (IsObject(wnd) ? " on window " . wnd.id : "") . " to " . action . ".", "Manager.applyRules")
If (action == "break") {
Break, 3
} Else {
If (IsObject(wnd)) {
action := RegExReplace(action, "^set/windows\?id=_", "set/windows?id=" . wnd.id)
action := RegExReplace(action, "^set/windows/_\?$", "set/windows/" . wnd.id . "?")
action := RegExReplace(action, "^set/windows/_\?(closed=True)?$", "set/windows/" . wnd.id . "?$1")
}
this.resolveAppCall(action)
}
Expand Down Expand Up @@ -154,6 +155,7 @@ class Manager {

this.updateActive()

logger.debug("Resolving app call <mark>" . uri . "</mark>.", "Manager.resolveAppCall")
If (uri == "get/True") {
Return, True
} Else If (RegExMatch(uri, "O)^get/windows/([0-9xa-f]{7,8})\?", id)) {
Expand Down Expand Up @@ -188,6 +190,7 @@ class Manager {
If (match[2] == "closed=True" && WinExist(match[1])) {
this.windows[match[1]].setProperty("closed=True")
}
logger.debug("Removing window with id <mark>" . match[1] . "</mark>.", "Manager.resolveAppCall")
this.uifaces[this.monmgrs[1].primaryMonitor].removeTableRows("windows", [match[1]])
this.windows[match[1]] := ""
} Else If (RegExMatch(uri, "O)^set/windows/([0-9xa-f]{7,8})\?", id)) {
Expand Down Expand Up @@ -317,7 +320,7 @@ UifaceEscape:
mgr.uifaces[A_Gui].wnd.setProperty("stackPosition=bottom")
Return

UfaceSize:
UifaceSize:
mgr.uifaces[A_Gui].resizeGuiControls()
Return

Expand Down
2 changes: 1 addition & 1 deletion src/configuration.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Configuration {
, {conditions: ["get/windows/_?class=^Xming$"], actions: ["set/windows?id=_&view=_&tile=True&title=On&caption=Off", "break"]}
, {conditions: ["get/windows/_?isChild=True"], actions: ["set/windows?id=_", "break"]}
, {conditions: ["get/windows/_?isPopup=True"], actions: ["set/windows?id=_", "break"]}
, {conditions: ["get/windows/_?isAppWindows=True"], actions: ["set/windows?id=_&view=_&tile=True&title=On&caption=Off", "break"]}]
, {conditions: ["get/windows/_?isAppWindow=True"], actions: ["set/windows?id=_&view=_&tile=True&title=On&caption=Off", "break"]}]

;;
this.rules[16] := this.rules[1]
Expand Down
7 changes: 5 additions & 2 deletions src/userinterface.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class UserInterface {
keys := ["index", "x", "y", "w", "h"]
}
For i, item in data {
html := "<tr>"
html := "<tr class='bug-n-tr'>"
For j, key in keys {
If (subId == "messages" && key == "winId" || subId == "windows" && key == "id") {
html .= "<td class='w3-tooltip'>" . item[key]
Expand Down Expand Up @@ -208,9 +208,12 @@ class UserInterface {
}

removeTableRows(subId, data) {
Global logger

tbody := this.display.document.getElementById("bug-n-" . subId . "-view").getElementsByTagName("tbody")[0]
For i, item in data {
rows := tbody.getElementsByTagName("tr")
logger.debug("Removing row with first cell's content <mark>" . item . "</mark>.", "UserInterface.removeTableRow")
rows := tbody.getElementsByClassName("bug-n-tr")
n := rows.length
Loop, % n {
If (RegExMatch(rows[n - A_Index].getElementsByTagName("td")[0].innerHTML, "^" . item . "<div")) {
Expand Down
12 changes: 7 additions & 5 deletions src/userinterface.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@
mark {background-color: lightblue;}
.w3-bar-item {line-height: 100%;}
#bug-n-bar {z-index: 4; overflow: hidden;}
#bug-n-shebang {cursor: pointer; font-weight: bold;}
/*#bug-n-system-time {background-color: #000;}
#bug-n-shebang {cursor: pointer; font-weight: bold;}
/*
#bug-n-system-time {background-color: #000;}
#bug-n-system-date {background-color: #222;}
#bug-n-system-battery {background-color: #333;}
#bug-n-system-volume {background-color: #444;}
#bug-n-system-cpu {background-color: #555;}
#bug-n-system-memory {background-color: #666;}
#bug-n-system-storage {background-color: #777;}
#bug-n-system-network {background-color: #888;}*/
#bug-n-system-network {background-color: #888;}
*/
div[id$="-icon"] {cursor: pointer;}
div[id$="-icon"] > div > i {padding: 8px;}
div[id$="-icon"] > div.w3-right {padding: 2px 8px 0 0;}
Expand Down Expand Up @@ -212,8 +214,8 @@ <h3><i class="fa fa-scroll w3-text-deep-orange w3-margin-left w3-margin-right"><
</div>

<!-- Footer -->
<footer class="w3-container w3-display-bottomleft w3-padding-16 w3-light-grey">
<p><img class="w3-left" src="./assets/logo.ico" width="28px" /> User interface Powered by <a href="https://www.w3schools.com/w3css/default.asp" target="_blank">w3.css</a></p>
<footer class="w3-container w3-display-bottomleft w3-padding-16">
<p class="w3-light-grey"><img class="w3-left" src="./assets/logo.ico" width="28px" /> User interface Powered by <a href="https://www.w3schools.com/w3css/default.asp" target="_blank">w3.css</a></p>
</footer>

<!-- End page content -->
Expand Down
11 changes: 8 additions & 3 deletions src/window.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class Window extends Rectangle {

DetectHiddenWindows, On
WinGetClass, winClass, % "ahk_id " . this.id
While (winId != 0 && WinExist(winId) && winClass == "") {
Sleep, 10
}
WinGetClass, winClass, % "ahk_id " . this.id
WinGetTitle, winTitle, % "ahk_id " . this.id
WinGet, winPID, PID, % "ahk_id " . this.id
WinGet, winPName, ProcessName, % "ahk_id " . this.id
Expand All @@ -38,10 +42,11 @@ class Window extends Rectangle {
this.getPosEx()

WinGetClass, winClass, % "ahk_id " . this.id
this.isHidden := (this.class != winClass)
this.isHidden := (this.class != "" && this.class != winClass)
this.hasCaption := (this.style & sys.WS_CAPTION)
isBugNDisplay := (this.class == "AutoHotkeyGUI" && RegExMatch(this.title, "bug.n Display \d+") && !this.hasCaption && this.exStyle & sys.WS_EX_TOOLWINDOW)
this.isAppWindow := (!isBugNDisplay && !this.isCloaked && !this.isHidden && this.w > 0 && this.h > 0)
this.isAppWindow := (!isBugNDisplay && !this.isCloaked && this.w > 0 && this.h > 0)
;; this.isHidden is not significant for a window being an app window; notepad for example first creates a hidden window, which later becomes fully visible.
this.isChild := (this.style & sys.WS_CHILD)
this.isElevated := (!A_IsAdmin && !DllCall("OpenProcess", UInt, 0x400, Int, 0, UInt, winPID, Ptr))
;; jeeswg: How would I mimic the windows Alt+Esc hotkey in AHK? (https://autohotkey.com/boards/viewtopic.php?p=134910&sid=192dd8fcd7839b6222826561491fcd57#p134910)
Expand All @@ -53,7 +58,7 @@ class Window extends Rectangle {
this.ownerId := Format("0x{:x}", DllCall("GetWindow", "UInt", this.id, "UInt", sys.GW_OWNER))
this.parentId := Format("0x{:x}", DllCall("GetParent", "UInt", this.id))

logger.debug("Window with id " . this.id . " added.", "Window.__New")
logger.debug("New window with id <mark>" . this.id . "</mark> and class '<mark>" . this.class . "</mark>' (<mark>" . winClass . "</mark>) added.", "Window.__New")
}

getPosEx() {
Expand Down

0 comments on commit b3f7dd9

Please sign in to comment.