aboutsummaryrefslogtreecommitdiff
path: root/sway/commands
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/bar.c57
-rw-r--r--sway/commands/bar/activate_button.c8
-rw-r--r--sway/commands/bar/binding_mode_indicator.c27
-rw-r--r--sway/commands/bar/bindsym.c11
-rw-r--r--sway/commands/bar/colors.c124
-rw-r--r--sway/commands/bar/context_button.c8
-rw-r--r--sway/commands/bar/font.c21
-rw-r--r--sway/commands/bar/height.c20
-rw-r--r--sway/commands/bar/hidden_state.c73
-rw-r--r--sway/commands/bar/icon_theme.c8
-rw-r--r--sway/commands/bar/id.c30
-rw-r--r--sway/commands/bar/mode.c74
-rw-r--r--sway/commands/bar/modifier.c35
-rw-r--r--sway/commands/bar/output.c49
-rw-r--r--sway/commands/bar/pango_markup.c28
-rw-r--r--sway/commands/bar/position.c26
-rw-r--r--sway/commands/bar/secondary_button.c8
-rw-r--r--sway/commands/bar/separator_symbol.c20
-rw-r--r--sway/commands/bar/status_command.c20
-rw-r--r--sway/commands/bar/strip_workspace_numbers.c29
-rw-r--r--sway/commands/bar/swaybar_command.c20
-rw-r--r--sway/commands/bar/tray_output.c8
-rw-r--r--sway/commands/bar/tray_padding.c9
-rw-r--r--sway/commands/bar/workspace_buttons.c28
-rw-r--r--sway/commands/bar/wrap_scroll.c27
-rw-r--r--sway/commands/mode.c59
-rw-r--r--sway/commands/reload.c3
-rw-r--r--sway/commands/swaybg_command.c20
28 files changed, 848 insertions, 2 deletions
diff --git a/sway/commands/bar.c b/sway/commands/bar.c
new file mode 100644
index 00000000..ff111163
--- /dev/null
+++ b/sway/commands/bar.c
@@ -0,0 +1,57 @@
+#include <string.h>
+#include <strings.h>
+#include <wlr/util/log.h>
+#include "sway/commands.h"
+#include "sway/config.h"
+#include "util.h"
+
+struct cmd_results *cmd_bar(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "bar", EXPECTED_AT_LEAST, 1))) {
+ return error;
+ }
+
+ if (config->reading && strcmp("{", argv[0]) != 0) {
+ return cmd_results_new(CMD_INVALID, "bar",
+ "Expected '{' at start of bar config definition.");
+ }
+
+ if (!config->reading) {
+ if (argc > 1) {
+ if (strcasecmp("mode", argv[0]) == 0) {
+ return bar_cmd_mode(argc-1, argv + 1);
+ }
+
+ if (strcasecmp("hidden_state", argv[0]) == 0) {
+ return bar_cmd_hidden_state(argc-1, argv + 1);
+ }
+ }
+ return cmd_results_new(CMD_FAILURE, "bar", "Can only be used in config file.");
+ }
+
+ // Create new bar with default values
+ struct bar_config *bar = default_bar_config();
+ if (!bar) {
+ return cmd_results_new(CMD_FAILURE, "bar", "Unable to allocate bar state");
+ }
+
+ // set bar id
+ for (int i = 0; i < config->bars->length; ++i) {
+ if (bar == config->bars->items[i]) {
+ const int len = 5 + numlen(i); // "bar-" + i + \0
+ bar->id = malloc(len * sizeof(char));
+ if (bar->id) {
+ snprintf(bar->id, len, "bar-%d", i);
+ } else {
+ return cmd_results_new(CMD_FAILURE,
+ "bar", "Unable to allocate bar ID");
+ }
+ break;
+ }
+ }
+
+ // Set current bar
+ config->current_bar = bar;
+ wlr_log(L_DEBUG, "Configuring bar %s", bar->id);
+ return cmd_results_new(CMD_BLOCK_BAR, NULL, NULL);
+}
diff --git a/sway/commands/bar/activate_button.c b/sway/commands/bar/activate_button.c
new file mode 100644
index 00000000..7310e7ec
--- /dev/null
+++ b/sway/commands/bar/activate_button.c
@@ -0,0 +1,8 @@
+#include <stdlib.h>
+#include "sway/commands.h"
+#include "log.h"
+
+struct cmd_results *bar_cmd_activate_button(int argc, char **argv) {
+ // TODO TRAY
+ return cmd_results_new(CMD_INVALID, "activate_button", "TODO TRAY");
+}
diff --git a/sway/commands/bar/binding_mode_indicator.c b/sway/commands/bar/binding_mode_indicator.c
new file mode 100644
index 00000000..3ba5f33f
--- /dev/null
+++ b/sway/commands/bar/binding_mode_indicator.c
@@ -0,0 +1,27 @@
+#include <string.h>
+#include <strings.h>
+#include "sway/commands.h"
+#include "log.h"
+
+struct cmd_results *bar_cmd_binding_mode_indicator(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc,
+ "binding_mode_indicator", EXPECTED_EQUAL_TO, 1))) {
+ return error;
+ }
+ if (!config->current_bar) {
+ return cmd_results_new(CMD_FAILURE,
+ "binding_mode_indicator", "No bar defined.");
+ }
+ if (strcasecmp("yes", argv[0]) == 0) {
+ config->current_bar->binding_mode_indicator = true;
+ wlr_log(L_DEBUG, "Enabling binding mode indicator on bar: %s",
+ config->current_bar->id);
+ } else if (strcasecmp("no", argv[0]) == 0) {
+ config->current_bar->binding_mode_indicator = false;
+ wlr_log(L_DEBUG, "Disabling binding mode indicator on bar: %s",
+ config->current_bar->id);
+ }
+ return cmd_results_new(CMD_INVALID, "binding_mode_indicator",
+ "Invalid value %s", argv[0]);
+}
diff --git a/sway/commands/bar/bindsym.c b/sway/commands/bar/bindsym.c
new file mode 100644
index 00000000..ac09a03f
--- /dev/null
+++ b/sway/commands/bar/bindsym.c
@@ -0,0 +1,11 @@
+#include <stdlib.h>
+#include <string.h>
+#include "sway/commands.h"
+#include "sway/config.h"
+#include "list.h"
+#include "log.h"
+#include "stringop.h"
+
+struct cmd_results *bar_cmd_bindsym(int argc, char **argv) {
+ return cmd_results_new(CMD_FAILURE, "bindsym", "TODO"); // TODO
+}
diff --git a/sway/commands/bar/colors.c b/sway/commands/bar/colors.c
new file mode 100644
index 00000000..17ba9b7c
--- /dev/null
+++ b/sway/commands/bar/colors.c
@@ -0,0 +1,124 @@
+#include <string.h>
+#include "sway/commands.h"
+
+static struct cmd_results *parse_single_color(char **color,
+ const char *cmd_name, int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, cmd_name, EXPECTED_EQUAL_TO, 1))) {
+ return error;
+ }
+ if (!*color && !(*color = malloc(10))) {
+ return NULL;
+ }
+ error = add_color(cmd_name, *color, argv[0]);
+ if (error) {
+ return error;
+ }
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
+
+static struct cmd_results *parse_three_colors(char ***colors,
+ const char *cmd_name, int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if (argc != 3) {
+ return cmd_results_new(CMD_INVALID,
+ cmd_name, "Requires exactly three color values");
+ }
+ for (size_t i = 0; i < 3; i++) {
+ if (!*colors[i] && !(*(colors[i]) = malloc(10))) {
+ return NULL;
+ }
+ error = add_color(cmd_name, *(colors[i]), argv[i]);
+ if (error) {
+ return error;
+ }
+ }
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
+
+struct cmd_results *bar_cmd_colors(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "colors", EXPECTED_EQUAL_TO, 1))) {
+ return error;
+ }
+ if (strcmp("{", argv[0]) != 0) {
+ return cmd_results_new(CMD_INVALID, "colors",
+ "Expected '{' at the start of colors config definition.");
+ }
+ return cmd_results_new(CMD_BLOCK_BAR_COLORS, NULL, NULL);
+}
+
+struct cmd_results *bar_colors_cmd_active_workspace(int argc, char **argv) {
+ char **colors[3] = {
+ &(config->current_bar->colors.active_workspace_border),
+ &(config->current_bar->colors.active_workspace_bg),
+ &(config->current_bar->colors.active_workspace_text)
+ };
+ return parse_three_colors(colors, "active_workspace", argc, argv);
+}
+
+struct cmd_results *bar_colors_cmd_background(int argc, char **argv) {
+ return parse_single_color(&(config->current_bar->colors.background),
+ "background", argc, argv);
+}
+
+struct cmd_results *bar_colors_cmd_focused_background(int argc, char **argv) {
+ return parse_single_color(&(config->current_bar->colors.focused_background),
+ "focused_background", argc, argv);
+}
+
+struct cmd_results *bar_colors_cmd_binding_mode(int argc, char **argv) {
+ char **colors[3] = {
+ &(config->current_bar->colors.binding_mode_border),
+ &(config->current_bar->colors.binding_mode_bg),
+ &(config->current_bar->colors.binding_mode_text)
+ };
+ return parse_three_colors(colors, "binding_mode", argc, argv);
+}
+
+struct cmd_results *bar_colors_cmd_focused_workspace(int argc, char **argv) {
+ char **colors[3] = {
+ &(config->current_bar->colors.focused_workspace_border),
+ &(config->current_bar->colors.focused_workspace_bg),
+ &(config->current_bar->colors.focused_workspace_text)
+ };
+ return parse_three_colors(colors, "focused_workspace", argc, argv);
+}
+
+struct cmd_results *bar_colors_cmd_inactive_workspace(int argc, char **argv) {
+ char **colors[3] = {
+ &(config->current_bar->colors.inactive_workspace_border),
+ &(config->current_bar->colors.inactive_workspace_bg),
+ &(config->current_bar->colors.inactive_workspace_text)
+ };
+ return parse_three_colors(colors, "inactive_workspace", argc, argv);
+}
+
+struct cmd_results *bar_colors_cmd_separator(int argc, char **argv) {
+ return parse_single_color(&(config->current_bar->colors.separator),
+ "separator", argc, argv);
+}
+
+struct cmd_results *bar_colors_cmd_focused_separator(int argc, char **argv) {
+ return parse_single_color(&(config->current_bar->colors.focused_separator),
+ "focused_separator", argc, argv);
+}
+
+struct cmd_results *bar_colors_cmd_statusline(int argc, char **argv) {
+ return parse_single_color(&(config->current_bar->colors.statusline),
+ "statusline", argc, argv);
+}
+
+struct cmd_results *bar_colors_cmd_focused_statusline(int argc, char **argv) {
+ return parse_single_color(&(config->current_bar->colors.focused_separator),
+ "focused_separator", argc, argv);
+}
+
+struct cmd_results *bar_colors_cmd_urgent_workspace(int argc, char **argv) {
+ char **colors[3] = {
+ &(config->current_bar->colors.urgent_workspace_border),
+ &(config->current_bar->colors.urgent_workspace_bg),
+ &(config->current_bar->colors.urgent_workspace_text)
+ };
+ return parse_three_colors(colors, "urgent_workspace", argc, argv);
+}
diff --git a/sway/commands/bar/context_button.c b/sway/commands/bar/context_button.c
new file mode 100644
index 00000000..3b76885a
--- /dev/null
+++ b/sway/commands/bar/context_button.c
@@ -0,0 +1,8 @@
+#include <stdlib.h>
+#include "sway/commands.h"
+#include "log.h"
+
+struct cmd_results *bar_cmd_context_button(int argc, char **argv) {
+ // TODO TRAY
+ return cmd_results_new(CMD_INVALID, "context_button", "TODO TRAY");
+}
diff --git a/sway/commands/bar/font.c b/sway/commands/bar/font.c
new file mode 100644
index 00000000..80b7a593
--- /dev/null
+++ b/sway/commands/bar/font.c
@@ -0,0 +1,21 @@
+#define _POSIX_C_SOURCE 200809L
+#include <string.h>
+#include "sway/commands.h"
+#include "log.h"
+#include "stringop.h"
+
+struct cmd_results *bar_cmd_font(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "font", EXPECTED_AT_LEAST, 1))) {
+ return error;
+ }
+ if (!config->current_bar) {
+ return cmd_results_new(CMD_FAILURE, "font", "No bar defined.");
+ }
+ char *font = join_args(argv, argc);
+ free(config->current_bar->font);
+ config->current_bar->font = strdup(font);
+ wlr_log(L_DEBUG, "Settings font '%s' for bar: %s",
+ config->current_bar->font, config->current_bar->id);
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/commands/bar/height.c b/sway/commands/bar/height.c
new file mode 100644
index 00000000..3160caed
--- /dev/null
+++ b/sway/commands/bar/height.c
@@ -0,0 +1,20 @@
+#include <stdlib.h>
+#include <string.h>
+#include "sway/commands.h"
+#include "log.h"
+
+struct cmd_results *bar_cmd_height(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "height", EXPECTED_EQUAL_TO, 1))) {
+ return error;
+ }
+ int height = atoi(argv[0]);
+ if (height < 0) {
+ return cmd_results_new(CMD_INVALID, "height",
+ "Invalid height value: %s", argv[0]);
+ }
+ config->current_bar->height = height;
+ wlr_log(L_DEBUG, "Setting bar height to %d on bar: %s",
+ height, config->current_bar->id);
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/commands/bar/hidden_state.c b/sway/commands/bar/hidden_state.c
new file mode 100644
index 00000000..6641f184
--- /dev/null
+++ b/sway/commands/bar/hidden_state.c
@@ -0,0 +1,73 @@
+#define _XOPEN_SOURCE 500
+#include <string.h>
+#include <strings.h>
+#include "sway/commands.h"
+#include "sway/config.h"
+#include "sway/ipc-server.h"
+#include "log.h"
+
+static struct cmd_results *bar_set_hidden_state(struct bar_config *bar,
+ const char *hidden_state) {
+ char *old_state = bar->hidden_state;
+ if (strcasecmp("toggle", hidden_state) == 0 && !config->reading) {
+ if (strcasecmp("hide", bar->hidden_state) == 0) {
+ bar->hidden_state = strdup("show");
+ } else if (strcasecmp("show", bar->hidden_state) == 0) {
+ bar->hidden_state = strdup("hide");
+ }
+ } else if (strcasecmp("hide", hidden_state) == 0) {
+ bar->hidden_state = strdup("hide");
+ } else if (strcasecmp("show", hidden_state) == 0) {
+ bar->hidden_state = strdup("show");
+ } else {
+ return cmd_results_new(CMD_INVALID, "hidden_state",
+ "Invalid value %s", hidden_state);
+ }
+ if (strcmp(old_state, bar->hidden_state) != 0) {
+ if (!config->reading) {
+ ipc_event_barconfig_update(bar);
+ }
+ wlr_log(L_DEBUG, "Setting hidden_state: '%s' for bar: %s",
+ bar->hidden_state, bar->id);
+ }
+ // free old mode
+ free(old_state);
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
+
+struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "hidden_state", EXPECTED_AT_LEAST, 1))) {
+ return error;
+ }
+ if ((error = checkarg(argc, "hidden_state", EXPECTED_LESS_THAN, 3))) {
+ return error;
+ }
+ if (config->reading && argc > 1) {
+ return cmd_results_new(CMD_INVALID, "hidden_state",
+ "Unexpected value %s in config mode", argv[1]);
+ }
+
+ const char *state = argv[0];
+ if (config->reading) {
+ return bar_set_hidden_state(config->current_bar, state);
+ }
+
+ const char *id = NULL;
+ if (argc == 2) {
+ id = argv[1];
+ }
+ struct bar_config *bar;
+ for (int i = 0; i < config->bars->length; ++i) {
+ bar = config->bars->items[i];
+ if (id && strcmp(id, bar->id) == 0) {
+ return bar_set_hidden_state(bar, state);
+ }
+
+ error = bar_set_hidden_state(bar, state);
+ if (error) {
+ return error;
+ }
+ }
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/commands/bar/icon_theme.c b/sway/commands/bar/icon_theme.c
new file mode 100644
index 00000000..44cd3076
--- /dev/null
+++ b/sway/commands/bar/icon_theme.c
@@ -0,0 +1,8 @@
+#define _XOPEN_SOURCE 500
+#include <string.h>
+#include "sway/commands.h"
+
+struct cmd_results *bar_cmd_icon_theme(int argc, char **argv) {
+ // TODO TRAY
+ return cmd_results_new(CMD_INVALID, "icon_theme", "TODO TRAY");
+}
diff --git a/sway/commands/bar/id.c b/sway/commands/bar/id.c
new file mode 100644
index 00000000..c1e56f03
--- /dev/null
+++ b/sway/commands/bar/id.c
@@ -0,0 +1,30 @@
+#define _XOPEN_SOURCE 500
+#include <string.h>
+#include "sway/commands.h"
+#include "log.h"
+
+struct cmd_results *bar_cmd_id(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "id", EXPECTED_EQUAL_TO, 1))) {
+ return error;
+ }
+
+ const char *name = argv[0];
+ const char *oldname = config->current_bar->id;
+ // check if id is used by a previously defined bar
+ for (int i = 0; i < config->bars->length; ++i) {
+ struct bar_config *find = config->bars->items[i];
+ if (strcmp(name, find->id) == 0 && config->current_bar != find) {
+ return cmd_results_new(CMD_FAILURE, "id",
+ "Id '%s' already defined for another bar. Id unchanged (%s).",
+ name, oldname);
+ }
+ }
+
+ wlr_log(L_DEBUG, "Renaming bar: '%s' to '%s'", oldname, name);
+
+ // free old bar id
+ free(config->current_bar->id);
+ config->current_bar->id = strdup(name);
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/commands/bar/mode.c b/sway/commands/bar/mode.c
new file mode 100644
index 00000000..34bb0a4f
--- /dev/null
+++ b/sway/commands/bar/mode.c
@@ -0,0 +1,74 @@
+#define _XOPEN_SOURCE 500
+#include <string.h>
+#include <strings.h>
+#include "sway/commands.h"
+#include "sway/config.h"
+#include "sway/ipc-server.h"
+#include "log.h"
+
+static struct cmd_results *bar_set_mode(struct bar_config *bar, const char *mode) {
+ char *old_mode = bar->mode;
+ if (strcasecmp("toggle", mode) == 0 && !config->reading) {
+ if (strcasecmp("dock", bar->mode) == 0) {
+ bar->mode = strdup("hide");
+ } else if (strcasecmp("hide", bar->mode) == 0) {
+ bar->mode = strdup("dock");
+ }
+ } else if (strcasecmp("dock", mode) == 0) {
+ bar->mode = strdup("dock");
+ } else if (strcasecmp("hide", mode) == 0) {
+ bar->mode = strdup("hide");
+ } else if (strcasecmp("invisible", mode) == 0) {
+ bar->mode = strdup("invisible");
+ } else {
+ return cmd_results_new(CMD_INVALID, "mode", "Invalid value %s", mode);
+ }
+
+ if (strcmp(old_mode, bar->mode) != 0) {
+ if (!config->reading) {
+ ipc_event_barconfig_update(bar);
+ }
+ wlr_log(L_DEBUG, "Setting mode: '%s' for bar: %s", bar->mode, bar->id);
+ }
+
+ // free old mode
+ free(old_mode);
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
+
+struct cmd_results *bar_cmd_mode(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "mode", EXPECTED_AT_LEAST, 1))) {
+ return error;
+ }
+ if ((error = checkarg(argc, "mode", EXPECTED_LESS_THAN, 3))) {
+ return error;
+ }
+ if (config->reading && argc > 1) {
+ return cmd_results_new(CMD_INVALID,
+ "mode", "Unexpected value %s in config mode", argv[1]);
+ }
+
+ const char *mode = argv[0];
+ if (config->reading) {
+ return bar_set_mode(config->current_bar, mode);
+ }
+
+ const char *id = NULL;
+ if (argc == 2) {
+ id = argv[1];
+ }
+
+ struct bar_config *bar;
+ for (int i = 0; i < config->bars->length; ++i) {
+ bar = config->bars->items[i];
+ if (id && strcmp(id, bar->id) == 0) {
+ return bar_set_mode(bar, mode);
+ }
+ error = bar_set_mode(bar, mode);
+ if (error) {
+ return error;
+ }
+ }
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/commands/bar/modifier.c b/sway/commands/bar/modifier.c
new file mode 100644
index 00000000..7ba4b125
--- /dev/null
+++ b/sway/commands/bar/modifier.c
@@ -0,0 +1,35 @@
+#include <string.h>
+#include "sway/commands.h"
+#include "log.h"
+#include "stringop.h"
+#include "util.h"
+
+struct cmd_results *bar_cmd_modifier(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "modifier", EXPECTED_EQUAL_TO, 1))) {
+ return error;
+ }
+
+ if (!config->current_bar) {
+ return cmd_results_new(CMD_FAILURE, "modifier", "No bar defined.");
+ }
+
+ uint32_t mod = 0;
+ list_t *split = split_string(argv[0], "+");
+ for (int i = 0; i < split->length; ++i) {
+ uint32_t tmp_mod;
+ if ((tmp_mod = get_modifier_mask_by_name(split->items[i])) > 0) {
+ mod |= tmp_mod;
+ continue;
+ } else {
+ free_flat_list(split);
+ return cmd_results_new(CMD_INVALID, "modifier",
+ "Unknown modifier '%s'", split->items[i]);
+ }
+ }
+ free_flat_list(split);
+ config->current_bar->modifier = mod;
+ wlr_log(L_DEBUG,
+ "Show/Hide the bar when pressing '%s' in hide mode.", argv[0]);
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/commands/bar/output.c b/sway/commands/bar/output.c
new file mode 100644
index 00000000..f7ca0aa4
--- /dev/null
+++ b/sway/commands/bar/output.c
@@ -0,0 +1,49 @@
+#define _XOPEN_SOURCE 500
+#include <stdbool.h>
+#include <string.h>
+#include "sway/commands.h"
+#include "list.h"
+#include "log.h"
+
+struct cmd_results *bar_cmd_output(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "output", EXPECTED_EQUAL_TO, 1))) {
+ return error;
+ }
+ if (!config->current_bar) {
+ return cmd_results_new(CMD_FAILURE, "output", "No bar defined.");
+ }
+
+ const char *output = argv[0];
+ list_t *outputs = config->current_bar->outputs;
+ if (!outputs) {
+ outputs = create_list();
+ config->current_bar->outputs = outputs;
+ }
+
+ bool add_output = true;
+ if (strcmp("*", output) == 0) {
+ // remove all previous defined outputs and replace with '*'
+ for (int i = 0; i < outputs->length; ++i) {
+ free(outputs->items[i]);
+ list_del(outputs, i);
+ }
+ } else {
+ // only add output if not already defined with either the same
+ // name or as '*'
+ for (int i = 0; i < outputs->length; ++i) {
+ const char *find = outputs->items[i];
+ if (strcmp("*", find) == 0 || strcmp(output, find) == 0) {
+ add_output = false;
+ break;
+ }
+ }
+ }
+
+ if (add_output) {
+ list_add(outputs, strdup(output));
+ wlr_log(L_DEBUG, "Adding bar: '%s' to output '%s'",
+ config->current_bar->id, output);
+ }
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/commands/bar/pango_markup.c b/sway/commands/bar/pango_markup.c
new file mode 100644
index 00000000..480af724
--- /dev/null
+++ b/sway/commands/bar/pango_markup.c
@@ -0,0 +1,28 @@
+#include <string.h>
+#include <strings.h>
+#include "sway/commands.h"
+#include "log.h"
+
+struct cmd_results *bar_cmd_pango_markup(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "pango_markup", EXPECTED_EQUAL_TO, 1))) {
+ return error;
+ }
+ if (!config->current_bar) {
+ return cmd_results_new(CMD_FAILURE, "pango_markup", "No bar defined.");
+ }
+ if (strcasecmp("enabled", argv[0]) == 0) {
+ config->current_bar->pango_markup = true;
+ wlr_log(L_DEBUG, "Enabling pango markup for bar: %s",
+ config->current_bar->id);
+ } else if (strcasecmp("disabled", argv[0]) == 0) {
+ config->current_bar->pango_markup = false;
+ wlr_log(L_DEBUG, "Disabling pango markup for bar: %s",
+ config->current_bar->id);
+ } else {
+ error = cmd_results_new(CMD_INVALID, "pango_markup",
+ "Invalid value %s", argv[0]);
+ return error;
+ }
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/commands/bar/position.c b/sway/commands/bar/position.c
new file mode 100644
index 00000000..9c580483
--- /dev/null
+++ b/sway/commands/bar/position.c
@@ -0,0 +1,26 @@
+#define _POSIX_C_SOURCE 200809L
+#include <string.h>
+#include <strings.h>
+#include "sway/commands.h"
+#include "log.h"
+
+struct cmd_results *bar_cmd_position(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "position", EXPECTED_EQUAL_TO, 1))) {
+ return error;
+ }
+ if (!config->current_bar) {
+ return cmd_results_new(CMD_FAILURE, "position", "No bar defined.");
+ }
+ char *valid[] = { "top", "bottom", "left", "right" };
+ for (size_t i = 0; i < sizeof(valid) / sizeof(valid[0]); ++i) {
+ if (strcasecmp(valid[i], argv[0]) == 0) {
+ wlr_log(L_DEBUG, "Setting bar position '%s' for bar: %s",
+ argv[0], config->current_bar->id);
+ config->current_bar->position = strdup(argv[0]);
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+ }
+ }
+ return cmd_results_new(CMD_INVALID,
+ "position", "Invalid value %s", argv[0]);
+}
diff --git a/sway/commands/bar/secondary_button.c b/sway/commands/bar/secondary_button.c
new file mode 100644
index 00000000..449124cb
--- /dev/null
+++ b/sway/commands/bar/secondary_button.c
@@ -0,0 +1,8 @@
+#include <stdlib.h>
+#include "sway/commands.h"
+#include "log.h"
+
+struct cmd_results *bar_cmd_secondary_button(int argc, char **argv) {
+ // TODO TRAY
+ return cmd_results_new(CMD_INVALID, "secondary_button", "TODO TRAY");
+}
diff --git a/sway/commands/bar/separator_symbol.c b/sway/commands/bar/separator_symbol.c
new file mode 100644
index 00000000..1e08df6d
--- /dev/null
+++ b/sway/commands/bar/separator_symbol.c
@@ -0,0 +1,20 @@
+#define _XOPEN_SOURCE 500
+#include <string.h>
+#include "sway/commands.h"
+#include "log.h"
+
+struct cmd_results *bar_cmd_separator_symbol(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "separator_symbol", EXPECTED_EQUAL_TO, 1))) {
+ return error;
+ }
+ if (!config->current_bar) {
+ return cmd_results_new(CMD_FAILURE,
+ "separator_symbol", "No bar defined.");
+ }
+ free(config->current_bar->separator_symbol);
+ config->current_bar->separator_symbol = strdup(argv[0]);
+ wlr_log(L_DEBUG, "Settings separator_symbol '%s' for bar: %s",
+ config->current_bar->separator_symbol, config->current_bar->id);
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/commands/bar/status_command.c b/sway/commands/bar/status_command.c
new file mode 100644
index 00000000..5e199cde
--- /dev/null
+++ b/sway/commands/bar/status_command.c
@@ -0,0 +1,20 @@
+#include <string.h>
+#include "sway/commands.h"
+#include "log.h"
+#include "stringop.h"
+
+struct cmd_results *bar_cmd_status_command(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "status_command", EXPECTED_AT_LEAST, 1))) {
+ return error;
+ }
+ if (!config->current_bar) {
+ return cmd_results_new(CMD_FAILURE,
+ "status_command", "No bar defined.");
+ }
+ free(config->current_bar->status_command);
+ config->current_bar->status_command = join_args(argv, argc);
+ wlr_log(L_DEBUG, "Feeding bar with status command: %s",
+ config->current_bar->status_command);
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/commands/bar/strip_workspace_numbers.c b/sway/commands/bar/strip_workspace_numbers.c
new file mode 100644
index 00000000..4f24a356
--- /dev/null
+++ b/sway/commands/bar/strip_workspace_numbers.c
@@ -0,0 +1,29 @@
+#include <string.h>
+#include <strings.h>
+#include "sway/commands.h"
+#include "log.h"
+
+struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc,
+ "strip_workspace_numbers", EXPECTED_EQUAL_TO, 1))) {
+ return error;
+ }
+ if (!config->current_bar) {
+ return cmd_results_new(CMD_FAILURE,
+ "strip_workspace_numbers", "No bar defined.");
+ }
+ if (strcasecmp("yes", argv[0]) == 0) {
+ config->current_bar->strip_workspace_numbers = true;
+ wlr_log(L_DEBUG, "Stripping workspace numbers on bar: %s",
+ config->current_bar->id);
+ } else if (strcasecmp("no", argv[0]) == 0) {
+ config->current_bar->strip_workspace_numbers = false;
+ wlr_log(L_DEBUG, "Enabling workspace numbers on bar: %s",
+ config->current_bar->id);
+ } else {
+ return cmd_results_new(CMD_INVALID,
+ "strip_workspace_numbers", "Invalid value %s", argv[0]);
+ }
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/commands/bar/swaybar_command.c b/sway/commands/bar/swaybar_command.c
new file mode 100644
index 00000000..520cdd11
--- /dev/null
+++ b/sway/commands/bar/swaybar_command.c
@@ -0,0 +1,20 @@
+#include <string.h>
+#include "sway/commands.h"
+#include "log.h"
+#include "stringop.h"
+
+struct cmd_results *bar_cmd_swaybar_command(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "swaybar_command", EXPECTED_AT_LEAST, 1))) {
+ return error;
+ }
+ if (!config->current_bar) {
+ return cmd_results_new(CMD_FAILURE,
+ "swaybar_command", "No bar defined.");
+ }
+ free(config->current_bar->swaybar_command);
+ config->current_bar->swaybar_command = join_args(argv, argc);
+ wlr_log(L_DEBUG, "Using custom swaybar command: %s",
+ config->current_bar->swaybar_command);
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/commands/bar/tray_output.c b/sway/commands/bar/tray_output.c
new file mode 100644
index 00000000..6ab16731
--- /dev/null
+++ b/sway/commands/bar/tray_output.c
@@ -0,0 +1,8 @@
+#define _XOPEN_SOURCE 500
+#include <string.h>
+#include "sway/commands.h"
+
+struct cmd_results *bar_cmd_tray_output(int argc, char **argv) {
+ // TODO TRAY
+ return cmd_results_new(CMD_INVALID, "tray_output", "TODO TRAY");
+}
diff --git a/sway/commands/bar/tray_padding.c b/sway/commands/bar/tray_padding.c
new file mode 100644
index 00000000..91c56f19
--- /dev/null
+++ b/sway/commands/bar/tray_padding.c
@@ -0,0 +1,9 @@
+#include <stdlib.h>
+#include <strings.h>
+#include "sway/commands.h"
+#include "log.h"
+
+struct cmd_results *bar_cmd_tray_padding(int argc, char **argv) {
+ // TODO TRAY
+ return cmd_results_new(CMD_INVALID, "tray_padding", "TODO TRAY");
+}
diff --git a/sway/commands/bar/workspace_buttons.c b/sway/commands/bar/workspace_buttons.c
new file mode 100644
index 00000000..6edc3a0d
--- /dev/null
+++ b/sway/commands/bar/workspace_buttons.c
@@ -0,0 +1,28 @@
+#include <string.h>
+#include <strings.h>
+#include "sway/commands.h"
+#include "log.h"
+
+struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "workspace_buttons", EXPECTED_EQUAL_TO, 1))) {
+ return error;
+ }
+ if (!config->current_bar) {
+ return cmd_results_new(CMD_FAILURE,
+ "workspace_buttons", "No bar defined.");
+ }
+ if (strcasecmp("yes", argv[0]) == 0) {
+ config->current_bar->workspace_buttons = true;
+ wlr_log(L_DEBUG, "Enabling workspace buttons on bar: %s",
+ config->current_bar->id);
+ } else if (strcasecmp("no", argv[0]) == 0) {
+ config->current_bar->workspace_buttons = false;
+ wlr_log(L_DEBUG, "Disabling workspace buttons on bar: %s",
+ config->current_bar->id);
+ } else {
+ return cmd_results_new(CMD_INVALID, "workspace_buttons",
+ "Invalid value %s", argv[0]);
+ }
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/commands/bar/wrap_scroll.c b/sway/commands/bar/wrap_scroll.c
new file mode 100644
index 00000000..7386f82c
--- /dev/null
+++ b/sway/commands/bar/wrap_scroll.c
@@ -0,0 +1,27 @@
+#include <string.h>
+#include <strings.h>
+#include "sway/commands.h"
+#include "log.h"
+
+struct cmd_results *bar_cmd_wrap_scroll(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "wrap_scroll", EXPECTED_EQUAL_TO, 1))) {
+ return error;
+ }
+ if (!config->current_bar) {
+ return cmd_results_new(CMD_FAILURE, "wrap_scroll", "No bar defined.");
+ }
+ if (strcasecmp("yes", argv[0]) == 0) {
+ config->current_bar->wrap_scroll = true;
+ wlr_log(L_DEBUG, "Enabling wrap scroll on bar: %s",
+ config->current_bar->id);
+ } else if (strcasecmp("no", argv[0]) == 0) {
+ config->current_bar->wrap_scroll = false;
+ wlr_log(L_DEBUG, "Disabling wrap scroll on bar: %s",
+ config->current_bar->id);
+ } else {
+ return cmd_results_new(CMD_INVALID,
+ "wrap_scroll", "Invalid value %s", argv[0]);
+ }
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/commands/mode.c b/sway/commands/mode.c
new file mode 100644
index 00000000..c30a8bac
--- /dev/null
+++ b/sway/commands/mode.c
@@ -0,0 +1,59 @@
+#define _XOPEN_SOURCE 500
+#include <stdbool.h>
+#include <string.h>
+#include <strings.h>
+#include "sway/commands.h"
+#include "sway/config.h"
+#include "sway/ipc-server.h"
+#include "list.h"
+#include "log.h"
+
+struct cmd_results *cmd_mode(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "mode", EXPECTED_AT_LEAST, 1))) {
+ return error;
+ }
+
+ const char *mode_name = argv[0];
+ bool new_mode = (argc == 2 && strcmp(argv[1], "{") == 0);
+ if (new_mode && !config->reading) {
+ return cmd_results_new(CMD_FAILURE,
+ "mode", "Can only be used in config file.");
+ }
+ struct sway_mode *mode = NULL;
+ // Find mode
+ for (int i = 0; i < config->modes->length; ++i) {
+ struct sway_mode *test = config->modes->items[i];
+ if (strcasecmp(test->name, mode_name) == 0) {
+ mode = test;
+ break;
+ }
+ }
+ // Create mode if it doesn't exist
+ if (!mode && new_mode) {
+ mode = calloc(1, sizeof(struct sway_mode));
+ if (!mode) {
+ return cmd_results_new(CMD_FAILURE,
+ "mode", "Unable to allocate mode");
+ }
+ mode->name = strdup(mode_name);
+ mode->keysym_bindings = create_list();
+ mode->keycode_bindings = create_list();
+ list_add(config->modes, mode);
+ }
+ if (!mode) {
+ error = cmd_results_new(CMD_INVALID,
+ "mode", "Unknown mode `%s'", mode_name);
+ return error;
+ }
+ if ((config->reading && new_mode) || (!config->reading && !new_mode)) {
+ wlr_log(L_DEBUG, "Switching to mode `%s'",mode->name);
+ }
+ // Set current mode
+ config->current_mode = mode;
+ if (!new_mode) {
+ // trigger IPC mode event
+ ipc_event_mode(config->current_mode->name);
+ }
+ return cmd_results_new(new_mode ? CMD_BLOCK_MODE : CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/commands/reload.c b/sway/commands/reload.c
index 8cef789b..5bca6cde 100644
--- a/sway/commands/reload.c
+++ b/sway/commands/reload.c
@@ -11,8 +11,7 @@ struct cmd_results *cmd_reload(int argc, char **argv) {
return cmd_results_new(CMD_FAILURE, "reload", "Error(s) reloading config.");
}
- /* load_swaybars(); -- for when it's implemented */
-
+ load_swaybars();
arrange_windows(&root_container, -1, -1);
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
diff --git a/sway/commands/swaybg_command.c b/sway/commands/swaybg_command.c
new file mode 100644
index 00000000..770d4821
--- /dev/null
+++ b/sway/commands/swaybg_command.c
@@ -0,0 +1,20 @@
+#include <string.h>
+#include "sway/commands.h"
+#include "log.h"
+#include "stringop.h"
+
+struct cmd_results *cmd_swaybg_command(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "swaybg_command", EXPECTED_AT_LEAST, 1))) {
+ return error;
+ }
+
+ if (config->swaybg_command) {
+ free(config->swaybg_command);
+ }
+ config->swaybg_command = join_args(argv, argc);
+ wlr_log(L_DEBUG, "Using custom swaybg command: %s",
+ config->swaybg_command);
+
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}