From 5d96922d2ccea845fc30b7c1e30147f4f26c9c65 Mon Sep 17 00:00:00 2001 From: dmitry Date: Wed, 1 Jul 2020 01:42:59 +0300 Subject: [PATCH 1/5] Save --- sway/tree/view.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sway/tree/view.c b/sway/tree/view.c index 6dccaa2e6..01841d131 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -715,11 +715,14 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface, input_manager_set_focus(&view->container->node); } - const char *app_id = view_get_app_id(view); - if (app_id != NULL) { + const char *app_id; + const char *class; + if ((app_id = view_get_app_id(view)) != NULL) { wlr_foreign_toplevel_handle_v1_set_app_id( view->foreign_toplevel, app_id); - } + } else if ((class = view_get_class(view)) != NULL) { + wlr_foreign_toplevel_handle_v1_set_app_id( + view->foreign_toplevel, class); } void view_unmap(struct sway_view *view) { From f8979957599468cd2f642caab8220456701f34b0 Mon Sep 17 00:00:00 2001 From: dmitry Date: Sun, 2 Aug 2020 04:24:24 +0300 Subject: [PATCH 2/5] Base implement --- include/sway/output.h | 3 +++ include/sway/server.h | 2 ++ include/sway/tree/workspace.h | 3 +++ sway/desktop/output.c | 2 ++ sway/server.c | 2 ++ sway/tree/output.c | 16 ++++++++++++++++ sway/tree/workspace.c | 19 +++++++++++++++++++ 7 files changed, 47 insertions(+) diff --git a/include/sway/output.h b/include/sway/output.h index f27f6344a..b9a4a01f2 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "config.h" #include "sway/tree/node.h" #include "sway/tree/view.h" @@ -57,6 +58,8 @@ struct sway_output { uint32_t refresh_nsec; int max_render_time; // In milliseconds struct wl_event_source *repaint_timer; + + struct wlr_workspace_group_handle_v1 *workspace_group; }; struct sway_output *output_create(struct wlr_output *wlr_output); diff --git a/include/sway/server.h b/include/sway/server.h index 0f5e3ab20..9e15fb394 100644 --- a/include/sway/server.h +++ b/include/sway/server.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -84,6 +85,7 @@ struct sway_server { struct wlr_input_method_manager_v2 *input_method; struct wlr_text_input_manager_v3 *text_input; struct wlr_foreign_toplevel_manager_v1 *foreign_toplevel_manager; + struct wlr_workspace_manager_v1 *workspace_manager; size_t txn_timeout_ms; list_t *transactions; diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h index 1adbe68a2..b57dceaa7 100644 --- a/include/sway/tree/workspace.h +++ b/include/sway/tree/workspace.h @@ -43,6 +43,9 @@ struct sway_workspace { bool urgent; struct sway_workspace_state current; + + struct wlr_workspace_handle_v1 *workspace_handle; + struct wl_listener *workspace_activate_request; }; struct workspace_config *workspace_find_config(const char *ws_name); diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 90653fa16..4d0e9b33c 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -919,6 +919,8 @@ void handle_new_output(struct wl_listener *listener, void *data) { return; } output->server = server; + output->workspace_group = wlr_workspace_group_handle_v1_create(output->server->workspace_manager); + wlr_workspace_group_handle_v1_output_enter(output->workspace_group, wlr_output); output->damage = wlr_output_damage_create(wlr_output); wl_signal_add(&wlr_output->events.destroy, &output->destroy); diff --git a/sway/server.c b/sway/server.c index ff848450d..b1b84daef 100644 --- a/sway/server.c +++ b/sway/server.c @@ -144,6 +144,8 @@ bool server_init(struct sway_server *server) { server->text_input = wlr_text_input_manager_v3_create(server->wl_display); server->foreign_toplevel_manager = wlr_foreign_toplevel_manager_v1_create(server->wl_display); + server->workspace_manager = + wlr_workspace_manager_v1_create(server->wl_display); 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 d600c5c31..a153a302e 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c @@ -233,6 +233,8 @@ void output_destroy(struct sway_output *output) { "which is still referenced by transactions")) { return; } + wlr_workspace_group_handle_v1_output_leave(output->workspace_group, output->wlr_output); + free(output->workspace_group); list_free(output->workspaces); list_free(output->current.workspaces); wl_event_source_remove(output->repaint_timer); @@ -377,8 +379,22 @@ 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) { + 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); + 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); } 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 3bcba8e54..d096062d2 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -110,6 +110,9 @@ struct sway_workspace *workspace_create(struct sway_output *output, // If not already added, add the output to the lowest priority workspace_output_add_priority(ws, output); + ws->workspace_handle = wlr_workspace_handle_v1_create(output->workspace_group); + wlr_workspace_handle_v1_set_name(ws->workspace_handle, ws->name); + output_add_workspace(output, ws); output_sort_workspaces(output); @@ -129,6 +132,9 @@ void workspace_destroy(struct sway_workspace *workspace) { return; } + wlr_workspace_handle_v1_destroy(workspace->workspace_handle); + + free(workspace->workspace_handle); free(workspace->name); free(workspace->representation); list_free_items_and_destroy(workspace->output_priority); @@ -453,6 +459,16 @@ struct sway_workspace *workspace_prev(struct sway_workspace *current) { return workspace_prev_next_impl(current, -1); } +static void set_active_current_and_diactivate_others(struct wlr_workspace_handle_v1 *workspace) { + wlr_workspace_handle_v1_set_active(workspace, true); + struct wlr_workspace_handle_v1 *tmp_workspace; + wl_list_for_each(tmp_workspace, &workspace->group->workspaces, link) { + if (workspace != tmp_workspace) { + wlr_workspace_handle_v1_set_active(tmp_workspace, false); + } + } +} + bool workspace_switch(struct sway_workspace *workspace, bool no_auto_back_and_forth) { struct sway_seat *seat = input_manager_current_seat(); @@ -475,6 +491,9 @@ bool workspace_switch(struct sway_workspace *workspace, sway_log(SWAY_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name); + + set_active_current_and_diactivate_others(workspace->workspace_handle); + struct sway_node *next = seat_get_focus_inactive(seat, &workspace->node); if (next == NULL) { next = &workspace->node; From 2e07370d1f07d94da7dedff52a9790c3c9118d6d Mon Sep 17 00:00:00 2001 From: dmitry Date: Sun, 2 Aug 2020 18:20:17 +0300 Subject: [PATCH 3/5] 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); From 0b97bbf9f6311e88f422925c19292461b1fb3b94 Mon Sep 17 00:00:00 2001 From: dmitry Date: Tue, 16 Nov 2021 22:39:00 +0300 Subject: [PATCH 4/5] Add cotinue --- sway/server.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sway/server.c b/sway/server.c index 3ac318fbe..28d680f87 100644 --- a/sway/server.c +++ b/sway/server.c @@ -59,12 +59,16 @@ static void handle_workspace_manager_commit_request(struct wl_listener *listener 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; + struct wlr_workspace_handle_v1 *next_active_workspace = NULL; wl_list_for_each(workspace, &group->workspaces, link) { if (workspace->current & WLR_WORKSPACE_HANDLE_V1_STATE_ACTIVE) { next_active_workspace = workspace; } } + if (!next_active_workspace) { + continue; + } + struct sway_workspace *sw_workspace = workspace_by_name(next_active_workspace->name); workspace_switch(sw_workspace, false); } From a8f6d416309f64b9214193a2ccf22cc1097f0c07 Mon Sep 17 00:00:00 2001 From: dmitry Date: Sat, 20 Nov 2021 21:36:57 +0300 Subject: [PATCH 5/5] Rename --- include/sway/output.h | 4 ++-- include/sway/server.h | 4 ++-- sway/desktop/output.c | 4 ++-- sway/server.c | 12 ++++++------ sway/tree/output.c | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/sway/output.h b/include/sway/output.h index dae6edc82..d815ce444 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include "config.h" #include "sway/tree/node.h" #include "sway/tree/view.h" @@ -58,7 +58,7 @@ struct sway_output { int max_render_time; // In milliseconds struct wl_event_source *repaint_timer; - struct wlr_workspace_group_handle_v1 *workspace_group; + struct wlr_ext_workspace_group_handle_v1 *workspace_group; }; struct sway_output *output_create(struct wlr_output *wlr_output); diff --git a/include/sway/server.h b/include/sway/server.h index e1fcb133f..7e530fcbe 100644 --- a/include/sway/server.h +++ b/include/sway/server.h @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include @@ -91,7 +91,7 @@ struct sway_server { struct wlr_input_method_manager_v2 *input_method; 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 wlr_ext_workspace_manager_v1 *workspace_manager; struct wl_listener workspace_manager_commit_request; struct wlr_xdg_activation_v1 *xdg_activation_v1; diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 5945b8cbf..0c4c159ad 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -855,8 +855,8 @@ void handle_new_output(struct wl_listener *listener, void *data) { return; } output->server = server; - output->workspace_group = wlr_workspace_group_handle_v1_create(output->server->workspace_manager); - wlr_workspace_group_handle_v1_output_enter(output->workspace_group, wlr_output); + output->workspace_group = wlr_ext_workspace_group_handle_v1_create(output->server->workspace_manager); + wlr_ext_workspace_group_handle_v1_output_enter(output->workspace_group, wlr_output); output->damage = wlr_output_damage_create(wlr_output); wl_signal_add(&wlr_output->events.destroy, &output->destroy); diff --git a/sway/server.c b/sway/server.c index 7b5bd4044..f171a312a 100644 --- a/sway/server.c +++ b/sway/server.c @@ -60,13 +60,13 @@ bool server_privileged_prepare(struct sway_server *server) { 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; + struct wlr_ext_workspace_manager_v1 *manager = data; + struct wlr_ext_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 = NULL; + struct wlr_ext_workspace_handle_v1 *workspace; + struct wlr_ext_workspace_handle_v1 *next_active_workspace = NULL; wl_list_for_each(workspace, &group->workspaces, link) { - if (workspace->current & WLR_WORKSPACE_HANDLE_V1_STATE_ACTIVE) { + if (workspace->current & WLR_EXT_WORKSPACE_HANDLE_V1_STATE_ACTIVE) { next_active_workspace = workspace; } } @@ -183,7 +183,7 @@ bool server_init(struct sway_server *server) { server->foreign_toplevel_manager = wlr_foreign_toplevel_manager_v1_create(server->wl_display); server->workspace_manager = - wlr_workspace_manager_v1_create(server->wl_display); + wlr_ext_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, diff --git a/sway/tree/output.c b/sway/tree/output.c index c0adc9e35..74856ed48 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c @@ -390,7 +390,7 @@ static void set_workspace_coordinates(list_t *workspaces) { struct wl_array coordinates; wl_array_init(&coordinates); *(int*)wl_array_add(&coordinates, sizeof(int)) = i + 1; - wlr_workspace_handle_v1_set_coordinates( + wlr_ext_workspace_handle_v1_set_coordinates( ((struct sway_workspace*)workspaces->items[i]) ->workspace_handle, &coordinates); wl_array_release(&coordinates);