Compare commits
2 Commits
1d0ca3a6e0
...
go-rework
Author | SHA1 | Date | |
---|---|---|---|
cd32ec980a | |||
0b1d073e4a |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
main.log
|
||||
__debug_bin3523166607.exe
|
||||
|
76
main.go
76
main.go
@@ -6,6 +6,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
"syscall"
|
||||
|
||||
// _ "embed"
|
||||
@@ -42,43 +43,86 @@ func init() {
|
||||
log.Lmicroseconds|log.Lshortfile)
|
||||
}
|
||||
|
||||
var processes = []uintptr{}
|
||||
var windows = make([]uintptr, 10, 10)
|
||||
|
||||
func main() {
|
||||
go systray.Run(onReady, nil)
|
||||
|
||||
hook.Register(hook.KeyDown, []string{"alt", "-"}, func(e hook.Event) {
|
||||
hwnd, _, _ := GetForegroundWindow.Call()
|
||||
if slices.Contains(processes, hwnd) {
|
||||
processes = slices.DeleteFunc(processes, func(i uintptr) bool {
|
||||
return i == hwnd
|
||||
})
|
||||
} else {
|
||||
processes = append(processes, hwnd)
|
||||
}
|
||||
log.Printf("%#v", processes)
|
||||
})
|
||||
hook.Register(hook.KeyDown, []string{"alt", "1"}, func(e hook.Event) {
|
||||
TabTo(0)
|
||||
TrackWindow(hwnd)
|
||||
})
|
||||
|
||||
for i := 1; i <= 9; i++ {
|
||||
tabIndex := i - 1
|
||||
log.Printf("Registering tab %d", tabIndex)
|
||||
hook.Register(hook.KeyDown, []string{"alt", strconv.Itoa(i)}, func(e hook.Event) {
|
||||
TabTo(tabIndex)
|
||||
})
|
||||
hook.Register(hook.KeyDown, []string{"alt", "shift", strconv.Itoa(i)}, func(e hook.Event) {
|
||||
Swap(tabIndex)
|
||||
})
|
||||
}
|
||||
|
||||
s := hook.Start()
|
||||
<-hook.Process(s)
|
||||
}
|
||||
func TabTo(idx int) {
|
||||
log.Printf("TabTo: %d", idx)
|
||||
log.Printf("%+v", processes)
|
||||
if idx > len(processes) {
|
||||
Warning.Printf("idx %d is greater than length of processes %d", idx, len(processes))
|
||||
log.Printf("%+v", windows)
|
||||
if idx > cap(windows)-1 {
|
||||
Warning.Printf("idx %d is greater than length of windows %d", idx, cap(windows))
|
||||
return
|
||||
}
|
||||
hwnd := processes[idx]
|
||||
hwnd := windows[idx]
|
||||
if hwnd == 0 {
|
||||
Warning.Printf("hwnd for idx %d is 0", idx)
|
||||
return
|
||||
}
|
||||
SetForegroundWindow.Call(hwnd)
|
||||
}
|
||||
func Swap(idx int) {
|
||||
log.Printf("Swap: %d", idx)
|
||||
if idx > cap(windows)-1 {
|
||||
Warning.Printf("idx %d is greater than length of windows %d", idx, cap(windows))
|
||||
return
|
||||
}
|
||||
hwnd, _, _ := GetForegroundWindow.Call()
|
||||
if !IsTracked(hwnd) {
|
||||
TrackWindow(hwnd)
|
||||
}
|
||||
log.Printf("Swapping %d to %d", hwnd, idx)
|
||||
for i := 0; i < cap(windows); i++ {
|
||||
if windows[i] == hwnd {
|
||||
windows[i] = windows[idx]
|
||||
windows[idx] = hwnd
|
||||
log.Printf("Swapped %d to %d at index %d", hwnd, idx, i)
|
||||
break
|
||||
}
|
||||
}
|
||||
log.Printf("windows swapped: %+v", windows)
|
||||
}
|
||||
|
||||
func TrackWindow(hwnd uintptr) {
|
||||
if IsTracked(hwnd) {
|
||||
log.Printf("Untracking window: %d", hwnd)
|
||||
windows = slices.DeleteFunc(windows, func(i uintptr) bool {
|
||||
return i == hwnd
|
||||
})
|
||||
} else {
|
||||
log.Printf("Tracking window: %d", hwnd)
|
||||
for i := 0; i < cap(windows); i++ {
|
||||
if windows[i] == 0 {
|
||||
windows[i] = hwnd
|
||||
log.Printf("Tracked window: %d at index %d", hwnd, i)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
func IsTracked(hwnd uintptr) bool {
|
||||
return slices.Contains(windows, hwnd)
|
||||
}
|
||||
|
||||
func onReady() {
|
||||
// Icons no workey... idk why...
|
||||
|
Reference in New Issue
Block a user