From 2b6f76852c3c27fddcbff198960504eba263c007 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ingo=20B=C3=BCrk?= Date: Sat, 2 May 2015 21:54:56 +0200 Subject: [PATCH] Implement i3's logic for maintaining a list of 'bindsym' directives and passing it to i3bar through the IPC. --- include/config.h | 23 ++++++++++++++++------- src/config_directives.c | 17 +++++++++++++++++ src/ipc.c | 23 ++++++++++++++--------- testcases/t/201-config-parser.t | 1 + 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/include/config.h b/include/config.h index 33cbaba0..3955fc79 100644 --- a/include/config.h +++ b/include/config.h @@ -281,13 +281,7 @@ struct Barconfig { M_MOD5 = 7 } modifier; - /** Command that should be run when mouse wheel up button is pressed over - * i3bar to override the default behavior. */ - char *wheel_up_cmd; - - /** Command that should be run when mouse wheel down button is pressed over - * i3bar to override the default behavior. */ - char *wheel_down_cmd; + TAILQ_HEAD(mouse_commands_head, Mousecommand) mouse_commands; /** Bar position (bottom by default). */ enum { P_BOTTOM = 0, @@ -353,6 +347,21 @@ struct Barconfig { TAILQ_ENTRY(Barconfig) configs; }; +/** + * Defines a mouse command to be executed instead of the default behavior when + * clicking on the non-statusline part of i3bar. + * + */ +struct Mousecommand { + /** The button for this command (e.g., "button1") */ + char *button; + + /** The command which is to be executed for this button. */ + char *command; + + TAILQ_ENTRY(Mousecommand) commands; +}; + /** * Finds the configuration file to use (either the one specified by * override_configpath), the user’s one or the system default) and calls diff --git a/src/config_directives.c b/src/config_directives.c index cf15d8d4..182f2e35 100644 --- a/src/config_directives.c +++ b/src/config_directives.c @@ -531,6 +531,23 @@ CFGFUN(bar_modifier, const char *modifier) { } static void bar_configure_mouse_command(const char *button, const char *command) { + if (strncasecmp(button, "button", sizeof("button") - 1) != 0) { + ELOG("unknown button \"%s\" for mouse command, ignoring.\n", button); + return; + } + + struct Mousecommand *current; + TAILQ_FOREACH(current, &(current_bar.mouse_commands), commands) { + if (strcasecmp(current->button, button) == 0) { + ELOG("command for button %s was already specified, ignoring.\n", button); + return; + } + } + + struct Mousecommand *new_command = scalloc(sizeof(struct Mousecommand)); + new_command->button = sstrdup(button); + new_command->command = sstrdup(command); + TAILQ_INSERT_TAIL(&(current_bar.mouse_commands), new_command, commands); } CFGFUN(bar_wheel_up_cmd, const char *command) { diff --git a/src/ipc.c b/src/ipc.c index ae213b3a..fa028834 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -469,6 +469,19 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) { y(map_close); } +static void dump_mouse_commands(yajl_gen gen, Barconfig *config) { + ystr("mouse_commands"); + y(map_open); + + struct Mousecommand *current; + TAILQ_FOREACH(current, &(config->mouse_commands), commands) { + ystr(current->button); + ystr(current->command); + } + + y(map_close); +} + static void dump_bar_config(yajl_gen gen, Barconfig *config) { y(map_open); @@ -549,15 +562,7 @@ static void dump_bar_config(yajl_gen gen, Barconfig *config) { break; } - if (config->wheel_up_cmd) { - ystr("wheel_up_cmd"); - ystr(config->wheel_up_cmd); - } - - if (config->wheel_down_cmd) { - ystr("wheel_down_cmd"); - ystr(config->wheel_down_cmd); - } + dump_mouse_commands(gen, config); ystr("position"); if (config->position == P_BOTTOM) diff --git a/testcases/t/201-config-parser.t b/testcases/t/201-config-parser.t index 9dc0f840..faf2f0db 100644 --- a/testcases/t/201-config-parser.t +++ b/testcases/t/201-config-parser.t @@ -688,6 +688,7 @@ bar { EOT $expected = <<'EOT'; +cfg_bar_start() cfg_bar_output(LVDS-1) ERROR: CONFIG: Expected one of these tokens: , '#', 'set', 'i3bar_command', 'status_command', 'socket_path', 'mode', 'hidden_state', 'id', 'modifier', 'wheel_up_cmd', 'wheel_down_cmd', 'bindsym', 'position', 'output', 'tray_output', 'font', 'separator_symbol', 'binding_mode_indicator', 'workspace_buttons', 'strip_workspace_numbers', 'verbose', 'colors', '}' ERROR: CONFIG: (in file ) -- 2.39.5