From 0356ab3ebaa57df9a71be3902a2273bdcc34af43 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Mon, 10 Aug 2015 19:50:22 -0500 Subject: [PATCH] Minor fixes Fixed workspace_next_name to use the first workspace name it can find in the config Minor fixes --- sway/commands.c | 14 +++++++++++++- sway/config.c | 10 +++++++++- sway/config.h | 1 + sway/layout.c | 2 +- sway/main.c | 14 +++++++------- sway/workspace.c | 16 ++++++---------- sway/workspace.h | 2 +- 7 files changed, 38 insertions(+), 21 deletions(-) diff --git a/sway/commands.c b/sway/commands.c index be9984e32..13a2d0b68 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -34,13 +34,22 @@ bool cmd_bindsym(struct sway_config *config, int argc, char **argv) { sway_log(L_ERROR, "Invalid set command (expected 2 arguments, got %d)", argc); return false; } - argv[0] = do_var_replacement(config, argv[0]); struct sway_binding *binding = malloc(sizeof(struct sway_binding)); binding->keys = create_list(); binding->modifiers = 0; binding->command = join_args(argv + 1, argc - 1); + //Set the first workspace name found to the init_workspace + list_t *cargs = split_string(binding->command, " "); + if (!config->init_workspace) { + if (strcmp("workspace", cargs->items[0]) == 0) { + argv[0] = do_var_replacement(config, argv[0]); + config->init_workspace = do_var_replacement(config, cargs->items[1]); + } + } + list_free(cargs); + list_t *split = split_string(argv[0], "+"); int i; for (i = 0; i < split->length; ++i) { @@ -381,6 +390,9 @@ bool handle_command(struct sway_config *config, char *exec) { int argc; char **argv = split_directive(exec + strlen(handler->command), &argc); int i; + + argv[0] = do_var_replacement(config, argv[0]); + exec_success = handler->handle(config, argc, argv); for (i = 0; i < argc; ++i) { free(argv[i]); diff --git a/sway/config.c b/sway/config.c index a1689f36b..8b4221de9 100644 --- a/sway/config.c +++ b/sway/config.c @@ -8,6 +8,8 @@ #include "commands.h" #include "config.h" +struct sway_config *config; + bool load_config() { sway_log(L_INFO, "Loading config"); // TODO: Allow use of more config file locations @@ -34,6 +36,7 @@ void config_defaults(struct sway_config *config) { config->current_mode = malloc(sizeof(struct sway_mode)); config->current_mode->name = NULL; config->current_mode->bindings = create_list(); + config->init_workspace = NULL; list_add(config->modes, config->current_mode); // Flags config->focus_follows_mouse = true; @@ -82,7 +85,12 @@ _continue: } if (is_active) { - config->reloading = true; + config->reloading = false; + } + + if (!config->init_workspace) { + sway_log(L_INFO, "No workspace names set, defaulting to 1"); + config->init_workspace = "1"; } return config; diff --git a/sway/config.h b/sway/config.h index 62b65723e..979a9ec8b 100644 --- a/sway/config.h +++ b/sway/config.h @@ -25,6 +25,7 @@ struct sway_config { list_t *symbols; list_t *modes; struct sway_mode *current_mode; + char *init_workspace; // Flags bool focus_follows_mouse; diff --git a/sway/layout.c b/sway/layout.c index ccf29f341..6a35df103 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -341,7 +341,7 @@ void add_output(wlc_handle output) { swayc_t *workspace = create_container(container, -1); workspace->type = C_WORKSPACE; - workspace->name = workspace_next_name(); + workspace->name = workspace_init_name(); workspace->width = size->w; // TODO: gaps workspace->height = size->h; workspace->layout = L_HORIZ; // TODO: Get default layout from config diff --git a/sway/main.c b/sway/main.c index f84451de0..2ae200d21 100644 --- a/sway/main.c +++ b/sway/main.c @@ -7,7 +7,6 @@ #include "log.h" #include "handlers.h" -struct sway_config *config; int main(int argc, char **argv) { init_log(L_DEBUG); // TODO: Control this with command line arg @@ -38,16 +37,17 @@ int main(int argc, char **argv) { }; - setenv("WLC_DIM", "0", 0); - if (!wlc_init(&interface, argc, argv)) { - return 1; - } - - setenv("DISPLAY", ":1", 1); if (!load_config()) { sway_abort("Unable to load config"); } + setenv("WLC_DIM", "0", 0); + if (!wlc_init(&interface, argc, argv)) { + return 1; + } + setenv("DISPLAY", ":1", 1); + + wlc_run(); return 0; } diff --git a/sway/workspace.c b/sway/workspace.c index 53675c030..7830d67e2 100644 --- a/sway/workspace.c +++ b/sway/workspace.c @@ -6,21 +6,17 @@ #include "list.h" #include "log.h" #include "container.h" +#include "config.h" swayc_t *active_workspace = NULL; int ws_num = 1; -char *workspace_next_name(void) { - int l = 1; - if (ws_num >= 10) { - l = 2; - } else if (ws_num >= 100) { - l = 3; - } - char *name = malloc(l + 1); - sprintf(name, "%d", ws_num++); - return name; +char *workspace_init_name(void) { + //It should be fine to just return the init name, since + //any non bound workspace can't be used outside of the very + //first workspace created + return config->init_workspace; } swayc_t *workspace_create(const char* name) { diff --git a/sway/workspace.h b/sway/workspace.h index 19f0d4c12..eebe94ee2 100644 --- a/sway/workspace.h +++ b/sway/workspace.h @@ -5,7 +5,7 @@ #include "list.h" #include "layout.h" -char *workspace_next_name(void); +char *workspace_init_name(void); swayc_t *workspace_create(const char*); swayc_t *workspace_find_by_name(const char*); void workspace_switch(swayc_t*);