diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-08-08 17:01:22 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-08-08 17:01:27 -0400 |
commit | 0427fddb5a919ae6b3a4205e057ae36133bfbc47 (patch) | |
tree | bf4e163872f63ad955148907f4ce03b63ed5384c /sway/layout.c | |
parent | Destroy outputs when appropriate (diff) | |
download | sway-0427fddb5a919ae6b3a4205e057ae36133bfbc47.tar.gz sway-0427fddb5a919ae6b3a4205e057ae36133bfbc47.tar.zst sway-0427fddb5a919ae6b3a4205e057ae36133bfbc47.zip |
Add logging and new windows into layout tree
Diffstat (limited to 'sway/layout.c')
-rw-r--r-- | sway/layout.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/sway/layout.c b/sway/layout.c index e61094e2..e95ee423 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -2,12 +2,18 @@ | |||
2 | #include <stdbool.h> | 2 | #include <stdbool.h> |
3 | #include <wlc/wlc.h> | 3 | #include <wlc/wlc.h> |
4 | #include "list.h" | 4 | #include "list.h" |
5 | #include "log.h" | ||
5 | #include "layout.h" | 6 | #include "layout.h" |
6 | 7 | ||
7 | list_t *outputs; | 8 | list_t *outputs; |
9 | wlc_handle focused_view; | ||
10 | |||
11 | void arrange_windows() { | ||
12 | } | ||
8 | 13 | ||
9 | void init_layout() { | 14 | void init_layout() { |
10 | outputs = create_list(); | 15 | outputs = create_list(); |
16 | focused_view = -1; | ||
11 | } | 17 | } |
12 | 18 | ||
13 | struct sway_container *get_container(wlc_handle output, int *index) { | 19 | struct sway_container *get_container(wlc_handle output, int *index) { |
@@ -21,6 +27,74 @@ struct sway_container *get_container(wlc_handle output, int *index) { | |||
21 | return NULL; | 27 | return NULL; |
22 | } | 28 | } |
23 | 29 | ||
30 | struct sway_container *get_container_for_view_recurse(wlc_handle handle, int *index, struct sway_container *parent) { | ||
31 | int j; | ||
32 | for (j = 0; j < parent->children->length; ++j) { | ||
33 | struct sway_container *child = parent->children->items[j]; | ||
34 | if (child->layout == LAYOUT_IS_VIEW) { | ||
35 | if (child->output == handle) { | ||
36 | *index = j; | ||
37 | return parent; | ||
38 | } | ||
39 | } else { | ||
40 | struct sway_container *res; | ||
41 | if ((res = get_container_for_view_recurse(handle, index, child))) { | ||
42 | return res; | ||
43 | } | ||
44 | } | ||
45 | } | ||
46 | return NULL; | ||
47 | } | ||
48 | |||
49 | struct sway_container *get_container_for_view(wlc_handle handle, int *index) { | ||
50 | int i; | ||
51 | for (i = 0; i < outputs->length; ++i) { | ||
52 | struct sway_container *c = outputs->items[i]; | ||
53 | struct sway_container *res; | ||
54 | if ((res = get_container_for_view_recurse(handle, index, c))) { | ||
55 | return res; | ||
56 | } | ||
57 | } | ||
58 | return NULL; | ||
59 | } | ||
60 | |||
61 | void add_view(wlc_handle view_handle) { | ||
62 | struct sway_container *container; | ||
63 | int _; | ||
64 | |||
65 | if (focused_view == -1) { // Add it to the output container | ||
66 | sway_log(L_DEBUG, "Adding initial view for output", view_handle); | ||
67 | wlc_handle output = wlc_get_focused_output(); | ||
68 | container = get_container(output, &_); | ||
69 | } else { | ||
70 | sway_log(L_DEBUG, "Adding view %d to output", view_handle); | ||
71 | // TODO | ||
72 | } | ||
73 | |||
74 | // Create "container" for this view | ||
75 | struct sway_container *view = malloc(sizeof(struct sway_container)); | ||
76 | view->layout = LAYOUT_IS_VIEW; | ||
77 | view->children = NULL; | ||
78 | view->output = view_handle; | ||
79 | list_add(container->children, view); | ||
80 | |||
81 | wlc_view_focus(view_handle); | ||
82 | |||
83 | arrange_windows(); | ||
84 | } | ||
85 | |||
86 | void destroy_view(wlc_handle view) { | ||
87 | sway_log(L_DEBUG, "Destroying view %d", view); | ||
88 | |||
89 | int index; | ||
90 | struct sway_container *container = get_container_for_view(view, &index); | ||
91 | list_del(container->children, index); | ||
92 | |||
93 | wlc_view_focus(get_topmost(wlc_view_get_output(view), 0)); | ||
94 | |||
95 | arrange_windows(); | ||
96 | } | ||
97 | |||
24 | void add_output(wlc_handle output) { | 98 | void add_output(wlc_handle output) { |
25 | struct sway_container *container = malloc(sizeof(struct sway_container)); | 99 | struct sway_container *container = malloc(sizeof(struct sway_container)); |
26 | // TODO: Get default layout from config | 100 | // TODO: Get default layout from config |