From b28e6d23698c98d616710c44a211a8121943b3ca Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 30 Mar 2018 13:56:31 -0400 Subject: IPC fixes --- sway/ipc-server.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'sway/ipc-server.c') diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 394161af..f1854bcc 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -398,6 +398,14 @@ static void ipc_get_workspaces_callback(struct sway_container *workspace, json_object_object_add(workspace_json, "focused", json_object_new_boolean(focused)); json_object_array_add((json_object *)data, workspace_json); + + focused_ws = sway_seat_get_focus_inactive(seat, workspace->parent); + if (focused_ws->type != C_WORKSPACE) { + focused_ws = container_parent(focused_ws, C_WORKSPACE); + } + bool visible = workspace == focused_ws; + json_object_object_add(workspace_json, "visible", + json_object_new_boolean(visible)); } void ipc_client_handle_command(struct ipc_client *client) { -- cgit v1.2.3 From eb716c6c43ab3c9f265c2629538e232c4b3de625 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 30 Mar 2018 16:12:02 -0400 Subject: Fix segfaults when focusing a workspace --- sway/input/cursor.c | 29 ++++++++++++++++++++--------- sway/ipc-server.c | 2 +- 2 files changed, 21 insertions(+), 10 deletions(-) (limited to 'sway/ipc-server.c') 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, 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, struct sway_seat *seat = sway_input_manager_get_default_seat(input_manager); struct sway_container *focused_ws = sway_seat_get_focus(seat); - if (focused_ws->type != C_WORKSPACE) { + if (focused_ws != NULL && focused_ws->type != C_WORKSPACE) { focused_ws = container_parent(focused_ws, C_WORKSPACE); } bool focused = workspace == focused_ws; -- cgit v1.2.3