Commit graph

133 commits

Author SHA1 Message Date
Jonas Ådahl d2510105a6 input: Make pointer grab motion callbacks take an event struct
Instead of only passing absolute pointer coordinates, effectively
loosing motion event data, pass a struct that can potentially contain
different types of motion events, currently being absolute and relative.

A helper function to get resulting absolute coordinates was added for
when previous callbacks simply used the (x, y) coordinates.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Derek Foreman <derekf@osg.samsung.com>
2015-11-20 11:44:56 +08:00
Jonas Ådahl 0336ca0cc5 input: Pass axis events through pointer grab interfaces
Don't only send motions and buttons but also axis events through the
pointer grab interface.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-By: Derek Foreman <derekf@osg.samsung.com>
2015-11-02 14:30:16 +08:00
Chokshi, Mitul d669714d71 input: add new client to resource_list instead of focus_resource_list
When new client registers touch listener, it was added to focus resource list.
At this point if another client "without" touch listener is in focus then
subsequent touch events are sent to new client with another client's resources
causing new client to stop rendering.
Now new client is added to resource list by default and it'll be added to focus
resource list only if its in focus.

Reviewed-by: Derek Foreman <derekf@osg.samsung.com>
2015-10-09 11:20:41 -05:00
Chris Michael 3f607d3e1c weston-input: Reformat weston_log line to add missing space between words
Signed-off-by: Chris Michael <cp.michael@samsung.com>
Reviewed-by: Derek Foreman <derekf@osg.samsung.com>
2015-10-07 11:34:49 -05:00
Derek Foreman f9318d1452 input: add a weston_pointer_clear_focus() helper function
Valgrind has shown that in at least one place (default_grab_pointer_focus)
we're testing uninitialized values coming out of weston_compositor_pick_view.

This is happening when default_grab_pointer_focus is called when there is
nothing on the view list, and during the first repaint when only the black
surface with no input region exists.

This patch adds a function to clear pointer focus and also set the sx,sy
co-ordinates to a sentinel value we shouldn't compute with.

Assertions are added to make sure any time pointer focus is set to NULL
these values are used.

weston_compositor_pick_view() now returns these values too.

Now the values are always initialized, even when no view exists, and
they're initialized in such a way that actually doing computation
with them should fail in an obvious way, but we can compare them
safely for equality.

Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2015-08-06 16:28:30 +01:00
Giulio Camuffo 61ed7b6bf0 input: pass the global touch coordinates to the touch grab
This makes it consistent with the pointer grab, which also gets
global coordinates and not surface relative ones, and allows to
easily filter out gestures based on compositor global hotspots.

Reviewed-by: Daniel Stone <daniels@collabora.com>
2015-08-06 16:21:01 +01:00
Derek Foreman 1281a36e3b input: Don't test keyboard/pointer/touch pointers
Keyboards and pointers aren't freed when devices are removed, so we should
really be testing keyboard_device_count and pointer_device_count in most
cases, not the actual pointers. Otherwise we end up with different
behaviour after removing a device than we had before it was inserted.

This commit renames the touch/keyboard/pointer pointers and adds helper
functions to get them that hide this complexity and return NULL when
*_device_count is 0.

Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
2015-07-31 15:16:09 -07:00
Derek Foreman 30ce607682 input: Check device counts in bind_seat()
We shouldn't be using seat->pointer|keyboard|touch here, we should be
testing *_device_count to see if a device is currently present.

Testing the pointers directly will result in incorrectly advertising
capabilities after all devices of a type have been removed.

Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
2015-07-31 15:15:46 -07:00
Derek Foreman 99a6a2db4c bindings: Make run binding functions take apropriate device instead of a seat
Going from seat to input device requires that we test the device
before relying on the pointer.  In all of these binding functions
we can trust exactly one input device type directly.  If we pass
that in instead of a seat it's more obvious that we can trust
the one pointer we have.

When a seat is required, we can access through the device we have
and use that to get to other device types for the seat, provided
we validate them appropriately.

Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
2015-07-16 19:04:40 -07:00
Jon Cruz 35b2eaa989 Moved helper macro to a discrete include file.
To help reduce code duplication and also 'kitchen-sink' includes
the ARRAY_LENGTH macro was moved to a stand-alone file and
referenced from the sources consuming it. Other macros will be
added in subsequent passes.

Signed-off-by: Jon A. Cruz <jonc@osg.samsung.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2015-06-15 17:11:45 -07:00
Jon Cruz 4678bab13c Remove redundant #include path component.
Using the parent '../' path component in #include statements makes
the codebase more rigid and is redundant due to proper -I use.

Signed-off-by: Jon A. Cruz <jonc@osg.samsung.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2015-06-15 17:11:09 -07:00
Bryce Harrington a0bbfea64b src: Update boilerplate from MIT X11 license to MIT Expat license 2015-06-15 13:04:18 -07:00
Derek Foreman bc91e54a8c input: clean up update_keymap a little
We already have a pointer to the keyboard, so we can change all
seat->keyboard to keyboard.

Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2015-06-04 13:43:57 -07:00
Derek Foreman 1b786eecaa input: minor clean up in weston_seat_repick()
Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2015-06-04 13:43:53 -07:00
Derek Foreman 244e99e18c input: clean up notify_modifiers a little
We already have a pointer to the keyboard, so we can change all
seat->keyboard to keyboard.

Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2015-06-04 13:43:50 -07:00
Derek Foreman 345c9f366f input: clean up seat_get_keyboard a little
We already have a pointer to the keyboard, so we can change all
seat->keyboard to keyboard

Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2015-06-04 13:43:45 -07:00
Derek Foreman 4c93c08679 touch: Make weston_touch_set_focus() take a touch instead of a seat
The other set_focus() functions take the relevant type instead of a seat
already, so this is consistent.

Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2015-05-01 12:42:52 +01:00
Derek Foreman 4e53c53fe7 input: Don't recreate the cursor sprite when only the hotspot changes
Currently we unmap and re-map the cursor when the hotspot changes which
causes spurious enter/leave events.

This changes the pointer_set_cursor() logic to avoid this.

Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2015-03-26 10:15:48 +02:00
Jonas Ådahl b407024ea1 input: Make setting the same pointer cursor state again a no-op
If the client calls wl_pointer.set_cursor with the same surface and hot
spot coordinate that is already set, don't do anything as no state was
changed.

This avoids an issue where a client setting the same cursor surface
multiple times would receive wl_surface.leave/enter on that surface
every time.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-By: Derek Foreman <derekf@osg.samsung.com>
2015-03-20 11:58:30 +08:00
Giulio Camuffo b6ddf6c229 input: store the grab serial of the keyboard
The serial can be checked against the one passed to wl_shell.set_popup
or equivalent.
Reviewed-by: Daniel Stone <daniels@collabora.com>
2015-02-11 19:35:13 -08:00
Derek Foreman fd5ca513f9 input: Add comment explaining why pointer isn't freed when device is removed
When the last pointer is removed from a seat, the pointer struct is
intentionally kept.  This has some interesting side effects, so I've
documented it here so people like me don't errantly assume it's a bug.

Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
2015-01-08 10:58:33 +08:00
Pekka Paalanen 8274d901f1 compositor: add weston_surface_set_label_func()
When printing out logs from Weston's actions, mainly for debugging, it
can be very difficult to identify the different surfaces.  Inspecting
the configure function pointer is not useful, as the configure functions
may live in modules.

Add vfunc get_label to weston_surface, which will produce a short,
human-readable description of the surface, which allows identifying it
better, rather than just looking at the surface size, for instance.

Set the label function from most parts of Weston, to identify cursors and
drag icons, and panels, backgrounds, screensavers and lock surfaces, and
the desktop shell's application surfaces.

v2: renamed 'description' to 'label', so we get
	weston_surface_set_label_func().

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-12-08 14:20:20 +02:00
Giulio Camuffo a20ca811f9 input: send focus events to the focused client when running a key binding
When running a key binding we don't send the key press to the client
via the wl_keyboard.key event. Instead, send a wl_keyboard.leave/enter
pair so that the client knows the actual state of the keyboard.

Reviewed-by: Daniel Stone <daniel@fooishbar.org>
2014-12-01 16:26:53 +02:00
Derek Foreman d621df2dee input: Use slightly less obscure logic in evdev_notify_keyboard_focus()
While the test is actually correct (for non-negative numbers), it's not
at all clear and seems to be an accidental order of operations mistake.

Also, add an assert() to make sure this number is never negative.

Closes bug 86346 - https://bugs.freedesktop.org/show_bug.cgi?id=86346

Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
Reviewed-by: Marek Chalupa <mchqwerty@gmail.com>
2014-11-27 15:26:04 +02:00
Giulio Camuffo fde9490d7e input: don't run the key bindings on focus in
When getting the focus we get the list of pressed keys, but we are
not supposed to run the key binding on them.

Reviewed-by: Daniel Stone <daniel@fooishbar.org>
2014-11-24 13:44:06 +02:00
Pekka Paalanen 86b5396d89 Revert "input: don't send to clients key events eaten by bindings"
This reverts commit 5c11fc6fb7.

According to two input specialists, this was the wrong way:
http://lists.freedesktop.org/archives/wayland-devel/2014-November/018287.html

Cc: Peter Hutterer <peter.hutterer@who-t.net>
Cc: Daniel Stone <daniel@fooishbar.org>
Cc: Giulio Camuffo <giuliocamuffo@gmail.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-11-19 13:45:38 +02:00
Pekka Paalanen c557ff7ea3 input: use tmp var in pointer_unmap_sprite
Remove lots of repeated indirection.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-11-12 16:42:52 +02:00
Giulio Camuffo 5c11fc6fb7 input: don't send to clients key events eaten by bindings
weston key bindings are supposed to eat the key events, and not pass it
on to clients, and indeed the wl_keyboard.key event is not sent. But
we must also not put the key in the keys array to pass to client with
the wl_keyboard.enter event, or else we may send the 'eaten' one too.
In the case of a key binding hiding a surface having the keyboard focus,
the shell may decide to give the focus to another surface, but that will
happen before the key is released, so the new focus surface will receive
the code of the bound key in the wl_keyboard.enter array.

Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-11-11 15:07:12 +02:00
Giulio Camuffo de77e32b10 input: fix access to invalid resource
the keyboard focus surface may not have a valid resource (server side
surface or a surface surviving its client), so check if it is valid
before using it.

Acked-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-11-11 11:56:37 +02:00
Derek Foreman 280e7dd918 cosmetic: replace boolean function return values with bool
For functions that test if something is true/valid and return a 1
or 0, it makes sense to switch to bool.

Reviewed-by: Bryce Harrington <b.harrington@samsung.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-11-04 12:45:49 +02:00
Pekka Paalanen 50b6747903 compositor: send error for surface role resets
With the more accurate definition of wl_surface roles in Wayland,
enforce the restriction: a role is always set permanently, and
attempting to change it is a protocol error.

This patch is based on Jasper's patch:
http://lists.freedesktop.org/archives/wayland-devel/2014-August/016811.html

The difference in this patch compared to his are:

- send role errors on the interface whose request triggers it, not on
  wl_surface

- an interface could have several requests assigning different roles,
  cannot use wl_interface as the unique key; use an arbitary string
  instead

- ensure in window-manager.c that create_shell_surface() ->
  create_common_surface() is never called with surface->configure set,
  to avoid compositor abort

- use wl_resource_post_no_memory() where appropriate instead of
  hand-rolling it with wl_resource_post_error()

Ideally we would not add weston_surface::role_name field, but use
weston_surface::configure. At the moment this is not possible though,
because at least shell.c uses several different roles with the same
configure function. Drag'n'drop uses two configure functions for the
same role. The configure hook is also reset in several places,
which is not good for role tracking.

This patch overlooks the wl_surface roles assigned in privileged
extensions: screensaver, panel, background, lock, input panel.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Jasper St. Pierre <jstpierre@mecheye.net>
2014-10-08 13:16:30 +03:00
Jonas Ådahl 16fe4dcea9 input: Schedule pointer sprite repaint when cursor is set
If a cursor was set with wl_pointer.set_cursor but not in combination
with an action that has the side effect of damaging the region where the
cursor is positioned, it would not be drawn. This patch explicitly
schedules a repaint of the pointer sprite when it is set.

clickdot is updated to illustrate the bug; when moving the pointer over
clickdot, the pointer is hidden. When not having moved the pointer for
500 ms it is made visible using wl_pointer.set_pointer.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-09-10 14:20:13 +03:00
Derek Foreman 362656bfa3 touch-input: Don't dereference NULL pointer during full screen fade
If a full screen program is fading out and a touch start happens, it
will result in a NULL pointer dereference when weston_touch_set_focus
tries to derefernce view->surface->resource.

Instead, this patch sets the focus to NULL, which should be the
same as if the program was destroyed during the touch anyway.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=78706
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-09-05 10:32:09 +03:00
Giulio Camuffo 6ef444d094 compositor: add a way to change the keyboard locks
This adds a function weston_keyboard_set_locks() which can be used to
change the state of the num lock and the caps locks, changing the leds too.
Only the evdev and libinput backends supports this, since it doesn't make
sense for embedded sessions.

Tested-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-09-03 15:31:04 +03:00
Ran Benita c9c74156cd Don't protect xkb_*_unref from NULL
Since xkbcommon-0.3.0, which is required by weston, a NULL argument
doesn't do anything.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-08-20 01:05:16 -07:00
Ran Benita 2e1968fa1f Replace deprecated xkbcommon symbols with current names
These symbols (xkb_map_* and others) were replaced in xkbcommon with more
consistent names. See the header xkbcommon/xkbcommon-compat.h for how
the old names map to the new.

The new names have been available since the first stable xkbcommon
release (0.2.0).

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-08-20 01:05:13 -07:00
Jonny Lamb 66a41a06e7 compositor: fetch repeat info from weston.ini 2014-08-15 15:39:47 +03:00
Jasper St. Pierre 0013a29d5e Use the named SINCE_VERSION defines for version checks
To make our code more clear.
2014-08-08 14:56:57 -07:00
Jasper St. Pierre d8c6aeb8a5 input: Send key-repeat 2014-08-05 12:31:04 -07:00
Giulio Camuffo 412e6a59eb compositor: keep track of the weston_layer a weston_view is in
This introduces a new struct, weston_layer_entry, which is now used
in place of wl_list to keep the link for the layer list in weston_view
and the head of the list in weston_layer.
weston_layer_entry also has a weston_layer*, which points to the layer
the view is in or, in the case the entry it's the head of the list, to
the layer itself.
2014-07-23 12:34:33 -07:00
Jonas Ådahl 1679f232e5 libinput: Forward frame events to clients
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=77353

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-04-21 16:03:28 -07:00
Jason Ekstrand a4ab5422e9 Add a signal for when a seat updates its capabilities
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2014-04-02 21:24:42 -07:00
Kristian Høgsberg db1fccb3d8 input: Send leave and enter pair when the surface moves under the cursor
The client needs to know that the pointer is at a different position in
its surface.  We can't send motion as that corresponds to the pointer
actually moving.  Leaving the surface and entering at the new position
is a better semantic match and doesn't correspond to pointer motion
or user input.

https://bugs.freedesktop.org/show_bug.cgi?id=71927
2014-02-18 13:47:41 -08:00
Kristian Høgsberg e11ef64534 compositor: Drop core ping_handler callout
This was always a little iffy.  At least it could have been a signal,
but we now have focus signal, so lets just use that.  We lose
the ability to detect unresponsive clients at key event time, but we
could add that back by adding a key_signal.
2014-02-11 16:35:22 -08:00
Kristian Høgsberg c896401209 input: Run touch binding before calling touch grab
We don't want to send events if the binding is going to handle the touch
event.  Also, this restricts touch bindings to only trigger on touch down.
For gesture bindings we want something similar to the motion signal we
have for the pointer.
2014-02-05 17:01:33 -08:00
Kristian Høgsberg c988362a39 input: Transform to surface coordinates outside resource for loop
When we send the pointer motion event, the transform from compositor to
surface coordinates doesn't depend on the resource.  Transform the
coordinates up front instead of everytime we send to a resource.
2014-02-05 13:36:02 -08:00
Ander Conselvan de Oliveira f84327aef2 input: Remove exported function weston_pointer_verify()
Instead, add a compositor signal that an output has been destroyed and
handle that case locally in input.c.
2014-02-01 01:36:05 -08:00
Ander Conselvan de Oliveira 4d363cfcf6 input: Fix weston_seat_init_keyboard() error path
The pointer seat->keyboard was set before some possible error returns.
That pointer was left unchanged in case of failure, pointing to an
uninitialized keyboard struct (that was also leaked). If a client sent
a wl_seat::get_keyboard request, that would cause Weston to crash.

Fix this by setting the seat->keyboard pointer only after the keymap
initialization is done and there is no more possibilities for failure.
Also plug the memory leaks on the error path.

https://bugs.freedesktop.org/show_bug.cgi?id=74035
2014-02-01 01:14:22 -08:00
Ander Conselvan de Oliveira 23900f70e5 input: Empty the current input region when configuring pointer surfaces
The input region of the cursor surface is set to empty in
pointer_cursor_surface_configure(). Since during the commit process
this function is called before the pending input region is made
current, it empties surface->pending.input instead of surface->input.

But pointer_cursor_surface_configure() is also called from
pointer_set_cursor() in order to map the cursor even if there isn't a
subsequent attach and commit to the cursor surface. In that case,
surface->input is never emptied, since the configure function emptied
only the pending input region and there wasn't a commit that made it
effective.

Fix this by emptying both pending and current input regions. The latter
shouldn't cause problems since the surface can't have a role prior to
being assigned the cursor role, so it shouldn't be mapped in the first
place.

Also change toytoolkit so that it triggers the bug.

https://bugs.freedesktop.org/show_bug.cgi?id=73711
2014-02-01 01:12:24 -08:00
Jonas Ådahl 1afb2383ea input: Unlink saved kbd focus listener when releasing seat
Not doing this would leave a invalid list item in the view's destroy
signal listener list if destroying a seat that had previously lost
keyboard focus.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-01-27 21:14:25 -08:00