diff options
author | emersion <contact@emersion.fr> | 2018-03-30 16:12:02 -0400 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2018-03-30 16:12:02 -0400 |
commit | eb716c6c43ab3c9f265c2629538e232c4b3de625 (patch) | |
tree | c73b086cbc468ad3449f364d2a14d9acc68d1f39 | |
parent | Fix pointer events for hidden workspaces (diff) | |
download | sway-eb716c6c43ab3c9f265c2629538e232c4b3de625.tar.gz sway-eb716c6c43ab3c9f265c2629538e232c4b3de625.tar.zst sway-eb716c6c43ab3c9f265c2629538e232c4b3de625.zip |
Fix segfaults when focusing a workspace
-rw-r--r-- | sway/input/cursor.c | 29 | ||||
-rw-r--r-- | sway/ipc-server.c | 2 |
2 files changed, 21 insertions, 10 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) { | |||
20 | cursor->y = y; | 20 | cursor->y = y; |
21 | } | 21 | } |
22 | 22 | ||
23 | static struct sway_container *cursor_at(struct sway_cursor *cursor, | 23 | /** |
24 | * Returns the container at the cursor's position. If the container is a view, | ||
25 | * stores the surface at the cursor's position in `*surface`. | ||
26 | */ | ||
27 | static struct sway_container *container_at_cursor(struct sway_cursor *cursor, | ||
24 | struct wlr_surface **surface, double *sx, double *sy) { | 28 | struct wlr_surface **surface, double *sx, double *sy) { |
25 | // check for unmanaged views first | 29 | // check for unmanaged views first |
26 | struct wl_list *unmanaged = &root_container.sway_root->unmanaged_views; | 30 | struct wl_list *unmanaged = &root_container.sway_root->unmanaged_views; |
@@ -55,13 +59,18 @@ static struct sway_container *cursor_at(struct sway_cursor *cursor, | |||
55 | struct sway_output *output = wlr_output->data; | 59 | struct sway_output *output = wlr_output->data; |
56 | 60 | ||
57 | // find the focused workspace on the output for this seat | 61 | // find the focused workspace on the output for this seat |
58 | struct sway_container *workspace = | 62 | struct sway_container *workspace_cont = |
59 | sway_seat_get_focus_inactive(cursor->seat, output->swayc); | 63 | sway_seat_get_focus_inactive(cursor->seat, output->swayc); |
60 | if (workspace->type != C_WORKSPACE) { | 64 | if (workspace_cont != NULL && workspace_cont->type != C_WORKSPACE) { |
61 | workspace = container_parent(workspace, C_WORKSPACE); | 65 | workspace_cont = container_parent(workspace_cont, C_WORKSPACE); |
66 | } | ||
67 | if (workspace_cont == NULL) { | ||
68 | return output->swayc; | ||
62 | } | 69 | } |
63 | 70 | ||
64 | return container_at(workspace, cursor->x, cursor->y, surface, sx, sy); | 71 | struct sway_container *view_cont = container_at(workspace_cont, |
72 | cursor->x, cursor->y, surface, sx, sy); | ||
73 | return view_cont != NULL ? view_cont : workspace_cont; | ||
65 | } | 74 | } |
66 | 75 | ||
67 | static void cursor_send_pointer_motion(struct sway_cursor *cursor, | 76 | static void cursor_send_pointer_motion(struct sway_cursor *cursor, |
@@ -69,9 +78,10 @@ static void cursor_send_pointer_motion(struct sway_cursor *cursor, | |||
69 | struct wlr_seat *seat = cursor->seat->wlr_seat; | 78 | struct wlr_seat *seat = cursor->seat->wlr_seat; |
70 | struct wlr_surface *surface = NULL; | 79 | struct wlr_surface *surface = NULL; |
71 | double sx, sy; | 80 | double sx, sy; |
72 | struct sway_container *cont = cursor_at(cursor, &surface, &sx, &sy); | 81 | struct sway_container *cont = |
82 | container_at_cursor(cursor, &surface, &sx, &sy); | ||
73 | 83 | ||
74 | if (cont) { | 84 | if (cont != NULL && surface != NULL) { |
75 | wlr_seat_pointer_notify_enter(seat, surface, sx, sy); | 85 | wlr_seat_pointer_notify_enter(seat, surface, sx, sy); |
76 | wlr_seat_pointer_notify_motion(seat, time, sx, sy); | 86 | wlr_seat_pointer_notify_motion(seat, time, sx, sy); |
77 | } else { | 87 | } else { |
@@ -105,8 +115,9 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) { | |||
105 | if (event->button == BTN_LEFT) { | 115 | if (event->button == BTN_LEFT) { |
106 | struct wlr_surface *surface = NULL; | 116 | struct wlr_surface *surface = NULL; |
107 | double sx, sy; | 117 | double sx, sy; |
108 | struct sway_container *swayc = cursor_at(cursor, &surface, &sx, &sy); | 118 | struct sway_container *cont = |
109 | sway_seat_set_focus(cursor->seat, swayc); | 119 | container_at_cursor(cursor, &surface, &sx, &sy); |
120 | sway_seat_set_focus(cursor->seat, cont); | ||
110 | } | 121 | } |
111 | 122 | ||
112 | wlr_seat_pointer_notify_button(cursor->seat->wlr_seat, event->time_msec, | 123 | wlr_seat_pointer_notify_button(cursor->seat->wlr_seat, event->time_msec, |
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 394161af..6f7a0670 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -390,7 +390,7 @@ static void ipc_get_workspaces_callback(struct sway_container *workspace, | |||
390 | struct sway_seat *seat = | 390 | struct sway_seat *seat = |
391 | sway_input_manager_get_default_seat(input_manager); | 391 | sway_input_manager_get_default_seat(input_manager); |
392 | struct sway_container *focused_ws = sway_seat_get_focus(seat); | 392 | struct sway_container *focused_ws = sway_seat_get_focus(seat); |
393 | if (focused_ws->type != C_WORKSPACE) { | 393 | if (focused_ws != NULL && focused_ws->type != C_WORKSPACE) { |
394 | focused_ws = container_parent(focused_ws, C_WORKSPACE); | 394 | focused_ws = container_parent(focused_ws, C_WORKSPACE); |
395 | } | 395 | } |
396 | bool focused = workspace == focused_ws; | 396 | bool focused = workspace == focused_ws; |