-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwsys.c
141 lines (125 loc) · 2.21 KB
/
wsys.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <u.h>
#include <libc.h>
#include <draw.h> /* for geometry */
#include "dat.h"
#include "fns.h"
static int snarffd;
static ulong snarfvers;
#define MAXSNARF 100*1024
#ifndef BUFSIZE
#define BUFSIZE 4*1024
#endif
static int
ishidden(void)
{
int wctl;
long n;
uchar buf[80];
char *p;
wctl = open("/dev/wctl", OREAD);
if(wctl < 0)
return 0;
n = read(wctl, buf, sizeof(buf));
close(wctl);
if(n < 12*4)
return 0;
buf[sizeof(buf)-1] = 0;
p = (char*)buf;
if(strstr(p, "hidden") != nil)
return 1;
return 0;
}
void
eresized(Rdp* c, int refresh)
{
int fd;
Point d;
USED(refresh);
if(display->locking)
lockdisplay(display);
if(getwindow(display, Refnone) < 0)
sysfatal("resize failed: %r");
/* lifted from /sys/src/cmd/vnc/wsys.c */
d = addpt(Pt(c->xsz, c->ysz), Pt(2*Borderwidth, 2*Borderwidth));
if(d.x < Dx(screen->r) || d.y < Dy(screen->r)){
fd = open("/dev/wctl", OWRITE);
if(fd >= 0){
fprint(fd, "resize -dx %d -dy %d", d.x, d.y);
close(fd);
}
}
turnupdates(c, 0);
turnupdates(c, !ishidden());
if(display->locking)
unlockdisplay(display);
}
void
initsnarf(void)
{
snarffd = open("/dev/snarf", OREAD);
}
/*
* /dev/snarf updates when the file is closed, so we must open our own
* fd here rather than use snarffd
*/
void
putsnarfn(char* s, int nb)
{
int fd, i;
if(nb==0 || nb > MAXSNARF)
return;
fd = open("/dev/snarf", OWRITE);
if(fd < 0)
return;
snarfvers++;
while(nb > 0){
i = write(fd, s, nb);
if(i < 0)
break;
s += i;
nb -= i;
}
close(fd);
}
char*
getsnarfn(int *pnb)
{
int i, n;
char *s, buf[BUFSIZE];
if(snarffd < 0)
return nil;
s = nil;
i = 0;
seek(snarffd, 0, 0);
while((n = read(snarffd, buf, sizeof(buf))) > 0){
s = erealloc(s, i+n+1); // an extra byte for the terminating zero
memmove(s+i, buf, n);
i += n;
}
s[i] = 0;
i++;
*pnb = i;
return s;
}
/* lifted from /sys/src/cmd/vnc/wsys.c */
void
pollsnarf(Rdp* c)
{
Dir *dir;
while(snarffd < 0){
snarffd = open("/dev/snarf", OREAD);
if(snarffd < 0)
sleep(1000*60);
}
for(;;){
sleep(1000);
dir = dirstat("/dev/snarf");
if(dir == nil) /* old drawterm */
continue;
if(dir->qid.vers > snarfvers){
clipannounce(c);
snarfvers = dir->qid.vers;
}
free(dir);
}
}