Read 'bindsym' rather than the old 'wheel_up_cmd' and 'wheel_down_cmd' directives in i3bar and call the command if specified.

The old directives are still read for transitional support which can be removed in a future version.
This commit is contained in:
Ingo Bürk
2015-06-13 14:58:41 +02:00
parent 2b6f76852c
commit 715fbf2d80
3 changed files with 62 additions and 22 deletions

View File

@ -20,6 +20,7 @@
#include "common.h"
static char *cur_key;
static bool parsing_mouse_commands;
/*
* Parse a key.
@ -34,6 +35,14 @@ static int config_map_key_cb(void *params_, const unsigned char *keyVal, size_t
strncpy(cur_key, (const char *)keyVal, keyLen);
cur_key[keyLen] = '\0';
if (strcmp(cur_key, "mouse_commands") == 0)
parsing_mouse_commands = true;
return 1;
}
static int config_end_map_cb(void *params_) {
parsing_mouse_commands = false;
return 1;
}
@ -63,6 +72,25 @@ static int config_string_cb(void *params_, const unsigned char *val, size_t _len
if (!strcmp(cur_key, "id") || !strcmp(cur_key, "socket_path"))
return 1;
if (parsing_mouse_commands) {
int button = atoi(cur_key + sizeof("button") - 1);
mouse_command_t *current;
TAILQ_FOREACH(current, &(config.mouse_commands), commands) {
if (current->button == button) {
FREE(current->command);
sasprintf(&(current->command), "%.*s", len, val);
return 1;
}
}
mouse_command_t *command = scalloc(sizeof(mouse_command_t));
command->button = button;
sasprintf(&(command->command), "%.*s", len, val);
TAILQ_INSERT_TAIL(&(config.mouse_commands), command, commands);
return 1;
}
if (!strcmp(cur_key, "mode")) {
DLOG("mode = %.*s, len = %d\n", len, val, len);
config.hide_on_modifier = (len == 4 && !strncmp((const char *)val, "dock", strlen("dock")) ? M_DOCK
@ -112,17 +140,25 @@ static int config_string_cb(void *params_, const unsigned char *val, size_t _len
return 1;
}
/* This key was sent in <= 4.10.2. We keep it around to avoid breakage for
* users updating from that version and restarting i3bar before i3. */
if (!strcmp(cur_key, "wheel_up_cmd")) {
DLOG("wheel_up_cmd = %.*s\n", len, val);
FREE(config.wheel_up_cmd);
sasprintf(&config.wheel_up_cmd, "%.*s", len, val);
binding_t *binding = scalloc(sizeof(binding_t));
binding->input_code = 4;
sasprintf(&(binding->command), "%.*s", len, val);
TAILQ_INSERT_TAIL(&(config.bindings), binding, bindings);
return 1;
}
/* This key was sent in <= 4.10.2. We keep it around to avoid breakage for
* users updating from that version and restarting i3bar before i3. */
if (!strcmp(cur_key, "wheel_down_cmd")) {
DLOG("wheel_down_cmd = %.*s\n", len, val);
FREE(config.wheel_down_cmd);
sasprintf(&config.wheel_down_cmd, "%.*s", len, val);
binding_t *binding = scalloc(sizeof(binding_t));
binding->input_code = 5;
sasprintf(&(binding->command), "%.*s", len, val);
TAILQ_INSERT_TAIL(&(config.bindings), binding, bindings);
return 1;
}
@ -237,6 +273,7 @@ static yajl_callbacks outputs_callbacks = {
.yajl_null = config_null_cb,
.yajl_boolean = config_boolean_cb,
.yajl_string = config_string_cb,
.yajl_end_map = config_end_map_cb,
.yajl_map_key = config_map_key_cb,
};
@ -249,6 +286,8 @@ void parse_config_json(char *json) {
yajl_status state;
handle = yajl_alloc(&outputs_callbacks, NULL, NULL);
TAILQ_INIT(&(config.mouse_commands));
state = yajl_parse(handle, (const unsigned char *)json, strlen(json));
/* FIXME: Proper error handling for JSON parsing */