Compare commits

..

69 Commits

Author SHA1 Message Date
Peter Hutterer
f7850a4042 evdev 2.3.2
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-12-11 13:42:33 +10:00
Peter Hutterer
bd4102af6e Fix up BTN_TOUCH handling for non-button tablets.
BTN_TOOL_* is treated as tool, just like before. BTN_TOUCH on the other hand
may need to be treated as a button left press. This again requires a button
class.

Tested on an HP Touchsmart and a Wacom tablet.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit 1b0df04abe)
2009-12-03 09:27:32 +10:00
Peter Hutterer
22e816eb32 Only init the calibration property for absolute devices.
Relative devices can't be calibrated anyway so why bother.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit 2ca24a16f0)
2009-12-03 09:27:31 +10:00
David Woodhouse
b6b377fe9a Report initial calibration parameters.
Where an initial calibration is provided through the Calibration option
to the driver, it wasn't being exposed in the 'Evdev Axis Calibration'
property. Remedy that...

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Acked-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit 7b285a802b)
2009-12-03 09:27:28 +10:00
David Woodhouse
3772676fd6 Swap axes before applying touch screen calibration.
When the SwapAxes option is set, the X and Y axes in calibration should
be labelled as the user perceives them -- not as the kernel sends them.

Currently, we apply the X-axis calibration to the X-axis of the input,
and then do the axis swapping so we've actually applied the X-axis
calibration to what the user sees as the Y-axis.

This patch changes the order of the operations, so that the axes are
swapped before the calibration is applied.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Acked-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit f187badb71)
2009-12-03 09:27:25 +10:00
Peter Hutterer
4f05afd495 evdev 2.3.1
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-11-20 11:18:03 +10:00
Bartosz Brachaczek
c6964dd28a Set all valuators for relative motion events (#24737)
We should process all the deltas reported by a relative motion device,
otherwise some devices such as A4Tech X-750F or similar may trigger a
situation when the `v` array contains random values (it isn't
initialized anywhere) and later we process them and in effect the mouse
cursor "jumps" on the screen.
I'm not sure why, but we also must be sure that the `first` and `last`
variables reflect the axis map, otherwise the mouse cursor "jumps" on
the screen when clicking mouse buttons in some rare cases reported by
Bartek Iwaniec on Bugzilla. That's why a simple initialization of the
`v` array with zeros isn't sufficient.

X.Org Bug 24737 <http://bugs.freedesktop.org/show_bug.cgi?id=24737>

Signed-off-by: Bartosz Brachaczek <b.brachaczek@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit c1f16a4f59)
2009-11-20 11:17:44 +10:00
Dmitry Torokhov
175af93bdb Relax checks when reopening devices
When checking whether we are dealing with the same device as before
when we try to reopen it evdev should not require exact match of
entire keymap. Users should be allowed to adjust keymaps to better
match their hardware even after X starts. However we don't expect
changes in [BTN_MISC, KEY_OK) range since these codes are reserved for
mice, joysticks, tablets and so forth, so we will limit the check to
this range.

The same goes for absinfo - limits can change and it should not result
in device being disabled.

Also check the length of the data returned by ioctl and don't try to
compare more than we were given.

[peter: moved the key comparison below the led+abs comparison]

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit a0f7f34dc5)
2009-11-20 11:17:42 +10:00
Peter Hutterer
7c3c7f83d0 Fix drag-lock property handler for multiple draglock buttons.
Parsing of the values was wrong. Given an input of 1 2 3 4, button 1 sets
the lock for button 2 and button 3 sets the lock for button 4.

This also means we need to return BadMatch if the property isn't a multiple
of 2.

Red Hat Bug 524428 <https://bugzilla.redhat.com/show_bug.cgi?id=524428>

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit 11669d8279)
2009-11-20 11:17:41 +10:00
Peter Hutterer
aa6399fdb9 evdev 2.3.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-10-19 11:40:24 +10:00
Peter Hutterer
1d86f5dec1 Convert IgnoreAbsolute/RelativeAxes options into trinary state.
The Xen Virtual Pointer device exports both absolute and relative axes from
the kernel device. Which coordinates are used is a run-time decision and
depends on the host-specific configuration.
0a3657d2ee broke these devices, and they are
now unusable out-of-the-box as there is no configuration to cover them.

This patch converts the IgnoreAbsoluteAxes and the IgnoreRelativeAxes
configuration options into a trinary state.
1. If unset, configure the device as normal by trying to guess the right
   axis setup.
2. If set to true, ignore the specific axis type completely (except for
   wheel events).
3. If set to false, explicitly 'unignore' the axis type, alwas configuring
   it if it is present on the device. This setting introduces seemingly
   buggy behaviour (see Bug 21832)

1. and 2. replicate the current driver behaviour.
The result of 3. is that is that if a device has absolute axes and the
options set to false, both axes will be initialized (absolute last to get
clipping right). This requires axis labelling priorty to switch from
relative first to absolute first.

Relative events are forwarded into the server through the absolute axes,
the server scales this into the device absolute range and everyone is happy.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-10-15 11:36:49 +10:00
Peter Hutterer
fbd86e2530 Fix copy/paste typo in comment. 2009-10-15 10:52:27 +10:00
Peter Hutterer
9ea1f9a695 Fix typo, use uppercase like the other messages
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-10-13 18:30:44 +10:00
Oliver McFadden
57b54ee399 evdev: Support the "Calibration" string option.
Originally based on a patch from Daniel Stone, this commit allows for
the calibration factors to be set either from Xorg.conf or via HAL.

Previously the only way was via the properties interface.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-10-13 18:30:43 +10:00
Peter Hutterer
f2dc0681fe Finalize the middle button emulation when a read error occurs (#23048)
If a read error occurs, remove the block and wakeup handlers for middle
mouse button emulation. Otherwise, they'll still be around after the device
has been reopened and overwritten with the new ones created by EvdevOn. Once
this happened, future removal of the device can lead to a server crash.

X.Org Bug 23048 <http://bugs.freedesktop.org/show_bug.cgi?id=23048>

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-10-10 11:12:42 +10:00
Peter Hutterer
3fa49dfcab evdev 2.2.99.2
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-10-08 14:26:41 +10:00
Peter Hutterer
941391ca34 Add explicit options to ignore relative or absolute axes.
The X server cannot deal with devices that have both relative and absolute
axes. Evdev tries to guess wich axes to ignore given the device type and
disables absolute axes for mice and relative axes for tablets, touchscreens
and touchpad. This guess is sometimes wrong and causes exitus felis
domesticae parvulae.

Two new configuration options are provided to explicitly allow ignoring an
axis. Mouse wheel axes are exempt and will work even if relative axes are
ignored.  No property, this option must be set in the configuration.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Daniel Stone <daniel@fooishbar.org>
2009-10-07 12:55:22 +10:00
Peter Hutterer
2144f7d834 Remove unused has_xy.
has_xy is only ever set, but not used for anything else.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-09-30 12:30:59 +10:00
Peter Hutterer
61b4e88e01 emuWheel: fix signed/unsigned screwup
This patch fixes wheel emulation on buttons other than 0.

Reported-by: Andy Neitzke
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-09-23 19:29:41 +10:00
Peter Hutterer
9ee70943ec Require xorg-macros 1.3 and XORG_DEFAULT_OPTIONS
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-09-11 09:57:22 +10:00
Peter Hutterer
415b6ffa95 Only take the driver-internal button mapping to count buttons (#23405)
Regression:
    If a user has multiple buttons mapped to the same button number, the
    number of buttons counted is set to a wrong value.  e.g. a button
    mapping of 1 1 1 for a mouse with three buttons would only initialize 1
    button to the X server.

    In the future, the user cannot change this button mapping as the server
    only knows about one button.

The user-supplied button map (option ButtonMapping) shouldn't matter when
counting the buttons. Only the driver-internal mapping (BTN_0 -> button 1,
etc.) matters.

X.Org Bug 23405 <http://bugs.freedesktop.org/show_bug.cgi?id=23405>

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-08-20 11:09:12 +10:00
Dima Kogan
f4ba2bd785 Allow 0 as wheel emulation button for unconditional scrolling (#20529)
If wheel emulation is on and the emulation button is 0, then any x/y motion
of the device is converted into wheel events. The devices becomes a
scrolling-only device.

Signed-off-by: Dima Kogan <dkogan@cds.caltech.edu>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-08-18 13:09:33 +10:00
Peter Hutterer
2e5f68754f Restrict wheel emulation to a single axis at a time.
Wheel emulation works for both horizontal and vertical axes. Thus, if a
device doesn't move in perfect straight line, scroll events build up on the
respective other axis.

In some clients, scroll wheel events have specific meanings other than
scrolling (e.g. mplayer). In these clients, erroneous scrolling events come
at a high cost.

Thus, if a scroll wheel event is generated for one axis, reset the inertia
of the other axis to 0, avoiding the buildup of these erroneous scrolling
events.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-08-18 13:07:13 +10:00
Peter Hutterer
8fdb2abb6f man: fix documentation for EVDEV_PROP_WHEEL_BUTTON
0 doesn't disable it, it's still treated like a button number. copy/paste
error.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-08-14 13:00:09 +10:00
Peter Hutterer
ca0fb396f1 evdev 2.2.99.1 2009-08-14 11:00:12 +10:00
Peter Hutterer
7967677789 Treat tablets (BTN_TOOL_PEN devices) differently from touchpads.
The previous checks for BTN_TOOL_FINGER and BTN_TOUCH reported false
positives for touchpads for most popular tablets.
As a result, their events were converted to relative events.

Add a new flag EVDEV_TABLET pending presence of BTN_TOOL_PEN and ignore the
touchpad special casing to report the events as-is.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-08-14 10:15:00 +10:00
Peter Hutterer
36064dca90 Add EvdevPostButtonEvent API to immediately post a button event (#23269)
The wheel emulation code needs this API. When the timer expires, the event
must be posted immediately, not enqueued onto the internal event queue.
Otherwise, the emulated middle button press is enqueued only and no event is
sent until the next physical event (and its EV_SYN) arrives.

Since the timer is triggered outside of the SIGIO and SIGIO is blocked
during this period anyway, we could also just enqueue the event and flush by
simulating an EV_SYN. It's easier this way though.

X.Org Bug 23269 <http://bugs.freedesktop.org/show_bug.cgi?id=23269>

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Oliver McFadden <oliver.mcfadden@nokia.com>
2009-08-14 10:00:31 +10:00
Peter Hutterer
8bf93709cb Rename parts of the Post API to a Queue API.
Button and key events aren't posted from EvdevPost*Event, they are simply
enqueued onto the evdev-internal event queue until the next EV_SYN arrives.
Rename those interfaces from EvdevPost* to EvdevQueue* and leave only those
that actually post to the server with a matching "*Post*" name.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Oliver McFadden <oliver.mcfadden@nokia.com>
2009-08-13 14:36:46 +10:00
Peter Hutterer
37373a223b comment typo fix
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-08-13 14:36:44 +10:00
Peter Hutterer
d764dded18 Skip check for EVDEV_RELATIVE_EVENTS for wheel events.
This patch fixes a regression introduced with 1f641d75e.
Wheel axis events are posted as button clicks, a device may have no relative
axes but it does need to post these button clicks.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-08-11 14:38:26 +10:00
Michael Witten
f352598e45 evdev.c: Fix/improve discrimination of rel/abs axes
The relevant comment from evdev.c:

We don't allow relative and absolute axes on the same device. The
reason is that some devices (MS Optical Desktop 2000) register both
rel and abs axes for x/y.

The abs axes register min/max; this min/max then also applies to the
relative device (the mouse) and caps it at 0..255 for both axes.
So, unless you have a small screen, you won't be enjoying it much;
consequently, absolute axes are generally ignored.

However, currenly only a device with absolute axes can be registered
as a touch{pad,screen}. Thus, given such a device, absolute axes are
used and relative axes are ignored.

The code for initializing abs/rel axes has been abstracted out into
3 functions, so that initialization in EvdevInit(device) is as easy
as:

    if (pEvdev->flags & (EVDEV_TOUCHPAD | EVDEV_TOUCHSCREEN))
        EvdevInitTouchDevice(device, pEvdev);
    else if (pEvdev->flags & EVDEV_RELATIVE_EVENTS)
        EvdevInitRelClass(device, pEvdev);
    else if (pEvdev->flags & EVDEV_ABSOLUTE_EVENTS)
        EvdevInitAbsClass(device, pEvdev);

Signed-off-by: Michael Witten <mfwitten@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-08-06 14:06:24 +10:00
Oliver McFadden
69d6ff3e01 evdev: Use the EvdevPost...Event() functions in the emulation code.
This is similar to commit 1f641d75ed.

It provides the same functionality of queuing the (in this case
emulated) events and waiting until an EV_SYN synchronization event is
received before posting them to the server.

This preserves the order of events (both real and emulated) and ensures
that MotionNotify events will always be posted first. It also unifies
the event posting into a few small functions which improves
maintainability.

From this point on, you should never use the xf86Post...Event()
functions in new code, but rather the EvdevPost...Event() versions.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-08-04 16:07:17 +10:00
Peter Hutterer
6f4634111a Evdev doesn't require inputproto.
None of the inputproto headers seem to be included anywhere.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-07-30 09:29:36 +10:00
Oliver McFadden
1f641d75ed evdev: Only send the events at synchronization time.
Instead of just posting the button/key press/release events to the
server as soon as they arrive, add them to an internal queue and post
them once we receive an EV_SYN synchronization event.

The motion events are always sent first, followed by the queued events.
There will be one motion event and possibly many queued button/key
events posted every EV_SYN event.

Note that the size of the event queue (EVDEV_MAXQUEUE) is arbitrary and
you may change it. If we receive more events than the queue can handle,
those events are dropped and a warning message printed.

Tested on my Lenovo T400 using evdev for all input devices; keyboard,
touchpad, and trackpoint.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-07-29 15:26:53 +10:00
Peter Hutterer
2994825665 Don't register middle mouse button emulation handlers for keyboards.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-07-20 14:52:46 +10:00
Oliver McFadden
9bfd9e8a36 Coverity Prevent: NO_EFFECT in EvdevWheelEmuSetProperty:
Event unsigned_compare: Comparing unsigned less than zero is never true. "pEvdev->emulateWheel.timeout < 0UL"
342  	            if (pEvdev->emulateWheel.timeout < 0)

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-07-17 11:08:51 +10:00
Peter Hutterer
dcca28a59c Count REL_DIAL as a scrollwheel during EvdevProbe (#21457)
The Griffin Powermate only has a single axis (REL_DIAL). This axis is
posted as horizontal scroll wheel, so we need to ensure the scroll wheel
setup (including ensuring that enough buttons are available) is triggered
accordingly.

X.Org Bug 21457 <http://bugs.freedesktop.org/show_bug.cgi?id=21457>

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-07-03 10:37:35 +10:00
Asbjrn Sannes
db8b1ca5cf evdev: Fix spelling of property in man page to match source code. #22571
Signed-off-by: Asbj�rn Sannes <ace@sannes.org>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-07-02 07:55:30 +10:00
Peter Hutterer
8cc0d0f285 Fix absolute axis labelling - mapping must be initialized before the labels.
88eedea281 added axis labelling to the
valuator initialization. This requires the axis mapping to be established
before the absolute axis labels are initialized.

88eedea did this for relative axes, but missed out on the absolute ones. As
a result, all abs. labels were initialized to "None".

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-06-29 14:40:21 +10:00
Peter Hutterer
aa1609285d Message "found absolute touchpad" also applies to tablets - fix.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-06-29 14:40:21 +10:00
Peter Hutterer
b07ab6ea97 If a device fails to initialize relative axes, init the abs. axes instead.
Some devices have relative axes that don't count (scroll wheels). In this
case, don't claim we've initialized relative axes, continue with the
absolute axes instead.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-06-29 14:40:18 +10:00
Peter Hutterer
7bc48c666d Fix wrong axis label index causing OOB reads/writes.
The atoms array is filled with each axis atom in mapping order (i.e. after
the driver mapping has been applied). 'axis' OTOH is from 0 to ABS_MAX.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-06-23 15:47:41 +10:00
Peter Hutterer
880ad1e19a Initialize the axis labels to 0, not "misc".
If we don't know what an axis label is, then don't initialize it. None is a
valid label.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-06-23 14:53:11 +10:00
Peter Hutterer
6ab23e4519 Add missing checks for ABI_XINPUT_VERSION 7.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-06-18 16:19:08 +10:00
Peter Hutterer
88eedea281 Cope with ABI_XINPUT_VERSION 7 - requires button + axes labels.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-06-18 15:33:48 +10:00
Peter Hutterer
9a5a4fed3a Split axes and button labels into separate function.
We'll re-use this bit very soon.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-06-18 15:18:14 +10:00
Derek Upham
0a3657d2ee evdev: Prevent driver from processing motion events that it has not configured. #21832
The current implementation initializes itself to support relative
motion events, or absolute motion events, or neither.  But the
event-handling code attempts to process all events, no matter what the
initialization was.  This patch reproduces the flag tests found during
init, to skip events that the driver doesn't support.

Signed-off-by: Derek Upham <sand@blarg.net>
Signed-off-by: Julien Cristau <jcristau@debian.org>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-05-28 08:53:56 +10:00
Peter Hutterer
dc2191285e Deal with BTN_3 to BTN_9 buttons.
These buttons were previously mapped to 0, i.e. inactive. This patch
slightly improves things in that the buttons are now mapped to 8+.

Devices that have both BTN_3 and BTN_SIDE (or a similar pair in that
sequence) have both mapped to the same button number though.
Devices that have BTN_LEFT, BTN_0, BTN_3 and BTN_SIDE have the last three
mapped to 8 (and their followers have double-mappings too). We'll fix that
once we actually see devices affected by this.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-05-21 15:51:08 +10:00
Peter Hutterer
255b9f6bbf Only initialize the number of buttons we actually have.
This takes into account driver-configured button mappings, i.e. if device
with one button has this button mapped to 25 through the ButtonMapping
option, the X server will think the device has result 25 buttons.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-05-21 15:51:08 +10:00
Peter Hutterer
aa117d49a5 Rename pEvdev->buttons to pEvdev->num_buttons for clarity.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-05-21 15:51:08 +10:00
Peter Hutterer
b358f1eb3a Ensure enough buttons are advertised to pass the button mapping.
Some buttons are mapped to higher button numbers. For example, BTN_0 is
posted as button 8 if BTN_LEFT is present. On top of that, the
driver-specific button mapping may map the button to something else again.
We need to take these mappings into account when counting the number of
buttons on the device.

Example: A device with BTN_LEFT and BTN_0 and a mapping from 1 -> 7 and 8 ->
2.

BTN_LEFT is mapped to 1. 1 is mapped to 7. num_buttons is 7.
BTN_0 is mapped to 8. 8 is mapped to 2. num_buttons remains 7.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-05-21 15:51:08 +10:00
Peter Hutterer
33cc112ca1 Up the number of button labels atoms to EVDEV_MAXBUTTONS.
Button labels would smash memory if the device had less than 4 buttons and
did not advertise a wheel event. In this case the hard-coded wheel button
labels would write past the atoms[] boundary.

Potential memory smash if a device had a BTN_LEFT and BTN_0, since the
latter would map to 8, regardless of the the number of actual buttons
(same with BTN_MIDDLE and BTN_1 or BTN_RIGHT and BTN_2).

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-05-21 15:51:08 +10:00
Peter Hutterer
3c43d880f1 Only label axes and buttons if the device has axes or buttons.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-05-21 15:51:08 +10:00
Peter Hutterer
5462898935 Use xf86DisableDevice instead of the DIX' DisableDevice.
DisableDevice has changed API in xi2, xf86DisableDevice hasn't. So let's use
this one so we can have one version for master and xi2.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-05-16 14:27:08 +10:00
Dan Nicholson
9243d338d1 Fix copy-paste error when probing type name
A minor copy and paste error was introduced in 71e9a69e leaving an "if"
where an "else if" should be. Without this, any device configured as
XI_TOUCHPAD or XI_TABLET will end up having the type_name reset to
either XI_TOUCHSCREEN or XI_MOUSE.

Signed-off-by: Dan Nicholson <dbn.lists@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-05-11 08:19:04 +10:00
Peter Hutterer
71e9a69ed6 Revamp the whole "has_axes" definition.
Since we can now deal with multiple axes, etc. we might as well print it
properly.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-04-29 18:27:13 +10:00
Peter Hutterer
220e2dfb8f Print read errors as X_NONE to avoid mallocs in the server.
Messages of type X_NONE are just passed down to the log files, everything else
gets the (EE) or (II) prefixed. Since this mallocs, we can't use it in the
signal handler.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-04-16 13:44:07 +10:00
Peter Hutterer
ddc1266374 Pre-allocate the reopen timer so we don't allocate during sigio handling.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-04-16 13:44:05 +10:00
Peter Hutterer
98ecb5233b Trigger read error handling if len is <= 0.
Red Hat Bug 494245 <https://bugzilla.redhat.com/show_bug.cgi?id=494245>

Reported-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-04-06 10:25:03 +10:00
Peter Hutterer
92ca3dc2e7 Fix wrong reference to axis and button label atom list.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-03-26 13:40:40 +10:00
Peter Hutterer
3fa28c8acd Remove test/ directory.
This shouldn't really be part of the driver source, it's better to just have
it as a separate repository. Code has moved to
git://people.freedesktop.org/~whot/testdevices.git

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-03-26 10:20:56 +10:00
Peter Hutterer
d9809d7edd Fix jumpy touchpads by updating old_vals only when reported by the device.
Remember whether ABS_X or ABS_Y were reported before the SYN event and only
update the old_vals[0, 1] if we got data for them.
Touchpads that reported pressure data before x/y would otherwise update
old_x/y with bogus values, leading to jumps when the first x/y coordinates
were actually reported.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-03-17 14:15:00 +10:00
Peter Hutterer
b11439a176 If we have a touchpad, print so, don't claim we're configuring a tablet.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-03-17 13:27:03 +10:00
Jeremy Jay
740dc202f7 make sure to clear all axis_map entries
don't use uninitialized axis_map entries, ie axis_map[ABS_PRESSURE]

Signed-off-by: Jeremy Jay <dinkumator@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-03-17 13:27:03 +10:00
Peter Hutterer
7ac0c4456d Assume touchscreen/touchpad if we have _either_ ABS_PRESSURE or BTN_TOUCH
Touchpads have pressure or touch and also BTN_TOOL_FINGER.
Touchscreens have either pressure or touch, but no finger.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-03-17 10:08:33 +10:00
Peter Hutterer
b4f6ab126d Move keymap/modifier initialization behind the ABI < 5 ifdefs.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-03-16 10:36:13 +10:00
Jeremy Jay
a3ea979c2b Set "rel" when converting absolute touchpad coordinates to relative (#20661)
We unset "abs" and convert to relative, but never set "rel" so the events
don't get posted. This bit got broken in 43dd2a9592.

X.Org Bug 20661 <http://bugs.freedesktop.org/show_bug.cgi?id=20661>

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-03-16 08:43:16 +10:00
Peter Hutterer
a7fb654a68 Restore repeat-filtering for server 1.5 and earlier.
Letting the server deal with key repeats is fine if we have server 1.6. For
earlier servers, we need to pass on the repeat events (except for modifier
keys).

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Tested-by: Marty Jack <martyj19@comcast.net>
2009-03-10 16:04:49 +10:00
Peter Hutterer
3f06825a44 Bump to 2.2.99.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2009-03-09 10:01:35 +10:00
16 changed files with 972 additions and 1161 deletions

View File

@@ -23,11 +23,7 @@ AUTOMAKE_OPTIONS = foreign
# Ensure headers are installed below $(prefix) for distcheck
DISTCHECK_CONFIGURE_FLAGS = --with-sdkdir='$${includedir}/xorg'
if BUILD_TEST
test_dir=test
endif
SUBDIRS = src man include $(test_dir)
SUBDIRS = src man include
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = xorg-evdev.pc

View File

@@ -22,7 +22,7 @@
AC_PREREQ(2.57)
AC_INIT([xf86-input-evdev],
2.2.5,
2.3.2,
[https://bugs.freedesktop.org/enter_bug.cgi?product=xorg],
xf86-input-evdev)
@@ -32,16 +32,16 @@ AM_INIT_AUTOMAKE([dist-bzip2])
AM_MAINTAINER_MODE
# Require xorg-macros: XORG_CWARNFLAGS, XORG_CHANGELOG
m4_ifndef([XORG_MACROS_VERSION], [AC_FATAL([must install xorg-macros 1.2 or later before running autoconf/autogen])])
XORG_MACROS_VERSION(1.2)
# Require xorg-macros: XORG_DEFAULT_OPTIONS
m4_ifndef([XORG_MACROS_VERSION], [AC_FATAL([must install xorg-macros 1.3 or later before running autoconf/autogen])])
XORG_MACROS_VERSION(1.3)
AM_CONFIG_HEADER([config.h])
# Checks for programs.
AC_DISABLE_STATIC
AC_PROG_LIBTOOL
AC_PROG_CC
XORG_CWARNFLAGS
XORG_DEFAULT_OPTIONS
AH_TOP([#include "xorg-server.h"])
@@ -53,21 +53,6 @@ AC_ARG_WITH(xorg-module-dir,
inputdir=${moduledir}/input
AC_SUBST(inputdir)
# Enable building everything in the test/ directory. These are uinput-based
# devices that resemble random hardware that may or may not look like a mouse,
# keyboard, etc.
AC_ARG_ENABLE(testdevices,
AC_HELP_STRING([--enable-testdevices], [Build uinput-based test devices]),
[BUILD_TEST="yes"],
[BUILD_TEST="no"])
AM_CONDITIONAL([BUILD_TEST], [test "x$BUILD_TEST" = "xyes"])
if test "x$BUILD_TEST" = "xyes"; then
AC_CHECK_FUNC([dlopen], [],
AC_CHECK_LIB([dl], [dlopen], DLOPEN_LIBS="-ldl"))
AC_SUBST([DLOPEN_LIBS])
fi
# Checks for pkg-config packages. We need to be able to override sdkdir
# to satisfy silly distcheck requirements.
PKG_CHECK_MODULES(XORG, xorg-server xproto $REQUIRED_MODULES)
@@ -85,13 +70,8 @@ AC_HEADER_STDC
DRIVER_NAME=evdev
AC_SUBST([DRIVER_NAME])
XORG_MANPAGE_SECTIONS
XORG_RELEASE_VERSION
XORG_CHANGELOG
AC_OUTPUT([Makefile
src/Makefile
man/Makefile
include/Makefile
test/Makefile
xorg-evdev.pc])

View File

@@ -43,7 +43,7 @@
#define EVDEV_PROP_WHEEL_INERTIA "Evdev Wheel Emulation Inertia"
/* CARD16 */
#define EVDEV_PROP_WHEEL_TIMEOUT "Evdev Wheel Emulation Timeout"
/* CARD8, value range 0-32, 0 to disable a value */
/* CARD8, value range 0-32, 0 to always scroll */
#define EVDEV_PROP_WHEEL_BUTTON "Evdev Wheel Emulation Button"
/* Drag lock */

View File

@@ -105,7 +105,10 @@ press/release events as specified for the
.B XAxisMapping
and
.B YAxisMapping
settings. Default: 4. Property: "Evdev Wheel Emulation Button".
settings. If the button is 0 and
.BR EmulateWheel
is on, any motion of the device is converted into wheel events. Default: 4.
Property: "Evdev Wheel Emulation Button".
.TP 7
.BI "Option \*qEmulateWheelInertia\*q \*q" integer \*q
Specifies how far (in pixels) the pointer must move to generate button
@@ -132,10 +135,34 @@ Default: disabled.
.BI "Option \*qInvertY\*q \*q" Bool \*q
Invert the given axis. Default: off. Property: "Evdev Axis Inversion".
.TP 7
.BI "Option \*qIgnoreRelativeAxes\*q \*q" Bool \*q
.TP 7
.BI "Option \*qIgnoreAbsoluteAxes\*q \*q" Bool \*q
Ignore the specified type of axis. Default: unset. The X server cannot deal
with devices that have both relative and absolute axes. Evdev tries to guess
wich axes to ignore given the device type and disables absolute axes for
mice and relative axes for tablets, touchscreens and touchpad. These options
allow to forcibly disable an axis type. Mouse wheel axes are exempt and will
work even if relative axes are ignored. No property, this configuration must
be set in the configuration.
.br
If either option is set to False, the driver will not ignore the specified
axes regardless of the presence of other axes. This may trigger buggy
behavior and events from this axis are always forwarded. Users are
discouraged from setting this option.
.TP 7
.BI "Option \*qReopenAttempts\*q \*q" integer \*q
Number of reopen attempts after a read error occurs on the device (e.g. after
waking up from suspend). In between each attempt is a 100ms wait. Default: 10.
.TP 7
.BI "Option \*qCalibration\*q \*q" "min-x max-x min-y max-y" \*q
Calibrates the X and Y axes for devices that need to scale to a different
coordinate system than reported to the X server. This feature is required
for devices that need to scale to a different coordinate system than
originally reported by the kernel (e.g. touchscreens). The scaling to the
custom coordinate system is done in-driver and the X server is unaware of
the transformation. Property: "Evdev Axis Calibration".
.TP 7
.BI "Option \*qSwapAxes\*q \*q" Bool \*q
Swap x/y axes. Default: off. Property: "Evdev Axes Swap".
.TP 7
@@ -164,9 +191,7 @@ driver.
.TP 7
.BI "Evdev Axis Calibration"
4 32-bit values, order min-x, max-x, min-y, max-y or 0 values to disable
run-time axis calibration. This feature is required for devices that need to
scale to a different coordinate system than originally reported to the X
server, such as touchscreens that require run-time calibration.
in-driver axis calibration.
.TP 7
.BI "Evdev Axis Inversion"
2 boolean values (8 bit, 0 or 1), order X, Y. 1 inverts the axis.

View File

@@ -147,18 +147,18 @@ EvdevDragLockPreInit(InputInfoPtr pInfo)
}
}
/* Updates DragLock button state and firest button event messges */
/* Updates DragLock button state and fires button event messges */
void
EvdevDragLockLockButton(InputInfoPtr pInfo, unsigned int button)
{
EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
BOOL state=0;
BOOL state = 0;
/* update button state */
state = pEvdev->dragLock.lock_state[button - 1] ? FALSE : TRUE;
pEvdev->dragLock.lock_state[button - 1] = state;
xf86PostButtonEvent(pInfo->dev, 0, button, state, 0, 0);
EvdevQueueButtonEvent(pInfo, button, state);
}
/* Filter button presses looking for either a meta button or the
@@ -256,7 +256,7 @@ EvdevDragLockSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
pEvdev->dragLock.meta = meta;
memset(pEvdev->dragLock.lock_pair, 0, sizeof(pEvdev->dragLock.lock_pair));
}
} else
} else if ((val->size % 2) == 0)
{
CARD8* vals = (CARD8*)val->data;
@@ -269,10 +269,11 @@ EvdevDragLockSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
pEvdev->dragLock.meta = 0;
memset(pEvdev->dragLock.lock_pair, 0, sizeof(pEvdev->dragLock.lock_pair));
for (i = 0; i < val->size && i < EVDEV_MAXBUTTONS; i++)
pEvdev->dragLock.lock_pair[i] = vals[i];
for (i = 0; i < val->size && i < EVDEV_MAXBUTTONS; i += 2)
pEvdev->dragLock.lock_pair[vals[i] - 1] = vals[i + 1];
}
}
} else
return BadMatch;
}
return Success;

View File

@@ -198,7 +198,7 @@ EvdevMBEmuTimer(InputInfoPtr pInfo)
pEvdev->emulateMB.pending = FALSE;
if ((id = stateTab[pEvdev->emulateMB.state][4][0]) != 0) {
xf86PostButtonEvent(pInfo->dev, 0, abs(id), (id >= 0), 0, 0);
EvdevPostButtonEvent(pInfo, abs(id), (id >= 0));
pEvdev->emulateMB.state =
stateTab[pEvdev->emulateMB.state][4][2];
} else {
@@ -248,12 +248,12 @@ EvdevMBEmuFilterEvent(InputInfoPtr pInfo, int button, BOOL press)
if ((id = stateTab[pEvdev->emulateMB.state][*btstate][0]) != 0)
{
xf86PostButtonEvent(pInfo->dev, 0, abs(id), (id >= 0), 0, 0);
EvdevQueueButtonEvent(pInfo, abs(id), (id >= 0));
ret = TRUE;
}
if ((id = stateTab[pEvdev->emulateMB.state][*btstate][1]) != 0)
{
xf86PostButtonEvent(pInfo->dev, 0, abs(id), (id >= 0), 0, 0);
EvdevQueueButtonEvent(pInfo, abs(id), (id >= 0));
ret = TRUE;
}

View File

@@ -54,7 +54,7 @@ static Atom prop_wheel_button = 0;
/* Local Funciton Prototypes */
static BOOL EvdevWheelEmuHandleButtonMap(InputInfoPtr pInfo, WheelAxisPtr pAxis, char *axis_name);
static void EvdevWheelEmuInertia(InputInfoPtr pInfo, WheelAxisPtr axis, int value);
static int EvdevWheelEmuInertia(InputInfoPtr pInfo, WheelAxisPtr axis, int value);
/* Filter mouse button events */
BOOL
@@ -82,8 +82,7 @@ EvdevWheelEmuFilterButton(InputInfoPtr pInfo, unsigned int button, int value)
* If the button is released early enough emit the button
* press/release events
*/
xf86PostButtonEvent(pInfo->dev, 0, button, 1, 0, 0);
xf86PostButtonEvent(pInfo->dev, 0, button, 0, 0, 0);
EvdevQueueButtonClicks(pInfo, button, 1);
}
}
@@ -99,38 +98,51 @@ BOOL
EvdevWheelEmuFilterMotion(InputInfoPtr pInfo, struct input_event *pEv)
{
EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
WheelAxisPtr pAxis = NULL;
WheelAxisPtr pAxis = NULL, pOtherAxis = NULL;
int value = pEv->value;
int ms;
/* Has wheel emulation been configured to be enabled? */
if (!pEvdev->emulateWheel.enabled)
return FALSE;
/* Handle our motion events if the emuWheel button is pressed*/
if (pEvdev->emulateWheel.button_state) {
/* Handle our motion events if the emuWheel button is pressed
* wheel button of 0 means always emulate wheel.
*/
if (pEvdev->emulateWheel.button_state || !pEvdev->emulateWheel.button) {
/* Just return if the timeout hasn't expired yet */
ms = pEvdev->emulateWheel.expires - GetTimeInMillis();
if (ms > 0)
return TRUE;
if (pEvdev->emulateWheel.button)
{
int ms = pEvdev->emulateWheel.expires - GetTimeInMillis();
if (ms > 0)
return TRUE;
}
/* We don't want to intercept real mouse wheel events */
switch(pEv->code) {
case REL_X:
pAxis = &(pEvdev->emulateWheel.X);
pOtherAxis = &(pEvdev->emulateWheel.Y);
break;
case REL_Y:
pAxis = &(pEvdev->emulateWheel.Y);
pOtherAxis = &(pEvdev->emulateWheel.X);
break;
default:
break;
}
/* If we found REL_X or REL_Y, emulate a mouse wheel */
/* If we found REL_X or REL_Y, emulate a mouse wheel.
Reset the inertia of the other axis when a scroll event was sent
to avoid the buildup of erroneous scroll events if the user
doesn't move in a perfectly straight line.
*/
if (pAxis)
EvdevWheelEmuInertia(pInfo, pAxis, value);
{
if (EvdevWheelEmuInertia(pInfo, pAxis, value))
pOtherAxis->traveled_distance = 0;
}
/* Eat motion events while emulateWheel button pressed. */
return TRUE;
@@ -139,17 +151,20 @@ EvdevWheelEmuFilterMotion(InputInfoPtr pInfo, struct input_event *pEv)
return FALSE;
}
/* Simulate inertia for our emulated mouse wheel */
static void
/* Simulate inertia for our emulated mouse wheel.
Returns the number of wheel events generated.
*/
static int
EvdevWheelEmuInertia(InputInfoPtr pInfo, WheelAxisPtr axis, int value)
{
EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
int button;
int inertia;
int rc = 0;
/* if this axis has not been configured, just eat the motion */
if (!axis->up_button)
return;
return rc;
axis->traveled_distance += value;
@@ -163,11 +178,11 @@ EvdevWheelEmuInertia(InputInfoPtr pInfo, WheelAxisPtr axis, int value)
/* Produce button press events for wheel motion */
while(abs(axis->traveled_distance) > pEvdev->emulateWheel.inertia) {
axis->traveled_distance -= inertia;
xf86PostButtonEvent(pInfo->dev, 0, button, 1, 0, 0);
xf86PostButtonEvent(pInfo->dev, 0, button, 0, 0, 0);
EvdevQueueButtonClicks(pInfo, button, 1);
rc++;
}
return rc;
}
/* Handle button mapping here to avoid code duplication,
@@ -201,8 +216,8 @@ EvdevWheelEmuHandleButtonMap(InputInfoPtr pInfo, WheelAxisPtr pAxis, char* axis_
pAxis->down_button = down_button;
/* Update the number of buttons if needed */
if (up_button > pEvdev->buttons) pEvdev->buttons = up_button;
if (down_button > pEvdev->buttons) pEvdev->buttons = down_button;
if (up_button > pEvdev->num_buttons) pEvdev->num_buttons = up_button;
if (down_button > pEvdev->num_buttons) pEvdev->num_buttons = down_button;
} else {
xf86Msg(X_WARNING, "%s: Invalid %s value:\"%s\"\n",
@@ -285,8 +300,8 @@ EvdevWheelEmuPreInit(InputInfoPtr pInfo)
/* Simpler to check just the largest value in this case */
/* XXX: we should post this to the server */
if (5 > pEvdev->buttons)
pEvdev->buttons = 5;
if (5 > pEvdev->num_buttons)
pEvdev->num_buttons = 5;
/* Display default Configuration */
xf86Msg(X_CONFIG, "%s: YAxisMapping: buttons %d and %d\n",

File diff suppressed because it is too large Load Diff

View File

@@ -25,6 +25,7 @@
* Kristian Høgsberg (krh@redhat.com)
* Adam Jackson (ajax@redhat.com)
* Peter Hutterer (peter@cs.unisa.edu.au)
* Oliver McFadden (oliver.mcfadden@nokia.com)
*/
#ifndef EVDEV_H
@@ -54,6 +55,7 @@
#endif
#define EVDEV_MAXBUTTONS 32
#define EVDEV_MAXQUEUE 32
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 3
#define HAVE_PROPERTIES 1
@@ -87,6 +89,16 @@ typedef struct {
int traveled_distance;
} WheelAxis, *WheelAxisPtr;
/* Event queue used to defer keyboard/button events until EV_SYN time. */
typedef struct {
enum {
EV_QUEUE_KEY, /* xf86PostKeyboardEvent() */
EV_QUEUE_BTN, /* xf86PostButtonEvent() */
} type;
int key; /* May be either a key code or button number. */
int val; /* State of the key/button; pressed or released. */
} EventQueueRec, *EventQueuePtr;
typedef struct {
const char *device;
int grabDevice; /* grab the event device? */
@@ -98,11 +110,14 @@ typedef struct {
int flags;
int tool;
int buttons; /* number of buttons */
int num_buttons; /* number of buttons */
BOOL swap_axes;
BOOL invert_x;
BOOL invert_y;
int delta[REL_CNT];
unsigned int abs, rel;
/* XKB stuff has to be per-device rather than per-driver */
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 5
XkbComponentNamesRec xkbnames;
@@ -159,8 +174,21 @@ typedef struct {
/* minor/major number */
dev_t min_maj;
/* Event queue used to defer keyboard/button events until EV_SYN time. */
int num_queue;
EventQueueRec queue[EVDEV_MAXQUEUE];
} EvdevRec, *EvdevPtr;
/* Event posting functions */
void EvdevQueueKbdEvent(InputInfoPtr pInfo, struct input_event *ev, int value);
void EvdevQueueButtonEvent(InputInfoPtr pInfo, int button, int value);
void EvdevPostButtonEvent(InputInfoPtr pInfo, int button, int value);
void EvdevQueueButtonClicks(InputInfoPtr pInfo, int button, int count);
void EvdevPostRelativeMotionEvents(InputInfoPtr pInfo, int *num_v, int *first_v,
int v[MAX_VALUATORS]);
void EvdevPostAbsoluteMotionEvents(InputInfoPtr pInfo, int *num_v, int *first_v,
int v[MAX_VALUATORS]);
unsigned int EvdevUtilButtonEventToButtonNumber(EvdevPtr pEvdev, int code);
/* Middle Button emulation */

View File

@@ -1,39 +0,0 @@
# Copyright 2008 Red Hat, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# on the rights to use, copy, modify, merge, publish, distribute, sub
# license, and/or sell copies of the Software, and to permit persons to whom
# the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice (including the next
# paragraph) shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
AM_CFLAGS = $(XORG_CFLAGS)
noinst_PROGRAMS=fakedev btn0 absrel abs dummy
fakedev_SOURCES=fakedev.c fakedev.h
fakedev_LDFLAGS=$(DLOPEN_LIBS) -rdynamic
LFLAGS=-shared -fPIC
btn0_SOURCES=btn0.c
btn0_LDFLAGS=$(LFLAGS)
absrel_SOURCES=absrel.c
absrel_LDFLAGS=$(LFLAGS)
abs_SOURCES=abs.c
abs_LDFLAGS=$(LFLAGS)
dummy_SOURCES=dummy.c
dummy_LDFLAGS=$(LFLAGS)

View File

@@ -1,84 +0,0 @@
/*
* Copyright © 2008 Red Hat, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the name of Red Hat
* not be used in advertising or publicity pertaining to distribution
* of the software without specific, written prior permission. Red
* Hat makes no representations about the suitability of this software
* for any purpose. It is provided "as is" without express or implied
* warranty.
*
* THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
* NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Authors:
* Peter Hutterer (peter.hutterer@redhat.com)
*/
/* creates a device with ABS_X, ABS_Y, BTN_LEFT, BTN_MIDDLE, BTN_RIGHT. */
#include <stdio.h>
#include <unistd.h>
#include <linux/input.h>
#include <linux/uinput.h>
#include "fakedev.h"
int abs_setup(struct uinput_user_dev* dev, int fd)
{
if (ioctl(fd, UI_SET_EVBIT, EV_ABS) == -1) goto error;
if (ioctl(fd, UI_SET_EVBIT, EV_SYN) == -1) goto error;
/* buttons */
if (ioctl(fd, UI_SET_KEYBIT, BTN_LEFT) == -1) goto error;
if (ioctl(fd, UI_SET_KEYBIT, BTN_MIDDLE) == -1) goto error;
if (ioctl(fd, UI_SET_KEYBIT, BTN_RIGHT) == -1) goto error;
/* axes */
if (ioctl(fd, UI_SET_ABSBIT, ABS_X) == -1) goto error;
if (ioctl(fd, UI_SET_ABSBIT, ABS_Y) == -1) goto error;
dev->absmin[ABS_X] = 0;
dev->absmax[ABS_X] = 120;
dev->absmin[ABS_Y] = 0;
dev->absmax[ABS_Y] = 120;
return 0;
error:
perror("ioctl failed.");
return -1;
}
int abs_run(int fd)
{
absmove(fd, 100, 100);
sleep(1);
absmove(fd, 120, 120);
sleep(1);
return 0;
}
struct test_device abs_dev = {
.name = "Abs test device",
.setup = abs_setup,
.run = abs_run,
};
struct test_device* get_device()
{
return &abs_dev;
}

View File

@@ -1,91 +0,0 @@
/*
* Copyright © 2008 Red Hat, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the name of Red Hat
* not be used in advertising or publicity pertaining to distribution
* of the software without specific, written prior permission. Red
* Hat makes no representations about the suitability of this software
* for any purpose. It is provided "as is" without express or implied
* warranty.
*
* THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
* NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Authors:
* Peter Hutterer (peter.hutterer@redhat.com)
*/
/* creates a device with ABS_X, ABS_Y, REL_X, REL_Y, BTN_LEFT, BTN_MIDDLE,
BTN_RIGHT. */
#include <stdio.h>
#include <unistd.h>
#include <linux/input.h>
#include <linux/uinput.h>
#include "fakedev.h"
int absrel_setup(struct uinput_user_dev* dev, int fd)
{
if (ioctl(fd, UI_SET_EVBIT, EV_REL) == -1) goto error;
if (ioctl(fd, UI_SET_EVBIT, EV_ABS) == -1) goto error;
if (ioctl(fd, UI_SET_EVBIT, EV_SYN) == -1) goto error;
/* buttons */
if (ioctl(fd, UI_SET_KEYBIT, BTN_LEFT) == -1) goto error;
if (ioctl(fd, UI_SET_KEYBIT, BTN_MIDDLE) == -1) goto error;
if (ioctl(fd, UI_SET_KEYBIT, BTN_RIGHT) == -1) goto error;
/* axes */
if (ioctl(fd, UI_SET_RELBIT, REL_X) == -1) goto error;
if (ioctl(fd, UI_SET_RELBIT, REL_Y) == -1) goto error;
if (ioctl(fd, UI_SET_ABSBIT, ABS_X) == -1) goto error;
if (ioctl(fd, UI_SET_ABSBIT, ABS_Y) == -1) goto error;
dev->absmin[ABS_X] = 0;
dev->absmax[ABS_X] = 1000;
dev->absmin[ABS_Y] = 0;
dev->absmax[ABS_Y] = 1000;
return 0;
error:
perror("ioctl failed.");
return -1;
}
int absrel_run(int fd)
{
absmove(fd, 100, 100);
sleep(1);
absmove(fd, 120, 120);
sleep(1);
move(fd, 10, 10);
return 0;
}
struct test_device absrel_dev = {
.name = "Abs/Rel test device",
.setup = absrel_setup,
.run = absrel_run,
};
struct test_device* get_device()
{
return &absrel_dev;
}

View File

@@ -1,87 +0,0 @@
/*
* Copyright © 2008 Red Hat, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the name of Red Hat
* not be used in advertising or publicity pertaining to distribution
* of the software without specific, written prior permission. Red
* Hat makes no representations about the suitability of this software
* for any purpose. It is provided "as is" without express or implied
* warranty.
*
* THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
* NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Authors:
* Peter Hutterer (peter.hutterer@redhat.com)
*/
/* Creates a device that has REL_X REL_Y BTN_0 BTN_1 BTN_2
*
* Moves the device around in a 10px square and clicks after each completed
* circle.
*/
#include <stdio.h>
#include <unistd.h>
#include <linux/input.h>
#include <linux/uinput.h>
#include "fakedev.h"
int btn0_setup(struct uinput_user_dev *dev, int fd)
{
if (ioctl(fd, UI_SET_EVBIT, EV_KEY) == -1) goto error;
if (ioctl(fd, UI_SET_EVBIT, EV_REL) == -1) goto error;
if (ioctl(fd, UI_SET_EVBIT, EV_SYN) == -1) goto error;
/* buttons */
if (ioctl(fd, UI_SET_KEYBIT, BTN_0) == -1) goto error;
if (ioctl(fd, UI_SET_KEYBIT, BTN_1) == -1) goto error;
if (ioctl(fd, UI_SET_KEYBIT, BTN_2) == -1) goto error;
/* axes */
if (ioctl(fd, UI_SET_RELBIT, REL_X) == -1) goto error;
if (ioctl(fd, UI_SET_RELBIT, REL_Y) == -1) goto error;
return 0;
error:
perror("ioctl failed.");
return -1;
}
int btn0_run(int fd)
{
move(fd, -10, 0);
usleep(1000);
move(fd, 0, -10);
usleep(1000);
move(fd, 10, 0);
usleep(1000);
move(fd, 0, 10);
usleep(1000);
click(fd, BTN_0, 1);
usleep(1000);
click(fd, BTN_0, 0);
return 0;
}
struct test_device btn0_dev = {
.name = "BTN_0 test device",
.setup = btn0_setup,
.run = btn0_run,
};
struct test_device* get_device()
{
return &btn0_dev;
}

View File

@@ -1,77 +0,0 @@
/*
* Copyright © 2008 Red Hat, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the name of Red Hat
* not be used in advertising or publicity pertaining to distribution
* of the software without specific, written prior permission. Red
* Hat makes no representations about the suitability of this software
* for any purpose. It is provided "as is" without express or implied
* warranty.
*
* THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
* NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Authors:
* Peter Hutterer (peter.hutterer@redhat.com)
*/
/* dummy device, looks like a mouse but doesn't do anything.
* Good for filling up the device list.
*
*/
#include <stdio.h>
#include <unistd.h>
#include <linux/input.h>
#include <linux/uinput.h>
#include "fakedev.h"
int dummy_setup(struct uinput_user_dev *dev, int fd)
{
if (ioctl(fd, UI_SET_EVBIT, EV_KEY) == -1) goto error;
if (ioctl(fd, UI_SET_EVBIT, EV_REL) == -1) goto error;
if (ioctl(fd, UI_SET_EVBIT, EV_SYN) == -1) goto error;
/* buttons */
if (ioctl(fd, UI_SET_KEYBIT, BTN_LEFT) == -1) goto error;
if (ioctl(fd, UI_SET_KEYBIT, BTN_MIDDLE) == -1) goto error;
if (ioctl(fd, UI_SET_KEYBIT, BTN_RIGHT) == -1) goto error;
/* axes */
if (ioctl(fd, UI_SET_RELBIT, REL_X) == -1) goto error;
if (ioctl(fd, UI_SET_RELBIT, REL_Y) == -1) goto error;
return 0;
error:
perror("ioctl failed.");
return -1;
}
int dummy_run(int fd)
{
usleep(1000);
return 0;
}
struct test_device dummy_dev = {
.name = "dummy_ test device",
.setup = dummy_setup,
.run = dummy_run,
};
struct test_device* get_device()
{
return &dummy_dev;
}

View File

@@ -1,199 +0,0 @@
/*
* Copyright © 2008 Red Hat, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the name of Red Hat
* not be used in advertising or publicity pertaining to distribution
* of the software without specific, written prior permission. Red
* Hat makes no representations about the suitability of this software
* for any purpose. It is provided "as is" without express or implied
* warranty.
*
* THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
* NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Authors:
* Peter Hutterer (peter.hutterer@redhat.com)
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
#include <linux/input.h>
#include <linux/uinput.h>
#include <dlfcn.h>
#include "fakedev.h"
/* "public interfaces" */
void send_event(int fd, int type, int code, int value)
{
struct input_event event;
event.type = type;
event.code = code;
event.value = value;
gettimeofday(&event.time, NULL);
if (write(fd, &event, sizeof(event)) < sizeof(event))
perror("Send event failed.");
}
void move(int fd, int x, int y)
{
if (!x && !y)
return;
send_event(fd, EV_REL, REL_X, x);
send_event(fd, EV_REL, REL_Y, y);
send_event(fd, EV_SYN, SYN_REPORT, 0);
}
void absmove(int fd, int x, int y)
{
send_event(fd, EV_ABS, ABS_X, x);
send_event(fd, EV_ABS, ABS_Y, y);
send_event(fd, EV_SYN, SYN_REPORT, 0);
}
void click(int fd, int btn, int down)
{
send_event(fd, EV_KEY, btn, down);
send_event(fd, EV_SYN, SYN_REPORT, 0);
}
/* end public interfaces */
static int fd = -1;
static int stop = 0;
static void sighandler(int signum)
{
printf("Stopping.\n");
stop = 1;
}
static void init_signal(void)
{
struct sigaction action;
sigset_t mask;
sigfillset(&mask);
action.sa_handler = sighandler;
action.sa_mask = mask;
action.sa_flags = 0;
sigaction(SIGTERM, &action, NULL);
sigaction(SIGINT, &action, NULL);
sigprocmask(SIG_UNBLOCK, &mask, 0);
}
static int init_uinput(struct test_device* test_dev)
{
struct uinput_user_dev dev;
fd = open("/dev/input/uinput", O_RDWR);
if (fd < 0)
goto error;
memset(&dev, 0, sizeof(dev));
strcpy(dev.name, test_dev->name);
dev.id.bustype = 0;
dev.id.vendor = 0x1F;
dev.id.product = 0x1F;
dev.id.version = 0;
test_dev->setup(&dev, fd);
if (write(fd, &dev, sizeof(dev)) < sizeof(dev))
goto error;
if (ioctl(fd, UI_DEV_CREATE, NULL) == -1) goto error;
return 0;
error:
fprintf(stderr, "Error: %s\n", strerror(errno));
if (fd != -1)
close(fd);
return -1;
}
static void cleanup_uinput(void)
{
if (fd == -1)
return;
ioctl(fd, UI_DEV_DESTROY, NULL);
close(fd);
fd = -1;
}
int main (int argc, char **argv)
{
struct test_device *dev;
void *dlhandle = NULL;
struct test_device* (*get_device)(void);
if (argc <= 1)
{
fprintf(stderr, "Usage: %s test_dev\n", argv[0]);
return -1;
}
printf("Loading %s.\n", argv[1]);
dlhandle = dlopen(argv[1], RTLD_NOW | RTLD_GLOBAL);
if (!dlhandle)
{
fprintf(stderr, "Error: %s\n", dlerror());
return -1;
}
*(void**)(&get_device) = dlsym(dlhandle, "get_device");
if (!get_device)
{
fprintf(stderr, "Error getting the symbol: %s.\n", dlerror());
return -1;
}
dev = (*get_device)();
if (init_uinput(dev) < 0) {
fprintf(stderr, "Failed to initialize /dev/uinput. Exiting.\n");
return -1;
}
init_signal();
printf("Device created. Press CTRL+C to terminate.\n");
while (!stop) {
if (dev->run(fd))
break;
}
cleanup_uinput();
return 0;
}

View File

@@ -1,51 +0,0 @@
/*
* Copyright © 2008 Red Hat, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the name of Red Hat
* not be used in advertising or publicity pertaining to distribution
* of the software without specific, written prior permission. Red
* Hat makes no representations about the suitability of this software
* for any purpose. It is provided "as is" without express or implied
* warranty.
*
* THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
* NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Authors:
* Peter Hutterer (peter.hutterer@redhat.com)
*/
#ifndef _EVDEV_TEST_H
#define _EVDEV_TEST_H
#include <linux/uinput.h>
struct test_device {
char *name; /* device name */
/**
* Called to setup the device. Call ioctls to set your EVBITs, KEYBITs,
* etc. here. Return 0 on success or non-zero to exit.
*/
int (*setup)(struct uinput_user_dev* dev, int fd);
/**
* Called during each run of the main loop. Generate events by calling
* move(), click(), etc.
* Return 0 on success, or non-zero to stop the main loop.
*/
int (*run)(int fd);
};
extern void move (int fd, int x, int y);
extern void absmove (int fd, int x, int y);
extern void click (int fd, int btn, int down);
#endif