Implement i3's logic for maintaining a list of 'bindsym' directives and passing it to i3bar through the IPC.

next
Ingo Bürk 2015-05-02 21:54:56 +02:00
parent ab12d3fc74
commit 2b6f76852c
4 changed files with 48 additions and 16 deletions

View File

@ -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 users one or the system default) and calls

View File

@ -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) {

View File

@ -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)

View File

@ -688,6 +688,7 @@ bar {
EOT
$expected = <<'EOT';
cfg_bar_start()
cfg_bar_output(LVDS-1)
ERROR: CONFIG: Expected one of these tokens: <end>, '#', '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 <stdin>)