aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2018-03-29 21:19:57 -0400
committerLibravatar Tony Crisci <tony@dubstepdish.com>2018-03-29 21:22:39 -0400
commit4c394a0e9ee04b46ed349f7b3ddf67c53719b3b6 (patch)
tree0833690f34940296a9cbd6b3dd4ba682d0713370
parent80col (diff)
downloadsway-4c394a0e9ee04b46ed349f7b3ddf67c53719b3b6.tar.gz
sway-4c394a0e9ee04b46ed349f7b3ddf67c53719b3b6.tar.zst
sway-4c394a0e9ee04b46ed349f7b3ddf67c53719b3b6.zip
address feedback
-rw-r--r--include/sway/tree/container.h14
-rw-r--r--sway/criteria.c2
-rw-r--r--sway/input/cursor.c4
-rw-r--r--sway/input/seat.c2
-rw-r--r--sway/tree/container.c39
5 files changed, 16 insertions, 45 deletions
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
index 3548afc1..92ff2b67 100644
--- a/include/sway/tree/container.h
+++ b/include/sway/tree/container.h
@@ -70,10 +70,10 @@ struct sway_container {
70 enum sway_container_layout prev_layout; 70 enum sway_container_layout prev_layout;
71 enum sway_container_layout workspace_layout; 71 enum sway_container_layout workspace_layout;
72 72
73 // TODO convert to layout coordinates 73 // TODO convert to layout coordinates
74 double x, y; 74 double x, y;
75 75
76 // does not include borders or gaps. 76 // does not include borders or gaps.
77 double width, height; 77 double width, height;
78 78
79 list_t *children; 79 list_t *children;
@@ -122,22 +122,16 @@ struct sway_container *container_parent(struct sway_container *container,
122 enum sway_container_type type); 122 enum sway_container_type type);
123 123
124/** 124/**
125 * Run a function for each child.
126 */
127void sway_container_for_each(struct sway_container *container,
128 void (*f)(struct sway_container *view, void *data), void *data);
129
130/**
131 * Find a container at the given coordinates. 125 * Find a container at the given coordinates.
132 */ 126 */
133struct sway_container *sway_container_at(struct sway_container *parent, 127struct sway_container *container_at(struct sway_container *parent,
134 double lx, double ly, struct wlr_surface **surface, 128 double lx, double ly, struct wlr_surface **surface,
135 double *sx, double *sy); 129 double *sx, double *sy);
136 130
137/** 131/**
138 * Apply the function for each child of the container breadth first. 132 * Apply the function for each child of the container breadth first.
139 */ 133 */
140void sway_container_for_each_bfs(struct sway_container *container, 134void container_for_each(struct sway_container *container,
141 void (*f)(struct sway_container *container, void *data), void *data); 135 void (*f)(struct sway_container *container, void *data), void *data);
142 136
143#endif 137#endif
diff --git a/sway/criteria.c b/sway/criteria.c
index 70f8e305..46961a60 100644
--- a/sway/criteria.c
+++ b/sway/criteria.c
@@ -435,7 +435,7 @@ list_t *container_for_crit_tokens(list_t *tokens) {
435 struct list_tokens list_tokens = 435 struct list_tokens list_tokens =
436 (struct list_tokens){create_list(), tokens}; 436 (struct list_tokens){create_list(), tokens};
437 437
438 sway_container_for_each(&root_container, 438 container_for_each(&root_container,
439 (void (*)(struct sway_container *, void *))container_match_add, 439 (void (*)(struct sway_container *, void *))container_match_add,
440 &list_tokens); 440 &list_tokens);
441 441
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index a0e4b9be..d57ac3e3 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -50,7 +50,7 @@ static void cursor_send_pointer_motion(struct sway_cursor *cursor,
50 } 50 }
51 51
52 struct sway_container *swayc = 52 struct sway_container *swayc =
53 sway_container_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy); 53 container_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy);
54 if (swayc) { 54 if (swayc) {
55 wlr_seat_pointer_notify_enter(seat, surface, sx, sy); 55 wlr_seat_pointer_notify_enter(seat, surface, sx, sy);
56 wlr_seat_pointer_notify_motion(seat, time, sx, sy); 56 wlr_seat_pointer_notify_motion(seat, time, sx, sy);
@@ -88,7 +88,7 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
88 struct wlr_surface *surface = NULL; 88 struct wlr_surface *surface = NULL;
89 double sx, sy; 89 double sx, sy;
90 struct sway_container *swayc = 90 struct sway_container *swayc =
91 sway_container_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy); 91 container_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy);
92 92
93 sway_seat_set_focus(cursor->seat, swayc); 93 sway_seat_set_focus(cursor->seat, swayc);
94 } 94 }
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 8e2189de..be0e15de 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -130,7 +130,7 @@ struct sway_seat *sway_seat_create(struct sway_input_manager *input,
130 // init the focus stack 130 // init the focus stack
131 wl_list_init(&seat->focus_stack); 131 wl_list_init(&seat->focus_stack);
132 132
133 sway_container_for_each_bfs(&root_container, collect_focus_iter, seat); 133 container_for_each(&root_container, collect_focus_iter, seat);
134 134
135 wl_signal_add(&root_container.sway_root->events.new_container, 135 wl_signal_add(&root_container.sway_root->events.new_container,
136 &seat->new_container); 136 &seat->new_container);
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 1f537025..dade8f54 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -38,7 +38,7 @@ static void notify_new_container(struct sway_container *container) {
38 ipc_event_window(container, "new"); 38 ipc_event_window(container, "new");
39} 39}
40 40
41static struct sway_container *new_swayc(enum sway_container_type type) { 41static struct sway_container *container_create(enum sway_container_type type) {
42 // next id starts at 1 because 0 is assigned to root_container in layout.c 42 // next id starts at 1 because 0 is assigned to root_container in layout.c
43 static size_t next_id = 1; 43 static size_t next_id = 1;
44 struct sway_container *c = calloc(1, sizeof(struct sway_container)); 44 struct sway_container *c = calloc(1, sizeof(struct sway_container));
@@ -122,7 +122,7 @@ struct sway_container *container_output_create(
122 return NULL; 122 return NULL;
123 } 123 }
124 124
125 struct sway_container *output = new_swayc(C_OUTPUT); 125 struct sway_container *output = container_create(C_OUTPUT);
126 output->sway_output = sway_output; 126 output->sway_output = sway_output;
127 output->name = strdup(name); 127 output->name = strdup(name);
128 if (output->name == NULL) { 128 if (output->name == NULL) {
@@ -151,14 +151,14 @@ struct sway_container *container_output_create(
151 return output; 151 return output;
152} 152}
153 153
154struct sway_container *container_workspace_create(struct sway_container 154struct sway_container *container_workspace_create(
155 *output, const char *name) { 155 struct sway_container *output, const char *name) {
156 if (!sway_assert(output, 156 if (!sway_assert(output,
157 "container_workspace_create called with null output")) { 157 "container_workspace_create called with null output")) {
158 return NULL; 158 return NULL;
159 } 159 }
160 wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name); 160 wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name);
161 struct sway_container *workspace = new_swayc(C_WORKSPACE); 161 struct sway_container *workspace = container_create(C_WORKSPACE);
162 162
163 workspace->x = output->x; 163 workspace->x = output->x;
164 workspace->y = output->y; 164 workspace->y = output->y;
@@ -182,7 +182,7 @@ struct sway_container *container_view_create(struct sway_container *sibling,
182 return NULL; 182 return NULL;
183 } 183 }
184 const char *title = view_get_title(sway_view); 184 const char *title = view_get_title(sway_view);
185 struct sway_container *swayc = new_swayc(C_VIEW); 185 struct sway_container *swayc = container_create(C_VIEW);
186 wlr_log(L_DEBUG, "Adding new view %p:%s to container %p %d %s", 186 wlr_log(L_DEBUG, "Adding new view %p:%s to container %p %d %s",
187 swayc, title, sibling, sibling ? sibling->type : 0, sibling->name); 187 swayc, title, sibling, sibling ? sibling->type : 0, sibling->name);
188 // Setup values 188 // Setup values
@@ -314,30 +314,7 @@ struct sway_container *container_parent(struct sway_container *container,
314 return container; 314 return container;
315} 315}
316 316
317void sway_container_for_each(struct sway_container *container, 317struct sway_container *container_at(struct sway_container *parent,
318 void (*f)(struct sway_container *view, void *data), void *data) {
319 if (container) {
320 int i;
321 if (container->children) {
322 for (i = 0; i < container->children->length; ++i) {
323 struct sway_container *child = container->children->items[i];
324 sway_container_for_each(child, f, data);
325 }
326 }
327 // TODO
328 /*
329 if (container->floating) {
330 for (i = 0; i < container->floating->length; ++i) {
331 struct sway_container *child = container->floating->items[i];
332 container_map(child, f, data);
333 }
334 }
335 */
336 f(container, data);
337 }
338}
339
340struct sway_container *sway_container_at(struct sway_container *parent,
341 double lx, double ly, 318 double lx, double ly,
342 struct wlr_surface **surface, double *sx, double *sy) { 319 struct wlr_surface **surface, double *sx, double *sy) {
343 list_t *queue = get_bfs_queue(); 320 list_t *queue = get_bfs_queue();
@@ -423,7 +400,7 @@ struct sway_container *sway_container_at(struct sway_container *parent,
423 return NULL; 400 return NULL;
424} 401}
425 402
426void sway_container_for_each_bfs(struct sway_container *con, 403void container_for_each(struct sway_container *con,
427 void (*f)(struct sway_container *con, void *data), void *data) { 404 void (*f)(struct sway_container *con, void *data), void *data) {
428 list_t *queue = get_bfs_queue(); 405 list_t *queue = get_bfs_queue();
429 if (!queue) { 406 if (!queue) {