Minor fixes

Fixed workspace_next_name to use the first workspace name it can find in the config

Minor fixes
This commit is contained in:
Luminarys 2015-08-10 19:50:22 -05:00
parent 803a4739b6
commit 0356ab3eba
7 changed files with 38 additions and 21 deletions

View File

@ -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]);

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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;
}

View File

@ -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) {

View File

@ -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*);