[PATCH v2 12/15] tablet-shell: add key binding for kill and activate surface.

ning.tang at intel.com ning.tang at intel.com
Thu Aug 23 01:07:47 PDT 2012


From: Ning Tang <ning.tang at intel.com>

Send kill signal to client in order to exit. After the client ends, the
surface below it would get focus.

 Signed-off-by: Ning Tang <ning.tang at intel.com>

---
 src/tablet-shell.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/src/tablet-shell.c b/src/tablet-shell.c
index b8dafbb..860a0f9 100644
--- a/src/tablet-shell.c
+++ b/src/tablet-shell.c
@@ -913,6 +913,71 @@ home_key_binding(struct wl_seat *seat, uint32_t time, uint32_t key, void *data)
 }
 
 static void
+terminate_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
+		  void *data)
+{
+	struct weston_compositor *compositor = data;
+	wl_display_terminate(compositor->wl_display);
+}
+
+static void
+click_to_activate_binding(struct wl_seat *seat, uint32_t time, uint32_t button,
+			  void *data)
+{
+	struct weston_surface * focus;
+	struct shell_surface * shsurf;
+	focus = (struct weston_surface *) seat->pointer->focus;
+
+	shsurf = get_shell_surface(focus);
+
+	if (shsurf)
+		weston_surface_activate(shsurf->surface, seat);
+
+}
+
+static void
+force_kill_binding(struct wl_seat *seat, uint32_t time, uint32_t key,
+		   void *data)
+{
+	struct tablet_shell *shell = data;
+	struct wl_client *client;
+	struct weston_surface * focus;
+	struct shell_surface * shsurf;
+	pid_t pid;
+	uid_t uid;
+	gid_t gid;
+	int client_cnt;
+
+	if (!seat->keyboard->focus)
+		return;
+	client = seat->keyboard->focus->resource.client;
+	shsurf = get_shell_surface(seat->keyboard->focus);
+	if (!shsurf)
+		return;
+
+	wl_client_get_credentials(client, &pid, &uid, &gid);
+	client_cnt = wl_list_length(&shell->application_layer.surface_list);
+	if (client_cnt > 2) {
+		wl_list_for_each(focus, &shell->application_layer.surface_list,
+				 layer_link) {
+			client_cnt--;
+			if (client_cnt < 2) {
+				weston_surface_activate(focus, seat);
+				break;
+			}
+		}
+	}
+	else
+		focus = NULL;
+	kill(pid, SIGKILL);
+	if (focus == NULL) {
+		tablet_shell_set_state(shell, STATE_HOME);
+		weston_surface_activate(shell->home_surface, seat);
+	}
+	weston_compositor_schedule_repaint(shell->compositor);
+}
+
+static void
 destroy_tablet_shell(struct wl_resource *resource)
 {
 }
@@ -1020,6 +1085,15 @@ shell_init(struct weston_compositor *compositor)
 	weston_compositor_add_key_binding(compositor, KEY_COMPOSE, 0,
 					  menu_key_binding, shell);
 
+	/* Use keyboard to simulate events */
+	weston_compositor_add_key_binding(compositor, KEY_BACKSPACE,
+					  MODIFIER_CTRL | MODIFIER_ALT,
+					  terminate_binding, compositor);
+	weston_compositor_add_button_binding(compositor, BTN_LEFT, 0,
+					     click_to_activate_binding,
+					     shell);
+	weston_compositor_add_key_binding(compositor, KEY_ESC, 0,
+					  force_kill_binding, shell);
 	weston_layer_init(&shell->homescreen_layer,
 			  &compositor->cursor_layer.link);
 	weston_layer_init(&shell->application_layer,
-- 
1.7.11.5



More information about the wayland-devel mailing list