forked from external/yambar
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:
parent
8f89545b32
commit
24a3b90a01
4 changed files with 34 additions and 10 deletions
|
@ -309,7 +309,7 @@ i3_receive_loop(int abort_fd, int sock,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pkt_handler != NULL)
|
if (pkt_handler != NULL)
|
||||||
err = !pkt_handler(hdr->type, json, data);
|
err = !pkt_handler(sock, hdr->type, json, data);
|
||||||
else
|
else
|
||||||
LOG_DBG("no handler for reply/event %d; ignoring", hdr->type);
|
LOG_DBG("no handler for reply/event %d; ignoring", hdr->type);
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
bool i3_get_socket_address(struct sockaddr_un *addr);
|
bool i3_get_socket_address(struct sockaddr_un *addr);
|
||||||
bool i3_send_pkg(int sock, int cmd, char *data);
|
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 {
|
struct i3_ipc_callbacks {
|
||||||
void (*burst_done)(void *data);
|
void (*burst_done)(void *data);
|
||||||
|
|
36
modules/i3.c
36
modules/i3.c
|
@ -251,7 +251,7 @@ workspace_lookup(struct private *m, int id)
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
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;
|
struct json_object *version;
|
||||||
if (!json_object_object_get_ex(json, "human_readable", &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
|
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;
|
struct json_object *success;
|
||||||
if (!json_object_object_get_ex(json, "success", &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
|
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 module *mod = _mod;
|
||||||
struct private *m = mod->private;
|
struct private *m = mod->private;
|
||||||
|
@ -337,7 +337,7 @@ err:
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
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 module *mod = _mod;
|
||||||
struct private *m = mod->private;
|
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_empty = strcmp(change_str, "empty") == 0;
|
||||||
bool is_focused = strcmp(change_str, "focus") == 0;
|
bool is_focused = strcmp(change_str, "focus") == 0;
|
||||||
bool is_rename = strcmp(change_str, "rename") == 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;
|
bool is_urgent = strcmp(change_str, "urgent") == 0;
|
||||||
|
|
||||||
struct json_object *current, *_current_id;
|
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);
|
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) {
|
else if (is_urgent) {
|
||||||
struct json_object *urgent;
|
struct json_object *urgent;
|
||||||
if (!json_object_object_get_ex(current, "urgent", &urgent)) {
|
if (!json_object_object_get_ex(current, "urgent", &urgent)) {
|
||||||
|
@ -472,7 +496,7 @@ err:
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
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 module *mod = _mod;
|
||||||
struct private *m = mod->private;
|
struct private *m = mod->private;
|
||||||
|
@ -606,7 +630,7 @@ handle_window_event(int type, const struct json_object *json, void *_mod)
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
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 module *mod = _mod;
|
||||||
struct private *m = mod->private;
|
struct private *m = mod->private;
|
||||||
|
|
|
@ -94,7 +94,7 @@ content(struct module *mod)
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
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 module *mod = _mod;
|
||||||
struct private *m = mod->private;
|
struct private *m = mod->private;
|
||||||
|
@ -162,7 +162,7 @@ handle_input_reply(int type, const struct json_object *json, void *_mod)
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
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 module *mod = _mod;
|
||||||
struct private *m = mod->private;
|
struct private *m = mod->private;
|
||||||
|
|
Loading…
Add table
Reference in a new issue