diff options
-rw-r--r-- | sway/commands.c | 2 | ||||
-rw-r--r-- | sway/commands.h | 2 | ||||
-rw-r--r-- | sway/config.c | 5 | ||||
-rw-r--r-- | sway/layout.c | 5 | ||||
-rw-r--r-- | sway/layout.h | 3 | ||||
-rw-r--r-- | sway/list.c | 2 | ||||
-rw-r--r-- | sway/list.h | 2 | ||||
-rw-r--r-- | sway/workspace.c | 28 | ||||
-rw-r--r-- | sway/workspace.h | 2 |
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 | |||
360 | return res; | 360 | return res; |
361 | } | 361 | } |
362 | 362 | ||
363 | int handle_command(struct sway_config *config, char *exec) { | 363 | bool handle_command(struct sway_config *config, char *exec) { |
364 | sway_log(L_INFO, "Handling command '%s'", exec); | 364 | sway_log(L_INFO, "Handling command '%s'", exec); |
365 | char *ptr, *cmd; | 365 | char *ptr, *cmd; |
366 | bool exec_success; | 366 | 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 { | |||
8 | bool (*handle)(struct sway_config *config, int argc, char **argv); | 8 | bool (*handle)(struct sway_config *config, int argc, char **argv); |
9 | }; | 9 | }; |
10 | 10 | ||
11 | int handle_command(struct sway_config *config, char *command); | 11 | bool handle_command(struct sway_config *config, char *command); |
12 | 12 | ||
13 | #endif | 13 | #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 @@ | |||
9 | #include "config.h" | 9 | #include "config.h" |
10 | 10 | ||
11 | bool load_config() { | 11 | bool load_config() { |
12 | sway_log(L_INFO, "Loading config"); | ||
12 | // TODO: Allow use of more config file locations | 13 | // TODO: Allow use of more config file locations |
13 | const char *name = "/.sway/config"; | 14 | const char *name = "/.sway/config"; |
14 | const char *home = getenv("HOME"); | 15 | const char *home = getenv("HOME"); |
@@ -65,7 +66,7 @@ struct sway_config *read_config(FILE *file, bool is_active) { | |||
65 | goto _continue; | 66 | goto _continue; |
66 | } | 67 | } |
67 | 68 | ||
68 | if (!temp_depth && handle_command(config, line) != 0) { | 69 | if (!temp_depth && handle_command(config, line) != true) { |
69 | success = false; | 70 | success = false; |
70 | } | 71 | } |
71 | 72 | ||
@@ -76,7 +77,7 @@ _continue: | |||
76 | free(line); | 77 | free(line); |
77 | } | 78 | } |
78 | 79 | ||
79 | if (!success) { | 80 | if (success == false) { |
80 | exit(1); | 81 | exit(1); |
81 | } | 82 | } |
82 | 83 | ||
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) { | |||
119 | } | 119 | } |
120 | } | 120 | } |
121 | 121 | ||
122 | void init_layout() { | 122 | void init_layout(void) { |
123 | root_container.type = C_ROOT; | 123 | root_container.type = C_ROOT; |
124 | root_container.layout = L_NONE; | 124 | root_container.layout = L_NONE; |
125 | root_container.children = create_list(); | 125 | root_container.children = create_list(); |
@@ -128,6 +128,9 @@ void init_layout() { | |||
128 | 128 | ||
129 | void free_swayc(swayc_t *container) { | 129 | void free_swayc(swayc_t *container) { |
130 | // NOTE: Does not handle moving children into a different container | 130 | // NOTE: Does not handle moving children into a different container |
131 | if (container->parent) { | ||
132 | remove_container_from_parent(container->parent, container); | ||
133 | } | ||
131 | list_free(container->children); | 134 | list_free(container->children); |
132 | if (container->name) { | 135 | if (container->name) { |
133 | free(container->name); | 136 | 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; | |||
45 | 45 | ||
46 | extern swayc_t root_container; | 46 | extern swayc_t root_container; |
47 | 47 | ||
48 | void init_layout(); | 48 | void init_layout(void); |
49 | void add_child(swayc_t *parent, swayc_t *child); | 49 | void add_child(swayc_t *parent, swayc_t *child); |
50 | void add_output(wlc_handle output); | 50 | void add_output(wlc_handle output); |
51 | void destroy_output(wlc_handle output); | 51 | void destroy_output(wlc_handle output); |
@@ -58,6 +58,7 @@ swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *da | |||
58 | swayc_t *get_focused_container(swayc_t *parent); | 58 | swayc_t *get_focused_container(swayc_t *parent); |
59 | int remove_container_from_parent(swayc_t *parent, swayc_t *container); | 59 | int remove_container_from_parent(swayc_t *parent, swayc_t *container); |
60 | swayc_t *create_container(swayc_t *parent, wlc_handle handle); | 60 | swayc_t *create_container(swayc_t *parent, wlc_handle handle); |
61 | void free_swayc(swayc_t *container); | ||
61 | swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent); | 62 | swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent); |
62 | 63 | ||
63 | #endif | 64 | #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 @@ | |||
3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
4 | #include <string.h> | 4 | #include <string.h> |
5 | 5 | ||
6 | list_t *create_list() { | 6 | list_t *create_list(void) { |
7 | list_t *list = malloc(sizeof(list_t)); | 7 | list_t *list = malloc(sizeof(list_t)); |
8 | list->capacity = 10; | 8 | list->capacity = 10; |
9 | list->length = 0; | 9 | 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 { | |||
7 | void **items; | 7 | void **items; |
8 | } list_t; | 8 | } list_t; |
9 | 9 | ||
10 | list_t *create_list(); | 10 | list_t *create_list(void); |
11 | void list_free(list_t *list); | 11 | void list_free(list_t *list); |
12 | void list_add(list_t *list, void *item); | 12 | void list_add(list_t *list, void *item); |
13 | void list_insert(list_t *list, int index, void *item); | 13 | 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 @@ | |||
9 | 9 | ||
10 | swayc_t *active_workspace = NULL; | 10 | swayc_t *active_workspace = NULL; |
11 | 11 | ||
12 | char *workspace_next_name() { | 12 | char *workspace_next_name(void) { |
13 | return "1"; | 13 | //TODO change this i guess. seems pretty bad |
14 | char *name = malloc(sizeof("1")); | ||
15 | return strcpy(name, "1"); | ||
14 | } | 16 | } |
15 | 17 | ||
16 | swayc_t *workspace_create(const char* name) { | 18 | swayc_t *workspace_create(const char* name) { |
@@ -35,6 +37,17 @@ bool workspace_by_name(swayc_t *view, void *data) { | |||
35 | (strcasecmp(view->name, (char *) data) == 0); | 37 | (strcasecmp(view->name, (char *) data) == 0); |
36 | } | 38 | } |
37 | 39 | ||
40 | bool workspace_destroy(swayc_t *workspace) { | ||
41 | //Dont destroy if there are children | ||
42 | if(workspace->children->length) { | ||
43 | return false; | ||
44 | } | ||
45 | sway_log(L_DEBUG, "Workspace: Destroying workspace '%s'", workspace->name); | ||
46 | free_swayc(workspace); | ||
47 | return true; | ||
48 | |||
49 | } | ||
50 | |||
38 | void set_mask(swayc_t *view, void *data) { | 51 | void set_mask(swayc_t *view, void *data) { |
39 | uint32_t *p = data; | 52 | uint32_t *p = data; |
40 | 53 | ||
@@ -49,12 +62,15 @@ swayc_t *workspace_find_by_name(const char* name) { | |||
49 | } | 62 | } |
50 | 63 | ||
51 | void workspace_switch(swayc_t *workspace) { | 64 | void workspace_switch(swayc_t *workspace) { |
52 | if(active_workspace) { | 65 | if (active_workspace) { |
53 | sway_log(L_DEBUG, "workspace: changing from %s to %s", active_workspace->name, workspace->name); | 66 | sway_log(L_DEBUG, "workspace: changing from '%s' to '%s'", active_workspace->name, workspace->name); |
54 | 67 | if(strcmp(active_workspace->name, workspace->name) == 0) { | |
68 | return; //Dont do anything if they are the same workspace | ||
69 | } | ||
55 | uint32_t mask = 1; | 70 | uint32_t mask = 1; |
56 | // set all c_views in the old workspace to the invisible mask | 71 | // set all c_views in the old workspace to the invisible mask |
57 | container_map(active_workspace, set_mask, &mask); | 72 | container_map(active_workspace, set_mask, &mask); |
73 | |||
58 | // and c_views in the new workspace to the visible mask | 74 | // and c_views in the new workspace to the visible mask |
59 | mask = 2; | 75 | mask = 2; |
60 | container_map(workspace, set_mask, &mask); | 76 | container_map(workspace, set_mask, &mask); |
@@ -62,7 +78,7 @@ void workspace_switch(swayc_t *workspace) { | |||
62 | wlc_output_set_mask(wlc_get_focused_output(), 2); | 78 | wlc_output_set_mask(wlc_get_focused_output(), 2); |
63 | unfocus_all(active_workspace); | 79 | unfocus_all(active_workspace); |
64 | focus_view(workspace); | 80 | focus_view(workspace); |
81 | workspace_destroy(active_workspace); | ||
65 | } | 82 | } |
66 | |||
67 | active_workspace = workspace; | 83 | active_workspace = workspace; |
68 | } | 84 | } |
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 @@ | |||
5 | #include "list.h" | 5 | #include "list.h" |
6 | #include "layout.h" | 6 | #include "layout.h" |
7 | 7 | ||
8 | char *workspace_next_name(); | 8 | char *workspace_next_name(void); |
9 | swayc_t *workspace_create(const char*); | 9 | swayc_t *workspace_create(const char*); |
10 | swayc_t *workspace_find_by_name(const char*); | 10 | swayc_t *workspace_find_by_name(const char*); |
11 | void workspace_switch(swayc_t*); | 11 | void workspace_switch(swayc_t*); |