diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-11-19 17:04:28 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2017-11-19 17:04:28 -0500 |
commit | db4fb1c85c132e001fb1ae18f03f7585def1ae19 (patch) | |
tree | 91da84c9476e6ec34c65f3f8923961fd893fa721 | |
parent | Move everything to sway/old/ (diff) | |
download | sway-db4fb1c85c132e001fb1ae18f03f7585def1ae19.tar.gz sway-db4fb1c85c132e001fb1ae18f03f7585def1ae19.tar.zst sway-db4fb1c85c132e001fb1ae18f03f7585def1ae19.zip |
Add outputs to the tree
-rw-r--r-- | include/sway/container.h | 130 | ||||
-rw-r--r-- | include/sway/layout.h | 9 | ||||
-rw-r--r-- | include/sway/output.h | 2 | ||||
-rw-r--r-- | sway/CMakeLists.txt | 3 | ||||
-rw-r--r-- | sway/desktop/output.c | 4 | ||||
-rw-r--r-- | sway/main.c | 5 | ||||
-rw-r--r-- | sway/tree/container.c | 45 | ||||
-rw-r--r-- | sway/tree/layout.c | 35 |
8 files changed, 229 insertions, 4 deletions
diff --git a/include/sway/container.h b/include/sway/container.h new file mode 100644 index 00000000..35d1c146 --- /dev/null +++ b/include/sway/container.h | |||
@@ -0,0 +1,130 @@ | |||
1 | #ifndef _SWAY_CONTAINER_H | ||
2 | #define _SWAY_CONTAINER_H | ||
3 | #include <stdint.h> | ||
4 | #include <sys/types.h> | ||
5 | #include <wlr/types/wlr_box.h> | ||
6 | #include "list.h" | ||
7 | |||
8 | typedef struct sway_container swayc_t; | ||
9 | |||
10 | extern swayc_t root_container; | ||
11 | |||
12 | struct sway_view; | ||
13 | |||
14 | /** | ||
15 | * Different kinds of containers. | ||
16 | * | ||
17 | * This enum is in order. A container will never be inside of a container below | ||
18 | * it on this list. | ||
19 | */ | ||
20 | enum swayc_types { | ||
21 | C_ROOT, /**< The root container. Only one of these ever exists. */ | ||
22 | C_OUTPUT, /**< An output (aka monitor, head, etc). */ | ||
23 | C_WORKSPACE, /**< A workspace. */ | ||
24 | C_CONTAINER, /**< A manually created container. */ | ||
25 | C_VIEW, /**< A view (aka window). */ | ||
26 | |||
27 | C_TYPES, | ||
28 | }; | ||
29 | |||
30 | /** | ||
31 | * Different ways to arrange a container. | ||
32 | */ | ||
33 | enum swayc_layouts { | ||
34 | L_NONE, /**< Used for containers that have no layout (views, root) */ | ||
35 | L_HORIZ, | ||
36 | L_VERT, | ||
37 | L_STACKED, | ||
38 | L_TABBED, | ||
39 | L_FLOATING, /**< A psuedo-container, removed from the tree, to hold floating windows */ | ||
40 | |||
41 | /* Awesome/Monad style auto layouts */ | ||
42 | L_AUTO_LEFT, | ||
43 | L_AUTO_RIGHT, | ||
44 | L_AUTO_TOP, | ||
45 | L_AUTO_BOTTOM, | ||
46 | |||
47 | L_AUTO_FIRST = L_AUTO_LEFT, | ||
48 | L_AUTO_LAST = L_AUTO_BOTTOM, | ||
49 | |||
50 | // Keep last | ||
51 | L_LAYOUTS, | ||
52 | }; | ||
53 | |||
54 | enum swayc_border_types { | ||
55 | B_NONE, /**< No border */ | ||
56 | B_PIXEL, /**< 1px border */ | ||
57 | B_NORMAL, /**< Normal border with title bar */ | ||
58 | }; | ||
59 | |||
60 | struct sway_output; | ||
61 | struct sway_view; | ||
62 | struct wlr_output_layout; | ||
63 | |||
64 | /** | ||
65 | * Stores information about a container. | ||
66 | * | ||
67 | * The tree is made of these. Views are containers that cannot have children. | ||
68 | */ | ||
69 | struct sway_container { | ||
70 | union { | ||
71 | // TODO: Encapsulate state for other node types as well like C_CONTAINER | ||
72 | struct wlr_output_layout *output_layout; // C_ROOT | ||
73 | struct sway_output *sway_output; // C_OUTPUT | ||
74 | struct sway_view *sway_view; // C_VIEW | ||
75 | }; | ||
76 | |||
77 | /** | ||
78 | * A unique ID to identify this container. Primarily used in the | ||
79 | * get_tree JSON output. | ||
80 | */ | ||
81 | size_t id; | ||
82 | |||
83 | char *name; | ||
84 | |||
85 | enum swayc_types type; | ||
86 | enum swayc_layouts layout; | ||
87 | enum swayc_layouts prev_layout; | ||
88 | enum swayc_layouts workspace_layout; | ||
89 | |||
90 | /** | ||
91 | * The coordinates that this view appear at, relative to the output they | ||
92 | * are located on (output containers have absolute coordinates). | ||
93 | */ | ||
94 | double x, y; | ||
95 | |||
96 | /** | ||
97 | * Width and height of this container, without borders or gaps. | ||
98 | */ | ||
99 | double width, height; | ||
100 | |||
101 | list_t *children; | ||
102 | |||
103 | /** | ||
104 | * The parent of this container. NULL for the root container. | ||
105 | */ | ||
106 | struct sway_container *parent; | ||
107 | /** | ||
108 | * Which of this container's children has focus. | ||
109 | */ | ||
110 | struct sway_container *focused; | ||
111 | |||
112 | /** | ||
113 | * Number of master views in auto layouts. | ||
114 | */ | ||
115 | size_t nb_master; | ||
116 | |||
117 | /** | ||
118 | * Number of slave groups (e.g. columns) in auto layouts. | ||
119 | */ | ||
120 | size_t nb_slave_groups; | ||
121 | |||
122 | /** | ||
123 | * Marks applied to the container, list_t of char*. | ||
124 | */ | ||
125 | list_t *marks; | ||
126 | }; | ||
127 | |||
128 | swayc_t *new_output(struct sway_output *sway_output); | ||
129 | |||
130 | #endif | ||
diff --git a/include/sway/layout.h b/include/sway/layout.h new file mode 100644 index 00000000..7e7a9c35 --- /dev/null +++ b/include/sway/layout.h | |||
@@ -0,0 +1,9 @@ | |||
1 | #ifndef _SWAY_LAYOUT_H | ||
2 | #define _SWAY_LAYOUT_H | ||
3 | |||
4 | struct sway_container; | ||
5 | |||
6 | void init_layout(void); | ||
7 | void add_child(struct sway_container *parent, struct sway_container *child); | ||
8 | |||
9 | #endif | ||
diff --git a/include/sway/output.h b/include/sway/output.h index ffc6708d..e2f81bcb 100644 --- a/include/sway/output.h +++ b/include/sway/output.h | |||
@@ -5,9 +5,11 @@ | |||
5 | #include <wlr/types/wlr_output.h> | 5 | #include <wlr/types/wlr_output.h> |
6 | 6 | ||
7 | struct sway_server; | 7 | struct sway_server; |
8 | struct sway_container; | ||
8 | 9 | ||
9 | struct sway_output { | 10 | struct sway_output { |
10 | struct wlr_output *wlr_output; | 11 | struct wlr_output *wlr_output; |
12 | struct sway_container *swayc; | ||
11 | struct sway_server *server; | 13 | struct sway_server *server; |
12 | struct timespec last_frame; | 14 | struct timespec last_frame; |
13 | struct wl_listener frame; | 15 | struct wl_listener frame; |
diff --git a/sway/CMakeLists.txt b/sway/CMakeLists.txt index 73531a84..9a92466c 100644 --- a/sway/CMakeLists.txt +++ b/sway/CMakeLists.txt | |||
@@ -14,6 +14,9 @@ add_executable(sway | |||
14 | desktop/output.c | 14 | desktop/output.c |
15 | desktop/xdg_shell_v6.c | 15 | desktop/xdg_shell_v6.c |
16 | 16 | ||
17 | tree/layout.c | ||
18 | tree/container.c | ||
19 | |||
17 | base64.c | 20 | base64.c |
18 | main.c | 21 | main.c |
19 | server.c | 22 | server.c |
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 6ddcac3b..27579c1b 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c | |||
@@ -5,6 +5,7 @@ | |||
5 | #include <wlr/types/wlr_output.h> | 5 | #include <wlr/types/wlr_output.h> |
6 | #include <wlr/render.h> | 6 | #include <wlr/render.h> |
7 | #include "log.h" | 7 | #include "log.h" |
8 | #include "sway/container.h" | ||
8 | #include "sway/output.h" | 9 | #include "sway/output.h" |
9 | #include "sway/server.h" | 10 | #include "sway/server.h" |
10 | 11 | ||
@@ -34,11 +35,10 @@ void output_add_notify(struct wl_listener *listener, void *data) { | |||
34 | struct sway_output *output = calloc(1, sizeof(struct sway_output)); | 35 | struct sway_output *output = calloc(1, sizeof(struct sway_output)); |
35 | output->wlr_output = wlr_output; | 36 | output->wlr_output = wlr_output; |
36 | output->server = server; | 37 | output->server = server; |
38 | output->swayc = new_output(output); | ||
37 | 39 | ||
38 | output->frame.notify = output_frame_notify; | 40 | output->frame.notify = output_frame_notify; |
39 | wl_signal_add(&wlr_output->events.frame, &output->frame); | 41 | wl_signal_add(&wlr_output->events.frame, &output->frame); |
40 | |||
41 | // TODO: Add to tree | ||
42 | } | 42 | } |
43 | 43 | ||
44 | void output_remove_notify(struct wl_listener *listener, void *data) { | 44 | void output_remove_notify(struct wl_listener *listener, void *data) { |
diff --git a/sway/main.c b/sway/main.c index 5710a099..42262b05 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -16,10 +16,11 @@ | |||
16 | #include <sys/prctl.h> | 16 | #include <sys/prctl.h> |
17 | #endif | 17 | #endif |
18 | #include "sway/server.h" | 18 | #include "sway/server.h" |
19 | #include "sway/layout.h" | ||
19 | #include "ipc-client.h" | 20 | #include "ipc-client.h" |
21 | #include "log.h" | ||
20 | #include "readline.h" | 22 | #include "readline.h" |
21 | #include "stringop.h" | 23 | #include "stringop.h" |
22 | #include "log.h" | ||
23 | #include "util.h" | 24 | #include "util.h" |
24 | 25 | ||
25 | static bool terminate_request = false; | 26 | static bool terminate_request = false; |
@@ -436,7 +437,7 @@ int main(int argc, char **argv) { | |||
436 | return 1; | 437 | return 1; |
437 | } | 438 | } |
438 | 439 | ||
439 | //init_layout(); | 440 | init_layout(); |
440 | //ipc_init(); | 441 | //ipc_init(); |
441 | 442 | ||
442 | //if (validate) { | 443 | //if (validate) { |
diff --git a/sway/tree/container.c b/sway/tree/container.c new file mode 100644 index 00000000..54bcf478 --- /dev/null +++ b/sway/tree/container.c | |||
@@ -0,0 +1,45 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
2 | #include <stdint.h> | ||
3 | #include <stdlib.h> | ||
4 | #include <string.h> | ||
5 | #include "sway/container.h" | ||
6 | #include "sway/layout.h" | ||
7 | #include "sway/output.h" | ||
8 | |||
9 | static swayc_t *new_swayc(enum swayc_types type) { | ||
10 | // next id starts at 1 because 0 is assigned to root_container in layout.c | ||
11 | static size_t next_id = 1; | ||
12 | swayc_t *c = calloc(1, sizeof(swayc_t)); | ||
13 | if (!c) { | ||
14 | return NULL; | ||
15 | } | ||
16 | c->id = next_id++; | ||
17 | c->layout = L_NONE; | ||
18 | c->workspace_layout = L_NONE; | ||
19 | c->type = type; | ||
20 | c->nb_master = 1; | ||
21 | c->nb_slave_groups = 1; | ||
22 | if (type != C_VIEW) { | ||
23 | c->children = create_list(); | ||
24 | } | ||
25 | return c; | ||
26 | } | ||
27 | |||
28 | swayc_t *new_output(struct sway_output *sway_output) { | ||
29 | struct wlr_box size; | ||
30 | wlr_output_effective_resolution(sway_output->wlr_output, | ||
31 | &size.width, &size.height); | ||
32 | const char *name = sway_output->wlr_output->name; | ||
33 | |||
34 | swayc_t *output = new_swayc(C_OUTPUT); | ||
35 | output->sway_output = sway_output; | ||
36 | output->name = name ? strdup(name) : NULL; | ||
37 | output->width = size.width; | ||
38 | output->height = size.width; | ||
39 | |||
40 | add_child(&root_container, output); | ||
41 | |||
42 | // TODO: Create workspace | ||
43 | |||
44 | return output; | ||
45 | } | ||
diff --git a/sway/tree/layout.c b/sway/tree/layout.c new file mode 100644 index 00000000..06200bbf --- /dev/null +++ b/sway/tree/layout.c | |||
@@ -0,0 +1,35 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
2 | #include <stdbool.h> | ||
3 | #include <string.h> | ||
4 | #include <wlr/types/wlr_output_layout.h> | ||
5 | #include "sway/container.h" | ||
6 | #include "list.h" | ||
7 | #include "log.h" | ||
8 | |||
9 | swayc_t root_container; | ||
10 | |||
11 | void init_layout(void) { | ||
12 | root_container.id = 0; // normally assigned in new_swayc() | ||
13 | root_container.type = C_ROOT; | ||
14 | root_container.layout = L_NONE; | ||
15 | root_container.name = strdup("root"); | ||
16 | root_container.children = create_list(); | ||
17 | root_container.output_layout = wlr_output_layout_create(); | ||
18 | } | ||
19 | |||
20 | void add_child(swayc_t *parent, swayc_t *child) { | ||
21 | sway_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", | ||
22 | child, child->type, child->width, child->height, | ||
23 | parent, parent->type, parent->width, parent->height); | ||
24 | list_add(parent->children, child); | ||
25 | child->parent = parent; | ||
26 | // set focus for this container | ||
27 | if (!parent->focused) { | ||
28 | parent->focused = child; | ||
29 | } | ||
30 | /* TODO WLR | ||
31 | if (parent->type == C_WORKSPACE && child->type == C_VIEW && (parent->workspace_layout == L_TABBED || parent->workspace_layout == L_STACKED)) { | ||
32 | child = new_container(child, parent->workspace_layout); | ||
33 | } | ||
34 | */ | ||
35 | } | ||