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); 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; struct wlr_box size;
wlr_output_effective_resolution(sway_output->wlr_output, &size.width, wlr_output_effective_resolution(sway_output->wlr_output, &size.width,
&size.height); &size.height);
@ -150,8 +151,10 @@ struct sway_container *container_output_create(struct sway_output *sway_output)
return output; return output;
} }
struct sway_container *container_workspace_create(struct sway_container *output, const char *name) { struct sway_container *container_workspace_create(struct sway_container
if (!sway_assert(output, "container_workspace_create called with null output")) { *output, const char *name) {
if (!sway_assert(output,
"container_workspace_create called with null output")) {
return NULL; return NULL;
} }
wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name); 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; return workspace;
} }
struct sway_container *container_view_create(struct sway_container *sibling, struct sway_view *sway_view) { struct sway_container *container_view_create(struct sway_container *sibling,
if (!sway_assert(sibling, "container_view_create called with NULL sibling/parent")) { struct sway_view *sway_view) {
if (!sway_assert(sibling,
"container_view_create called with NULL sibling/parent")) {
return NULL; return NULL;
} }
const char *title = view_get_title(sway_view); 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) { 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; 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_add_child(root_container.children->items[p], child);
} }
container_sort_workspaces(root_container.children->items[p]); 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; 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) { if (container->type == C_WORKSPACE) {
container->workspace_layout = layout; container->workspace_layout = layout;
if (layout == L_HORIZ || layout == L_VERT) { if (layout == L_HORIZ || layout == L_VERT) {
@ -258,7 +266,8 @@ struct sway_container *container_set_layout(struct sway_container *container, en
return container; 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) { void (*func)(struct sway_container *item, void *data), void *data) {
for (int i = 0; i < root->children->length; ++i) { for (int i = 0; i < root->children->length; ++i) {
struct sway_container *item = root->children->items[i]; struct sway_container *item = root->children->items[i];
@ -291,7 +300,8 @@ struct sway_container *container_find(struct sway_container *container,
return NULL; 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")) { if (!sway_assert(container, "container is NULL")) {
return NULL; return NULL;
} }
@ -304,7 +314,8 @@ struct sway_container *container_parent(struct sway_container *container, enum s
return container; 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) { if (container) {
int i; int i;
if (container->children) { 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) { struct wlr_surface **surface, double *sx, double *sy) {
list_t *queue = get_bfs_queue(); list_t *queue = get_bfs_queue();
if (!queue) { if (!queue) {
@ -411,8 +423,8 @@ struct sway_container *sway_container_at(struct sway_container *parent, double l
return NULL; return NULL;
} }
void sway_container_for_each_bfs(struct sway_container *con, void (*f)(struct sway_container *con, void *data), void sway_container_for_each_bfs(struct sway_container *con,
void *data) { void (*f)(struct sway_container *con, void *data), void *data) {
list_t *queue = get_bfs_queue(); list_t *queue = get_bfs_queue();
if (!queue) { if (!queue) {
return; return;

View File

@ -16,14 +16,16 @@
struct sway_container root_container; 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( struct wlr_box *layout_box = wlr_output_layout_get_box(
root_container.sway_root->output_layout, NULL); root_container.sway_root->output_layout, NULL);
root_container.width = layout_box->width; root_container.width = layout_box->width;
root_container.height = layout_box->height; root_container.height = layout_box->height;
for (int i = 0 ; i < root_container.children->length; ++i) { 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) { if (output_container->type != C_OUTPUT) {
continue; continue;
} }
@ -79,7 +81,8 @@ static int index_child(const struct sway_container *child) {
return i; 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 // TODO handle floating
struct sway_container *parent = fixed->parent; struct sway_container *parent = fixed->parent;
int i = index_child(fixed); int i = index_child(fixed);
@ -88,7 +91,8 @@ struct sway_container *container_add_sibling(struct sway_container *fixed, struc
return active->parent; 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)", wlr_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)",
child, child->type, child->width, child->height, child, child->type, child->width, child->height,
parent, parent->type, parent->width, parent->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; child->parent = parent;
// set focus for this container // set focus for this container
/* TODO WLR /* 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); child = new_container(child, parent->workspace_layout);
} }
*/ */
@ -115,7 +121,8 @@ struct sway_container *container_remove_child(struct sway_container *child) {
return parent; 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 /* TODO WLR
if (config->default_layout != L_NONE) { if (config->default_layout != L_NONE) {
//return config->default_layout; //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 double height, const int start,
const int end); 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; int i;
if (width == -1 || height == -1) { if (width == -1 || height == -1) {
width = container->width; width = container->width;
@ -203,7 +211,8 @@ void container_arrange_windows(struct sway_container *container, double width, d
return; return;
case C_WORKSPACE: 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; struct wlr_box *area = &output->sway_output->usable_area;
wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d", wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d",
area->width, area->height, area->x, area->y); area->width, area->height, area->x, area->y);
@ -259,7 +268,8 @@ static void apply_horiz_layout(struct sway_container *container,
double scale = 0; double scale = 0;
// Calculate total width // Calculate total width
for (int i = start; i < end; ++i) { 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 (*old_width <= 0) {
if (end - start > 1) { if (end - start > 1) {
*old_width = width / (end - start - 1); *old_width = width / (end - start - 1);
@ -309,7 +319,8 @@ void apply_vert_layout(struct sway_container *container,
double scale = 0; double scale = 0;
// Calculate total height // Calculate total height
for (i = start; i < end; ++i) { 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 (*old_height <= 0) {
if (end - start > 1) { if (end - start > 1) {
*old_height = height / (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. * Get swayc in the direction of newly entered output.
*/ */
static struct sway_container *get_swayc_in_output_direction(struct sway_container *output, static struct sway_container *get_swayc_in_output_direction(
enum movement_direction dir, struct sway_seat *seat) { struct sway_container *output, enum movement_direction dir,
struct sway_seat *seat) {
if (!output) { if (!output) {
return NULL; return NULL;
} }
@ -380,13 +392,15 @@ static struct sway_container *get_swayc_in_output_direction(struct sway_containe
return ws->children->items[0]; return ws->children->items[0];
case MOVE_UP: case MOVE_UP:
case MOVE_DOWN: { 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) { if (focused && focused->parent) {
struct sway_container *parent = focused->parent; struct sway_container *parent = focused->parent;
if (parent->layout == L_VERT) { if (parent->layout == L_VERT) {
if (dir == MOVE_UP) { if (dir == MOVE_UP) {
// get child furthest down on new output // 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) { } else if (dir == MOVE_DOWN) {
// get child furthest up on new output // get child furthest up on new output
return parent->children->items[0]; return parent->children->items[0];
@ -404,7 +418,8 @@ static struct sway_container *get_swayc_in_output_direction(struct sway_containe
return ws; 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 // FIXME view coords are inconsistently referred to in layout/output systems
if (container->type == C_OUTPUT) { if (container->type == C_OUTPUT) {
*x = container->x + container->width/2; *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) { switch (dir) {
case MOVE_UP: case MOVE_UP:
*out = WLR_DIRECTION_UP; *out = WLR_DIRECTION_UP;
@ -457,8 +473,9 @@ static struct sway_container *sway_output_from_wlr(struct wlr_output *output) {
return NULL; return NULL;
} }
static struct sway_container *get_swayc_in_direction_under(struct sway_container *container, static struct sway_container *get_swayc_in_direction_under(
enum movement_direction dir, struct sway_seat *seat, struct sway_container *limit) { struct sway_container *container, enum movement_direction dir,
struct sway_seat *seat, struct sway_container *limit) {
if (dir == MOVE_CHILD) { if (dir == MOVE_CHILD) {
return sway_seat_get_focus_inactive(seat, container); 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"); wlr_log(L_DEBUG, "Moving from fullscreen view, skipping to output");
container = container_parent(container, C_OUTPUT); container = container_parent(container, C_OUTPUT);
get_layout_center_position(container, &abs_pos); 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); return get_swayc_in_output_direction(output, dir);
} }
if (container->type == C_WORKSPACE && container->fullscreen) { 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; int lx, ly;
get_layout_center_position(container, &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 = struct wlr_output *wlr_adjacent =
wlr_output_layout_adjacent_output(layout, wlr_dir, wlr_output_layout_adjacent_output(layout, wlr_dir,
container->sway_output->wlr_output, lx, ly); 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) { if (!adjacent || adjacent == container) {
return wrap_candidate; 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) { if (next == NULL) {
return NULL; return NULL;
} }
@ -570,8 +591,9 @@ static struct sway_container *get_swayc_in_direction_under(struct sway_container
} }
} }
} else { } else {
wlr_log(L_DEBUG, "%s cont %d-%p dir %i sibling %d: %p", __func__, wlr_log(L_DEBUG,
idx, container, dir, desired, parent->children->items[desired]); "%s cont %d-%p dir %i sibling %d: %p", __func__, idx,
container, dir, desired, parent->children->items[desired]);
return 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) { enum movement_direction dir) {
return get_swayc_in_direction_under(container, dir, seat, NULL); 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) { if (wbnd.len <= 0) {
return NULL; 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) { 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) { } else if (strcmp(name, "current") == 0) {
return current_workspace; return current_workspace;
} else { } 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 // Otherwise create a new one
struct sway_seat *seat = input_manager_current_seat(input_manager); 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 = focus;
parent = container_parent(parent, C_OUTPUT); parent = container_parent(parent, C_OUTPUT);
return container_workspace_create(parent, name); 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, * the end and beginning. If next is false, the previous workspace is returned,
* otherwise the next one 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, if (!sway_assert(output->type == C_OUTPUT,
"Argument must be an output, is %d", output->type)) { "Argument must be an output, is %d", output->type)) {
return NULL; 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; 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 * next is false, the previous workspace is returned, otherwise the next one is
* returned. * 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, if (!sway_assert(workspace->type == C_WORKSPACE,
"Argument must be a workspace, is %d", workspace->type)) { "Argument must be a workspace, is %d", workspace->type)) {
return NULL; 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; int num_outputs = root_container.children->length;
for (i = 0; i < num_outputs; i++) { for (i = 0; i < num_outputs; i++) {
if (root_container.children->items[i] == current_output) { 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; return NULL;
} }
@ -201,7 +209,8 @@ bool workspace_switch(struct sway_container *workspace) {
return false; return false;
} }
struct sway_seat *seat = input_manager_current_seat(input_manager); 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) { if (!seat || !focus) {
return false; return false;
} }
@ -230,7 +239,8 @@ bool workspace_switch(struct sway_container *workspace) {
// TODO: Deal with sticky containers // 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); struct sway_container *next = sway_seat_get_focus_inactive(seat, workspace);
if (next == NULL) { if (next == NULL) {
next = workspace; next = workspace;