-
Notifications
You must be signed in to change notification settings - Fork 0
/
p9win.c
47 lines (42 loc) · 878 Bytes
/
p9win.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
#define _RESEARCH_SOURCE
#define _LOCK_EXTENSION
#define _QLOCK_EXTENSION
#define _BSD_EXTENSION
#define _POSIX_EXTENSION
#define _POSIX_SOURCE
#define _PLAN9_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <u.h>
#include <fmt.h>
#include <lock.h>
#include <qlock.h>
#include <draw.h>
/* PROTO */
int
getwidth(void)
{
int linewidth, charwidth, fd, num;
char buf[128], *fn;
Font *font;
if ((fn = getenv("font")) == NULL)
return -1;
if ((font = openfont(NULL, fn)) == NULL)
return -1;
if ((fd = open("/dev/window", O_RDONLY)) < 0) {
font = NULL;
return -1;
}
num = read(fd, buf, 60);
close(fd);
if (num < 60) {
font = NULL;
return -1;
}
buf[num] = 0;
linewidth = atoi(buf + 36) - atoi(buf + 12) - 25;
charwidth = stringwidth(font, "0");
return linewidth / charwidth;
}