summaryrefslogtreecommitdiff
path: root/synclient.c
blob: 43df589bf57fd32681954964a16e41b4aa31d8d7 (plain)
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
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <unistd.h>
#include <string.h>

#include <X11/Xdefs.h>
#include "synaptics.h"

static int is_equal(SynapticsSHM* s1, SynapticsSHM* s2)
{
	return ((s1->x     == s2->x) &&
			(s1->y     == s2->y) &&
			(s1->z     == s2->z) &&
			(s1->w     == s2->w) &&
			(s1->left  == s2->left) &&
			(s1->right == s2->right) &&
			(s1->up    == s2->up) &&
			(s1->down  == s2->down));
}

int main()
{
	SynapticsSHM *synshm;
	int shmid;
	SynapticsSHM old;
	memset(&old, 0, sizeof(SynapticsSHM));
	old.x = -1;							/* Force first equality test to fail */

	if((shmid = shmget(SHM_SYNAPTICS, sizeof(SynapticsSHM), 0)) == -1) {
		if ((shmid = shmget(SHM_SYNAPTICS, 0, 0)) == -1) {
			fprintf(stderr, "Can't access shared memory area. SHMConfig disabled?\n");
			exit(1);
		} else {
			fprintf(stderr, "Incorrect size of shared memory area. "
					"Incompatible driver version?\n");
			exit(1);
		}
	}
	if((synshm = (SynapticsSHM*) shmat(shmid, NULL, 0)) == NULL) {
		perror("shmat");
		exit(1);
	}

	while(1) {
		SynapticsSHM cur = *synshm;
		if (!is_equal(&old, &cur)) {
			printf("x:%4d y:%4d z:%3d w:%2d left:%d right:%d up:%d down:%d\n",
				   cur.x, cur.y, cur.z, cur.w, cur.left, cur.right, cur.up, cur.down);
			old = cur;
		}
		usleep(100000);
	}

	exit(0);
}

/* Local Variables: */
/* tab-width: 4 */
/* End: */