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.
This commit is contained in:
Timur Celik 2021-07-06 12:06:49 +02:00
parent c495aabb8b
commit 77183e6da0
4 changed files with 34 additions and 10 deletions

View file

@ -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);

View file

@ -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);

View file

@ -213,7 +213,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)) {
@ -226,7 +226,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)) {
@ -243,7 +243,7 @@ handle_subscribe_reply(int type, const struct json_object *json, void *_m)
}
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;
@ -272,7 +272,7 @@ handle_get_workspaces_reply(int type, const struct json_object *json, void *_mod
}
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;
@ -289,6 +289,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;
@ -384,6 +385,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)) {
@ -410,7 +434,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;
@ -536,7 +560,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;

View file

@ -90,7 +90,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;
@ -155,7 +155,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;