aboutsummaryrefslogtreecommitdiff
path: root/sway/commands.c
diff options
context:
space:
mode:
authorLuminarys <kizunanohikari@gmail.com>2015-08-10 13:53:43 -0500
committerLuminarys <kizunanohikari@gmail.com>2015-08-10 13:53:43 -0500
commitc0ee2a64065f3a9953e977e517a466361444c144 (patch)
tree505618d3711dcd48c5e7941abd7dfe1ae070752f /sway/commands.c
parent9c3a04b996649c0c578410e02181d8808b13c646 (diff)
Added in reload and exec_always handling
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c51
1 files changed, 50 insertions, 1 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 64130fdc..df394901 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -39,7 +39,7 @@ int cmd_bindsym(struct sway_config *config, int argc, char **argv) {
binding->keys = create_list();
binding->modifiers = 0;
binding->command = join_args(argv + 1, argc - 1);
-
+
list_t *split = split_string(argv[0], "+");
int i;
for (i = 0; i < split->length; ++i) {
@@ -78,6 +78,28 @@ int cmd_exec(struct sway_config *config, int argc, char **argv) {
sway_log(L_ERROR, "Invalid exec command (expected at least 1 argument, got %d)", argc);
return 1;
}
+
+ if (config->reloading) {
+ sway_log(L_DEBUG, "Ignoring exec %s due to reload", join_args(argv, argc));
+ return 0;
+ }
+
+ if (fork() == 0) {
+ char *args = join_args(argv, argc);
+ sway_log(L_DEBUG, "Executing %s", args);
+ execl("/bin/sh", "sh", "-c", args, (char *)NULL);
+ free(args);
+ exit(0);
+ }
+ return 0;
+}
+
+int cmd_exec_always(struct sway_config *config, int argc, char **argv) {
+ if (argc < 1) {
+ sway_log(L_ERROR, "Invalid exec_always command (expected at least 1 argument, got %d)", argc);
+ return 1;
+ }
+
if (fork() == 0) {
char *args = join_args(argv, argc);
sway_log(L_DEBUG, "Executing %s", args);
@@ -152,6 +174,31 @@ int cmd_layout(struct sway_config *config, int argc, char **argv) {
return 0;
}
+int cmd_reload(struct sway_config *config, int argc, char **argv) {
+ if (argc != 0) {
+ sway_log(L_ERROR, "Invalid reload command (expected 1 arguments, got %d)", argc);
+ return 1;
+ }
+
+ // TODO: Allow use of more config file locations
+ const char *name = "/.sway/config";
+ const char *home = getenv("HOME");
+ char *temp = malloc(strlen(home) + strlen(name) + 1);
+ strcpy(temp, home);
+ strcat(temp, name);
+ FILE *f = fopen(temp, "r");
+ if (!f) {
+ fprintf(stderr, "Unable to open %s for reading", temp);
+ free(temp);
+ exit(1);
+ }
+ free(temp);
+ config = read_config(f, true);
+ fclose(f);
+
+ return 0;
+}
+
int cmd_set(struct sway_config *config, int argc, char **argv) {
if (argc != 2) {
sway_log(L_ERROR, "Invalid set command (expected 2 arguments, got %d)", argc);
@@ -232,12 +279,14 @@ int cmd_fullscreen(struct sway_config *config, int argc, char **argv) {
struct cmd_handler handlers[] = {
{ "bindsym", cmd_bindsym },
{ "exec", cmd_exec },
+ { "exec_always", cmd_exec_always },
{ "exit", cmd_exit },
{ "focus", cmd_focus },
{ "focus_follows_mouse", cmd_focus_follows_mouse },
{ "fullscreen", cmd_fullscreen },
{ "layout", cmd_layout },
{ "log_colors", cmd_log_colors },
+ { "reload", cmd_reload },
{ "set", cmd_set },
{ "splith", cmd_splith },
{ "splitv", cmd_splitv }