mirror of
https://github.com/swaywm/sway.git
synced 2025-11-19 06:59:52 -05:00
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers to layout containers and view containers. Workspaces, outputs and the root are no longer known as containers. Instead, root, outputs, workspaces and containers are all a type of node, and containers come in two types: layout containers and view containers. In addition to the above, this implements type safe variables. This means we use specific types such as sway_output and sway_workspace instead of generic containers or nodes. However, it's worth noting that in a few places places (eg. seat focus and transactions) referring to them in a generic way is unavoidable which is why we still use nodes in some places. If you want a TL;DR, look at node.h, as well as the struct definitions for root, output, workspace and container. Note that sway_output now contains a workspaces list, and workspaces now contain a tiling and floating list, and containers now contain a pointer back to the workspace. There are now functions for seat_get_focused_workspace and seat_get_focused_container. The latter will return NULL if a workspace itself is focused. Most other seat functions like seat_get_focus and seat_set_focus now accept and return nodes. In the config->handler_context struct, current_container has been replaced with three pointers: node, container and workspace. node is the same as what current_container was, while workspace is the workspace that the node resides on and container is the actual container, which may be NULL if a workspace itself is focused. The global root_container variable has been replaced with one simply called root, which is a pointer to the sway_root instance. The way outputs are created, enabled, disabled and destroyed has changed. Previously we'd wrap the sway_output in a container when it is enabled, but as we don't have containers any more it needs a different approach. The output_create and output_destroy functions previously created/destroyed the container, but now they create/destroy the sway_output. There is a new function output_disable to disable an output without destroying it. Containers have a new view property. If this is populated then the container is a view container, otherwise it's a layout container. Like before, this property is immutable for the life of the container. Containers have both a `sway_container *parent` and `sway_workspace *workspace`. As we use specific types now, parent cannot point to a workspace so it'll be NULL for containers which are direct children of the workspace. The workspace property is set for all containers, except those which are hidden in the scratchpad as they have no workspace. In some cases we need to refer to workspaces in a container-like way. For example, workspaces have layout and children, but when using specific types this makes it difficult. Likewise, it's difficult for a container to get its parent's layout when the parent could be another container or a workspace. To make it easier, some helper functions have been created: container_parent_layout and container_get_siblings. container_remove_child has been renamed to container_detach and container_replace_child has been renamed to container_replace. `container_handle_fullscreen_reparent(con, old_parent)` has had the old_parent removed. We now unfullscreen the workspace when detaching the container, so this function is simplified and only needs one argument now. container_notify_subtree_changed has been renamed to container_update_representation. This is more descriptive of its purpose. I also wanted to be able to call it with whatever container was changed rather than the container's parent, which makes bubbling up to the workspace easier. There are now state structs per node thing. ie. sway_output_state, sway_workspace_state and sway_container_state. The focus, move and layout commands have been completely refactored to work with the specific types. I considered making these a separate PR, but I'd be backporting my changes only to replace them again, and it's easier just to test everything at once.
This commit is contained in:
parent
309fcf2300
commit
7586f150c0
68 changed files with 3515 additions and 3509 deletions
|
|
@ -166,29 +166,23 @@ void arrange_container(struct sway_container *container) {
|
|||
if (config->reloading) {
|
||||
return;
|
||||
}
|
||||
if (container->type == C_VIEW) {
|
||||
view_autoconfigure(container->sway_view);
|
||||
container_set_dirty(container);
|
||||
return;
|
||||
}
|
||||
if (!sway_assert(container->type == C_CONTAINER, "Expected a container")) {
|
||||
if (container->view) {
|
||||
view_autoconfigure(container->view);
|
||||
node_set_dirty(&container->node);
|
||||
return;
|
||||
}
|
||||
struct wlr_box box;
|
||||
container_get_box(container, &box);
|
||||
arrange_children(container->children, container->layout, &box);
|
||||
container_set_dirty(container);
|
||||
node_set_dirty(&container->node);
|
||||
}
|
||||
|
||||
void arrange_workspace(struct sway_container *workspace) {
|
||||
void arrange_workspace(struct sway_workspace *workspace) {
|
||||
if (config->reloading) {
|
||||
return;
|
||||
}
|
||||
if (!sway_assert(workspace->type == C_WORKSPACE, "Expected a workspace")) {
|
||||
return;
|
||||
}
|
||||
struct sway_container *output = workspace->parent;
|
||||
struct wlr_box *area = &output->sway_output->usable_area;
|
||||
struct sway_output *output = workspace->output;
|
||||
struct wlr_box *area = &output->usable_area;
|
||||
wlr_log(WLR_DEBUG, "Usable area for ws: %dx%d@%d,%d",
|
||||
area->width, area->height, area->x, area->y);
|
||||
workspace_remove_gaps(workspace);
|
||||
|
|
@ -197,21 +191,20 @@ void arrange_workspace(struct sway_container *workspace) {
|
|||
double prev_y = workspace->y;
|
||||
workspace->width = area->width;
|
||||
workspace->height = area->height;
|
||||
workspace->x = output->x + area->x;
|
||||
workspace->y = output->y + area->y;
|
||||
workspace->x = output->wlr_output->lx + area->x;
|
||||
workspace->y = output->wlr_output->ly + area->y;
|
||||
|
||||
// Adjust any floating containers
|
||||
double diff_x = workspace->x - prev_x;
|
||||
double diff_y = workspace->y - prev_y;
|
||||
if (diff_x != 0 || diff_y != 0) {
|
||||
for (int i = 0; i < workspace->sway_workspace->floating->length; ++i) {
|
||||
struct sway_container *floater =
|
||||
workspace->sway_workspace->floating->items[i];
|
||||
for (int i = 0; i < workspace->floating->length; ++i) {
|
||||
struct sway_container *floater = workspace->floating->items[i];
|
||||
container_floating_translate(floater, diff_x, diff_y);
|
||||
double center_x = floater->x + floater->width / 2;
|
||||
double center_y = floater->y + floater->height / 2;
|
||||
struct wlr_box workspace_box;
|
||||
container_get_box(workspace, &workspace_box);
|
||||
workspace_get_box(workspace, &workspace_box);
|
||||
if (!wlr_box_contains_point(&workspace_box, center_x, center_y)) {
|
||||
container_floating_move_to_center(floater);
|
||||
}
|
||||
|
|
@ -219,43 +212,32 @@ void arrange_workspace(struct sway_container *workspace) {
|
|||
}
|
||||
|
||||
workspace_add_gaps(workspace);
|
||||
container_set_dirty(workspace);
|
||||
node_set_dirty(&workspace->node);
|
||||
wlr_log(WLR_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name,
|
||||
workspace->x, workspace->y);
|
||||
if (workspace->sway_workspace->fullscreen) {
|
||||
struct sway_container *fs = workspace->sway_workspace->fullscreen;
|
||||
fs->x = workspace->parent->x;
|
||||
fs->y = workspace->parent->y;
|
||||
fs->width = workspace->parent->width;
|
||||
fs->height = workspace->parent->height;
|
||||
if (workspace->fullscreen) {
|
||||
struct sway_container *fs = workspace->fullscreen;
|
||||
fs->x = output->wlr_output->lx;
|
||||
fs->y = output->wlr_output->ly;
|
||||
fs->width = output->wlr_output->width;
|
||||
fs->height = output->wlr_output->height;
|
||||
arrange_container(fs);
|
||||
} else {
|
||||
struct wlr_box box;
|
||||
container_get_box(workspace, &box);
|
||||
arrange_children(workspace->children, workspace->layout, &box);
|
||||
arrange_floating(workspace->sway_workspace->floating);
|
||||
workspace_get_box(workspace, &box);
|
||||
arrange_children(workspace->tiling, workspace->layout, &box);
|
||||
arrange_floating(workspace->floating);
|
||||
}
|
||||
}
|
||||
|
||||
void arrange_output(struct sway_container *output) {
|
||||
void arrange_output(struct sway_output *output) {
|
||||
if (config->reloading) {
|
||||
return;
|
||||
}
|
||||
if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) {
|
||||
return;
|
||||
}
|
||||
const struct wlr_box *output_box = wlr_output_layout_get_box(
|
||||
root_container.sway_root->output_layout,
|
||||
output->sway_output->wlr_output);
|
||||
output->x = output_box->x;
|
||||
output->y = output_box->y;
|
||||
output->width = output_box->width;
|
||||
output->height = output_box->height;
|
||||
container_set_dirty(output);
|
||||
wlr_log(WLR_DEBUG, "Arranging output '%s' at %f,%f",
|
||||
output->name, output->x, output->y);
|
||||
for (int i = 0; i < output->children->length; ++i) {
|
||||
struct sway_container *workspace = output->children->items[i];
|
||||
// Outputs have no pending x/y/width/height,
|
||||
// so all we do here is arrange the workspaces.
|
||||
for (int i = 0; i < output->workspaces->length; ++i) {
|
||||
struct sway_workspace *workspace = output->workspaces->items[i];
|
||||
arrange_workspace(workspace);
|
||||
}
|
||||
}
|
||||
|
|
@ -264,37 +246,31 @@ void arrange_root(void) {
|
|||
if (config->reloading) {
|
||||
return;
|
||||
}
|
||||
struct wlr_output_layout *output_layout =
|
||||
root_container.sway_root->output_layout;
|
||||
const struct wlr_box *layout_box =
|
||||
wlr_output_layout_get_box(output_layout, NULL);
|
||||
root_container.x = layout_box->x;
|
||||
root_container.y = layout_box->y;
|
||||
root_container.width = layout_box->width;
|
||||
root_container.height = layout_box->height;
|
||||
container_set_dirty(&root_container);
|
||||
for (int i = 0; i < root_container.children->length; ++i) {
|
||||
struct sway_container *output = root_container.children->items[i];
|
||||
wlr_output_layout_get_box(root->output_layout, NULL);
|
||||
root->x = layout_box->x;
|
||||
root->y = layout_box->y;
|
||||
root->width = layout_box->width;
|
||||
root->height = layout_box->height;
|
||||
for (int i = 0; i < root->outputs->length; ++i) {
|
||||
struct sway_output *output = root->outputs->items[i];
|
||||
arrange_output(output);
|
||||
}
|
||||
}
|
||||
|
||||
void arrange_windows(struct sway_container *container) {
|
||||
switch (container->type) {
|
||||
case C_ROOT:
|
||||
void arrange_node(struct sway_node *node) {
|
||||
switch (node->type) {
|
||||
case N_ROOT:
|
||||
arrange_root();
|
||||
break;
|
||||
case C_OUTPUT:
|
||||
arrange_output(container);
|
||||
case N_OUTPUT:
|
||||
arrange_output(node->sway_output);
|
||||
break;
|
||||
case C_WORKSPACE:
|
||||
arrange_workspace(container);
|
||||
case N_WORKSPACE:
|
||||
arrange_workspace(node->sway_workspace);
|
||||
break;
|
||||
case C_CONTAINER:
|
||||
case C_VIEW:
|
||||
arrange_container(container);
|
||||
break;
|
||||
case C_TYPES:
|
||||
case N_CONTAINER:
|
||||
arrange_container(node->sway_container);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
151
sway/tree/node.c
Normal file
151
sway/tree/node.c
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
#define _POSIX_C_SOURCE 200809L
|
||||
#include "sway/output.h"
|
||||
#include "sway/server.h"
|
||||
#include "sway/tree/container.h"
|
||||
#include "sway/tree/node.h"
|
||||
#include "sway/tree/root.h"
|
||||
#include "sway/tree/workspace.h"
|
||||
#include "log.h"
|
||||
|
||||
void node_init(struct sway_node *node, enum sway_node_type type, void *thing) {
|
||||
static size_t next_id = 1;
|
||||
node->id = next_id++;
|
||||
node->type = type;
|
||||
node->sway_root = thing;
|
||||
wl_signal_init(&node->events.destroy);
|
||||
}
|
||||
|
||||
const char *node_type_to_str(enum sway_node_type type) {
|
||||
switch (type) {
|
||||
case N_ROOT:
|
||||
return "N_ROOT";
|
||||
case N_OUTPUT:
|
||||
return "N_OUTPUT";
|
||||
case N_WORKSPACE:
|
||||
return "N_WORKSPACE";
|
||||
case N_CONTAINER:
|
||||
return "N_CONTAINER";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void node_set_dirty(struct sway_node *node) {
|
||||
if (node->dirty) {
|
||||
return;
|
||||
}
|
||||
node->dirty = true;
|
||||
list_add(server.dirty_nodes, node);
|
||||
}
|
||||
|
||||
bool node_is_view(struct sway_node *node) {
|
||||
return node->type == N_CONTAINER && node->sway_container->view;
|
||||
}
|
||||
|
||||
char *node_get_name(struct sway_node *node) {
|
||||
switch (node->type) {
|
||||
case N_ROOT:
|
||||
return "root";
|
||||
case N_OUTPUT:
|
||||
return node->sway_output->wlr_output->name;
|
||||
case N_WORKSPACE:
|
||||
return node->sway_workspace->name;
|
||||
case N_CONTAINER:
|
||||
return node->sway_container->title;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void node_get_box(struct sway_node *node, struct wlr_box *box) {
|
||||
switch (node->type) {
|
||||
case N_ROOT:
|
||||
root_get_box(root, box);
|
||||
break;
|
||||
case N_OUTPUT:
|
||||
output_get_box(node->sway_output, box);
|
||||
break;
|
||||
case N_WORKSPACE:
|
||||
workspace_get_box(node->sway_workspace, box);
|
||||
break;
|
||||
case N_CONTAINER:
|
||||
container_get_box(node->sway_container, box);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
struct sway_output *node_get_output(struct sway_node *node) {
|
||||
switch (node->type) {
|
||||
case N_CONTAINER:
|
||||
return node->sway_container->workspace->output;
|
||||
case N_WORKSPACE:
|
||||
return node->sway_workspace->output;
|
||||
case N_OUTPUT:
|
||||
return node->sway_output;
|
||||
case N_ROOT:
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
enum sway_container_layout node_get_layout(struct sway_node *node) {
|
||||
switch (node->type) {
|
||||
case N_CONTAINER:
|
||||
return node->sway_container->layout;
|
||||
case N_WORKSPACE:
|
||||
return node->sway_workspace->layout;
|
||||
case N_OUTPUT:
|
||||
case N_ROOT:
|
||||
return L_NONE;
|
||||
}
|
||||
return L_NONE;
|
||||
}
|
||||
|
||||
struct sway_node *node_get_parent(struct sway_node *node) {
|
||||
switch (node->type) {
|
||||
case N_CONTAINER: {
|
||||
struct sway_container *con = node->sway_container;
|
||||
if (con->parent) {
|
||||
return &con->parent->node;
|
||||
}
|
||||
if (con->workspace) {
|
||||
return &con->workspace->node;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
case N_WORKSPACE: {
|
||||
struct sway_workspace *ws = node->sway_workspace;
|
||||
if (ws->output) {
|
||||
return &ws->output->node;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
case N_OUTPUT:
|
||||
return &root->node;
|
||||
case N_ROOT:
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
list_t *node_get_children(struct sway_node *node) {
|
||||
switch (node->type) {
|
||||
case N_CONTAINER:
|
||||
return node->sway_container->children;
|
||||
case N_WORKSPACE:
|
||||
return node->sway_workspace->tiling;
|
||||
case N_OUTPUT:
|
||||
case N_ROOT:
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool node_has_ancestor(struct sway_node *node, struct sway_node *ancestor) {
|
||||
struct sway_node *parent = node_get_parent(node);
|
||||
while (parent) {
|
||||
if (parent == ancestor) {
|
||||
return true;
|
||||
}
|
||||
parent = node_get_parent(parent);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -2,28 +2,31 @@
|
|||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <wlr/types/wlr_output_damage.h>
|
||||
#include "sway/ipc-server.h"
|
||||
#include "sway/layers.h"
|
||||
#include "sway/output.h"
|
||||
#include "sway/tree/arrange.h"
|
||||
#include "sway/tree/output.h"
|
||||
#include "sway/tree/workspace.h"
|
||||
#include "log.h"
|
||||
#include "util.h"
|
||||
|
||||
static void restore_workspaces(struct sway_container *output) {
|
||||
static void restore_workspaces(struct sway_output *output) {
|
||||
// Workspace output priority
|
||||
for (int i = 0; i < root_container.children->length; i++) {
|
||||
struct sway_container *other = root_container.children->items[i];
|
||||
for (int i = 0; i < root->outputs->length; i++) {
|
||||
struct sway_output *other = root->outputs->items[i];
|
||||
if (other == output) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 0; j < other->children->length; j++) {
|
||||
struct sway_container *ws = other->children->items[j];
|
||||
struct sway_container *highest =
|
||||
for (int j = 0; j < other->workspaces->length; j++) {
|
||||
struct sway_workspace *ws = other->workspaces->items[j];
|
||||
struct sway_output *highest =
|
||||
workspace_output_get_highest_available(ws, NULL);
|
||||
if (highest == output) {
|
||||
container_remove_child(ws);
|
||||
container_add_child(output, ws);
|
||||
workspace_detach(ws);
|
||||
output_add_workspace(output, ws);
|
||||
ipc_event_workspace(NULL, ws, "move");
|
||||
j--;
|
||||
}
|
||||
|
|
@ -31,22 +34,197 @@ static void restore_workspaces(struct sway_container *output) {
|
|||
}
|
||||
|
||||
// Saved workspaces
|
||||
list_t *saved = root_container.sway_root->saved_workspaces;
|
||||
for (int i = 0; i < saved->length; ++i) {
|
||||
struct sway_container *ws = saved->items[i];
|
||||
container_add_child(output, ws);
|
||||
for (int i = 0; i < root->saved_workspaces->length; ++i) {
|
||||
struct sway_workspace *ws = root->saved_workspaces->items[i];
|
||||
output_add_workspace(output, ws);
|
||||
ipc_event_workspace(NULL, ws, "move");
|
||||
}
|
||||
saved->length = 0;
|
||||
root->saved_workspaces->length = 0;
|
||||
|
||||
output_sort_workspaces(output);
|
||||
}
|
||||
|
||||
struct sway_container *output_create(
|
||||
struct sway_output *sway_output) {
|
||||
const char *name = sway_output->wlr_output->name;
|
||||
struct sway_output *output_create(struct wlr_output *wlr_output) {
|
||||
struct sway_output *output = calloc(1, sizeof(struct sway_output));
|
||||
node_init(&output->node, N_OUTPUT, output);
|
||||
output->wlr_output = wlr_output;
|
||||
wlr_output->data = output;
|
||||
|
||||
wl_signal_add(&wlr_output->events.destroy, &output->destroy);
|
||||
|
||||
wl_list_insert(&root->all_outputs, &output->link);
|
||||
|
||||
if (!wl_list_empty(&wlr_output->modes)) {
|
||||
struct wlr_output_mode *mode =
|
||||
wl_container_of(wlr_output->modes.prev, mode, link);
|
||||
wlr_output_set_mode(wlr_output, mode);
|
||||
}
|
||||
|
||||
output->workspaces = create_list();
|
||||
output->current.workspaces = create_list();
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
void output_enable(struct sway_output *output, struct output_config *oc) {
|
||||
if (!sway_assert(!output->enabled, "output is already enabled")) {
|
||||
return;
|
||||
}
|
||||
struct wlr_output *wlr_output = output->wlr_output;
|
||||
output->enabled = true;
|
||||
apply_output_config(oc, output);
|
||||
list_add(root->outputs, output);
|
||||
|
||||
restore_workspaces(output);
|
||||
|
||||
if (!output->workspaces->length) {
|
||||
// Create workspace
|
||||
char *ws_name = workspace_next_name(wlr_output->name);
|
||||
wlr_log(WLR_DEBUG, "Creating default workspace %s", ws_name);
|
||||
struct sway_workspace *ws = workspace_create(output, ws_name);
|
||||
// Set each seat's focus if not already set
|
||||
struct sway_seat *seat = NULL;
|
||||
wl_list_for_each(seat, &input_manager->seats, link) {
|
||||
if (!seat->has_focus) {
|
||||
seat_set_focus(seat, &ws->node);
|
||||
}
|
||||
}
|
||||
free(ws_name);
|
||||
}
|
||||
|
||||
size_t len = sizeof(output->layers) / sizeof(output->layers[0]);
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
wl_list_init(&output->layers[i]);
|
||||
}
|
||||
wl_signal_init(&output->events.destroy);
|
||||
|
||||
input_manager_configure_xcursor(input_manager);
|
||||
|
||||
wl_signal_add(&wlr_output->events.mode, &output->mode);
|
||||
wl_signal_add(&wlr_output->events.transform, &output->transform);
|
||||
wl_signal_add(&wlr_output->events.scale, &output->scale);
|
||||
wl_signal_add(&output->damage->events.frame, &output->damage_frame);
|
||||
wl_signal_add(&output->damage->events.destroy, &output->damage_destroy);
|
||||
|
||||
output_add_listeners(output);
|
||||
|
||||
wl_signal_emit(&root->events.new_node, &output->node);
|
||||
|
||||
load_swaybars();
|
||||
|
||||
arrange_layers(output);
|
||||
arrange_root();
|
||||
}
|
||||
|
||||
static void output_evacuate(struct sway_output *output) {
|
||||
if (!output->workspaces->length) {
|
||||
return;
|
||||
}
|
||||
struct sway_output *fallback_output = NULL;
|
||||
if (root->outputs->length > 1) {
|
||||
fallback_output = root->outputs->items[0];
|
||||
if (fallback_output == output) {
|
||||
fallback_output = root->outputs->items[1];
|
||||
}
|
||||
}
|
||||
|
||||
while (output->workspaces->length) {
|
||||
struct sway_workspace *workspace = output->workspaces->items[0];
|
||||
|
||||
workspace_detach(workspace);
|
||||
|
||||
if (workspace_is_empty(workspace)) {
|
||||
workspace_begin_destroy(workspace);
|
||||
continue;
|
||||
}
|
||||
|
||||
struct sway_output *new_output =
|
||||
workspace_output_get_highest_available(workspace, output);
|
||||
if (!new_output) {
|
||||
new_output = fallback_output;
|
||||
}
|
||||
|
||||
if (new_output) {
|
||||
workspace_output_add_priority(workspace, new_output);
|
||||
output_add_workspace(new_output, workspace);
|
||||
output_sort_workspaces(new_output);
|
||||
ipc_event_workspace(NULL, workspace, "move");
|
||||
} else {
|
||||
list_add(root->saved_workspaces, workspace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void output_destroy(struct sway_output *output) {
|
||||
if (!sway_assert(output->node.destroying,
|
||||
"Tried to free output which wasn't marked as destroying")) {
|
||||
return;
|
||||
}
|
||||
if (!sway_assert(output->wlr_output == NULL,
|
||||
"Tried to free output which still had a wlr_output")) {
|
||||
return;
|
||||
}
|
||||
if (!sway_assert(output->node.ntxnrefs == 0, "Tried to free output "
|
||||
"which is still referenced by transactions")) {
|
||||
return;
|
||||
}
|
||||
list_free(output->workspaces);
|
||||
list_free(output->current.workspaces);
|
||||
free(output);
|
||||
}
|
||||
|
||||
static void untrack_output(struct sway_container *con, void *data) {
|
||||
struct sway_output *output = data;
|
||||
int index = list_find(con->outputs, output);
|
||||
if (index != -1) {
|
||||
list_del(con->outputs, index);
|
||||
}
|
||||
}
|
||||
|
||||
void output_disable(struct sway_output *output) {
|
||||
if (!sway_assert(output->enabled, "Expected an enabled output")) {
|
||||
return;
|
||||
}
|
||||
wlr_log(WLR_DEBUG, "Disabling output '%s'", output->wlr_output->name);
|
||||
wl_signal_emit(&output->events.destroy, output);
|
||||
|
||||
output_evacuate(output);
|
||||
|
||||
root_for_each_container(untrack_output, output);
|
||||
|
||||
int index = list_find(root->outputs, output);
|
||||
list_del(root->outputs, index);
|
||||
|
||||
wl_list_remove(&output->mode.link);
|
||||
wl_list_remove(&output->transform.link);
|
||||
wl_list_remove(&output->scale.link);
|
||||
wl_list_remove(&output->damage_destroy.link);
|
||||
wl_list_remove(&output->damage_frame.link);
|
||||
|
||||
output->enabled = false;
|
||||
|
||||
arrange_root();
|
||||
}
|
||||
|
||||
void output_begin_destroy(struct sway_output *output) {
|
||||
if (!sway_assert(!output->enabled, "Expected a disabled output")) {
|
||||
return;
|
||||
}
|
||||
wlr_log(WLR_DEBUG, "Destroying output '%s'", output->wlr_output->name);
|
||||
|
||||
output->node.destroying = true;
|
||||
node_set_dirty(&output->node);
|
||||
|
||||
wl_list_remove(&output->link);
|
||||
wl_list_remove(&output->destroy.link);
|
||||
output->wlr_output->data = NULL;
|
||||
output->wlr_output = NULL;
|
||||
}
|
||||
|
||||
struct output_config *output_find_config(struct sway_output *output) {
|
||||
const char *name = output->wlr_output->name;
|
||||
char identifier[128];
|
||||
output_get_identifier(identifier, sizeof(identifier), sway_output);
|
||||
output_get_identifier(identifier, sizeof(identifier), output);
|
||||
|
||||
struct output_config *oc = NULL, *all = NULL;
|
||||
for (int i = 0; i < config->output_configs->length; ++i) {
|
||||
|
|
@ -73,189 +251,61 @@ struct sway_container *output_create(
|
|||
if (oc && !oc->enabled) {
|
||||
return NULL;
|
||||
}
|
||||
return oc;
|
||||
}
|
||||
|
||||
struct sway_container *output = container_create(C_OUTPUT);
|
||||
output->sway_output = sway_output;
|
||||
output->name = strdup(name);
|
||||
if (output->name == NULL) {
|
||||
output_begin_destroy(output);
|
||||
struct sway_output *output_from_wlr_output(struct wlr_output *output) {
|
||||
return output->data;
|
||||
}
|
||||
|
||||
struct sway_output *output_get_in_direction(struct sway_output *reference,
|
||||
enum movement_direction direction) {
|
||||
enum wlr_direction wlr_dir = 0;
|
||||
if (!sway_assert(sway_dir_to_wlr(direction, &wlr_dir),
|
||||
"got invalid direction: %d", direction)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
apply_output_config(oc, output);
|
||||
container_add_child(&root_container, output);
|
||||
load_swaybars();
|
||||
|
||||
struct wlr_box size;
|
||||
wlr_output_effective_resolution(sway_output->wlr_output, &size.width,
|
||||
&size.height);
|
||||
output->width = size.width;
|
||||
output->height = size.height;
|
||||
|
||||
restore_workspaces(output);
|
||||
|
||||
if (!output->children->length) {
|
||||
// Create workspace
|
||||
char *ws_name = workspace_next_name(output->name);
|
||||
wlr_log(WLR_DEBUG, "Creating default workspace %s", ws_name);
|
||||
struct sway_container *ws = workspace_create(output, ws_name);
|
||||
// Set each seat's focus if not already set
|
||||
struct sway_seat *seat = NULL;
|
||||
wl_list_for_each(seat, &input_manager->seats, link) {
|
||||
if (!seat->has_focus) {
|
||||
seat_set_focus(seat, ws);
|
||||
}
|
||||
}
|
||||
free(ws_name);
|
||||
}
|
||||
|
||||
container_create_notify(output);
|
||||
return output;
|
||||
}
|
||||
|
||||
static void output_evacuate(struct sway_container *output) {
|
||||
if (!output->children->length) {
|
||||
return;
|
||||
}
|
||||
struct sway_container *fallback_output = NULL;
|
||||
if (root_container.children->length > 1) {
|
||||
fallback_output = root_container.children->items[0];
|
||||
if (fallback_output == output) {
|
||||
fallback_output = root_container.children->items[1];
|
||||
}
|
||||
}
|
||||
|
||||
while (output->children->length) {
|
||||
struct sway_container *workspace = output->children->items[0];
|
||||
|
||||
container_remove_child(workspace);
|
||||
|
||||
if (workspace_is_empty(workspace)) {
|
||||
workspace_begin_destroy(workspace);
|
||||
continue;
|
||||
}
|
||||
|
||||
struct sway_container *new_output =
|
||||
workspace_output_get_highest_available(workspace, output);
|
||||
if (!new_output) {
|
||||
new_output = fallback_output;
|
||||
}
|
||||
|
||||
if (new_output) {
|
||||
workspace_output_add_priority(workspace, new_output);
|
||||
container_add_child(new_output, workspace);
|
||||
output_sort_workspaces(new_output);
|
||||
ipc_event_workspace(NULL, workspace, "move");
|
||||
} else {
|
||||
list_add(root_container.sway_root->saved_workspaces, workspace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void output_destroy(struct sway_container *output) {
|
||||
if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) {
|
||||
return;
|
||||
}
|
||||
if (!sway_assert(output->destroying,
|
||||
"Tried to free output which wasn't marked as destroying")) {
|
||||
return;
|
||||
}
|
||||
if (!sway_assert(output->ntxnrefs == 0, "Tried to free output "
|
||||
"which is still referenced by transactions")) {
|
||||
return;
|
||||
}
|
||||
free(output->name);
|
||||
free(output->formatted_title);
|
||||
wlr_texture_destroy(output->title_focused);
|
||||
wlr_texture_destroy(output->title_focused_inactive);
|
||||
wlr_texture_destroy(output->title_unfocused);
|
||||
wlr_texture_destroy(output->title_urgent);
|
||||
list_free(output->children);
|
||||
list_free(output->current.children);
|
||||
list_free(output->outputs);
|
||||
free(output);
|
||||
|
||||
// NOTE: We don't actually destroy the sway_output here
|
||||
}
|
||||
|
||||
static void untrack_output(struct sway_container *con, void *data) {
|
||||
struct sway_output *output = data;
|
||||
int index = list_find(con->outputs, output);
|
||||
if (index != -1) {
|
||||
list_del(con->outputs, index);
|
||||
}
|
||||
}
|
||||
|
||||
void output_begin_destroy(struct sway_container *output) {
|
||||
if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) {
|
||||
return;
|
||||
}
|
||||
wlr_log(WLR_DEBUG, "OUTPUT: Destroying output '%s'", output->name);
|
||||
wl_signal_emit(&output->events.destroy, output);
|
||||
|
||||
output_evacuate(output);
|
||||
|
||||
output->destroying = true;
|
||||
container_set_dirty(output);
|
||||
|
||||
root_for_each_container(untrack_output, output->sway_output);
|
||||
|
||||
wl_list_remove(&output->sway_output->mode.link);
|
||||
wl_list_remove(&output->sway_output->transform.link);
|
||||
wl_list_remove(&output->sway_output->scale.link);
|
||||
wl_list_remove(&output->sway_output->damage_destroy.link);
|
||||
wl_list_remove(&output->sway_output->damage_frame.link);
|
||||
|
||||
output->sway_output->swayc = NULL;
|
||||
output->sway_output = NULL;
|
||||
|
||||
if (output->parent) {
|
||||
container_remove_child(output);
|
||||
}
|
||||
}
|
||||
|
||||
struct sway_container *output_from_wlr_output(struct wlr_output *output) {
|
||||
if (output == NULL) {
|
||||
int lx = reference->wlr_output->lx + reference->wlr_output->width / 2;
|
||||
int ly = reference->wlr_output->ly + reference->wlr_output->height / 2;
|
||||
struct wlr_output *wlr_adjacent = wlr_output_layout_adjacent_output(
|
||||
root->output_layout, wlr_dir, reference->wlr_output, lx, ly);
|
||||
if (!wlr_adjacent) {
|
||||
return NULL;
|
||||
}
|
||||
for (int i = 0; i < root_container.children->length; ++i) {
|
||||
struct sway_container *o = root_container.children->items[i];
|
||||
if (o->type == C_OUTPUT && o->sway_output->wlr_output == output) {
|
||||
return o;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return output_from_wlr_output(wlr_adjacent);
|
||||
}
|
||||
|
||||
void output_for_each_workspace(struct sway_container *output,
|
||||
void (*f)(struct sway_container *con, void *data), void *data) {
|
||||
if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) {
|
||||
return;
|
||||
void output_add_workspace(struct sway_output *output,
|
||||
struct sway_workspace *workspace) {
|
||||
if (workspace->output) {
|
||||
workspace_detach(workspace);
|
||||
}
|
||||
for (int i = 0; i < output->children->length; ++i) {
|
||||
struct sway_container *workspace = output->children->items[i];
|
||||
list_add(output->workspaces, workspace);
|
||||
workspace->output = output;
|
||||
node_set_dirty(&output->node);
|
||||
node_set_dirty(&workspace->node);
|
||||
}
|
||||
|
||||
void output_for_each_workspace(struct sway_output *output,
|
||||
void (*f)(struct sway_workspace *ws, void *data), void *data) {
|
||||
for (int i = 0; i < output->workspaces->length; ++i) {
|
||||
struct sway_workspace *workspace = output->workspaces->items[i];
|
||||
f(workspace, data);
|
||||
}
|
||||
}
|
||||
|
||||
void output_for_each_container(struct sway_container *output,
|
||||
void output_for_each_container(struct sway_output *output,
|
||||
void (*f)(struct sway_container *con, void *data), void *data) {
|
||||
if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < output->children->length; ++i) {
|
||||
struct sway_container *workspace = output->children->items[i];
|
||||
for (int i = 0; i < output->workspaces->length; ++i) {
|
||||
struct sway_workspace *workspace = output->workspaces->items[i];
|
||||
workspace_for_each_container(workspace, f, data);
|
||||
}
|
||||
}
|
||||
|
||||
struct sway_container *output_find_workspace(struct sway_container *output,
|
||||
bool (*test)(struct sway_container *con, void *data), void *data) {
|
||||
if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) {
|
||||
return NULL;
|
||||
}
|
||||
for (int i = 0; i < output->children->length; ++i) {
|
||||
struct sway_container *workspace = output->children->items[i];
|
||||
struct sway_workspace *output_find_workspace(struct sway_output *output,
|
||||
bool (*test)(struct sway_workspace *ws, void *data), void *data) {
|
||||
for (int i = 0; i < output->workspaces->length; ++i) {
|
||||
struct sway_workspace *workspace = output->workspaces->items[i];
|
||||
if (test(workspace, data)) {
|
||||
return workspace;
|
||||
}
|
||||
|
|
@ -263,14 +313,11 @@ struct sway_container *output_find_workspace(struct sway_container *output,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct sway_container *output_find_container(struct sway_container *output,
|
||||
struct sway_container *output_find_container(struct sway_output *output,
|
||||
bool (*test)(struct sway_container *con, void *data), void *data) {
|
||||
if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) {
|
||||
return NULL;
|
||||
}
|
||||
struct sway_container *result = NULL;
|
||||
for (int i = 0; i < output->children->length; ++i) {
|
||||
struct sway_container *workspace = output->children->items[i];
|
||||
for (int i = 0; i < output->workspaces->length; ++i) {
|
||||
struct sway_workspace *workspace = output->workspaces->items[i];
|
||||
if ((result = workspace_find_container(workspace, test, data))) {
|
||||
return result;
|
||||
}
|
||||
|
|
@ -279,8 +326,8 @@ struct sway_container *output_find_container(struct sway_container *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;
|
||||
struct sway_workspace *a = *(void **)_a;
|
||||
struct sway_workspace *b = *(void **)_b;
|
||||
|
||||
if (isdigit(a->name[0]) && isdigit(b->name[0])) {
|
||||
int a_num = strtol(a->name, NULL, 10);
|
||||
|
|
@ -294,6 +341,27 @@ static int sort_workspace_cmp_qsort(const void *_a, const void *_b) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void output_sort_workspaces(struct sway_container *output) {
|
||||
list_stable_sort(output->children, sort_workspace_cmp_qsort);
|
||||
void output_sort_workspaces(struct sway_output *output) {
|
||||
list_stable_sort(output->workspaces, sort_workspace_cmp_qsort);
|
||||
}
|
||||
|
||||
void output_get_box(struct sway_output *output, struct wlr_box *box) {
|
||||
box->x = output->wlr_output->lx;
|
||||
box->y = output->wlr_output->ly;
|
||||
box->width = output->wlr_output->width;
|
||||
box->height = output->wlr_output->height;
|
||||
}
|
||||
|
||||
enum sway_container_layout output_get_default_layout(
|
||||
struct sway_output *output) {
|
||||
if (config->default_layout != L_NONE) {
|
||||
return config->default_layout;
|
||||
}
|
||||
if (config->default_orientation != L_NONE) {
|
||||
return config->default_orientation;
|
||||
}
|
||||
if (output->wlr_output->height > output->wlr_output->width) {
|
||||
return L_VERT;
|
||||
}
|
||||
return L_HORIZ;
|
||||
}
|
||||
|
|
|
|||
184
sway/tree/root.c
184
sway/tree/root.c
|
|
@ -14,54 +14,45 @@
|
|||
#include "log.h"
|
||||
#include "util.h"
|
||||
|
||||
struct sway_container root_container;
|
||||
struct sway_root *root;
|
||||
|
||||
static void output_layout_handle_change(struct wl_listener *listener,
|
||||
void *data) {
|
||||
arrange_windows(&root_container);
|
||||
arrange_root();
|
||||
transaction_commit_dirty();
|
||||
}
|
||||
|
||||
void root_create(void) {
|
||||
root_container.id = 0; // normally assigned in new_swayc()
|
||||
root_container.type = C_ROOT;
|
||||
root_container.layout = L_NONE;
|
||||
root_container.name = strdup("root");
|
||||
root_container.children = create_list();
|
||||
root_container.current.children = create_list();
|
||||
wl_signal_init(&root_container.events.destroy);
|
||||
|
||||
root_container.sway_root = calloc(1, sizeof(*root_container.sway_root));
|
||||
root_container.sway_root->output_layout = wlr_output_layout_create();
|
||||
wl_list_init(&root_container.sway_root->all_outputs);
|
||||
struct sway_root *root_create(void) {
|
||||
struct sway_root *root = calloc(1, sizeof(struct sway_root));
|
||||
if (!root) {
|
||||
wlr_log(WLR_ERROR, "Unable to allocate sway_root");
|
||||
return NULL;
|
||||
}
|
||||
node_init(&root->node, N_ROOT, root);
|
||||
root->output_layout = wlr_output_layout_create();
|
||||
wl_list_init(&root->all_outputs);
|
||||
#ifdef HAVE_XWAYLAND
|
||||
wl_list_init(&root_container.sway_root->xwayland_unmanaged);
|
||||
wl_list_init(&root->xwayland_unmanaged);
|
||||
#endif
|
||||
wl_list_init(&root_container.sway_root->drag_icons);
|
||||
wl_signal_init(&root_container.sway_root->events.new_container);
|
||||
root_container.sway_root->scratchpad = create_list();
|
||||
root_container.sway_root->saved_workspaces = create_list();
|
||||
wl_list_init(&root->drag_icons);
|
||||
wl_signal_init(&root->events.new_node);
|
||||
root->outputs = create_list();
|
||||
root->scratchpad = create_list();
|
||||
root->saved_workspaces = create_list();
|
||||
|
||||
root_container.sway_root->output_layout_change.notify =
|
||||
output_layout_handle_change;
|
||||
wl_signal_add(&root_container.sway_root->output_layout->events.change,
|
||||
&root_container.sway_root->output_layout_change);
|
||||
root->output_layout_change.notify = output_layout_handle_change;
|
||||
wl_signal_add(&root->output_layout->events.change,
|
||||
&root->output_layout_change);
|
||||
return root;
|
||||
}
|
||||
|
||||
void root_destroy(void) {
|
||||
// sway_root
|
||||
wl_list_remove(&root_container.sway_root->output_layout_change.link);
|
||||
list_free(root_container.sway_root->scratchpad);
|
||||
list_free(root_container.sway_root->saved_workspaces);
|
||||
wlr_output_layout_destroy(root_container.sway_root->output_layout);
|
||||
free(root_container.sway_root);
|
||||
|
||||
// root_container
|
||||
list_free(root_container.children);
|
||||
list_free(root_container.current.children);
|
||||
free(root_container.name);
|
||||
|
||||
memset(&root_container, 0, sizeof(root_container));
|
||||
void root_destroy(struct sway_root *root) {
|
||||
wl_list_remove(&root->output_layout_change.link);
|
||||
list_free(root->scratchpad);
|
||||
list_free(root->saved_workspaces);
|
||||
list_free(root->outputs);
|
||||
wlr_output_layout_destroy(root->output_layout);
|
||||
free(root);
|
||||
}
|
||||
|
||||
void root_scratchpad_add_container(struct sway_container *con) {
|
||||
|
|
@ -69,15 +60,21 @@ void root_scratchpad_add_container(struct sway_container *con) {
|
|||
return;
|
||||
}
|
||||
con->scratchpad = true;
|
||||
list_add(root_container.sway_root->scratchpad, con);
|
||||
list_add(root->scratchpad, con);
|
||||
|
||||
struct sway_container *parent = con->parent;
|
||||
struct sway_workspace *workspace = con->workspace;
|
||||
container_set_floating(con, true);
|
||||
container_remove_child(con);
|
||||
arrange_windows(parent);
|
||||
container_detach(con);
|
||||
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
seat_set_focus(seat, seat_get_focus_inactive(seat, parent));
|
||||
if (parent) {
|
||||
arrange_container(parent);
|
||||
seat_set_focus(seat, seat_get_focus_inactive(seat, &parent->node));
|
||||
} else {
|
||||
arrange_workspace(workspace);
|
||||
seat_set_focus(seat, seat_get_focus_inactive(seat, &workspace->node));
|
||||
}
|
||||
}
|
||||
|
||||
void root_scratchpad_remove_container(struct sway_container *con) {
|
||||
|
|
@ -85,28 +82,25 @@ void root_scratchpad_remove_container(struct sway_container *con) {
|
|||
return;
|
||||
}
|
||||
con->scratchpad = false;
|
||||
int index = list_find(root_container.sway_root->scratchpad, con);
|
||||
int index = list_find(root->scratchpad, con);
|
||||
if (index != -1) {
|
||||
list_del(root_container.sway_root->scratchpad, index);
|
||||
list_del(root->scratchpad, index);
|
||||
}
|
||||
}
|
||||
|
||||
void root_scratchpad_show(struct sway_container *con) {
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_container *ws = seat_get_focus(seat);
|
||||
if (ws->type != C_WORKSPACE) {
|
||||
ws = container_parent(ws, C_WORKSPACE);
|
||||
}
|
||||
struct sway_workspace *ws = seat_get_focused_workspace(seat);
|
||||
|
||||
// If the current con or any of its parents are in fullscreen mode, we
|
||||
// first need to disable it before showing the scratchpad con.
|
||||
if (ws->sway_workspace->fullscreen) {
|
||||
container_set_fullscreen(ws->sway_workspace->fullscreen, false);
|
||||
if (ws->fullscreen) {
|
||||
container_set_fullscreen(ws->fullscreen, false);
|
||||
}
|
||||
|
||||
// Show the container
|
||||
if (con->parent) {
|
||||
container_remove_child(con);
|
||||
if (con->workspace) {
|
||||
container_detach(con);
|
||||
}
|
||||
workspace_add_floating(ws, con);
|
||||
|
||||
|
|
@ -115,7 +109,7 @@ void root_scratchpad_show(struct sway_container *con) {
|
|||
double center_ly = con->y + con->height / 2;
|
||||
|
||||
struct wlr_box workspace_box;
|
||||
container_get_box(ws, &workspace_box);
|
||||
workspace_get_box(ws, &workspace_box);
|
||||
if (!wlr_box_contains_point(&workspace_box, center_lx, center_ly)) {
|
||||
// Maybe resize it
|
||||
if (con->width > ws->width || con->height > ws->height) {
|
||||
|
|
@ -128,23 +122,21 @@ void root_scratchpad_show(struct sway_container *con) {
|
|||
container_floating_move_to(con, new_lx, new_ly);
|
||||
}
|
||||
|
||||
arrange_windows(ws);
|
||||
seat_set_focus(seat, seat_get_focus_inactive(seat, con));
|
||||
|
||||
container_set_dirty(con->parent);
|
||||
arrange_workspace(ws);
|
||||
seat_set_focus(seat, seat_get_focus_inactive(seat, &con->node));
|
||||
}
|
||||
|
||||
void root_scratchpad_hide(struct sway_container *con) {
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_container *focus = seat_get_focus(seat);
|
||||
struct sway_container *ws = container_parent(con, C_WORKSPACE);
|
||||
struct sway_node *focus = seat_get_focus(seat);
|
||||
struct sway_workspace *ws = con->workspace;
|
||||
|
||||
container_remove_child(con);
|
||||
arrange_windows(ws);
|
||||
if (con == focus) {
|
||||
seat_set_focus(seat, seat_get_focus_inactive(seat, ws));
|
||||
container_detach(con);
|
||||
arrange_workspace(ws);
|
||||
if (&con->node == focus) {
|
||||
seat_set_focus(seat, seat_get_focus_inactive(seat, &ws->node));
|
||||
}
|
||||
list_move_to_end(root_container.sway_root->scratchpad, con);
|
||||
list_move_to_end(root->scratchpad, con);
|
||||
}
|
||||
|
||||
struct pid_workspace {
|
||||
|
|
@ -152,7 +144,7 @@ struct pid_workspace {
|
|||
char *workspace;
|
||||
struct timespec time_added;
|
||||
|
||||
struct sway_container *output;
|
||||
struct sway_output *output;
|
||||
struct wl_listener output_destroy;
|
||||
|
||||
struct wl_list link;
|
||||
|
|
@ -160,13 +152,13 @@ struct pid_workspace {
|
|||
|
||||
static struct wl_list pid_workspaces;
|
||||
|
||||
struct sway_container *root_workspace_for_pid(pid_t pid) {
|
||||
struct sway_workspace *root_workspace_for_pid(pid_t pid) {
|
||||
if (!pid_workspaces.prev && !pid_workspaces.next) {
|
||||
wl_list_init(&pid_workspaces);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct sway_container *ws = NULL;
|
||||
struct sway_workspace *ws = NULL;
|
||||
struct pid_workspace *pw = NULL;
|
||||
|
||||
wlr_log(WLR_DEBUG, "Looking up workspace for pid %d", pid);
|
||||
|
|
@ -219,16 +211,12 @@ void root_record_workspace_pid(pid_t pid) {
|
|||
}
|
||||
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_container *ws =
|
||||
seat_get_focus_inactive(seat, &root_container);
|
||||
if (ws && ws->type != C_WORKSPACE) {
|
||||
ws = container_parent(ws, C_WORKSPACE);
|
||||
}
|
||||
struct sway_workspace *ws = seat_get_focused_workspace(seat);
|
||||
if (!ws) {
|
||||
wlr_log(WLR_DEBUG, "Bailing out, no workspace");
|
||||
return;
|
||||
}
|
||||
struct sway_container *output = ws->parent;
|
||||
struct sway_output *output = ws->output;
|
||||
if (!output) {
|
||||
wlr_log(WLR_DEBUG, "Bailing out, no output");
|
||||
return;
|
||||
|
|
@ -255,30 +243,28 @@ void root_record_workspace_pid(pid_t pid) {
|
|||
pw->pid = pid;
|
||||
memcpy(&pw->time_added, &now, sizeof(struct timespec));
|
||||
pw->output_destroy.notify = pw_handle_output_destroy;
|
||||
wl_signal_add(&output->sway_output->wlr_output->events.destroy,
|
||||
&pw->output_destroy);
|
||||
wl_signal_add(&output->wlr_output->events.destroy, &pw->output_destroy);
|
||||
wl_list_insert(&pid_workspaces, &pw->link);
|
||||
}
|
||||
|
||||
void root_for_each_workspace(void (*f)(struct sway_container *con, void *data),
|
||||
void root_for_each_workspace(void (*f)(struct sway_workspace *ws, void *data),
|
||||
void *data) {
|
||||
for (int i = 0; i < root_container.children->length; ++i) {
|
||||
struct sway_container *output = root_container.children->items[i];
|
||||
for (int i = 0; i < root->outputs->length; ++i) {
|
||||
struct sway_output *output = root->outputs->items[i];
|
||||
output_for_each_workspace(output, f, data);
|
||||
}
|
||||
}
|
||||
|
||||
void root_for_each_container(void (*f)(struct sway_container *con, void *data),
|
||||
void *data) {
|
||||
for (int i = 0; i < root_container.children->length; ++i) {
|
||||
struct sway_container *output = root_container.children->items[i];
|
||||
for (int i = 0; i < root->outputs->length; ++i) {
|
||||
struct sway_output *output = root->outputs->items[i];
|
||||
output_for_each_container(output, f, data);
|
||||
}
|
||||
|
||||
// Scratchpad
|
||||
for (int i = 0; i < root_container.sway_root->scratchpad->length; ++i) {
|
||||
struct sway_container *container =
|
||||
root_container.sway_root->scratchpad->items[i];
|
||||
for (int i = 0; i < root->scratchpad->length; ++i) {
|
||||
struct sway_container *container = root->scratchpad->items[i];
|
||||
// If the container has a parent then it's visible on a workspace
|
||||
// and will have been iterated in the previous for loop. So we only
|
||||
// iterate the hidden scratchpad containers here.
|
||||
|
|
@ -289,10 +275,10 @@ void root_for_each_container(void (*f)(struct sway_container *con, void *data),
|
|||
}
|
||||
}
|
||||
|
||||
struct sway_container *root_find_output(
|
||||
bool (*test)(struct sway_container *con, void *data), void *data) {
|
||||
for (int i = 0; i < root_container.children->length; ++i) {
|
||||
struct sway_container *output = root_container.children->items[i];
|
||||
struct sway_output *root_find_output(
|
||||
bool (*test)(struct sway_output *output, void *data), void *data) {
|
||||
for (int i = 0; i < root->outputs->length; ++i) {
|
||||
struct sway_output *output = root->outputs->items[i];
|
||||
if (test(output, data)) {
|
||||
return output;
|
||||
}
|
||||
|
|
@ -300,11 +286,11 @@ struct sway_container *root_find_output(
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct sway_container *root_find_workspace(
|
||||
bool (*test)(struct sway_container *con, void *data), void *data) {
|
||||
struct sway_container *result = NULL;
|
||||
for (int i = 0; i < root_container.children->length; ++i) {
|
||||
struct sway_container *output = root_container.children->items[i];
|
||||
struct sway_workspace *root_find_workspace(
|
||||
bool (*test)(struct sway_workspace *ws, void *data), void *data) {
|
||||
struct sway_workspace *result = NULL;
|
||||
for (int i = 0; i < root->outputs->length; ++i) {
|
||||
struct sway_output *output = root->outputs->items[i];
|
||||
if ((result = output_find_workspace(output, test, data))) {
|
||||
return result;
|
||||
}
|
||||
|
|
@ -315,17 +301,16 @@ struct sway_container *root_find_workspace(
|
|||
struct sway_container *root_find_container(
|
||||
bool (*test)(struct sway_container *con, void *data), void *data) {
|
||||
struct sway_container *result = NULL;
|
||||
for (int i = 0; i < root_container.children->length; ++i) {
|
||||
struct sway_container *output = root_container.children->items[i];
|
||||
for (int i = 0; i < root->outputs->length; ++i) {
|
||||
struct sway_output *output = root->outputs->items[i];
|
||||
if ((result = output_find_container(output, test, data))) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// Scratchpad
|
||||
for (int i = 0; i < root_container.sway_root->scratchpad->length; ++i) {
|
||||
struct sway_container *container =
|
||||
root_container.sway_root->scratchpad->items[i];
|
||||
for (int i = 0; i < root->scratchpad->length; ++i) {
|
||||
struct sway_container *container = root->scratchpad->items[i];
|
||||
if (!container->parent) {
|
||||
if (test(container, data)) {
|
||||
return container;
|
||||
|
|
@ -337,3 +322,10 @@ struct sway_container *root_find_container(
|
|||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void root_get_box(struct sway_root *root, struct wlr_box *box) {
|
||||
box->x = root->x;
|
||||
box->y = root->y;
|
||||
box->width = root->width;
|
||||
box->height = root->height;
|
||||
}
|
||||
|
|
|
|||
279
sway/tree/view.c
279
sway/tree/view.c
|
|
@ -33,6 +33,8 @@ void view_init(struct sway_view *view, enum sway_view_type type,
|
|||
view->marks = create_list();
|
||||
view->allow_request_urgent = true;
|
||||
wl_signal_init(&view->events.unmap);
|
||||
|
||||
view->container = container_create(view);
|
||||
}
|
||||
|
||||
void view_destroy(struct sway_view *view) {
|
||||
|
|
@ -43,8 +45,8 @@ void view_destroy(struct sway_view *view) {
|
|||
"Tried to free view which wasn't marked as destroying")) {
|
||||
return;
|
||||
}
|
||||
if (!sway_assert(view->swayc == NULL,
|
||||
"Tried to free view which still has a swayc "
|
||||
if (!sway_assert(view->container == NULL,
|
||||
"Tried to free view which still has a container "
|
||||
"(might have a pending transaction?)")) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -57,6 +59,7 @@ void view_destroy(struct sway_view *view) {
|
|||
wlr_texture_destroy(view->marks_focused_inactive);
|
||||
wlr_texture_destroy(view->marks_unfocused);
|
||||
wlr_texture_destroy(view->marks_urgent);
|
||||
free(view->title_format);
|
||||
|
||||
if (view->impl->destroy) {
|
||||
view->impl->destroy(view);
|
||||
|
|
@ -65,23 +68,13 @@ void view_destroy(struct sway_view *view) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The view may or may not be involved in a transaction. For example, a view may
|
||||
* unmap then attempt to destroy itself before we've applied the new layout. If
|
||||
* an unmapping view is still involved in a transaction then it'll still have a
|
||||
* swayc.
|
||||
*
|
||||
* If there's no transaction we can simply free the view. Otherwise the
|
||||
* destroying flag will make the view get freed when the transaction is
|
||||
* finished.
|
||||
*/
|
||||
void view_begin_destroy(struct sway_view *view) {
|
||||
if (!sway_assert(view->surface == NULL, "Tried to destroy a mapped view")) {
|
||||
return;
|
||||
}
|
||||
view->destroying = true;
|
||||
|
||||
if (!view->swayc) {
|
||||
if (!view->container) {
|
||||
view_destroy(view);
|
||||
}
|
||||
}
|
||||
|
|
@ -171,30 +164,27 @@ uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
|
|||
}
|
||||
|
||||
void view_autoconfigure(struct sway_view *view) {
|
||||
if (!sway_assert(view->swayc,
|
||||
"Called view_autoconfigure() on a view without a swayc")) {
|
||||
struct sway_output *output = view->container->workspace->output;
|
||||
|
||||
if (view->container->is_fullscreen) {
|
||||
view->x = output->wlr_output->lx;
|
||||
view->y = output->wlr_output->ly;
|
||||
view->width = output->wlr_output->width;
|
||||
view->height = output->wlr_output->height;
|
||||
return;
|
||||
}
|
||||
|
||||
struct sway_container *output = container_parent(view->swayc, C_OUTPUT);
|
||||
struct sway_workspace *ws = view->container->workspace;
|
||||
|
||||
if (view->swayc->is_fullscreen) {
|
||||
view->x = output->x;
|
||||
view->y = output->y;
|
||||
view->width = output->width;
|
||||
view->height = output->height;
|
||||
return;
|
||||
}
|
||||
|
||||
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
|
||||
|
||||
int other_views = 0;
|
||||
bool other_views = false;
|
||||
if (config->hide_edge_borders == E_SMART) {
|
||||
struct sway_container *con = view->swayc;
|
||||
while (con != output) {
|
||||
if (con->layout != L_TABBED && con->layout != L_STACKED) {
|
||||
other_views += con->children ? con->children->length - 1 : 0;
|
||||
if (other_views > 0) {
|
||||
struct sway_container *con = view->container;
|
||||
while (con) {
|
||||
enum sway_container_layout layout = container_parent_layout(con);
|
||||
if (layout != L_TABBED && layout != L_STACKED) {
|
||||
list_t *siblings = container_get_siblings(con);
|
||||
if (siblings && siblings->length > 1) {
|
||||
other_views = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -202,7 +192,7 @@ void view_autoconfigure(struct sway_view *view) {
|
|||
}
|
||||
}
|
||||
|
||||
struct sway_container *con = view->swayc;
|
||||
struct sway_container *con = view->container;
|
||||
|
||||
view->border_top = view->border_bottom = true;
|
||||
view->border_left = view->border_right = true;
|
||||
|
|
@ -228,7 +218,8 @@ void view_autoconfigure(struct sway_view *view) {
|
|||
// In a tabbed or stacked container, the swayc's y is the bottom of the
|
||||
// title area. We have to disable any top border because the title bar is
|
||||
// rendered by the parent.
|
||||
if (con->parent->layout == L_TABBED || con->parent->layout == L_STACKED) {
|
||||
enum sway_container_layout layout = container_parent_layout(con);
|
||||
if (layout == L_TABBED || layout == L_STACKED) {
|
||||
view->border_top = false;
|
||||
} else {
|
||||
y_offset = container_titlebar_height();
|
||||
|
|
@ -281,13 +272,16 @@ void view_set_activated(struct sway_view *view, bool activated) {
|
|||
}
|
||||
|
||||
void view_request_activate(struct sway_view *view) {
|
||||
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
|
||||
struct sway_workspace *ws = view->container->workspace;
|
||||
if (!ws) { // hidden scratchpad container
|
||||
return;
|
||||
}
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
|
||||
switch (config->focus_on_window_activation) {
|
||||
case FOWA_SMART:
|
||||
if (workspace_is_visible(ws)) {
|
||||
seat_set_focus(seat, view->swayc);
|
||||
seat_set_focus(seat, &view->container->node);
|
||||
} else {
|
||||
view_set_urgent(view, true);
|
||||
}
|
||||
|
|
@ -296,7 +290,7 @@ void view_request_activate(struct sway_view *view) {
|
|||
view_set_urgent(view, true);
|
||||
break;
|
||||
case FOWA_FOCUS:
|
||||
seat_set_focus(seat, view->swayc);
|
||||
seat_set_focus(seat, &view->container->node);
|
||||
break;
|
||||
case FOWA_NONE:
|
||||
break;
|
||||
|
|
@ -331,23 +325,12 @@ void view_close_popups(struct sway_view *view) {
|
|||
}
|
||||
|
||||
void view_damage_from(struct sway_view *view) {
|
||||
for (int i = 0; i < root_container.children->length; ++i) {
|
||||
struct sway_container *cont = root_container.children->items[i];
|
||||
if (cont->type == C_OUTPUT) {
|
||||
output_damage_from_view(cont->sway_output, view);
|
||||
}
|
||||
for (int i = 0; i < root->outputs->length; ++i) {
|
||||
struct sway_output *output = root->outputs->items[i];
|
||||
output_damage_from_view(output, view);
|
||||
}
|
||||
}
|
||||
|
||||
static void view_get_layout_box(struct sway_view *view, struct wlr_box *box) {
|
||||
struct sway_container *output = container_parent(view->swayc, C_OUTPUT);
|
||||
|
||||
box->x = output->x + view->swayc->x;
|
||||
box->y = output->y + view->swayc->y;
|
||||
box->width = view->width;
|
||||
box->height = view->height;
|
||||
}
|
||||
|
||||
void view_for_each_surface(struct sway_view *view,
|
||||
wlr_surface_iterator_func_t iterator, void *user_data) {
|
||||
if (!view->surface) {
|
||||
|
|
@ -396,11 +379,8 @@ static bool view_has_executed_criteria(struct sway_view *view,
|
|||
}
|
||||
|
||||
void view_execute_criteria(struct sway_view *view) {
|
||||
if (!view->swayc) {
|
||||
return;
|
||||
}
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_container *prior_focus = seat_get_focus(seat);
|
||||
struct sway_node *prior_focus = seat_get_focus(seat);
|
||||
list_t *criterias = criteria_for_view(view, CT_COMMAND);
|
||||
for (int i = 0; i < criterias->length; i++) {
|
||||
struct criteria *criteria = criterias->items[i];
|
||||
|
|
@ -411,7 +391,7 @@ void view_execute_criteria(struct sway_view *view) {
|
|||
}
|
||||
wlr_log(WLR_DEBUG, "for_window '%s' matches view %p, cmd: '%s'",
|
||||
criteria->raw, view, criteria->cmdlist);
|
||||
seat_set_focus(seat, view->swayc);
|
||||
seat_set_focus(seat, &view->container->node);
|
||||
list_add(view->executed_criteria, criteria);
|
||||
struct cmd_results *res = execute_command(criteria->cmdlist, NULL);
|
||||
if (res->status != CMD_SUCCESS) {
|
||||
|
|
@ -423,19 +403,19 @@ void view_execute_criteria(struct sway_view *view) {
|
|||
seat_set_focus(seat, prior_focus);
|
||||
}
|
||||
|
||||
static struct sway_container *select_workspace(struct sway_view *view) {
|
||||
static struct sway_workspace *select_workspace(struct sway_view *view) {
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
|
||||
// Check if there's any `assign` criteria for the view
|
||||
list_t *criterias = criteria_for_view(view,
|
||||
CT_ASSIGN_WORKSPACE | CT_ASSIGN_WORKSPACE_NUMBER | CT_ASSIGN_OUTPUT);
|
||||
struct sway_container *ws = NULL;
|
||||
struct sway_workspace *ws = NULL;
|
||||
for (int i = 0; i < criterias->length; ++i) {
|
||||
struct criteria *criteria = criterias->items[i];
|
||||
if (criteria->type == CT_ASSIGN_OUTPUT) {
|
||||
struct sway_container *output = output_by_name(criteria->target);
|
||||
struct sway_output *output = output_by_name(criteria->target);
|
||||
if (output) {
|
||||
ws = seat_get_active_child(seat, output);
|
||||
ws = output_get_active_workspace(output);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -484,20 +464,14 @@ static struct sway_container *select_workspace(struct sway_view *view) {
|
|||
}
|
||||
|
||||
// Use the focused workspace
|
||||
ws = seat_get_focus_inactive(seat, &root_container);
|
||||
if (ws->type != C_WORKSPACE) {
|
||||
ws = container_parent(ws, C_WORKSPACE);
|
||||
}
|
||||
return ws;
|
||||
return seat_get_focused_workspace(seat);
|
||||
}
|
||||
|
||||
static bool should_focus(struct sway_view *view) {
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_container *prev_focus =
|
||||
seat_get_focus_inactive(seat, &root_container);
|
||||
struct sway_container *prev_ws = prev_focus->type == C_WORKSPACE ?
|
||||
prev_focus : container_parent(prev_focus, C_WORKSPACE);
|
||||
struct sway_container *map_ws = container_parent(view->swayc, C_WORKSPACE);
|
||||
struct sway_container *prev_con = seat_get_focused_container(seat);
|
||||
struct sway_workspace *prev_ws = seat_get_focused_workspace(seat);
|
||||
struct sway_workspace *map_ws = view->container->workspace;
|
||||
|
||||
// Views can only take focus if they are mapped into the active workspace
|
||||
if (prev_ws != map_ws) {
|
||||
|
|
@ -506,10 +480,9 @@ static bool should_focus(struct sway_view *view) {
|
|||
|
||||
// If the view is the only one in the focused workspace, it'll get focus
|
||||
// regardless of any no_focus criteria.
|
||||
struct sway_container *parent = view->swayc->parent;
|
||||
if (parent->type == C_WORKSPACE && prev_focus == parent) {
|
||||
size_t num_children = parent->children->length +
|
||||
parent->sway_workspace->floating->length;
|
||||
if (!view->container->parent && !prev_con) {
|
||||
size_t num_children = view->container->workspace->tiling->length +
|
||||
view->container->workspace->floating->length;
|
||||
if (num_children == 1) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -529,16 +502,24 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
|
|||
view->surface = wlr_surface;
|
||||
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_container *ws = select_workspace(view);
|
||||
struct sway_container *target_sibling = seat_get_focus_inactive(seat, ws);
|
||||
struct sway_workspace *ws = select_workspace(view);
|
||||
struct sway_node *node = seat_get_focus_inactive(seat, &ws->node);
|
||||
struct sway_container *target_sibling = node->type == N_CONTAINER ?
|
||||
node->sway_container : NULL;
|
||||
|
||||
// If we're about to launch the view into the floating container, then
|
||||
// launch it as a tiled view in the root of the workspace instead.
|
||||
if (container_is_floating(target_sibling)) {
|
||||
target_sibling = target_sibling->parent;
|
||||
if (target_sibling && container_is_floating(target_sibling)) {
|
||||
target_sibling = NULL;
|
||||
}
|
||||
|
||||
view->swayc = container_view_create(target_sibling, view);
|
||||
view->container = container_create(view);
|
||||
if (target_sibling) {
|
||||
container_add_sibling(target_sibling, view->container, 1);
|
||||
} else {
|
||||
workspace_add_tiling(ws, view->container);
|
||||
}
|
||||
ipc_event_window(view->container, "new");
|
||||
|
||||
view_init_subsurfaces(view, wlr_surface);
|
||||
wl_signal_add(&wlr_surface->events.new_subsurface,
|
||||
|
|
@ -548,7 +529,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
|
|||
if (view->impl->wants_floating && view->impl->wants_floating(view)) {
|
||||
view->border = config->floating_border;
|
||||
view->border_thickness = config->floating_border_thickness;
|
||||
container_set_floating(view->swayc, true);
|
||||
container_set_floating(view->container, true);
|
||||
} else {
|
||||
view->border = config->border;
|
||||
view->border_thickness = config->border_thickness;
|
||||
|
|
@ -556,11 +537,11 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
|
|||
}
|
||||
|
||||
if (should_focus(view)) {
|
||||
input_manager_set_focus(input_manager, view->swayc);
|
||||
input_manager_set_focus(input_manager, &view->container->node);
|
||||
}
|
||||
|
||||
view_update_title(view, false);
|
||||
container_notify_subtree_changed(view->swayc->parent);
|
||||
container_update_representation(view->container);
|
||||
view_execute_criteria(view);
|
||||
}
|
||||
|
||||
|
|
@ -574,17 +555,17 @@ void view_unmap(struct sway_view *view) {
|
|||
view->urgent_timer = NULL;
|
||||
}
|
||||
|
||||
bool was_fullscreen = view->swayc->is_fullscreen;
|
||||
struct sway_container *parent = view->swayc->parent;
|
||||
container_begin_destroy(view->swayc);
|
||||
struct sway_container *surviving_ancestor = container_reap_empty(parent);
|
||||
struct sway_container *parent = view->container->parent;
|
||||
struct sway_workspace *ws = view->container->workspace;
|
||||
container_begin_destroy(view->container);
|
||||
if (parent) {
|
||||
container_reap_empty(parent);
|
||||
} else {
|
||||
workspace_consider_destroy(ws);
|
||||
}
|
||||
|
||||
// If the workspace wasn't reaped
|
||||
if (surviving_ancestor && surviving_ancestor->type >= C_WORKSPACE) {
|
||||
struct sway_container *ws = surviving_ancestor->type == C_WORKSPACE ?
|
||||
surviving_ancestor :
|
||||
container_parent(surviving_ancestor, C_WORKSPACE);
|
||||
arrange_windows(was_fullscreen ? ws : surviving_ancestor);
|
||||
if (!ws->node.destroying) {
|
||||
arrange_workspace(ws);
|
||||
workspace_detect_urgent(ws);
|
||||
}
|
||||
|
||||
|
|
@ -593,15 +574,15 @@ void view_unmap(struct sway_view *view) {
|
|||
}
|
||||
|
||||
void view_update_size(struct sway_view *view, int width, int height) {
|
||||
if (!sway_assert(container_is_floating(view->swayc),
|
||||
if (!sway_assert(container_is_floating(view->container),
|
||||
"Expected a floating container")) {
|
||||
return;
|
||||
}
|
||||
view->width = width;
|
||||
view->height = height;
|
||||
view->swayc->current.view_width = width;
|
||||
view->swayc->current.view_height = height;
|
||||
container_set_geometry_from_floating_view(view->swayc);
|
||||
view->container->current.view_width = width;
|
||||
view->container->current.view_height = height;
|
||||
container_set_geometry_from_floating_view(view->container);
|
||||
}
|
||||
|
||||
static void view_subsurface_create(struct sway_view *view,
|
||||
|
|
@ -670,27 +651,18 @@ void view_child_init(struct sway_view_child *child,
|
|||
wl_signal_add(&view->events.unmap, &child->view_unmap);
|
||||
child->view_unmap.notify = view_child_handle_view_unmap;
|
||||
|
||||
struct sway_container *output = child->view->swayc->parent;
|
||||
if (output != NULL) {
|
||||
if (output->type != C_OUTPUT) {
|
||||
output = container_parent(output, C_OUTPUT);
|
||||
}
|
||||
wlr_surface_send_enter(child->surface, output->sway_output->wlr_output);
|
||||
}
|
||||
struct sway_output *output = child->view->container->workspace->output;
|
||||
wlr_surface_send_enter(child->surface, output->wlr_output);
|
||||
|
||||
view_init_subsurfaces(child->view, surface);
|
||||
|
||||
// TODO: only damage the whole child
|
||||
if (child->view->swayc) {
|
||||
container_damage_whole(child->view->swayc);
|
||||
}
|
||||
container_damage_whole(child->view->container);
|
||||
}
|
||||
|
||||
void view_child_destroy(struct sway_view_child *child) {
|
||||
// TODO: only damage the whole child
|
||||
if (child->view->swayc) {
|
||||
container_damage_whole(child->view->swayc);
|
||||
}
|
||||
container_damage_whole(child->view->container);
|
||||
|
||||
wl_list_remove(&child->surface_commit.link);
|
||||
wl_list_remove(&child->surface_destroy.link);
|
||||
|
|
@ -808,22 +780,20 @@ static char *escape_title(char *buffer) {
|
|||
}
|
||||
|
||||
void view_update_title(struct sway_view *view, bool force) {
|
||||
if (!view->swayc) {
|
||||
return;
|
||||
}
|
||||
const char *title = view_get_title(view);
|
||||
|
||||
if (!force) {
|
||||
if (title && view->swayc->name && strcmp(title, view->swayc->name) == 0) {
|
||||
if (title && view->container->title &&
|
||||
strcmp(title, view->container->title) == 0) {
|
||||
return;
|
||||
}
|
||||
if (!title && !view->swayc->name) {
|
||||
if (!title && !view->container->title) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
free(view->swayc->name);
|
||||
free(view->swayc->formatted_title);
|
||||
free(view->container->title);
|
||||
free(view->container->formatted_title);
|
||||
if (title) {
|
||||
size_t len = parse_title_format(view, NULL);
|
||||
char *buffer = calloc(len + 1, sizeof(char));
|
||||
|
|
@ -836,25 +806,25 @@ void view_update_title(struct sway_view *view, bool force) {
|
|||
buffer = escape_title(buffer);
|
||||
}
|
||||
|
||||
view->swayc->name = strdup(title);
|
||||
view->swayc->formatted_title = buffer;
|
||||
view->container->title = strdup(title);
|
||||
view->container->formatted_title = buffer;
|
||||
} else {
|
||||
view->swayc->name = NULL;
|
||||
view->swayc->formatted_title = NULL;
|
||||
view->container->title = NULL;
|
||||
view->container->formatted_title = NULL;
|
||||
}
|
||||
container_calculate_title_height(view->swayc);
|
||||
container_calculate_title_height(view->container);
|
||||
config_update_font_height(false);
|
||||
|
||||
// Update title after the global font height is updated
|
||||
container_update_title_textures(view->swayc);
|
||||
container_update_title_textures(view->container);
|
||||
|
||||
ipc_event_window(view->swayc, "title");
|
||||
ipc_event_window(view->container, "title");
|
||||
}
|
||||
|
||||
static bool find_by_mark_iterator(struct sway_container *con,
|
||||
void *data) {
|
||||
char *mark = data;
|
||||
return con->type == C_VIEW && view_has_mark(con->sway_view, mark);
|
||||
return con->view && view_has_mark(con->view, mark);
|
||||
}
|
||||
|
||||
struct sway_view *view_find_mark(char *mark) {
|
||||
|
|
@ -863,7 +833,7 @@ struct sway_view *view_find_mark(char *mark) {
|
|||
if (!container) {
|
||||
return NULL;
|
||||
}
|
||||
return container->sway_view;
|
||||
return container->view;
|
||||
}
|
||||
|
||||
bool view_find_and_unmark(char *mark) {
|
||||
|
|
@ -872,7 +842,7 @@ bool view_find_and_unmark(char *mark) {
|
|||
if (!container) {
|
||||
return false;
|
||||
}
|
||||
struct sway_view *view = container->sway_view;
|
||||
struct sway_view *view = container->view;
|
||||
|
||||
for (int i = 0; i < view->marks->length; ++i) {
|
||||
char *view_mark = view->marks->items[i];
|
||||
|
|
@ -888,10 +858,9 @@ bool view_find_and_unmark(char *mark) {
|
|||
}
|
||||
|
||||
void view_clear_marks(struct sway_view *view) {
|
||||
while (view->marks->length) {
|
||||
list_del(view->marks, 0);
|
||||
ipc_event_window(view->swayc, "mark");
|
||||
}
|
||||
list_foreach(view->marks, free);
|
||||
view->marks->length = 0;
|
||||
ipc_event_window(view->container, "mark");
|
||||
}
|
||||
|
||||
bool view_has_mark(struct sway_view *view, char *mark) {
|
||||
|
|
@ -906,12 +875,13 @@ bool view_has_mark(struct sway_view *view, char *mark) {
|
|||
|
||||
void view_add_mark(struct sway_view *view, char *mark) {
|
||||
list_add(view->marks, strdup(mark));
|
||||
ipc_event_window(view->swayc, "mark");
|
||||
ipc_event_window(view->container, "mark");
|
||||
}
|
||||
|
||||
static void update_marks_texture(struct sway_view *view,
|
||||
struct wlr_texture **texture, struct border_colors *class) {
|
||||
struct sway_output *output = container_get_effective_output(view->swayc);
|
||||
struct sway_output *output =
|
||||
container_get_effective_output(view->container);
|
||||
if (!output) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -949,7 +919,7 @@ static void update_marks_texture(struct sway_view *view,
|
|||
|
||||
double scale = output->wlr_output->scale;
|
||||
int width = 0;
|
||||
int height = view->swayc->title_height * scale;
|
||||
int height = view->container->title_height * scale;
|
||||
|
||||
cairo_t *c = cairo_create(NULL);
|
||||
get_text_size(c, config->font, &width, NULL, scale, false, "%s", buffer);
|
||||
|
|
@ -994,44 +964,40 @@ void view_update_marks_textures(struct sway_view *view) {
|
|||
&config->border_colors.unfocused);
|
||||
update_marks_texture(view, &view->marks_urgent,
|
||||
&config->border_colors.urgent);
|
||||
container_damage_whole(view->swayc);
|
||||
container_damage_whole(view->container);
|
||||
}
|
||||
|
||||
bool view_is_visible(struct sway_view *view) {
|
||||
if (!view->swayc || view->swayc->destroying) {
|
||||
if (view->container->node.destroying) {
|
||||
return false;
|
||||
}
|
||||
struct sway_container *workspace =
|
||||
container_parent(view->swayc, C_WORKSPACE);
|
||||
struct sway_workspace *workspace = view->container->workspace;
|
||||
if (!workspace) {
|
||||
return false;
|
||||
}
|
||||
// Determine if view is nested inside a floating container which is sticky.
|
||||
// A simple floating view will have this ancestry:
|
||||
// C_VIEW -> floating -> workspace
|
||||
// A more complex ancestry could be:
|
||||
// C_VIEW -> C_CONTAINER (tabbed) -> floating -> workspace
|
||||
struct sway_container *floater = view->swayc;
|
||||
while (floater->parent->type != C_WORKSPACE
|
||||
&& floater->parent->parent->type != C_WORKSPACE) {
|
||||
// Determine if view is nested inside a floating container which is sticky
|
||||
struct sway_container *floater = view->container;
|
||||
while (floater->parent) {
|
||||
floater = floater->parent;
|
||||
}
|
||||
bool is_sticky = container_is_floating(floater) && floater->is_sticky;
|
||||
// Check view isn't in a tabbed or stacked container on an inactive tab
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_container *container = view->swayc;
|
||||
while (container->type != C_WORKSPACE) {
|
||||
if (container->parent->layout == L_TABBED ||
|
||||
container->parent->layout == L_STACKED) {
|
||||
if (seat_get_active_child(seat, container->parent) != container) {
|
||||
struct sway_container *container = view->container;
|
||||
while (container) {
|
||||
enum sway_container_layout layout = container_parent_layout(container);
|
||||
if (layout == L_TABBED || layout == L_STACKED) {
|
||||
struct sway_node *parent = container->parent ?
|
||||
&container->parent->node : &container->workspace->node;
|
||||
if (seat_get_active_child(seat, parent) != &container->node) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
container = container->parent;
|
||||
}
|
||||
// Check view isn't hidden by another fullscreen view
|
||||
if (workspace->sway_workspace->fullscreen &&
|
||||
!container_is_fullscreen_or_child(view->swayc)) {
|
||||
if (workspace->fullscreen &&
|
||||
!container_is_fullscreen_or_child(view->container)) {
|
||||
return false;
|
||||
}
|
||||
// Check the workspace is visible
|
||||
|
|
@ -1047,7 +1013,7 @@ void view_set_urgent(struct sway_view *view, bool enable) {
|
|||
}
|
||||
if (enable) {
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
if (seat_get_focus(seat) == view->swayc) {
|
||||
if (seat_get_focused_container(seat) == view->container) {
|
||||
return;
|
||||
}
|
||||
clock_gettime(CLOCK_MONOTONIC, &view->urgent);
|
||||
|
|
@ -1058,12 +1024,11 @@ void view_set_urgent(struct sway_view *view, bool enable) {
|
|||
view->urgent_timer = NULL;
|
||||
}
|
||||
}
|
||||
container_damage_whole(view->swayc);
|
||||
container_damage_whole(view->container);
|
||||
|
||||
ipc_event_window(view->swayc, "urgent");
|
||||
ipc_event_window(view->container, "urgent");
|
||||
|
||||
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
|
||||
workspace_detect_urgent(ws);
|
||||
workspace_detect_urgent(view->container->workspace);
|
||||
}
|
||||
|
||||
bool view_is_urgent(struct sway_view *view) {
|
||||
|
|
|
|||
|
|
@ -12,128 +12,105 @@
|
|||
#include "sway/output.h"
|
||||
#include "sway/tree/arrange.h"
|
||||
#include "sway/tree/container.h"
|
||||
#include "sway/tree/node.h"
|
||||
#include "sway/tree/view.h"
|
||||
#include "sway/tree/workspace.h"
|
||||
#include "list.h"
|
||||
#include "log.h"
|
||||
#include "util.h"
|
||||
|
||||
struct sway_container *workspace_get_initial_output(const char *name) {
|
||||
struct sway_container *parent;
|
||||
struct sway_output *workspace_get_initial_output(const char *name) {
|
||||
// Search for workspace<->output pair
|
||||
int e = config->workspace_outputs->length;
|
||||
for (int i = 0; i < config->workspace_outputs->length; ++i) {
|
||||
struct workspace_output *wso = config->workspace_outputs->items[i];
|
||||
if (strcasecmp(wso->workspace, name) == 0) {
|
||||
// Find output to use if it exists
|
||||
e = root_container.children->length;
|
||||
for (i = 0; i < e; ++i) {
|
||||
parent = root_container.children->items[i];
|
||||
if (strcmp(parent->name, wso->output) == 0) {
|
||||
return parent;
|
||||
}
|
||||
struct sway_output *output = output_by_name(wso->output);
|
||||
if (output) {
|
||||
return output;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Otherwise put it on the focused output
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_container *focus =
|
||||
seat_get_focus_inactive(seat, &root_container);
|
||||
parent = focus;
|
||||
parent = container_parent(parent, C_OUTPUT);
|
||||
return parent;
|
||||
struct sway_workspace *focus = seat_get_focused_workspace(seat);
|
||||
return focus->output;
|
||||
}
|
||||
|
||||
struct sway_container *workspace_create(struct sway_container *output,
|
||||
struct sway_workspace *workspace_create(struct sway_output *output,
|
||||
const char *name) {
|
||||
if (output == NULL) {
|
||||
output = workspace_get_initial_output(name);
|
||||
}
|
||||
|
||||
wlr_log(WLR_DEBUG, "Added workspace %s for output %s", name, output->name);
|
||||
struct sway_container *workspace = container_create(C_WORKSPACE);
|
||||
wlr_log(WLR_DEBUG, "Adding workspace %s for output %s", name,
|
||||
output->wlr_output->name);
|
||||
|
||||
workspace->x = output->x;
|
||||
workspace->y = output->y;
|
||||
workspace->width = output->width;
|
||||
workspace->height = output->height;
|
||||
workspace->name = !name ? NULL : strdup(name);
|
||||
workspace->prev_split_layout = L_NONE;
|
||||
workspace->layout = container_get_default_layout(output);
|
||||
|
||||
struct sway_workspace *swayws = calloc(1, sizeof(struct sway_workspace));
|
||||
if (!swayws) {
|
||||
struct sway_workspace *ws = calloc(1, sizeof(struct sway_workspace));
|
||||
if (!ws) {
|
||||
wlr_log(WLR_ERROR, "Unable to allocate sway_workspace");
|
||||
return NULL;
|
||||
}
|
||||
swayws->swayc = workspace;
|
||||
swayws->floating = create_list();
|
||||
swayws->output_priority = create_list();
|
||||
workspace->sway_workspace = swayws;
|
||||
workspace_output_add_priority(workspace, output);
|
||||
node_init(&ws->node, N_WORKSPACE, ws);
|
||||
ws->x = output->wlr_output->lx;
|
||||
ws->y = output->wlr_output->ly;
|
||||
ws->width = output->wlr_output->width;
|
||||
ws->height = output->wlr_output->height;
|
||||
ws->name = name ? strdup(name) : NULL;
|
||||
ws->prev_split_layout = L_NONE;
|
||||
ws->layout = output_get_default_layout(output);
|
||||
ws->floating = create_list();
|
||||
ws->tiling = create_list();
|
||||
ws->output_priority = create_list();
|
||||
workspace_output_add_priority(ws, output);
|
||||
|
||||
container_add_child(output, workspace);
|
||||
output_add_workspace(output, ws);
|
||||
output_sort_workspaces(output);
|
||||
container_create_notify(workspace);
|
||||
|
||||
return workspace;
|
||||
ipc_event_workspace(NULL, ws, "init");
|
||||
wl_signal_emit(&root->events.new_node, &ws->node);
|
||||
|
||||
return ws;
|
||||
}
|
||||
|
||||
void workspace_destroy(struct sway_container *workspace) {
|
||||
if (!sway_assert(workspace->type == C_WORKSPACE, "Expected a workspace")) {
|
||||
return;
|
||||
}
|
||||
if (!sway_assert(workspace->destroying,
|
||||
void workspace_destroy(struct sway_workspace *workspace) {
|
||||
if (!sway_assert(workspace->node.destroying,
|
||||
"Tried to free workspace which wasn't marked as destroying")) {
|
||||
return;
|
||||
}
|
||||
if (!sway_assert(workspace->ntxnrefs == 0, "Tried to free workspace "
|
||||
if (!sway_assert(workspace->node.ntxnrefs == 0, "Tried to free workspace "
|
||||
"which is still referenced by transactions")) {
|
||||
return;
|
||||
}
|
||||
// sway_workspace
|
||||
struct sway_workspace *ws = workspace->sway_workspace;
|
||||
list_foreach(ws->output_priority, free);
|
||||
list_free(ws->output_priority);
|
||||
list_free(ws->floating);
|
||||
free(ws);
|
||||
|
||||
// swayc
|
||||
free(workspace->name);
|
||||
free(workspace->formatted_title);
|
||||
wlr_texture_destroy(workspace->title_focused);
|
||||
wlr_texture_destroy(workspace->title_focused_inactive);
|
||||
wlr_texture_destroy(workspace->title_unfocused);
|
||||
wlr_texture_destroy(workspace->title_urgent);
|
||||
list_free(workspace->children);
|
||||
list_free(workspace->current.children);
|
||||
list_free(workspace->outputs);
|
||||
free(workspace->representation);
|
||||
list_foreach(workspace->output_priority, free);
|
||||
list_free(workspace->output_priority);
|
||||
list_free(workspace->floating);
|
||||
list_free(workspace->tiling);
|
||||
list_free(workspace->current.floating);
|
||||
list_free(workspace->current.tiling);
|
||||
free(workspace);
|
||||
}
|
||||
|
||||
void workspace_begin_destroy(struct sway_container *workspace) {
|
||||
if (!sway_assert(workspace->type == C_WORKSPACE, "Expected a workspace")) {
|
||||
return;
|
||||
}
|
||||
void workspace_begin_destroy(struct sway_workspace *workspace) {
|
||||
wlr_log(WLR_DEBUG, "Destroying workspace '%s'", workspace->name);
|
||||
wl_signal_emit(&workspace->events.destroy, workspace);
|
||||
ipc_event_workspace(NULL, workspace, "empty"); // intentional
|
||||
wl_signal_emit(&workspace->node.events.destroy, &workspace->node);
|
||||
|
||||
workspace->destroying = true;
|
||||
container_set_dirty(workspace);
|
||||
|
||||
if (workspace->parent) {
|
||||
container_remove_child(workspace);
|
||||
if (workspace->output) {
|
||||
workspace_detach(workspace);
|
||||
}
|
||||
|
||||
workspace->node.destroying = true;
|
||||
node_set_dirty(&workspace->node);
|
||||
}
|
||||
|
||||
void workspace_consider_destroy(struct sway_container *ws) {
|
||||
if (!sway_assert(ws->type == C_WORKSPACE, "Expected a workspace")) {
|
||||
return;
|
||||
}
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
if (ws->children->length == 0 && ws->sway_workspace->floating->length == 0
|
||||
&& seat_get_active_child(seat, ws->parent) != ws) {
|
||||
void workspace_consider_destroy(struct sway_workspace *ws) {
|
||||
if (ws->tiling->length == 0 && ws->floating->length == 0
|
||||
&& output_get_active_workspace(ws->output) != ws) {
|
||||
workspace_begin_destroy(ws);
|
||||
}
|
||||
}
|
||||
|
|
@ -272,59 +249,49 @@ char *workspace_next_name(const char *output_name) {
|
|||
}
|
||||
// As a fall back, get the current number of active workspaces
|
||||
// and return that + 1 for the next workspace's name
|
||||
int ws_num = root_container.children->length;
|
||||
int ws_num = root->outputs->length;
|
||||
int l = snprintf(NULL, 0, "%d", ws_num);
|
||||
char *name = malloc(l + 1);
|
||||
if (!sway_assert(name, "Cloud not allocate workspace name")) {
|
||||
if (!sway_assert(name, "Could not allocate workspace name")) {
|
||||
return NULL;
|
||||
}
|
||||
sprintf(name, "%d", ws_num++);
|
||||
return name;
|
||||
}
|
||||
|
||||
static bool _workspace_by_number(struct sway_container *view, void *data) {
|
||||
if (view->type != C_WORKSPACE) {
|
||||
return false;
|
||||
}
|
||||
static bool _workspace_by_number(struct sway_workspace *ws, void *data) {
|
||||
char *name = data;
|
||||
char *view_name = view->name;
|
||||
char *ws_name = ws->name;
|
||||
while (isdigit(*name)) {
|
||||
if (*name++ != *view_name++) {
|
||||
if (*name++ != *ws_name++) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return !isdigit(*view_name);
|
||||
return !isdigit(*ws_name);
|
||||
}
|
||||
|
||||
struct sway_container *workspace_by_number(const char* name) {
|
||||
struct sway_workspace *workspace_by_number(const char* name) {
|
||||
return root_find_workspace(_workspace_by_number, (void *) name);
|
||||
}
|
||||
|
||||
static bool _workspace_by_name(struct sway_container *view, void *data) {
|
||||
return (view->type == C_WORKSPACE) &&
|
||||
(strcasecmp(view->name, (char *) data) == 0);
|
||||
static bool _workspace_by_name(struct sway_workspace *ws, void *data) {
|
||||
return strcasecmp(ws->name, data) == 0;
|
||||
}
|
||||
|
||||
struct sway_container *workspace_by_name(const char *name) {
|
||||
struct sway_workspace *workspace_by_name(const char *name) {
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_container *current_workspace = NULL, *current_output = NULL;
|
||||
struct sway_container *focus = seat_get_focus(seat);
|
||||
if (focus) {
|
||||
current_workspace = focus->type == C_WORKSPACE ?
|
||||
focus : container_parent(focus, C_WORKSPACE);
|
||||
current_output = container_parent(focus, C_OUTPUT);
|
||||
}
|
||||
struct sway_workspace *current = seat_get_focused_workspace(seat);
|
||||
|
||||
if (strcmp(name, "prev") == 0) {
|
||||
return workspace_prev(current_workspace);
|
||||
return workspace_prev(current);
|
||||
} else if (strcmp(name, "prev_on_output") == 0) {
|
||||
return workspace_output_prev(current_output);
|
||||
return workspace_output_prev(current);
|
||||
} else if (strcmp(name, "next") == 0) {
|
||||
return workspace_next(current_workspace);
|
||||
return workspace_next(current);
|
||||
} else if (strcmp(name, "next_on_output") == 0) {
|
||||
return workspace_output_next(current_output);
|
||||
return workspace_output_next(current);
|
||||
} else if (strcmp(name, "current") == 0) {
|
||||
return current_workspace;
|
||||
return current;
|
||||
} else if (strcasecmp(name, "back_and_forth") == 0) {
|
||||
return prev_workspace_name ?
|
||||
root_find_workspace(_workspace_by_name, (void*)prev_workspace_name)
|
||||
|
|
@ -339,97 +306,68 @@ struct sway_container *workspace_by_name(const char *name) {
|
|||
* the end and beginning. If next is false, the previous workspace is returned,
|
||||
* otherwise the next one is returned.
|
||||
*/
|
||||
static struct sway_container *workspace_output_prev_next_impl(
|
||||
struct sway_container *output, int dir) {
|
||||
if (!output) {
|
||||
return NULL;
|
||||
}
|
||||
if (!sway_assert(output->type == C_OUTPUT,
|
||||
"Argument must be an output, is %d", output->type)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct sway_workspace *workspace_output_prev_next_impl(
|
||||
struct sway_output *output, int dir) {
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_container *focus = seat_get_focus_inactive(seat, output);
|
||||
struct sway_container *workspace = (focus->type == C_WORKSPACE ?
|
||||
focus :
|
||||
container_parent(focus, C_WORKSPACE));
|
||||
struct sway_workspace *workspace = seat_get_focused_workspace(seat);
|
||||
|
||||
int index = list_find(output->children, workspace);
|
||||
size_t new_index = wrap(index + dir, output->children->length);
|
||||
return output->children->items[new_index];
|
||||
int index = list_find(output->workspaces, workspace);
|
||||
size_t new_index = wrap(index + dir, output->workspaces->length);
|
||||
return output->workspaces->items[new_index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the previous or next workspace. If the first/last workspace on an output
|
||||
* is active, proceed to the previous/next output's previous/next workspace.
|
||||
*/
|
||||
static struct sway_container *workspace_prev_next_impl(
|
||||
struct sway_container *workspace, int dir) {
|
||||
if (!workspace) {
|
||||
return NULL;
|
||||
}
|
||||
if (!sway_assert(workspace->type == C_WORKSPACE,
|
||||
"Argument must be a workspace, is %d", workspace->type)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct sway_container *output = workspace->parent;
|
||||
int index = list_find(output->children, workspace);
|
||||
static struct sway_workspace *workspace_prev_next_impl(
|
||||
struct sway_workspace *workspace, int dir) {
|
||||
struct sway_output *output = workspace->output;
|
||||
int index = list_find(output->workspaces, workspace);
|
||||
int new_index = index + dir;
|
||||
|
||||
if (new_index >= 0 && new_index < output->children->length) {
|
||||
return output->children->items[index + dir];
|
||||
if (new_index >= 0 && new_index < output->workspaces->length) {
|
||||
return output->workspaces->items[new_index];
|
||||
}
|
||||
|
||||
// Look on a different output
|
||||
int output_index = list_find(root_container.children, output);
|
||||
new_index = wrap(output_index + dir, root_container.children->length);
|
||||
output = root_container.children->items[new_index];
|
||||
int output_index = list_find(root->outputs, output);
|
||||
new_index = wrap(output_index + dir, root->outputs->length);
|
||||
output = root->outputs->items[new_index];
|
||||
|
||||
if (dir == 1) {
|
||||
return output->children->items[0];
|
||||
return output->workspaces->items[0];
|
||||
} else {
|
||||
return output->children->items[output->children->length - 1];
|
||||
return output->workspaces->items[output->workspaces->length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
struct sway_container *workspace_output_next(struct sway_container *current) {
|
||||
return workspace_output_prev_next_impl(current, 1);
|
||||
struct sway_workspace *workspace_output_next(struct sway_workspace *current) {
|
||||
return workspace_output_prev_next_impl(current->output, 1);
|
||||
}
|
||||
|
||||
struct sway_container *workspace_next(struct sway_container *current) {
|
||||
struct sway_workspace *workspace_next(struct sway_workspace *current) {
|
||||
return workspace_prev_next_impl(current, 1);
|
||||
}
|
||||
|
||||
struct sway_container *workspace_output_prev(struct sway_container *current) {
|
||||
return workspace_output_prev_next_impl(current, -1);
|
||||
struct sway_workspace *workspace_output_prev(struct sway_workspace *current) {
|
||||
return workspace_output_prev_next_impl(current->output, -1);
|
||||
}
|
||||
|
||||
struct sway_container *workspace_prev(struct sway_container *current) {
|
||||
struct sway_workspace *workspace_prev(struct sway_workspace *current) {
|
||||
return workspace_prev_next_impl(current, -1);
|
||||
}
|
||||
|
||||
bool workspace_switch(struct sway_container *workspace,
|
||||
bool workspace_switch(struct sway_workspace *workspace,
|
||||
bool no_auto_back_and_forth) {
|
||||
if (!workspace) {
|
||||
return false;
|
||||
}
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_container *focus =
|
||||
seat_get_focus_inactive(seat, &root_container);
|
||||
if (!seat || !focus) {
|
||||
return false;
|
||||
}
|
||||
struct sway_container *active_ws = focus;
|
||||
if (active_ws->type != C_WORKSPACE) {
|
||||
active_ws = container_parent(focus, C_WORKSPACE);
|
||||
}
|
||||
struct sway_node *focus = seat_get_focus_inactive(seat, &root->node);
|
||||
struct sway_workspace *active_ws = seat_get_focused_workspace(seat);
|
||||
|
||||
if (!no_auto_back_and_forth && config->auto_back_and_forth
|
||||
&& active_ws == workspace
|
||||
&& prev_workspace_name) {
|
||||
struct sway_container *new_ws = workspace_by_name(prev_workspace_name);
|
||||
struct sway_workspace *new_ws = workspace_by_name(prev_workspace_name);
|
||||
workspace = new_ws ?
|
||||
new_ws :
|
||||
workspace_create(NULL, prev_workspace_name);
|
||||
|
|
@ -447,21 +385,21 @@ bool workspace_switch(struct sway_container *workspace,
|
|||
}
|
||||
|
||||
// Move sticky containers to new workspace
|
||||
struct sway_container *next_output = workspace->parent;
|
||||
struct sway_container *next_output_prev_ws =
|
||||
seat_get_active_child(seat, next_output);
|
||||
list_t *floating = next_output_prev_ws->sway_workspace->floating;
|
||||
struct sway_output *next_output = workspace->output;
|
||||
struct sway_workspace *next_output_prev_ws =
|
||||
output_get_active_workspace(next_output);
|
||||
bool has_sticky = false;
|
||||
if (workspace != next_output_prev_ws) {
|
||||
for (int i = 0; i < floating->length; ++i) {
|
||||
struct sway_container *floater = floating->items[i];
|
||||
for (int i = 0; i < next_output_prev_ws->floating->length; ++i) {
|
||||
struct sway_container *floater =
|
||||
next_output_prev_ws->floating->items[i];
|
||||
if (floater->is_sticky) {
|
||||
has_sticky = true;
|
||||
container_remove_child(floater);
|
||||
container_detach(floater);
|
||||
workspace_add_floating(workspace, floater);
|
||||
if (floater == focus) {
|
||||
if (&floater->node == focus) {
|
||||
seat_set_focus(seat, NULL);
|
||||
seat_set_focus(seat, floater);
|
||||
seat_set_focus(seat, &floater->node);
|
||||
}
|
||||
--i;
|
||||
}
|
||||
|
|
@ -470,9 +408,9 @@ bool workspace_switch(struct sway_container *workspace,
|
|||
|
||||
wlr_log(WLR_DEBUG, "Switching to workspace %p:%s",
|
||||
workspace, workspace->name);
|
||||
struct sway_container *next = seat_get_focus_inactive(seat, workspace);
|
||||
struct sway_node *next = seat_get_focus_inactive(seat, &workspace->node);
|
||||
if (next == NULL) {
|
||||
next = workspace;
|
||||
next = &workspace->node;
|
||||
}
|
||||
if (has_sticky) {
|
||||
// If there's a sticky container, we might be setting focus to the same
|
||||
|
|
@ -483,35 +421,24 @@ bool workspace_switch(struct sway_container *workspace,
|
|||
workspace_consider_destroy(active_ws);
|
||||
}
|
||||
seat_set_focus(seat, next);
|
||||
struct sway_container *output = container_parent(workspace, C_OUTPUT);
|
||||
arrange_windows(output);
|
||||
arrange_workspace(workspace);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool workspace_is_visible(struct sway_container *ws) {
|
||||
if (ws->destroying) {
|
||||
bool workspace_is_visible(struct sway_workspace *ws) {
|
||||
if (ws->node.destroying) {
|
||||
return false;
|
||||
}
|
||||
struct sway_container *output = container_parent(ws, C_OUTPUT);
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_container *focus = seat_get_focus_inactive(seat, output);
|
||||
if (focus->type != C_WORKSPACE) {
|
||||
focus = container_parent(focus, C_WORKSPACE);
|
||||
}
|
||||
return focus == ws;
|
||||
return output_get_active_workspace(ws->output) == ws;
|
||||
}
|
||||
|
||||
bool workspace_is_empty(struct sway_container *ws) {
|
||||
if (!sway_assert(ws->type == C_WORKSPACE, "Expected a workspace")) {
|
||||
return false;
|
||||
}
|
||||
if (ws->children->length) {
|
||||
bool workspace_is_empty(struct sway_workspace *ws) {
|
||||
if (ws->tiling->length) {
|
||||
return false;
|
||||
}
|
||||
// Sticky views are not considered to be part of this workspace
|
||||
list_t *floating = ws->sway_workspace->floating;
|
||||
for (int i = 0; i < floating->length; ++i) {
|
||||
struct sway_container *floater = floating->items[i];
|
||||
for (int i = 0; i < ws->floating->length; ++i) {
|
||||
struct sway_container *floater = ws->floating->items[i];
|
||||
if (!floater->is_sticky) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -523,20 +450,19 @@ static int find_output(const void *id1, const void *id2) {
|
|||
return strcmp(id1, id2) ? 0 : 1;
|
||||
}
|
||||
|
||||
void workspace_output_raise_priority(struct sway_container *workspace,
|
||||
struct sway_container *old_output, struct sway_container *output) {
|
||||
struct sway_workspace *ws = workspace->sway_workspace;
|
||||
|
||||
void workspace_output_raise_priority(struct sway_workspace *ws,
|
||||
struct sway_output *old_output, struct sway_output *output) {
|
||||
int old_index = list_seq_find(ws->output_priority, find_output,
|
||||
old_output->name);
|
||||
old_output->wlr_output->name);
|
||||
if (old_index < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int new_index = list_seq_find(ws->output_priority, find_output,
|
||||
output->name);
|
||||
output->wlr_output->name);
|
||||
if (new_index < 0) {
|
||||
list_insert(ws->output_priority, old_index, strdup(output->name));
|
||||
list_insert(ws->output_priority, old_index,
|
||||
strdup(output->wlr_output->name));
|
||||
} else if (new_index > old_index) {
|
||||
char *name = ws->output_priority->items[new_index];
|
||||
list_del(ws->output_priority, new_index);
|
||||
|
|
@ -544,29 +470,24 @@ void workspace_output_raise_priority(struct sway_container *workspace,
|
|||
}
|
||||
}
|
||||
|
||||
void workspace_output_add_priority(struct sway_container *workspace,
|
||||
struct sway_container *output) {
|
||||
int index = list_seq_find(workspace->sway_workspace->output_priority,
|
||||
find_output, output->name);
|
||||
void workspace_output_add_priority(struct sway_workspace *workspace,
|
||||
struct sway_output *output) {
|
||||
int index = list_seq_find(workspace->output_priority,
|
||||
find_output, output->wlr_output->name);
|
||||
if (index < 0) {
|
||||
list_add(workspace->sway_workspace->output_priority,
|
||||
strdup(output->name));
|
||||
list_add(workspace->output_priority, strdup(output->wlr_output->name));
|
||||
}
|
||||
}
|
||||
|
||||
static bool _output_by_name(struct sway_container *output, void *data) {
|
||||
return output->type == C_OUTPUT && strcasecmp(output->name, data) == 0;
|
||||
}
|
||||
|
||||
struct sway_container *workspace_output_get_highest_available(
|
||||
struct sway_container *ws, struct sway_container *exclude) {
|
||||
for (int i = 0; i < ws->sway_workspace->output_priority->length; i++) {
|
||||
char *name = ws->sway_workspace->output_priority->items[i];
|
||||
if (exclude && strcasecmp(name, exclude->name) == 0) {
|
||||
struct sway_output *workspace_output_get_highest_available(
|
||||
struct sway_workspace *ws, struct sway_output *exclude) {
|
||||
for (int i = 0; i < ws->output_priority->length; i++) {
|
||||
char *name = ws->output_priority->items[i];
|
||||
if (exclude && strcasecmp(name, exclude->wlr_output->name) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
struct sway_container *output = root_find_output(_output_by_name, name);
|
||||
struct sway_output *output = output_by_name(name);
|
||||
if (output) {
|
||||
return output;
|
||||
}
|
||||
|
|
@ -576,49 +497,42 @@ struct sway_container *workspace_output_get_highest_available(
|
|||
}
|
||||
|
||||
static bool find_urgent_iterator(struct sway_container *con, void *data) {
|
||||
return con->type == C_VIEW && view_is_urgent(con->sway_view);
|
||||
return con->view && view_is_urgent(con->view);
|
||||
}
|
||||
|
||||
void workspace_detect_urgent(struct sway_container *workspace) {
|
||||
void workspace_detect_urgent(struct sway_workspace *workspace) {
|
||||
bool new_urgent = (bool)workspace_find_container(workspace,
|
||||
find_urgent_iterator, NULL);
|
||||
|
||||
if (workspace->sway_workspace->urgent != new_urgent) {
|
||||
workspace->sway_workspace->urgent = new_urgent;
|
||||
if (workspace->urgent != new_urgent) {
|
||||
workspace->urgent = new_urgent;
|
||||
ipc_event_workspace(NULL, workspace, "urgent");
|
||||
container_damage_whole(workspace);
|
||||
output_damage_whole(workspace->output);
|
||||
}
|
||||
}
|
||||
|
||||
void workspace_for_each_container(struct sway_container *ws,
|
||||
void workspace_for_each_container(struct sway_workspace *ws,
|
||||
void (*f)(struct sway_container *con, void *data), void *data) {
|
||||
if (!sway_assert(ws->type == C_WORKSPACE, "Expected a workspace")) {
|
||||
return;
|
||||
}
|
||||
// Tiling
|
||||
for (int i = 0; i < ws->children->length; ++i) {
|
||||
struct sway_container *container = ws->children->items[i];
|
||||
for (int i = 0; i < ws->tiling->length; ++i) {
|
||||
struct sway_container *container = ws->tiling->items[i];
|
||||
f(container, data);
|
||||
container_for_each_child(container, f, data);
|
||||
}
|
||||
// Floating
|
||||
for (int i = 0; i < ws->sway_workspace->floating->length; ++i) {
|
||||
struct sway_container *container =
|
||||
ws->sway_workspace->floating->items[i];
|
||||
for (int i = 0; i < ws->floating->length; ++i) {
|
||||
struct sway_container *container = ws->floating->items[i];
|
||||
f(container, data);
|
||||
container_for_each_child(container, f, data);
|
||||
}
|
||||
}
|
||||
|
||||
struct sway_container *workspace_find_container(struct sway_container *ws,
|
||||
struct sway_container *workspace_find_container(struct sway_workspace *ws,
|
||||
bool (*test)(struct sway_container *con, void *data), void *data) {
|
||||
if (!sway_assert(ws->type == C_WORKSPACE, "Expected a workspace")) {
|
||||
return NULL;
|
||||
}
|
||||
struct sway_container *result = NULL;
|
||||
// Tiling
|
||||
for (int i = 0; i < ws->children->length; ++i) {
|
||||
struct sway_container *child = ws->children->items[i];
|
||||
for (int i = 0; i < ws->tiling->length; ++i) {
|
||||
struct sway_container *child = ws->tiling->items[i];
|
||||
if (test(child, data)) {
|
||||
return child;
|
||||
}
|
||||
|
|
@ -627,8 +541,8 @@ struct sway_container *workspace_find_container(struct sway_container *ws,
|
|||
}
|
||||
}
|
||||
// Floating
|
||||
for (int i = 0; i < ws->sway_workspace->floating->length; ++i) {
|
||||
struct sway_container *child = ws->sway_workspace->floating->items[i];
|
||||
for (int i = 0; i < ws->floating->length; ++i) {
|
||||
struct sway_container *child = ws->floating->items[i];
|
||||
if (test(child, data)) {
|
||||
return child;
|
||||
}
|
||||
|
|
@ -639,37 +553,76 @@ struct sway_container *workspace_find_container(struct sway_container *ws,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct sway_container *workspace_wrap_children(struct sway_container *ws) {
|
||||
struct sway_container *middle = container_create(C_CONTAINER);
|
||||
struct sway_container *workspace_wrap_children(struct sway_workspace *ws) {
|
||||
struct sway_container *middle = container_create(NULL);
|
||||
middle->layout = ws->layout;
|
||||
while (ws->children->length) {
|
||||
struct sway_container *child = ws->children->items[0];
|
||||
container_remove_child(child);
|
||||
while (ws->tiling->length) {
|
||||
struct sway_container *child = ws->tiling->items[0];
|
||||
container_detach(child);
|
||||
container_add_child(middle, child);
|
||||
}
|
||||
container_add_child(ws, middle);
|
||||
workspace_add_tiling(ws, middle);
|
||||
return middle;
|
||||
}
|
||||
|
||||
void workspace_add_floating(struct sway_container *workspace,
|
||||
struct sway_container *con) {
|
||||
if (!sway_assert(workspace->type == C_WORKSPACE, "Expected a workspace")) {
|
||||
return;
|
||||
}
|
||||
if (!sway_assert(con->parent == NULL, "Expected an orphan container")) {
|
||||
return;
|
||||
void workspace_detach(struct sway_workspace *workspace) {
|
||||
struct sway_output *output = workspace->output;
|
||||
int index = list_find(output->workspaces, workspace);
|
||||
if (index != -1) {
|
||||
list_del(output->workspaces, index);
|
||||
}
|
||||
workspace->output = NULL;
|
||||
|
||||
list_add(workspace->sway_workspace->floating, con);
|
||||
con->parent = workspace;
|
||||
container_set_dirty(workspace);
|
||||
container_set_dirty(con);
|
||||
node_set_dirty(&workspace->node);
|
||||
node_set_dirty(&output->node);
|
||||
}
|
||||
|
||||
void workspace_remove_gaps(struct sway_container *ws) {
|
||||
if (!sway_assert(ws->type == C_WORKSPACE, "Expected a workspace")) {
|
||||
return;
|
||||
static void set_workspace(struct sway_container *container, void *data) {
|
||||
container->workspace = container->parent->workspace;
|
||||
}
|
||||
|
||||
void workspace_add_tiling(struct sway_workspace *workspace,
|
||||
struct sway_container *con) {
|
||||
if (con->workspace) {
|
||||
container_detach(con);
|
||||
}
|
||||
list_add(workspace->tiling, con);
|
||||
con->workspace = workspace;
|
||||
container_for_each_child(con, set_workspace, NULL);
|
||||
container_handle_fullscreen_reparent(con);
|
||||
workspace_update_representation(workspace);
|
||||
node_set_dirty(&workspace->node);
|
||||
node_set_dirty(&con->node);
|
||||
}
|
||||
|
||||
void workspace_add_floating(struct sway_workspace *workspace,
|
||||
struct sway_container *con) {
|
||||
if (con->workspace) {
|
||||
container_detach(con);
|
||||
}
|
||||
list_add(workspace->floating, con);
|
||||
con->workspace = workspace;
|
||||
container_for_each_child(con, set_workspace, NULL);
|
||||
container_handle_fullscreen_reparent(con);
|
||||
node_set_dirty(&workspace->node);
|
||||
node_set_dirty(&con->node);
|
||||
}
|
||||
|
||||
void workspace_insert_tiling(struct sway_workspace *workspace,
|
||||
struct sway_container *con, int index) {
|
||||
if (con->workspace) {
|
||||
container_detach(con);
|
||||
}
|
||||
list_insert(workspace->tiling, index, con);
|
||||
con->workspace = workspace;
|
||||
container_for_each_child(con, set_workspace, NULL);
|
||||
container_handle_fullscreen_reparent(con);
|
||||
workspace_update_representation(workspace);
|
||||
node_set_dirty(&workspace->node);
|
||||
node_set_dirty(&con->node);
|
||||
}
|
||||
|
||||
void workspace_remove_gaps(struct sway_workspace *ws) {
|
||||
if (ws->current_gaps == 0) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -681,15 +634,12 @@ void workspace_remove_gaps(struct sway_container *ws) {
|
|||
ws->current_gaps = 0;
|
||||
}
|
||||
|
||||
void workspace_add_gaps(struct sway_container *ws) {
|
||||
if (!sway_assert(ws->type == C_WORKSPACE, "Expected a workspace")) {
|
||||
return;
|
||||
}
|
||||
void workspace_add_gaps(struct sway_workspace *ws) {
|
||||
if (ws->current_gaps > 0) {
|
||||
return;
|
||||
}
|
||||
bool should_apply =
|
||||
config->edge_gaps || (config->smart_gaps && ws->children->length > 1);
|
||||
config->edge_gaps || (config->smart_gaps && ws->tiling->length > 1);
|
||||
if (!should_apply) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -708,3 +658,36 @@ void workspace_add_gaps(struct sway_container *ws) {
|
|||
ws->width -= 2 * ws->current_gaps;
|
||||
ws->height -= 2 * ws->current_gaps;
|
||||
}
|
||||
|
||||
struct sway_container *workspace_split(struct sway_workspace *workspace,
|
||||
enum sway_container_layout layout) {
|
||||
if (workspace->tiling->length == 0) {
|
||||
workspace->prev_split_layout = workspace->layout;
|
||||
workspace->layout = layout;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
enum sway_container_layout old_layout = workspace->layout;
|
||||
struct sway_container *middle = workspace_wrap_children(workspace);
|
||||
workspace->layout = layout;
|
||||
middle->layout = old_layout;
|
||||
|
||||
return middle;
|
||||
}
|
||||
|
||||
void workspace_update_representation(struct sway_workspace *ws) {
|
||||
size_t len = container_build_representation(ws->layout, ws->tiling, NULL);
|
||||
free(ws->representation);
|
||||
ws->representation = calloc(len + 1, sizeof(char));
|
||||
if (!sway_assert(ws->representation, "Unable to allocate title string")) {
|
||||
return;
|
||||
}
|
||||
container_build_representation(ws->layout, ws->tiling, ws->representation);
|
||||
}
|
||||
|
||||
void workspace_get_box(struct sway_workspace *workspace, struct wlr_box *box) {
|
||||
box->x = workspace->x;
|
||||
box->y = workspace->y;
|
||||
box->width = workspace->width;
|
||||
box->height = workspace->height;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue