From 9f185f8fb20f29d6e7e8e8fd80115355b302728f Mon Sep 17 00:00:00 2001 From: ShuheiKubota Date: Mon, 18 Nov 2019 14:48:49 +0900 Subject: [PATCH] add: wait command --- cmd_wait.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ vvin.go | 1 + 2 files changed, 48 insertions(+) create mode 100644 cmd_wait.go diff --git a/cmd_wait.go b/cmd_wait.go new file mode 100644 index 0000000..53f8bf8 --- /dev/null +++ b/cmd_wait.go @@ -0,0 +1,47 @@ +package main + +import ( + "errors" + "strings" + "time" + + "github.com/shu-go/gli" +) + +type waitCmd struct { + _ struct{} `help:"[--wait] {Title}"` + + Closed bool + Intervals gli.Duration `cli:"intervals,i=DURATION" default:"1s"` +} + +func (c waitCmd) Run(args []string) error { + if len(args) != 1 { + return errors.New("not one target") + } + + an := ancestors() + t := strings.ToLower(args[0]) + + for { + wins, err := listAllWindows() + if err != nil { + return err + } + + win := findFirstTarget(t, wins, an) + if c.Closed { + if win == nil { + break + } + } else { + if win != nil { + break + } + } + + time.Sleep(c.Intervals.Duration()) + } + + return nil +} diff --git a/vvin.go b/vvin.go index 0f9d726..f74991e 100644 --- a/vvin.go +++ b/vvin.go @@ -33,6 +33,7 @@ type globalCmd struct { Resize resizeCmd `cli:"resize,move,mv" help:"resize/move"` Alpha alphaCmd `cli:"alpha" help:"set alpha 0%(transparent) - 100%(opaque)"` Topmost topmostCmd `cli:"topmost" help:"set always on top/restore"` + Wait waitCmd `cli:"wait"` targetHandle syscall.Handle