~ubuntu-branches/ubuntu/natty/xserver-xorg-input-evdev/natty

« back to all changes in this revision

Viewing changes to test/btn0.c

Tags: 1:2.3.1-1
* New upstream release.
  + Finalize the middle button emulation when a read error occurs
    (closes: #550970, #552012)
* Replace the fdi file with an udev rule.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2008 Red Hat, Inc.
3
 
 *
4
 
 * Permission to use, copy, modify, distribute, and sell this software
5
 
 * and its documentation for any purpose is hereby granted without
6
 
 * fee, provided that the above copyright notice appear in all copies
7
 
 * and that both that copyright notice and this permission notice
8
 
 * appear in supporting documentation, and that the name of Red Hat
9
 
 * not be used in advertising or publicity pertaining to distribution
10
 
 * of the software without specific, written prior permission.  Red
11
 
 * Hat makes no representations about the suitability of this software
12
 
 * for any purpose.  It is provided "as is" without express or implied
13
 
 * warranty.
14
 
 *
15
 
 * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16
 
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17
 
 * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18
 
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19
 
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20
 
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21
 
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
 
 *
23
 
 * Authors:
24
 
 *      Peter Hutterer (peter.hutterer@redhat.com)
25
 
 */
26
 
 
27
 
/* Creates a device that has REL_X REL_Y BTN_0 BTN_1 BTN_2
28
 
 *
29
 
 * Moves the device around in a 10px square and clicks after each completed
30
 
 * circle.
31
 
 */
32
 
 
33
 
#include <stdio.h>
34
 
#include <unistd.h>
35
 
#include <linux/input.h>
36
 
#include <linux/uinput.h>
37
 
 
38
 
#include "fakedev.h"
39
 
 
40
 
int btn0_setup(struct uinput_user_dev *dev, int fd)
41
 
{
42
 
    if (ioctl(fd, UI_SET_EVBIT, EV_KEY) == -1) goto error;
43
 
    if (ioctl(fd, UI_SET_EVBIT, EV_REL) == -1) goto error;
44
 
    if (ioctl(fd, UI_SET_EVBIT, EV_SYN) == -1) goto error;
45
 
 
46
 
    /* buttons */
47
 
    if (ioctl(fd, UI_SET_KEYBIT, BTN_0) == -1) goto error;
48
 
    if (ioctl(fd, UI_SET_KEYBIT, BTN_1) == -1) goto error;
49
 
    if (ioctl(fd, UI_SET_KEYBIT, BTN_2) == -1) goto error;
50
 
 
51
 
    /* axes */
52
 
    if (ioctl(fd, UI_SET_RELBIT, REL_X) == -1) goto error;
53
 
    if (ioctl(fd, UI_SET_RELBIT, REL_Y) == -1) goto error;
54
 
 
55
 
    return 0;
56
 
error:
57
 
    perror("ioctl failed.");
58
 
    return -1;
59
 
}
60
 
 
61
 
int btn0_run(int fd)
62
 
{
63
 
    move(fd, -10, 0);
64
 
    usleep(1000);
65
 
    move(fd, 0, -10);
66
 
    usleep(1000);
67
 
    move(fd, 10, 0);
68
 
    usleep(1000);
69
 
    move(fd, 0, 10);
70
 
    usleep(1000);
71
 
    click(fd, BTN_0, 1);
72
 
    usleep(1000);
73
 
    click(fd, BTN_0, 0);
74
 
    return 0;
75
 
}
76
 
 
77
 
struct test_device btn0_dev = {
78
 
    .name  = "BTN_0 test device",
79
 
    .setup = btn0_setup,
80
 
    .run   = btn0_run,
81
 
};
82
 
 
83
 
 
84
 
struct test_device* get_device()
85
 
{
86
 
    return &btn0_dev;
87
 
}