Implement basic functionality of tabbing
This commit is contained in:
86
main.go
86
main.go
@@ -5,6 +5,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"slices"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
// _ "embed"
|
// _ "embed"
|
||||||
@@ -19,7 +20,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// //go:embed duck2.jpg
|
// //go:embed duck2.jpg
|
||||||
//var icon []byte
|
// var icon []byte
|
||||||
var Error *log.Logger
|
var Error *log.Logger
|
||||||
var Warning *log.Logger
|
var Warning *log.Logger
|
||||||
|
|
||||||
@@ -41,58 +42,43 @@ func init() {
|
|||||||
log.Lmicroseconds|log.Lshortfile)
|
log.Lmicroseconds|log.Lshortfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
var processes = []uintptr{}
|
||||||
ALT = 0xa4
|
|
||||||
TILDE = 0xc0
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
systray.Run(onReady, nil)
|
go systray.Run(onReady, nil)
|
||||||
keyEvents := make(chan *hook.Event, 4096)
|
|
||||||
hook.Register(hook.KeyDown, []string{}, func(e hook.Event) {
|
|
||||||
keyEvents <- &e
|
|
||||||
})
|
|
||||||
hook.Register(hook.KeyUp, []string{}, func(e hook.Event) {
|
|
||||||
keyEvents <- &e
|
|
||||||
})
|
|
||||||
|
|
||||||
processes := make(map[uintptr]bool)
|
hook.Register(hook.KeyDown, []string{"alt", "-"}, func(e hook.Event) {
|
||||||
keysDown := make(map[uint16]bool)
|
hwnd, _, _ := GetForegroundWindow.Call()
|
||||||
go func() {
|
if slices.Contains(processes, hwnd) {
|
||||||
for {
|
processes = slices.DeleteFunc(processes, func(i uintptr) bool {
|
||||||
key, ok := <-keyEvents
|
return i == hwnd
|
||||||
if !ok {
|
})
|
||||||
Error.Printf("Error reading key events")
|
} else {
|
||||||
return
|
processes = append(processes, hwnd)
|
||||||
}
|
|
||||||
log.Printf("%#v", key)
|
|
||||||
if key.Kind == hook.KeyDown {
|
|
||||||
keysDown[key.Rawcode] = true
|
|
||||||
} else {
|
|
||||||
keysDown[key.Rawcode] = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if keysDown[ALT] && key.Rawcode == TILDE {
|
|
||||||
hwnd, _, _ := GetForegroundWindow.Call()
|
|
||||||
existing, ok := processes[hwnd]
|
|
||||||
if !ok {
|
|
||||||
processes[hwnd] = true
|
|
||||||
} else {
|
|
||||||
processes[hwnd] = !existing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if key.Kind == hook.KeyUp {
|
|
||||||
// StopSpam(key.Rawcode)
|
|
||||||
// } else if key.Kind == hook.KeyDown {
|
|
||||||
// DoSpam(key.Rawcode)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}()
|
log.Printf("%#v", processes)
|
||||||
|
})
|
||||||
|
hook.Register(hook.KeyDown, []string{"alt", "1"}, func(e hook.Event) {
|
||||||
|
TabTo(0)
|
||||||
|
})
|
||||||
|
|
||||||
s := hook.Start()
|
s := hook.Start()
|
||||||
<-hook.Process(s)
|
<-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))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
hwnd := processes[idx]
|
||||||
|
if hwnd == 0 {
|
||||||
|
Warning.Printf("hwnd for idx %d is 0", idx)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
SetForegroundWindow.Call(hwnd)
|
||||||
|
}
|
||||||
|
|
||||||
func onReady() {
|
func onReady() {
|
||||||
// Icons no workey... idk why...
|
// Icons no workey... idk why...
|
||||||
@@ -100,7 +86,15 @@ func onReady() {
|
|||||||
//systray.SetIcon(icon)
|
//systray.SetIcon(icon)
|
||||||
systray.SetTitle("Awesome App")
|
systray.SetTitle("Awesome App")
|
||||||
systray.SetTooltip("Pretty awesome超级棒")
|
systray.SetTooltip("Pretty awesome超级棒")
|
||||||
//mQuit := systray.AddMenuItem("Quit", "Quit the whole app")
|
mQuit := systray.AddMenuItem("Quit", "Quit the whole app")
|
||||||
|
go func() {
|
||||||
|
<-mQuit.ClickedCh
|
||||||
|
fmt.Println("Requesting quit")
|
||||||
|
systray.Quit()
|
||||||
|
os.Exit(0)
|
||||||
|
// TODO: Quit properly, not this exit bullshit
|
||||||
|
fmt.Println("Finished quitting")
|
||||||
|
}()
|
||||||
|
|
||||||
// Sets the icon of a menu item. Only available on Mac and Windows.
|
// Sets the icon of a menu item. Only available on Mac and Windows.
|
||||||
//mQuit.SetIcon(icon)
|
//mQuit.SetIcon(icon)
|
||||||
|
|||||||
Reference in New Issue
Block a user