Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workspace and varsub fixes. #17

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion sway/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,20 @@ 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
if (!config->init_workspace) {
if (strcmp("workspace", argv[1]) == 0) {
config->init_workspace = malloc(strlen(argv[2]) + 1);
strcpy(config->init_workspace, argv[2]);
}
}

list_t *split = split_string(argv[0], "+");
int i;
for (i = 0; i < split->length; ++i) {
Expand Down Expand Up @@ -381,6 +388,12 @@ bool handle_command(struct sway_config *config, char *exec) {
int argc;
char **argv = split_directive(exec + strlen(handler->command), &argc);
int i;

//Perform var subs on all parts of the command
for (i = 0; i < argc; ++i) {
argv[i] = do_var_replacement(config, argv[i]);
}

exec_success = handler->handle(config, argc, argv);
for (i = 0; i < argc; ++i) {
free(argv[i]);
Expand Down
12 changes: 11 additions & 1 deletion sway/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -82,7 +85,14 @@ struct sway_config *read_config(FILE *file, bool is_active) {
}

if (is_active) {
config->reloading = true;
config->reloading = false;
}

if (!config->init_workspace) {
sway_log(L_INFO, "No workspace names set, defaulting to 1");
char* default_init_workspace = "1";
config->init_workspace = malloc(strlen(default_init_workspace) + 1);
strcpy(config->init_workspace, default_init_workspace);
}

return config;
Expand Down
1 change: 1 addition & 0 deletions sway/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion sway/layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions sway/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -38,15 +37,16 @@ int main(int argc, char **argv) {

};

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);
if (!load_config()) {
sway_abort("Unable to load config");
}


wlc_run();
return 0;
Expand Down
16 changes: 6 additions & 10 deletions sway/workspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion sway/workspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*);
Expand Down