diff options
Diffstat (limited to 'include/container.h')
-rw-r--r-- | include/container.h | 139 |
1 files changed, 94 insertions, 45 deletions
diff --git a/include/container.h b/include/container.h index a9b95229..b164af95 100644 --- a/include/container.h +++ b/include/container.h | |||
@@ -2,29 +2,25 @@ | |||
2 | #define _SWAY_CONTAINER_H | 2 | #define _SWAY_CONTAINER_H |
3 | #include <wlc/wlc.h> | 3 | #include <wlc/wlc.h> |
4 | typedef struct sway_container swayc_t; | 4 | typedef struct sway_container swayc_t; |
5 | |||
6 | #include "layout.h" | 5 | #include "layout.h" |
7 | 6 | ||
8 | enum swayc_types{ | 7 | enum swayc_types { |
9 | C_ROOT, | 8 | C_ROOT = 1 << 0, |
10 | C_OUTPUT, | 9 | C_OUTPUT = 1 << 1, |
11 | C_WORKSPACE, | 10 | C_WORKSPACE = 1 << 2, |
12 | C_CONTAINER, | 11 | C_CONTAINER = 1 << 3, |
13 | C_VIEW, | 12 | C_VIEW = 1 << 4, |
14 | // Keep last | 13 | C_TYPES = 5, |
15 | C_TYPES, | ||
16 | }; | 14 | }; |
17 | 15 | ||
18 | 16 | enum swayc_layouts { | |
19 | enum swayc_layouts{ | 17 | L_NONE = 1 << 0, |
20 | L_NONE, | 18 | L_HORIZ = 1 << 1, |
21 | L_HORIZ, | 19 | L_VERT = 1 << 2, |
22 | L_VERT, | 20 | L_STACKED = 1 << 3, |
23 | L_STACKED, | 21 | L_TABBED = 1 << 4, |
24 | L_TABBED, | 22 | L_FLOATING = 1 << 5, |
25 | L_FLOATING, | 23 | L_LAYOUTS = 6, |
26 | // Keep last | ||
27 | L_LAYOUTS, | ||
28 | }; | 24 | }; |
29 | 25 | ||
30 | struct sway_container { | 26 | struct sway_container { |
@@ -35,13 +31,16 @@ struct sway_container { | |||
35 | 31 | ||
36 | // Not including borders or margins | 32 | // Not including borders or margins |
37 | double width, height; | 33 | double width, height; |
34 | double x, y; | ||
38 | 35 | ||
39 | // Used for setting floating geometry | 36 | // Used for setting floating geometry |
40 | int desired_width, desired_height; | 37 | int desired_width, desired_height; |
41 | 38 | ||
42 | double x, y; | 39 | enum visibility_mask { |
40 | INVISIBLE = false, | ||
41 | VISIBLE = true, | ||
42 | } visible; | ||
43 | 43 | ||
44 | bool visible; | ||
45 | bool is_floating; | 44 | bool is_floating; |
46 | bool is_focused; | 45 | bool is_focused; |
47 | 46 | ||
@@ -56,70 +55,120 @@ struct sway_container { | |||
56 | struct sway_container *focused; | 55 | struct sway_container *focused; |
57 | }; | 56 | }; |
58 | 57 | ||
59 | enum visibility_mask { | 58 | // swayc Creation |
60 | VISIBLE = 1 | ||
61 | }; | ||
62 | |||
63 | // Container Creation | ||
64 | 59 | ||
60 | /* Creates and returns new, or an already created output. | ||
61 | * If it creates a new output, it also creates a workspace using | ||
62 | * `new_workspace(outputname, NULL);` */ | ||
65 | swayc_t *new_output(wlc_handle handle); | 63 | swayc_t *new_output(wlc_handle handle); |
64 | |||
65 | /* Creates workspace with given name, under given output. | ||
66 | * If workspace with that name already exists, returns that workspace | ||
67 | * If name is NULL, it will choose a name automatically. | ||
68 | * If output is NULL, it will choose an output automatically. */ | ||
66 | swayc_t *new_workspace(swayc_t *output, const char *name); | 69 | swayc_t *new_workspace(swayc_t *output, const char *name); |
70 | |||
67 | // Creates container Around child (parent child) -> (parent (container child)) | 71 | // Creates container Around child (parent child) -> (parent (container child)) |
68 | swayc_t *new_container(swayc_t *child, enum swayc_layouts layout); | 72 | swayc_t *new_container(swayc_t *child, enum swayc_layouts layout); |
73 | |||
69 | // Creates view as a sibling of current focused container, or as child of a workspace | 74 | // Creates view as a sibling of current focused container, or as child of a workspace |
70 | swayc_t *new_view(swayc_t *sibling, wlc_handle handle); | 75 | swayc_t *new_view(swayc_t *sibling, wlc_handle handle); |
76 | |||
71 | // Creates view as a new floating view which is in the active workspace | 77 | // Creates view as a new floating view which is in the active workspace |
72 | swayc_t *new_floating_view(wlc_handle handle); | 78 | swayc_t *new_floating_view(wlc_handle handle); |
73 | 79 | ||
74 | // Container Destroying | 80 | // Container Destroying |
75 | 81 | // Destroys output and moves workspaces to another output | |
76 | swayc_t *destroy_output(swayc_t *output); | 82 | swayc_t *destroy_output(swayc_t *output); |
83 | |||
77 | // Destroys workspace if empty and returns parent pointer, else returns NULL | 84 | // Destroys workspace if empty and returns parent pointer, else returns NULL |
78 | swayc_t *destroy_workspace(swayc_t *workspace); | 85 | swayc_t *destroy_workspace(swayc_t *workspace); |
86 | |||
79 | // Destroyes container and all parent container if they are empty, returns | 87 | // Destroyes container and all parent container if they are empty, returns |
80 | // topmost non-empty parent. returns NULL otherwise | 88 | // topmost non-empty parent. returns NULL otherwise |
81 | swayc_t *destroy_container(swayc_t *container); | 89 | swayc_t *destroy_container(swayc_t *container); |
90 | |||
82 | // Destroys view and all empty parent containers. return topmost non-empty | 91 | // Destroys view and all empty parent containers. return topmost non-empty |
83 | // parent | 92 | // parent |
84 | swayc_t *destroy_view(swayc_t *view); | 93 | swayc_t *destroy_view(swayc_t *view); |
85 | 94 | ||
86 | // Container Lookup | 95 | // Container Mapping and testing functions |
96 | typedef bool swayc_test_func(swayc_t *view, void *data); | ||
97 | typedef void swayc_map_func(swayc_t *view, void *data); | ||
98 | |||
99 | // Returns the first swayc that matches test() | ||
100 | swayc_t *swayc_by_test_r(swayc_t *root, swayc_test_func test, void *data); | ||
101 | swayc_t *swayc_by_test(swayc_test_func test, void *data); | ||
102 | |||
103 | // Calls func for all children. | ||
104 | void swayc_map_r(swayc_t *root, swayc_map_func func, void *data); | ||
105 | void swayc_map(swayc_map_func func, void *data); | ||
106 | |||
107 | |||
108 | // Call func on container if test passes | ||
109 | void swayc_map_by_test_r(swayc_t *root, | ||
110 | swayc_map_func func, swayc_test_func test, | ||
111 | void *funcdata, void *testdata); | ||
112 | void swayc_map_by_test( | ||
113 | swayc_map_func func, swayc_test_func test, | ||
114 | void *funcdata, void *testdata); | ||
115 | |||
116 | // Map functions | ||
117 | swayc_map_func set_gaps; | ||
118 | swayc_map_func add_gaps; | ||
119 | |||
120 | // Test functions | ||
121 | // generic swayc tests | ||
122 | swayc_test_func test_name; | ||
123 | swayc_test_func test_name_regex; | ||
124 | swayc_test_func test_layout; | ||
125 | swayc_test_func test_type; | ||
126 | swayc_test_func test_visibility; | ||
127 | swayc_test_func test_handle; | ||
128 | |||
129 | // C_VIEW tests | ||
130 | // See wlc_view_*_bit enums | ||
131 | swayc_test_func test_view_state; | ||
132 | swayc_test_func test_view_type; | ||
133 | swayc_test_func test_view_title; | ||
134 | swayc_test_func test_view_class; | ||
135 | swayc_test_func test_view_appid; | ||
136 | swayc_test_func test_view_title_regex; | ||
137 | swayc_test_func test_view_class_regex; | ||
138 | swayc_test_func test_view_appid_regex; | ||
139 | |||
140 | // functions for test_*_regex | ||
141 | void *compile_regex(const char *regex); | ||
142 | void free_regex(void *); | ||
143 | |||
144 | // these take a NULL terminated array of test_list struct. | ||
145 | struct test_list { swayc_test_func *test; void *data ; }; | ||
146 | swayc_test_func test_and; | ||
147 | swayc_test_func test_or; | ||
87 | 148 | ||
88 | swayc_t *swayc_by_test(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data); | ||
89 | swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types); | 149 | swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types); |
90 | swayc_t *swayc_parent_by_layout(swayc_t *container, enum swayc_layouts); | 150 | swayc_t *swayc_parent_by_layout(swayc_t *container, enum swayc_layouts); |
91 | // Follow focused until type/layout | 151 | // Follow focused until type/layout |
92 | swayc_t *swayc_focus_by_type(swayc_t *container, enum swayc_types); | 152 | swayc_t *swayc_focus_by_type(swayc_t *container, enum swayc_types); |
93 | swayc_t *swayc_focus_by_layout(swayc_t *container, enum swayc_layouts); | 153 | swayc_t *swayc_focus_by_layout(swayc_t *container, enum swayc_layouts); |
94 | 154 | ||
95 | |||
96 | swayc_t *swayc_by_handle(wlc_handle handle); | ||
97 | swayc_t *swayc_by_name(const char *name); | ||
98 | swayc_t *swayc_active_output(void); | 155 | swayc_t *swayc_active_output(void); |
99 | swayc_t *swayc_active_workspace(void); | 156 | swayc_t *swayc_active_workspace(void); |
100 | swayc_t *swayc_active_workspace_for(swayc_t *view); | 157 | swayc_t *swayc_active_workspace_for(swayc_t *view); |
101 | 158 | ||
102 | // Container information | 159 | // Container information |
103 | 160 | // if `parent` is the parent of `child` | |
104 | bool swayc_is_fullscreen(swayc_t *view); | ||
105 | bool swayc_is_active(swayc_t *view); | ||
106 | // Is `parent` the parent of `child` | ||
107 | bool swayc_is_parent_of(swayc_t *parent, swayc_t *child); | 161 | bool swayc_is_parent_of(swayc_t *parent, swayc_t *child); |
108 | // Is `child` a child of `parent` | 162 | // If `child` is a child of `parent` |
109 | bool swayc_is_child_of(swayc_t *child, swayc_t *parent); | 163 | bool swayc_is_child_of(swayc_t *child, swayc_t *parent); |
110 | // Return gap of specified container | 164 | // Return gap of specified container |
111 | int swayc_gap(swayc_t *container); | 165 | int swayc_gap(swayc_t *container); |
112 | 166 | ||
113 | // Mapping functions | 167 | bool swayc_is_fullscreen(swayc_t *view); |
114 | 168 | bool swayc_is_active(swayc_t *view); | |
115 | void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *); | ||
116 | 169 | ||
117 | // Mappings | ||
118 | void set_view_visibility(swayc_t *view, void *data); | ||
119 | // Set or add to gaps | ||
120 | void set_gaps(swayc_t *view, void *amount); | ||
121 | void add_gaps(swayc_t *view, void *amount); | ||
122 | 170 | ||
171 | // Specialized mapping functions | ||
123 | void update_visibility(swayc_t *container); | 172 | void update_visibility(swayc_t *container); |
124 | 173 | ||
125 | #endif | 174 | #endif |