Merge branch 'i3-mode'

Closes #19
This commit is contained in:
Daniel Eklöf 2020-12-12 22:42:27 +01:00
commit e411553035
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 37 additions and 2 deletions

View file

@ -20,6 +20,7 @@
list is sorted. Can be set to one of `none`, `ascending` or list is sorted. Can be set to one of `none`, `ascending` or
`descending`. Default is `none` `descending`. Default is `none`
(https://codeberg.org/dnkl/yambar/issues/17). (https://codeberg.org/dnkl/yambar/issues/17).
* i3: `mode` tag: the name of the currently active mode
### Deprecated ### Deprecated

View file

@ -361,6 +361,9 @@ with the _application_ and _title_ tags to replace the X11-only
| title | title
: string : string
: This workspace's focused window's title : This workspace's focused window's title
| mode
: string
: The name of the current mode
## CONFIGURATION ## CONFIGURATION

View file

@ -49,6 +49,8 @@ struct private {
bool dirty; bool dirty;
char *mode;
struct { struct {
struct ws_content *v; struct ws_content *v;
size_t count; size_t count;
@ -459,6 +461,30 @@ handle_window_event(int type, const struct json_object *json, void *_mod)
return true; return true;
} }
static bool
handle_mode_event(int type, const struct json_object *json, void *_mod)
{
struct module *mod = _mod;
struct private *m = mod->private;
struct json_object *change;
if (!json_object_object_get_ex(json, "change", &change)) {
LOG_ERR("mode event without 'change' property");
return false;
}
const char *current_mode = json_object_get_string(change);
mtx_lock(&mod->lock);
{
free(m->mode);
m->mode = strdup(current_mode);
m->dirty = true;
}
mtx_unlock(&mod->lock);
return true;
}
static void static void
burst_done(void *_mod) burst_done(void *_mod)
{ {
@ -492,7 +518,7 @@ run(struct module *mod)
} }
i3_send_pkg(sock, I3_IPC_MESSAGE_TYPE_GET_VERSION, NULL); i3_send_pkg(sock, I3_IPC_MESSAGE_TYPE_GET_VERSION, NULL);
i3_send_pkg(sock, I3_IPC_MESSAGE_TYPE_SUBSCRIBE, "[\"workspace\", \"window\"]"); i3_send_pkg(sock, I3_IPC_MESSAGE_TYPE_SUBSCRIBE, "[\"workspace\", \"window\", \"mode\"]");
i3_send_pkg(sock, I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL); i3_send_pkg(sock, I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL);
static const struct i3_ipc_callbacks callbacks = { static const struct i3_ipc_callbacks callbacks = {
@ -502,6 +528,7 @@ run(struct module *mod)
.reply_workspaces = &handle_get_workspaces_reply, .reply_workspaces = &handle_get_workspaces_reply,
.event_workspace = &handle_workspace_event, .event_workspace = &handle_workspace_event,
.event_window = &handle_window_event, .event_window = &handle_window_event,
.event_mode = &handle_mode_event,
}; };
bool ret = i3_receive_loop(mod->abort_fd, sock, &callbacks, mod); bool ret = i3_receive_loop(mod->abort_fd, sock, &callbacks, mod);
@ -523,6 +550,7 @@ destroy(struct module *mod)
free(m->ws_content.v); free(m->ws_content.v);
workspaces_free(m); workspaces_free(m);
free(m->mode);
free(m); free(m);
module_default_destroy(mod); module_default_destroy(mod);
} }
@ -578,8 +606,10 @@ content(struct module *mod)
tag_new_string(mod, "application", ws->window.application), tag_new_string(mod, "application", ws->window.application),
tag_new_string(mod, "title", ws->window.title), tag_new_string(mod, "title", ws->window.title),
tag_new_string(mod, "mode", m->mode),
}, },
.count = 7, .count = 8,
}; };
if (ws->focused) { if (ws->focused) {
@ -620,6 +650,7 @@ i3_new(struct i3_workspaces workspaces[], size_t workspace_count,
{ {
struct private *m = calloc(1, sizeof(*m)); struct private *m = calloc(1, sizeof(*m));
m->mode = strdup("default");
m->left_spacing = left_spacing; m->left_spacing = left_spacing;
m->right_spacing = right_spacing; m->right_spacing = right_spacing;