Пример #1
0
swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data) {
	if (!container->children) {
		return NULL;
	}
	// Special case for checking floating stuff
	int i;
	if (container->type == C_WORKSPACE) {
		for (i = 0; i < container->floating->length; ++i) {
			swayc_t *child = container->floating->items[i];
			if (test(child, data)) {
				return child;
			}
		}
	}
	for (i = 0; i < container->children->length; ++i) {
		swayc_t *child = container->children->items[i];
		if (test(child, data)) {
			return child;
		} else {
			swayc_t *res = find_container(child, test, data);
			if (res) {
				return res;
			}
		}
	}
	return NULL;
}
Пример #2
0
TEST_FIXTURE(e2e_raw_client, create_entity)
{
	auto model = client.get_model().get();

	::utility::string_t entity_set_name = U("Accounts");
	std::shared_ptr<odata_entity_value> entity = std::make_shared<odata_entity_value>(model->find_container()->find_entity_set(entity_set_name)->get_entity_type());

	entity->set_value(U("AccountID"), 130);
	entity->set_value(U("Country"), U("CN"));

	auto accountinfo_type = model->find_complex_type(U("AccountInfo"));
	auto account_info = std::make_shared<odata_complex_value>(accountinfo_type);
	::utility::string_t account_firstname = U("cpp");
	::utility::string_t account_lastname = U("client");
	account_info->set_value(U("FirstName"), account_firstname);
	account_info->set_value(U("LastName"), account_lastname);

	entity->set_value(U("AccountInfo"), account_info);

	auto response_code = client.create_entity(entity_set_name, entity).get();
	VERIFY_ARE_EQUAL(201, response_code);

	//query the newly created entity
	auto query_result = client.get_data_from_server(U("Accounts(130)")).get();
	VERIFY_ARE_EQUAL(query_result.size(), 1);

	auto new_entity = std::dynamic_pointer_cast<odata_entity_value>(query_result[0]);
	std::shared_ptr<odata_value> property_value;
	VERIFY_IS_TRUE(entity->get_property_value(U("AccountID"), property_value));
	auto primitive_value = std::dynamic_pointer_cast<odata_primitive_value>(property_value);
	int32_t new_id = primitive_value->as<int32_t>();
	VERIFY_ARE_EQUAL(130, new_id);
}
Пример #3
0
swayc_t *focus_pointer(void) {
    swayc_t *focused = get_focused_container(&root_container);
    if (!(wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN)) {
        swayc_t *pointer = find_container(&root_container, pointer_test, &mouse_origin);
        if (pointer && focused != pointer) {
            unfocus_all(&root_container);
            focus_view(pointer);
        } else if (!focused) {
            focus_view(active_workspace);
        }
        focused = pointer;
    }
    return focused;
}
Пример #4
0
swayc_t *new_output(wlc_handle handle) {
	const struct wlc_size* size = wlc_output_get_resolution(handle);
	const char *name = wlc_output_get_name(handle);
	sway_log(L_DEBUG, "Added output %lu:%s", handle, name);

	swayc_t *output = new_swayc(C_OUTPUT);
	output->width = size->w;
	output->height = size->h;
	output->handle = handle;
	output->name = name ? strdup(name) : NULL;
	output->gaps = config->gaps_outer + config->gaps_inner / 2;

	add_child(&root_container, output);

	// Create workspace
	char *ws_name = NULL;
	if (name) {
		int i;
		for (i = 0; i < config->workspace_outputs->length; ++i) {
			struct workspace_output *wso = config->workspace_outputs->items[i];
			if (strcasecmp(wso->output, name) == 0) {
				sway_log(L_DEBUG, "Matched workspace to output: %s for %s", wso->workspace, wso->output);
				// Check if any other workspaces are using this name
				if (find_container(&root_container, workspace_test, wso->workspace)) {
					sway_log(L_DEBUG, "But it's already taken");
					break;
				}
				sway_log(L_DEBUG, "So we're going to use it");
				ws_name = strdup(wso->workspace);
				break;
			}
		}
	}
	if (!ws_name) {
		ws_name = workspace_next_name();
	}

	// create and initilize default workspace
	swayc_t *ws = new_workspace(output, ws_name);
	ws->is_focused = true;

	free(ws_name);
	
	return output;
}
Пример #5
0
swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data) {
    if (!container->children) {
        return NULL;
    }
    int i;
    for (i = 0; i < container->children->length; ++i) {
        swayc_t *child = container->children->items[i];
        if (test(child, data)) {
            return child;
        } else {
            swayc_t *_ = find_container(child, test, data);
            if (_) {
                return _;
            }
        }
    }
    return NULL;
}