Exemple #1
0
static swayc_t *fetch_view_from_scratchpad() {
	if (sp_index >= scratchpad->length) {
		sp_index = 0;
	}
	swayc_t *view = scratchpad->items[sp_index++];

	if (wlc_view_get_output(view->handle) != swayc_active_output()->handle) {
		wlc_view_set_output(view->handle, swayc_active_output()->handle);
	}
	if (!view->is_floating) {
		view->width = swayc_active_workspace()->width/2;
		view->height = swayc_active_workspace()->height/2;
		view->x = (swayc_active_workspace()->width - view->width)/2;
		view->y = (swayc_active_workspace()->height - view->height)/2;
	}
	if (swayc_active_workspace()->width < view->x + 20 || view->x + view->width < 20) {
		view->x = (swayc_active_workspace()->width - view->width)/2;
	}
	if (swayc_active_workspace()->height < view->y + 20 || view->y + view->height < 20) {
		view->y = (swayc_active_workspace()->height - view->height)/2;
	}

	add_floating(swayc_active_workspace(), view);
	wlc_view_set_mask(view->handle, VISIBLE);
	view->visible = true;
	arrange_windows(swayc_active_workspace(), -1, -1);
	set_focused_container(view);
	return view;
}
Exemple #2
0
bool move_focus(enum movement_direction direction) {
	swayc_t *old_view = get_focused_container(&root_container);
	swayc_t *new_view = get_swayc_in_direction(old_view, direction);
	if (!new_view) {
		return false;
	} else if (new_view->type == C_ROOT) {
		sway_log(L_DEBUG, "Not setting focus above the workspace level");
		return false;
	} else if (new_view->type == C_OUTPUT) {
		return set_focused_container(swayc_active_workspace_for(new_view));
	} else if (direction == MOVE_PARENT || direction == MOVE_CHILD) {
		return set_focused_container(new_view);
	} else if (config->mouse_warping) {
		swayc_t *old_op = old_view->type == C_OUTPUT ?
			old_view : swayc_parent_by_type(old_view, C_OUTPUT);
		swayc_t *focused = get_focused_view(new_view);
		if (set_focused_container(focused)) {
			if (old_op != swayc_active_output() && focused && focused->type == C_VIEW) {
				center_pointer_on(focused);
			}
			return true;
		}
	} else {
		return set_focused_container(get_focused_view(new_view));
	}
	return false;
}
Exemple #3
0
bool move_focus(enum movement_direction direction) {
	swayc_t *old_view = get_focused_container(&root_container);
	swayc_t *new_view = get_swayc_in_direction(old_view, direction);
	if (!new_view) {
		return false;
	} else if (direction == MOVE_PARENT) {
		return set_focused_container(new_view);
	} else if (config->mouse_warping) {
		swayc_t *old_op = old_view->type == C_OUTPUT ?
			old_view : swayc_parent_by_type(old_view, C_OUTPUT);
		swayc_t *focused = get_focused_view(new_view);
		if (set_focused_container(focused)) {
			if (old_op != swayc_active_output() && focused && focused->type == C_VIEW) {
				center_pointer_on(focused);
			}
			return true;
		}
	} else {
		return set_focused_container(get_focused_view(new_view));
	}
	return false;
}
Exemple #4
0
swayc_t *workspace_output_prev() {
	return workspace_output_prev_next_impl(swayc_active_output(), false);
}
Exemple #5
0
swayc_t *swayc_adjacent_output(swayc_t *output, enum movement_direction dir) {
	// TODO: This implementation is naïve: We assume all outputs are
	// perfectly aligned (ie. only a single output per edge which covers
	// the whole edge).
	if (!output) {
		output = swayc_active_output();
	}
	swayc_t *adjacent = NULL;
	switch(dir) {
		case MOVE_LEFT:
			for(int i = 0; i < root_container.children->length; ++i) {
				swayc_t *c = root_container.children->items[i];
				if (c == output || c->type != C_OUTPUT) {
					continue;
				}
				if (c->y == output->y && c->x + c->width == output->x) {
					sway_log(L_DEBUG, "%s is left of current output %s", c->name, output->name);
					adjacent = c;
					break;
				}
			}
			break;
		case MOVE_RIGHT:
			for(int i = 0; i < root_container.children->length; ++i) {
				swayc_t *c = root_container.children->items[i];
				if (c == output || c->type != C_OUTPUT) {
					continue;
				}
				if (c->y == output->y && output->x + output->width == c->x) {
					sway_log(L_DEBUG, "%s is right of current output %s", c->name, output->name);
					adjacent = c;
					break;
				}
			}
			break;
		case MOVE_UP:
			for(int i = 0; i < root_container.children->length; ++i) {
				swayc_t *c = root_container.children->items[i];
				if (c == output || c->type != C_OUTPUT) {
					continue;
				}
				if (output->x == c->x && c->y + c->height == output->y) {
					sway_log(L_DEBUG, "%s is above current output %s", c->name, output->name);
					adjacent = c;
					break;
				}
			}
			break;
		case MOVE_DOWN:
			for(int i = 0; i < root_container.children->length; ++i) {
				swayc_t *c = root_container.children->items[i];
				if (c == output || c->type != C_OUTPUT) {
					continue;
				}
				if (output->x == c->x && output->y + output->height == c->y) {
					sway_log(L_DEBUG, "%s is below current output %s", c->name, output->name);
					adjacent = c;
					break;
				}
			}
			break;
		default:
			sway_abort("Function called with invalid argument.");
			break;
	}
	return adjacent;
}