Commit graph

65 commits

Author SHA1 Message Date
Jason Ekstrand
1488c96a5d Add accessor functions for wl_resource and deprecate wl_client_add_resource
This is the first step towards making wl_resource an opaque pointer type.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-06-05 00:59:08 -04:00
Kristian Høgsberg
508dd69b56 server: Drop struct wl_surface
This struct was only defined in the server API for the purpose of the
input structs and helper functions.  Now that those are gone we can dro it.
2013-05-08 09:45:59 -04:00
Kristian Høgsberg
e920572e5c Remove input structs
Looking at the functionality in the server library, it's clear (in
hindsight) that there are two different "things" in there: 1) The IPC
API, that is, everything that concerns wl_display, wl_client,
wl_resource and 2) and half-hearted attempt at sharing input code and
focus logic that leaves a lot of problematic structs in the API
surface, only to share less than 1000 lines of code.

We can just move those input structs and helper functions into weston
and cut libwayland-server down to just the core server side IPC API.
In the short term, compositors can copy those structs and functions
into their source, but longer term, they're probably better off
reimplementing those objects and logic their native framework
(QObject, GObject etc).
2013-05-07 09:10:49 -04:00
Rob Bradford
db19b443cc wayland-server: Listen for pointer current surface destruction
Add a destroy listener so that when the current surface associated with the
pointer is destroyed we can reset the pointer to the current surface. In order
to achieve this add a wl_pointer_set_current() which handles assigning the
surface and creating the listener.

This resolves a use-after-free error triggered with nested popup surfaces

Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=696946
2013-04-03 12:46:57 -04:00
Giulio Camuffo
6ca428edc8 server: use the right function pointer type in wl_signal_get
use the wl_notify_func type, and not void *, or else wl_signal_get
will not be usable by a c++ plugin because it will not cast
void * to a function pointer.
2013-04-02 17:11:44 -04:00
Jason Ekstrand
bedc3432ff Add wl_resource_init and use it in libwayland implementations of data sharing and SHM
This commit adds a wl_resource_init function for initializing wl_resource
structures similar to wl_client_add_object.

From this commit forward, wl_resource structures should not be initialized
manually, but should use wl_resource_init.  In the event of a change to the
wl_resource structure, this allows us to protect against regressions by filling
in added fields with reasonable defaults.  In this way, while changing
wl_object or wl_resource still constitutes an ABI break, compositors following
this rule will only need to be recompiled in order to properly link against the
new version.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-03-18 23:04:32 -04:00
Jason Ekstrand
2423497b99 Add a destroy signal to the wl_event_loop object 2013-01-15 14:05:27 -05:00
Jason Ekstrand
31511d0ea0 Added a destroy signal to the wl_display object.
Added a destroy signal to the wl_display object.
2013-01-11 15:52:39 -05:00
Matt Roper
4ce294d641 wayland-server: Add touch grab support
Touch grabs allow the compositor to be placed into a mode where touch events
temporarily bypass their default behavior and perform other operations.
Wayland already supports keyboard and pointer grabs, but was lacking
corresponding touch support.  The default touch grab handlers here contain the
client event delivery code that was previously called directly in weston.

Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
2012-10-15 19:44:08 -04:00
Kristian Høgsberg
53d24713a3 Change filedescriptor API to be thread safe
The update callback for the file descriptors was always a bit awkward and
un-intuitive.  The idea was that whenever the protocol code needed to
write data to the fd it would call the 'update' function.  This function
would adjust the mainloop so that it polls for POLLOUT on the fd so we
can eventually flush the data to the socket.

The problem is that in multi-threaded applications, any thread can issue
a request, which writes data to the output buffer and thus triggers the
update callback.  Thus, we'll be calling out with the display mutex
held and may call from any thread.

The solution is to eliminate the udpate callback and just require that
the application or server flushes all connection buffers before blocking.
This turns out to be a simpler API, although we now require clients to
deal with EAGAIN and non-blocking writes.  It also saves a few syscalls,
since the socket will be writable most of the time and most writes will
complete, so we avoid changing epoll to poll for POLLOUT, then write and
then change it back for each write.
2012-10-10 20:59:00 -04:00
David Herrmann
003a946aa6 event-loop: export wl_event_loop_dispatch_idle()
When integrating the wayland event-loop into another event-loop, we
currently have no chance of checking whether there are pending idle
sources that have to be called. This patch exports the
"dispatch_idle_sources()" call so other event loops can call this before
going to sleep. This is what wl_event_loop_dispatch() currently does so we
simply allow external event-loops to do the same now.

To avoid breaking existing applications, we keep the call to
dispatch_idle_sources() in wl_event_loop_dispatch() for now. However, if
we want we can remove this later and require every application to call
this manually. This needs to be discussed, but the overhead is negligible
so we will probably leave it as it is.

This finally allows to fully integrate the wayland-server API into
existing event-loops without any nasty workarounds.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-12 12:28:54 -04:00
David Herrmann
9fe135c46f wayland-server: return new ID in wl_client_add_resource()
wl_client_add_resource() used to return no error even though the new
resource wasn't added to the client. This currently makes it very easy to
DOS weston by simply posting thousands of "create_surface" requests with
an invalid ID. Weston simply assumes the wl_client_add_resource() request
succeeds but will never destroy the surface again as the "destroy" signal
is never called (because the surface isn't linked into the wl_map).

This change makes wl_client_add_resource() return the new ID of the added
object and 0 on failure. Servers (like weston) can now correctly
immediately destroy the surface when this call fails instead of leaving
the surface around and producing memory-leaks.

Instead of returning -1 on failure and 0 on success, I made it return the
new ID as this seems more appropriate. We can directly use it when calling
it with new_id==0.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-09-10 21:44:47 -04:00
Kristian Høgsberg
7d3ccec18e Add wl_shm_buffer_create() 2012-08-16 10:49:48 -04:00
Kristian Høgsberg
7ba218c9f8 shm: Add shm_buffer getters for width and height 2012-07-20 12:04:42 -04:00
Daniel Stone
bcefacb89d Maintain keyboard modifier state in wayland-server
Provide a slot for keyboard modifier state inside wl_keyboard for
implementations to update, and use this to send wl_keyboard:;modifier
events whenever the keyboard or pointer focus changes.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-06-22 11:06:44 -04:00
Jonas Ådahl
1432bd62df wayland-server: Add destroy signal to wl_seat
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2012-06-12 20:18:42 -04:00
Kristian Høgsberg
aa792ad3d6 Add a focus change signal for wl_pointer and wl_keyboard 2012-06-05 09:56:42 -04:00
Kristian Høgsberg
68f058ffd3 data-device: Don't implement data source through data offer object
The wl_data_source object used to specify the implementation for data
offers created for it.  This means you need a data offer to retrieve the
data from the source, which makes it awkward to use in-process in a
compositor.  Now we instead have three virtual functions that can be
connected to a protocol object or in-process data-sources such as an
X server proxy or clipboard.
2012-06-03 17:30:12 -04:00
Daniel Stone
9a1705c5f5 wl_keyboard: Add modifier event
This event sends the current keyboard modifier/group state from the
compositor to the client, allowing all clients to have a consistent view
of the keyboard state (e.g. current layout, Caps Lock, et al).  It
should be sent after a keyboard enter event, and also immediately after
any key event which changes the modifier state.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-05-31 14:01:56 -04:00
Martin Minarik
8e2a786703 Wayland: logging
The core libwayland libraries should not handle logging, only passing
the error messages to subscribed functions.
An application linked to libwayland-server or libwayland-client
will be able to set own functions (one per library) to handle error
messages.

Change in this series: make the wl_log return int, because
of compatibility with printf. It will return the number of bytes logged.
2012-05-31 13:57:15 -04:00
Ander Conselvan de Oliveira
75a5f7476a data-device: implement drags with no data source for self-dnd
Properly handle a drag with no data source, i.e., don't crash and send
events only to the client that initiated the drag. This way a client can
do self drag and drop without offering anything to other clients.
2012-05-29 09:58:13 -04:00
Daniel Stone
aa0fb0f49c Convert wl_input_device to wl_seat (and friends)
wl_input_device has been both renamed and split.  wl_seat is now a
virtual object representing a group of logically related input devices
with related focus.

It now only generates one event: to let clients know that it has new
capabilities.  It takes requests which hand back objects for the
wl_pointer, wl_keyboard and wl_touch interfaces it exposes which all
provide the old input interface, just under different names.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-05-16 14:19:22 -04:00
Daniel Stone
0c20496e1a Input: Convert pointer co-ordinates to signed_24_8
This offers more precision when using devices like tablets, and also for
transformed surfaces.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-05-08 14:40:46 -04:00
Daniel Stone
c5aba11acc Add support for signed 24.8 decimal numbers
'fixed' is a signed decimal type which offers a sign bit, 23 bits of
integer precision, and 8 bits of decimal precision.  This is exposed as
an opaque struct with conversion helpers to and from double and int on
the C API side.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-05-08 14:40:39 -04:00
Daniel Stone
3f7048e0e9 Use unsigned for key/button up/down state in grabs
Since we just use it as a simple boolean flag, might as well convert it
to unsigned.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-05-07 12:15:14 -04:00
Kristian Høgsberg
ac73a74f43 Add wl_client_get_object() 2012-04-27 11:28:06 -04:00
Kristian Høgsberg
4fd3696f98 Drop stale prototype 2012-04-27 11:26:57 -04:00
Kristian Høgsberg
a9f951b003 data-device: Record the serial number for the current selection
And reject setting a selection that's older than our current selection.
2012-04-13 12:48:38 -04:00
Kristian Høgsberg
fa5f7b1191 server: Add client destroy signal 2012-04-13 09:53:15 -04:00
Neil Roberts
18a770c80d Add a public header for the version number
This adds a public header so that applications can get the Wayland
version number at compile time. This can be used to make applications
that support compiling against multiple versions of Wayland.

There is a separate installed header called cogl-version.h which gets
included by both wayland-client.h and wayland-server.h

The canonical place for the version number is the configure.ac script
which splits it into three separate m4 defines for the major, minor
and micro version. These are copied into the generated
wayland-version.h header using AC_SUBST. There is also a string form
of the complete version number.

The version number is now also automatically copied into the two .pc
files.

Because the major, minor and micro parts are required it is no longer
possible to leave the version number as 'master' when building from
git. Most projects seem to immediately bump the git repo to a fake
version number (usually odd) after making a release so that there is
always a relative number that can be used for comparison. This patch
sets the git version to 0.99.0 under the assumption that the next
release will be 1.0.0.
2012-04-12 17:54:44 -04:00
Kristian Høgsberg
6802eaa68a Introduce wl_signal
This is mostly renaming and consolidating the listener_list pattern
into something more concise and reusable.
2012-04-12 15:52:44 -04:00
Kristian Høgsberg
5535f155d8 Switch protocol to using serial numbers for ordering events and requests
The wayland protocol, as X, uses timestamps to match up certain
requests with input events.  The problem is that sometimes we need to
send out an event that doesn't have a corresponding timestamped input
event.  For example, the pointer focus surface goes away and new
surface needs to receive a pointer enter event.  These events are
normally timestamped with the evdev event timestamp, but in this case,
we don't have a evdev timestamp.  So we have to go to gettimeofday (or
clock_gettime()) and then we don't know if it's coming from the same
time source etc.

However for all these cases we don't need a real time timestamp, we
just need a serial number that encodes the order of events inside the
server.  So we introduce a serial number mechanism that we can use to
order events.  We still need real-time timestamps for actual input
device events (motion, buttons, keys, touch), to be able to reason
about double-click speed and movement speed so events that correspond to user input carry both a serial number and a timestamp.

The serial number also give us a mechanism to key together events that
are "logically the same" such as a unicode event and a keycode event,
or a motion event and a relative event from a raw device.
2012-04-11 22:27:26 -04:00
Jørgen Lind
a13aab4e15 remove superfluous functions 2012-04-11 08:17:20 -04:00
Pekka Paalanen
4560b6b6b4 server: fix button signedness in wl_grab_interface
wl_input_device::grab_button is unsigned but the button parameter to
wl_grab_interface::button is signed. This lead to a warning in
data-device.c.

The button number is unsigned in the protocol, so make it unsigned in
the wl_grab_interface API, too. Fixes the compiler warning "comparison
between signed and unsigned integer expressions".

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-03-30 10:14:51 -04:00
Kristian Høgsberg
4fe458346c Remove unused bits from wayland-server.h 2012-03-29 14:03:40 -04:00
Ander Conselvan de Oliveira
897a4ec62d data-device: notify the compositor about new drag icons
Let the compositor use a listener to be notified when a new drag icon
is set up.
2012-03-27 16:32:02 -04:00
Kristian Høgsberg
83685c506e Remove wl_buffer.damage and simplify shm implementation 2012-03-26 16:33:24 -04:00
Bill Spitzak
81ffaa04b9 Check arguments to wl_resource_post_error in gcc
The attached patch turns on printf argument warnings for this function,
which I found was being called incorrectly at least once in the wayland
source code.
2012-03-20 16:52:17 -04:00
Ander Conselvan de Oliveira
214e343311 Terminate drag if data source is destroyed 2012-03-02 11:45:11 -05:00
Pekka Paalanen
86a5d17afe scanner: emit event wrapper functions for server
Generate typed wrapper functions for sending events in a server.

This allows compile time type checking, unlike the existing method of
calling the variadic function wl_resource_post_event().

The stuff in wayland-server.h had to be slightly reordered to have all
(forward) declarations before use.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-03-02 17:55:45 +02:00
Ander Conselvan de Oliveira
e7f6c509e2 Fix server crash when a client dies during a drag with an icon
If a client dies during a drag that it started using an icon surface,
the server could crash because the icon surface is not valid anymore.

Fix this by using a destroy listener to reset device->drag_surface to
nil when the surface is destroyed.
2012-03-01 11:52:05 -05:00
Thiago Macieira
c56667bb83 Fix compilation: uid_t, gid_t and pid_t are defined in sys/types.h
This error shows up in third-party code when including
wayland-server.h.
2012-02-23 15:35:30 -05:00
Scott Moreau
ab3b5cd71c server: Implement wl_keyboard_grab_interface. 2012-02-18 11:55:22 -05:00
Scott Moreau
8134e06742 server: Rename wl_grab_interface.
In order to separate pointer and keyboard grabs, we need to
introduce a keyboard grab interface but first we must rename
some generic types to denote which device is holding the grab.

Type renames:

wl_grab_interface -> wl_pointer_grab_interface
wl_grab -> wl_pointer_grab
wl_input_device_start_grab -> wl_input_device_start_pointer_grab
wl_input_device_end_grab -> wl_input_device_end_pointer_grab
2012-02-18 11:51:38 -05:00
Kristian Høgsberg
8503cd6859 Add wl_client_get_credentials() to get unix credentials for client 2012-02-18 00:29:25 -05:00
Pekka Paalanen
5536031bfb protocol: remove absolute coordinates from pointer
Remove the absolute coordinate fields from the pointer motion and
pointer_focus events. Clients are not supposed to see any global
coordinates.

Fix wayland-server code accordingly. wayland-client code is unaffected.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-02-16 16:33:01 -05:00
Ander Conselvan de Oliveira
7243062f93 data_device: get rid of attach request
In the effort to make everything a regular surface, remove
data_device.attach request. To maintan the functionality, add
an icon surface parameter to data_device.start_drag.

Signed-off-by: Kristian Høgsberg <krh@bitplanet.net>
Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com>
2012-02-16 16:11:44 -05:00
Kristian Høgsberg
b6b3d07c83 Move data device implementation into wayland-server 2012-01-06 11:40:02 -05:00
Kristian Høgsberg
5ffe9f4708 New grab API
This commit changes the way struct wl_grab works in a couple of ways:

 - The grab itself now decides when it ends instead of hardcoding button
   up as the terminating event.  We remove the end vfunc since a grab now
   always know when it ends and can just clean up at that point.

 - We add a new focus vfunc that is invoked every time the pointer enters
   a new surface, regardless of any grabs.  The callback receives the
   surface and the surface-relative pointer coordinates.  The callback lets
   a grab send enter/leave events and change the grab focus.

 - The grab has a focus surface, wich determines the coordinate space
   for the motion callback coordinates.

 - The input device always tracks the current surface, ie the surface that
   currently contains the pointer, and coordinates relative to that surface.

With these changes, we will be able to pull the core input event delivery
and the drag and drop grab into the core wayland-server library.
2012-01-06 11:30:08 -05:00
Pekka Paalanen
2755847fce server: add wl_input_device_release()
Add a clean-up function for destroying all objects created in
wl_input_device_init(). Can be used to fix memory leaks reported by
Valgrind in the demos.

The init function was also missing an explicit initialisation of the
'keys' array. Add the explicit array init, although it is redundant with
the zeroing of the whole struct.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>

krh: Edited to rename function to *_release()
2012-01-03 11:22:58 -05:00