aboutsummaryrefslogtreecommitdiff
path: root/sway/input
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2018-03-30 16:12:02 -0400
committeremersion <contact@emersion.fr>2018-03-30 16:12:02 -0400
commiteb716c6c43ab3c9f265c2629538e232c4b3de625 (patch)
treec73b086cbc468ad3449f364d2a14d9acc68d1f39 /sway/input
parent03255fd20209bc26ca54ae6c1562feb0a157c5e3 (diff)
Fix segfaults when focusing a workspace
Diffstat (limited to 'sway/input')
-rw-r--r--sway/input/cursor.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 4abc61ea..717d864b 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -20,7 +20,11 @@ static void cursor_update_position(struct sway_cursor *cursor) {
cursor->y = y;
}
-static struct sway_container *cursor_at(struct sway_cursor *cursor,
+/**
+ * Returns the container at the cursor's position. If the container is a view,
+ * stores the surface at the cursor's position in `*surface`.
+ */
+static struct sway_container *container_at_cursor(struct sway_cursor *cursor,
struct wlr_surface **surface, double *sx, double *sy) {
// check for unmanaged views first
struct wl_list *unmanaged = &root_container.sway_root->unmanaged_views;
@@ -55,13 +59,18 @@ static struct sway_container *cursor_at(struct sway_cursor *cursor,
struct sway_output *output = wlr_output->data;
// find the focused workspace on the output for this seat
- struct sway_container *workspace =
+ struct sway_container *workspace_cont =
sway_seat_get_focus_inactive(cursor->seat, output->swayc);
- if (workspace->type != C_WORKSPACE) {
- workspace = container_parent(workspace, C_WORKSPACE);
+ if (workspace_cont != NULL && workspace_cont->type != C_WORKSPACE) {
+ workspace_cont = container_parent(workspace_cont, C_WORKSPACE);
+ }
+ if (workspace_cont == NULL) {
+ return output->swayc;
}
- return container_at(workspace, cursor->x, cursor->y, surface, sx, sy);
+ struct sway_container *view_cont = container_at(workspace_cont,
+ cursor->x, cursor->y, surface, sx, sy);
+ return view_cont != NULL ? view_cont : workspace_cont;
}
static void cursor_send_pointer_motion(struct sway_cursor *cursor,
@@ -69,9 +78,10 @@ static void cursor_send_pointer_motion(struct sway_cursor *cursor,
struct wlr_seat *seat = cursor->seat->wlr_seat;
struct wlr_surface *surface = NULL;
double sx, sy;
- struct sway_container *cont = cursor_at(cursor, &surface, &sx, &sy);
+ struct sway_container *cont =
+ container_at_cursor(cursor, &surface, &sx, &sy);
- if (cont) {
+ if (cont != NULL && surface != NULL) {
wlr_seat_pointer_notify_enter(seat, surface, sx, sy);
wlr_seat_pointer_notify_motion(seat, time, sx, sy);
} else {
@@ -105,8 +115,9 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
if (event->button == BTN_LEFT) {
struct wlr_surface *surface = NULL;
double sx, sy;
- struct sway_container *swayc = cursor_at(cursor, &surface, &sx, &sy);
- sway_seat_set_focus(cursor->seat, swayc);
+ struct sway_container *cont =
+ container_at_cursor(cursor, &surface, &sx, &sy);
+ sway_seat_set_focus(cursor->seat, cont);
}
wlr_seat_pointer_notify_button(cursor->seat->wlr_seat, event->time_msec,