aboutsummaryrefslogtreecommitdiff
path: root/swaybar/ipc.c
diff options
context:
space:
mode:
authorBrian Ashworth <bosrsf04@gmail.com>2018-10-08 11:40:13 -0400
committerBrian Ashworth <bosrsf04@gmail.com>2018-10-09 08:12:46 -0400
commit1c969e86f50065985ddf35b7fef62c14aa7688a5 (patch)
tree1d44b026ffb8cd67595b695ac92275ba320ee4d9 /swaybar/ipc.c
parente143c9613d350b74e02c5ac3c9a055ab26fc9588 (diff)
Implement bar bindsym
Diffstat (limited to 'swaybar/ipc.c')
-rw-r--r--swaybar/ipc.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/swaybar/ipc.c b/swaybar/ipc.c
index 7c53a44f..70086a36 100644
--- a/swaybar/ipc.c
+++ b/swaybar/ipc.c
@@ -7,6 +7,7 @@
#include "swaybar/config.h"
#include "swaybar/ipc.h"
#include "ipc-client.h"
+#include "list.h"
void ipc_send_workspace_command(struct swaybar *bar, const char *ws) {
const char *fmt = "workspace \"%s\"";
@@ -154,6 +155,7 @@ static bool ipc_parse_config(
json_object *markup, *mode, *hidden_bar, *position, *status_command;
json_object *font, *bar_height, *wrap_scroll, *workspace_buttons, *strip_workspace_numbers;
json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol, *outputs;
+ json_object *bindings;
json_object_object_get_ex(bar_config, "mode", &mode);
json_object_object_get_ex(bar_config, "hidden_bar", &hidden_bar);
json_object_object_get_ex(bar_config, "position", &position);
@@ -169,6 +171,7 @@ static bool ipc_parse_config(
json_object_object_get_ex(bar_config, "colors", &colors);
json_object_object_get_ex(bar_config, "outputs", &outputs);
json_object_object_get_ex(bar_config, "pango_markup", &markup);
+ json_object_object_get_ex(bar_config, "bindings", &bindings);
if (status_command) {
free(config->status_command);
config->status_command = strdup(json_object_get_string(status_command));
@@ -202,6 +205,21 @@ static bool ipc_parse_config(
if (markup) {
config->pango_markup = json_object_get_boolean(markup);
}
+ if (bindings) {
+ int length = json_object_array_length(bindings);
+ for (int i = 0; i < length; ++i) {
+ json_object *bindobj = json_object_array_get_idx(bindings, i);
+ struct swaybar_binding *binding =
+ calloc(1, sizeof(struct swaybar_binding));
+ binding->button = json_object_get_int(
+ json_object_object_get(bindobj, "input_code"));
+ binding->command = strdup(json_object_get_string(
+ json_object_object_get(bindobj, "command")));
+ binding->release = json_object_get_boolean(
+ json_object_object_get(bindobj, "release"));
+ list_add(config->bindings, binding);
+ }
+ }
struct config_output *output, *tmp;
wl_list_for_each_safe(output, tmp, &config->outputs, link) {
@@ -319,6 +337,12 @@ static void ipc_get_outputs(struct swaybar *bar) {
free(res);
}
+void ipc_execute_binding(struct swaybar *bar, struct swaybar_binding *bind) {
+ uint32_t len = strlen(bind->command);
+ free(ipc_single_command(bar->ipc_socketfd,
+ IPC_COMMAND, bind->command, &len));
+}
+
bool ipc_initialize(struct swaybar *bar, const char *bar_id) {
uint32_t len = strlen(bar_id);
char *res = ipc_single_command(bar->ipc_socketfd,