diff options
author | 2015-12-14 23:43:52 +0100 | |
---|---|---|
committer | 2015-12-15 00:15:32 +0100 | |
commit | 87126a9fc2306f8e15e6148ccdc021517c414114 (patch) | |
tree | 9b81f04d730f5ee0f5e7323517c0e31164cc0cf8 /sway/commands.c | |
parent | Merge pull request #320 from mikkeloscar/configure-mouse-btn2 (diff) | |
download | sway-87126a9fc2306f8e15e6148ccdc021517c414114.tar.gz sway-87126a9fc2306f8e15e6148ccdc021517c414114.tar.zst sway-87126a9fc2306f8e15e6148ccdc021517c414114.zip |
Added bar_cmd_bindsym
Defined a sway_mouse_binding for clicks on the swaybar
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/sway/commands.c b/sway/commands.c index aa4cb89e..053f40fc 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -65,6 +65,7 @@ static sway_cmd cmd_sticky; | |||
65 | static sway_cmd cmd_workspace; | 65 | static sway_cmd cmd_workspace; |
66 | static sway_cmd cmd_ws_auto_back_and_forth; | 66 | static sway_cmd cmd_ws_auto_back_and_forth; |
67 | 67 | ||
68 | static sway_cmd bar_cmd_bindsym; | ||
68 | static sway_cmd bar_cmd_mode; | 69 | static sway_cmd bar_cmd_mode; |
69 | static sway_cmd bar_cmd_hidden_state; | 70 | static sway_cmd bar_cmd_hidden_state; |
70 | static sway_cmd bar_cmd_id; | 71 | static sway_cmd bar_cmd_id; |
@@ -1132,6 +1133,7 @@ static struct cmd_results *cmd_bar(int argc, char **argv) { | |||
1132 | bar->hidden_state = strdup(config->bar.hidden_state); | 1133 | bar->hidden_state = strdup(config->bar.hidden_state); |
1133 | bar->modifier = config->bar.modifier; | 1134 | bar->modifier = config->bar.modifier; |
1134 | bar->position = config->bar.position; | 1135 | bar->position = config->bar.position; |
1136 | bar->bindings = create_list(); | ||
1135 | bar->status_command = strdup(config->bar.status_command); | 1137 | bar->status_command = strdup(config->bar.status_command); |
1136 | bar->font = strdup(config->bar.font); | 1138 | bar->font = strdup(config->bar.font); |
1137 | bar->bar_height = config->bar.bar_height; | 1139 | bar->bar_height = config->bar.bar_height; |
@@ -1539,6 +1541,44 @@ static struct cmd_handler handlers[] = { | |||
1539 | { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth }, | 1541 | { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth }, |
1540 | }; | 1542 | }; |
1541 | 1543 | ||
1544 | static struct cmd_results *bar_cmd_bindsym(int argc, char **argv) { | ||
1545 | struct cmd_results *error = NULL; | ||
1546 | if ((error = checkarg(argc, "bindsym", EXPECTED_MORE_THAN, 1))) { | ||
1547 | return error; | ||
1548 | } else if (!config->reading) { | ||
1549 | return cmd_results_new(CMD_FAILURE, "bindsym", "Can only be used in config file."); | ||
1550 | } | ||
1551 | |||
1552 | if (!config->current_bar) { | ||
1553 | return cmd_results_new(CMD_FAILURE, "bindsym", "No bar defined."); | ||
1554 | } | ||
1555 | |||
1556 | if (strlen(argv[1]) != 7) { | ||
1557 | return cmd_results_new(CMD_INVALID, "bindsym", "Invalid mouse binding %s", argv[1]); | ||
1558 | } | ||
1559 | uint32_t numbutton = (uint32_t)atoi(argv[1] + 6); | ||
1560 | if (numbutton < 1 || numbutton > 5 || strncmp(argv[1], "button", 6) != 0) { | ||
1561 | return cmd_results_new(CMD_INVALID, "bindsym", "Invalid mouse binding %s", argv[1]); | ||
1562 | } | ||
1563 | struct sway_mouse_binding *binding = malloc(sizeof(struct sway_mouse_binding)); | ||
1564 | binding->button = numbutton; | ||
1565 | binding->command = join_args(argv + 1, argc - 1); | ||
1566 | |||
1567 | struct bar_config *bar = config->current_bar; | ||
1568 | int i = list_seq_find(bar->bindings, sway_mouse_binding_cmp_buttons, binding); | ||
1569 | if (i > -1) { | ||
1570 | sway_log(L_DEBUG, "bindsym - '%s' for swaybar already exists, overwriting", argv[0]); | ||
1571 | struct sway_mouse_binding *dup = bar->bindings->items[i]; | ||
1572 | free_sway_mouse_binding(dup); | ||
1573 | list_del(bar->bindings, i); | ||
1574 | } | ||
1575 | list_add(bar->bindings, binding); | ||
1576 | list_sort(bar->bindings, sway_mouse_binding_cmp); | ||
1577 | |||
1578 | sway_log(L_DEBUG, "bindsym - Bound %s to command %s when clicking swaybar", argv[0], binding->command); | ||
1579 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1580 | } | ||
1581 | |||
1542 | static struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) { | 1582 | static struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) { |
1543 | struct cmd_results *error = NULL; | 1583 | struct cmd_results *error = NULL; |
1544 | if ((error = checkarg(argc, "hidden_state", EXPECTED_EQUAL_TO, 1))) { | 1584 | if ((error = checkarg(argc, "hidden_state", EXPECTED_EQUAL_TO, 1))) { |
@@ -1723,7 +1763,7 @@ static struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) { | |||
1723 | 1763 | ||
1724 | static struct cmd_handler bar_handlers[] = { | 1764 | static struct cmd_handler bar_handlers[] = { |
1725 | { "binding_mode_indicator", NULL }, | 1765 | { "binding_mode_indicator", NULL }, |
1726 | { "bindsym", NULL }, | 1766 | { "bindsym", bar_cmd_bindsym }, |
1727 | { "colors", NULL }, | 1767 | { "colors", NULL }, |
1728 | { "font", NULL }, | 1768 | { "font", NULL }, |
1729 | { "hidden_state", bar_cmd_hidden_state }, | 1769 | { "hidden_state", bar_cmd_hidden_state }, |