From 874f009866abaf8ca43ed4cd88a69d22a3fbfc5a Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 29 Mar 2018 12:15:31 -0400 Subject: move tree includes to their own directory --- include/sway/tree/layout.h | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 include/sway/tree/layout.h (limited to 'include/sway/tree/layout.h') diff --git a/include/sway/tree/layout.h b/include/sway/tree/layout.h new file mode 100644 index 00000000..39b7fb24 --- /dev/null +++ b/include/sway/tree/layout.h @@ -0,0 +1,51 @@ +#ifndef _SWAY_LAYOUT_H +#define _SWAY_LAYOUT_H + +#include +#include "sway/tree/container.h" + +enum movement_direction { + MOVE_LEFT, + MOVE_RIGHT, + MOVE_UP, + MOVE_DOWN, + MOVE_PARENT, + MOVE_CHILD, + MOVE_NEXT, + MOVE_PREV, + MOVE_FIRST +}; + +struct sway_container; + +struct sway_root { + struct wlr_output_layout *output_layout; + + struct wl_listener output_layout_change; + + struct wl_list unmanaged_views; // sway_view::unmanaged_view_link + + struct { + struct wl_signal new_container; + } events; +}; + +void init_layout(void); + +void add_child(struct sway_container *parent, struct sway_container *child); + +swayc_t *add_sibling(swayc_t *parent, swayc_t *child); + +struct sway_container *remove_child(struct sway_container *child); + +enum swayc_layouts default_layout(struct sway_container *output); + +void sort_workspaces(struct sway_container *output); + +void arrange_windows(struct sway_container *container, + double width, double height); + +swayc_t *get_swayc_in_direction(swayc_t *container, + struct sway_seat *seat, enum movement_direction dir); + +#endif -- cgit v1.2.3 From 83d09cf5945ba10a703dc5cc977a6d2814f0fd64 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 29 Mar 2018 14:31:10 -0400 Subject: remove swayc_t typedef --- include/sway/config.h | 5 +++-- include/sway/criteria.h | 4 ++-- include/sway/input/input-manager.h | 4 ++-- include/sway/input/seat.h | 11 +++++----- include/sway/ipc-json.h | 4 ++-- include/sway/ipc-server.h | 2 +- include/sway/tree/container.h | 45 ++++++++++++++++++++------------------ include/sway/tree/layout.h | 7 +++--- include/sway/tree/workspace.h | 14 ++++++------ sway/input/input-manager.c | 4 ++-- 10 files changed, 53 insertions(+), 47 deletions(-) (limited to 'include/sway/tree/layout.h') diff --git a/include/sway/config.h b/include/sway/config.h index 48ebba3b..e9910be4 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -356,7 +356,7 @@ struct sway_config { struct input_config *input_config; struct seat_config *seat_config; struct sway_seat *seat; - swayc_t *current_container; + struct sway_container *current_container; } handler_context; }; @@ -416,7 +416,8 @@ void output_get_identifier(char *identifier, size_t len, struct sway_output *output); struct output_config *new_output_config(const char *name); void merge_output_config(struct output_config *dst, struct output_config *src); -void apply_output_config(struct output_config *oc, swayc_t *output); +void apply_output_config(struct output_config *oc, + struct sway_container *output); void free_output_config(struct output_config *oc); /** diff --git a/include/sway/criteria.h b/include/sway/criteria.h index 431cfa3a..ec256ddb 100644 --- a/include/sway/criteria.h +++ b/include/sway/criteria.h @@ -31,12 +31,12 @@ char *extract_crit_tokens(list_t *tokens, const char *criteria); // Returns list of criteria that match given container. These criteria have // been set with `for_window` commands and have an associated cmdlist. -list_t *criteria_for(swayc_t *cont); +list_t *criteria_for(struct sway_container *cont); // Returns a list of all containers that match the given list of tokens. list_t *container_for_crit_tokens(list_t *tokens); // Returns true if any criteria in the given list matches this container -bool criteria_any(swayc_t *cont, list_t *criteria); +bool criteria_any(struct sway_container *cont, list_t *criteria); #endif diff --git a/include/sway/input/input-manager.h b/include/sway/input/input-manager.h index eab7dc90..c6c73dba 100644 --- a/include/sway/input/input-manager.h +++ b/include/sway/input/input-manager.h @@ -31,10 +31,10 @@ struct sway_input_manager *sway_input_manager_create( struct sway_server *server); bool sway_input_manager_has_focus(struct sway_input_manager *input, - swayc_t *container); + struct sway_container *container); void sway_input_manager_set_focus(struct sway_input_manager *input, - swayc_t *container); + struct sway_container *container); void sway_input_manager_configure_xcursor(struct sway_input_manager *input); diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h index 1d55bec7..e43e6fd4 100644 --- a/include/sway/input/seat.h +++ b/include/sway/input/seat.h @@ -14,7 +14,7 @@ struct sway_seat_device { struct sway_seat_container { struct sway_seat *seat; - swayc_t *container; + struct sway_container *container; struct wl_list link; // sway_seat::focus_stack @@ -54,9 +54,9 @@ void sway_seat_remove_device(struct sway_seat *seat, void sway_seat_configure_xcursor(struct sway_seat *seat); -void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container); +void sway_seat_set_focus(struct sway_seat *seat, struct sway_container *container); -swayc_t *sway_seat_get_focus(struct sway_seat *seat); +struct sway_container *sway_seat_get_focus(struct sway_seat *seat); /** * Return the last container to be focused for the seat (or the most recently @@ -67,9 +67,10 @@ swayc_t *sway_seat_get_focus(struct sway_seat *seat); * is destroyed, or focus moves to a container with children and we need to * descend into the next leaf in focus order. */ -swayc_t *sway_seat_get_focus_inactive(struct sway_seat *seat, swayc_t *container); +struct sway_container *sway_seat_get_focus_inactive(struct sway_seat *seat, + struct sway_container *container); -swayc_t *sway_seat_get_focus_by_type(struct sway_seat *seat, +struct sway_container *sway_seat_get_focus_by_type(struct sway_seat *seat, enum swayc_types type); void sway_seat_set_config(struct sway_seat *seat, struct seat_config *seat_config); diff --git a/include/sway/ipc-json.h b/include/sway/ipc-json.h index 76b7d45b..3d2fdc4f 100644 --- a/include/sway/ipc-json.h +++ b/include/sway/ipc-json.h @@ -6,8 +6,8 @@ json_object *ipc_json_get_version(); -json_object *ipc_json_describe_container(swayc_t *c); -json_object *ipc_json_describe_container_recursive(swayc_t *c); +json_object *ipc_json_describe_container(struct sway_container *c); +json_object *ipc_json_describe_container_recursive(struct sway_container *c); json_object *ipc_json_describe_input(struct sway_input_device *device); #endif diff --git a/include/sway/ipc-server.h b/include/sway/ipc-server.h index db690b6e..d73006dc 100644 --- a/include/sway/ipc-server.h +++ b/include/sway/ipc-server.h @@ -12,6 +12,6 @@ void ipc_terminate(void); struct sockaddr_un *ipc_user_sockaddr(void); -void ipc_event_window(swayc_t *window, const char *change); +void ipc_event_window(struct sway_container *window, const char *change); #endif diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 5a2ae349..5def5e71 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -6,9 +6,7 @@ #include #include "list.h" -typedef struct sway_container swayc_t; - -extern swayc_t root_container; +extern struct sway_container root_container; struct sway_view; struct sway_seat; @@ -89,48 +87,53 @@ struct sway_container { } events; }; -void swayc_descendants_of_type(swayc_t *root, enum swayc_types type, - void (*func)(swayc_t *item, void *data), void *data); +void swayc_descendants_of_type(struct sway_container *root, + enum swayc_types type, + void (*func)(struct sway_container *item, void *data), void *data); // TODO only one container create function and pass the type? -swayc_t *new_output(struct sway_output *sway_output); +struct sway_container *new_output(struct sway_output *sway_output); -swayc_t *new_workspace(swayc_t *output, const char *name); +struct sway_container *new_workspace(struct sway_container *output, + const char *name); -swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view); +struct sway_container *new_view(struct sway_container *sibling, + struct sway_view *sway_view); -swayc_t *destroy_output(swayc_t *output); -swayc_t *destroy_view(swayc_t *view); +struct sway_container *destroy_output(struct sway_container *output); +struct sway_container *destroy_view(struct sway_container *view); -swayc_t *next_view_sibling(struct sway_seat *seat); +struct sway_container *next_view_sibling(struct sway_seat *seat); /** * Finds a container based on test criteria. Returns the first container that * passes the test. */ -swayc_t *swayc_by_test(swayc_t *container, - bool (*test)(swayc_t *view, void *data), void *data); +struct sway_container *swayc_by_test(struct sway_container *container, + bool (*test)(struct sway_container *view, void *data), void *data); /** * Finds a parent container with the given swayc_type. */ -swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type); +struct sway_container *swayc_parent_by_type(struct sway_container *container, + enum swayc_types type); /** * Maps a container's children over a function. */ -void container_map(swayc_t *container, - void (*f)(swayc_t *view, void *data), void *data); +void container_map(struct sway_container *container, + void (*f)(struct sway_container *view, void *data), void *data); -swayc_t *swayc_at(swayc_t *parent, double lx, double ly, - struct wlr_surface **surface, double *sx, double *sy); +struct sway_container *swayc_at(struct sway_container *parent, double lx, + double ly, struct wlr_surface **surface, double *sx, double *sy); /** * Apply the function for each child of the container breadth first. */ -void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data), - void *data); +void container_for_each_bfs(struct sway_container *con, void (*f)(struct + sway_container *con, void *data), void *data); -swayc_t *swayc_change_layout(swayc_t *container, enum swayc_layouts layout); +struct sway_container *swayc_change_layout(struct sway_container *container, + enum swayc_layouts layout); #endif diff --git a/include/sway/tree/layout.h b/include/sway/tree/layout.h index 39b7fb24..8bb9e075 100644 --- a/include/sway/tree/layout.h +++ b/include/sway/tree/layout.h @@ -34,7 +34,8 @@ void init_layout(void); void add_child(struct sway_container *parent, struct sway_container *child); -swayc_t *add_sibling(swayc_t *parent, swayc_t *child); +struct sway_container *add_sibling(struct sway_container *parent, + struct sway_container *child); struct sway_container *remove_child(struct sway_container *child); @@ -45,7 +46,7 @@ void sort_workspaces(struct sway_container *output); void arrange_windows(struct sway_container *container, double width, double height); -swayc_t *get_swayc_in_direction(swayc_t *container, - struct sway_seat *seat, enum movement_direction dir); +struct sway_container *get_swayc_in_direction(struct sway_container + *container, struct sway_seat *seat, enum movement_direction dir); #endif diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h index c8ce40d1..d73b29c1 100644 --- a/include/sway/tree/workspace.h +++ b/include/sway/tree/workspace.h @@ -7,20 +7,20 @@ extern char *prev_workspace_name; char *workspace_next_name(const char *output_name); -swayc_t *workspace_create(const char *name); +struct sway_container *workspace_create(const char *name); -bool workspace_switch(swayc_t *workspace); +bool workspace_switch(struct sway_container *workspace); struct sway_container *workspace_by_number(const char* name); -swayc_t *workspace_by_name(const char*); +struct sway_container *workspace_by_name(const char*); -struct sway_container *workspace_output_next(swayc_t *current); +struct sway_container *workspace_output_next(struct sway_container *current); -struct sway_container *workspace_next(swayc_t *current); +struct sway_container *workspace_next(struct sway_container *current); -struct sway_container *workspace_output_prev(swayc_t *current); +struct sway_container *workspace_output_prev(struct sway_container *current); -struct sway_container *workspace_prev(swayc_t *current); +struct sway_container *workspace_prev(struct sway_container *current); #endif diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index 27c2c72e..d421a03f 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c @@ -278,7 +278,7 @@ struct sway_input_manager *sway_input_manager_create( } bool sway_input_manager_has_focus(struct sway_input_manager *input, - swayc_t *container) { + struct sway_container *container) { struct sway_seat *seat = NULL; wl_list_for_each(seat, &input->seats, link) { if (sway_seat_get_focus(seat) == container) { @@ -290,7 +290,7 @@ bool sway_input_manager_has_focus(struct sway_input_manager *input, } void sway_input_manager_set_focus(struct sway_input_manager *input, - swayc_t *container) { + struct sway_container *container) { struct sway_seat *seat ; wl_list_for_each(seat, &input->seats, link) { sway_seat_set_focus(seat, container); -- cgit v1.2.3 From b90099b4b7df8068446c658ab99b58ff83648954 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 29 Mar 2018 16:17:55 -0400 Subject: rename container functions --- include/sway/config.h | 8 +- include/sway/input/seat.h | 2 +- include/sway/tree/container.h | 70 +++++++++------- include/sway/tree/layout.h | 2 +- sway/commands/focus.c | 4 +- sway/commands/kill.c | 2 +- sway/commands/layout.c | 4 +- sway/commands/output.c | 2 +- sway/commands/workspace.c | 12 +-- sway/config/output.c | 4 +- sway/criteria.c | 12 +-- sway/desktop/output.c | 14 ++-- sway/desktop/wl_shell.c | 6 +- sway/desktop/xdg_shell_v6.c | 6 +- sway/desktop/xwayland.c | 18 ++--- sway/input/cursor.c | 8 +- sway/input/seat.c | 34 ++++---- sway/ipc-json.c | 14 ++-- sway/ipc-server.c | 4 +- sway/tree/container.c | 182 +++++++++++++++++++++--------------------- sway/tree/layout.c | 86 ++++++++++---------- sway/tree/workspace.c | 70 ++++++++-------- swaybar/ipc.c | 2 +- 23 files changed, 287 insertions(+), 279 deletions(-) (limited to 'include/sway/tree/layout.h') diff --git a/include/sway/config.h b/include/sway/config.h index e9910be4..7fdd0be0 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -299,8 +299,8 @@ struct sway_config { char *floating_scroll_down_cmd; char *floating_scroll_left_cmd; char *floating_scroll_right_cmd; - enum swayc_layouts default_orientation; - enum swayc_layouts default_layout; + enum sway_container_layout default_orientation; + enum sway_container_layout default_layout; char *font; int font_height; @@ -324,8 +324,8 @@ struct sway_config { list_t *config_chain; const char *current_config; - enum swayc_border_types border; - enum swayc_border_types floating_border; + enum sway_container_border border; + enum sway_container_border floating_border; int border_thickness; int floating_border_thickness; enum edge_border_types hide_edge_borders; diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h index e43e6fd4..496bfd5d 100644 --- a/include/sway/input/seat.h +++ b/include/sway/input/seat.h @@ -71,7 +71,7 @@ struct sway_container *sway_seat_get_focus_inactive(struct sway_seat *seat, struct sway_container *container); struct sway_container *sway_seat_get_focus_by_type(struct sway_seat *seat, - enum swayc_types type); + enum sway_container_type type); void sway_seat_set_config(struct sway_seat *seat, struct seat_config *seat_config); diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 5def5e71..0dfed455 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -17,7 +17,7 @@ struct sway_seat; * This enum is in order. A container will never be inside of a container below * it on this list. */ -enum swayc_types { +enum sway_container_type { C_ROOT, C_OUTPUT, C_WORKSPACE, @@ -27,7 +27,7 @@ enum swayc_types { C_TYPES, }; -enum swayc_layouts { +enum sway_container_layout { L_NONE, L_HORIZ, L_VERT, @@ -39,7 +39,7 @@ enum swayc_layouts { L_LAYOUTS, }; -enum swayc_border_types { +enum sway_container_border { B_NONE, B_PIXEL, B_NORMAL, @@ -65,10 +65,10 @@ struct sway_container { char *name; - enum swayc_types type; - enum swayc_layouts layout; - enum swayc_layouts prev_layout; - enum swayc_layouts workspace_layout; + enum sway_container_type type; + enum sway_container_layout layout; + enum sway_container_layout prev_layout; + enum sway_container_layout workspace_layout; // TODO convert to layout coordinates double x, y; @@ -87,53 +87,61 @@ struct sway_container { } events; }; -void swayc_descendants_of_type(struct sway_container *root, - enum swayc_types type, - void (*func)(struct sway_container *item, void *data), void *data); - // TODO only one container create function and pass the type? -struct sway_container *new_output(struct sway_output *sway_output); +struct sway_container *sway_container_output_create( + struct sway_output *sway_output); + +struct sway_container *sway_container_workspace_create( + struct sway_container *output, const char *name); -struct sway_container *new_workspace(struct sway_container *output, - const char *name); +struct sway_container *sway_container_view_create( + struct sway_container *sibling, struct sway_view *sway_view); -struct sway_container *new_view(struct sway_container *sibling, - struct sway_view *sway_view); +struct sway_container *sway_container_output_destroy( + struct sway_container *output); -struct sway_container *destroy_output(struct sway_container *output); -struct sway_container *destroy_view(struct sway_container *view); +struct sway_container *sway_container_view_destroy(struct sway_container *view); +struct sway_container *sway_container_set_layout( + struct sway_container *container, enum sway_container_layout layout); + +void sway_container_descendents(struct sway_container *root, + enum sway_container_type type, + void (*func)(struct sway_container *item, void *data), void *data); + +// XXX: what is this? struct sway_container *next_view_sibling(struct sway_seat *seat); /** * Finds a container based on test criteria. Returns the first container that * passes the test. */ -struct sway_container *swayc_by_test(struct sway_container *container, +struct sway_container *sway_container_find(struct sway_container *container, bool (*test)(struct sway_container *view, void *data), void *data); /** - * Finds a parent container with the given swayc_type. + * Finds a parent container with the given struct sway_containerype. */ -struct sway_container *swayc_parent_by_type(struct sway_container *container, - enum swayc_types type); +struct sway_container *sway_container_parent(struct sway_container *container, + enum sway_container_type type); /** - * Maps a container's children over a function. + * Run a function for each child. */ -void container_map(struct sway_container *container, +void sway_container_for_each(struct sway_container *container, void (*f)(struct sway_container *view, void *data), void *data); -struct sway_container *swayc_at(struct sway_container *parent, double lx, - double ly, struct wlr_surface **surface, double *sx, double *sy); +/** + * Find a container at the given coordinates. + */ +struct sway_container *sway_container_at(struct sway_container *parent, + double lx, double ly, struct wlr_surface **surface, + double *sx, double *sy); /** * Apply the function for each child of the container breadth first. */ -void container_for_each_bfs(struct sway_container *con, void (*f)(struct - sway_container *con, void *data), void *data); - -struct sway_container *swayc_change_layout(struct sway_container *container, - enum swayc_layouts layout); +void sway_container_for_each_bfs(struct sway_container *container, + void (*f)(struct sway_container *container, void *data), void *data); #endif diff --git a/include/sway/tree/layout.h b/include/sway/tree/layout.h index 8bb9e075..f73b3880 100644 --- a/include/sway/tree/layout.h +++ b/include/sway/tree/layout.h @@ -39,7 +39,7 @@ struct sway_container *add_sibling(struct sway_container *parent, struct sway_container *remove_child(struct sway_container *child); -enum swayc_layouts default_layout(struct sway_container *output); +enum sway_container_layout default_layout(struct sway_container *output); void sort_workspaces(struct sway_container *output); diff --git a/sway/commands/focus.c b/sway/commands/focus.c index 18e9e0bf..64b05904 100644 --- a/sway/commands/focus.c +++ b/sway/commands/focus.c @@ -32,7 +32,7 @@ static bool parse_movement_direction(const char *name, } struct cmd_results *cmd_focus(int argc, char **argv) { - swayc_t *con = config->handler_context.current_container; + struct sway_container *con = config->handler_context.current_container; struct sway_seat *seat = config->handler_context.seat; if (con->type < C_WORKSPACE) { return cmd_results_new(CMD_FAILURE, "focus", @@ -51,7 +51,7 @@ struct cmd_results *cmd_focus(int argc, char **argv) { "Expected 'focus ' or 'focus output '"); } - swayc_t *next_focus = get_swayc_in_direction(con, seat, direction); + struct sway_container *next_focus = get_swayc_in_direction(con, seat, direction); if (next_focus) { sway_seat_set_focus(seat, next_focus); } diff --git a/sway/commands/kill.c b/sway/commands/kill.c index c0faed7a..f6774767 100644 --- a/sway/commands/kill.c +++ b/sway/commands/kill.c @@ -6,7 +6,7 @@ #include "sway/commands.h" struct cmd_results *cmd_kill(int argc, char **argv) { - enum swayc_types type = config->handler_context.current_container->type; + enum sway_container_type type = config->handler_context.current_container->type; if (type != C_VIEW && type != C_CONTAINER) { return cmd_results_new(CMD_INVALID, NULL, "Can only kill views and containers with this command"); diff --git a/sway/commands/layout.c b/sway/commands/layout.c index 2b193136..e10334e2 100644 --- a/sway/commands/layout.c +++ b/sway/commands/layout.c @@ -10,7 +10,7 @@ struct cmd_results *cmd_layout(int argc, char **argv) { if ((error = checkarg(argc, "layout", EXPECTED_MORE_THAN, 0))) { return error; } - swayc_t *parent = config->handler_context.current_container; + struct sway_container *parent = config->handler_context.current_container; // TODO: floating /* @@ -28,7 +28,7 @@ struct cmd_results *cmd_layout(int argc, char **argv) { if (strcasecmp(argv[0], "default") == 0) { swayc_change_layout(parent, parent->prev_layout); if (parent->layout == L_NONE) { - swayc_t *output = swayc_parent_by_type(parent, C_OUTPUT); + struct sway_container *output = sway_container_parent(parent, C_OUTPUT); swayc_change_layout(parent, default_layout(output)); } } else { diff --git a/sway/commands/output.c b/sway/commands/output.c index 35bc8099..f7e3372c 100644 --- a/sway/commands/output.c +++ b/sway/commands/output.c @@ -296,7 +296,7 @@ struct cmd_results *cmd_output(int argc, char **argv) { char identifier[128]; bool all = strcmp(output->name, "*") == 0; for (int i = 0; i < root_container.children->length; ++i) { - swayc_t *cont = root_container.children->items[i]; + struct sway_container *cont = root_container.children->items[i]; if (cont->type != C_OUTPUT) { continue; } diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c index 8751dffe..8b7139a9 100644 --- a/sway/commands/workspace.c +++ b/sway/commands/workspace.c @@ -17,15 +17,15 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { int output_location = -1; - swayc_t *current_container = config->handler_context.current_container; - swayc_t *old_workspace = NULL, *old_output = NULL; + struct sway_container *current_container = config->handler_context.current_container; + struct sway_container *old_workspace = NULL, *old_output = NULL; if (current_container) { if (current_container->type == C_WORKSPACE) { old_workspace = current_container; } else { - old_workspace = swayc_parent_by_type(current_container, C_WORKSPACE); + old_workspace = sway_container_parent(current_container, C_WORKSPACE); } - old_output = swayc_parent_by_type(current_container, C_OUTPUT); + old_output = sway_container_parent(current_container, C_OUTPUT); } for (int i = 0; i < argc; ++i) { @@ -57,7 +57,7 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { if (config->reading || !config->active) { return cmd_results_new(CMD_DEFER, "workspace", NULL); } - swayc_t *ws = NULL; + struct sway_container *ws = NULL; if (strcasecmp(argv[0], "number") == 0) { if (!(ws = workspace_by_number(argv[1]))) { char *name = join_args(argv + 1, argc - 1); @@ -92,7 +92,7 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { workspace_switch(ws); current_container = sway_seat_get_focus(config->handler_context.seat); - swayc_t *new_output = swayc_parent_by_type(current_container, C_OUTPUT); + struct sway_container *new_output = sway_container_parent(current_container, C_OUTPUT); if (config->mouse_warping && old_output != new_output) { // TODO: Warp mouse diff --git a/sway/config/output.c b/sway/config/output.c index 9e211861..5763bd21 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -120,14 +120,14 @@ void terminate_swaybg(pid_t pid) { } } -void apply_output_config(struct output_config *oc, swayc_t *output) { +void apply_output_config(struct output_config *oc, struct sway_container *output) { assert(output->type == C_OUTPUT); struct wlr_output *wlr_output = output->sway_output->wlr_output; if (oc && oc->enabled == 0) { wlr_output_layout_remove(root_container.sway_root->output_layout, wlr_output); - destroy_output(output); + sway_container_output_destroy(output); return; } diff --git a/sway/criteria.c b/sway/criteria.c index b8b581ed..70f8e305 100644 --- a/sway/criteria.c +++ b/sway/criteria.c @@ -272,7 +272,7 @@ static int regex_cmp(const char *item, const pcre *regex) { } // test a single view if it matches list of criteria tokens (all of them). -static bool criteria_test(swayc_t *cont, list_t *tokens) { +static bool criteria_test(struct sway_container *cont, list_t *tokens) { if (cont->type != C_VIEW) { return false; } @@ -398,7 +398,7 @@ void free_criteria(struct criteria *crit) { free(crit); } -bool criteria_any(swayc_t *cont, list_t *criteria) { +bool criteria_any(struct sway_container *cont, list_t *criteria) { for (int i = 0; i < criteria->length; i++) { struct criteria *bc = criteria->items[i]; if (criteria_test(cont, bc->tokens)) { @@ -408,7 +408,7 @@ bool criteria_any(swayc_t *cont, list_t *criteria) { return false; } -list_t *criteria_for(swayc_t *cont) { +list_t *criteria_for(struct sway_container *cont) { list_t *criteria = config->criteria, *matches = create_list(); for (int i = 0; i < criteria->length; i++) { struct criteria *bc = criteria->items[i]; @@ -424,7 +424,7 @@ struct list_tokens { list_t *tokens; }; -static void container_match_add(swayc_t *container, +static void container_match_add(struct sway_container *container, struct list_tokens *list_tokens) { if (criteria_test(container, list_tokens->tokens)) { list_add(list_tokens->list, container); @@ -435,8 +435,8 @@ list_t *container_for_crit_tokens(list_t *tokens) { struct list_tokens list_tokens = (struct list_tokens){create_list(), tokens}; - container_map(&root_container, - (void (*)(swayc_t *, void *))container_match_add, + sway_container_for_each(&root_container, + (void (*)(struct sway_container *, void *))container_match_add, &list_tokens); // TODO look in the scratchpad diff --git a/sway/desktop/output.c b/sway/desktop/output.c index debda396..3e7d8509 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -145,7 +145,7 @@ struct render_data { struct timespec *now; }; -static void output_frame_view(swayc_t *view, void *data) { +static void output_frame_view(struct sway_container *view, void *data) { struct render_data *rdata = data; struct sway_output *output = rdata->output; struct timespec *now = rdata->now; @@ -218,16 +218,16 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { &soutput->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]); struct sway_seat *seat = input_manager_current_seat(input_manager); - swayc_t *focus = sway_seat_get_focus_inactive(seat, soutput->swayc); - swayc_t *workspace = (focus->type == C_WORKSPACE ? + struct sway_container *focus = sway_seat_get_focus_inactive(seat, soutput->swayc); + struct sway_container *workspace = (focus->type == C_WORKSPACE ? focus : - swayc_parent_by_type(focus, C_WORKSPACE)); + sway_container_parent(focus, C_WORKSPACE)); struct render_data rdata = { .output = soutput, .now = &now, }; - swayc_descendants_of_type(workspace, C_VIEW, output_frame_view, &rdata); + sway_container_descendents(workspace, C_VIEW, output_frame_view, &rdata); // render unmanaged views on top struct sway_view *view; @@ -258,7 +258,7 @@ static void handle_output_destroy(struct wl_listener *listener, void *data) { struct wlr_output *wlr_output = data; wlr_log(L_DEBUG, "Output %p %s removed", wlr_output, wlr_output->name); - destroy_output(output->swayc); + sway_container_output_destroy(output->swayc); } static void handle_output_mode(struct wl_listener *listener, void *data) { @@ -286,7 +286,7 @@ void handle_new_output(struct wl_listener *listener, void *data) { wlr_output_set_mode(wlr_output, mode); } - output->swayc = new_output(output); + output->swayc = sway_container_output_create(output); if (!output->swayc) { free(output); return; diff --git a/sway/desktop/wl_shell.c b/sway/desktop/wl_shell.c index bb97fad4..bf41d7bf 100644 --- a/sway/desktop/wl_shell.c +++ b/sway/desktop/wl_shell.c @@ -74,7 +74,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_container_of(listener, sway_surface, destroy); wl_list_remove(&sway_surface->commit.link); wl_list_remove(&sway_surface->destroy.link); - swayc_t *parent = destroy_view(sway_surface->view->swayc); + struct sway_container *parent = sway_container_view_destroy(sway_surface->view->swayc); free(sway_surface->view); free(sway_surface); arrange_windows(parent, -1, -1); @@ -132,8 +132,8 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { wl_signal_add(&shell_surface->events.destroy, &sway_surface->destroy); struct sway_seat *seat = input_manager_current_seat(input_manager); - swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); - swayc_t *cont = new_view(focus, sway_view); + struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container); + struct sway_container *cont = sway_container_view_create(focus, sway_view); sway_view->swayc = cont; arrange_windows(cont->parent, -1, -1); diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 25ffacbb..6b50d470 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -83,7 +83,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_container_of(listener, sway_xdg_surface, destroy); wl_list_remove(&sway_xdg_surface->commit.link); wl_list_remove(&sway_xdg_surface->destroy.link); - swayc_t *parent = destroy_view(sway_xdg_surface->view->swayc); + struct sway_container *parent = sway_container_view_destroy(sway_xdg_surface->view->swayc); free(sway_xdg_surface->view); free(sway_xdg_surface); arrange_windows(parent, -1, -1); @@ -136,8 +136,8 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { wl_signal_add(&xdg_surface->events.destroy, &sway_surface->destroy); struct sway_seat *seat = input_manager_current_seat(input_manager); - swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); - swayc_t *cont = new_view(focus, sway_view); + struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container); + struct sway_container *cont = sway_container_view_create(focus, sway_view); sway_view->swayc = cont; arrange_windows(cont->parent, -1, -1); diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 7f66f746..96edab51 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -49,11 +49,11 @@ static void set_position(struct sway_view *view, double ox, double oy) { if (!assert_xwayland(view)) { return; } - swayc_t *output = swayc_parent_by_type(view->swayc, C_OUTPUT); + struct sway_container *output = sway_container_parent(view->swayc, C_OUTPUT); if (!sway_assert(output, "view must be within tree to set position")) { return; } - swayc_t *root = swayc_parent_by_type(output, C_ROOT); + struct sway_container *root = sway_container_parent(output, C_ROOT); if (!sway_assert(root, "output must be within tree to set position")) { return; } @@ -114,7 +114,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { } } - swayc_t *parent = destroy_view(sway_surface->view->swayc); + struct sway_container *parent = sway_container_view_destroy(sway_surface->view->swayc); if (parent) { arrange_windows(parent, -1, -1); } @@ -132,7 +132,7 @@ static void handle_unmap_notify(struct wl_listener *listener, void *data) { } // take it out of the tree - swayc_t *parent = destroy_view(sway_surface->view->swayc); + struct sway_container *parent = sway_container_view_destroy(sway_surface->view->swayc); if (parent) { arrange_windows(parent, -1, -1); } @@ -155,12 +155,12 @@ static void handle_map_notify(struct wl_listener *listener, void *data) { &sway_surface->view->unmanaged_view_link); } else { struct sway_view *view = sway_surface->view; - destroy_view(view->swayc); + sway_container_view_destroy(view->swayc); - swayc_t *parent = root_container.children->items[0]; + struct sway_container *parent = root_container.children->items[0]; parent = parent->children->items[0]; // workspace - swayc_t *cont = new_view(parent, view); + struct sway_container *cont = sway_container_view_create(parent, view); view->swayc = cont; arrange_windows(cont->parent, -1, -1); @@ -238,8 +238,8 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { } struct sway_seat *seat = input_manager_current_seat(input_manager); - swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); - swayc_t *cont = new_view(focus, sway_view); + struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container); + struct sway_container *cont = sway_container_view_create(focus, sway_view); sway_view->swayc = cont; arrange_windows(cont->parent, -1, -1); diff --git a/sway/input/cursor.c b/sway/input/cursor.c index c0e14265..a0e4b9be 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -49,8 +49,8 @@ static void cursor_send_pointer_motion(struct sway_cursor *cursor, } } - swayc_t *swayc = - swayc_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy); + struct sway_container *swayc = + sway_container_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy); if (swayc) { wlr_seat_pointer_notify_enter(seat, surface, sx, sy); wlr_seat_pointer_notify_motion(seat, time, sx, sy); @@ -87,8 +87,8 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) { if (event->button == BTN_LEFT) { struct wlr_surface *surface = NULL; double sx, sy; - swayc_t *swayc = - swayc_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy); + struct sway_container *swayc = + sway_container_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy); sway_seat_set_focus(cursor->seat, swayc); } diff --git a/sway/input/seat.c b/sway/input/seat.c index 56b39766..f03a03b4 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -37,7 +37,7 @@ static void handle_seat_container_destroy(struct wl_listener *listener, struct sway_seat_container *seat_con = wl_container_of(listener, seat_con, destroy); struct sway_seat *seat = seat_con->seat; - swayc_t *con = seat_con->container; + struct sway_container *con = seat_con->container; bool is_focus = (sway_seat_get_focus(seat) == con); @@ -46,7 +46,7 @@ static void handle_seat_container_destroy(struct wl_listener *listener, if (is_focus) { // pick next focus sway_seat_set_focus(seat, NULL); - swayc_t *next = sway_seat_get_focus_inactive(seat, con->parent); + struct sway_container *next = sway_seat_get_focus_inactive(seat, con->parent); if (next == NULL) { next = con->parent; } @@ -59,7 +59,7 @@ static void handle_seat_container_destroy(struct wl_listener *listener, } static struct sway_seat_container *seat_container_from_container( - struct sway_seat *seat, swayc_t *con) { + struct sway_seat *seat, struct sway_container *con) { if (con->type < C_WORKSPACE) { // these don't get seat containers ever return NULL; @@ -89,11 +89,11 @@ static struct sway_seat_container *seat_container_from_container( static void handle_new_container(struct wl_listener *listener, void *data) { struct sway_seat *seat = wl_container_of(listener, seat, new_container); - swayc_t *con = data; + struct sway_container *con = data; seat_container_from_container(seat, con); } -static void collect_focus_iter(swayc_t *con, void *data) { +static void collect_focus_iter(struct sway_container *con, void *data) { struct sway_seat *seat = data; if (con->type > C_WORKSPACE) { return; @@ -130,7 +130,7 @@ struct sway_seat *sway_seat_create(struct sway_input_manager *input, // init the focus stack wl_list_init(&seat->focus_stack); - container_for_each_bfs(&root_container, collect_focus_iter, seat); + sway_container_for_each_bfs(&root_container, collect_focus_iter, seat); wl_signal_add(&root_container.sway_root->events.new_container, &seat->new_container); @@ -166,7 +166,7 @@ static void seat_configure_keyboard(struct sway_seat *seat, sway_keyboard_configure(seat_device->keyboard); wlr_seat_set_keyboard(seat->wlr_seat, seat_device->input_device->wlr_device); - swayc_t *focus = sway_seat_get_focus(seat); + struct sway_container *focus = sway_seat_get_focus(seat); if (focus && focus->type == C_VIEW) { // force notify reenter to pick up the new configuration wlr_seat_keyboard_clear_focus(seat->wlr_seat); @@ -270,7 +270,7 @@ void sway_seat_configure_xcursor(struct sway_seat *seat) { } for (int i = 0; i < root_container.children->length; ++i) { - swayc_t *output_container = root_container.children->items[i]; + struct sway_container *output_container = root_container.children->items[i]; struct wlr_output *output = output_container->sway_output->wlr_output; bool result = @@ -289,8 +289,8 @@ void sway_seat_configure_xcursor(struct sway_seat *seat) { seat->cursor->cursor->y); } -void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) { - swayc_t *last_focus = sway_seat_get_focus(seat); +void sway_seat_set_focus(struct sway_seat *seat, struct sway_container *container) { + struct sway_container *last_focus = sway_seat_get_focus(seat); if (container && last_focus == container) { return; @@ -330,9 +330,9 @@ void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) { seat->has_focus = (container != NULL); } -swayc_t *sway_seat_get_focus_inactive(struct sway_seat *seat, swayc_t *container) { +struct sway_container *sway_seat_get_focus_inactive(struct sway_seat *seat, struct sway_container *container) { struct sway_seat_container *current = NULL; - swayc_t *parent = NULL; + struct sway_container *parent = NULL; wl_list_for_each(current, &seat->focus_stack, link) { parent = current->container->parent; @@ -351,21 +351,21 @@ swayc_t *sway_seat_get_focus_inactive(struct sway_seat *seat, swayc_t *container return NULL; } -swayc_t *sway_seat_get_focus(struct sway_seat *seat) { +struct sway_container *sway_seat_get_focus(struct sway_seat *seat) { if (!seat->has_focus) { return NULL; } return sway_seat_get_focus_inactive(seat, &root_container); } -swayc_t *sway_seat_get_focus_by_type(struct sway_seat *seat, - enum swayc_types type) { - swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); +struct sway_container *sway_seat_get_focus_by_type(struct sway_seat *seat, + enum sway_container_type type) { + struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container); if (focus->type == type) { return focus; } - return swayc_parent_by_type(focus, type); + return sway_container_parent(focus, type); } void sway_seat_set_config(struct sway_seat *seat, diff --git a/sway/ipc-json.c b/sway/ipc-json.c index ebd5e43a..7caa2457 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -25,7 +25,7 @@ json_object *ipc_json_get_version() { return version; } -static json_object *ipc_json_create_rect(swayc_t *c) { +static json_object *ipc_json_create_rect(struct sway_container *c) { json_object *rect = json_object_new_object(); json_object_object_add(rect, "x", json_object_new_int((int32_t)c->x)); @@ -36,7 +36,7 @@ static json_object *ipc_json_create_rect(swayc_t *c) { return rect; } -static void ipc_json_describe_root(swayc_t *root, json_object *object) { +static void ipc_json_describe_root(struct sway_container *root, json_object *object) { json_object_object_add(object, "type", json_object_new_string("root")); json_object_object_add(object, "layout", json_object_new_string("splith")); } @@ -63,7 +63,7 @@ static const char *ipc_json_get_output_transform(enum wl_output_transform transf return NULL; } -static void ipc_json_describe_output(swayc_t *container, json_object *object) { +static void ipc_json_describe_output(struct sway_container *container, json_object *object) { struct wlr_output *wlr_output = container->sway_output->wlr_output; json_object_object_add(object, "type", json_object_new_string("output")); json_object_object_add(object, "active", json_object_new_boolean(true)); @@ -94,7 +94,7 @@ static void ipc_json_describe_output(swayc_t *container, json_object *object) { json_object_object_add(object, "modes", modes_array); } -static void ipc_json_describe_workspace(swayc_t *workspace, json_object *object) { +static void ipc_json_describe_workspace(struct sway_container *workspace, json_object *object) { int num = (isdigit(workspace->name[0])) ? atoi(workspace->name) : -1; json_object_object_add(object, "num", json_object_new_int(num)); @@ -102,11 +102,11 @@ static void ipc_json_describe_workspace(swayc_t *workspace, json_object *object) json_object_object_add(object, "type", json_object_new_string("workspace")); } -static void ipc_json_describe_view(swayc_t *c, json_object *object) { +static void ipc_json_describe_view(struct sway_container *c, json_object *object) { json_object_object_add(object, "name", (c->name) ? json_object_new_string(c->name) : NULL); } -json_object *ipc_json_describe_container(swayc_t *c) { +json_object *ipc_json_describe_container(struct sway_container *c) { if (!(sway_assert(c, "Container must not be null."))) { return NULL; } @@ -147,7 +147,7 @@ json_object *ipc_json_describe_container(swayc_t *c) { return object; } -json_object *ipc_json_describe_container_recursive(swayc_t *c) { +json_object *ipc_json_describe_container_recursive(struct sway_container *c) { json_object *object = ipc_json_describe_container(c); int i; diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 156de380..50d0bcf3 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -279,7 +279,7 @@ static void ipc_send_event(const char *json_string, enum ipc_command_type event) } } -void ipc_event_window(swayc_t *window, const char *change) { +void ipc_event_window(struct sway_container *window, const char *change) { wlr_log(L_DEBUG, "Sending window::%s event", change); json_object *obj = json_object_new_object(); json_object_object_add(obj, "change", json_object_new_string(change)); @@ -400,7 +400,7 @@ void ipc_client_handle_command(struct ipc_client *client) { { json_object *outputs = json_object_new_array(); for (int i = 0; i < root_container.children->length; ++i) { - swayc_t *container = root_container.children->items[i]; + struct sway_container *container = root_container.children->items[i]; if (container->type == C_OUTPUT) { json_object_array_add(outputs, ipc_json_describe_container(container)); diff --git a/sway/tree/container.c b/sway/tree/container.c index 805d5644..d31966b3 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -33,48 +33,15 @@ static list_t *get_bfs_queue() { return bfs_queue; } -static void notify_new_container(swayc_t *container) { +static void notify_new_container(struct sway_container *container) { wl_signal_emit(&root_container.sway_root->events.new_container, container); ipc_event_window(container, "new"); } -swayc_t *swayc_by_test(swayc_t *container, - bool (*test)(swayc_t *view, void *data), void *data) { - if (!container->children) { - return NULL; - } - // TODO: floating windows - for (int i = 0; i < container->children->length; ++i) { - swayc_t *child = container->children->items[i]; - if (test(child, data)) { - return child; - } else { - swayc_t *res = swayc_by_test(child, test, data); - if (res) { - return res; - } - } - } - return NULL; -} - -void swayc_descendants_of_type(swayc_t *root, enum swayc_types type, - void (*func)(swayc_t *item, void *data), void *data) { - for (int i = 0; i < root->children->length; ++i) { - swayc_t *item = root->children->items[i]; - if (item->type == type) { - func(item, data); - } - if (item->children && item->children->length) { - swayc_descendants_of_type(item, type, func, data); - } - } -} - -static swayc_t *new_swayc(enum swayc_types type) { +static struct sway_container *new_swayc(enum sway_container_type type) { // next id starts at 1 because 0 is assigned to root_container in layout.c static size_t next_id = 1; - swayc_t *c = calloc(1, sizeof(swayc_t)); + struct sway_container *c = calloc(1, sizeof(struct sway_container)); if (!c) { return NULL; } @@ -91,7 +58,7 @@ static swayc_t *new_swayc(enum swayc_types type) { return c; } -static void free_swayc(swayc_t *cont) { +static void free_swayc(struct sway_container *cont) { if (!sway_assert(cont, "free_swayc passed NULL")) { return; } @@ -119,7 +86,7 @@ static void free_swayc(swayc_t *cont) { free(cont); } -swayc_t *new_output(struct sway_output *sway_output) { +struct sway_container *sway_container_output_create(struct sway_output *sway_output) { struct wlr_box size; wlr_output_effective_resolution(sway_output->wlr_output, &size.width, &size.height); @@ -154,7 +121,7 @@ swayc_t *new_output(struct sway_output *sway_output) { return NULL; } - swayc_t *output = new_swayc(C_OUTPUT); + struct sway_container *output = new_swayc(C_OUTPUT); output->sway_output = sway_output; output->name = strdup(name); if (output->name == NULL) { @@ -169,7 +136,7 @@ swayc_t *new_output(struct sway_output *sway_output) { // Create workspace char *ws_name = workspace_next_name(output->name); wlr_log(L_DEBUG, "Creating default workspace %s", ws_name); - swayc_t *ws = new_workspace(output, ws_name); + struct sway_container *ws = sway_container_workspace_create(output, ws_name); // Set each seat's focus if not already set struct sway_seat *seat = NULL; wl_list_for_each(seat, &input_manager->seats, link) { @@ -183,12 +150,12 @@ swayc_t *new_output(struct sway_output *sway_output) { return output; } -swayc_t *new_workspace(swayc_t *output, const char *name) { - if (!sway_assert(output, "new_workspace called with null output")) { +struct sway_container *sway_container_workspace_create(struct sway_container *output, const char *name) { + if (!sway_assert(output, "sway_container_workspace_create called with null output")) { return NULL; } wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name); - swayc_t *workspace = new_swayc(C_WORKSPACE); + struct sway_container *workspace = new_swayc(C_WORKSPACE); workspace->x = output->x; workspace->y = output->y; @@ -205,12 +172,12 @@ swayc_t *new_workspace(swayc_t *output, const char *name) { return workspace; } -swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view) { - if (!sway_assert(sibling, "new_view called with NULL sibling/parent")) { +struct sway_container *sway_container_view_create(struct sway_container *sibling, struct sway_view *sway_view) { + if (!sway_assert(sibling, "sway_container_view_create called with NULL sibling/parent")) { return NULL; } const char *title = view_get_title(sway_view); - swayc_t *swayc = new_swayc(C_VIEW); + struct sway_container *swayc = new_swayc(C_VIEW); wlr_log(L_DEBUG, "Adding new view %p:%s to container %p %d %s", swayc, title, sibling, sibling ? sibling->type : 0, sibling->name); // Setup values @@ -230,8 +197,8 @@ swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view) { return swayc; } -swayc_t *destroy_output(swayc_t *output) { - if (!sway_assert(output, "null output passed to destroy_output")) { +struct sway_container *sway_container_output_destroy(struct sway_container *output) { + if (!sway_assert(output, "null output passed to sway_container_output_destroy")) { return NULL; } @@ -243,7 +210,7 @@ swayc_t *destroy_output(swayc_t *output) { int p = root_container.children->items[0] == output; // Move workspace from this output to another output while (output->children->length) { - swayc_t *child = output->children->items[0]; + struct sway_container *child = output->children->items[0]; remove_child(child); add_child(root_container.children->items[p], child); } @@ -262,12 +229,12 @@ swayc_t *destroy_output(swayc_t *output) { return &root_container; } -swayc_t *destroy_view(swayc_t *view) { +struct sway_container *sway_container_view_destroy(struct sway_container *view) { if (!view) { return NULL; } wlr_log(L_DEBUG, "Destroying view '%s'", view->name); - swayc_t *parent = view->parent; + struct sway_container *parent = view->parent; free_swayc(view); // TODO WLR: Destroy empty containers @@ -279,7 +246,52 @@ swayc_t *destroy_view(swayc_t *view) { return parent; } -swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) { +struct sway_container *swayc_change_layout(struct sway_container *container, enum sway_container_layout layout) { + if (container->type == C_WORKSPACE) { + container->workspace_layout = layout; + if (layout == L_HORIZ || layout == L_VERT) { + container->layout = layout; + } + } else { + container->layout = layout; + } + return container; +} + +void sway_container_descendents(struct sway_container *root, enum sway_container_type type, + void (*func)(struct sway_container *item, void *data), void *data) { + for (int i = 0; i < root->children->length; ++i) { + struct sway_container *item = root->children->items[i]; + if (item->type == type) { + func(item, data); + } + if (item->children && item->children->length) { + sway_container_descendents(item, type, func, data); + } + } +} + +struct sway_container *sway_container_find(struct sway_container *container, + bool (*test)(struct sway_container *view, void *data), void *data) { + if (!container->children) { + return NULL; + } + // TODO: floating windows + for (int i = 0; i < container->children->length; ++i) { + struct sway_container *child = container->children->items[i]; + if (test(child, data)) { + return child; + } else { + struct sway_container *res = sway_container_find(child, test, data); + if (res) { + return res; + } + } + } + return NULL; +} + +struct sway_container *sway_container_parent(struct sway_container *container, enum sway_container_type type) { if (!sway_assert(container, "container is NULL")) { return NULL; } @@ -292,7 +304,29 @@ swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) { return container; } -swayc_t *swayc_at(swayc_t *parent, double lx, double ly, +void sway_container_for_each(struct sway_container *container, void (*f)(struct sway_container *view, void *data), void *data) { + if (container) { + int i; + if (container->children) { + for (i = 0; i < container->children->length; ++i) { + struct sway_container *child = container->children->items[i]; + sway_container_for_each(child, f, data); + } + } + // TODO + /* + if (container->floating) { + for (i = 0; i < container->floating->length; ++i) { + struct sway_container *child = container->floating->items[i]; + container_map(child, f, data); + } + } + */ + f(container, data); + } +} + +struct sway_container *sway_container_at(struct sway_container *parent, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { list_t *queue = get_bfs_queue(); if (!queue) { @@ -301,13 +335,13 @@ swayc_t *swayc_at(swayc_t *parent, double lx, double ly, list_add(queue, parent); - swayc_t *swayc = NULL; + struct sway_container *swayc = NULL; while (queue->length) { swayc = queue->items[0]; list_del(queue, 0); if (swayc->type == C_VIEW) { struct sway_view *sview = swayc->sway_view; - swayc_t *soutput = swayc_parent_by_type(swayc, C_OUTPUT); + struct sway_container *soutput = sway_container_parent(swayc, C_OUTPUT); struct wlr_box *output_box = wlr_output_layout_get_box( root_container.sway_root->output_layout, @@ -377,29 +411,7 @@ swayc_t *swayc_at(swayc_t *parent, double lx, double ly, return NULL; } -void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { - if (container) { - int i; - if (container->children) { - for (i = 0; i < container->children->length; ++i) { - swayc_t *child = container->children->items[i]; - container_map(child, f, data); - } - } - // TODO - /* - if (container->floating) { - for (i = 0; i < container->floating->length; ++i) { - swayc_t *child = container->floating->items[i]; - container_map(child, f, data); - } - } - */ - f(container, data); - } -} - -void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data), +void sway_container_for_each_bfs(struct sway_container *con, void (*f)(struct sway_container *con, void *data), void *data) { list_t *queue = get_bfs_queue(); if (!queue) { @@ -413,7 +425,7 @@ void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data), list_add(queue, con); - swayc_t *current = NULL; + struct sway_container *current = NULL; while (queue->length) { current = queue->items[0]; list_del(queue, 0); @@ -422,15 +434,3 @@ void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data), list_cat(queue, current->children); } } - -swayc_t *swayc_change_layout(swayc_t *container, enum swayc_layouts layout) { - if (container->type == C_WORKSPACE) { - container->workspace_layout = layout; - if (layout == L_HORIZ || layout == L_VERT) { - container->layout = layout; - } - } else { - container->layout = layout; - } - return container; -} diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 5a15f3a2..068fb39c 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -14,7 +14,7 @@ #include "list.h" #include "log.h" -swayc_t root_container; +struct sway_container root_container; static void output_layout_change_notify(struct wl_listener *listener, void *data) { struct wlr_box *layout_box = wlr_output_layout_get_box( @@ -23,7 +23,7 @@ static void output_layout_change_notify(struct wl_listener *listener, void *data root_container.height = layout_box->height; for (int i = 0 ; i < root_container.children->length; ++i) { - swayc_t *output_container = root_container.children->items[i]; + struct sway_container *output_container = root_container.children->items[i]; if (output_container->type != C_OUTPUT) { continue; } @@ -62,9 +62,9 @@ void init_layout(void) { &root_container.sway_root->output_layout_change); } -static int index_child(const swayc_t *child) { +static int index_child(const struct sway_container *child) { // TODO handle floating - swayc_t *parent = child->parent; + struct sway_container *parent = child->parent; int i, len; len = parent->children->length; for (i = 0; i < len; ++i) { @@ -79,16 +79,16 @@ static int index_child(const swayc_t *child) { return i; } -swayc_t *add_sibling(swayc_t *fixed, swayc_t *active) { +struct sway_container *add_sibling(struct sway_container *fixed, struct sway_container *active) { // TODO handle floating - swayc_t *parent = fixed->parent; + struct sway_container *parent = fixed->parent; int i = index_child(fixed); list_insert(parent->children, i + 1, active); active->parent = parent; return active->parent; } -void add_child(swayc_t *parent, swayc_t *child) { +void add_child(struct sway_container *parent, struct sway_container *child) { wlr_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", child, child->type, child->width, child->height, parent, parent->type, parent->width, parent->height); @@ -102,9 +102,9 @@ void add_child(swayc_t *parent, swayc_t *child) { */ } -swayc_t *remove_child(swayc_t *child) { +struct sway_container *remove_child(struct sway_container *child) { int i; - swayc_t *parent = child->parent; + struct sway_container *parent = child->parent; for (i = 0; i < parent->children->length; ++i) { if (parent->children->items[i] == child) { list_del(parent->children, i); @@ -115,7 +115,7 @@ swayc_t *remove_child(swayc_t *child) { return parent; } -enum swayc_layouts default_layout(swayc_t *output) { +enum sway_container_layout default_layout(struct sway_container *output) { /* TODO WLR if (config->default_layout != L_NONE) { //return config->default_layout; @@ -129,8 +129,8 @@ enum swayc_layouts default_layout(swayc_t *output) { } static int sort_workspace_cmp_qsort(const void *_a, const void *_b) { - swayc_t *a = *(void **)_a; - swayc_t *b = *(void **)_b; + struct sway_container *a = *(void **)_a; + struct sway_container *b = *(void **)_b; int retval = 0; if (isdigit(a->name[0]) && isdigit(b->name[0])) { @@ -146,21 +146,21 @@ static int sort_workspace_cmp_qsort(const void *_a, const void *_b) { return retval; } -void sort_workspaces(swayc_t *output) { +void sort_workspaces(struct sway_container *output) { list_stable_sort(output->children, sort_workspace_cmp_qsort); } -static void apply_horiz_layout(swayc_t *container, const double x, +static void apply_horiz_layout(struct sway_container *container, const double x, const double y, const double width, const double height, const int start, const int end); -static void apply_vert_layout(swayc_t *container, const double x, +static void apply_vert_layout(struct sway_container *container, const double x, const double y, const double width, const double height, const int start, const int end); -void arrange_windows(swayc_t *container, double width, double height) { +void arrange_windows(struct sway_container *container, double width, double height) { int i; if (width == -1 || height == -1) { width = container->width; @@ -181,7 +181,7 @@ void arrange_windows(swayc_t *container, double width, double height) { case C_ROOT: // TODO: wlr_output_layout probably for (i = 0; i < container->children->length; ++i) { - swayc_t *output = container->children->items[i]; + struct sway_container *output = container->children->items[i]; wlr_log(L_DEBUG, "Arranging output '%s' at %f,%f", output->name, output->x, output->y); arrange_windows(output, -1, -1); @@ -197,13 +197,13 @@ void arrange_windows(swayc_t *container, double width, double height) { } // arrange all workspaces: for (i = 0; i < container->children->length; ++i) { - swayc_t *child = container->children->items[i]; + struct sway_container *child = container->children->items[i]; arrange_windows(child, -1, -1); } return; case C_WORKSPACE: { - swayc_t *output = swayc_parent_by_type(container, C_OUTPUT); + struct sway_container *output = sway_container_parent(container, C_OUTPUT); struct wlr_box *area = &output->sway_output->usable_area; wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d", area->width, area->height, area->x, area->y); @@ -252,14 +252,14 @@ void arrange_windows(swayc_t *container, double width, double height) { } } -static void apply_horiz_layout(swayc_t *container, +static void apply_horiz_layout(struct sway_container *container, const double x, const double y, const double width, const double height, const int start, const int end) { double scale = 0; // Calculate total width for (int i = start; i < end; ++i) { - double *old_width = &((swayc_t *)container->children->items[i])->width; + double *old_width = &((struct sway_container *)container->children->items[i])->width; if (*old_width <= 0) { if (end - start > 1) { *old_width = width / (end - start - 1); @@ -276,7 +276,7 @@ static void apply_horiz_layout(swayc_t *container, if (scale > 0.1) { wlr_log(L_DEBUG, "Arranging %p horizontally", container); for (int i = start; i < end; ++i) { - swayc_t *child = container->children->items[i]; + struct sway_container *child = container->children->items[i]; wlr_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, width, scale); @@ -301,7 +301,7 @@ static void apply_horiz_layout(swayc_t *container, } } -void apply_vert_layout(swayc_t *container, +void apply_vert_layout(struct sway_container *container, const double x, const double y, const double width, const double height, const int start, const int end) { @@ -309,7 +309,7 @@ void apply_vert_layout(swayc_t *container, double scale = 0; // Calculate total height for (i = start; i < end; ++i) { - double *old_height = &((swayc_t *)container->children->items[i])->height; + double *old_height = &((struct sway_container *)container->children->items[i])->height; if (*old_height <= 0) { if (end - start > 1) { *old_height = height / (end - start - 1); @@ -326,7 +326,7 @@ void apply_vert_layout(swayc_t *container, if (scale > 0.1) { wlr_log(L_DEBUG, "Arranging %p vertically", container); for (i = start; i < end; ++i) { - swayc_t *child = container->children->items[i]; + struct sway_container *child = container->children->items[i]; wlr_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, height, scale); @@ -354,15 +354,15 @@ void apply_vert_layout(swayc_t *container, /** * Get swayc in the direction of newly entered output. */ -static swayc_t *get_swayc_in_output_direction(swayc_t *output, +static struct sway_container *get_swayc_in_output_direction(struct sway_container *output, enum movement_direction dir, struct sway_seat *seat) { if (!output) { return NULL; } - swayc_t *ws = sway_seat_get_focus_inactive(seat, output); + struct sway_container *ws = sway_seat_get_focus_inactive(seat, output); if (ws->type != C_WORKSPACE) { - ws = swayc_parent_by_type(ws, C_WORKSPACE); + ws = sway_container_parent(ws, C_WORKSPACE); } if (ws == NULL) { @@ -380,9 +380,9 @@ static swayc_t *get_swayc_in_output_direction(swayc_t *output, return ws->children->items[0]; case MOVE_UP: case MOVE_DOWN: { - swayc_t *focused = sway_seat_get_focus_inactive(seat, ws); + struct sway_container *focused = sway_seat_get_focus_inactive(seat, ws); if (focused && focused->parent) { - swayc_t *parent = focused->parent; + struct sway_container *parent = focused->parent; if (parent->layout == L_VERT) { if (dir == MOVE_UP) { // get child furthest down on new output @@ -404,13 +404,13 @@ static swayc_t *get_swayc_in_output_direction(swayc_t *output, return ws; } -static void get_layout_center_position(swayc_t *container, int *x, int *y) { +static void get_layout_center_position(struct sway_container *container, int *x, int *y) { // FIXME view coords are inconsistently referred to in layout/output systems if (container->type == C_OUTPUT) { *x = container->x + container->width/2; *y = container->y + container->height/2; } else { - swayc_t *output = swayc_parent_by_type(container, C_OUTPUT); + struct sway_container *output = sway_container_parent(container, C_OUTPUT); if (container->type == C_WORKSPACE) { // Workspace coordinates are actually wrong/arbitrary, but should // be same as output. @@ -444,12 +444,12 @@ static bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out return true; } -static swayc_t *sway_output_from_wlr(struct wlr_output *output) { +static struct sway_container *sway_output_from_wlr(struct wlr_output *output) { if (output == NULL) { return NULL; } for (int i = 0; i < root_container.children->length; ++i) { - swayc_t *o = root_container.children->items[i]; + struct sway_container *o = root_container.children->items[i]; if (o->type == C_OUTPUT && o->sway_output->wlr_output == output) { return o; } @@ -457,13 +457,13 @@ static swayc_t *sway_output_from_wlr(struct wlr_output *output) { return NULL; } -static swayc_t *get_swayc_in_direction_under(swayc_t *container, - enum movement_direction dir, struct sway_seat *seat, swayc_t *limit) { +static struct sway_container *get_swayc_in_direction_under(struct sway_container *container, + enum movement_direction dir, struct sway_seat *seat, struct sway_container *limit) { if (dir == MOVE_CHILD) { return sway_seat_get_focus_inactive(seat, container); } - swayc_t *parent = container->parent; + struct sway_container *parent = container->parent; if (dir == MOVE_PARENT) { if (parent->type == C_OUTPUT) { return NULL; @@ -496,9 +496,9 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container, /* if (container->type == C_VIEW && swayc_is_fullscreen(container)) { wlr_log(L_DEBUG, "Moving from fullscreen view, skipping to output"); - container = swayc_parent_by_type(container, C_OUTPUT); + container = sway_container_parent(container, C_OUTPUT); get_layout_center_position(container, &abs_pos); - swayc_t *output = swayc_adjacent_output(container, dir, &abs_pos, true); + struct sway_container *output = swayc_adjacent_output(container, dir, &abs_pos, true); return get_swayc_in_output_direction(output, dir); } if (container->type == C_WORKSPACE && container->fullscreen) { @@ -507,7 +507,7 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container, } */ - swayc_t *wrap_candidate = NULL; + struct sway_container *wrap_candidate = NULL; while (true) { // Test if we can even make a difference here bool can_move = false; @@ -525,12 +525,12 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container, struct wlr_output *wlr_adjacent = wlr_output_layout_adjacent_output(layout, wlr_dir, container->sway_output->wlr_output, lx, ly); - swayc_t *adjacent = sway_output_from_wlr(wlr_adjacent); + struct sway_container *adjacent = sway_output_from_wlr(wlr_adjacent); if (!adjacent || adjacent == container) { return wrap_candidate; } - swayc_t *next = get_swayc_in_output_direction(adjacent, dir, seat); + struct sway_container *next = get_swayc_in_output_direction(adjacent, dir, seat); if (next == NULL) { return NULL; } @@ -587,7 +587,7 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container, } } -swayc_t *get_swayc_in_direction(swayc_t *container, struct sway_seat *seat, +struct sway_container *get_swayc_in_direction(struct sway_container *container, struct sway_seat *seat, enum movement_direction dir) { return get_swayc_in_direction_under(container, dir, seat, NULL); } diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 3da3fde6..32e82845 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -17,7 +17,7 @@ struct workspace_by_number_data { const char *name; }; -void next_name_map(swayc_t *ws, void *data) { +void next_name_map(struct sway_container *ws, void *data) { int *count = data; ++count; } @@ -37,7 +37,7 @@ char *workspace_next_name(const char *output_name) { return name; } -static bool _workspace_by_number(swayc_t *view, void *data) { +static bool _workspace_by_number(struct sway_container *view, void *data) { if (view->type != C_WORKSPACE) { return false; } @@ -46,27 +46,27 @@ static bool _workspace_by_number(swayc_t *view, void *data) { return a == wbnd->len && strncmp(view->name, wbnd->name, a) == 0; } -swayc_t *workspace_by_number(const char* name) { +struct sway_container *workspace_by_number(const char* name) { struct workspace_by_number_data wbnd = {0, "1234567890", name}; wbnd.len = strspn(name, wbnd.cset); if (wbnd.len <= 0) { return NULL; } - return swayc_by_test(&root_container, _workspace_by_number, (void *) &wbnd); + return sway_container_find(&root_container, _workspace_by_number, (void *) &wbnd); } -static bool _workspace_by_name(swayc_t *view, void *data) { +static bool _workspace_by_name(struct sway_container *view, void *data) { return (view->type == C_WORKSPACE) && (strcasecmp(view->name, (char *) data) == 0); } -swayc_t *workspace_by_name(const char *name) { +struct sway_container *workspace_by_name(const char *name) { struct sway_seat *seat = input_manager_current_seat(input_manager); - swayc_t *current_workspace = NULL, *current_output = NULL; - swayc_t *focus = sway_seat_get_focus(seat); + struct sway_container *current_workspace = NULL, *current_output = NULL; + struct sway_container *focus = sway_seat_get_focus(seat); if (focus) { - current_workspace = swayc_parent_by_type(focus, C_WORKSPACE); - current_output = swayc_parent_by_type(focus, C_OUTPUT); + current_workspace = sway_container_parent(focus, C_WORKSPACE); + current_output = sway_container_parent(focus, C_OUTPUT); } if (strcmp(name, "prev") == 0) { return workspace_prev(current_workspace); @@ -79,12 +79,12 @@ swayc_t *workspace_by_name(const char *name) { } else if (strcmp(name, "current") == 0) { return current_workspace; } else { - return swayc_by_test(&root_container, _workspace_by_name, (void *) name); + return sway_container_find(&root_container, _workspace_by_name, (void *) name); } } -swayc_t *workspace_create(const char *name) { - swayc_t *parent; +struct sway_container *workspace_create(const char *name) { + struct sway_container *parent; // Search for workspace<->output pair int i, e = config->workspace_outputs->length; for (i = 0; i < e; ++i) { @@ -95,7 +95,7 @@ swayc_t *workspace_create(const char *name) { for (i = 0; i < e; ++i) { parent = root_container.children->items[i]; if (strcmp(parent->name, wso->output) == 0) { - return new_workspace(parent, name); + return sway_container_workspace_create(parent, name); } } break; @@ -103,10 +103,10 @@ swayc_t *workspace_create(const char *name) { } // Otherwise create a new one struct sway_seat *seat = input_manager_current_seat(input_manager); - swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); + struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container); parent = focus; - parent = swayc_parent_by_type(parent, C_OUTPUT); - return new_workspace(parent, name); + parent = sway_container_parent(parent, C_OUTPUT); + return sway_container_workspace_create(parent, name); } /** @@ -114,17 +114,17 @@ swayc_t *workspace_create(const char *name) { * the end and beginning. If next is false, the previous workspace is returned, * otherwise the next one is returned. */ -swayc_t *workspace_output_prev_next_impl(swayc_t *output, bool next) { +struct sway_container *workspace_output_prev_next_impl(struct sway_container *output, bool next) { if (!sway_assert(output->type == C_OUTPUT, "Argument must be an output, is %d", output->type)) { return NULL; } struct sway_seat *seat = input_manager_current_seat(input_manager); - swayc_t *focus = sway_seat_get_focus_inactive(seat, output); - swayc_t *workspace = (focus->type == C_WORKSPACE ? + struct sway_container *focus = sway_seat_get_focus_inactive(seat, output); + struct sway_container *workspace = (focus->type == C_WORKSPACE ? focus : - swayc_parent_by_type(focus, C_WORKSPACE)); + sway_container_parent(focus, C_WORKSPACE)); int i; for (i = 0; i < output->children->length; i++) { @@ -144,13 +144,13 @@ swayc_t *workspace_output_prev_next_impl(swayc_t *output, bool next) { * next is false, the previous workspace is returned, otherwise the next one is * returned. */ -swayc_t *workspace_prev_next_impl(swayc_t *workspace, bool next) { +struct sway_container *workspace_prev_next_impl(struct sway_container *workspace, bool next) { if (!sway_assert(workspace->type == C_WORKSPACE, "Argument must be a workspace, is %d", workspace->type)) { return NULL; } - swayc_t *current_output = workspace->parent; + struct sway_container *current_output = workspace->parent; int offset = next ? 1 : -1; int start = next ? 0 : 1; int end; @@ -170,7 +170,7 @@ swayc_t *workspace_prev_next_impl(swayc_t *workspace, bool next) { int num_outputs = root_container.children->length; for (i = 0; i < num_outputs; i++) { if (root_container.children->items[i] == current_output) { - swayc_t *next_output = root_container.children->items[ + struct sway_container *next_output = root_container.children->items[ wrap(i + offset, num_outputs)]; return workspace_output_prev_next_impl(next_output, next); } @@ -180,40 +180,40 @@ swayc_t *workspace_prev_next_impl(swayc_t *workspace, bool next) { return NULL; } -swayc_t *workspace_output_next(swayc_t *current) { +struct sway_container *workspace_output_next(struct sway_container *current) { return workspace_output_prev_next_impl(current, true); } -swayc_t *workspace_next(swayc_t *current) { +struct sway_container *workspace_next(struct sway_container *current) { return workspace_prev_next_impl(current, true); } -swayc_t *workspace_output_prev(swayc_t *current) { +struct sway_container *workspace_output_prev(struct sway_container *current) { return workspace_output_prev_next_impl(current, false); } -swayc_t *workspace_prev(swayc_t *current) { +struct sway_container *workspace_prev(struct sway_container *current) { return workspace_prev_next_impl(current, false); } -bool workspace_switch(swayc_t *workspace) { +bool workspace_switch(struct sway_container *workspace) { if (!workspace) { return false; } struct sway_seat *seat = input_manager_current_seat(input_manager); - swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); + struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container); if (!seat || !focus) { return false; } - swayc_t *active_ws = focus; + struct sway_container *active_ws = focus; if (active_ws->type != C_WORKSPACE) { - swayc_parent_by_type(focus, C_WORKSPACE); + sway_container_parent(focus, C_WORKSPACE); } if (config->auto_back_and_forth && active_ws == workspace && prev_workspace_name) { - swayc_t *new_ws = workspace_by_name(prev_workspace_name); + struct sway_container *new_ws = workspace_by_name(prev_workspace_name); workspace = new_ws ? new_ws : workspace_create(prev_workspace_name); } @@ -231,12 +231,12 @@ bool workspace_switch(swayc_t *workspace) { // TODO: Deal with sticky containers wlr_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name); - swayc_t *next = sway_seat_get_focus_inactive(seat, workspace); + struct sway_container *next = sway_seat_get_focus_inactive(seat, workspace); if (next == NULL) { next = workspace; } sway_seat_set_focus(seat, next); - swayc_t *output = swayc_parent_by_type(workspace, C_OUTPUT); + struct sway_container *output = sway_container_parent(workspace, C_OUTPUT); arrange_windows(output, -1, -1); return true; } diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 93d1219c..f9df0d10 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c @@ -352,7 +352,7 @@ void ipc_bar_init(struct bar *bar, const char *bar_id) { } // add bar to the output - struct output *bar_output = new_output(name); + struct output *bar_output = sway_container_output_create(name); bar_output->idx = i; list_add(bar->outputs, bar_output); } -- cgit v1.2.3 From eca029f218fbb54ddf7316845be5d296e834358e Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 29 Mar 2018 17:06:29 -0400 Subject: more renaming things --- include/sway/tree/container.h | 21 +++++++--------- include/sway/tree/layout.h | 16 ++++++------ sway/commands/layout.c | 16 ++++++------ sway/commands/reload.c | 2 +- sway/commands/workspace.c | 6 ++--- sway/config/output.c | 2 +- sway/desktop/layer_shell.c | 2 +- sway/desktop/output.c | 12 ++++----- sway/desktop/wl_shell.c | 8 +++--- sway/desktop/xdg_shell_v6.c | 8 +++--- sway/desktop/xwayland.c | 22 ++++++++-------- sway/input/seat.c | 2 +- sway/tree/container.c | 58 +++++++++++++++++++++---------------------- sway/tree/layout.c | 34 ++++++++++++------------- sway/tree/workspace.c | 22 ++++++++-------- swaybar/ipc.c | 2 +- 16 files changed, 115 insertions(+), 118 deletions(-) (limited to 'include/sway/tree/layout.h') diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 0dfed455..572dd8e3 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -88,41 +88,38 @@ struct sway_container { }; // TODO only one container create function and pass the type? -struct sway_container *sway_container_output_create( +struct sway_container *container_output_create( struct sway_output *sway_output); -struct sway_container *sway_container_workspace_create( +struct sway_container *container_workspace_create( struct sway_container *output, const char *name); -struct sway_container *sway_container_view_create( +struct sway_container *container_view_create( struct sway_container *sibling, struct sway_view *sway_view); -struct sway_container *sway_container_output_destroy( +struct sway_container *container_output_destroy( struct sway_container *output); -struct sway_container *sway_container_view_destroy(struct sway_container *view); +struct sway_container *container_view_destroy(struct sway_container *view); -struct sway_container *sway_container_set_layout( +struct sway_container *container_set_layout( struct sway_container *container, enum sway_container_layout layout); -void sway_container_descendents(struct sway_container *root, +void container_descendents(struct sway_container *root, enum sway_container_type type, void (*func)(struct sway_container *item, void *data), void *data); -// XXX: what is this? -struct sway_container *next_view_sibling(struct sway_seat *seat); - /** * Finds a container based on test criteria. Returns the first container that * passes the test. */ -struct sway_container *sway_container_find(struct sway_container *container, +struct sway_container *container_find(struct sway_container *container, bool (*test)(struct sway_container *view, void *data), void *data); /** * Finds a parent container with the given struct sway_containerype. */ -struct sway_container *sway_container_parent(struct sway_container *container, +struct sway_container *container_parent(struct sway_container *container, enum sway_container_type type); /** diff --git a/include/sway/tree/layout.h b/include/sway/tree/layout.h index f73b3880..6980ec9e 100644 --- a/include/sway/tree/layout.h +++ b/include/sway/tree/layout.h @@ -30,23 +30,23 @@ struct sway_root { } events; }; -void init_layout(void); +void layout_init(void); -void add_child(struct sway_container *parent, struct sway_container *child); +void container_add_child(struct sway_container *parent, struct sway_container *child); -struct sway_container *add_sibling(struct sway_container *parent, +struct sway_container *container_add_sibling(struct sway_container *parent, struct sway_container *child); -struct sway_container *remove_child(struct sway_container *child); +struct sway_container *container_remove_child(struct sway_container *child); -enum sway_container_layout default_layout(struct sway_container *output); +enum sway_container_layout container_get_default_layout(struct sway_container *output); -void sort_workspaces(struct sway_container *output); +void container_sort_workspaces(struct sway_container *output); -void arrange_windows(struct sway_container *container, +void container_arrange_windows(struct sway_container *container, double width, double height); -struct sway_container *get_swayc_in_direction(struct sway_container +struct sway_container *container_get_in_direction(struct sway_container *container, struct sway_seat *seat, enum movement_direction dir); #endif diff --git a/sway/commands/layout.c b/sway/commands/layout.c index e10334e2..e9cfeb8f 100644 --- a/sway/commands/layout.c +++ b/sway/commands/layout.c @@ -26,10 +26,10 @@ struct cmd_results *cmd_layout(int argc, char **argv) { // TODO: stacks and tabs if (strcasecmp(argv[0], "default") == 0) { - swayc_change_layout(parent, parent->prev_layout); + container_set_layout(parent, parent->prev_layout); if (parent->layout == L_NONE) { - struct sway_container *output = sway_container_parent(parent, C_OUTPUT); - swayc_change_layout(parent, default_layout(output)); + struct sway_container *output = container_parent(parent, C_OUTPUT); + container_set_layout(parent, container_get_default_layout(output)); } } else { if (parent->layout != L_TABBED && parent->layout != L_STACKED) { @@ -37,20 +37,20 @@ struct cmd_results *cmd_layout(int argc, char **argv) { } if (strcasecmp(argv[0], "splith") == 0) { - swayc_change_layout(parent, L_HORIZ); + container_set_layout(parent, L_HORIZ); } else if (strcasecmp(argv[0], "splitv") == 0) { - swayc_change_layout(parent, L_VERT); + container_set_layout(parent, L_VERT); } else if (strcasecmp(argv[0], "toggle") == 0 && argc == 2 && strcasecmp(argv[1], "split") == 0) { if (parent->layout == L_HORIZ && (parent->workspace_layout == L_NONE || parent->workspace_layout == L_HORIZ)) { - swayc_change_layout(parent, L_VERT); + container_set_layout(parent, L_VERT); } else { - swayc_change_layout(parent, L_HORIZ); + container_set_layout(parent, L_HORIZ); } } } - arrange_windows(parent, parent->width, parent->height); + container_arrange_windows(parent, parent->width, parent->height); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/reload.c b/sway/commands/reload.c index 8cef789b..83ecd75b 100644 --- a/sway/commands/reload.c +++ b/sway/commands/reload.c @@ -13,6 +13,6 @@ struct cmd_results *cmd_reload(int argc, char **argv) { /* load_swaybars(); -- for when it's implemented */ - arrange_windows(&root_container, -1, -1); + container_arrange_windows(&root_container, -1, -1); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c index 8b7139a9..8f39e5fc 100644 --- a/sway/commands/workspace.c +++ b/sway/commands/workspace.c @@ -23,9 +23,9 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { if (current_container->type == C_WORKSPACE) { old_workspace = current_container; } else { - old_workspace = sway_container_parent(current_container, C_WORKSPACE); + old_workspace = container_parent(current_container, C_WORKSPACE); } - old_output = sway_container_parent(current_container, C_OUTPUT); + old_output = container_parent(current_container, C_OUTPUT); } for (int i = 0; i < argc; ++i) { @@ -92,7 +92,7 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { workspace_switch(ws); current_container = sway_seat_get_focus(config->handler_context.seat); - struct sway_container *new_output = sway_container_parent(current_container, C_OUTPUT); + struct sway_container *new_output = container_parent(current_container, C_OUTPUT); if (config->mouse_warping && old_output != new_output) { // TODO: Warp mouse diff --git a/sway/config/output.c b/sway/config/output.c index 5763bd21..7fc79739 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -127,7 +127,7 @@ void apply_output_config(struct output_config *oc, struct sway_container *output if (oc && oc->enabled == 0) { wlr_output_layout_remove(root_container.sway_root->output_layout, wlr_output); - sway_container_output_destroy(output); + container_output_destroy(output); return; } diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c index 137b3260..4bfd1c45 100644 --- a/sway/desktop/layer_shell.c +++ b/sway/desktop/layer_shell.c @@ -172,7 +172,7 @@ void arrange_layers(struct sway_output *output) { if (memcmp(&usable_area_before, &usable_area, sizeof(struct wlr_box)) != 0) { wlr_log(L_DEBUG, "arrange"); - arrange_windows(output->swayc, -1, -1); + container_arrange_windows(output->swayc, -1, -1); } // Arrange non-exlusive surfaces from top->bottom diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 3e7d8509..fa1b0680 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -221,13 +221,13 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { struct sway_container *focus = sway_seat_get_focus_inactive(seat, soutput->swayc); struct sway_container *workspace = (focus->type == C_WORKSPACE ? focus : - sway_container_parent(focus, C_WORKSPACE)); + container_parent(focus, C_WORKSPACE)); struct render_data rdata = { .output = soutput, .now = &now, }; - sway_container_descendents(workspace, C_VIEW, output_frame_view, &rdata); + container_descendents(workspace, C_VIEW, output_frame_view, &rdata); // render unmanaged views on top struct sway_view *view; @@ -258,13 +258,13 @@ static void handle_output_destroy(struct wl_listener *listener, void *data) { struct wlr_output *wlr_output = data; wlr_log(L_DEBUG, "Output %p %s removed", wlr_output, wlr_output->name); - sway_container_output_destroy(output->swayc); + container_output_destroy(output->swayc); } static void handle_output_mode(struct wl_listener *listener, void *data) { struct sway_output *output = wl_container_of(listener, output, mode); arrange_layers(output); - arrange_windows(output->swayc, -1, -1); + container_arrange_windows(output->swayc, -1, -1); } void handle_new_output(struct wl_listener *listener, void *data) { @@ -286,7 +286,7 @@ void handle_new_output(struct wl_listener *listener, void *data) { wlr_output_set_mode(wlr_output, mode); } - output->swayc = sway_container_output_create(output); + output->swayc = container_output_create(output); if (!output->swayc) { free(output); return; @@ -307,5 +307,5 @@ void handle_new_output(struct wl_listener *listener, void *data) { output->mode.notify = handle_output_mode; arrange_layers(output); - arrange_windows(&root_container, -1, -1); + container_arrange_windows(&root_container, -1, -1); } diff --git a/sway/desktop/wl_shell.c b/sway/desktop/wl_shell.c index bf41d7bf..ac1c7f26 100644 --- a/sway/desktop/wl_shell.c +++ b/sway/desktop/wl_shell.c @@ -74,10 +74,10 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_container_of(listener, sway_surface, destroy); wl_list_remove(&sway_surface->commit.link); wl_list_remove(&sway_surface->destroy.link); - struct sway_container *parent = sway_container_view_destroy(sway_surface->view->swayc); + struct sway_container *parent = container_view_destroy(sway_surface->view->swayc); free(sway_surface->view); free(sway_surface); - arrange_windows(parent, -1, -1); + container_arrange_windows(parent, -1, -1); } void handle_wl_shell_surface(struct wl_listener *listener, void *data) { @@ -133,9 +133,9 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container); - struct sway_container *cont = sway_container_view_create(focus, sway_view); + struct sway_container *cont = container_view_create(focus, sway_view); sway_view->swayc = cont; - arrange_windows(cont->parent, -1, -1); + container_arrange_windows(cont->parent, -1, -1); sway_input_manager_set_focus(input_manager, cont); } diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 6b50d470..616cb88f 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -83,10 +83,10 @@ static void handle_destroy(struct wl_listener *listener, void *data) { wl_container_of(listener, sway_xdg_surface, destroy); wl_list_remove(&sway_xdg_surface->commit.link); wl_list_remove(&sway_xdg_surface->destroy.link); - struct sway_container *parent = sway_container_view_destroy(sway_xdg_surface->view->swayc); + struct sway_container *parent = container_view_destroy(sway_xdg_surface->view->swayc); free(sway_xdg_surface->view); free(sway_xdg_surface); - arrange_windows(parent, -1, -1); + container_arrange_windows(parent, -1, -1); } void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { @@ -137,10 +137,10 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container); - struct sway_container *cont = sway_container_view_create(focus, sway_view); + struct sway_container *cont = container_view_create(focus, sway_view); sway_view->swayc = cont; - arrange_windows(cont->parent, -1, -1); + container_arrange_windows(cont->parent, -1, -1); sway_input_manager_set_focus(input_manager, cont); } diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 96edab51..fa1054f2 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -49,11 +49,11 @@ static void set_position(struct sway_view *view, double ox, double oy) { if (!assert_xwayland(view)) { return; } - struct sway_container *output = sway_container_parent(view->swayc, C_OUTPUT); + struct sway_container *output = container_parent(view->swayc, C_OUTPUT); if (!sway_assert(output, "view must be within tree to set position")) { return; } - struct sway_container *root = sway_container_parent(output, C_ROOT); + struct sway_container *root = container_parent(output, C_ROOT); if (!sway_assert(root, "output must be within tree to set position")) { return; } @@ -114,9 +114,9 @@ static void handle_destroy(struct wl_listener *listener, void *data) { } } - struct sway_container *parent = sway_container_view_destroy(sway_surface->view->swayc); + struct sway_container *parent = container_view_destroy(sway_surface->view->swayc); if (parent) { - arrange_windows(parent, -1, -1); + container_arrange_windows(parent, -1, -1); } free(sway_surface->view); @@ -132,9 +132,9 @@ static void handle_unmap_notify(struct wl_listener *listener, void *data) { } // take it out of the tree - struct sway_container *parent = sway_container_view_destroy(sway_surface->view->swayc); + struct sway_container *parent = container_view_destroy(sway_surface->view->swayc); if (parent) { - arrange_windows(parent, -1, -1); + container_arrange_windows(parent, -1, -1); } sway_surface->view->swayc = NULL; @@ -155,15 +155,15 @@ static void handle_map_notify(struct wl_listener *listener, void *data) { &sway_surface->view->unmanaged_view_link); } else { struct sway_view *view = sway_surface->view; - sway_container_view_destroy(view->swayc); + container_view_destroy(view->swayc); struct sway_container *parent = root_container.children->items[0]; parent = parent->children->items[0]; // workspace - struct sway_container *cont = sway_container_view_create(parent, view); + struct sway_container *cont = container_view_create(parent, view); view->swayc = cont; - arrange_windows(cont->parent, -1, -1); + container_arrange_windows(cont->parent, -1, -1); sway_input_manager_set_focus(input_manager, cont); } } @@ -239,9 +239,9 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container); - struct sway_container *cont = sway_container_view_create(focus, sway_view); + struct sway_container *cont = container_view_create(focus, sway_view); sway_view->swayc = cont; - arrange_windows(cont->parent, -1, -1); + container_arrange_windows(cont->parent, -1, -1); sway_input_manager_set_focus(input_manager, cont); } diff --git a/sway/input/seat.c b/sway/input/seat.c index f03a03b4..8e2189de 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -365,7 +365,7 @@ struct sway_container *sway_seat_get_focus_by_type(struct sway_seat *seat, return focus; } - return sway_container_parent(focus, type); + return container_parent(focus, type); } void sway_seat_set_config(struct sway_seat *seat, diff --git a/sway/tree/container.c b/sway/tree/container.c index d31966b3..b41626e1 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -67,7 +67,7 @@ static void free_swayc(struct sway_container *cont) { if (cont->children) { // remove children until there are no more, free_swayc calls - // remove_child, which removes child from this container + // container_remove_child, which removes child from this container while (cont->children->length) { free_swayc(cont->children->items[0]); } @@ -78,7 +78,7 @@ static void free_swayc(struct sway_container *cont) { list_free(cont->marks); } if (cont->parent) { - remove_child(cont); + container_remove_child(cont); } if (cont->name) { free(cont->name); @@ -86,7 +86,7 @@ static void free_swayc(struct sway_container *cont) { free(cont); } -struct sway_container *sway_container_output_create(struct sway_output *sway_output) { +struct sway_container *container_output_create(struct sway_output *sway_output) { struct wlr_box size; wlr_output_effective_resolution(sway_output->wlr_output, &size.width, &size.height); @@ -131,12 +131,12 @@ struct sway_container *sway_container_output_create(struct sway_output *sway_out apply_output_config(oc, output); - add_child(&root_container, output); + container_add_child(&root_container, output); // Create workspace char *ws_name = workspace_next_name(output->name); wlr_log(L_DEBUG, "Creating default workspace %s", ws_name); - struct sway_container *ws = sway_container_workspace_create(output, ws_name); + struct sway_container *ws = container_workspace_create(output, ws_name); // Set each seat's focus if not already set struct sway_seat *seat = NULL; wl_list_for_each(seat, &input_manager->seats, link) { @@ -150,8 +150,8 @@ struct sway_container *sway_container_output_create(struct sway_output *sway_out return output; } -struct sway_container *sway_container_workspace_create(struct sway_container *output, const char *name) { - if (!sway_assert(output, "sway_container_workspace_create called with null output")) { +struct sway_container *container_workspace_create(struct sway_container *output, const char *name) { + if (!sway_assert(output, "container_workspace_create called with null output")) { return NULL; } wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name); @@ -163,17 +163,17 @@ struct sway_container *sway_container_workspace_create(struct sway_container *ou workspace->height = output->height; workspace->name = !name ? NULL : strdup(name); workspace->prev_layout = L_NONE; - workspace->layout = default_layout(output); - workspace->workspace_layout = default_layout(output); + workspace->layout = container_get_default_layout(output); + workspace->workspace_layout = container_get_default_layout(output); - add_child(output, workspace); - sort_workspaces(output); + container_add_child(output, workspace); + container_sort_workspaces(output); notify_new_container(workspace); return workspace; } -struct sway_container *sway_container_view_create(struct sway_container *sibling, struct sway_view *sway_view) { - if (!sway_assert(sibling, "sway_container_view_create called with NULL sibling/parent")) { +struct sway_container *container_view_create(struct sway_container *sibling, struct sway_view *sway_view) { + if (!sway_assert(sibling, "container_view_create called with NULL sibling/parent")) { return NULL; } const char *title = view_get_title(sway_view); @@ -188,17 +188,17 @@ struct sway_container *sway_container_view_create(struct sway_container *sibling if (sibling->type == C_WORKSPACE) { // Case of focused workspace, just create as child of it - add_child(sibling, swayc); + container_add_child(sibling, swayc); } else { // Regular case, create as sibling of current container - add_sibling(sibling, swayc); + container_add_sibling(sibling, swayc); } notify_new_container(swayc); return swayc; } -struct sway_container *sway_container_output_destroy(struct sway_container *output) { - if (!sway_assert(output, "null output passed to sway_container_output_destroy")) { +struct sway_container *container_output_destroy(struct sway_container *output) { + if (!sway_assert(output, "null output passed to container_output_destroy")) { return NULL; } @@ -211,11 +211,11 @@ struct sway_container *sway_container_output_destroy(struct sway_container *outp // Move workspace from this output to another output while (output->children->length) { struct sway_container *child = output->children->items[0]; - remove_child(child); - add_child(root_container.children->items[p], child); + container_remove_child(child); + container_add_child(root_container.children->items[p], child); } - sort_workspaces(root_container.children->items[p]); - arrange_windows(root_container.children->items[p], -1, -1); + container_sort_workspaces(root_container.children->items[p]); + container_arrange_windows(root_container.children->items[p], -1, -1); } } @@ -229,7 +229,7 @@ struct sway_container *sway_container_output_destroy(struct sway_container *outp return &root_container; } -struct sway_container *sway_container_view_destroy(struct sway_container *view) { +struct sway_container *container_view_destroy(struct sway_container *view) { if (!view) { return NULL; } @@ -246,7 +246,7 @@ struct sway_container *sway_container_view_destroy(struct sway_container *view) return parent; } -struct sway_container *swayc_change_layout(struct sway_container *container, enum sway_container_layout layout) { +struct sway_container *container_set_layout(struct sway_container *container, enum sway_container_layout layout) { if (container->type == C_WORKSPACE) { container->workspace_layout = layout; if (layout == L_HORIZ || layout == L_VERT) { @@ -258,7 +258,7 @@ struct sway_container *swayc_change_layout(struct sway_container *container, enu return container; } -void sway_container_descendents(struct sway_container *root, enum sway_container_type type, +void container_descendents(struct sway_container *root, enum sway_container_type type, void (*func)(struct sway_container *item, void *data), void *data) { for (int i = 0; i < root->children->length; ++i) { struct sway_container *item = root->children->items[i]; @@ -266,12 +266,12 @@ void sway_container_descendents(struct sway_container *root, enum sway_container func(item, data); } if (item->children && item->children->length) { - sway_container_descendents(item, type, func, data); + container_descendents(item, type, func, data); } } } -struct sway_container *sway_container_find(struct sway_container *container, +struct sway_container *container_find(struct sway_container *container, bool (*test)(struct sway_container *view, void *data), void *data) { if (!container->children) { return NULL; @@ -282,7 +282,7 @@ struct sway_container *sway_container_find(struct sway_container *container, if (test(child, data)) { return child; } else { - struct sway_container *res = sway_container_find(child, test, data); + struct sway_container *res = container_find(child, test, data); if (res) { return res; } @@ -291,7 +291,7 @@ struct sway_container *sway_container_find(struct sway_container *container, return NULL; } -struct sway_container *sway_container_parent(struct sway_container *container, enum sway_container_type type) { +struct sway_container *container_parent(struct sway_container *container, enum sway_container_type type) { if (!sway_assert(container, "container is NULL")) { return NULL; } @@ -341,7 +341,7 @@ struct sway_container *sway_container_at(struct sway_container *parent, double l list_del(queue, 0); if (swayc->type == C_VIEW) { struct sway_view *sview = swayc->sway_view; - struct sway_container *soutput = sway_container_parent(swayc, C_OUTPUT); + struct sway_container *soutput = container_parent(swayc, C_OUTPUT); struct wlr_box *output_box = wlr_output_layout_get_box( root_container.sway_root->output_layout, diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 068fb39c..07534620 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -40,7 +40,7 @@ static void output_layout_change_notify(struct wl_listener *listener, void *data output_container->height = output_box->height; } - arrange_windows(&root_container, -1, -1); + container_arrange_windows(&root_container, -1, -1); } void init_layout(void) { @@ -79,7 +79,7 @@ static int index_child(const struct sway_container *child) { return i; } -struct sway_container *add_sibling(struct sway_container *fixed, struct sway_container *active) { +struct sway_container *container_add_sibling(struct sway_container *fixed, struct sway_container *active) { // TODO handle floating struct sway_container *parent = fixed->parent; int i = index_child(fixed); @@ -88,7 +88,7 @@ struct sway_container *add_sibling(struct sway_container *fixed, struct sway_con return active->parent; } -void add_child(struct sway_container *parent, struct sway_container *child) { +void container_add_child(struct sway_container *parent, struct sway_container *child) { wlr_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", child, child->type, child->width, child->height, parent, parent->type, parent->width, parent->height); @@ -102,7 +102,7 @@ void add_child(struct sway_container *parent, struct sway_container *child) { */ } -struct sway_container *remove_child(struct sway_container *child) { +struct sway_container *container_remove_child(struct sway_container *child) { int i; struct sway_container *parent = child->parent; for (i = 0; i < parent->children->length; ++i) { @@ -115,7 +115,7 @@ struct sway_container *remove_child(struct sway_container *child) { return parent; } -enum sway_container_layout default_layout(struct sway_container *output) { +enum sway_container_layout container_get_default_layout(struct sway_container *output) { /* TODO WLR if (config->default_layout != L_NONE) { //return config->default_layout; @@ -146,7 +146,7 @@ static int sort_workspace_cmp_qsort(const void *_a, const void *_b) { return retval; } -void sort_workspaces(struct sway_container *output) { +void container_sort_workspaces(struct sway_container *output) { list_stable_sort(output->children, sort_workspace_cmp_qsort); } @@ -160,7 +160,7 @@ static void apply_vert_layout(struct sway_container *container, const double x, const double height, const int start, const int end); -void arrange_windows(struct sway_container *container, double width, double height) { +void container_arrange_windows(struct sway_container *container, double width, double height) { int i; if (width == -1 || height == -1) { width = container->width; @@ -184,7 +184,7 @@ void arrange_windows(struct sway_container *container, double width, double heig struct sway_container *output = container->children->items[i]; wlr_log(L_DEBUG, "Arranging output '%s' at %f,%f", output->name, output->x, output->y); - arrange_windows(output, -1, -1); + container_arrange_windows(output, -1, -1); } return; case C_OUTPUT: @@ -198,12 +198,12 @@ void arrange_windows(struct sway_container *container, double width, double heig // arrange all workspaces: for (i = 0; i < container->children->length; ++i) { struct sway_container *child = container->children->items[i]; - arrange_windows(child, -1, -1); + container_arrange_windows(child, -1, -1); } return; case C_WORKSPACE: { - struct sway_container *output = sway_container_parent(container, C_OUTPUT); + struct sway_container *output = container_parent(container, C_OUTPUT); struct wlr_box *area = &output->sway_output->usable_area; wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d", area->width, area->height, area->x, area->y); @@ -284,9 +284,9 @@ static void apply_horiz_layout(struct sway_container *container, if (i == end - 1) { double remaining_width = x + width - child_x; - arrange_windows(child, remaining_width, height); + container_arrange_windows(child, remaining_width, height); } else { - arrange_windows(child, child->width * scale, height); + container_arrange_windows(child, child->width * scale, height); } child_x += child->width; } @@ -334,9 +334,9 @@ void apply_vert_layout(struct sway_container *container, if (i == end - 1) { double remaining_height = y + height - child_y; - arrange_windows(child, width, remaining_height); + container_arrange_windows(child, width, remaining_height); } else { - arrange_windows(child, width, child->height * scale); + container_arrange_windows(child, width, child->height * scale); } child_y += child->height; } @@ -362,7 +362,7 @@ static struct sway_container *get_swayc_in_output_direction(struct sway_containe struct sway_container *ws = sway_seat_get_focus_inactive(seat, output); if (ws->type != C_WORKSPACE) { - ws = sway_container_parent(ws, C_WORKSPACE); + ws = container_parent(ws, C_WORKSPACE); } if (ws == NULL) { @@ -410,7 +410,7 @@ static void get_layout_center_position(struct sway_container *container, int *x, *x = container->x + container->width/2; *y = container->y + container->height/2; } else { - struct sway_container *output = sway_container_parent(container, C_OUTPUT); + struct sway_container *output = container_parent(container, C_OUTPUT); if (container->type == C_WORKSPACE) { // Workspace coordinates are actually wrong/arbitrary, but should // be same as output. @@ -496,7 +496,7 @@ static struct sway_container *get_swayc_in_direction_under(struct sway_container /* if (container->type == C_VIEW && swayc_is_fullscreen(container)) { wlr_log(L_DEBUG, "Moving from fullscreen view, skipping to output"); - container = sway_container_parent(container, C_OUTPUT); + container = container_parent(container, C_OUTPUT); get_layout_center_position(container, &abs_pos); struct sway_container *output = swayc_adjacent_output(container, dir, &abs_pos, true); return get_swayc_in_output_direction(output, dir); diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 32e82845..0fdd9975 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -52,7 +52,7 @@ struct sway_container *workspace_by_number(const char* name) { if (wbnd.len <= 0) { return NULL; } - return sway_container_find(&root_container, _workspace_by_number, (void *) &wbnd); + return container_find(&root_container, _workspace_by_number, (void *) &wbnd); } static bool _workspace_by_name(struct sway_container *view, void *data) { @@ -65,8 +65,8 @@ struct sway_container *workspace_by_name(const char *name) { struct sway_container *current_workspace = NULL, *current_output = NULL; struct sway_container *focus = sway_seat_get_focus(seat); if (focus) { - current_workspace = sway_container_parent(focus, C_WORKSPACE); - current_output = sway_container_parent(focus, C_OUTPUT); + current_workspace = container_parent(focus, C_WORKSPACE); + current_output = container_parent(focus, C_OUTPUT); } if (strcmp(name, "prev") == 0) { return workspace_prev(current_workspace); @@ -79,7 +79,7 @@ struct sway_container *workspace_by_name(const char *name) { } else if (strcmp(name, "current") == 0) { return current_workspace; } else { - return sway_container_find(&root_container, _workspace_by_name, (void *) name); + return container_find(&root_container, _workspace_by_name, (void *) name); } } @@ -95,7 +95,7 @@ struct sway_container *workspace_create(const char *name) { for (i = 0; i < e; ++i) { parent = root_container.children->items[i]; if (strcmp(parent->name, wso->output) == 0) { - return sway_container_workspace_create(parent, name); + return container_workspace_create(parent, name); } } break; @@ -105,8 +105,8 @@ struct sway_container *workspace_create(const char *name) { struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container); parent = focus; - parent = sway_container_parent(parent, C_OUTPUT); - return sway_container_workspace_create(parent, name); + parent = container_parent(parent, C_OUTPUT); + return container_workspace_create(parent, name); } /** @@ -124,7 +124,7 @@ struct sway_container *workspace_output_prev_next_impl(struct sway_container *ou struct sway_container *focus = sway_seat_get_focus_inactive(seat, output); struct sway_container *workspace = (focus->type == C_WORKSPACE ? focus : - sway_container_parent(focus, C_WORKSPACE)); + container_parent(focus, C_WORKSPACE)); int i; for (i = 0; i < output->children->length; i++) { @@ -207,7 +207,7 @@ bool workspace_switch(struct sway_container *workspace) { } struct sway_container *active_ws = focus; if (active_ws->type != C_WORKSPACE) { - sway_container_parent(focus, C_WORKSPACE); + container_parent(focus, C_WORKSPACE); } if (config->auto_back_and_forth @@ -236,7 +236,7 @@ bool workspace_switch(struct sway_container *workspace) { next = workspace; } sway_seat_set_focus(seat, next); - struct sway_container *output = sway_container_parent(workspace, C_OUTPUT); - arrange_windows(output, -1, -1); + struct sway_container *output = container_parent(workspace, C_OUTPUT); + container_arrange_windows(output, -1, -1); return true; } diff --git a/swaybar/ipc.c b/swaybar/ipc.c index f9df0d10..2d2b3b69 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c @@ -352,7 +352,7 @@ void ipc_bar_init(struct bar *bar, const char *bar_id) { } // add bar to the output - struct output *bar_output = sway_container_output_create(name); + struct output *bar_output = container_output_create(name); bar_output->idx = i; list_add(bar->outputs, bar_output); } -- cgit v1.2.3 From 2778edef976a669dd0019ebb5327bcfeb4de13c5 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 29 Mar 2018 23:15:39 -0400 Subject: arrange windows --- include/sway/tree/layout.h | 2 +- sway/commands/layout.c | 2 +- sway/commands/reload.c | 2 +- sway/desktop/layer_shell.c | 2 +- sway/desktop/output.c | 4 ++-- sway/desktop/wl_shell.c | 4 ++-- sway/desktop/xdg_shell_v6.c | 4 ++-- sway/desktop/xwayland.c | 8 ++++---- sway/tree/container.c | 2 +- sway/tree/layout.c | 16 ++++++++-------- sway/tree/workspace.c | 2 +- 11 files changed, 24 insertions(+), 24 deletions(-) (limited to 'include/sway/tree/layout.h') diff --git a/include/sway/tree/layout.h b/include/sway/tree/layout.h index 6980ec9e..ad52bdb0 100644 --- a/include/sway/tree/layout.h +++ b/include/sway/tree/layout.h @@ -43,7 +43,7 @@ enum sway_container_layout container_get_default_layout(struct sway_container *o void container_sort_workspaces(struct sway_container *output); -void container_arrange_windows(struct sway_container *container, +void arrange_windows(struct sway_container *container, double width, double height); struct sway_container *container_get_in_direction(struct sway_container diff --git a/sway/commands/layout.c b/sway/commands/layout.c index e9cfeb8f..ebab2a48 100644 --- a/sway/commands/layout.c +++ b/sway/commands/layout.c @@ -50,7 +50,7 @@ struct cmd_results *cmd_layout(int argc, char **argv) { } } - container_arrange_windows(parent, parent->width, parent->height); + arrange_windows(parent, parent->width, parent->height); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/reload.c b/sway/commands/reload.c index 83ecd75b..8cef789b 100644 --- a/sway/commands/reload.c +++ b/sway/commands/reload.c @@ -13,6 +13,6 @@ struct cmd_results *cmd_reload(int argc, char **argv) { /* load_swaybars(); -- for when it's implemented */ - container_arrange_windows(&root_container, -1, -1); + arrange_windows(&root_container, -1, -1); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c index 4bfd1c45..137b3260 100644 --- a/sway/desktop/layer_shell.c +++ b/sway/desktop/layer_shell.c @@ -172,7 +172,7 @@ void arrange_layers(struct sway_output *output) { if (memcmp(&usable_area_before, &usable_area, sizeof(struct wlr_box)) != 0) { wlr_log(L_DEBUG, "arrange"); - container_arrange_windows(output->swayc, -1, -1); + arrange_windows(output->swayc, -1, -1); } // Arrange non-exlusive surfaces from top->bottom diff --git a/sway/desktop/output.c b/sway/desktop/output.c index fa1b0680..b463dfdc 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -264,7 +264,7 @@ static void handle_output_destroy(struct wl_listener *listener, void *data) { static void handle_output_mode(struct wl_listener *listener, void *data) { struct sway_output *output = wl_container_of(listener, output, mode); arrange_layers(output); - container_arrange_windows(output->swayc, -1, -1); + arrange_windows(output->swayc, -1, -1); } void handle_new_output(struct wl_listener *listener, void *data) { @@ -307,5 +307,5 @@ void handle_new_output(struct wl_listener *listener, void *data) { output->mode.notify = handle_output_mode; arrange_layers(output); - container_arrange_windows(&root_container, -1, -1); + arrange_windows(&root_container, -1, -1); } diff --git a/sway/desktop/wl_shell.c b/sway/desktop/wl_shell.c index ac1c7f26..4d4d1ed7 100644 --- a/sway/desktop/wl_shell.c +++ b/sway/desktop/wl_shell.c @@ -77,7 +77,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { struct sway_container *parent = container_view_destroy(sway_surface->view->swayc); free(sway_surface->view); free(sway_surface); - container_arrange_windows(parent, -1, -1); + arrange_windows(parent, -1, -1); } void handle_wl_shell_surface(struct wl_listener *listener, void *data) { @@ -136,6 +136,6 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { struct sway_container *cont = container_view_create(focus, sway_view); sway_view->swayc = cont; - container_arrange_windows(cont->parent, -1, -1); + arrange_windows(cont->parent, -1, -1); sway_input_manager_set_focus(input_manager, cont); } diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 616cb88f..09894f0e 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -86,7 +86,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { struct sway_container *parent = container_view_destroy(sway_xdg_surface->view->swayc); free(sway_xdg_surface->view); free(sway_xdg_surface); - container_arrange_windows(parent, -1, -1); + arrange_windows(parent, -1, -1); } void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { @@ -140,7 +140,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { struct sway_container *cont = container_view_create(focus, sway_view); sway_view->swayc = cont; - container_arrange_windows(cont->parent, -1, -1); + arrange_windows(cont->parent, -1, -1); sway_input_manager_set_focus(input_manager, cont); } diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index fa1054f2..fd0bcaca 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -116,7 +116,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { struct sway_container *parent = container_view_destroy(sway_surface->view->swayc); if (parent) { - container_arrange_windows(parent, -1, -1); + arrange_windows(parent, -1, -1); } free(sway_surface->view); @@ -134,7 +134,7 @@ static void handle_unmap_notify(struct wl_listener *listener, void *data) { // take it out of the tree struct sway_container *parent = container_view_destroy(sway_surface->view->swayc); if (parent) { - container_arrange_windows(parent, -1, -1); + arrange_windows(parent, -1, -1); } sway_surface->view->swayc = NULL; @@ -163,7 +163,7 @@ static void handle_map_notify(struct wl_listener *listener, void *data) { struct sway_container *cont = container_view_create(parent, view); view->swayc = cont; - container_arrange_windows(cont->parent, -1, -1); + arrange_windows(cont->parent, -1, -1); sway_input_manager_set_focus(input_manager, cont); } } @@ -242,6 +242,6 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { struct sway_container *cont = container_view_create(focus, sway_view); sway_view->swayc = cont; - container_arrange_windows(cont->parent, -1, -1); + arrange_windows(cont->parent, -1, -1); sway_input_manager_set_focus(input_manager, cont); } diff --git a/sway/tree/container.c b/sway/tree/container.c index fe97d645..40047dcf 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -221,7 +221,7 @@ struct sway_container *container_output_destroy(struct sway_container *output) { container_add_child(root_container.children->items[p], child); } container_sort_workspaces(root_container.children->items[p]); - container_arrange_windows(root_container.children->items[p], + arrange_windows(root_container.children->items[p], -1, -1); } } diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 614d0505..dc0ee5b4 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -42,7 +42,7 @@ static void output_layout_change_notify(struct wl_listener *listener, output_container->height = output_box->height; } - container_arrange_windows(&root_container, -1, -1); + arrange_windows(&root_container, -1, -1); } void layout_init(void) { @@ -167,7 +167,7 @@ static void apply_vert_layout(struct sway_container *container, const double x, const double height, const int start, const int end); -void container_arrange_windows(struct sway_container *container, +void arrange_windows(struct sway_container *container, double width, double height) { int i; if (width == -1 || height == -1) { @@ -192,7 +192,7 @@ void container_arrange_windows(struct sway_container *container, struct sway_container *output = container->children->items[i]; wlr_log(L_DEBUG, "Arranging output '%s' at %f,%f", output->name, output->x, output->y); - container_arrange_windows(output, -1, -1); + arrange_windows(output, -1, -1); } return; case C_OUTPUT: @@ -206,7 +206,7 @@ void container_arrange_windows(struct sway_container *container, // arrange all workspaces: for (i = 0; i < container->children->length; ++i) { struct sway_container *child = container->children->items[i]; - container_arrange_windows(child, -1, -1); + arrange_windows(child, -1, -1); } return; case C_WORKSPACE: @@ -294,9 +294,9 @@ static void apply_horiz_layout(struct sway_container *container, if (i == end - 1) { double remaining_width = x + width - child_x; - container_arrange_windows(child, remaining_width, height); + arrange_windows(child, remaining_width, height); } else { - container_arrange_windows(child, child->width * scale, height); + arrange_windows(child, child->width * scale, height); } child_x += child->width; } @@ -345,9 +345,9 @@ void apply_vert_layout(struct sway_container *container, if (i == end - 1) { double remaining_height = y + height - child_y; - container_arrange_windows(child, width, remaining_height); + arrange_windows(child, width, remaining_height); } else { - container_arrange_windows(child, width, child->height * scale); + arrange_windows(child, width, child->height * scale); } child_y += child->height; } diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 369cf14c..ba04c55c 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -247,6 +247,6 @@ bool workspace_switch(struct sway_container *workspace) { } sway_seat_set_focus(seat, next); struct sway_container *output = container_parent(workspace, C_OUTPUT); - container_arrange_windows(output, -1, -1); + arrange_windows(output, -1, -1); return true; } -- cgit v1.2.3