diff options
author | 2015-08-06 08:40:16 -0400 | |
---|---|---|
committer | 2015-08-06 08:40:16 -0400 | |
commit | c102f184994638155248991e50a7a8ae5c620c91 (patch) | |
tree | 2ee8ed6f0bf7e9a7249ff0a49fe83d8999fd01a1 | |
parent | Start to build out window management functions (diff) | |
download | sway-c102f184994638155248991e50a7a8ae5c620c91.tar.gz sway-c102f184994638155248991e50a7a8ae5c620c91.tar.zst sway-c102f184994638155248991e50a7a8ae5c620c91.zip |
Add layout containers for new outputs
-rw-r--r-- | sway/handlers.c | 1 | ||||
-rw-r--r-- | sway/layout.c | 38 | ||||
-rw-r--r-- | sway/layout.h | 16 | ||||
-rw-r--r-- | sway/main.c | 2 |
4 files changed, 55 insertions, 2 deletions
diff --git a/sway/handlers.c b/sway/handlers.c index d6d30b71..9bf3f964 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -5,6 +5,7 @@ | |||
5 | #include "handlers.h" | 5 | #include "handlers.h" |
6 | 6 | ||
7 | bool handle_output_created(wlc_handle output) { | 7 | bool handle_output_created(wlc_handle output) { |
8 | add_output(output); | ||
8 | return true; | 9 | return true; |
9 | } | 10 | } |
10 | 11 | ||
diff --git a/sway/layout.c b/sway/layout.c index aeb8167e..e61094e2 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -1,8 +1,46 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <stdbool.h> | 2 | #include <stdbool.h> |
3 | #include <wlc/wlc.h> | 3 | #include <wlc/wlc.h> |
4 | #include "list.h" | ||
4 | #include "layout.h" | 5 | #include "layout.h" |
5 | 6 | ||
7 | list_t *outputs; | ||
8 | |||
9 | void init_layout() { | ||
10 | outputs = create_list(); | ||
11 | } | ||
12 | |||
13 | struct sway_container *get_container(wlc_handle output, int *index) { | ||
14 | int i; | ||
15 | for (i = 0; i < outputs->length; ++i) { | ||
16 | struct sway_container *c = outputs->items[i]; | ||
17 | if (c->output == output) { | ||
18 | return c; | ||
19 | } | ||
20 | } | ||
21 | return NULL; | ||
22 | } | ||
23 | |||
24 | void add_output(wlc_handle output) { | ||
25 | struct sway_container *container = malloc(sizeof(struct sway_container)); | ||
26 | // TODO: Get default layout from config | ||
27 | container->output = output; | ||
28 | container->children = create_list(); | ||
29 | container->layout = LAYOUT_TILE_HORIZ; | ||
30 | list_add(outputs, container); | ||
31 | } | ||
32 | |||
33 | void destroy_output(wlc_handle output) { | ||
34 | int index; | ||
35 | struct sway_container *c = get_container(output, &index); | ||
36 | // TODO: Move all windows in this output somewhere else? | ||
37 | // I don't think this will ever be called unless we destroy the output ourselves | ||
38 | if (!c) { | ||
39 | return; | ||
40 | } | ||
41 | list_del(outputs, index); | ||
42 | } | ||
43 | |||
6 | wlc_handle get_topmost(wlc_handle output, size_t offset) { | 44 | wlc_handle get_topmost(wlc_handle output, size_t offset) { |
7 | size_t memb; | 45 | size_t memb; |
8 | const wlc_handle *views = wlc_output_get_views(output, &memb); | 46 | const wlc_handle *views = wlc_output_get_views(output, &memb); |
diff --git a/sway/layout.h b/sway/layout.h index a6fb35a7..24d214d8 100644 --- a/sway/layout.h +++ b/sway/layout.h | |||
@@ -4,11 +4,23 @@ | |||
4 | #include <wlc/wlc.h> | 4 | #include <wlc/wlc.h> |
5 | #include "list.h" | 5 | #include "list.h" |
6 | 6 | ||
7 | typedef enum { | ||
8 | LAYOUT_TILE_HORIZ, | ||
9 | LAYOUT_TILE_VERT, | ||
10 | LAYOUT_TABBED, | ||
11 | LAYOUT_STACKED | ||
12 | } container_layout_t; | ||
13 | |||
7 | struct sway_container { | 14 | struct sway_container { |
8 | wlc_handle output; // May be NULL | 15 | wlc_handle output; |
9 | list_t children; | 16 | list_t *children; |
17 | container_layout_t layout; | ||
10 | }; | 18 | }; |
11 | 19 | ||
20 | extern list_t *outputs; | ||
21 | |||
22 | void init_layout(); | ||
23 | void add_output(wlc_handle output); | ||
12 | wlc_handle get_topmost(wlc_handle output, size_t offset); | 24 | wlc_handle get_topmost(wlc_handle output, size_t offset); |
13 | 25 | ||
14 | #endif | 26 | #endif |
diff --git a/sway/main.c b/sway/main.c index 303d2776..3a6c3f9d 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -2,6 +2,7 @@ | |||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <stdbool.h> | 3 | #include <stdbool.h> |
4 | #include <wlc/wlc.h> | 4 | #include <wlc/wlc.h> |
5 | #include "layout.h" | ||
5 | #include "config.h" | 6 | #include "config.h" |
6 | #include "handlers.h" | 7 | #include "handlers.h" |
7 | 8 | ||
@@ -27,6 +28,7 @@ void load_config() { | |||
27 | 28 | ||
28 | int main(int argc, char **argv) { | 29 | int main(int argc, char **argv) { |
29 | load_config(); | 30 | load_config(); |
31 | init_layout(); | ||
30 | 32 | ||
31 | static struct wlc_interface interface = { | 33 | static struct wlc_interface interface = { |
32 | .output = { | 34 | .output = { |