Re: [RFC wayland-protocols] unstable: add protocol to give focus to a foreign surface

2018-07-10 Thread raof
On 10 July 2018 6:03:26 pm AEST, David Edmundson  
wrote:
>>Hm. If you wanted to, you could make this explicit by requiring an
>event serial in the export_surface request rather than the wl_surface.
>
>Certainly an option. Though I'm not sure we have a use case of needing
>to limit a client releasing its focus?

I can't think of one offhand. I just prefer the explicitness of “*this* user 
action caused us to request focus”.

That's just for delegating focus, though.

As Markus suggested, this *could* be a special case of a more general 
interface. We had this handle as MirCookie in Mir, and had a bunch of 
interfaces which requires a cookie. It turned out that a transferable token 
containing an unforgeable timestamp of a user interaction was a useful 
primitive.

>>Does this interface need to exist?
>
>It doesn't /need/ to, but I need to be able to export a handle
>multiple times and it's nice in the client to be able to match up
>requests with the reply.

This is also an advantage of the handle-for-serial style interface - the reply 
event can contain both the handle and the serial it's for, eliminating this 
otherwise superfluous interface.

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 1/2] server: Split out varargs version of wl_resource_post_error.

2018-02-19 Thread raof
From: Christopher James Halse Rogers 

This will allow other wrappers around wl_resource_post_error to accept
variable argument lists.

Signed-off-by: Christopher James Halse Rogers 

---
 src/wayland-server.c | 23 ---
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/wayland-server.c b/src/wayland-server.c
index eb1e500..00c93f7 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -273,17 +273,14 @@ wl_resource_queue_event(struct wl_resource *resource, 
uint32_t opcode, ...)
wl_resource_queue_event_array(resource, opcode, args);
 }
 
-WL_EXPORT void
-wl_resource_post_error(struct wl_resource *resource,
-  uint32_t code, const char *msg, ...)
+static void
+wl_resource_post_error_vargs(struct wl_resource *resource,
+uint32_t code, const char *msg, va_list argp)
 {
struct wl_client *client = resource->client;
char buffer[128];
-   va_list ap;
 
-   va_start(ap, msg);
-   vsnprintf(buffer, sizeof buffer, msg, ap);
-   va_end(ap);
+   vsnprintf(buffer, sizeof buffer, msg, argp);
 
/*
 * When a client aborts, its resources are destroyed in id order,
@@ -298,6 +295,18 @@ wl_resource_post_error(struct wl_resource *resource,
wl_resource_post_event(client->display_resource,
   WL_DISPLAY_ERROR, resource, code, buffer);
client->error = 1;
+
+}
+
+WL_EXPORT void
+wl_resource_post_error(struct wl_resource *resource,
+  uint32_t code, const char *msg, ...)
+{
+   va_list ap;
+
+   va_start(ap, msg);
+   wl_resource_post_error_vargs(resource, code, msg, ap);
+   va_end(ap);
 }
 
 static void
-- 
2.15.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


RFC - Add internal server error message

2018-02-19 Thread raof
Because C++ exceptions escaping into C FFI invokes undefined behaviour
our Wayland implementation wraps all the interface vtable callbacks
with try {} catch (...) { log_error }.

This has the nice property of not crashing the server, but does result
in the client and server having different ideas about the current state.

In the interests of debugability it would be nice to tell clients that
their request failed due to server error rather than silently continue
into unknown territory.

These patches introduce a WL_DISPLAY_ERROR_INTERNAL error the compositor
can send in such cases.

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 2/2] proto, server: Add internal server error message.

2018-02-19 Thread raof
From: Christopher James Halse Rogers 

Many languages such as C++ or Rust have an unwinding error-reporting
mechanism. Code in these languages can (and must!) wrap request handling
callbacks in unwind guards to avoid undefined behaviour.

As a consequence such code will detect internal server errors, but have
no way to communicate such failures to the client.

This adds a WL_DISPLAY_ERROR_INTERNAL error to wl_display so that
such code can notify (and disconnect) client which hit internal bugs.

Signed-off-by: Christopher James Halse Rogers 

---
 protocol/wayland.xml  |  2 ++
 src/wayland-client.c  |  3 +++
 src/wayland-server-core.h |  4 
 src/wayland-server.c  | 23 +++
 tests/display-test.c  | 40 
 5 files changed, 72 insertions(+)

diff --git a/protocol/wayland.xml b/protocol/wayland.xml
index b5662e0..1db31a6 100644
--- a/protocol/wayland.xml
+++ b/protocol/wayland.xml
@@ -94,6 +94,8 @@
 summary="method doesn't exist on the specified interface"/>
   
+  
 
 
 
diff --git a/src/wayland-client.c b/src/wayland-client.c
index c1369b8..7c442b1 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -192,6 +192,9 @@ display_protocol_error(struct wl_display *display, uint32_t 
code,
case WL_DISPLAY_ERROR_NO_MEMORY:
err = ENOMEM;
break;
+   case WL_DISPLAY_ERROR_INTERNAL:
+   err = EPROTO;
+   break;
default:
err = EFAULT;
}
diff --git a/src/wayland-server-core.h b/src/wayland-server-core.h
index 2e725d9..7137da6 100644
--- a/src/wayland-server-core.h
+++ b/src/wayland-server-core.h
@@ -324,6 +324,10 @@ wl_client_get_object(struct wl_client *client, uint32_t 
id);
 void
 wl_client_post_no_memory(struct wl_client *client);
 
+void
+wl_client_post_internal_error(struct wl_client *client,
+ const char* msg, ...) WL_PRINTF(2,3);
+
 void
 wl_client_add_resource_created_listener(struct wl_client *client,
 struct wl_listener *listener);
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 00c93f7..6317f8f 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -650,6 +650,29 @@ wl_client_post_no_memory(struct wl_client *client)
   WL_DISPLAY_ERROR_NO_MEMORY, "no memory");
 }
 
+/** Report an internal server error
+ *
+ * \param client The client object
+ * \param msg A printf-style format string
+ * \param ... Format string arguments
+ *
+ * Report an unspecified internal error and disconnect the client.
+ *
+ * \memberof wl_client
+ */
+WL_EXPORT void
+wl_client_post_internal_error(struct wl_client *client,
+ char const *msg, ...)
+{
+   va_list ap;
+
+   va_start(ap, msg);
+   wl_resource_post_error_vargs(client->display_resource,
+WL_DISPLAY_ERROR_INTERNAL,
+msg, ap);
+   va_end(ap);
+}
+
 WL_EXPORT void
 wl_resource_post_no_memory(struct wl_resource *resource)
 {
diff --git a/tests/display-test.c b/tests/display-test.c
index 9b49a0e..63f8b5a 100644
--- a/tests/display-test.c
+++ b/tests/display-test.c
@@ -419,6 +419,46 @@ TEST(post_nomem_tst)
display_destroy(d);
 }
 
+static void
+post_internal_error_main(void)
+{
+   struct client *c = client_connect();
+   struct wl_seat *seat = client_get_seat(c);
+   uint32_t object_id, protocol_error;
+   const struct wl_interface *interface;
+
+   assert(stop_display(c, 1) == -1);
+   int err = wl_display_get_error(c->wl_display);
+   fprintf(stderr, "Err is %i\n", err);
+   assert(err == EPROTO);
+   protocol_error = wl_display_get_protocol_error(c->wl_display,
+  ,
+  _id);
+   assert(protocol_error == WL_DISPLAY_ERROR_INTERNAL);
+   assert(interface == _display_interface);
+
+   wl_proxy_destroy((struct wl_proxy *) seat);
+   client_disconnect_nocheck(c);
+}
+
+TEST(post_internal_error_tst)
+{
+   struct display *d = display_create();
+   struct client_info *cl;
+
+   wl_global_create(d->wl_display, _seat_interface,
+1, d, bind_seat);
+
+   cl = client_create_noarg(d, post_internal_error_main);
+   display_run(d);
+
+   wl_client_post_internal_error(cl->wl_client, "Error %i", 20);
+
+   display_resume(d);
+
+   display_destroy(d);
+}
+
 static void
 register_reading(struct wl_display *display)
 {
-- 
2.15.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org

[PATCH] docs: Add documentation for wl_event_source callbacks

2017-09-13 Thread raof
From: Christopher James Halse Rogers 

Signed-off-by: Christopher James Halse Rogers 

---
 src/wayland-server-core.h | 59 +++
 1 file changed, 59 insertions(+)

diff --git a/src/wayland-server-core.h b/src/wayland-server-core.h
index 61da8ab..0a2c689 100644
--- a/src/wayland-server-core.h
+++ b/src/wayland-server-core.h
@@ -43,9 +43,68 @@ enum {
WL_EVENT_ERROR= 0x08
 };
 
+/** Callback for fd-based wl_event_source
+ *
+ * \param fd   The fd that this wl_event_source watches
+ * \param mask Event mask of the wakeup trigger
+ * \param data Userdata that was passed to wl_event_loop_add_fd
+ *
+ * \return Ignored, unless this source has been registered with
+ * wl_event_source_check().
+ *
+ * If triggered from the post-dispatch check, returning non-zero
+ * will influence whether or not checked sources will be
+ * immediately checked again.
+ *
+ * The return values all checked sources will be accumulated;
+ * if their sum is > 0 all checked sources will be re-checked.
+ */
 typedef int (*wl_event_loop_fd_func_t)(int fd, uint32_t mask, void *data);
+/** Callback for timer wl_event_source
+ *
+ * \param data Userdata that was passed to wl_event_loop_add_timer()
+ *
+ * \return Ignored, unless this source has been registered with
+ * wl_event_source_check().
+ *
+ * If triggered from the post-dispatch check, returning non-zero
+ * will influence whether or not checked sources will be
+ * immediately checked again.
+ *
+ * The return values all checked sources will be accumulated;
+ * if their sum is > 0 all checked sources will be re-checked.
+ */
 typedef int (*wl_event_loop_timer_func_t)(void *data);
+/** Callback for signal-based wl_event_source
+ *
+ * \param signal_numberSignal number that triggered this wakeup
+ * \param data Userdata that was passed to wl_event_loop_add_signal
+ *
+ * \return Ignored, unless this source has been registered with
+ * wl_event_source_check().
+ *
+ * If triggered from the post-dispatch check, returning non-zero
+ * will influence whether or not checked sources will be
+ * immediately checked again.
+ *
+ * The return values all checked sources will be accumulated;
+ * if their sum is > 0 all checked sources will be re-checked.
+ */
 typedef int (*wl_event_loop_signal_func_t)(int signal_number, void *data);
+/** Callback for idle wl_event_source
+ *
+ * \param data Userdata that was passed to wl_event_loop_add_fd
+ *
+ * \return Ignored, unless this source has been registered with
+ * wl_event_source_check().
+ *
+ * If triggered from the post-dispatch check, returning non-zero
+ * will influence whether or not checked sources will be
+ * immediately checked again.
+ *
+ * The return values all checked sources will be accumulated;
+ * if their sum is > 0 all checked sources will be re-checked.
+ */
 typedef void (*wl_event_loop_idle_func_t)(void *data);
 
 struct wl_event_loop *
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel