-
Notifications
You must be signed in to change notification settings - Fork 2
/
launch-cm.c
72 lines (62 loc) · 1.62 KB
/
launch-cm.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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
static int has_touch_screen(void)
{
DIR *dir;
struct dirent *ent;
char filename[PATH_MAX];
int ret = 0;
dir = opendir("/sys/class/input");
if (!dir)
return 0;
do {
FILE *file;
char line[PATH_MAX];
ent = readdir(dir);
if (!ent)
break;
/* touch screens are "absolute" positioning and will have an 'abs' attribute set to 1 */
sprintf(filename, "/sys/class/input/%s/capabilities/abs", ent->d_name);
file = fopen(filename, "r");
if (!file)
continue;
line[0] = 0;
fgets(line, 4096, file);
fclose(file);
if (line[0] == '1')
ret = 1;
} while (ent != NULL);
closedir(dir);
return ret;
}
int main(int argc, char **argv)
{
while (1) {
int ret;
ret = access("/etc/xdg/autostart/piwiz.desktop", F_OK);
if (ret != 0)
break;
usleep(500000);
}
if (fork() == 0) {
/* If we're not on a touch screen, NULL out the --touch parameter */
if (!has_touch_screen()) {
if (argc > 2 && strcmp(argv[2], "--touch") == 0)
argv[2] = "";
}
execv("/usr/local/bin/carbidemotion", argv);
} else {
#ifdef FULLSCREEN
while (1) {
int ret;
ret = system("wmctrl -r \"Carbide Motion\" -b toggle,fullscreen");
if (ret == 0)
break;
usleep(500000);
}
#endif
}
}