Implement iterators per container type

This introduces the following `for_each` functions:

* root_for_each_workspace
* root_for_each_container
* output_for_each_workspace
* output_for_each_container
* workspace_for_each_container

And introduces the following `find` functions:

* root_find_output
* root_find_workspace
* root_find_container
* output_find_workspace
* output_find_container
* workspace_find_container
* container_find_child

And removes the following functions:

* container_descendants
* container_for_each_descendant
* container_find

This change is preparing the way for demoting sway_container. Eventually
these functions will accept and return sway_outputs, sway_workspaces and
sway_containers (meaning a C_CONTAINER or C_VIEW).

This change also makes it easy to handle abnormalities like the
workspace floating list, root's scratchpad list and (once implemented)
root's saved workspaces list for when there's no connected outputs.
This commit is contained in:
Ryan Dwyer 2018-08-17 19:48:34 +10:00
parent d4a32800d5
commit d6cd79c342
18 changed files with 268 additions and 110 deletions

View file

@ -522,7 +522,7 @@ void ipc_client_disconnect(struct ipc_client *client) {
static void ipc_get_workspaces_callback(struct sway_container *workspace,
void *data) {
if (workspace->type != C_WORKSPACE) {
if (!sway_assert(workspace->type == C_WORKSPACE, "Expected a workspace")) {
return;
}
json_object *workspace_json = ipc_json_describe_container(workspace);
@ -631,8 +631,7 @@ void ipc_client_handle_command(struct ipc_client *client) {
case IPC_GET_WORKSPACES:
{
json_object *workspaces = json_object_new_array();
container_for_each_descendant(&root_container,
ipc_get_workspaces_callback, workspaces);
root_for_each_workspace(ipc_get_workspaces_callback, workspaces);
const char *json_string = json_object_to_json_string(workspaces);
client_valid =
ipc_send_reply(client, json_string, (uint32_t)strlen(json_string));
@ -729,8 +728,7 @@ void ipc_client_handle_command(struct ipc_client *client) {
case IPC_GET_MARKS:
{
json_object *marks = json_object_new_array();
container_descendants(&root_container, C_VIEW, ipc_get_marks_callback,
marks);
root_for_each_container(ipc_get_marks_callback, marks);
const char *json_string = json_object_to_json_string(marks);
client_valid =
ipc_send_reply(client, json_string, (uint32_t)strlen(json_string));