[mutter/wip/tablet-protocol-v3: 15/18] wayland: Implement tool notification



commit ee05032303a3b30d58c068e7f76e64f0f0b23961
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Oct 28 17:02:16 2015 +0100

    wayland: Implement tool notification
    
    Those must be notified to clients before proximity_in, only if the client
    didn't have a resource for this tool previously.

 src/wayland/meta-wayland-tablet-tool.c |   77 +++++++++++++++++++++++++++++++-
 1 files changed, 76 insertions(+), 1 deletions(-)
---
diff --git a/src/wayland/meta-wayland-tablet-tool.c b/src/wayland/meta-wayland-tablet-tool.c
index b594be0..76db06f 100644
--- a/src/wayland/meta-wayland-tablet-tool.c
+++ b/src/wayland/meta-wayland-tablet-tool.c
@@ -146,6 +146,79 @@ input_device_get_capabilities (ClutterInputDevice *device)
   return capabilities;
 }
 
+static enum zwp_tablet_tool1_type
+input_device_tool_get_type (ClutterInputDeviceTool *device_tool)
+{
+  ClutterInputDeviceToolType tool_type;
+
+  tool_type = clutter_input_device_tool_get_tool_type (device_tool);
+
+  switch (tool_type)
+    {
+    case CLUTTER_INPUT_DEVICE_TOOL_NONE:
+    case CLUTTER_INPUT_DEVICE_TOOL_PEN:
+      return ZWP_TABLET_TOOL1_TYPE_PEN;
+    case CLUTTER_INPUT_DEVICE_TOOL_ERASER:
+      return ZWP_TABLET_TOOL1_TYPE_ERASER;
+    case CLUTTER_INPUT_DEVICE_TOOL_BRUSH:
+      return ZWP_TABLET_TOOL1_TYPE_BRUSH;
+    case CLUTTER_INPUT_DEVICE_TOOL_PENCIL:
+      return ZWP_TABLET_TOOL1_TYPE_PENCIL;
+    case CLUTTER_INPUT_DEVICE_TOOL_AIRBRUSH:
+      return ZWP_TABLET_TOOL1_TYPE_AIRBRUSH;
+    case CLUTTER_INPUT_DEVICE_TOOL_FINGER:
+      return ZWP_TABLET_TOOL1_TYPE_FINGER;
+    case CLUTTER_INPUT_DEVICE_TOOL_MOUSE:
+      return ZWP_TABLET_TOOL1_TYPE_MOUSE;
+    case CLUTTER_INPUT_DEVICE_TOOL_LENS:
+      return ZWP_TABLET_TOOL1_TYPE_LENS;
+    }
+
+  g_assert_not_reached ();
+  return 0;
+}
+
+static void
+meta_wayland_tablet_tool_notify_details (MetaWaylandTabletTool *tool,
+                                         struct wl_resource    *resource)
+{
+  guint64 serial;
+
+  zwp_tablet_tool1_send_type (resource,
+                              input_device_tool_get_type (tool->device_tool));
+
+  serial = (guint64) clutter_input_device_tool_get_serial (tool->device_tool);
+  zwp_tablet_tool1_send_serial_id (resource, (uint32_t) (serial >> 32),
+                                   (uint32_t) (serial & G_MAXUINT32));
+
+  zwp_tablet_tool1_send_capability (resource,
+                                    input_device_get_capabilities (tool->device));
+
+  /* FIXME: zwp_tablet_tool1.hardware_id missing */
+
+  zwp_tablet_tool1_send_done (resource);
+}
+
+static void
+meta_wayland_tablet_tool_ensure_resource (MetaWaylandTabletTool *tool,
+                                          struct wl_client      *client)
+{
+  struct wl_resource *seat_resource, *tool_resource;
+
+  seat_resource = meta_wayland_tablet_seat_lookup_resource (tool->seat, client);
+
+  if (seat_resource &&
+      !meta_wayland_tablet_tool_lookup_resource (tool, client))
+    {
+      tool_resource = meta_wayland_tablet_tool_create_new_resource (tool, client,
+                                                                    seat_resource,
+                                                                    0);
+
+      meta_wayland_tablet_seat_notify_tool (tool->seat, tool, client);
+      meta_wayland_tablet_tool_notify_details (tool, tool_resource);
+    }
+}
+
 static void
 meta_wayland_tablet_tool_set_focus (MetaWaylandTabletTool *tool,
                                     MetaWaylandSurface    *surface)
@@ -173,7 +246,7 @@ meta_wayland_tablet_tool_set_focus (MetaWaylandTabletTool *tool,
       tool->focus_surface = NULL;
     }
 
-  if (surface != NULL)
+  if (surface != NULL && tool->current_tablet)
     {
       struct wl_resource *resource, *tablet_resource;
       struct wl_client *client;
@@ -187,6 +260,8 @@ meta_wayland_tablet_tool_set_focus (MetaWaylandTabletTool *tool,
       move_resources_for_client (&tool->focus_resource_list,
                                  &tool->resource_list, client);
 
+      meta_wayland_tablet_tool_ensure_resource (tool, client);
+
       tablet_resource = meta_wayland_tablet_lookup_resource (tool->current_tablet,
                                                              client);
       l = &tool->focus_resource_list;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]