From 24a3b90a01068819297055ed277cf8d78b9130ee Mon Sep 17 00:00:00 2001 From: Timur Celik Date: Tue, 6 Jul 2021 12:06:49 +0200 Subject: [PATCH] modules: Implement workspace move event Implementing the move event required to pass the IPC socket to `i3_ipc_callback_t`, because we won't get notified about any visibility changes of other workspaces. That's why we query all workspaces again after a focused workspace was moved. --- modules/i3-common.c | 2 +- modules/i3-common.h | 2 +- modules/i3.c | 36 ++++++++++++++++++++++++++++++------ modules/sway-xkb.c | 4 ++-- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/modules/i3-common.c b/modules/i3-common.c index 589bfb8..a0769f2 100644 --- a/modules/i3-common.c +++ b/modules/i3-common.c @@ -309,7 +309,7 @@ i3_receive_loop(int abort_fd, int sock, } if (pkt_handler != NULL) - err = !pkt_handler(hdr->type, json, data); + err = !pkt_handler(sock, hdr->type, json, data); else LOG_DBG("no handler for reply/event %d; ignoring", hdr->type); diff --git a/modules/i3-common.h b/modules/i3-common.h index e3d94d1..0cbfa3e 100644 --- a/modules/i3-common.h +++ b/modules/i3-common.h @@ -11,7 +11,7 @@ bool i3_get_socket_address(struct sockaddr_un *addr); bool i3_send_pkg(int sock, int cmd, char *data); -typedef bool (*i3_ipc_callback_t)(int type, const struct json_object *json, void *data); +typedef bool (*i3_ipc_callback_t)(int sock, int type, const struct json_object *json, void *data); struct i3_ipc_callbacks { void (*burst_done)(void *data); diff --git a/modules/i3.c b/modules/i3.c index f970b0a..160913b 100644 --- a/modules/i3.c +++ b/modules/i3.c @@ -251,7 +251,7 @@ workspace_lookup(struct private *m, int id) } static bool -handle_get_version_reply(int type, const struct json_object *json, void *_m) +handle_get_version_reply(int sock, int type, const struct json_object *json, void *_m) { struct json_object *version; if (!json_object_object_get_ex(json, "human_readable", &version)) { @@ -264,7 +264,7 @@ handle_get_version_reply(int type, const struct json_object *json, void *_m) } static bool -handle_subscribe_reply(int type, const struct json_object *json, void *_m) +handle_subscribe_reply(int sock, int type, const struct json_object *json, void *_m) { struct json_object *success; if (!json_object_object_get_ex(json, "success", &success)) { @@ -310,7 +310,7 @@ workspace_update_or_add(struct private *m, const struct json_object *ws_json) } static bool -handle_get_workspaces_reply(int type, const struct json_object *json, void *_mod) +handle_get_workspaces_reply(int sock, int type, const struct json_object *json, void *_mod) { struct module *mod = _mod; struct private *m = mod->private; @@ -337,7 +337,7 @@ err: } static bool -handle_workspace_event(int type, const struct json_object *json, void *_mod) +handle_workspace_event(int sock, int type, const struct json_object *json, void *_mod) { struct module *mod = _mod; struct private *m = mod->private; @@ -354,6 +354,7 @@ handle_workspace_event(int type, const struct json_object *json, void *_mod) bool is_empty = strcmp(change_str, "empty") == 0; bool is_focused = strcmp(change_str, "focus") == 0; bool is_rename = strcmp(change_str, "rename") == 0; + bool is_move = strcmp(change_str, "move") == 0; bool is_urgent = strcmp(change_str, "urgent") == 0; struct json_object *current, *_current_id; @@ -446,6 +447,29 @@ handle_workspace_event(int type, const struct json_object *json, void *_mod) workspace_add(m, ws); } + else if (is_move) { + struct workspace *w = workspace_lookup(m, current_id); + assert(w != NULL); + + struct json_object *_current_output; + if (!json_object_object_get_ex(current, "output", &_current_output)) { + LOG_ERR("workspace 'move' event without 'output' property"); + mtx_unlock(&mod->lock); + return false; + } + + free(w->output); + w->output = strdup(json_object_get_string(_current_output)); + + /* + * If the moved workspace was focused, schedule a full update because + * visibility for other workspaces may have changed. + */ + if (w->focused) { + i3_send_pkg(sock, I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL); + } + } + else if (is_urgent) { struct json_object *urgent; if (!json_object_object_get_ex(current, "urgent", &urgent)) { @@ -472,7 +496,7 @@ err: } static bool -handle_window_event(int type, const struct json_object *json, void *_mod) +handle_window_event(int sock, int type, const struct json_object *json, void *_mod) { struct module *mod = _mod; struct private *m = mod->private; @@ -606,7 +630,7 @@ handle_window_event(int type, const struct json_object *json, void *_mod) } static bool -handle_mode_event(int type, const struct json_object *json, void *_mod) +handle_mode_event(int sock, int type, const struct json_object *json, void *_mod) { struct module *mod = _mod; struct private *m = mod->private; diff --git a/modules/sway-xkb.c b/modules/sway-xkb.c index 3f2e965..269df24 100644 --- a/modules/sway-xkb.c +++ b/modules/sway-xkb.c @@ -94,7 +94,7 @@ content(struct module *mod) } static bool -handle_input_reply(int type, const struct json_object *json, void *_mod) +handle_input_reply(int sock, int type, const struct json_object *json, void *_mod) { struct module *mod = _mod; struct private *m = mod->private; @@ -162,7 +162,7 @@ handle_input_reply(int type, const struct json_object *json, void *_mod) } static bool -handle_input_event(int type, const struct json_object *json, void *_mod) +handle_input_event(int sock, int type, const struct json_object *json, void *_mod) { struct module *mod = _mod; struct private *m = mod->private;