From 2e07370d1f07d94da7dedff52a9790c3c9118d6d Mon Sep 17 00:00:00 2001 From: dmitry Date: Sun, 2 Aug 2020 18:20:17 +0300 Subject: [PATCH] Finish implement commit event --- include/sway/output.h | 1 + include/sway/server.h | 1 + sway/server.c | 22 ++++++++++++++++++++++ sway/tree/output.c | 16 ++++++++-------- sway/tree/workspace.c | 1 - 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/include/sway/output.h b/include/sway/output.h index b9a4a01f2..4e4588a6f 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -9,6 +9,7 @@ #include "config.h" #include "sway/tree/node.h" #include "sway/tree/view.h" +#include struct sway_server; struct sway_container; diff --git a/include/sway/server.h b/include/sway/server.h index 9e15fb394..c1229b0b1 100644 --- a/include/sway/server.h +++ b/include/sway/server.h @@ -86,6 +86,7 @@ struct sway_server { struct wlr_text_input_manager_v3 *text_input; struct wlr_foreign_toplevel_manager_v1 *foreign_toplevel_manager; struct wlr_workspace_manager_v1 *workspace_manager; + struct wl_listener workspace_manager_commit_request; size_t txn_timeout_ms; list_t *transactions; diff --git a/sway/server.c b/sway/server.c index b1b84daef..3ac318fbe 100644 --- a/sway/server.c +++ b/sway/server.c @@ -52,6 +52,24 @@ bool server_privileged_prepare(struct sway_server *server) { return true; } + +static void handle_workspace_manager_commit_request(struct wl_listener *listener, void *data) { + struct sway_server *_server = wl_container_of(listener, _server, workspace_manager_commit_request); + struct wlr_workspace_manager_v1 *manager = data; + struct wlr_workspace_group_handle_v1 *group; + wl_list_for_each(group, &manager->groups, link) { + struct wlr_workspace_handle_v1 *workspace; + struct wlr_workspace_handle_v1 *next_active_workspace; + wl_list_for_each(workspace, &group->workspaces, link) { + if (workspace->current & WLR_WORKSPACE_HANDLE_V1_STATE_ACTIVE) { + next_active_workspace = workspace; + } + } + struct sway_workspace *sw_workspace = workspace_by_name(next_active_workspace->name); + workspace_switch(sw_workspace, false); + } +} + bool server_init(struct sway_server *server) { sway_log(SWAY_DEBUG, "Initializing Wayland server"); @@ -146,6 +164,10 @@ bool server_init(struct sway_server *server) { wlr_foreign_toplevel_manager_v1_create(server->wl_display); server->workspace_manager = wlr_workspace_manager_v1_create(server->wl_display); + server->workspace_manager_commit_request.notify = + handle_workspace_manager_commit_request; + wl_signal_add(&server->workspace_manager->events.commit, + &server->workspace_manager_commit_request); wlr_export_dmabuf_manager_v1_create(server->wl_display); wlr_screencopy_manager_v1_create(server->wl_display); diff --git a/sway/tree/output.c b/sway/tree/output.c index a153a302e..fe079dd4c 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c @@ -131,6 +131,7 @@ void output_enable(struct sway_output *output) { wl_list_for_each(seat, &server.input->seats, link) { if (!seat->has_focus) { seat_set_focus_workspace(seat, ws); + wlr_workspace_handle_v1_set_active(ws->workspace_handle, true); } } free(ws_name); @@ -379,22 +380,21 @@ static int sort_workspace_cmp_qsort(const void *_a, const void *_b) { return 0; } -static void set_workspace_coordinates(struct wlr_workspace_group_handle_v1 *workspace_group) { - struct wlr_workspace_handle_v1 *workspace_handle; - int i = wl_list_length(&workspace_group->workspaces); - wl_list_for_each(workspace_handle, &workspace_group->workspaces, link) { +static void set_workspace_coordinates(list_t *workspaces) { + for (int i = 0; i < workspaces->length; ++i) { struct wl_array coordinates; wl_array_init(&coordinates); - *(int*)wl_array_add(&coordinates, sizeof(int)) = i; - wlr_workspace_handle_v1_set_coordinates(workspace_handle, &coordinates); + *(int*)wl_array_add(&coordinates, sizeof(int)) = i + 1; + wlr_workspace_handle_v1_set_coordinates( + ((struct sway_workspace*)workspaces->items[i]) + ->workspace_handle, &coordinates); wl_array_release(&coordinates); - --i; } } void output_sort_workspaces(struct sway_output *output) { list_stable_sort(output->workspaces, sort_workspace_cmp_qsort); - set_workspace_coordinates(output->workspace_group); + set_workspace_coordinates(output->workspaces); } void output_get_box(struct sway_output *output, struct wlr_box *box) { diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index d096062d2..cc4a1cbbb 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -131,7 +131,6 @@ void workspace_destroy(struct sway_workspace *workspace) { "which is still referenced by transactions")) { return; } - wlr_workspace_handle_v1_destroy(workspace->workspace_handle); free(workspace->workspace_handle);