Merge pull request #2481 from RyanDwyer/rename-functions

Rename container_sort_workspaces and container_wrap_children
master
Drew DeVault 6 years ago committed by GitHub
commit 5c779c11f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -58,6 +58,8 @@ void output_damage_whole_container(struct sway_output *output,
struct sway_container *output_by_name(const char *name);
void output_sort_workspaces(struct sway_container *output);
void output_enable(struct sway_output *output);
bool output_has_opaque_overlay_layer_surface(struct sway_output *output);

@ -361,12 +361,4 @@ bool container_is_floating_or_child(struct sway_container *container);
*/
bool container_is_fullscreen_or_child(struct sway_container *container);
/**
* Wrap the children of parent in a new container. The new container will be the
* only child of parent.
*
* The new container is returned.
*/
struct sway_container *container_wrap_children(struct sway_container *parent);
#endif

@ -45,8 +45,6 @@ void container_move(struct sway_container *container,
enum sway_container_layout container_get_default_layout(
struct sway_container *con);
void container_sort_workspaces(struct sway_container *output);
struct sway_container *container_get_in_direction(struct sway_container
*container, struct sway_seat *seat, enum movement_direction dir);

@ -50,4 +50,11 @@ struct sway_container *workspace_output_get_highest_available(
void workspace_detect_urgent(struct sway_container *workspace);
/**
* Wrap the workspace's tiling children in a new container.
* The new container will be the only direct tiling child of the workspace.
* The new container is returned.
*/
struct sway_container *workspace_wrap_children(struct sway_container *ws);
#endif

@ -8,6 +8,7 @@
#include "sway/tree/container.h"
#include "sway/tree/layout.h"
#include "sway/tree/view.h"
#include "sway/tree/workspace.h"
#include "list.h"
struct cmd_results *cmd_floating(int argc, char **argv) {
@ -24,7 +25,7 @@ struct cmd_results *cmd_floating(int argc, char **argv) {
if (container->type == C_WORKSPACE) {
// Wrap the workspace's children in a container so we can float it
struct sway_container *workspace = container;
container = container_wrap_children(container);
container = workspace_wrap_children(container);
workspace->layout = L_HORIZ;
seat_set_focus(config->handler_context.seat, container);
}

@ -4,6 +4,7 @@
#include "sway/tree/arrange.h"
#include "sway/tree/container.h"
#include "sway/tree/view.h"
#include "sway/tree/workspace.h"
#include "sway/tree/layout.h"
#include "util.h"
@ -21,7 +22,7 @@ struct cmd_results *cmd_fullscreen(int argc, char **argv) {
if (container->type == C_WORKSPACE) {
// Wrap the workspace's children in a container so we can fullscreen it
struct sway_container *workspace = container;
container = container_wrap_children(container);
container = workspace_wrap_children(container);
workspace->layout = L_HORIZ;
seat_set_focus(config->handler_context.seat, container);
}

@ -64,7 +64,7 @@ static struct cmd_results *cmd_move_container(struct sway_container *current,
return cmd_results_new(CMD_FAILURE, "move",
"Can't move an empty workspace");
}
current = container_wrap_children(current);
current = workspace_wrap_children(current);
} else if (current->type != C_CONTAINER && current->type != C_VIEW) {
return cmd_results_new(CMD_FAILURE, "move",
"Can only move containers and views.");
@ -245,7 +245,7 @@ static void workspace_move_to_output(struct sway_container *workspace,
// Try to remove an empty workspace from the destination output.
container_reap_empty_recursive(new_output_focus);
container_sort_workspaces(output);
output_sort_workspaces(output);
seat_set_focus(seat, output);
workspace_output_raise_priority(workspace, old_output, output);
ipc_event_workspace(NULL, workspace, "move");
@ -437,7 +437,7 @@ static struct cmd_results *move_to_scratchpad(struct sway_container *con) {
if (con->type == C_WORKSPACE) {
// Wrap the workspace's children in a container
struct sway_container *workspace = con;
con = container_wrap_children(con);
con = workspace_wrap_children(con);
workspace->layout = L_HORIZ;
}

@ -6,6 +6,7 @@
#include "sway/commands.h"
#include "sway/config.h"
#include "sway/ipc-server.h"
#include "sway/output.h"
#include "sway/tree/container.h"
#include "sway/tree/workspace.h"
@ -82,7 +83,7 @@ struct cmd_results *cmd_rename(int argc, char **argv) {
free(workspace->name);
workspace->name = new_name;
container_sort_workspaces(workspace->parent);
output_sort_workspaces(workspace->parent);
ipc_event_workspace(NULL, workspace, "rename");
return cmd_results_new(CMD_SUCCESS, NULL, NULL);

@ -270,7 +270,7 @@ static struct sway_container *container_output_destroy(
container_destroy(workspace);
}
container_sort_workspaces(new_output);
output_sort_workspaces(new_output);
}
}
}
@ -1305,15 +1305,3 @@ bool container_is_fullscreen_or_child(struct sway_container *container) {
return false;
}
struct sway_container *container_wrap_children(struct sway_container *parent) {
struct sway_container *middle = container_create(C_CONTAINER);
middle->layout = parent->layout;
while (parent->children->length) {
struct sway_container *child = parent->children->items[0];
container_remove_child(child);
container_add_child(middle, child);
}
container_add_child(parent, middle);
return middle;
}

@ -1,5 +1,4 @@
#define _POSIX_C_SOURCE 200809L
#include <ctype.h>
#include <math.h>
#include <stdbool.h>
#include <stdlib.h>
@ -591,28 +590,6 @@ enum sway_container_layout container_get_default_layout(
}
}
static int sort_workspace_cmp_qsort(const void *_a, const void *_b) {
struct sway_container *a = *(void **)_a;
struct sway_container *b = *(void **)_b;
int retval = 0;
if (isdigit(a->name[0]) && isdigit(b->name[0])) {
int a_num = strtol(a->name, NULL, 10);
int b_num = strtol(b->name, NULL, 10);
retval = (a_num < b_num) ? -1 : (a_num > b_num);
} else if (isdigit(a->name[0])) {
retval = -1;
} else if (isdigit(b->name[0])) {
retval = 1;
}
return retval;
}
void container_sort_workspaces(struct sway_container *output) {
list_stable_sort(output->children, sort_workspace_cmp_qsort);
}
/**
* Get swayc in the direction of newly entered output.
*/

@ -1,4 +1,5 @@
#define _POSIX_C_SOURCE 200809L
#include <ctype.h>
#include <string.h>
#include <strings.h>
#include "sway/ipc-server.h"
@ -28,7 +29,7 @@ static void restore_workspaces(struct sway_container *output) {
}
}
container_sort_workspaces(output);
output_sort_workspaces(output);
}
struct sway_container *output_create(
@ -102,3 +103,23 @@ struct sway_container *output_create(
return output;
}
static int sort_workspace_cmp_qsort(const void *_a, const void *_b) {
struct sway_container *a = *(void **)_a;
struct sway_container *b = *(void **)_b;
if (isdigit(a->name[0]) && isdigit(b->name[0])) {
int a_num = strtol(a->name, NULL, 10);
int b_num = strtol(b->name, NULL, 10);
return (a_num < b_num) ? -1 : (a_num > b_num);
} else if (isdigit(a->name[0])) {
return -1;
} else if (isdigit(b->name[0])) {
return 1;
}
return 0;
}
void output_sort_workspaces(struct sway_container *output) {
list_stable_sort(output->children, sort_workspace_cmp_qsort);
}

@ -75,7 +75,7 @@ struct sway_container *workspace_create(struct sway_container *output,
workspace_output_add_priority(workspace, output);
container_add_child(output, workspace);
container_sort_workspaces(output);
output_sort_workspaces(output);
container_create_notify(workspace);
return workspace;
@ -537,3 +537,15 @@ void workspace_detect_urgent(struct sway_container *workspace) {
container_damage_whole(workspace);
}
}
struct sway_container *workspace_wrap_children(struct sway_container *ws) {
struct sway_container *middle = container_create(C_CONTAINER);
middle->layout = ws->layout;
while (ws->children->length) {
struct sway_container *child = ws->children->items[0];
container_remove_child(child);
container_add_child(middle, child);
}
container_add_child(ws, middle);
return middle;
}

Loading…
Cancel
Save