-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxrandr.c
45 lines (35 loc) · 969 Bytes
/
xrandr.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
#include "xrandr.h"
int XRandrGetResolution(int *width, int *height)
{
char *Tempstr=NULL, *Token=NULL;
const char *ptr;
STREAM *S;
S=STREAMSpawnCommand("xrandr -q", "");
if (S)
{
Tempstr=STREAMReadLine(Tempstr, S);
ptr=GetToken(Tempstr, " ", &Token, 0);
while (ptr)
{
if (strcmp(Token, "current")==0)
{
ptr=GetToken(ptr, " ", &Token, 0);
*width=atoi(Token);
ptr=GetToken(ptr, " ", &Token, 0);
ptr=GetToken(ptr, " ", &Token, 0);
*height=atoi(Token);
}
ptr=GetToken(ptr, " ", &Token, 0);
}
STREAMClose(S);
}
Destroy(Tempstr);
}
int XRandrSetResolution(int width, int height)
{
char *Tempstr=NULL;
Tempstr=FormatStr(Tempstr, "xrandr -s %dx%d", width, height);
printf("XRANDR: %s\n", Tempstr);
Spawn(Tempstr, "");
Destroy(Tempstr);
}