~ecs/swapple

4806b9d025a2b11b2fd47304e69de325633e6833 — Ember Sawady 1 year, 5 months ago 53f2f0e
Various fixes

No clue what most of this is, but it fixes most of the bugs
2 files changed, 26 insertions(+), 19 deletions(-)

M Makefile
M swapple.go
M Makefile => Makefile +1 -1
@@ 1,7 1,7 @@
.POSIX:

RES?=10
FPS?=10
FPS?=30

all: build/frames build/badapple.mkv
	@printf "BUILD\tswapple\n"

M swapple.go => swapple.go +25 -18
@@ 22,10 22,6 @@ func cmd(ipc *i3ipc.IPCSocket, cmd string) {
}

func main() {
	if len(os.Args) != 1 {
		fmt.Fprintln(os.Stderr, "usage: swapple")
		os.Exit(1)
	}
	res, err := strconv.Atoi(os.Getenv("RESOLUTION"))
	if err != nil {
		panic(err)


@@ 43,11 39,10 @@ func main() {
	cmd(ipc, "floating_minimum_size 0 x 0")
	for x := 0; x < res; x++ {
		for y := 0; y < res; y++ {
			cmd(ipc, "exec sh -c 'foot --hold --title "+strconv.Itoa(x)+","+strconv.Itoa(y)+" true &>/dev/null'")
			cmd(ipc, "exec sh -c 'foot --hold --title "+strconv.Itoa(x)+","+strconv.Itoa(y)+" true >/dev/null 2>/dev/null'")
		}
		cmd(ipc, "[tiling] move scratchpad")
	}
	cmd(ipc, "[tiling] move scratchpad")
	time.Sleep(5 * time.Second)
	scanner := bufio.NewScanner(os.Stdin)
	cmd(ipc, "[tiling] move scratchpad")


@@ 55,9 50,9 @@ func main() {
	if err != nil {
		panic(err)
	}
	xres := int(outputs[0].Rect.Width)
	yres := int(outputs[0].Rect.Height)
	fmt.Println("Starting", xres, yres, res)
	xfac := int(float64(outputs[0].Rect.Width) / float64(res))
	yfac := int(float64(outputs[0].Rect.Height) / float64(res))
	fmt.Println("Starting")
	frame := 0
	dropped := 0
	mpv := exec.Command("mpv", "--no-video", "./build/badapple.mkv")


@@ 66,7 61,7 @@ func main() {
	if err != nil {
		panic(err)
	}
	var prev image.Image
	var prev image.Image = nil
	for scanner.Scan() {
		f, err := os.Open(scanner.Text())
		if err != nil {


@@ 85,20 80,32 @@ func main() {
				pon := pr+pg+pb < mid*3
				if on && !pon {
					cmd(ipc, "[title=\""+strconv.Itoa(x)+","+strconv.Itoa(y)+"\"] scratchpad show")
					cmd(ipc, "floating disable")
					cmd(ipc, "floating enable")
					cmd(ipc, "move position "+strconv.Itoa((x-1)*xres/res)+" "+strconv.Itoa((y-1)*yres/res))
					cmd(ipc, "resize set "+strconv.Itoa(xres/res)+" "+strconv.Itoa(yres/res))
					cmd(ipc, "[title=\""+strconv.Itoa(x)+","+strconv.Itoa(y)+"\"] move position "+strconv.Itoa(x*xfac)+" "+strconv.Itoa(y*yfac))
					cmd(ipc, "[title=\""+strconv.Itoa(x)+","+strconv.Itoa(y)+"\"] resize set "+strconv.Itoa(xfac)+" "+strconv.Itoa(yfac))
				} else if !on && pon {
					cmd(ipc, "[title=\""+strconv.Itoa(x)+","+strconv.Itoa(y)+"\"] move scratchpad")
				}
			}
		}
		for y := 0; y < res; y++ {
			for x := 0; x < res; x++ {
				r, g, b, _ := i.At(x, y).RGBA()
				pr, pg, pb, _ := color.White.RGBA()
				if prev != nil {
					pr, pg, pb, _ = prev.At(x, y).RGBA()
				}
				if !on && pon {
				mid, _, _, _ := color.Gray{Y: 128}.RGBA()
				on := r+g+b < mid*3
				pon := pr+pg+pb < mid*3
				if on && !pon {
					cmd(ipc, "[title=\""+strconv.Itoa(x)+","+strconv.Itoa(y)+"\"] move position "+strconv.Itoa(x*xfac)+" "+strconv.Itoa(y*yfac))
				} else if !on && pon {
					cmd(ipc, "[title=\""+strconv.Itoa(x)+","+strconv.Itoa(y)+"\"] move scratchpad")
				}
			}
		}
		fmt.Println("Finished frame")
		fmt.Println("waiting", time.Duration(frame)*time.Second/time.Duration(fps)-time.Now().Sub(start), "until next frame")
		for time.Duration(frame)*time.Second/time.Duration(fps) < time.Now().Sub(start) {
			fmt.Println("[warning] dropping frame")
			fmt.Println("[warning] dropping frame", frame)
			frame++
			dropped++
			scanner.Scan()