[PATCH 2/2] server: Implement wl_keyboard_grab_interface.

Scott Moreau oreaus at gmail.com
Fri Feb 17 09:00:51 PST 2012


---
 src/wayland-server.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 src/wayland-server.h |   22 ++++++++++++++++++++++
 2 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/src/wayland-server.c b/src/wayland-server.c
index fce6025..fc4fab0 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -465,6 +465,24 @@ static const struct wl_pointer_grab_interface
 	default_grab_button
 };
 
+static void
+default_grab_key(struct wl_keyboard_grab *grab,
+		    uint32_t time, uint32_t key, int32_t state)
+{
+	struct wl_input_device *device = grab->input_device;
+	struct wl_resource *resource;
+
+	resource = device->keyboard_focus_resource;
+	if (resource)
+		wl_resource_post_event(resource, WL_INPUT_DEVICE_KEY,
+				       time, key, state);
+}
+
+static const struct wl_keyboard_grab_interface
+				default_keyboard_grab_interface = {
+	default_grab_key
+};
+
 WL_EXPORT void
 wl_input_device_init(struct wl_input_device *device)
 {
@@ -477,6 +495,10 @@ wl_input_device_init(struct wl_input_device *device)
 	device->default_pointer_grab.interface = &default_pointer_grab_interface;
 	device->default_pointer_grab.input_device = device;
 	device->pointer_grab = &device->default_pointer_grab;
+	
+	device->default_keyboard_grab.interface = &default_keyboard_grab_interface;
+	device->default_keyboard_grab.input_device = device;
+	device->keyboard_grab = &device->default_keyboard_grab;
 
 	wl_list_init(&device->drag_resource_list);
 	device->selection_data_source = NULL;
@@ -586,6 +608,28 @@ wl_input_device_set_keyboard_focus(struct wl_input_device *device,
 }
 
 WL_EXPORT void
+wl_input_device_start_keyboard_grab(struct wl_input_device *device,
+			   struct wl_keyboard_grab *grab, uint32_t time)
+{
+	const struct wl_keyboard_grab_interface *interface;
+
+	device->keyboard_grab = grab;
+	interface = device->keyboard_grab->interface;
+	grab->input_device = device;
+ 
+}
+
+WL_EXPORT void
+wl_input_device_end_keyboard_grab(struct wl_input_device *device, uint32_t time)
+{
+	const struct wl_keyboard_grab_interface *interface;
+
+	device->keyboard_grab = &device->default_keyboard_grab;
+	interface = device->keyboard_grab->interface;
+
+}
+
+WL_EXPORT void
 wl_input_device_start_pointer_grab(struct wl_input_device *device,
 			   struct wl_pointer_grab *grab, uint32_t time)
 {
diff --git a/src/wayland-server.h b/src/wayland-server.h
index ed8bb10..9726a08 100644
--- a/src/wayland-server.h
+++ b/src/wayland-server.h
@@ -162,6 +162,19 @@ struct wl_pointer_grab {
 	int32_t x, y;
 };
 
+struct wl_keyboard_grab;
+struct wl_keyboard_grab_interface {
+	void (*key)(struct wl_keyboard_grab *grab,
+		       uint32_t time, uint32_t key, int32_t state);
+};
+
+struct wl_keyboard_grab {
+	const struct wl_keyboard_grab_interface *interface;
+	struct wl_input_device *input_device;
+	struct wl_surface *focus;
+	uint32_t key;
+};
+
 struct wl_data_offer {
 	struct wl_resource resource;
 	struct wl_data_source *source;
@@ -200,10 +213,13 @@ struct wl_input_device {
 
 	struct wl_pointer_grab *pointer_grab;
 	struct wl_pointer_grab default_pointer_grab;
+	struct wl_keyboard_grab *keyboard_grab;
+	struct wl_keyboard_grab default_keyboard_grab;
 	uint32_t button_count;
 	uint32_t grab_time;
 	int32_t grab_x, grab_y;
 	uint32_t grab_button;
+	uint32_t grab_key;
 	struct wl_listener grab_listener;
 
 	struct wl_list drag_resource_list;
@@ -281,6 +297,12 @@ int
 wl_data_device_manager_init(struct wl_display *display);
 
 void
+wl_input_device_start_keyboard_grab(struct wl_input_device *device,
+			   struct wl_keyboard_grab *grab, uint32_t time);
+void
+wl_input_device_end_keyboard_grab(struct wl_input_device *device, uint32_t time);
+
+void
 wl_input_device_start_pointer_grab(struct wl_input_device *device,
 			   struct wl_pointer_grab *grab, uint32_t time);
 void
-- 
1.7.4.1



More information about the wayland-devel mailing list