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:
parent
2b6f76852c
commit
715fbf2d80
@ -22,10 +22,16 @@ typedef enum { M_DOCK = 0,
|
|||||||
M_HIDE = 1,
|
M_HIDE = 1,
|
||||||
M_INVISIBLE = 2 } bar_display_mode_t;
|
M_INVISIBLE = 2 } bar_display_mode_t;
|
||||||
|
|
||||||
|
typedef struct mouse_command_t {
|
||||||
|
int button;
|
||||||
|
char *command;
|
||||||
|
|
||||||
|
TAILQ_ENTRY(mouse_command_t) commands;
|
||||||
|
} mouse_command_t;
|
||||||
|
|
||||||
typedef struct config_t {
|
typedef struct config_t {
|
||||||
int modifier;
|
int modifier;
|
||||||
char *wheel_up_cmd;
|
TAILQ_HEAD(mouse_commands_head, mouse_command_t) mouse_commands;
|
||||||
char *wheel_down_cmd;
|
|
||||||
position_t position;
|
position_t position;
|
||||||
int verbose;
|
int verbose;
|
||||||
struct xcb_color_strings_t colors;
|
struct xcb_color_strings_t colors;
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
static char *cur_key;
|
static char *cur_key;
|
||||||
|
static bool parsing_mouse_commands;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse a key.
|
* 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);
|
strncpy(cur_key, (const char *)keyVal, keyLen);
|
||||||
cur_key[keyLen] = '\0';
|
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;
|
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"))
|
if (!strcmp(cur_key, "id") || !strcmp(cur_key, "socket_path"))
|
||||||
return 1;
|
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")) {
|
if (!strcmp(cur_key, "mode")) {
|
||||||
DLOG("mode = %.*s, len = %d\n", len, val, len);
|
DLOG("mode = %.*s, len = %d\n", len, val, len);
|
||||||
config.hide_on_modifier = (len == 4 && !strncmp((const char *)val, "dock", strlen("dock")) ? M_DOCK
|
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;
|
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")) {
|
if (!strcmp(cur_key, "wheel_up_cmd")) {
|
||||||
DLOG("wheel_up_cmd = %.*s\n", len, val);
|
DLOG("wheel_up_cmd = %.*s\n", len, val);
|
||||||
FREE(config.wheel_up_cmd);
|
binding_t *binding = scalloc(sizeof(binding_t));
|
||||||
sasprintf(&config.wheel_up_cmd, "%.*s", len, val);
|
binding->input_code = 4;
|
||||||
|
sasprintf(&(binding->command), "%.*s", len, val);
|
||||||
|
TAILQ_INSERT_TAIL(&(config.bindings), binding, bindings);
|
||||||
return 1;
|
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")) {
|
if (!strcmp(cur_key, "wheel_down_cmd")) {
|
||||||
DLOG("wheel_down_cmd = %.*s\n", len, val);
|
DLOG("wheel_down_cmd = %.*s\n", len, val);
|
||||||
FREE(config.wheel_down_cmd);
|
binding_t *binding = scalloc(sizeof(binding_t));
|
||||||
sasprintf(&config.wheel_down_cmd, "%.*s", len, val);
|
binding->input_code = 5;
|
||||||
|
sasprintf(&(binding->command), "%.*s", len, val);
|
||||||
|
TAILQ_INSERT_TAIL(&(config.bindings), binding, bindings);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,6 +273,7 @@ static yajl_callbacks outputs_callbacks = {
|
|||||||
.yajl_null = config_null_cb,
|
.yajl_null = config_null_cb,
|
||||||
.yajl_boolean = config_boolean_cb,
|
.yajl_boolean = config_boolean_cb,
|
||||||
.yajl_string = config_string_cb,
|
.yajl_string = config_string_cb,
|
||||||
|
.yajl_end_map = config_end_map_cb,
|
||||||
.yajl_map_key = config_map_key_cb,
|
.yajl_map_key = config_map_key_cb,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -249,6 +286,8 @@ void parse_config_json(char *json) {
|
|||||||
yajl_status state;
|
yajl_status state;
|
||||||
handle = yajl_alloc(&outputs_callbacks, NULL, NULL);
|
handle = yajl_alloc(&outputs_callbacks, NULL, NULL);
|
||||||
|
|
||||||
|
TAILQ_INIT(&(config.mouse_commands));
|
||||||
|
|
||||||
state = yajl_parse(handle, (const unsigned char *)json, strlen(json));
|
state = yajl_parse(handle, (const unsigned char *)json, strlen(json));
|
||||||
|
|
||||||
/* FIXME: Proper error handling for JSON parsing */
|
/* FIXME: Proper error handling for JSON parsing */
|
||||||
|
@ -468,20 +468,23 @@ void handle_button(xcb_button_press_event_t *event) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If a custom command was specified for this mouse button, it overrides
|
||||||
|
* the default behavior. */
|
||||||
|
mouse_command_t *command;
|
||||||
|
TAILQ_FOREACH(command, &(config.mouse_commands), commands) {
|
||||||
|
if (command->button != event->detail)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
i3_send_msg(I3_IPC_MESSAGE_TYPE_COMMAND, command->command);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (event->detail) {
|
switch (event->detail) {
|
||||||
case 4:
|
case 4:
|
||||||
/* Mouse wheel up. We select the previous ws, if any.
|
/* Mouse wheel up. We select the previous ws, if any.
|
||||||
* If there is no more workspace, don’t even send the workspace
|
* If there is no more workspace, don’t even send the workspace
|
||||||
* command, otherwise (with workspace auto_back_and_forth) we’d end
|
* command, otherwise (with workspace auto_back_and_forth) we’d end
|
||||||
* up on the wrong workspace. */
|
* up on the wrong workspace. */
|
||||||
|
|
||||||
/* If `wheel_up_cmd [COMMAND]` was specified, it should override
|
|
||||||
* the default behavior */
|
|
||||||
if (config.wheel_up_cmd) {
|
|
||||||
i3_send_msg(I3_IPC_MESSAGE_TYPE_COMMAND, config.wheel_up_cmd);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cur_ws == TAILQ_FIRST(walk->workspaces))
|
if (cur_ws == TAILQ_FIRST(walk->workspaces))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -492,14 +495,6 @@ void handle_button(xcb_button_press_event_t *event) {
|
|||||||
* If there is no more workspace, don’t even send the workspace
|
* If there is no more workspace, don’t even send the workspace
|
||||||
* command, otherwise (with workspace auto_back_and_forth) we’d end
|
* command, otherwise (with workspace auto_back_and_forth) we’d end
|
||||||
* up on the wrong workspace. */
|
* up on the wrong workspace. */
|
||||||
|
|
||||||
/* if `wheel_down_cmd [COMMAND]` was specified, it should override
|
|
||||||
* the default behavior */
|
|
||||||
if (config.wheel_down_cmd) {
|
|
||||||
i3_send_msg(I3_IPC_MESSAGE_TYPE_COMMAND, config.wheel_down_cmd);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cur_ws == TAILQ_LAST(walk->workspaces, ws_head))
|
if (cur_ws == TAILQ_LAST(walk->workspaces, ws_head))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user