<div dir="ltr"><div><div><div><div>Andrew,<br></div>I've had ideas kicking around in the back of my head for a while now about how to do just this. However, my ideas have taken a substantially different route. I don't have any real problems with what you suggested (although I didn't read it in careful detail). What follows below is more of a counter-proposal.<br>
<br>Some time ago I proposed to the list a protocol for a fullscreen shell that only runs one client at a time. The proposal can be found here: <a href="http://lists.freedesktop.org/archives/wayland-devel/2013-August/010720.html">http://lists.freedesktop.org/archives/wayland-devel/2013-August/010720.html</a>. (As a disclaimer, I have since renamed it to wl_fullscreen_shell because that's a bit more accurate and because I do not intend for actual system compositors.) One of the purposes for this protocol is to allow you to nest compositors and use the Wayland protocol itself as an input/output abstraction. This way compositors (such as GNOME shell or Weston) can run on another system without having to have built-in back-end support for it. All that is needed is for someone to write a fairly simple compositor that provides wl_fullscreen_shell. This simple compositor could be, for instance, a VNC or RDP server. In particular this would allow any other compositor to run on top of Weston's backends because I have already implemented the fullscreen shell in Weston.<br>
<br></div>You may be thinking, "But I don't want to start the compositor inside my VNC server, I want it to mirror what's already on the screen." It wouldn't have be restricted to headless operation. Weston (or any other compositor) could spawn the VNC server and then immediately connect to it as a wl_fullscreen_shell client. (For security purposes, the connection could be established by passing an already opened file descriptor via an environment variable.) Instead of using that as the primary backend, Weston (or any other compositor) would simply mirror outputs to the VNC server. The assignment of seats would then be a compositor-configured thing (although I would vote for just adding the VNC seats).<br>
<br></div>The advantage of this method is that it requires very little repetition of protocol. If we run the VNC server as a client, we have to repeat most of the Wayland protocol only in the opposite direction. If we let the VNC server run as a server and the compositor as a client, we get all of the input handling, buffer passing, etc. for free.<br>
<br>Let me know what you think,<br></div>--Jason Ekstrand<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Oct 18, 2013 at 9:50 AM, Andrew Wedgbury <span dir="ltr"><<a href="mailto:andrew.wedgbury@realvnc.com" target="_blank">andrew.wedgbury@realvnc.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I've been working on a weston module to support an interface for remote access systems such as VNC. This is now at a point where it's usable (and works rather well with a suitably modified version of our VNC server) so I wanted to present it here with a view to including it in weston at some point.<br>
<br>
The module is named remote-access - which is intended to be a suitably generic name since it could be used by VNC or RDP (or others). It exposes a new global interface called remote-access, which can be used to create instances of remote-capture and remote-seat interfaces as required.<br>
<br>
The remote-capture interface allows a particular output to be captured. It is created by specifying a shared memory region of the required size, and the output to capture. The interface allows a single refresh to be requested, in which case an update event will signal when the update is ready to be read from the buffer. It can also operate in continuous mode, when update events are sent whenever the output changes and the buffer has been updated. The update event contains the coordinates of the rectangle that changed (in coordinates relative to the output). This part is loosely based on weston's screenshooter code.<br>
<br>
The remote-seat interface allows input events to be injected via a weston seat. The interface allows multiple remote-seat objects to be created, each of which can use an existing seat, or create a new seat. That way the remote access system has the flexibility of creating a separate seat for each connected user, or simply control an a single seat, as required.<br>
<br>
There are (at least!) two outstanding issues that I am aware of:<br>
<br>
* Access to these interfaces should be restricted somehow. This could be achieved in a way similar to screenshooter, where weston could launch the VNC/RDP server. Or weston could prompt the user somehow (although this would not be effective when trying to access a remote, unattended machine).<br>
<br>
* We need to be able to capture the pointer sprite, and detect when this changes. This would need to be part of the remote-seat interface since each seat can have a pointer. So far I've not found a method to reliably detect when the pointer changes, so I would appreciate some help on this one.<br>
<br>
I've also written a test client, but this is very much work-in-progress at this point.<br>
<br>
Any feedback would be greatly appreciated, diff follows below:<br>
<br>
---<br>
<br>
clients/.gitignore | 3 +<br>
clients/Makefile.am | 13 +<br>
clients/remote-test.c | 437 +++++++++++++++++++++++++++++++<br>
<a href="http://configure.ac" target="_blank">configure.ac</a> | 8 +<br>
protocol/Makefile.am | 3 +-<br>
protocol/remote-access.xml | 160 ++++++++++++<br>
src/.gitignore | 2 +<br>
src/Makefile.am | 14 +<br>
src/remote-access.c | 612 ++++++++++++++++++++++++++++++++++++++++++++<br>
9 files changed, 1251 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/clients/.gitignore b/clients/.gitignore<br>
index 23959cc..3e98fcf 100644<br>
--- a/clients/.gitignore<br>
+++ b/clients/.gitignore<br>
@@ -45,3 +45,6 @@ weston-multi-resource<br>
workspaces-client-protocol.h<br>
workspaces-protocol.c<br>
weston-simple-im<br>
+remote-access-protocol.c<br>
+remote-access-client-protocol.h<br>
+weston-remote-test<br>
diff --git a/clients/Makefile.am b/clients/Makefile.am<br>
index 4f9dc48..61c5b7a 100644<br>
--- a/clients/Makefile.am<br>
+++ b/clients/Makefile.am<br>
@@ -19,6 +19,7 @@ libexec_PROGRAMS = \<br>
$(desktop_shell) \<br>
$(tablet_shell) \<br>
$(screenshooter) \<br>
+ $(remote_test) \<br>
$(screensaver) \<br>
$(keyboard) \<br>
weston-simple-im<br>
@@ -90,6 +91,10 @@ endif<br>
<br>
screenshooter = weston-screenshooter<br>
<br>
+if ENABLE_REMOTE_ACCESS<br>
+remote_test = weston-remote-test<br>
+endif<br>
+<br>
noinst_LTLIBRARIES = <a href="http://libtoytoolkit.la" target="_blank">libtoytoolkit.la</a><br>
<br>
libtoytoolkit_la_SOURCES = \<br>
@@ -118,6 +123,12 @@ weston_screenshooter_SOURCES = \<br>
../shared/os-compatibility.h<br>
weston_screenshooter_LDADD = $(CLIENT_LIBS)<br>
<br>
+weston_remote_test_SOURCES = \<br>
+ remote-test.c \<br>
+ remote-access-protocol.c \<br>
+ remote-access-client-protocol.h<br>
+weston_remote_test_LDADD = <a href="http://libtoytoolkit.la" target="_blank">libtoytoolkit.la</a><br>
+<br>
weston_terminal_SOURCES = terminal.c<br>
weston_terminal_LDADD = <a href="http://libtoytoolkit.la" target="_blank">libtoytoolkit.la</a> -lutil<br>
<br>
@@ -217,6 +228,8 @@ weston_tablet_shell_LDADD = <a href="http://libtoytoolkit.la" target="_blank">libtoytoolkit.la</a><br>
BUILT_SOURCES = \<br>
screenshooter-client-protocol.h \<br>
screenshooter-protocol.c \<br>
+ remote-access-client-protocol.h \<br>
+ remote-access-protocol.c \<br>
text-cursor-position-client-protocol.h \<br>
text-cursor-position-protocol.c \<br>
text-protocol.c \<br>
diff --git a/clients/remote-test.c b/clients/remote-test.c<br>
new file mode 100644<br>
index 0000000..13594e4<br>
--- /dev/null<br>
+++ b/clients/remote-test.c<br>
@@ -0,0 +1,437 @@<br>
+/*<br>
+ * Copyright © 2013 RealVNC Limited<br>
+ *<br>
+ * Permission to use, copy, modify, distribute, and sell this software and its<br>
+ * documentation for any purpose is hereby granted without fee, provided that<br>
+ * the above copyright notice appear in all copies and that both that copyright<br>
+ * notice and this permission notice appear in supporting documentation, and<br>
+ * that the name of the copyright holders not be used in advertising or<br>
+ * publicity pertaining to distribution of the software without specific,<br>
+ * written prior permission. The copyright holders make no representations<br>
+ * about the suitability of this software for any purpose. It is provided "as<br>
+ * is" without express or implied warranty.<br>
+ *<br>
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,<br>
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO<br>
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR<br>
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,<br>
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER<br>
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE<br>
+ * OF THIS SOFTWARE.<br>
+ */<br>
+<br>
+#include <stdint.h><br>
+#include <stdlib.h><br>
+#include <stdio.h><br>
+#include <string.h><br>
+#include <fcntl.h><br>
+#include <unistd.h><br>
+#include <limits.h><br>
+#include <sys/param.h><br>
+#include <sys/mman.h><br>
+#include <sys/select.h><br>
+#include <sys/time.h><br>
+#include <sys/types.h><br>
+#include <cairo.h><br>
+#include <termios.h><br>
+#include <linux/input.h><br>
+<br>
+#include <wayland-client.h><br>
+#include "remote-access-client-protocol.h"<br>
+#include "../shared/os-compatibility.h"<br>
+<br>
+#define US_PER_SECOND 1000000<br>
+<br>
+static struct wl_shm *shm;<br>
+static struct remote_access *remote_access;<br>
+struct remote_seat *remote_seat;<br>
+int ptr_x, ptr_y;<br>
+static struct wl_list output_list;<br>
+int min_x, min_y, max_x, max_y;<br>
+int updates;<br>
+long int max_update_time = 1 * US_PER_SECOND;<br>
+<br>
+struct remote_access_output {<br>
+ struct wl_output *output;<br>
+ struct wl_buffer *buffer;<br>
+ int width, height, offset_x, offset_y;<br>
+ void *data;<br>
+ struct wl_list link;<br>
+};<br>
+<br>
+// wl_output<br>
+<br>
+static void<br>
+display_handle_geometry(void *data,<br>
+ struct wl_output *wl_output,<br>
+ int x,<br>
+ int y,<br>
+ int physical_width,<br>
+ int physical_height,<br>
+ int subpixel,<br>
+ const char *make,<br>
+ const char *model,<br>
+ int transform)<br>
+{<br>
+ struct remote_access_output *output;<br>
+<br>
+ output = wl_output_get_user_data(wl_output);<br>
+<br>
+ if (wl_output == output->output) {<br>
+ output->offset_x = x;<br>
+ output->offset_y = y;<br>
+ }<br>
+}<br>
+<br>
+static void<br>
+display_handle_mode(void *data,<br>
+ struct wl_output *wl_output,<br>
+ uint32_t flags,<br>
+ int width,<br>
+ int height,<br>
+ int refresh)<br>
+{<br>
+ struct remote_access_output *output;<br>
+<br>
+ output = wl_output_get_user_data(wl_output);<br>
+<br>
+ if (wl_output == output->output && (flags & WL_OUTPUT_MODE_CURRENT)) {<br>
+ output->width = width;<br>
+ output->height = height;<br>
+ }<br>
+}<br>
+<br>
+static const struct wl_output_listener output_listener = {<br>
+ display_handle_geometry,<br>
+ display_handle_mode<br>
+};<br>
+<br>
+<br>
+// remote-access<br>
+<br>
+static void<br>
+remote_capture_update(void *data, struct remote_capture *remote_capture,<br>
+ int32_t x, int32_t y, int32_t width, int32_t height)<br>
+{<br>
+ fprintf(stdout, "remote_capture_update: %d,%d %dx%d\n",<br>
+ x, y, width, height);<br>
+ ++updates;<br>
+}<br>
+<br>
+static const struct remote_capture_listener remote_capture_listener = {<br>
+ remote_capture_update<br>
+};<br>
+<br>
+<br>
+// registry<br>
+<br>
+static void<br>
+handle_global(void *data, struct wl_registry *registry,<br>
+ uint32_t name, const char *interface, uint32_t version)<br>
+{<br>
+ static struct remote_access_output *output;<br>
+<br>
+ if (strcmp(interface, "wl_output") == 0) {<br>
+ output = malloc(sizeof *output);<br>
+ output->output = wl_registry_bind(registry, name,<br>
+ &wl_output_interface, 1);<br>
+ wl_list_insert(&output_list, &output->link);<br>
+ wl_output_add_listener(output->output, &output_listener, output);<br>
+<br>
+ } else if (strcmp(interface, "wl_shm") == 0) {<br>
+ shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);<br>
+<br>
+ } else if (strcmp(interface, "remote_access") == 0) {<br>
+ remote_access = wl_registry_bind(registry, name,<br>
+ &remote_access_interface, 1);<br>
+ }<br>
+}<br>
+<br>
+static void<br>
+handle_global_remove(void *data, struct wl_registry *registry, uint32_t name)<br>
+{<br>
+ /* XXX: unimplemented */<br>
+}<br>
+<br>
+static const struct wl_registry_listener registry_listener = {<br>
+ handle_global,<br>
+ handle_global_remove<br>
+};<br>
+<br>
+<br>
+static struct wl_buffer *<br>
+create_shm_buffer(int width, int height, void **data_out)<br>
+{<br>
+ struct wl_shm_pool *pool;<br>
+ struct wl_buffer *buffer;<br>
+ int fd, size, stride;<br>
+ void *data;<br>
+<br>
+ stride = width * 4;<br>
+ size = stride * height;<br>
+<br>
+ fd = os_create_anonymous_file(size);<br>
+ if (fd < 0) {<br>
+ fprintf(stderr, "creating a buffer file for %d B failed: %m\n",<br>
+ size);<br>
+ return NULL;<br>
+ }<br>
+<br>
+ data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);<br>
+ if (data == MAP_FAILED) {<br>
+ fprintf(stderr, "mmap failed: %m\n");<br>
+ close(fd);<br>
+ return NULL;<br>
+ }<br>
+<br>
+ pool = wl_shm_create_pool(shm, fd, size);<br>
+ close(fd);<br>
+ buffer = wl_shm_pool_create_buffer(pool, 0, width, height, stride,<br>
+ WL_SHM_FORMAT_XRGB8888);<br>
+ wl_shm_pool_destroy(pool);<br>
+<br>
+ *data_out = data;<br>
+<br>
+ return buffer;<br>
+}<br>
+<br>
+static void<br>
+write_png(const char* filename, int width, int height)<br>
+{<br>
+ int output_stride, buffer_stride, i;<br>
+ cairo_surface_t *surface;<br>
+ void *data, *d, *s;<br>
+ struct remote_access_output *output, *next;<br>
+<br>
+ buffer_stride = width * 4;<br>
+<br>
+ data = malloc(buffer_stride * height);<br>
+ if (!data)<br>
+ return;<br>
+<br>
+ wl_list_for_each_safe(output, next, &output_list, link) {<br>
+ output_stride = output->width * 4;<br>
+ s = output->data;<br>
+ d = data + (output->offset_y - min_y) * buffer_stride +<br>
+ (output->offset_x - min_x) * 4;<br>
+<br>
+ for (i = 0; i < output->height; i++) {<br>
+ memcpy(d, s, output_stride);<br>
+ d += buffer_stride;<br>
+ s += output_stride;<br>
+ }<br>
+ }<br>
+<br>
+ surface = cairo_image_surface_create_for_data(data,<br>
+ CAIRO_FORMAT_ARGB32,<br>
+ width, height,<br>
+ buffer_stride);<br>
+ cairo_surface_write_to_png(surface, filename);<br>
+ cairo_surface_destroy(surface);<br>
+ free(data);<br>
+}<br>
+<br>
+static int<br>
+set_buffer_size(int *width, int *height)<br>
+{<br>
+ struct remote_access_output *output;<br>
+ min_x = min_y = INT_MAX;<br>
+ max_x = max_y = INT_MIN;<br>
+ int position = 0;<br>
+<br>
+ wl_list_for_each_reverse(output, &output_list, link) {<br>
+ output->offset_x = position;<br>
+ position += output->width;<br>
+ }<br>
+<br>
+ wl_list_for_each(output, &output_list, link) {<br>
+ min_x = MIN(min_x, output->offset_x);<br>
+ min_y = MIN(min_y, output->offset_y);<br>
+ max_x = MAX(max_x, output->offset_x + output->width);<br>
+ max_y = MAX(max_y, output->offset_y + output->height);<br>
+ }<br>
+<br>
+ if (max_x <= min_x || max_y <= min_y)<br>
+ return -1;<br>
+<br>
+ *width = max_x - min_x;<br>
+ *height = max_y - min_y;<br>
+<br>
+ return 0;<br>
+}<br>
+<br>
+static int<br>
+handle_input(int fd)<br>
+{<br>
+ char buffer[16];<br>
+ int n = read(fd, buffer, 16);<br>
+ if (n < 0) return 0;<br>
+<br>
+ if (buffer[0] != 0x1b) {<br>
+ remote_seat_send_key(remote_seat, buffer[0], 1);<br>
+ remote_seat_send_key(remote_seat, buffer[0], 0);<br>
+ return 0;<br>
+ }<br>
+<br>
+ if (n == 1) return -1; // Escape key<br>
+ if (n < 3) return 0;<br>
+ switch (buffer[2]) {<br>
+ case 0x41:<br>
+ ptr_y -= 10;<br>
+ remote_seat_move_pointer(remote_seat,<br>
+ wl_fixed_from_int(ptr_x),<br>
+ wl_fixed_from_int(ptr_y), 0);<br>
+ break;<br>
+ case 0x42:<br>
+ ptr_y += 10;<br>
+ remote_seat_move_pointer(remote_seat,<br>
+ wl_fixed_from_int(ptr_x),<br>
+ wl_fixed_from_int(ptr_y), 0);<br>
+ break;<br>
+ case 0x43:<br>
+ ptr_x += 10;<br>
+ remote_seat_move_pointer(remote_seat,<br>
+ wl_fixed_from_int(ptr_x),<br>
+ wl_fixed_from_int(ptr_y), 0);<br>
+ break;<br>
+ case 0x44:<br>
+ ptr_x -= 10;<br>
+ remote_seat_move_pointer(remote_seat,<br>
+ wl_fixed_from_int(ptr_x),<br>
+ wl_fixed_from_int(ptr_y), 0);<br>
+ break;<br>
+ case 0x32:<br>
+ remote_seat_pointer_button(remote_seat, BTN_LEFT, 1);<br>
+ remote_seat_pointer_button(remote_seat, BTN_LEFT, 0);<br>
+ break;<br>
+ case 0x31:<br>
+ remote_seat_pointer_button(remote_seat, BTN_RIGHT, 1);<br>
+ remote_seat_pointer_button(remote_seat, BTN_RIGHT, 0);<br>
+ break;<br>
+ case 0x33:<br>
+ remote_seat_pointer_button(remote_seat, BTN_MIDDLE, 1);<br>
+ remote_seat_pointer_button(remote_seat, BTN_MIDDLE, 0);<br>
+ break;<br>
+ case 0x35:<br>
+ remote_seat_pointer_axis(remote_seat,<br>
+ WL_POINTER_AXIS_VERTICAL_SCROLL,<br>
+ wl_fixed_from_int(-10));<br>
+ break;<br>
+ case 0x36:<br>
+ remote_seat_pointer_axis(remote_seat,<br>
+ WL_POINTER_AXIS_VERTICAL_SCROLL,<br>
+ wl_fixed_from_int(10));<br>
+ break;<br>
+ }<br>
+ return 0;<br>
+}<br>
+<br>
+int<br>
+main(int argc, char *argv[])<br>
+{<br>
+ struct wl_display *display;<br>
+ struct wl_registry *registry;<br>
+ struct remote_access_output *output;<br>
+ struct timeval update_time;<br>
+ struct termios old_termios, new_termios;<br>
+ int fd_wl;<br>
+ int fd_in = 0;<br>
+ int width, height;<br>
+ int seq = 0;<br>
+<br>
+ display = wl_display_connect(NULL);<br>
+ if (display == NULL) {<br>
+ fprintf(stderr, "failed to create display: %m\n");<br>
+ return -1;<br>
+ }<br>
+ fd_wl = wl_display_get_fd(display);<br>
+<br>
+ wl_list_init(&output_list);<br>
+ registry = wl_display_get_registry(display);<br>
+ wl_registry_add_listener(registry, ®istry_listener, NULL);<br>
+ wl_display_dispatch(display);<br>
+ wl_display_roundtrip(display);<br>
+ if (remote_access == NULL) {<br>
+ fprintf(stderr, "display doesn't support remote_access\n");<br>
+ return -1;<br>
+ }<br>
+<br>
+ remote_seat = remote_access_create_seat(remote_access, "remote-test");<br>
+ ptr_x = 100; ptr_y=100;<br>
+<br>
+ tcgetattr(fd_in, &old_termios);<br>
+ new_termios = old_termios;<br>
+ new_termios.c_lflag &= (~ICANON);<br>
+ new_termios.c_lflag &= (~ECHO);<br>
+ new_termios.c_cc[VTIME] = 0;<br>
+ new_termios.c_cc[VMIN] = 1;<br>
+ tcsetattr(fd_in, TCSANOW, &new_termios);<br>
+<br>
+ if (set_buffer_size(&width, &height))<br>
+ return -1;<br>
+<br>
+ wl_list_for_each(output, &output_list, link) {<br>
+ output->buffer = create_shm_buffer(output->width,<br>
+ output->height,<br>
+ &output->data);<br>
+<br>
+ struct remote_capture* capture =<br>
+ remote_access_create_capture(remote_access,<br>
+ output->output,<br>
+ output->buffer);<br>
+ remote_capture_add_listener(capture, &remote_capture_listener,<br>
+ capture);<br>
+ remote_capture_start(capture);<br>
+ remote_capture_refresh(capture);<br>
+ }<br>
+<br>
+ gettimeofday(&update_time, NULL);<br>
+ updates = 0;<br>
+<br>
+ wl_display_roundtrip(display);<br>
+<br>
+ while (1) {<br>
+ fd_set fds_read;<br>
+ struct timeval timeout;<br>
+ struct timeval current_time;<br>
+ long int delta;<br>
+ char filename[PATH_MAX];<br>
+<br>
+ FD_ZERO(&fds_read);<br>
+ FD_SET(fd_wl, &fds_read);<br>
+ FD_SET(fd_in, &fds_read);<br>
+<br>
+ timeout.tv_usec = 100; timeout.tv_sec = 0;<br>
+ select(fd_wl+1, &fds_read, NULL, NULL, &timeout);<br>
+<br>
+ if (FD_ISSET(fd_in, &fds_read)) {<br>
+ if (handle_input(fd_in) < 0)<br>
+ break;<br>
+ }<br>
+<br>
+ wl_display_roundtrip(display);<br>
+<br>
+ gettimeofday(¤t_time, NULL);<br>
+ delta = (current_time.tv_usec - update_time.tv_usec) +<br>
+ (current_time.tv_sec - update_time.tv_sec) * US_PER_SECOND;<br>
+ if (updates && delta >= max_update_time) {<br>
+ sprintf(filename, "remote-%04d.png", ++seq);<br>
+ fprintf(stdout, "Writing %s [%d updates / %f s]\n",<br>
+ filename, updates, (float)delta/US_PER_SECOND);<br>
+<br>
+ write_png(filename, width, height);<br>
+<br>
+ update_time.tv_sec = current_time.tv_sec;<br>
+ update_time.tv_usec = current_time.tv_usec;<br>
+ updates = 0;<br>
+ }<br>
+ }<br>
+<br>
+ tcsetattr(fd_in, TCSANOW, &old_termios);<br>
+<br>
+ //TODO: destroy remote_captures<br>
+ remote_seat_destroy(remote_seat);<br>
+ remote_access_destroy(remote_access);<br>
+<br>
+ return 0;<br>
+}<br>
diff --git a/<a href="http://configure.ac" target="_blank">configure.ac</a> b/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
index 950086d..c069885 100644<br>
--- a/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
+++ b/<a href="http://configure.ac" target="_blank">configure.ac</a><br>
@@ -379,6 +379,13 @@ if test "x$enable_colord" != "xno"; then<br>
fi<br>
AM_CONDITIONAL(ENABLE_COLORD, test "x$enable_colord" = "xyes")<br>
<br>
+# Remote access module<br>
+AC_ARG_ENABLE(remote-access,<br>
+ AS_HELP_STRING([--disable-remote-access],<br>
+ [do not build remote access support]),,<br>
+ enable_remote_access=auto)<br>
+AM_CONDITIONAL(ENABLE_REMOTE_ACCESS, test "x$enable_remote_access" = "xyes")<br>
+<br>
AC_ARG_ENABLE(wcap-tools, [ --disable-wcap-tools],, enable_wcap_tools=yes)<br>
AM_CONDITIONAL(BUILD_WCAP_TOOLS, test x$enable_wcap_tools = xyes)<br>
if test x$enable_wcap_tools = xyes; then<br>
@@ -497,4 +504,5 @@ AC_MSG_RESULT([<br>
libwebp Support ${have_webp}<br>
libunwind Support ${have_libunwind}<br>
VA H.264 encoding Support ${have_libva}<br>
+ Remote access Support ${enable_remote_access}<br>
])<br>
diff --git a/protocol/Makefile.am b/protocol/Makefile.am<br>
index 924e48f..b889ce4 100644<br>
--- a/protocol/Makefile.am<br>
+++ b/protocol/Makefile.am<br>
@@ -8,4 +8,5 @@ EXTRA_DIST = \<br>
workspaces.xml \<br>
subsurface.xml \<br>
text-cursor-position.xml \<br>
- wayland-test.xml<br>
+ wayland-test.xml \<br>
+ remote-access.xml<br>
diff --git a/protocol/remote-access.xml b/protocol/remote-access.xml<br>
new file mode 100644<br>
index 0000000..a66d526<br>
--- /dev/null<br>
+++ b/protocol/remote-access.xml<br>
@@ -0,0 +1,160 @@<br>
+<protocol name="remote_access"><br>
+<br>
+ <copyright><br>
+ Copyright © 2013 RealVNC Limited<br>
+<br>
+ Permission to use, copy, modify, distribute, and sell this<br>
+ software and its documentation for any purpose is hereby granted<br>
+ without fee, provided that the above copyright notice appear in<br>
+ all copies and that both that copyright notice and this permission<br>
+ notice appear in supporting documentation, and that the name of<br>
+ the copyright holders not be used in advertising or publicity<br>
+ pertaining to distribution of the software without specific,<br>
+ written prior permission. The copyright holders make no<br>
+ representations about the suitability of this software for any<br>
+ purpose. It is provided "as is" without express or implied<br>
+ warranty.<br>
+<br>
+ THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS<br>
+ SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND<br>
+ FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY<br>
+ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES<br>
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN<br>
+ AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,<br>
+ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF<br>
+ THIS SOFTWARE.<br>
+ </copyright><br>
+<br>
+ <interface name="remote_capture" version="1"><br>
+ <description summary="Output capture for remote access"><br>
+ Allows a particular output to be captured, and provides notifications<br>
+ whenever updates occur.<br>
+ </description><br>
+<br>
+ <request name="destroy" type="destructor"><br>
+ <description summary="Destroy output capture"><br>
+ Destroy the output capture object.<br>
+ </description><br>
+ </request><br>
+<br>
+ <request name="refresh"><br>
+ <description summary="Request a single capture"><br>
+ Request a single capture of the output.<br>
+ An update event is sent when the capture data is ready in the buffer.<br>
+ </description><br>
+ </request><br>
+<br>
+ <request name="start"><br>
+ <description summary="Start continuous capture"><br>
+ Request that the output is captured continuously.<br>
+ An update event is sent whenever the output changes.<br>
+ </description><br>
+ </request><br>
+<br>
+ <request name="stop"><br>
+ <description summary="Stop continuous capture"><br>
+ Stop an ongoing continuous capture. No more updates will be sent.<br>
+ </description><br>
+ </request><br>
+<br>
+ <event name="update"><br>
+ <description summary="Notification of an update"><br>
+ Notification that an area of the output has changed.<br>
+ The arguments x,y,width,height describe the rectangle that changed.<br>
+ </description><br>
+ <arg name="x" type="int"/><br>
+ <arg name="y" type="int"/><br>
+ <arg name="width" type="int"/><br>
+ <arg name="height" type="int"/><br>
+ </event><br>
+ </interface><br>
+<br>
+ <interface name="remote_seat" version="1"><br>
+ <description summary="Handles input events for remote access"><br>
+ Allows remote access clients to inject input events. The remote access<br>
+ system may choose to create separate remote seats for each of its clients,<br>
+ or have them all use a single seat.<br>
+ </description><br>
+<br>
+ <request name="destroy" type="destructor"><br>
+ <description summary="Destroy remote seat"><br>
+ Destroy the remote seat object.<br>
+ </description><br>
+ </request><br>
+<br>
+ <request name="move_pointer"><br>
+ <description summary="Send pointer movement event"><br>
+ Inject a pointer movement event from the remote system.<br>
+ </description><br>
+ <arg name="x" type="fixed"/><br>
+ <arg name="y" type="fixed"/><br>
+ <arg name="relative" type="uint"/><br>
+ </request><br>
+<br>
+ <request name="pointer_button"><br>
+ <description summary="Send pointer button event"><br>
+ Inject a pointer button event from the remote system.<br>
+ </description><br>
+ <arg name="button" type="uint"/><br>
+ <arg name="state" type="uint"/><br>
+ </request><br>
+<br>
+ <request name="pointer_axis"><br>
+ <description summary="Send pointer axis event"><br>
+ Inject a pointer axis event from the remote system.<br>
+ </description><br>
+ <arg name="axis" type="uint"/><br>
+ <arg name="value" type="fixed"/><br>
+ </request><br>
+<br>
+ <request name="send_key"><br>
+ <description summary="Send keyboard event"><br>
+ Inject a keyboard event from the remote system.<br>
+ </description><br>
+ <arg name="key" type="uint"/><br>
+ <arg name="state" type="uint"/><br>
+ </request><br>
+<br>
+ </interface><br>
+<br>
+ <interface name="remote_access" version="1"><br>
+ <description summary="Interface for remote access systems"><br>
+ This global interface is intended to support remote access systems.<br>
+ It allows screen outputs to be captured, and mouse and keyboard events<br>
+ to be injected from the remote system.<br>
+ </description><br>
+<br>
+ <request name="create_capture"><br>
+ <description summary="Create an output capture object"><br>
+ Creates an object that can be used to capture the specified output.<br>
+ A buffer must be supplied, into which the image from the output is<br>
+ copied. This must be in XRGB8888 format and large enough to contain<br>
+ the image.<br>
+ </description><br>
+ <arg name="capture" type="new_id" interface="remote_capture"/><br>
+ <arg name="output" type="object" interface="wl_output"/><br>
+ <arg name="buffer" type="object" interface="wl_buffer"/><br>
+ </request><br>
+<br>
+ <request name="create_seat"><br>
+ <description summary="Create a new remote seat"><br>
+ Creates an object that can be used to send input events into the system<br>
+ from a new remote seat.<br>
+ </description><br>
+ <arg name="seat" type="new_id" interface="remote_seat"/><br>
+ <arg name="name" type="string"/><br>
+ </request><br>
+<br>
+ <request name="create_existing_seat"><br>
+ <description summary="Create a remote seat for an existing local seat"><br>
+ Creates an object that can be used to send input events into the system<br>
+ from an existing seat.<br>
+ The name argument must correspond to the name of an existing wl_seat.<br>
+ </description><br>
+ <arg name="seat" type="new_id" interface="remote_seat"/><br>
+ <arg name="name" type="string"/><br>
+ </request><br>
+<br>
+ </interface><br>
+<br>
+</protocol><br>
diff --git a/src/.gitignore b/src/.gitignore<br>
index 539150d..cae3316 100644<br>
--- a/src/.gitignore<br>
+++ b/src/.gitignore<br>
@@ -21,4 +21,6 @@ input-method-protocol.c<br>
input-method-server-protocol.h<br>
subsurface-server-protocol.h<br>
subsurface-protocol.c<br>
+remote-access-protocol.c<br>
+remote-access-server-protocol.h<br>
<br>
diff --git a/src/Makefile.am b/src/Makefile.am<br>
index b0eae7c..def50b9 100644<br>
--- a/src/Makefile.am<br>
+++ b/src/Makefile.am<br>
@@ -97,6 +97,7 @@ module_LTLIBRARIES = \<br>
$(cms_static) \<br>
$(cms_colord) \<br>
$(gl_renderer) \<br>
+ $(remote_access) \<br>
$(x11_backend) \<br>
$(drm_backend) \<br>
$(wayland_backend) \<br>
@@ -302,6 +303,17 @@ cms_colord_la_SOURCES = \<br>
endif<br>
endif<br>
<br>
+if ENABLE_REMOTE_ACCESS<br>
+remote_access = <a href="http://remote-access.la" target="_blank">remote-access.la</a><br>
+remote_access_la_LDFLAGS = -module -avoid-version<br>
+remote_access_la_LIBADD = $(COMPOSITOR_LIBS) $(REMOTE_ACCESS_LIBS)<br>
+remote_access_la_CFLAGS = $(GCC_CFLAGS) $(COMPOSITOR_CFLAGS) $(REMOTE_ACCESS_CFLAGS)<br>
+remote_access_la_SOURCES = \<br>
+ remote-access.c \<br>
+ remote-access-protocol.c \<br>
+ remote-access-server-protocol.h<br>
+endif<br>
+<br>
noinst_PROGRAMS = spring-tool<br>
<br>
spring_tool_CFLAGS = $(GCC_CFLAGS) $(COMPOSITOR_CFLAGS)<br>
@@ -330,6 +342,8 @@ BUILT_SOURCES = \<br>
workspaces-protocol.c \<br>
subsurface-server-protocol.h \<br>
subsurface-protocol.c \<br>
+ remote-access-protocol.c \<br>
+ remote-access-server-protocol.h \<br>
git-version.h<br>
<br>
CLEANFILES = $(BUILT_SOURCES)<br>
diff --git a/src/remote-access.c b/src/remote-access.c<br>
new file mode 100644<br>
index 0000000..68087cc<br>
--- /dev/null<br>
+++ b/src/remote-access.c<br>
@@ -0,0 +1,612 @@<br>
+/*<br>
+ * Copyright © 2013 RealVNC Limited<br>
+ *<br>
+ * Permission to use, copy, modify, distribute, and sell this software and<br>
+ * its documentation for any purpose is hereby granted without fee, provided<br>
+ * that the above copyright notice appear in all copies and that both that<br>
+ * copyright notice and this permission notice appear in supporting<br>
+ * documentation, and that the name of the copyright holders not be used in<br>
+ * advertising or publicity pertaining to distribution of the software<br>
+ * without specific, written prior permission. The copyright holders make<br>
+ * no representations about the suitability of this software for any<br>
+ * purpose. It is provided "as is" without express or implied warranty.<br>
+ *<br>
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS<br>
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND<br>
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY<br>
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER<br>
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF<br>
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN<br>
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.<br>
+ */<br>
+<br>
+#include "config.h"<br>
+<br>
+#include <unistd.h><br>
+#include <stdio.h><br>
+#include <stdlib.h><br>
+#include <string.h><br>
+#include <stdbool.h><br>
+#include <linux/input.h><br>
+<br>
+#include "compositor.h"<br>
+#include "remote-access-server-protocol.h"<br>
+<br>
+<br>
+struct remote_capture {<br>
+ struct wl_listener listener;<br>
+ struct weston_buffer *buffer;<br>
+ struct wl_resource *resource;<br>
+ struct weston_output *output;<br>
+ uint32_t flags;<br>
+};<br>
+<br>
+enum remote_capture_flags {<br>
+ CAPTURE_REFRESHING = (1 << 0),<br>
+ CAPTURE_CONTINUOUS = (1 << 1)<br>
+};<br>
+<br>
+struct remote_seat {<br>
+ struct weston_seat *seat;<br>
+ struct wl_resource *resource;<br>
+ uint32_t flags;<br>
+};<br>
+<br>
+enum remote_seat_flags {<br>
+ SEAT_EXISTING = (1 << 0)<br>
+};<br>
+<br>
+struct remote_access {<br>
+ struct weston_compositor *ec;<br>
+ struct wl_global *global;<br>
+ struct wl_listener destroy_listener;<br>
+};<br>
+<br>
+<br>
+/* Utils */<br>
+<br>
+static void<br>
+copy_bgra_yflip(uint8_t *dst, uint8_t *src, int height, int stride)<br>
+{<br>
+ uint8_t *end;<br>
+<br>
+ end = dst + height * stride;<br>
+ while (dst < end) {<br>
+ memcpy(dst, src, stride);<br>
+ dst += stride;<br>
+ src -= stride;<br>
+ }<br>
+}<br>
+<br>
+static void<br>
+copy_bgra(uint8_t *dst, uint8_t *src, int height, int stride)<br>
+{<br>
+ /* TODO: optimize this out */<br>
+ memcpy(dst, src, height * stride);<br>
+}<br>
+<br>
+static void<br>
+copy_row_swap_RB(void *vdst, void *vsrc, int bytes)<br>
+{<br>
+ uint32_t *dst = vdst;<br>
+ uint32_t *src = vsrc;<br>
+ uint32_t *end = dst + bytes / 4;<br>
+<br>
+ while (dst < end) {<br>
+ uint32_t v = *src++;<br>
+ /* A R G B */<br>
+ uint32_t tmp = v & 0xff00ff00;<br>
+ tmp |= (v >> 16) & 0x000000ff;<br>
+ tmp |= (v << 16) & 0x00ff0000;<br>
+ *dst++ = tmp;<br>
+ }<br>
+}<br>
+<br>
+static void<br>
+copy_rgba_yflip(uint8_t *dst, uint8_t *src, int height, int stride)<br>
+{<br>
+ uint8_t *end;<br>
+<br>
+ end = dst + height * stride;<br>
+ while (dst < end) {<br>
+ copy_row_swap_RB(dst, src, stride);<br>
+ dst += stride;<br>
+ src -= stride;<br>
+ }<br>
+}<br>
+<br>
+static void<br>
+copy_rgba(uint8_t *dst, uint8_t *src, int height, int stride)<br>
+{<br>
+ uint8_t *end;<br>
+<br>
+ end = dst + height * stride;<br>
+ while (dst < end) {<br>
+ copy_row_swap_RB(dst, src, stride);<br>
+ dst += stride;<br>
+ src += stride;<br>
+ }<br>
+}<br>
+<br>
+<br>
+/* --- remote-capture --- */<br>
+<br>
+static void<br>
+remote_capture_frame_notify(struct wl_listener *listener, void *data);<br>
+<br>
+static void<br>
+remote_capture_setup_listener(struct remote_capture *capture)<br>
+{<br>
+ if (capture->listener.notify == NULL &&<br>
+ capture->flags != 0) {<br>
+ /* Listener is required but not currently set */<br>
+ capture->listener.notify = remote_capture_frame_notify;<br>
+ wl_signal_add(&capture->output->frame_signal,<br>
+ &capture->listener);<br>
+ } else if (capture->listener.notify &&<br>
+ capture->flags == 0) {<br>
+ /* Listener isn't required but is currently set */<br>
+ wl_list_remove(&capture->listener.link);<br>
+ capture->listener.notify = NULL;<br>
+ }<br>
+}<br>
+<br>
+static void<br>
+remote_capture_frame_notify(struct wl_listener *listener, void *data)<br>
+{<br>
+ struct remote_capture *capture =<br>
+ container_of(listener, struct remote_capture, listener);<br>
+ struct weston_output *output = data;<br>
+ struct weston_compositor *compositor = output->compositor;<br>
+<br>
+ weston_log("remote-capture: frame_notify\n");<br>
+<br>
+ pixman_box32_t *r;<br>
+ pixman_box32_t tr;<br>
+ pixman_region32_t damage;<br>
+ int i, n, stride;<br>
+ uint8_t *pixels, *d, *s;<br>
+<br>
+ stride = capture->buffer->width *<br>
+ (PIXMAN_FORMAT_BPP(compositor->read_format) / 8);<br>
+ pixels = malloc(stride * capture->buffer->height);<br>
+<br>
+ compositor->renderer->read_pixels(output, compositor->read_format,<br>
+ pixels,<br>
+ 0, 0,<br>
+ output->current_mode->width,<br>
+ output->current_mode->height);<br>
+<br>
+ d = wl_shm_buffer_get_data(capture->buffer->shm_buffer);<br>
+ s = pixels + stride * (capture->buffer->height - 1);<br>
+<br>
+ switch (compositor->read_format) {<br>
+ case PIXMAN_a8r8g8b8:<br>
+ case PIXMAN_x8r8g8b8:<br>
+ if (compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP)<br>
+ copy_bgra_yflip(d, s, output->current_mode->height,<br>
+ stride);<br>
+ else<br>
+ copy_bgra(d, pixels, output->current_mode->height,<br>
+ stride);<br>
+ break;<br>
+ case PIXMAN_x8b8g8r8:<br>
+ case PIXMAN_a8b8g8r8:<br>
+ if (compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP)<br>
+ copy_rgba_yflip(d, s, output->current_mode->height,<br>
+ stride);<br>
+ else<br>
+ copy_rgba(d, pixels, output->current_mode->height,<br>
+ stride);<br>
+ break;<br>
+ default:<br>
+ break;<br>
+ }<br>
+ free(pixels);<br>
+<br>
+ pixman_region32_init(&damage);<br>
+ pixman_region32_intersect(&damage, &output->region,<br>
+ &output->previous_damage);<br>
+<br>
+ r = pixman_region32_rectangles(&damage, &n);<br>
+ if (n >= 0) {<br>
+ for (i = 0; i < n; i++) {<br>
+ tr = weston_transformed_rect(output->width,<br>
+ output->height,<br>
+ output->transform,<br>
+ output->current_scale,<br>
+ r[i]);<br>
+ remote_capture_send_update(capture->resource,<br>
+ tr.x1,<br>
+ tr.y1,<br>
+ tr.x2-tr.x1,<br>
+ tr.y2-tr.y1);<br>
+ }<br>
+ }<br>
+ pixman_region32_fini(&damage);<br>
+<br>
+ capture->flags &= ~CAPTURE_REFRESHING;<br>
+ remote_capture_setup_listener(capture);<br>
+}<br>
+<br>
+static void<br>
+remote_capture_destroy_handler(struct wl_resource *resource)<br>
+{<br>
+ struct remote_capture *capture =<br>
+ wl_resource_get_user_data(resource);<br>
+ capture->flags = 0;<br>
+ remote_capture_setup_listener(capture);<br>
+ free(capture);<br>
+}<br>
+<br>
+static void<br>
+remote_capture_destroy(struct wl_client *client,<br>
+ struct wl_resource *resource)<br>
+{<br>
+ wl_resource_destroy(resource);<br>
+}<br>
+<br>
+static void<br>
+remote_capture_refresh(struct wl_client *client,<br>
+ struct wl_resource *resource)<br>
+{<br>
+ struct remote_capture *capture =<br>
+ wl_resource_get_user_data(resource);<br>
+ struct weston_output *output = capture->output;<br>
+<br>
+ capture->flags |= CAPTURE_REFRESHING;<br>
+ remote_capture_setup_listener(capture);<br>
+ weston_output_damage(output);<br>
+}<br>
+<br>
+static void<br>
+remote_capture_start(struct wl_client *client,<br>
+ struct wl_resource *resource)<br>
+{<br>
+ struct remote_capture *capture =<br>
+ wl_resource_get_user_data(resource);<br>
+<br>
+ capture->flags |= CAPTURE_CONTINUOUS;<br>
+ remote_capture_setup_listener(capture);<br>
+}<br>
+<br>
+static void<br>
+remote_capture_stop(struct wl_client *client,<br>
+ struct wl_resource *resource)<br>
+{<br>
+ struct remote_capture *capture =<br>
+ wl_resource_get_user_data(resource);<br>
+<br>
+ capture->flags &= ~CAPTURE_CONTINUOUS;<br>
+ remote_capture_setup_listener(capture);<br>
+}<br>
+<br>
+struct remote_capture_interface remote_capture_implementation = {<br>
+ remote_capture_destroy,<br>
+ remote_capture_refresh,<br>
+ remote_capture_start,<br>
+ remote_capture_stop<br>
+};<br>
+<br>
+<br>
+/* --- remote-seat --- */<br>
+<br>
+static void<br>
+remote_seat_destroy_handler(struct wl_resource *resource)<br>
+{<br>
+ weston_log("remote-seat: destroy handler\n");<br>
+ struct remote_seat *rseat =<br>
+ wl_resource_get_user_data(resource);<br>
+ if (!(rseat->flags & SEAT_EXISTING)) {<br>
+ /* Release the seat if we created it */<br>
+ weston_seat_release(rseat->seat);<br>
+ free(rseat->seat);<br>
+ }<br>
+ free(rseat);<br>
+}<br>
+<br>
+static void<br>
+remote_seat_destroy(struct wl_client *client,<br>
+ struct wl_resource *resource)<br>
+{<br>
+ weston_log("remote-seat: destroy\n");<br>
+ wl_resource_destroy(resource);<br>
+}<br>
+<br>
+static void<br>
+remote_seat_move_pointer(struct wl_client *client,<br>
+ struct wl_resource *resource,<br>
+ wl_fixed_t x, wl_fixed_t y,<br>
+ uint32_t relative)<br>
+{<br>
+ struct remote_seat *rseat = wl_resource_get_user_data(resource);<br>
+ uint32_t time = weston_compositor_get_time();<br>
+<br>
+ if (relative) {<br>
+ notify_motion(rseat->seat, time, x, y);<br>
+ } else {<br>
+ notify_motion_absolute(rseat->seat, time, x, y);<br>
+ }<br>
+}<br>
+<br>
+static void<br>
+remote_seat_pointer_button(struct wl_client *client,<br>
+ struct wl_resource *resource,<br>
+ uint32_t button, uint32_t state)<br>
+{<br>
+ struct remote_seat *rseat = wl_resource_get_user_data(resource);<br>
+ uint32_t time = weston_compositor_get_time();<br>
+<br>
+ weston_log("remote-seat[%p]: pointer_button( button=%u, state=%u )\n",<br>
+ rseat, button, state);<br>
+<br>
+ notify_button(rseat->seat, time, button,<br>
+ state ? WL_POINTER_BUTTON_STATE_PRESSED :<br>
+ WL_POINTER_BUTTON_STATE_RELEASED);<br>
+}<br>
+<br>
+static void<br>
+remote_seat_pointer_axis(struct wl_client *client,<br>
+ struct wl_resource *resource,<br>
+ uint32_t axis, wl_fixed_t value)<br>
+{<br>
+ struct remote_seat *rseat = wl_resource_get_user_data(resource);<br>
+ uint32_t time = weston_compositor_get_time();<br>
+<br>
+ weston_log("remote-seat[%p]: pointer_axis( axis=%u, value=%g )\n",<br>
+ rseat, axis, wl_fixed_to_double(value));<br>
+<br>
+ notify_axis(rseat->seat, time, axis, value);<br>
+}<br>
+<br>
+static void<br>
+remote_seat_send_key(struct wl_client *client,<br>
+ struct wl_resource *resource,<br>
+ uint32_t key, uint32_t state)<br>
+{<br>
+ struct remote_seat *rseat = wl_resource_get_user_data(resource);<br>
+<br>
+ weston_log("remote-seat[%p]: send_key( key=%u, state=%u )\n",<br>
+ rseat, key, state);<br>
+<br>
+ notify_key(rseat->seat, weston_compositor_get_time(), key,<br>
+ state ? WL_KEYBOARD_KEY_STATE_PRESSED :<br>
+ WL_KEYBOARD_KEY_STATE_RELEASED,<br>
+ STATE_UPDATE_AUTOMATIC);<br>
+}<br>
+<br>
+struct remote_seat_interface remote_seat_implementation = {<br>
+ remote_seat_destroy,<br>
+ remote_seat_move_pointer,<br>
+ remote_seat_pointer_button,<br>
+ remote_seat_pointer_axis,<br>
+ remote_seat_send_key<br>
+};<br>
+<br>
+<br>
+/* --- remote-access --- */<br>
+<br>
+static void<br>
+remote_buffer_destroy_handler(struct wl_listener *listener, void* data)<br>
+{<br>
+ struct weston_buffer *buffer =<br>
+ container_of(listener, struct weston_buffer, destroy_listener);<br>
+<br>
+ wl_signal_emit(&buffer->destroy_signal, buffer);<br>
+ free(buffer);<br>
+}<br>
+<br>
+static struct weston_buffer*<br>
+remote_buffer_from_resource(struct wl_resource *resource)<br>
+{<br>
+ struct weston_buffer *buffer;<br>
+ struct wl_listener *listener;<br>
+<br>
+ listener = wl_resource_get_destroy_listener(resource,<br>
+ remote_buffer_destroy_handler);<br>
+<br>
+ if (listener)<br>
+ return container_of(listener, struct weston_buffer,<br>
+ destroy_listener);<br>
+<br>
+ buffer = zalloc(sizeof *buffer);<br>
+ if (buffer == NULL)<br>
+ return NULL;<br>
+<br>
+ buffer->resource = resource;<br>
+ wl_signal_init(&buffer->destroy_signal);<br>
+ buffer->destroy_listener.notify = remote_buffer_destroy_handler;<br>
+ wl_resource_add_destroy_listener(resource,<br>
+ &buffer->destroy_listener);<br>
+ return buffer;<br>
+}<br>
+<br>
+static void<br>
+remote_access_create_capture(struct wl_client *client,<br>
+ struct wl_resource *resource,<br>
+ uint32_t id,<br>
+ struct wl_resource *output_resource,<br>
+ struct wl_resource *buffer_resource)<br>
+{<br>
+ struct weston_output *output =<br>
+ wl_resource_get_user_data(output_resource);<br>
+ struct weston_buffer *buffer =<br>
+ remote_buffer_from_resource(buffer_resource);<br>
+ struct remote_capture* capture = zalloc(sizeof *capture);<br>
+<br>
+ weston_log("remote-access: create_capture\n");<br>
+<br>
+ if (capture == NULL) {<br>
+ wl_resource_post_no_memory(resource);<br>
+ return;<br>
+ }<br>
+<br>
+ capture->resource = wl_resource_create(client,<br>
+ &remote_capture_interface,<br>
+ 1, id);<br>
+ wl_resource_set_implementation(capture->resource,<br>
+ &remote_capture_implementation,<br>
+ capture,<br>
+ remote_capture_destroy_handler);<br>
+<br>
+ buffer->shm_buffer = wl_shm_buffer_get(buffer->resource);<br>
+ if (!buffer->shm_buffer)<br>
+ return;<br>
+<br>
+ buffer->width = wl_shm_buffer_get_width(buffer->shm_buffer);<br>
+ buffer->height = wl_shm_buffer_get_height(buffer->shm_buffer);<br>
+ if (buffer->width < output->current_mode->width ||<br>
+ buffer->height < output->current_mode->height)<br>
+ return;<br>
+<br>
+ capture->buffer = buffer;<br>
+ capture->output = output;<br>
+}<br>
+<br>
+static void<br>
+remote_access_create_seat(struct wl_client *client,<br>
+ struct wl_resource *resource,<br>
+ uint32_t id,<br>
+ const char* name)<br>
+{<br>
+ struct remote_access *remote =<br>
+ wl_resource_get_user_data(resource);<br>
+<br>
+ struct remote_seat *rseat = zalloc(sizeof *rseat);<br>
+ if (rseat == NULL) {<br>
+ wl_resource_post_no_memory(resource);<br>
+ return;<br>
+ }<br>
+<br>
+ rseat->seat = zalloc(sizeof *rseat->seat);<br>
+ if (rseat->seat == NULL) {<br>
+ wl_resource_post_no_memory(resource);<br>
+ return;<br>
+ }<br>
+<br>
+ rseat->resource = wl_resource_create(client,<br>
+ &remote_seat_interface,<br>
+ 1, id);<br>
+ wl_resource_set_implementation(rseat->resource,<br>
+ &remote_seat_implementation,<br>
+ rseat,<br>
+ remote_seat_destroy_handler);<br>
+<br>
+ weston_seat_init(rseat->seat, remote->ec, name);<br>
+ weston_seat_init_pointer(rseat->seat);<br>
+ weston_seat_init_keyboard(rseat->seat, NULL);<br>
+}<br>
+<br>
+static void<br>
+remote_access_create_existing_seat(struct wl_client *client,<br>
+ struct wl_resource *resource,<br>
+ uint32_t id,<br>
+ const char* name)<br>
+{<br>
+ struct remote_access *remote =<br>
+ wl_resource_get_user_data(resource);<br>
+ struct weston_seat* seat;<br>
+ struct remote_seat *rseat = zalloc(sizeof *rseat);<br>
+ if (rseat == NULL) {<br>
+ wl_resource_post_no_memory(resource);<br>
+ return;<br>
+ }<br>
+<br>
+ wl_list_for_each(seat, &remote->ec->seat_list, link) {<br>
+ if (strcmp(seat->seat_name, name) == 0) {<br>
+ rseat->seat = seat;<br>
+ break;<br>
+ }<br>
+ }<br>
+<br>
+ if (!rseat->seat)<br>
+ return;<br>
+<br>
+ rseat->resource = wl_resource_create(client,<br>
+ &remote_seat_interface,<br>
+ 1, id);<br>
+ wl_resource_set_implementation(rseat->resource,<br>
+ &remote_seat_implementation,<br>
+ rseat,<br>
+ remote_seat_destroy_handler);<br>
+<br>
+ rseat->flags |= SEAT_EXISTING;<br>
+}<br>
+<br>
+struct remote_access_interface remote_access_implementation = {<br>
+ remote_access_create_capture,<br>
+ remote_access_create_seat,<br>
+ remote_access_create_existing_seat<br>
+};<br>
+<br>
+static void<br>
+unbind_remote_access(struct wl_resource *resource)<br>
+{<br>
+ weston_log("remote-access: unbind\n");<br>
+}<br>
+<br>
+static int<br>
+remote_client_check_permission(struct wl_client *client)<br>
+{<br>
+ pid_t pid; uid_t uid; gid_t gid;<br>
+ wl_client_get_credentials(client, &pid, &uid, &gid);<br>
+ /* TODO: Check if the client is allowed, somehow.<br>
+ Always allow for now */<br>
+ return 1;<br>
+}<br>
+<br>
+static void<br>
+bind_remote_access(struct wl_client *client,<br>
+ void *data, uint32_t version, uint32_t id)<br>
+{<br>
+ struct remote_access *remote = data;<br>
+ struct wl_resource *resource =<br>
+ wl_resource_create(client, &remote_access_interface, 1, id);<br>
+<br>
+ if (!remote_client_check_permission(client)) {<br>
+ wl_resource_post_error(resource,<br>
+ WL_DISPLAY_ERROR_INVALID_OBJECT,<br>
+ "remote-access: permission denied");<br>
+ wl_resource_destroy(resource);<br>
+ return;<br>
+ }<br>
+<br>
+ weston_log("remote-access: bind\n");<br>
+<br>
+ wl_resource_set_implementation(resource, &remote_access_implementation,<br>
+ remote, unbind_remote_access);<br>
+}<br>
+<br>
+static void<br>
+remote_module_destroy(struct wl_listener *listener, void *data)<br>
+{<br>
+ struct remote_access *remote =<br>
+ container_of(listener, struct remote_access, destroy_listener);<br>
+ weston_log("remote-access: destroy module\n");<br>
+ wl_global_destroy(remote->global);<br>
+ free(remote);<br>
+}<br>
+<br>
+WL_EXPORT int<br>
+module_init(struct weston_compositor *ec,<br>
+ int *argc, char *argv[])<br>
+{<br>
+ struct remote_access *remote;<br>
+ weston_log("remote-access: init module\n");<br>
+<br>
+ /* create local state object */<br>
+ remote = zalloc(sizeof *remote);<br>
+ if (remote == NULL)<br>
+ return -1;<br>
+ remote->ec = ec;<br>
+<br>
+ /* destroy listener */<br>
+ remote->destroy_listener.notify = remote_module_destroy;<br>
+ wl_signal_add(&ec->destroy_signal, &remote->destroy_listener);<br>
+<br>
+ /* Our global object */<br>
+ remote->global = wl_global_create(ec->wl_display,<br>
+ &remote_access_interface, 1,<br>
+ remote, bind_remote_access);<br>
+ return 0;<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.10.4<br>
_______________________________________________<br>
wayland-devel mailing list<br>
<a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
</font></span></blockquote></div><br></div>