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

destroys empty workspace + minor fixes #15

Merged
merged 3 commits into from
Aug 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion sway/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ struct cmd_handler *find_handler(struct cmd_handler handlers[], int l, char *lin
return res;
}

int handle_command(struct sway_config *config, char *exec) {
bool handle_command(struct sway_config *config, char *exec) {
sway_log(L_INFO, "Handling command '%s'", exec);
char *ptr, *cmd;
bool exec_success;
Expand Down
2 changes: 1 addition & 1 deletion sway/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ struct cmd_handler {
bool (*handle)(struct sway_config *config, int argc, char **argv);
};

int handle_command(struct sway_config *config, char *command);
bool handle_command(struct sway_config *config, char *command);

#endif
5 changes: 3 additions & 2 deletions sway/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "config.h"

bool load_config() {
sway_log(L_INFO, "Loading config");
// TODO: Allow use of more config file locations
const char *name = "/.sway/config";
const char *home = getenv("HOME");
Expand Down Expand Up @@ -65,7 +66,7 @@ struct sway_config *read_config(FILE *file, bool is_active) {
goto _continue;
}

if (!temp_depth && handle_command(config, line) != 0) {
if (!temp_depth && handle_command(config, line) != true) {
success = false;
}

Expand All @@ -76,7 +77,7 @@ struct sway_config *read_config(FILE *file, bool is_active) {
free(line);
}

if (!success) {
if (success == false) {
exit(1);
}

Expand Down
5 changes: 4 additions & 1 deletion sway/layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void arrange_windows(swayc_t *container, int width, int height) {
}
}

void init_layout() {
void init_layout(void) {
root_container.type = C_ROOT;
root_container.layout = L_NONE;
root_container.children = create_list();
Expand All @@ -128,6 +128,9 @@ void init_layout() {

void free_swayc(swayc_t *container) {
// NOTE: Does not handle moving children into a different container
if (container->parent) {
remove_container_from_parent(container->parent, container);
}
list_free(container->children);
if (container->name) {
free(container->name);
Expand Down
3 changes: 2 additions & 1 deletion sway/layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ typedef struct sway_container swayc_t;

extern swayc_t root_container;

void init_layout();
void init_layout(void);
void add_child(swayc_t *parent, swayc_t *child);
void add_output(wlc_handle output);
void destroy_output(wlc_handle output);
Expand All @@ -58,6 +58,7 @@ swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *da
swayc_t *get_focused_container(swayc_t *parent);
int remove_container_from_parent(swayc_t *parent, swayc_t *container);
swayc_t *create_container(swayc_t *parent, wlc_handle handle);
void free_swayc(swayc_t *container);
swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent);

#endif
2 changes: 1 addition & 1 deletion sway/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <stdlib.h>
#include <string.h>

list_t *create_list() {
list_t *create_list(void) {
list_t *list = malloc(sizeof(list_t));
list->capacity = 10;
list->length = 0;
Expand Down
2 changes: 1 addition & 1 deletion sway/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ typedef struct {
void **items;
} list_t;

list_t *create_list();
list_t *create_list(void);
void list_free(list_t *list);
void list_add(list_t *list, void *item);
void list_insert(list_t *list, int index, void *item);
Expand Down
25 changes: 19 additions & 6 deletions sway/workspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

swayc_t *active_workspace = NULL;

char *workspace_next_name() {
return "1";
char *workspace_next_name(void) {
//TODO change this i guess. seems pretty bad
char *name = malloc(sizeof("1"));
return strcpy(name, "1");
}

swayc_t *workspace_create(const char* name) {
Expand All @@ -35,6 +37,17 @@ bool workspace_by_name(swayc_t *view, void *data) {
(strcasecmp(view->name, (char *) data) == 0);
}

bool workspace_destroy(swayc_t *workspace) {
//Dont destroy if there are children
if (workspace->children->length) {
return false;
}
sway_log(L_DEBUG, "Workspace: Destroying workspace '%s'", workspace->name);
free_swayc(workspace);
return true;

}

void set_mask(swayc_t *view, void *data) {
uint32_t *p = data;

Expand All @@ -49,20 +62,20 @@ swayc_t *workspace_find_by_name(const char* name) {
}

void workspace_switch(swayc_t *workspace) {
if(active_workspace) {
sway_log(L_DEBUG, "workspace: changing from %s to %s", active_workspace->name, workspace->name);

if (workspace != active_workspace && active_workspace) {
sway_log(L_DEBUG, "workspace: changing from '%s' to '%s'", active_workspace->name, workspace->name);
uint32_t mask = 1;
// set all c_views in the old workspace to the invisible mask
container_map(active_workspace, set_mask, &mask);

// and c_views in the new workspace to the visible mask
mask = 2;
container_map(workspace, set_mask, &mask);

wlc_output_set_mask(wlc_get_focused_output(), 2);
unfocus_all(active_workspace);
focus_view(workspace);
workspace_destroy(active_workspace);
}

active_workspace = workspace;
}
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();
char *workspace_next_name(void);
swayc_t *workspace_create(const char*);
swayc_t *workspace_find_by_name(const char*);
void workspace_switch(swayc_t*);
Expand Down