aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
Diffstat (limited to 'sway')
-rw-r--r--sway/commands.c2
-rw-r--r--sway/commands.h2
-rw-r--r--sway/config.c5
-rw-r--r--sway/layout.c5
-rw-r--r--sway/layout.h3
-rw-r--r--sway/list.c2
-rw-r--r--sway/list.h2
-rw-r--r--sway/workspace.c28
-rw-r--r--sway/workspace.h2
9 files changed, 36 insertions, 15 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 41141f87..be9984e3 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -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;
diff --git a/sway/commands.h b/sway/commands.h
index 19fd3f33..c2046e13 100644
--- a/sway/commands.h
+++ b/sway/commands.h
@@ -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
diff --git a/sway/config.c b/sway/config.c
index 3c7badec..a1689f36 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -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");
@@ -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;
}
@@ -76,7 +77,7 @@ _continue:
free(line);
}
- if (!success) {
+ if (success == false) {
exit(1);
}
diff --git a/sway/layout.c b/sway/layout.c
index bec1ec49..37f47673 100644
--- a/sway/layout.c
+++ b/sway/layout.c
@@ -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();
@@ -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);
diff --git a/sway/layout.h b/sway/layout.h
index 8cafe0d2..b4769e08 100644
--- a/sway/layout.h
+++ b/sway/layout.h
@@ -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);
@@ -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
diff --git a/sway/list.c b/sway/list.c
index 52943efe..68455f89 100644
--- a/sway/list.c
+++ b/sway/list.c
@@ -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;
diff --git a/sway/list.h b/sway/list.h
index e035ec4c..29b988aa 100644
--- a/sway/list.h
+++ b/sway/list.h
@@ -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);
diff --git a/sway/workspace.c b/sway/workspace.c
index d88e2786..8ff89132 100644
--- a/sway/workspace.c
+++ b/sway/workspace.c
@@ -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) {
@@ -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;
@@ -49,12 +62,15 @@ 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 (active_workspace) {
+ sway_log(L_DEBUG, "workspace: changing from '%s' to '%s'", active_workspace->name, workspace->name);
+ if(strcmp(active_workspace->name, workspace->name) == 0) {
+ return; //Dont do anything if they are the same workspace
+ }
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);
@@ -62,7 +78,7 @@ void workspace_switch(swayc_t *workspace) {
wlc_output_set_mask(wlc_get_focused_output(), 2);
unfocus_all(active_workspace);
focus_view(workspace);
+ workspace_destroy(active_workspace);
}
-
active_workspace = workspace;
}
diff --git a/sway/workspace.h b/sway/workspace.h
index bc7eed55..19f0d4c1 100644
--- a/sway/workspace.h
+++ b/sway/workspace.h
@@ -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*);