5 typedef struct Cursor Cursor;
7 typedef struct Mouse Mouse;
14 adjustwin(Vnc *v, int force)
23 * limit the window to at most the vnc server's size
25 d = subpt(screen->r.max, screen->r.min);
26 if(d.x > v->dim.max.x){
30 if(d.y > v->dim.max.y){
36 fd = open("/dev/wctl", OWRITE);
38 fprint(fd, "resize -dx %d -dy %d", d.x+2*Borderwidth, d.y+2*Borderwidth);
48 if(getwindow(display, Refnone) < 0)
49 sysfatal("internal error: can't get the window image");
50 if((vnc->canresize&2) == 0)
51 adjustwin(vnc, first);
52 unlockdisplay(display);
53 requestupdate(vnc, 0);
56 static Cursor dotcursor = {
93 mouseevent(Vnc *v, Mouse m)
97 vncwrchar(v, m.buttons);
106 pt = addpt(pt, screen->r.min);
107 if(fprint(mousefd, "m%d %d", pt.x, pt.y) < 0)
108 fprint(2, "mousefd write: %r\n");
116 snprint(buf, sizeof buf, "%s/mouse", display->devdir);
117 if((mousefd = open(buf, ORDWR)) < 0)
118 sysfatal("open %s: %r", buf);
127 int cursorfd, len, n;
128 char buf[10*EventSize], *start, *end;
129 uchar curs[2*4+2*2*16];
135 snprint(buf, sizeof buf, "%s/cursor", display->devdir);
136 if((cursorfd = open(buf, OWRITE)) < 0)
137 sysfatal("open %s: %r", buf);
139 BPLONG(curs+0*4, cs->offset.x);
140 BPLONG(curs+1*4, cs->offset.y);
141 memmove(curs+2*4, cs->clr, 2*2*16);
142 write(cursorfd, curs, sizeof curs);
148 if((n = read(mousefd, end, sizeof(buf) - (end - buf))) < 0)
149 sysfatal("read mouse failed");
153 while(len >= EventSize){
155 m.xy.x = atoi(start+1);
156 m.xy.y = atoi(start+1+12);
157 m.buttons = atoi(start+1+2*12) & 0x1F;
158 m.xy = subpt(m.xy, screen->r.min);
159 if(ptinrect(m.xy, v->dim)){
161 /* send wheel button *release* */
162 if ((m.buttons & 0x7) != m.buttons) {
172 if(start - buf > sizeof(buf) - EventSize){
173 memmove(buf, start, len);
181 tcs(int fd0, int fd1)
185 if(strcmp(charset, "utf-8") == 0)
189 switch(rfork(RFPROC|RFFDG|RFMEM)){
206 execl("/bin/tcs", "tcs", fd0 < 0 ? "-f" : "-t", charset, nil);
207 execl("/bin/cat", "cat", nil);
213 return dup(fd0 < 0 ? fd1 : fd0, -1);
216 static int snarffd = -1;
217 static ulong snarfvers;
225 if(snarffd < 0 || (dir = dirfstat(snarffd)) == nil)
228 ret = dir->qid.vers != snarfvers;
229 snarfvers = dir->qid.vers;
236 writesnarf(Vnc *v, long n)
244 if((sfd = create("/dev/snarf", OWRITE, 0666)) >= 0){
255 vncrdbytes(v, buf, m);
274 p = snarf = malloc(n);
277 if((fd = tcs(snarffd, -1)) >= 0){
278 while((c = read(fd, p, n)) > 0){
283 snarf = realloc(snarf, *sz + 8192);
300 snarffd = open("/dev/snarf", OREAD);
302 sysfatal("can't open /dev/snarf: %r");
310 snarf = getsnarf(&len);
313 vncwrbytes(v, "pad", 3);
315 vncwrbytes(v, snarf, len);