5 typedef struct Cursor Cursor;
7 typedef struct Mouse Mouse;
14 resize(Vnc *v, int first)
20 if(getwindow(display, Refnone) < 0)
21 sysfatal("internal error: can't get the window image");
24 * limit the window to at most the vnc server's size
26 d = addpt(v->dim.max, Pt(2*Borderwidth, 2*Borderwidth));
27 if(first || d.x < Dx(screen->r) || d.y < Dy(screen->r)){
28 fd = open("/dev/wctl", OWRITE);
30 fprint(fd, "resize -dx %d -dy %d", d.x, d.y);
35 unlockdisplay(display);
42 requestupdate(vnc, 0);
45 static Cursor dotcursor = {
82 mouseevent(Vnc *v, Mouse m)
86 vncwrchar(v, m.buttons);
95 pt = addpt(pt, screen->r.min);
96 if(fprint(mousefd, "m%d %d", pt.x, pt.y) < 0)
97 fprint(2, "mousefd write: %r\n");
105 snprint(buf, sizeof buf, "%s/mouse", display->devdir);
106 if((mousefd = open(buf, ORDWR)) < 0)
107 sysfatal("open %s: %r", buf);
116 int cursorfd, len, n;
117 char buf[10*EventSize], *start, *end;
118 uchar curs[2*4+2*2*16];
124 snprint(buf, sizeof buf, "%s/cursor", display->devdir);
125 if((cursorfd = open(buf, OWRITE)) < 0)
126 sysfatal("open %s: %r", buf);
128 BPLONG(curs+0*4, cs->offset.x);
129 BPLONG(curs+1*4, cs->offset.y);
130 memmove(curs+2*4, cs->clr, 2*2*16);
131 write(cursorfd, curs, sizeof curs);
134 requestupdate(vnc, 0);
138 if((n = read(mousefd, end, sizeof(buf) - (end - buf))) < 0)
139 sysfatal("read mouse failed");
143 while(len >= EventSize){
145 m.xy.x = atoi(start+1);
146 m.xy.y = atoi(start+1+12);
147 m.buttons = atoi(start+1+2*12) & 0x1F;
148 m.xy = subpt(m.xy, screen->r.min);
149 if(ptinrect(m.xy, v->dim)){
151 /* send wheel button *release* */
152 if ((m.buttons & 0x7) != m.buttons) {
163 if(start - buf > sizeof(buf) - EventSize){
164 memmove(buf, start, len);
172 tcs(int fd0, int fd1)
176 if(strcmp(charset, "utf-8") == 0)
180 switch(rfork(RFPROC|RFFDG|RFMEM)){
197 execl("/bin/tcs", "tcs", fd0 < 0 ? "-f" : "-t", charset, nil);
198 execl("/bin/cat", "cat", nil);
204 return dup(fd0 < 0 ? fd1 : fd0, -1);
207 static int snarffd = -1;
208 static ulong snarfvers;
216 if(snarffd < 0 || (dir = dirfstat(snarffd)) == nil)
219 ret = dir->qid.vers != snarfvers;
220 snarfvers = dir->qid.vers;
227 writesnarf(Vnc *v, long n)
235 if((sfd = create("/dev/snarf", OWRITE, 0666)) >= 0){
246 vncrdbytes(v, buf, m);
265 p = snarf = malloc(n);
268 if((fd = tcs(snarffd, -1)) >= 0){
269 while((c = read(fd, p, n)) > 0){
274 snarf = realloc(snarf, *sz + 8192);
291 snarffd = open("/dev/snarf", OREAD);
293 sysfatal("can't open /dev/snarf: %r");
301 snarf = getsnarf(&len);
304 vncwrbytes(v, "pad", 3);
306 vncwrbytes(v, snarf, len);