-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
69 lines (55 loc) · 1.46 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package ghettowm
import (
"bits.chrsm.org/x/windows/virtd"
"github.com/chrsm/winapi"
"github.com/chrsm/winapi/user"
)
func bound(i, max int) int {
// loop backwards
if i > max {
return 0
}
// loop forwards
if i < 0 {
return max
}
return i
}
func isUsefulHShellMsg(wparam uintptr) bool {
if wparam == user.HShellWindowActivated ||
wparam == user.HShellWindowCreated ||
wparam == user.HShellWindowDestroyed ||
wparam == user.HShellWindowReplaced {
return true
}
return false
}
func usableWindow(hwnd winapi.HWND) bool {
// is it even visible? lol
if !user.IsWindowVisible(hwnd) || !user.IsWindow(hwnd) {
return false
}
// There are some "windows" that aren't actually on the desktop.
// I don't know enough about Win32 to say _why_ this is.
// For example, there's an invisible Calculator window. It seems
// to become active after the app is launched.
if virtd.GetWindowDesktopNumber(hwnd) == -1 {
return false
}
// we need to remember to re-check the parent after this..
parent := user.GetParent(hwnd)
// src := user.GetWindow(hwnd, user.GwOwner)
style, exstyle := user.GetWindowLong(hwnd, user.GwlStyle), user.GetWindowLong(hwnd, user.GwlExStyle)
if style&user.WsDisabled == user.WsDisabled {
return false
}
// ..figure out how to handle these
if exstyle&user.WsExToolWindow == user.WsExToolWindow {
return false
}
buf := make([]uint16, 10)
if len(user.GetWindowText(hwnd, buf)) == 0 {
return false
}
return parent == 0
}