Finish implement commit event

This commit is contained in:
dmitry 2020-08-02 18:20:17 +03:00
parent f897995759
commit 2e07370d1f
5 changed files with 32 additions and 9 deletions

View file

@ -9,6 +9,7 @@
#include "config.h" #include "config.h"
#include "sway/tree/node.h" #include "sway/tree/node.h"
#include "sway/tree/view.h" #include "sway/tree/view.h"
#include <sway/tree/workspace.h>
struct sway_server; struct sway_server;
struct sway_container; struct sway_container;

View file

@ -86,6 +86,7 @@ struct sway_server {
struct wlr_text_input_manager_v3 *text_input; struct wlr_text_input_manager_v3 *text_input;
struct wlr_foreign_toplevel_manager_v1 *foreign_toplevel_manager; struct wlr_foreign_toplevel_manager_v1 *foreign_toplevel_manager;
struct wlr_workspace_manager_v1 *workspace_manager; struct wlr_workspace_manager_v1 *workspace_manager;
struct wl_listener workspace_manager_commit_request;
size_t txn_timeout_ms; size_t txn_timeout_ms;
list_t *transactions; list_t *transactions;

View file

@ -52,6 +52,24 @@ bool server_privileged_prepare(struct sway_server *server) {
return true; 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) { bool server_init(struct sway_server *server) {
sway_log(SWAY_DEBUG, "Initializing Wayland 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); wlr_foreign_toplevel_manager_v1_create(server->wl_display);
server->workspace_manager = server->workspace_manager =
wlr_workspace_manager_v1_create(server->wl_display); 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_export_dmabuf_manager_v1_create(server->wl_display);
wlr_screencopy_manager_v1_create(server->wl_display); wlr_screencopy_manager_v1_create(server->wl_display);

View file

@ -131,6 +131,7 @@ void output_enable(struct sway_output *output) {
wl_list_for_each(seat, &server.input->seats, link) { wl_list_for_each(seat, &server.input->seats, link) {
if (!seat->has_focus) { if (!seat->has_focus) {
seat_set_focus_workspace(seat, ws); seat_set_focus_workspace(seat, ws);
wlr_workspace_handle_v1_set_active(ws->workspace_handle, true);
} }
} }
free(ws_name); free(ws_name);
@ -379,22 +380,21 @@ static int sort_workspace_cmp_qsort(const void *_a, const void *_b) {
return 0; return 0;
} }
static void set_workspace_coordinates(struct wlr_workspace_group_handle_v1 *workspace_group) { static void set_workspace_coordinates(list_t *workspaces) {
struct wlr_workspace_handle_v1 *workspace_handle; for (int i = 0; i < workspaces->length; ++i) {
int i = wl_list_length(&workspace_group->workspaces);
wl_list_for_each(workspace_handle, &workspace_group->workspaces, link) {
struct wl_array coordinates; struct wl_array coordinates;
wl_array_init(&coordinates); wl_array_init(&coordinates);
*(int*)wl_array_add(&coordinates, sizeof(int)) = i; *(int*)wl_array_add(&coordinates, sizeof(int)) = i + 1;
wlr_workspace_handle_v1_set_coordinates(workspace_handle, &coordinates); wlr_workspace_handle_v1_set_coordinates(
((struct sway_workspace*)workspaces->items[i])
->workspace_handle, &coordinates);
wl_array_release(&coordinates); wl_array_release(&coordinates);
--i;
} }
} }
void output_sort_workspaces(struct sway_output *output) { void output_sort_workspaces(struct sway_output *output) {
list_stable_sort(output->workspaces, sort_workspace_cmp_qsort); 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) { void output_get_box(struct sway_output *output, struct wlr_box *box) {

View file

@ -131,7 +131,6 @@ void workspace_destroy(struct sway_workspace *workspace) {
"which is still referenced by transactions")) { "which is still referenced by transactions")) {
return; return;
} }
wlr_workspace_handle_v1_destroy(workspace->workspace_handle); wlr_workspace_handle_v1_destroy(workspace->workspace_handle);
free(workspace->workspace_handle); free(workspace->workspace_handle);