[PATCH] shell: add key binding for destoying a surface.

Scott Moreau oreaus at gmail.com
Mon Jan 30 05:47:32 PST 2012


---
 clients/window.c |   15 ++++++++++++++-
 src/shell.c      |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletions(-)

diff --git a/clients/window.c b/clients/window.c
index 6c00186..b9e8fb7 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -2103,9 +2103,22 @@ handle_popup_done(void *data, struct wl_shell_surface *shell_surface)
 	menu_destroy(menu);
 }
 
+static void
+handle_close(void *data, struct wl_shell_surface *shell_surface)
+{
+	struct window *window = data;
+
+	if (window->close_handler)
+		window->close_handler(window->parent,
+					  window->user_data);
+	else
+		display_exit(window->display);
+}
+
 static const struct wl_shell_surface_listener shell_surface_listener = {
 	handle_configure,
-	handle_popup_done
+	handle_popup_done,
+	handle_close
 };
 
 void
diff --git a/src/shell.c b/src/shell.c
index 168443b..54eadfd 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -966,6 +966,38 @@ resize_binding(struct wl_input_device *device, uint32_t time,
 }
 
 static void
+close_binding(struct wl_input_device *device, uint32_t time,
+	     uint32_t key, uint32_t button, uint32_t state, void *data)
+{
+	if (!device->keyboard_focus_resource)
+		return;
+
+	struct weston_surface *surface =
+		(struct weston_surface *) device->keyboard_focus;
+	struct shell_surface *shsurf;
+
+	if (surface == NULL)
+		return;
+
+	shsurf = get_shell_surface(surface);
+	if (!shsurf)
+		return;
+
+	switch (shsurf->type) {
+		case SHELL_SURFACE_NONE:
+		case SHELL_SURFACE_PANEL:
+		case SHELL_SURFACE_BACKGROUND:
+		case SHELL_SURFACE_LOCK:
+		case SHELL_SURFACE_SCREENSAVER:
+			return;
+		default:
+			break;
+	}
+
+	wl_resource_post_event(&shsurf->resource, WL_SHELL_SURFACE_CLOSE);
+}
+
+static void
 terminate_binding(struct wl_input_device *device, uint32_t time,
 		  uint32_t key, uint32_t button, uint32_t state, void *data)
 {
@@ -1640,6 +1672,8 @@ shell_init(struct weston_compositor *ec)
 				    move_binding, shell);
 	weston_compositor_add_binding(ec, 0, BTN_MIDDLE, MODIFIER_SUPER,
 				    resize_binding, shell);
+	weston_compositor_add_binding(ec, KEY_F4, 0, MODIFIER_SUPER,
+				    close_binding, shell);
 	weston_compositor_add_binding(ec, KEY_BACKSPACE, 0,
 				    MODIFIER_CTRL | MODIFIER_ALT,
 				    terminate_binding, ec);
-- 
1.7.4.1



More information about the wayland-devel mailing list