Commit Graph

55 Commits

Author SHA1 Message Date
Carlos Garnacho
4c4e72a9dc x11: Set the input device stage on XI_TouchBegin, if not already set
Until now, touch events sort of rely on XI_Enter/XI_Leave events accompanying
the pointer emulating touch in order to have a stage set on the device, These
events won't happen though if it's not a pointer emulating touch which happens
on the stage, causing touch events to be ignored.

Fix this by ensuring that the input device has a stage on XI_TouchBegin itself,
but only if it's not already set, so we don't possibly steal touch events to
an already interacting stage.

https://bugzilla.gnome.org/show_bug.cgi?id=732234
2014-06-25 16:55:16 +01:00
Gustavo Noronha Silva
fcdd222c61 device-manager-xi2: use allocation for clamping
The coordinates translated by the XI2 device manager were being clamped using
the X window size kept by StageX11. However, when the stage is fullscreen,
that size is not updated to the screen size, but kept the same in order to
allow going back to it when the stage goes out of fullscreen.

https://bugzilla.gnome.org/show_bug.cgi?id=731268
2014-06-05 15:03:10 -03:00
Adel Gadllah
4a3ad9c3af DeviceManagerXi2: Cache the client pointer
Currently clutter_device_manager_xi2_get_core_device always
does a round trip to query the client.

So avoid that by caching the client pointer and only update it when the
xi devices change.

https://bugzilla.gnome.org/show_bug.cgi?id=725561
2014-03-03 15:06:11 +01:00
Carlos Garnacho
488639eb63 x11: Avoid invalid ClutterInputDevice pointers in the device list
Due to the way add_device() invariably adds to the master/slave device
lists, while keeping ClutterInputDevices 1:1 with device IDs, it may
leave invalid pointers in the list if add_device() is called multiple
times for the same device ID. There are two situations where this may
happen:

1) If devices are disabled and later enabled: devices are added invariably
   to the master/slave lists on constructed(), but then on XIDeviceEnabled
   they'd get added yet again.
2) Racy cases where the ClutterDeviceManager is created around the same time
   XIHierarchyEvents are sent. When getting the XIDeviceInfo on constructed(),
   these devices may already appear as enabled, even though XIDeviceEnabled
   is seen through XIHierarchyEvents processed in the event loop sortly after.

   This last case can be seen when starting gnome-shell on a different tty,
   and entering in the one it's been spawned on, clutter initialization
   happens around the same time devices are added back because of the tty
   switch, and multiple extra ClutterInputDevices are created.

https://bugzilla.gnome.org/show_bug.cgi?id=724971
2014-02-25 10:18:20 +01:00
Rui Matos
ce1f8f1dd0 device-manager-xi2: Fix device instances leaking on removal
Don't add an extra reference when adding to the devices hash table. We
already own the initial reference.

https://bugzilla.gnome.org/show_bug.cgi?id=712812
2013-11-21 19:34:14 +01:00
Jasper St. Pierre
98e03fc03f device-manager-xi2: Clamp coordinates of events to the stage coordinates
The X server can sometimes send us coordinates in the negatives or above
our window in extreme cases. Ensure that the user never sees this.
2013-11-14 18:34:40 +00:00
Jasper St. Pierre
1de024b5fa device-manager-xi2: Don't divide by the scale factor twice
The coordinates we pass into translate_axes are already scaled.
2013-11-14 18:34:40 +00:00
Emmanuele Bassi
300c76df17 x11: Ensure we have a stage before accessing its fields
For some XI2 we do not have a Stage associated to the event window.

Original patch by: Giovanni Campagna <scampa.giovanni@gmail.com>
Signed-off-by: Emmanuele Bassi <ebassi@gnome.org>

https://bugzilla.gnome.org/show_bug.cgi?id=708439
2013-09-20 10:56:57 +01:00
Emmanuele Bassi
75f81fee70 x11: Apply the window scaling factor
On high DPI density displays we create surfaces with a size scaled up by
a certain factor. Even if the contents stay at the same relative size
and position, we need to compensate the scaling both when changing the
surface size, and when dealing with input.

https://bugzilla.gnome.org/show_bug.cgi?id=705915
2013-09-19 22:51:52 +01:00
Giovanni Campagna
59f1e531f9 ClutterEvent: add API to query the full keyboard state when the event was generated
When talking to other applications or serializing the modifier
state (and in particular when implementing a wayland compositor),
the effective modifier state alone is not sufficient, one needs
to know the base, latched and locked modifiers.

Previously one could do with backend specific functionality
such as clutter_device_manager_evdev_get_xkb_state(), but the
problem is that the internal data structures are updated as
soon as the events are fetched from the upstream source, but
the events are reported to the application some time later,
and thus the two can get out of sync.
This way, on the other hand, the information is cached in the
event, and provided to the application with the value that
was current when the event was generated.

https://bugzilla.gnome.org/show_bug.cgi?id=706494
2013-09-09 13:18:23 +02:00
Jasper St. Pierre
e62cf4745f device-manager: Select for events on XIAllMasterDevices
This removes a bit of work that we have to do for every device, and makes it
easy for mutter to patch out parts of the event mask it doesn't want.

https://bugzilla.gnome.org/show_bug.cgi?id=703969
2013-07-11 14:09:43 -04:00
Matthias Clasen
d343cc6289 x11: trap errors when calling XIQueryDevice
Devices can disappear at any time, causing XIQueryDevice
to throw an error. At the same time, plug a memory leak.

https://bugzilla.gnome.org/show_bug.cgi?id=701974
2013-06-10 21:45:47 -04:00
Sebastian Keller
9dbc01b61f xi2: Reset scroll info for correct device on device change 2013-03-12 17:09:29 -04:00
Rui Matos
40ef7a5f6e x11/xi2: Factor the XKB group state in to fill events' modifier_state
Otherwise XkbTranslateKeyCode() won't yeld the correct keysyms when
group > 1.

https://bugzilla.gnome.org/show_bug.cgi?id=695260
2013-03-06 13:36:09 +01:00
Rui Matos
c0469601c7 x11/device-manager-xi2: Fix slave to master association
A slave is associated to a master device, not the other way around.

https://bugzilla.gnome.org/show_bug.cgi?id=692971
2013-02-01 10:13:01 +01:00
Yanko Kaneti
069abd1122 xi2: Fix access beyond array boundaries 2013-02-01 06:17:36 +02:00
Jasper St. Pierre
4691878a76 x11: Ignore num lock / scroll lock for event state
As x11 considers num lock and scroll lock to be modifiers, code that
checks for an exact modifier combination will fail if naively done when
num lock or scroll lock are turned on. Applications that want to ignore
these modifiers will need to use XKB to manually mask out the modifier
state.

As it is very unlikely that applications will want to care about the
state of num lock or scroll lock for key press/key release events, mask
out the num lock and scroll lock keys automatically.

https://bugzilla.gnome.org/show_bug.cgi?id=690664
2013-01-14 12:56:07 -05:00
Jasper St. Pierre
9614dff158 xi2: Reset the correct scroll axes on DeviceChanged
Otherwise, we'll have incorrect scrolling when we switch hardware
devices without switching virtual devices. For example, on a ThinkPad,
scroll using the touchpad, move the eraser mouse, and then scroll again:
the deltas will be wrong. This also matches what GTK+ does.

https://bugzilla.gnome.org/show_bug.cgi?id=689258
2012-11-29 16:50:54 -05:00
Emanuele Aina
35faaf604c x11: set the stage for core events with no associated stage
When the last touch has been released the stage on the
corresponding master device (eg. the virtual core pointer) is set
to NULL and no mouse events can be delivered until an ENTER event
has occurred and the stage pointer restored.

This is due to the fact that the master devices can send both
touch events and mouse events, forwarding events coming from the
attached slave devices.

To restore delivery of mouse events we need to ensure that the
stage is set on each ButtonPress, ButtonRelease and Motion event
coming from master devices.

https://bugzilla.gnome.org/show_bug.cgi?id=684509
2012-09-24 17:08:24 +01:00
Emanuele Aina
a6abf86e94 input-device: print device number in debug messages
https://bugzilla.gnome.org/show_bug.cgi?id=684530
2012-09-24 17:04:08 +01:00
Emmanuele Bassi
950e60f824 x11: Add EventSequence → touch detail accessor
The ClutterEventSequence structure is a fully opaque type; on X11, it is
just an unsigned integer that gets converted into a pointer, but in the
future it may become a fully fledged data structure.

Obviously, we cannot tell people to just dereference the pointer into an
integer in order to use it, and still retain the ability to change the
type; for this reason, we need a proper accessor function to convert the
EventSequence into a touch detail, to be used with the XInput API.
2012-09-05 09:43:47 +01:00
Lionel Landwerlin
d6a0f7eb61 input-device: don't reset a device's stage until all touch points are gone
803b3bafb6 introduced a new issue for
multi touch events.

In the case where 2 touch events for 2 different touch points are
processed in the same iteration, a call to
_clutter_stage_remove_device() when processing the first event will
remove the stage setting of the InputDevice. That means Clutter will
skip the second event, because it can't find a stage to which relate
the event, so no related actor and so no emission.

To fix this we move the _clutter_stage_(add/remove)_device() calls
into the input device. This way the input device can find out exactly
when to call these functions (i.e. when no touch point were previously
active or when no touch point remain active).

https://bugzilla.gnome.org/show_bug.cgi?id=682362
2012-09-03 21:50:24 +01:00
Tomeu Vizoso
d5332d1e4c stage: Remove tracking input devices, it's not used
https://bugzilla.gnome.org/show_bug.cgi?id=683126
2012-09-03 21:50:19 +01:00
Emmanuele Bassi
b2b22dbe6c x11/device-manager-xi2: Put XIPointerEmulated under conditionals
There are a couple of debugging messages using XInput 2.2 symbols
unconditionally, and it breaks builds on older systems.

https://bugzilla.gnome.org/show_bug.cgi?id=683219
2012-09-02 22:48:52 +01:00
Emmanuele Bassi
31b8b2e22f x11: Add debug notes for pointer-emulated 2012-07-18 17:14:17 -04:00
Emmanuele Bassi
2a31a93c5e x11/xi2: Do not generate scroll events on ButtonRelease
Scroll events are generated on ButtonPress only in the core event
handling, so it should happen the same if we use XInput.

https://bugzilla.gnome.org/show_bug.cgi?id=680088
2012-07-17 10:13:12 -04:00
Matthias Clasen
e3ca87784e XI2: Avoid a crash in event translation
It is possible that we get a DeviceChanged event for a device
that is not in the hash table yet. E.g. I've seen this when
using xrandr to change screen resolution. Prevent a crash in
this case.

https://bugzilla.gnome.org/review?bug=678439
2012-06-20 07:22:12 -04:00
Bastien Nocera
2bb84d9169 x11/device-manager-xi2: Fix assertions with touch
When getting touch events, the device manager would try
to pass an invalid device to translate_axes().

clutter_event_set_device() will only update event->touch.device
for touch events, not event->motion.device, as used.

Fixes Totem crashing on mouse motion/button press when using
a touchpad.

https://bugzilla.gnome.org/show_bug.cgi?id=675371
2012-05-03 19:32:07 +02:00
Cosimo Cecchi
032870dccc device-manager: select/unselect device events as device change
When a device is added or changes, select/unselect events from X
accordingly.

https://bugzilla.gnome.org/show_bug.cgi?id=673644
2012-04-24 18:49:42 -04:00
Cosimo Cecchi
d61515322a x11/device-manager-xi2: Flip deltas around
Up/down is Y.
2012-04-20 18:33:16 +01:00
Peter Hutterer
a66fbd258e Rename XINPUT_2_2 define to HAVE_XINPUT_2_2
configure.ac defines XINPUT_2_2 if XI 2.2 support was found. The code
expects XINPUT_2_2 in the device manager, but HAVE_XINPUT_2_2 in the x11
backend.

On newer X servers, the latter causes a BadValue when XIQueryDevice sends a
different major/minor than gdk's device manager (gnome-control-center).

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>

https://bugzilla.gnome.org/show_bug.cgi?id=673961
2012-04-12 11:31:29 +01:00
Emmanuele Bassi
f6da5ea616 x11/device-manager-xi2: Add 'Abs Distance' axis
In XInput 2, the proximity events of XInput 1 have been replaced by an
axis on a valuator class. This means that, on devices that support
proximity information, for instance pens of a tablet, you will start
receiving events with the distance as an axis value - similarly to how
the pressure and tilt are presented in the API.
2012-04-10 09:32:00 +01:00
Emmanuele Bassi
86a5213473 x11/device-manager-xi2: Remove heuristics for touchscreen devices
Devices that have touch valuator classes will be touchscreens or
touchpads; anything else should be ignored.
2012-04-07 23:07:59 +01:00
Emmanuele Bassi
09a317d23d x11: Add support for touch events
For the time being, we just relay everything we get from the X server to
the Clutter application.
2012-03-19 14:29:24 +00:00
Emmanuele Bassi
1c500f7de9 x11: Reset scroll valuators
We need to clear up the state on enter and leave, as well as when the X
server tells us that the device has changed.
2012-03-19 14:29:23 +00:00
Emmanuele Bassi
676a317439 x11: Add support for scroll valuators on XInput2.2 2012-03-19 12:41:24 +00:00
Carlos Garnacho
075a4ed86c x11: Improve XGenericEventCookie data allocation
https://bugzilla.gnome.org/show_bug.cgi?id=654656

Clutter may be used together with GTK+, which indirectly may use
XInput2 too, so the cookie data must persist when both are handling
events.

What happens now in a nutshell is, Clutter is only guaranteed to allocate
the cookie itself after XNextEvent(), and only frees the cookie if its
XGetEventData() call allocated the cookie data.

The X[Get|Free]EventData() calls happen now in clutter-event-x11.c as
hypothetically different event translators could also handle other set
of X Generic Events, or other libraries handling events for that matter.
2011-07-15 13:46:33 +02:00
Emmanuele Bassi
d3a7b7502e event: Add setters for ClutterEvent members
Creating a synthetic event requires direct access to the ClutterEvent
union members; this access does not map in bindings to high-level
languages, especially run-time bindings using GObject-Introspection.
It's also midly annoying from C, as it unnecessarily exposes the guts of
ClutterEvent - something we might want to fix in the future.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2575
2011-02-28 14:16:23 +00:00
Emmanuele Bassi
0d17b1463b device-manager/xi2: Silence a compiler warning 2011-02-19 16:48:59 +00:00
Emmanuele Bassi
f99d2336f0 x11: Remove unused variables 2011-02-19 16:47:20 +00:00
Emmanuele Bassi
3e5aa9ed63 Add private header for event-related API 2011-02-18 16:35:36 +00:00
Emmanuele Bassi
82d1e5a6ee Clean up crossing event synthesis code
Clutter should just require that the windowing system used by a backend
adds a device to the stage when the device enters, and removes it from
the stage when the device leaves; with this information, we can
synthesize every crossing event and update the device state without
other intervention from the backend-specific code.

The generation of additional crossing events for actors that are
covering the stage at the coordinates of the crossing event should be
delegated to the event processing code.

The x11 and win32 backends need to be modified to relay the enter and
leave events from the windowing system.
2011-01-28 18:19:49 +00:00
Emmanuele Bassi
5593792a40 Include stdint.h when using uint32_t
Since the XI2 device manager code is going to be compiled only on
POSIX compliant systems, we can safely assume the presence of stdint.h
and include it unconditionally.
2011-01-26 10:32:42 +00:00
Emmanuele Bassi
e46571d639 device-manager/xi2: Sync the stage of source devices
Keep the slave devices in sync with their master, so that we don't
ignore their events because they lack the stage pointer.
2011-01-21 15:26:52 +00:00
Emmanuele Bassi
0e99346915 device-manager/xi2: Fix device hotplugging
Hierarchy and Device changed events come through with the X window set
to be the root window, not the stage window. We need to whitelist them
so that we can actually support hotplugging and device changes.
2011-01-21 11:41:36 +00:00
Emmanuele Bassi
6da51f6ed3 device/x11: Store min/max keycode in the XI device class
The generic device class shouldn't have the minimum and maximum keycode,
since no other input backend provides those.
2011-01-21 10:25:46 +00:00
Emmanuele Bassi
73cf6bd52c device: Allow enabling/disabling non-master devices
Slave and floating devices should always be disabled, and not deliver
events to the scene. It is up to the user to enable non-master devices
and handle events coming from them.

ClutterInputDevice gets a new :enabled property, defaulting to FALSE;
when a device manager creates a new device it has to set it to TRUE if
the :device-mode property is set to CLUTTER_INPUT_MODE_MASTER.

The main event queue entry point, _clutter_event_push(), will
automatically discard events coming from disabled devices.
2011-01-21 10:25:45 +00:00
Emmanuele Bassi
405e611279 device/xi2: Translate the axis data after setting devices
We need the devices (source and virtual) to be set before translating
the axis data from XI2 to the Clutter event.
2011-01-21 10:25:45 +00:00
Emmanuele Bassi
431200f40d device: Add keys and axes accessors
Allow retrieving the number of keys and axes, since we provide the API
to iterate over them both.
2011-01-21 10:25:44 +00:00
Emmanuele Bassi
a3102a777e docs: Fill out documentation for new symbols 2011-01-21 10:25:44 +00:00