diff options
author | 2015-12-15 01:01:01 +0100 | |
---|---|---|
committer | 2015-12-15 01:53:45 +0100 | |
commit | 0ead9324dcf812d8dca5065f40429afaa4733599 (patch) | |
tree | 5a72f7581dcfd75cfabbe93586c2440f0ab19c08 /sway | |
parent | Merge pull request #321 from gpyh/bar_cmds (diff) | |
download | sway-0ead9324dcf812d8dca5065f40429afaa4733599.tar.gz sway-0ead9324dcf812d8dca5065f40429afaa4733599.tar.zst sway-0ead9324dcf812d8dca5065f40429afaa4733599.zip |
Added bar_cmd_modifier
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/sway/commands.c b/sway/commands.c index 053f40fc..5c23a611 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -67,6 +67,7 @@ static sway_cmd cmd_ws_auto_back_and_forth; | |||
67 | 67 | ||
68 | static sway_cmd bar_cmd_bindsym; | 68 | static sway_cmd bar_cmd_bindsym; |
69 | static sway_cmd bar_cmd_mode; | 69 | static sway_cmd bar_cmd_mode; |
70 | static sway_cmd bar_cmd_modifier; | ||
70 | static sway_cmd bar_cmd_hidden_state; | 71 | static sway_cmd bar_cmd_hidden_state; |
71 | static sway_cmd bar_cmd_id; | 72 | static sway_cmd bar_cmd_id; |
72 | static sway_cmd bar_cmd_position; | 73 | static sway_cmd bar_cmd_position; |
@@ -1658,6 +1659,41 @@ static struct cmd_results *bar_cmd_id(int argc, char **argv) { | |||
1658 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 1659 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
1659 | } | 1660 | } |
1660 | 1661 | ||
1662 | static struct cmd_results *bar_cmd_modifier(int argc, char **argv) { | ||
1663 | struct cmd_results *error = NULL; | ||
1664 | if ((error = checkarg(argc, "modifier", EXPECTED_EQUAL_TO, 1))) { | ||
1665 | return error; | ||
1666 | } | ||
1667 | |||
1668 | if (!config->current_bar) { | ||
1669 | return cmd_results_new(CMD_FAILURE, "modifier", "No bar defined."); | ||
1670 | } | ||
1671 | |||
1672 | uint32_t mod = 0; | ||
1673 | |||
1674 | list_t *split = split_string(argv[0], "+"); | ||
1675 | for (int i = 0; i < split->length; ++i) { | ||
1676 | int j; | ||
1677 | bool is_mod = false; | ||
1678 | for (j = 0; j < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++j) { | ||
1679 | if (strcasecmp(modifiers[j].name, split->items[i]) == 0) { | ||
1680 | mod |= modifiers[j].mod; | ||
1681 | is_mod = true; | ||
1682 | break; | ||
1683 | } | ||
1684 | } | ||
1685 | if (!is_mod) { | ||
1686 | free_flat_list(split); | ||
1687 | return cmd_results_new(CMD_INVALID, "modifier", "Unknown modifier '%s'", split->items[i]); | ||
1688 | } | ||
1689 | } | ||
1690 | free_flat_list(split); | ||
1691 | |||
1692 | config->current_bar->modifier = mod; | ||
1693 | sway_log(L_DEBUG, "Show/Hide the bar when pressing '%s' in hide mode.", argv[0]); | ||
1694 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1695 | } | ||
1696 | |||
1661 | static struct cmd_results *bar_cmd_position(int argc, char **argv) { | 1697 | static struct cmd_results *bar_cmd_position(int argc, char **argv) { |
1662 | struct cmd_results *error = NULL; | 1698 | struct cmd_results *error = NULL; |
1663 | if ((error = checkarg(argc, "position", EXPECTED_EQUAL_TO, 1))) { | 1699 | if ((error = checkarg(argc, "position", EXPECTED_EQUAL_TO, 1))) { |
@@ -1769,7 +1805,7 @@ static struct cmd_handler bar_handlers[] = { | |||
1769 | { "hidden_state", bar_cmd_hidden_state }, | 1805 | { "hidden_state", bar_cmd_hidden_state }, |
1770 | { "id", bar_cmd_id }, | 1806 | { "id", bar_cmd_id }, |
1771 | { "mode", bar_cmd_mode }, | 1807 | { "mode", bar_cmd_mode }, |
1772 | { "modifier", NULL }, | 1808 | { "modifier", bar_cmd_modifier }, |
1773 | { "output", NULL }, | 1809 | { "output", NULL }, |
1774 | { "position", bar_cmd_position }, | 1810 | { "position", bar_cmd_position }, |
1775 | { "seperator_symbol", NULL }, | 1811 | { "seperator_symbol", NULL }, |