This commit is contained in:
Tony Crisci 2018-03-29 18:38:43 -04:00
parent 62d1b4cb96
commit 4ec8bf4cee
3 changed files with 94 additions and 49 deletions

View File

@ -86,7 +86,8 @@ static void container_destroy(struct sway_container *cont) {
free(cont);
}
struct sway_container *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);
@ -150,8 +151,10 @@ struct sway_container *container_output_create(struct sway_output *sway_output)
return 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")) {
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);
@ -172,8 +175,10 @@ struct sway_container *container_workspace_create(struct sway_container *output,
return workspace;
}
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")) {
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);
@ -198,7 +203,8 @@ struct sway_container *container_view_create(struct sway_container *sibling, str
}
struct sway_container *container_output_destroy(struct sway_container *output) {
if (!sway_assert(output, "null output passed to container_output_destroy")) {
if (!sway_assert(output,
"null output passed to container_output_destroy")) {
return NULL;
}
@ -215,7 +221,8 @@ 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], -1, -1);
container_arrange_windows(root_container.children->items[p],
-1, -1);
}
}
@ -246,7 +253,8 @@ struct sway_container *container_view_destroy(struct sway_container *view) {
return parent;
}
struct sway_container *container_set_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 +266,8 @@ struct sway_container *container_set_layout(struct sway_container *container, en
return container;
}
void 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];
@ -291,7 +300,8 @@ struct sway_container *container_find(struct sway_container *container,
return NULL;
}
struct sway_container *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;
}
@ -304,7 +314,8 @@ struct sway_container *container_parent(struct sway_container *container, enum s
return container;
}
void sway_container_for_each(struct sway_container *container, void (*f)(struct sway_container *view, void *data), void *data) {
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) {
@ -326,7 +337,8 @@ void sway_container_for_each(struct sway_container *container, void (*f)(struct
}
}
struct sway_container *sway_container_at(struct sway_container *parent, double lx, double ly,
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) {
@ -411,8 +423,8 @@ struct sway_container *sway_container_at(struct sway_container *parent, double l
return NULL;
}
void sway_container_for_each_bfs(struct sway_container *con, void (*f)(struct sway_container *con, void *data),
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) {
return;

View File

@ -16,14 +16,16 @@
struct sway_container root_container;
static void output_layout_change_notify(struct wl_listener *listener, void *data) {
static void output_layout_change_notify(struct wl_listener *listener,
void *data) {
struct wlr_box *layout_box = wlr_output_layout_get_box(
root_container.sway_root->output_layout, NULL);
root_container.width = layout_box->width;
root_container.height = layout_box->height;
for (int i = 0 ; i < root_container.children->length; ++i) {
struct sway_container *output_container = root_container.children->items[i];
struct sway_container *output_container =
root_container.children->items[i];
if (output_container->type != C_OUTPUT) {
continue;
}
@ -79,7 +81,8 @@ static int index_child(const struct sway_container *child) {
return i;
}
struct sway_container *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 +91,8 @@ struct sway_container *container_add_sibling(struct sway_container *fixed, struc
return active->parent;
}
void container_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);
@ -96,7 +100,9 @@ void container_add_child(struct sway_container *parent, struct sway_container *c
child->parent = parent;
// set focus for this container
/* TODO WLR
if (parent->type == C_WORKSPACE && child->type == C_VIEW && (parent->workspace_layout == L_TABBED || parent->workspace_layout == L_STACKED)) {
if (parent->type == C_WORKSPACE && child->type == C_VIEW &&
(parent->workspace_layout == L_TABBED || parent->workspace_layout ==
L_STACKED)) {
child = new_container(child, parent->workspace_layout);
}
*/
@ -115,7 +121,8 @@ struct sway_container *container_remove_child(struct sway_container *child) {
return parent;
}
enum sway_container_layout container_get_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;
@ -160,7 +167,8 @@ 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, 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;
@ -203,7 +211,8 @@ void container_arrange_windows(struct sway_container *container, double width, d
return;
case C_WORKSPACE:
{
struct sway_container *output = 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);
@ -259,7 +268,8 @@ static void apply_horiz_layout(struct sway_container *container,
double scale = 0;
// Calculate total width
for (int i = start; i < end; ++i) {
double *old_width = &((struct sway_container *)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);
@ -309,7 +319,8 @@ void apply_vert_layout(struct sway_container *container,
double scale = 0;
// Calculate total height
for (i = start; i < end; ++i) {
double *old_height = &((struct sway_container *)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);
@ -354,8 +365,9 @@ void apply_vert_layout(struct sway_container *container,
/**
* Get swayc in the direction of newly entered output.
*/
static struct sway_container *get_swayc_in_output_direction(struct sway_container *output,
enum movement_direction dir, struct sway_seat *seat) {
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;
}
@ -380,13 +392,15 @@ static struct sway_container *get_swayc_in_output_direction(struct sway_containe
return ws->children->items[0];
case MOVE_UP:
case MOVE_DOWN: {
struct sway_container *focused = sway_seat_get_focus_inactive(seat, ws);
struct sway_container *focused =
sway_seat_get_focus_inactive(seat, ws);
if (focused && focused->parent) {
struct sway_container *parent = focused->parent;
if (parent->layout == L_VERT) {
if (dir == MOVE_UP) {
// get child furthest down on new output
return parent->children->items[parent->children->length-1];
int idx = parent->children->length - 1;
return parent->children->items[idx];
} else if (dir == MOVE_DOWN) {
// get child furthest up on new output
return parent->children->items[0];
@ -404,7 +418,8 @@ static struct sway_container *get_swayc_in_output_direction(struct sway_containe
return ws;
}
static void get_layout_center_position(struct sway_container *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;
@ -423,7 +438,8 @@ static void get_layout_center_position(struct sway_container *container, int *x,
}
}
static bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out) {
static bool sway_dir_to_wlr(enum movement_direction dir,
enum wlr_direction *out) {
switch (dir) {
case MOVE_UP:
*out = WLR_DIRECTION_UP;
@ -457,8 +473,9 @@ static struct sway_container *sway_output_from_wlr(struct wlr_output *output) {
return NULL;
}
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) {
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);
}
@ -498,7 +515,8 @@ static struct sway_container *get_swayc_in_direction_under(struct sway_container
wlr_log(L_DEBUG, "Moving from fullscreen view, skipping to 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);
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) {
@ -521,16 +539,19 @@ static struct sway_container *get_swayc_in_direction_under(struct sway_container
}
int lx, ly;
get_layout_center_position(container, &lx, &ly);
struct wlr_output_layout *layout = root_container.sway_root->output_layout;
struct wlr_output_layout *layout =
root_container.sway_root->output_layout;
struct wlr_output *wlr_adjacent =
wlr_output_layout_adjacent_output(layout, wlr_dir,
container->sway_output->wlr_output, lx, ly);
struct sway_container *adjacent = sway_output_from_wlr(wlr_adjacent);
struct sway_container *adjacent =
sway_output_from_wlr(wlr_adjacent);
if (!adjacent || adjacent == container) {
return wrap_candidate;
}
struct sway_container *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;
}
@ -570,8 +591,9 @@ static struct sway_container *get_swayc_in_direction_under(struct sway_container
}
}
} else {
wlr_log(L_DEBUG, "%s cont %d-%p dir %i sibling %d: %p", __func__,
idx, container, dir, desired, parent->children->items[desired]);
wlr_log(L_DEBUG,
"%s cont %d-%p dir %i sibling %d: %p", __func__, idx,
container, dir, desired, parent->children->items[desired]);
return parent->children->items[desired];
}
}
@ -587,7 +609,8 @@ static struct sway_container *get_swayc_in_direction_under(struct sway_container
}
}
struct sway_container *container_get_in_direction(struct sway_container *container, struct sway_seat *seat,
struct sway_container *container_get_in_direction(
struct sway_container *container, struct sway_seat *seat,
enum movement_direction dir) {
return get_swayc_in_direction_under(container, dir, seat, NULL);
}

View File

@ -52,7 +52,8 @@ struct sway_container *workspace_by_number(const char* name) {
if (wbnd.len <= 0) {
return NULL;
}
return 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) {
@ -79,7 +80,8 @@ struct sway_container *workspace_by_name(const char *name) {
} else if (strcmp(name, "current") == 0) {
return current_workspace;
} else {
return container_find(&root_container, _workspace_by_name, (void *) name);
return container_find(&root_container, _workspace_by_name,
(void *)name);
}
}
@ -103,7 +105,8 @@ struct sway_container *workspace_create(const char *name) {
}
// Otherwise create a new one
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 *focus =
sway_seat_get_focus_inactive(seat, &root_container);
parent = focus;
parent = container_parent(parent, C_OUTPUT);
return container_workspace_create(parent, name);
@ -114,7 +117,8 @@ struct sway_container *workspace_create(const char *name) {
* the end and beginning. If next is false, the previous workspace is returned,
* otherwise the next one is returned.
*/
struct sway_container *workspace_output_prev_next_impl(struct sway_container *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;
@ -134,7 +138,8 @@ struct sway_container *workspace_output_prev_next_impl(struct sway_container *ou
}
}
// Doesn't happen, at worst the for loop returns the previously active workspace
// Doesn't happen, at worst the for loop returns the previously active
// workspace
return NULL;
}
@ -144,7 +149,8 @@ struct sway_container *workspace_output_prev_next_impl(struct sway_container *ou
* next is false, the previous workspace is returned, otherwise the next one is
* returned.
*/
struct sway_container *workspace_prev_next_impl(struct sway_container *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;
@ -166,7 +172,8 @@ struct sway_container *workspace_prev_next_impl(struct sway_container *workspace
}
}
// Given workspace is the first/last on the output, jump to the previous/next output
// Given workspace is the first/last on the output, jump to the
// previous/next output
int num_outputs = root_container.children->length;
for (i = 0; i < num_outputs; i++) {
if (root_container.children->items[i] == current_output) {
@ -176,7 +183,8 @@ struct sway_container *workspace_prev_next_impl(struct sway_container *workspace
}
}
// Doesn't happen, at worst the for loop returns the previously active workspace on the active output
// Doesn't happen, at worst the for loop returns the previously active
// workspace on the active output
return NULL;
}
@ -201,7 +209,8 @@ bool workspace_switch(struct sway_container *workspace) {
return false;
}
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 *focus =
sway_seat_get_focus_inactive(seat, &root_container);
if (!seat || !focus) {
return false;
}
@ -230,7 +239,8 @@ bool workspace_switch(struct sway_container *workspace) {
// TODO: Deal with sticky containers
wlr_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name);
wlr_log(L_DEBUG, "Switching to workspace %p:%s",
workspace, workspace->name);
struct sway_container *next = sway_seat_get_focus_inactive(seat, workspace);
if (next == NULL) {
next = workspace;