Plan 9 from Bell Labs’s /usr/web/sources/contrib/maht/limbo/appl/cmd/vncgrab.b

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


implement vncgrab;

include "sys.m";
	sys: Sys;
include "draw.m";
	Context: import Draw;

include "bufio.m";
	bufio : Bufio;
	Iobuf: import bufio;

include "arg.m";
	arg : Arg;

include "ppm.m";
	images : Images;
	Image : import images;
	

include "vnc.m";
	vnc : Vnc;
	Server, Rect : import vnc;

vncgrab : module {
	init: fn(nil: ref Context, nil: list of string);
};

pixel_colour_trigger(s : ref Server, pixel_index, trigger_value, until : int, hotspot : ref Rect) : int
{
	r : ref Rect;
	pick bm := s.image.bitmap {
	rgba8 =>
		if(until) {
			do {
				s.send_framebuffer_request(1, hotspot);
				r = <- s.updates;
			} while(bm.pixels[pixel_index] != byte trigger_value);
		} else {
			do {
				s.send_framebuffer_request(1, hotspot);
				r = <- s.updates;
			} while(bm.pixels[pixel_index] == byte trigger_value);
		}
		return 1;
	}
	return 0;
}

init(nil: ref Context, args: list of string)
{
	sys = load Sys Sys->PATH;
	bufio = load Bufio Bufio->PATH;
	vnc = load Vnc Vnc->PATH;
	vnc->init(nil, nil);
	images = load Images Images->PATH;
	images->init(nil, nil);
	arg = load Arg Arg->PATH;
	arg->init(args);
	arg->setusage("vncgrab: -f filename");

	filename := "";

	while((c := arg->opt()) != 0)
		case c {
		'f' => filename = arg->earg();
		}

	if(filename == "")
		arg->usage();

	s := vnc->new_server("tcp!127.0.0.1!5903", "", 3, 1, 0);

	sys->print("Server : %s\n", s.to_string());

	pick bm := s.image.bitmap {
		rgba8 =>
			while(pixel_colour_trigger(s, 66024, 189, 1, ref Rect(120, 10, 20, 20))) {
				r : ref Rect;
				do {
					s.send_framebuffer_request(0, ref Rect(0, 0, 1024, 768));
					r = <- s.updates;
				} while(r.x != 0 && r.y != 0 && r.w != 1024 && r.h != 768) ;
				images->create_ppm(s.image, filename);
				pixel_colour_trigger(s, 66024, 189, 0, ref Rect(120, 10, 20, 20)) ;
			}
		* =>
			raise "how did you get this far!";
	}

	s.io = nil;

}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.