5 typedef struct Cursor Cursor;
7 typedef struct Mouse Mouse;
14 resize(Vnc *v, int first)
19 d = addpt(v->dim, Pt(2*Borderwidth, 2*Borderwidth));
22 if(getwindow(display, Refnone) < 0)
23 sysfatal("internal error: can't get the window image");
26 * limit the window to at most the vnc server's size
28 if(first || d.x < Dx(screen->r) || d.y < Dy(screen->r)){
29 fd = open("/dev/wctl", OWRITE);
31 fprint(fd, "resize -dx %d -dy %d", d.x, d.y);
35 unlockdisplay(display);
43 requestupdate(vnc, 0);
46 static Cursor dotcursor = {
83 mouseevent(Vnc *v, Mouse m)
87 vncwrchar(v, m.buttons);
96 pt = addpt(pt, screen->r.min);
97 if(fprint(mousefd, "m%d %d", pt.x, pt.y) < 0)
98 fprint(2, "mousefd write: %r\n");
106 snprint(buf, sizeof buf, "%s/mouse", display->devdir);
107 if((mousefd = open(buf, ORDWR)) < 0)
108 sysfatal("open %s: %r", buf);
117 int cursorfd, len, n;
118 char buf[10*EventSize], *start, *end;
119 uchar curs[2*4+2*2*16];
125 snprint(buf, sizeof buf, "%s/cursor", display->devdir);
126 if((cursorfd = open(buf, OWRITE)) < 0)
127 sysfatal("open %s: %r", buf);
129 BPLONG(curs+0*4, cs->offset.x);
130 BPLONG(curs+1*4, cs->offset.y);
131 memmove(curs+2*4, cs->clr, 2*2*16);
132 write(cursorfd, curs, sizeof curs);
135 requestupdate(vnc, 0);
139 if((n = read(mousefd, end, sizeof(buf) - (end - buf))) < 0)
140 sysfatal("read mouse failed");
144 while(len >= EventSize){
146 m.xy.x = atoi(start+1);
147 m.xy.y = atoi(start+1+12);
148 m.buttons = atoi(start+1+2*12) & 0x1F;
149 m.xy = subpt(m.xy, screen->r.min);
150 if(ptinrect(m.xy, Rpt(ZP, v->dim))){
152 /* send wheel button *release* */
153 if ((m.buttons & 0x7) != m.buttons) {
164 if(start - buf > sizeof(buf) - EventSize){
165 memmove(buf, start, len);
173 tcs(int fd0, int fd1)
177 if(strcmp(charset, "utf-8") == 0)
181 switch(rfork(RFPROC|RFFDG|RFMEM)){
198 execl("/bin/tcs", "tcs", fd0 < 0 ? "-f" : "-t", charset, 0);
199 execl("/bin/cat", "cat", 0);
205 return dup(fd0 < 0 ? fd1 : fd0, -1);
208 static int snarffd = -1;
209 static ulong snarfvers;
217 if(snarffd < 0 || (dir = dirfstat(snarffd)) == nil)
220 ret = dir->qid.vers != snarfvers;
221 snarfvers = dir->qid.vers;
228 writesnarf(Vnc *v, long n)
236 if((sfd = create("/dev/snarf", OWRITE, 0666)) >= 0){
247 vncrdbytes(v, buf, m);
266 p = snarf = malloc(n);
269 if((fd = tcs(snarffd, -1)) >= 0){
270 while((c = read(fd, p, n)) > 0){
275 snarf = realloc(snarf, *sz + 8192);
292 snarffd = open("/dev/snarf", OREAD);
294 sysfatal("can't open /dev/snarf: %r");
302 snarf = getsnarf(&len);
305 vncwrbytes(v, "pad", 3);
307 vncwrbytes(v, snarf, len);