2015-12-18 01:01:02 +01:00
|
|
|
#include <ctype.h>
|
2015-08-14 21:42:19 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <strings.h>
|
2015-09-18 13:27:35 +02:00
|
|
|
#include <string.h>
|
2016-09-01 14:18:37 +02:00
|
|
|
#include "sway/config.h"
|
|
|
|
#include "sway/container.h"
|
|
|
|
#include "sway/workspace.h"
|
|
|
|
#include "sway/focus.h"
|
|
|
|
#include "sway/border.h"
|
|
|
|
#include "sway/layout.h"
|
|
|
|
#include "sway/input_state.h"
|
|
|
|
#include "sway/ipc-server.h"
|
|
|
|
#include "sway/output.h"
|
2015-08-14 21:42:19 +02:00
|
|
|
#include "log.h"
|
2016-09-01 14:18:37 +02:00
|
|
|
#include "stringop.h"
|
2015-08-10 22:31:23 +02:00
|
|
|
|
2015-08-20 18:52:54 +02:00
|
|
|
#define ASSERT_NONNULL(PTR) \
|
2015-08-26 20:01:26 +02:00
|
|
|
sway_assert (PTR, #PTR "must be non-null")
|
2015-08-14 21:42:19 +02:00
|
|
|
|
2016-09-22 04:05:09 +02:00
|
|
|
|
2015-08-14 21:42:19 +02:00
|
|
|
static swayc_t *new_swayc(enum swayc_types type) {
|
2016-09-22 04:05:09 +02:00
|
|
|
// next id starts at 1 because 0 is assigned to root_container in layout.c
|
|
|
|
static size_t next_id = 1;
|
2015-08-14 21:42:19 +02:00
|
|
|
swayc_t *c = calloc(1, sizeof(swayc_t));
|
2016-09-22 04:05:09 +02:00
|
|
|
c->id = next_id++;
|
2015-08-14 21:42:19 +02:00
|
|
|
c->handle = -1;
|
2015-09-05 01:14:59 +02:00
|
|
|
c->gaps = -1;
|
2015-08-14 21:42:19 +02:00
|
|
|
c->layout = L_NONE;
|
|
|
|
c->type = type;
|
|
|
|
if (type != C_VIEW) {
|
|
|
|
c->children = create_list();
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2015-08-20 18:52:54 +02:00
|
|
|
static void free_swayc(swayc_t *cont) {
|
|
|
|
if (!ASSERT_NONNULL(cont)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (cont->children) {
|
2015-08-21 21:19:29 +02:00
|
|
|
// remove children until there are no more, free_swayc calls
|
|
|
|
// remove_child, which removes child from this container
|
|
|
|
while (cont->children->length) {
|
|
|
|
free_swayc(cont->children->items[0]);
|
2015-08-18 20:22:52 +02:00
|
|
|
}
|
2015-08-20 18:52:54 +02:00
|
|
|
list_free(cont->children);
|
2015-08-14 21:42:19 +02:00
|
|
|
}
|
2015-12-17 01:20:34 +01:00
|
|
|
if (cont->unmanaged) {
|
|
|
|
list_free(cont->unmanaged);
|
|
|
|
}
|
2015-08-20 18:52:54 +02:00
|
|
|
if (cont->floating) {
|
2015-08-31 17:49:24 +02:00
|
|
|
while (cont->floating->length) {
|
|
|
|
free_swayc(cont->floating->items[0]);
|
2015-08-18 20:22:52 +02:00
|
|
|
}
|
2015-08-20 18:52:54 +02:00
|
|
|
list_free(cont->floating);
|
2015-08-18 20:22:52 +02:00
|
|
|
}
|
2015-08-20 18:52:54 +02:00
|
|
|
if (cont->parent) {
|
|
|
|
remove_child(cont);
|
2015-08-14 21:42:19 +02:00
|
|
|
}
|
2015-08-20 18:52:54 +02:00
|
|
|
if (cont->name) {
|
|
|
|
free(cont->name);
|
2015-08-16 22:38:54 +02:00
|
|
|
}
|
2015-11-22 22:05:00 +01:00
|
|
|
if (cont->class) {
|
|
|
|
free(cont->class);
|
|
|
|
}
|
2015-11-22 22:09:33 +01:00
|
|
|
if (cont->app_id) {
|
|
|
|
free(cont->app_id);
|
|
|
|
}
|
2015-12-18 18:02:39 +01:00
|
|
|
if (cont->bg_pid != 0) {
|
|
|
|
terminate_swaybg(cont->bg_pid);
|
|
|
|
}
|
2016-04-20 00:22:15 +02:00
|
|
|
if (cont->border) {
|
|
|
|
if (cont->border->buffer) {
|
|
|
|
free(cont->border->buffer);
|
|
|
|
}
|
|
|
|
free(cont->border);
|
|
|
|
}
|
2015-08-20 18:52:54 +02:00
|
|
|
free(cont);
|
2015-08-14 21:42:19 +02:00
|
|
|
}
|
|
|
|
|
2016-07-04 20:34:44 +02:00
|
|
|
static void update_root_geometry() {
|
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
|
|
|
swayc_t *child;
|
|
|
|
int child_width;
|
|
|
|
int child_height;
|
|
|
|
|
|
|
|
for (int i = 0; i < root_container.children->length; ++i) {
|
|
|
|
child = root_container.children->items[i];
|
|
|
|
child_width = child->width + child->x;
|
|
|
|
child_height = child->height + child->y;
|
|
|
|
if (child_width > width) {
|
|
|
|
width = child_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child_height > height) {
|
|
|
|
height = child_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
root_container.width = width;
|
|
|
|
root_container.height = height;
|
|
|
|
}
|
|
|
|
|
2015-08-20 18:52:54 +02:00
|
|
|
// New containers
|
2015-08-14 21:42:19 +02:00
|
|
|
|
|
|
|
swayc_t *new_output(wlc_handle handle) {
|
2016-07-16 16:04:18 +02:00
|
|
|
struct wlc_size size;
|
2016-07-18 22:21:45 +02:00
|
|
|
output_get_scaled_size(handle, &size);
|
2015-08-16 19:07:43 +02:00
|
|
|
const char *name = wlc_output_get_name(handle);
|
2015-08-28 05:32:56 +02:00
|
|
|
// Find current outputs to see if this already exists
|
2015-09-14 01:46:16 +02:00
|
|
|
{
|
|
|
|
int i, len = root_container.children->length;
|
2015-08-28 05:32:56 +02:00
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
swayc_t *op = root_container.children->items[i];
|
2015-09-14 01:46:16 +02:00
|
|
|
const char *op_name = op->name;
|
|
|
|
if (op_name && name && strcmp(op_name, name) == 0) {
|
2016-04-17 16:26:26 +02:00
|
|
|
sway_log(L_DEBUG, "restoring output %" PRIuPTR ":%s", handle, op_name);
|
2015-08-28 05:32:56 +02:00
|
|
|
return op;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-17 16:26:26 +02:00
|
|
|
sway_log(L_DEBUG, "New output %" PRIuPTR ":%s", handle, name);
|
2015-08-14 21:42:19 +02:00
|
|
|
|
2016-02-12 13:22:20 +01:00
|
|
|
struct output_config *oc = NULL, *all = NULL;
|
2015-09-14 01:46:16 +02:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < config->output_configs->length; ++i) {
|
2015-12-02 22:04:50 +01:00
|
|
|
struct output_config *cur = config->output_configs->items[i];
|
|
|
|
if (strcasecmp(name, cur->name) == 0) {
|
2015-08-22 17:18:55 +02:00
|
|
|
sway_log(L_DEBUG, "Matched output config for %s", name);
|
2015-12-02 22:04:50 +01:00
|
|
|
oc = cur;
|
2015-08-22 17:18:55 +02:00
|
|
|
}
|
2015-12-02 22:04:50 +01:00
|
|
|
if (strcasecmp("*", cur->name) == 0) {
|
2015-11-28 16:18:37 +01:00
|
|
|
sway_log(L_DEBUG, "Matched wildcard output config for %s", name);
|
2016-02-12 13:22:20 +01:00
|
|
|
all = cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oc && all) {
|
2015-11-28 16:18:37 +01:00
|
|
|
break;
|
|
|
|
}
|
2015-08-22 17:18:55 +02:00
|
|
|
}
|
|
|
|
|
2016-02-12 13:22:20 +01:00
|
|
|
if (!oc) {
|
|
|
|
oc = all;
|
|
|
|
}
|
|
|
|
|
2015-08-23 19:22:45 +02:00
|
|
|
if (oc && !oc->enabled) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-23 19:22:33 +02:00
|
|
|
|
2015-08-14 21:42:19 +02:00
|
|
|
swayc_t *output = new_swayc(C_OUTPUT);
|
2015-08-15 21:10:44 +02:00
|
|
|
output->handle = handle;
|
2015-08-17 19:02:09 +02:00
|
|
|
output->name = name ? strdup(name) : NULL;
|
2016-07-16 16:04:18 +02:00
|
|
|
output->width = size.w;
|
|
|
|
output->height = size.h;
|
2015-12-17 01:20:34 +01:00
|
|
|
output->unmanaged = create_list();
|
2015-12-18 17:43:03 +01:00
|
|
|
output->bg_pid = 0;
|
2015-09-14 01:46:16 +02:00
|
|
|
|
2015-10-21 16:34:12 +02:00
|
|
|
apply_output_config(oc, output);
|
2015-09-12 11:38:03 +02:00
|
|
|
add_child(&root_container, output);
|
2016-09-17 09:25:45 +02:00
|
|
|
load_swaybars();
|
2015-08-18 13:19:20 +02:00
|
|
|
|
2015-09-14 01:46:16 +02:00
|
|
|
// Create workspace
|
|
|
|
char *ws_name = NULL;
|
2016-05-29 01:18:46 +02:00
|
|
|
swayc_t *ws = NULL;
|
|
|
|
|
2015-09-14 01:46:16 +02:00
|
|
|
if (name) {
|
|
|
|
for (i = 0; i < config->workspace_outputs->length; ++i) {
|
|
|
|
struct workspace_output *wso = config->workspace_outputs->items[i];
|
|
|
|
if (strcasecmp(wso->output, name) == 0) {
|
|
|
|
sway_log(L_DEBUG, "Matched workspace to output: %s for %s", wso->workspace, wso->output);
|
|
|
|
// Check if any other workspaces are using this name
|
2016-05-29 01:18:46 +02:00
|
|
|
if ((ws = workspace_by_name(wso->workspace))) {
|
|
|
|
// if yes, move those to this output, because they should be here
|
|
|
|
move_workspace_to(ws, output);
|
|
|
|
} else if (!ws_name) {
|
|
|
|
// set a workspace name in case we need to create a default one
|
|
|
|
ws_name = strdup(wso->workspace);
|
2015-09-14 01:46:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-29 01:18:46 +02:00
|
|
|
if (output->children->length == 0) {
|
|
|
|
if (!ws_name) {
|
|
|
|
ws_name = workspace_next_name(output->name);
|
|
|
|
}
|
|
|
|
// create and initialize default workspace
|
|
|
|
sway_log(L_DEBUG, "Creating default workspace %s", ws_name);
|
|
|
|
ws = new_workspace(output, ws_name);
|
|
|
|
ws->is_focused = true;
|
|
|
|
} else {
|
|
|
|
sort_workspaces(output);
|
|
|
|
set_focused_container(output->children->items[0]);
|
|
|
|
}
|
2015-08-18 09:28:44 +02:00
|
|
|
|
2015-09-14 01:46:16 +02:00
|
|
|
free(ws_name);
|
2016-07-04 20:34:44 +02:00
|
|
|
update_root_geometry();
|
2015-08-14 21:42:19 +02:00
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2015-08-18 02:34:53 +02:00
|
|
|
swayc_t *new_workspace(swayc_t *output, const char *name) {
|
2015-09-14 01:46:16 +02:00
|
|
|
if (!ASSERT_NONNULL(output)) {
|
|
|
|
return NULL;
|
2015-08-20 18:52:54 +02:00
|
|
|
}
|
2015-09-14 01:46:16 +02:00
|
|
|
sway_log(L_DEBUG, "Added workspace %s for output %u", name, (unsigned int)output->handle);
|
2015-08-14 21:42:19 +02:00
|
|
|
swayc_t *workspace = new_swayc(C_WORKSPACE);
|
2015-09-14 01:46:16 +02:00
|
|
|
|
2016-04-02 16:29:31 +02:00
|
|
|
workspace->prev_layout = L_NONE;
|
2016-10-13 03:26:06 +02:00
|
|
|
workspace->layout = default_layout(output);
|
2016-04-01 15:58:29 +02:00
|
|
|
|
2015-08-18 23:53:57 +02:00
|
|
|
workspace->x = output->x;
|
|
|
|
workspace->y = output->y;
|
2015-08-15 21:10:44 +02:00
|
|
|
workspace->width = output->width;
|
|
|
|
workspace->height = output->height;
|
|
|
|
workspace->name = strdup(name);
|
2015-08-27 00:44:47 +02:00
|
|
|
workspace->visible = false;
|
2015-08-17 07:38:34 +02:00
|
|
|
workspace->floating = create_list();
|
2015-08-14 21:42:19 +02:00
|
|
|
|
2016-05-28 00:37:56 +02:00
|
|
|
add_child(output, workspace);
|
|
|
|
sort_workspaces(output);
|
2015-12-18 01:01:02 +01:00
|
|
|
|
2015-08-14 21:42:19 +02:00
|
|
|
return workspace;
|
|
|
|
}
|
|
|
|
|
|
|
|
swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) {
|
2015-08-21 19:28:37 +02:00
|
|
|
if (!ASSERT_NONNULL(child)
|
|
|
|
&& !sway_assert(!child->is_floating, "cannot create container around floating window")) {
|
2015-08-20 18:52:54 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-14 21:42:19 +02:00
|
|
|
swayc_t *cont = new_swayc(C_CONTAINER);
|
|
|
|
|
|
|
|
sway_log(L_DEBUG, "creating container %p around %p", cont, child);
|
|
|
|
|
2016-04-02 16:29:31 +02:00
|
|
|
cont->prev_layout = L_NONE;
|
2015-08-15 21:10:44 +02:00
|
|
|
cont->layout = layout;
|
2015-08-15 21:12:42 +02:00
|
|
|
cont->width = child->width;
|
2015-08-15 21:10:44 +02:00
|
|
|
cont->height = child->height;
|
2015-08-17 19:02:09 +02:00
|
|
|
cont->x = child->x;
|
2015-08-15 21:10:44 +02:00
|
|
|
cont->y = child->y;
|
|
|
|
cont->visible = child->visible;
|
2016-04-20 00:22:15 +02:00
|
|
|
cont->cached_geometry = child->cached_geometry;
|
2016-04-22 22:44:02 +02:00
|
|
|
cont->gaps = child->gaps;
|
2015-08-14 21:42:19 +02:00
|
|
|
|
2015-08-15 20:19:44 +02:00
|
|
|
/* Container inherits all of workspaces children, layout and whatnot */
|
|
|
|
if (child->type == C_WORKSPACE) {
|
|
|
|
swayc_t *workspace = child;
|
2015-08-18 13:19:20 +02:00
|
|
|
// reorder focus
|
2015-08-15 20:19:44 +02:00
|
|
|
cont->focused = workspace->focused;
|
|
|
|
workspace->focused = cont;
|
2015-08-18 13:19:20 +02:00
|
|
|
// set all children focu to container
|
2015-08-18 11:46:14 +02:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < workspace->children->length; ++i) {
|
|
|
|
((swayc_t *)workspace->children->items[i])->parent = cont;
|
|
|
|
}
|
2015-08-18 13:19:20 +02:00
|
|
|
// Swap children
|
2015-08-15 20:19:44 +02:00
|
|
|
list_t *tmp_list = workspace->children;
|
|
|
|
workspace->children = cont->children;
|
|
|
|
cont->children = tmp_list;
|
2015-08-18 13:19:20 +02:00
|
|
|
// add container to workspace chidren
|
2015-08-15 20:19:44 +02:00
|
|
|
add_child(workspace, cont);
|
2015-08-18 13:19:20 +02:00
|
|
|
// give them proper layouts
|
2016-10-13 03:26:06 +02:00
|
|
|
cont->layout = workspace->layout;
|
2016-04-02 16:29:31 +02:00
|
|
|
cont->prev_layout = workspace->prev_layout;
|
2016-04-01 13:36:36 +02:00
|
|
|
/* TODO: might break shit in move_container!!! workspace->layout = layout; */
|
2015-08-20 01:15:17 +02:00
|
|
|
set_focused_container_for(workspace, get_focused_view(workspace));
|
2015-08-18 13:19:20 +02:00
|
|
|
} else { // Or is built around container
|
2015-08-15 20:19:44 +02:00
|
|
|
swayc_t *parent = replace_child(child, cont);
|
|
|
|
if (parent) {
|
|
|
|
add_child(cont, child);
|
|
|
|
}
|
2015-08-14 21:42:19 +02:00
|
|
|
}
|
|
|
|
return cont;
|
|
|
|
}
|
|
|
|
|
|
|
|
swayc_t *new_view(swayc_t *sibling, wlc_handle handle) {
|
2015-08-20 18:52:54 +02:00
|
|
|
if (!ASSERT_NONNULL(sibling)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-18 09:28:44 +02:00
|
|
|
const char *title = wlc_view_get_title(handle);
|
2015-08-14 21:42:19 +02:00
|
|
|
swayc_t *view = new_swayc(C_VIEW);
|
2016-04-17 16:26:26 +02:00
|
|
|
sway_log(L_DEBUG, "Adding new view %" PRIuPTR ":%s to container %p %d",
|
2015-08-18 09:28:44 +02:00
|
|
|
handle, title, sibling, sibling ? sibling->type : 0);
|
2015-08-18 13:19:20 +02:00
|
|
|
// Setup values
|
2015-08-15 21:10:44 +02:00
|
|
|
view->handle = handle;
|
2015-08-17 19:02:09 +02:00
|
|
|
view->name = title ? strdup(title) : NULL;
|
2015-11-22 22:05:00 +01:00
|
|
|
const char *class = wlc_view_get_class(handle);
|
|
|
|
view->class = class ? strdup(class) : NULL;
|
2015-11-22 22:09:33 +01:00
|
|
|
const char *app_id = wlc_view_get_app_id(handle);
|
|
|
|
view->app_id = app_id ? strdup(app_id) : NULL;
|
2015-08-14 21:42:19 +02:00
|
|
|
view->visible = true;
|
2015-08-18 09:28:44 +02:00
|
|
|
view->is_focused = true;
|
2015-11-26 23:53:20 +01:00
|
|
|
view->sticky = false;
|
2015-08-20 13:57:01 +02:00
|
|
|
view->width = 0;
|
|
|
|
view->height = 0;
|
2016-04-09 22:51:58 +02:00
|
|
|
view->desired_width = -1;
|
|
|
|
view->desired_height = -1;
|
2016-03-31 12:17:21 +02:00
|
|
|
// setup border
|
|
|
|
view->border_type = config->border;
|
|
|
|
view->border_thickness = config->border_thickness;
|
2015-08-14 21:42:19 +02:00
|
|
|
|
2015-08-17 07:38:34 +02:00
|
|
|
view->is_floating = false;
|
|
|
|
|
2015-08-14 21:42:19 +02:00
|
|
|
if (sibling->type == C_WORKSPACE) {
|
2015-08-18 13:19:20 +02:00
|
|
|
// Case of focused workspace, just create as child of it
|
2015-08-14 21:42:19 +02:00
|
|
|
add_child(sibling, view);
|
2015-08-18 13:19:20 +02:00
|
|
|
} else {
|
|
|
|
// Regular case, create as sibling of current container
|
2015-08-14 21:42:19 +02:00
|
|
|
add_sibling(sibling, view);
|
|
|
|
}
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2015-08-17 17:18:06 +02:00
|
|
|
swayc_t *new_floating_view(wlc_handle handle) {
|
2015-08-21 19:28:37 +02:00
|
|
|
if (swayc_active_workspace() == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-18 13:19:20 +02:00
|
|
|
const char *title = wlc_view_get_title(handle);
|
2015-08-17 17:18:06 +02:00
|
|
|
swayc_t *view = new_swayc(C_VIEW);
|
2016-04-17 16:26:26 +02:00
|
|
|
sway_log(L_DEBUG, "Adding new view %" PRIuPTR ":%x:%s as a floating view",
|
2015-08-18 09:28:44 +02:00
|
|
|
handle, wlc_view_get_type(handle), title);
|
2015-08-18 13:19:20 +02:00
|
|
|
// Setup values
|
2015-08-17 17:18:06 +02:00
|
|
|
view->handle = handle;
|
2015-08-17 19:02:09 +02:00
|
|
|
view->name = title ? strdup(title) : NULL;
|
2015-11-22 22:05:00 +01:00
|
|
|
const char *class = wlc_view_get_class(handle);
|
|
|
|
view->class = class ? strdup(class) : NULL;
|
2015-11-22 22:09:33 +01:00
|
|
|
const char *app_id = wlc_view_get_app_id(handle);
|
|
|
|
view->app_id = app_id ? strdup(app_id) : NULL;
|
2015-08-17 17:18:06 +02:00
|
|
|
view->visible = true;
|
2015-11-26 23:53:20 +01:00
|
|
|
view->sticky = false;
|
2015-08-17 17:18:06 +02:00
|
|
|
|
|
|
|
// Set the geometry of the floating view
|
2016-03-29 14:47:30 +02:00
|
|
|
struct wlc_geometry geometry;
|
|
|
|
wlc_view_get_visible_geometry(handle, &geometry);
|
2015-08-17 17:18:06 +02:00
|
|
|
|
2015-08-20 14:06:22 +02:00
|
|
|
// give it requested geometry, but place in center
|
2016-03-29 14:47:30 +02:00
|
|
|
view->x = (swayc_active_workspace()->width - geometry.size.w) / 2;
|
|
|
|
view->y = (swayc_active_workspace()->height- geometry.size.h) / 2;
|
|
|
|
view->width = geometry.size.w;
|
|
|
|
view->height = geometry.size.h;
|
2015-08-17 17:18:06 +02:00
|
|
|
|
2015-08-17 17:34:39 +02:00
|
|
|
view->desired_width = view->width;
|
|
|
|
view->desired_height = view->height;
|
2015-08-17 17:18:06 +02:00
|
|
|
|
2016-03-31 12:17:21 +02:00
|
|
|
// setup border
|
|
|
|
view->border_type = config->floating_border;
|
|
|
|
view->border_thickness = config->floating_border_thickness;
|
|
|
|
|
2015-08-17 17:18:06 +02:00
|
|
|
view->is_floating = true;
|
|
|
|
|
2015-08-18 13:19:20 +02:00
|
|
|
// Case of focused workspace, just create as child of it
|
2015-08-21 19:28:37 +02:00
|
|
|
list_add(swayc_active_workspace()->floating, view);
|
|
|
|
view->parent = swayc_active_workspace();
|
|
|
|
if (swayc_active_workspace()->focused == NULL) {
|
|
|
|
set_focused_container_for(swayc_active_workspace(), view);
|
2015-08-17 17:18:06 +02:00
|
|
|
}
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2016-05-31 14:59:33 +02:00
|
|
|
void floating_view_sane_size(swayc_t *view) {
|
2016-06-02 17:35:02 +02:00
|
|
|
// floating_minimum is used as sane value.
|
|
|
|
// floating_maximum has priority in case of conflict
|
|
|
|
// TODO: implement total_outputs_dimensions()
|
2016-05-31 14:59:33 +02:00
|
|
|
if (config->floating_minimum_height != -1 &&
|
|
|
|
view->desired_height < config->floating_minimum_height) {
|
|
|
|
view->desired_height = config->floating_minimum_height;
|
|
|
|
}
|
|
|
|
if (config->floating_minimum_width != -1 &&
|
|
|
|
view->desired_width < config->floating_minimum_width) {
|
|
|
|
view->desired_width = config->floating_minimum_width;
|
|
|
|
}
|
|
|
|
|
2016-06-02 17:35:02 +02:00
|
|
|
// if 0 do not resize, only enforce max value
|
|
|
|
if (config->floating_maximum_height == 0) {
|
|
|
|
// Missing total_outputs_dimensions() using swayc_active_workspace()
|
|
|
|
config->floating_maximum_height = swayc_active_workspace()->height;
|
|
|
|
|
|
|
|
} else if (config->floating_maximum_height != -1 &&
|
|
|
|
view->desired_height > config->floating_maximum_height) {
|
|
|
|
view->desired_height = config->floating_maximum_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if 0 do not resize, only enforce max value
|
|
|
|
if (config->floating_maximum_width == 0) {
|
|
|
|
// Missing total_outputs_dimensions() using swayc_active_workspace()
|
|
|
|
config->floating_maximum_width = swayc_active_workspace()->width;
|
|
|
|
|
|
|
|
} else if (config->floating_maximum_width != -1 &&
|
2016-05-31 14:59:33 +02:00
|
|
|
view->desired_width > config->floating_maximum_width) {
|
|
|
|
view->desired_width = config->floating_maximum_width;
|
|
|
|
}
|
2016-06-02 17:35:02 +02:00
|
|
|
|
2016-07-04 20:34:44 +02:00
|
|
|
sway_log(L_DEBUG, "Sane values for view to %d x %d @ %.f, %.f",
|
2016-05-31 14:59:33 +02:00
|
|
|
view->desired_width, view->desired_height, view->x, view->y);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-20 18:52:54 +02:00
|
|
|
// Destroy container
|
2015-08-14 21:42:19 +02:00
|
|
|
|
|
|
|
swayc_t *destroy_output(swayc_t *output) {
|
2015-08-20 18:52:54 +02:00
|
|
|
if (!ASSERT_NONNULL(output)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-27 06:25:57 +02:00
|
|
|
if (output->children->length > 0) {
|
|
|
|
// TODO save workspaces when there are no outputs.
|
|
|
|
// TODO also check if there will ever be no outputs except for exiting
|
|
|
|
// program
|
2015-08-31 17:49:24 +02:00
|
|
|
if (root_container.children->length > 1) {
|
2015-08-27 06:25:57 +02:00
|
|
|
int p = root_container.children->items[0] == output;
|
|
|
|
// Move workspace from this output to another output
|
2015-08-31 17:49:24 +02:00
|
|
|
while (output->children->length) {
|
|
|
|
swayc_t *child = output->children->items[0];
|
2015-08-27 06:25:57 +02:00
|
|
|
remove_child(child);
|
|
|
|
add_child(root_container.children->items[p], child);
|
|
|
|
}
|
2016-05-28 00:37:56 +02:00
|
|
|
sort_workspaces(root_container.children->items[p]);
|
2015-08-27 17:32:06 +02:00
|
|
|
update_visibility(root_container.children->items[p]);
|
|
|
|
arrange_windows(root_container.children->items[p], -1, -1);
|
2015-08-27 06:25:57 +02:00
|
|
|
}
|
2015-08-14 21:42:19 +02:00
|
|
|
}
|
2016-04-17 16:26:26 +02:00
|
|
|
sway_log(L_DEBUG, "OUTPUT: Destroying output '%" PRIuPTR "'", output->handle);
|
2015-08-14 21:42:19 +02:00
|
|
|
free_swayc(output);
|
2016-07-04 20:34:44 +02:00
|
|
|
update_root_geometry();
|
2015-08-14 21:42:19 +02:00
|
|
|
return &root_container;
|
|
|
|
}
|
|
|
|
|
|
|
|
swayc_t *destroy_workspace(swayc_t *workspace) {
|
2015-08-20 18:52:54 +02:00
|
|
|
if (!ASSERT_NONNULL(workspace)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-01-05 23:42:40 +01:00
|
|
|
|
2015-08-18 14:20:59 +02:00
|
|
|
// Do not destroy this if it's the last workspace on this output
|
2015-08-20 18:52:54 +02:00
|
|
|
swayc_t *output = swayc_parent_by_type(workspace, C_OUTPUT);
|
|
|
|
if (output && output->children->length == 1) {
|
|
|
|
return NULL;
|
2015-08-18 14:20:59 +02:00
|
|
|
}
|
|
|
|
|
2015-12-13 18:19:24 +01:00
|
|
|
swayc_t *parent = workspace->parent;
|
|
|
|
// destroy the WS if there are no children
|
2015-08-23 03:25:05 +02:00
|
|
|
if (workspace->children->length == 0 && workspace->floating->length == 0) {
|
2015-08-28 05:55:48 +02:00
|
|
|
sway_log(L_DEBUG, "destroying workspace '%s'", workspace->name);
|
2016-02-25 12:59:22 +01:00
|
|
|
ipc_event_workspace(workspace, NULL, "empty");
|
2015-12-13 18:19:24 +01:00
|
|
|
} else {
|
|
|
|
// Move children to a different workspace on this output
|
|
|
|
swayc_t *new_workspace = NULL;
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < output->children->length; i++) {
|
|
|
|
if(output->children->items[i] != workspace) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
new_workspace = output->children->items[i];
|
|
|
|
|
|
|
|
sway_log(L_DEBUG, "moving children to different workspace '%s' -> '%s'",
|
|
|
|
workspace->name, new_workspace->name);
|
|
|
|
|
|
|
|
for(i = 0; i < workspace->children->length; i++) {
|
|
|
|
move_container_to(workspace->children->items[i], new_workspace);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < workspace->floating->length; i++) {
|
|
|
|
move_container_to(workspace->floating->items[i], new_workspace);
|
|
|
|
}
|
2015-08-14 21:42:19 +02:00
|
|
|
}
|
2015-12-13 18:19:24 +01:00
|
|
|
|
|
|
|
free_swayc(workspace);
|
|
|
|
return parent;
|
2015-08-14 21:42:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
swayc_t *destroy_container(swayc_t *container) {
|
2015-08-20 18:52:54 +02:00
|
|
|
if (!ASSERT_NONNULL(container)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-14 21:42:19 +02:00
|
|
|
while (container->children->length == 0 && container->type == C_CONTAINER) {
|
|
|
|
sway_log(L_DEBUG, "Container: Destroying container '%p'", container);
|
|
|
|
swayc_t *parent = container->parent;
|
|
|
|
free_swayc(container);
|
|
|
|
container = parent;
|
|
|
|
}
|
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
|
|
|
swayc_t *destroy_view(swayc_t *view) {
|
2015-08-20 18:52:54 +02:00
|
|
|
if (!ASSERT_NONNULL(view)) {
|
2015-08-14 21:42:19 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
sway_log(L_DEBUG, "Destroying view '%p'", view);
|
|
|
|
swayc_t *parent = view->parent;
|
|
|
|
free_swayc(view);
|
|
|
|
|
2015-08-18 13:19:20 +02:00
|
|
|
// Destroy empty containers
|
2015-08-14 21:42:19 +02:00
|
|
|
if (parent->type == C_CONTAINER) {
|
|
|
|
return destroy_container(parent);
|
|
|
|
}
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
2015-08-20 18:52:54 +02:00
|
|
|
// Container lookup
|
|
|
|
|
2015-08-21 19:28:37 +02:00
|
|
|
|
2015-09-14 01:46:16 +02:00
|
|
|
swayc_t *swayc_by_test(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data) {
|
2015-08-21 19:28:37 +02:00
|
|
|
if (!container->children) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
// Special case for checking floating stuff
|
|
|
|
int i;
|
|
|
|
if (container->type == C_WORKSPACE) {
|
|
|
|
for (i = 0; i < container->floating->length; ++i) {
|
|
|
|
swayc_t *child = container->floating->items[i];
|
|
|
|
if (test(child, data)) {
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < container->children->length; ++i) {
|
|
|
|
swayc_t *child = container->children->items[i];
|
|
|
|
if (test(child, data)) {
|
|
|
|
return child;
|
|
|
|
} else {
|
2015-09-14 01:46:16 +02:00
|
|
|
swayc_t *res = swayc_by_test(child, test, data);
|
2015-08-21 19:28:37 +02:00
|
|
|
if (res) {
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-14 01:46:16 +02:00
|
|
|
static bool test_name(swayc_t *view, void *data) {
|
2015-09-18 15:52:04 +02:00
|
|
|
if (!view || !view->name) {
|
2015-09-14 01:46:16 +02:00
|
|
|
return false;
|
2015-08-28 05:32:56 +02:00
|
|
|
}
|
2015-09-14 01:46:16 +02:00
|
|
|
return strcmp(view->name, data) == 0;
|
2015-08-28 05:32:56 +02:00
|
|
|
}
|
|
|
|
|
2015-09-14 01:46:16 +02:00
|
|
|
swayc_t *swayc_by_name(const char *name) {
|
|
|
|
return swayc_by_test(&root_container, test_name, (void *)name);
|
2015-08-28 05:32:56 +02:00
|
|
|
}
|
|
|
|
|
2015-08-20 18:52:54 +02:00
|
|
|
swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) {
|
|
|
|
if (!ASSERT_NONNULL(container)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-26 20:01:26 +02:00
|
|
|
if (!sway_assert(type < C_TYPES && type >= C_ROOT, "invalid type")) {
|
2015-08-20 18:52:54 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
container = container->parent;
|
2015-08-21 21:41:54 +02:00
|
|
|
} while (container && container->type != type);
|
2015-08-20 18:52:54 +02:00
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
|
|
|
swayc_t *swayc_parent_by_layout(swayc_t *container, enum swayc_layouts layout) {
|
|
|
|
if (!ASSERT_NONNULL(container)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-26 20:01:26 +02:00
|
|
|
if (!sway_assert(layout < L_LAYOUTS && layout >= L_NONE, "invalid layout")) {
|
2015-08-20 18:52:54 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
container = container->parent;
|
|
|
|
} while (container && container->layout != layout);
|
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
2015-08-24 10:11:21 +02:00
|
|
|
swayc_t *swayc_focus_by_type(swayc_t *container, enum swayc_types type) {
|
|
|
|
if (!ASSERT_NONNULL(container)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-26 20:01:26 +02:00
|
|
|
if (!sway_assert(type < C_TYPES && type >= C_ROOT, "invalid type")) {
|
2015-08-24 10:11:21 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
container = container->focused;
|
|
|
|
} while (container && container->type != type);
|
|
|
|
return container;
|
|
|
|
}
|
2015-08-26 20:01:26 +02:00
|
|
|
|
2015-08-24 10:11:21 +02:00
|
|
|
swayc_t *swayc_focus_by_layout(swayc_t *container, enum swayc_layouts layout) {
|
|
|
|
if (!ASSERT_NONNULL(container)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-26 20:01:26 +02:00
|
|
|
if (!sway_assert(layout < L_LAYOUTS && layout >= L_NONE, "invalid layout")) {
|
2015-08-24 10:11:21 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
container = container->focused;
|
|
|
|
} while (container && container->layout != layout);
|
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
2015-09-14 01:46:16 +02:00
|
|
|
|
|
|
|
static swayc_t *_swayc_by_handle_helper(wlc_handle handle, swayc_t *parent) {
|
|
|
|
if (!parent || !parent->children) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
int i, len;
|
|
|
|
swayc_t **child;
|
|
|
|
if (parent->type == C_WORKSPACE) {
|
|
|
|
len = parent->floating->length;
|
|
|
|
child = (swayc_t **)parent->floating->items;
|
|
|
|
for (i = 0; i < len; ++i, ++child) {
|
|
|
|
if ((*child)->handle == handle) {
|
|
|
|
return *child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
len = parent->children->length;
|
|
|
|
child = (swayc_t**)parent->children->items;
|
|
|
|
for (i = 0; i < len; ++i, ++child) {
|
|
|
|
if ((*child)->handle == handle) {
|
|
|
|
return *child;
|
|
|
|
} else {
|
|
|
|
swayc_t *res;
|
|
|
|
if ((res = _swayc_by_handle_helper(handle, *child))) {
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
swayc_t *swayc_by_handle(wlc_handle handle) {
|
|
|
|
return _swayc_by_handle_helper(handle, &root_container);
|
|
|
|
}
|
|
|
|
|
2015-08-21 19:28:37 +02:00
|
|
|
swayc_t *swayc_active_output(void) {
|
|
|
|
return root_container.focused;
|
|
|
|
}
|
|
|
|
|
|
|
|
swayc_t *swayc_active_workspace(void) {
|
|
|
|
return root_container.focused ? root_container.focused->focused : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
swayc_t *swayc_active_workspace_for(swayc_t *cont) {
|
2015-08-21 21:41:54 +02:00
|
|
|
if (!cont) {
|
2015-08-21 19:28:37 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
switch (cont->type) {
|
2015-08-21 21:41:54 +02:00
|
|
|
case C_ROOT:
|
|
|
|
cont = cont->focused;
|
|
|
|
/* Fallthrough */
|
|
|
|
|
|
|
|
case C_OUTPUT:
|
2015-08-25 22:29:33 +02:00
|
|
|
cont = cont ? cont->focused : NULL;
|
2015-08-21 21:41:54 +02:00
|
|
|
/* Fallthrough */
|
|
|
|
|
|
|
|
case C_WORKSPACE:
|
|
|
|
return cont;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return swayc_parent_by_type(cont, C_WORKSPACE);
|
2015-08-21 19:28:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-28 00:22:52 +01:00
|
|
|
static bool pointer_test(swayc_t *view, void *_origin) {
|
2015-11-14 17:30:23 +01:00
|
|
|
const struct wlc_point *origin = _origin;
|
2015-10-28 00:22:52 +01:00
|
|
|
// Determine the output that the view is under
|
|
|
|
swayc_t *parent = swayc_parent_by_type(view, C_OUTPUT);
|
|
|
|
if (origin->x >= view->x && origin->y >= view->y
|
|
|
|
&& origin->x < view->x + view->width && origin->y < view->y + view->height
|
|
|
|
&& view->visible && parent == root_container.focused) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
swayc_t *container_under_pointer(void) {
|
|
|
|
// root.output->workspace
|
|
|
|
if (!root_container.focused || !root_container.focused->focused) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
swayc_t *lookup = root_container.focused->focused;
|
|
|
|
// Case of empty workspace
|
|
|
|
if (lookup->children == 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-11-14 17:30:23 +01:00
|
|
|
struct wlc_point origin;
|
|
|
|
wlc_pointer_get_position(&origin);
|
2016-03-31 16:39:40 +02:00
|
|
|
while (lookup && lookup->type != C_VIEW) {
|
2015-10-28 00:22:52 +01:00
|
|
|
int i;
|
|
|
|
int len;
|
|
|
|
// if tabbed/stacked go directly to focused container, otherwise search
|
|
|
|
// children
|
|
|
|
if (lookup->layout == L_TABBED || lookup->layout == L_STACKED) {
|
|
|
|
lookup = lookup->focused;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// if workspace, search floating
|
|
|
|
if (lookup->type == C_WORKSPACE) {
|
|
|
|
i = len = lookup->floating->length;
|
|
|
|
bool got_floating = false;
|
|
|
|
while (--i > -1) {
|
2015-10-29 18:02:02 +01:00
|
|
|
if (pointer_test(lookup->floating->items[i], &origin)) {
|
2015-10-28 00:22:52 +01:00
|
|
|
lookup = lookup->floating->items[i];
|
|
|
|
got_floating = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (got_floating) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// search children
|
|
|
|
len = lookup->children->length;
|
|
|
|
for (i = 0; i < len; ++i) {
|
2015-10-29 18:02:02 +01:00
|
|
|
if (pointer_test(lookup->children->items[i], &origin)) {
|
2015-10-28 00:22:52 +01:00
|
|
|
lookup = lookup->children->items[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// when border and titles are done, this could happen
|
|
|
|
if (i == len) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lookup;
|
|
|
|
}
|
|
|
|
|
2016-10-06 20:23:46 +02:00
|
|
|
swayc_t *container_find(swayc_t *container, bool (*f)(swayc_t *, const void *), const void *data) {
|
|
|
|
if (container->children == NULL || container->children->length == 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-10-13 03:54:19 +02:00
|
|
|
swayc_t *con;
|
|
|
|
if (container->type == C_WORKSPACE) {
|
|
|
|
for (int i = 0; i < container->floating->length; ++i) {
|
|
|
|
con = container->floating->items[i];
|
|
|
|
if (f(con, data)) {
|
|
|
|
return con;
|
|
|
|
}
|
|
|
|
con = container_find(con, f, data);
|
|
|
|
if (con != NULL) {
|
|
|
|
return con;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-06 20:23:46 +02:00
|
|
|
for (int i = 0; i < container->children->length; ++i) {
|
2016-10-13 03:54:19 +02:00
|
|
|
con = container->children->items[i];
|
|
|
|
if (f(con, data)) {
|
|
|
|
return con;
|
2016-10-06 20:23:46 +02:00
|
|
|
}
|
|
|
|
|
2016-10-13 03:54:19 +02:00
|
|
|
con = container_find(con, f, data);
|
|
|
|
if (con != NULL) {
|
|
|
|
return con;
|
2016-10-06 20:23:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-08-21 19:28:37 +02:00
|
|
|
// Container information
|
|
|
|
|
|
|
|
bool swayc_is_fullscreen(swayc_t *view) {
|
2015-09-14 01:46:16 +02:00
|
|
|
return view && view->type == C_VIEW && (wlc_view_get_state(view->handle) & WLC_BIT_FULLSCREEN);
|
2015-08-21 19:28:37 +02:00
|
|
|
}
|
|
|
|
|
2015-08-26 20:01:26 +02:00
|
|
|
bool swayc_is_active(swayc_t *view) {
|
2015-09-14 01:46:16 +02:00
|
|
|
return view && view->type == C_VIEW && (wlc_view_get_state(view->handle) & WLC_BIT_ACTIVATED);
|
2015-08-26 20:01:26 +02:00
|
|
|
}
|
|
|
|
|
2015-08-28 08:18:28 +02:00
|
|
|
bool swayc_is_parent_of(swayc_t *parent, swayc_t *child) {
|
|
|
|
while (child != &root_container) {
|
|
|
|
child = child->parent;
|
|
|
|
if (child == parent) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool swayc_is_child_of(swayc_t *child, swayc_t *parent) {
|
|
|
|
return swayc_is_parent_of(parent, child);
|
|
|
|
}
|
|
|
|
|
2016-07-07 22:28:57 +02:00
|
|
|
bool swayc_is_empty_workspace(swayc_t *container) {
|
|
|
|
return container->type == C_WORKSPACE && container->children->length == 0;
|
|
|
|
}
|
|
|
|
|
2015-09-05 01:14:59 +02:00
|
|
|
int swayc_gap(swayc_t *container) {
|
2016-04-22 22:44:02 +02:00
|
|
|
if (container->type == C_VIEW || container->type == C_CONTAINER) {
|
2015-09-05 01:14:59 +02:00
|
|
|
return container->gaps >= 0 ? container->gaps : config->gaps_inner;
|
|
|
|
} else if (container->type == C_WORKSPACE) {
|
2015-12-19 01:21:00 +01:00
|
|
|
int base = container->gaps >= 0 ? container->gaps : config->gaps_outer;
|
2016-03-20 12:29:47 +01:00
|
|
|
if (config->edge_gaps && !(config->smart_gaps && container->children->length == 1)) {
|
2015-12-19 01:21:00 +01:00
|
|
|
// the inner gap is created via a margin around each window which
|
|
|
|
// is half the gap size, so the workspace also needs half a gap
|
|
|
|
// size to make the outermost gap the same size (excluding the
|
|
|
|
// actual "outer gap" size which is handled independently)
|
|
|
|
return base + config->gaps_inner / 2;
|
2016-07-21 22:55:01 +02:00
|
|
|
} else if (config->smart_gaps && container->children->length == 1) {
|
|
|
|
return 0;
|
2015-12-19 01:21:00 +01:00
|
|
|
} else {
|
|
|
|
return base;
|
|
|
|
}
|
2015-09-05 01:14:59 +02:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-21 19:28:37 +02:00
|
|
|
// Mapping
|
|
|
|
|
2015-09-14 01:46:16 +02:00
|
|
|
void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) {
|
|
|
|
if (container) {
|
|
|
|
f(container, data);
|
|
|
|
int i;
|
|
|
|
if (container->children) {
|
|
|
|
for (i = 0; i < container->children->length; ++i) {
|
|
|
|
swayc_t *child = container->children->items[i];
|
|
|
|
container_map(child, f, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (container->floating) {
|
|
|
|
for (i = 0; i < container->floating->length; ++i) {
|
|
|
|
swayc_t *child = container->floating->items[i];
|
|
|
|
container_map(child, f, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-28 08:18:28 +02:00
|
|
|
void update_visibility_output(swayc_t *container, wlc_handle output) {
|
|
|
|
// Inherit visibility
|
|
|
|
swayc_t *parent = container->parent;
|
|
|
|
container->visible = parent->visible;
|
|
|
|
// special cases where visibility depends on focus
|
2016-04-24 22:04:26 +02:00
|
|
|
if (parent->type == C_OUTPUT || parent->layout == L_TABBED ||
|
|
|
|
parent->layout == L_STACKED) {
|
2016-04-01 00:04:08 +02:00
|
|
|
container->visible = parent->focused == container && parent->visible;
|
2015-08-28 08:18:28 +02:00
|
|
|
}
|
|
|
|
// Set visibility and output for view
|
|
|
|
if (container->type == C_VIEW) {
|
|
|
|
wlc_view_set_output(container->handle, output);
|
|
|
|
wlc_view_set_mask(container->handle, container->visible ? VISIBLE : 0);
|
|
|
|
}
|
|
|
|
// Update visibility for children
|
2015-08-28 08:42:26 +02:00
|
|
|
else {
|
|
|
|
if (container->children) {
|
|
|
|
int i, len = container->children->length;
|
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
update_visibility_output(container->children->items[i], output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (container->floating) {
|
|
|
|
int i, len = container->floating->length;
|
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
update_visibility_output(container->floating->items[i], output);
|
|
|
|
}
|
2015-08-17 04:06:31 +02:00
|
|
|
}
|
|
|
|
}
|
2015-08-25 18:24:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void update_visibility(swayc_t *container) {
|
2015-08-28 08:18:28 +02:00
|
|
|
if (!container) return;
|
|
|
|
switch (container->type) {
|
|
|
|
case C_ROOT:
|
|
|
|
container->visible = true;
|
|
|
|
if (container->children) {
|
|
|
|
int i, len = container->children->length;
|
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
update_visibility(container->children->items[i]);
|
|
|
|
}
|
|
|
|
}
|
2015-08-28 05:55:48 +02:00
|
|
|
return;
|
2015-08-28 08:18:28 +02:00
|
|
|
|
|
|
|
case C_OUTPUT:
|
|
|
|
container->visible = true;
|
|
|
|
if (container->children) {
|
|
|
|
int i, len = container->children->length;
|
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
update_visibility_output(container->children->items[i], container->handle);
|
|
|
|
}
|
2015-08-28 05:55:48 +02:00
|
|
|
}
|
|
|
|
return;
|
2015-08-28 08:18:28 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
swayc_t *op = swayc_parent_by_type(container, C_OUTPUT);
|
|
|
|
update_visibility_output(container, op->handle);
|
|
|
|
}
|
2015-08-28 05:55:48 +02:00
|
|
|
}
|
2015-08-17 04:06:31 +02:00
|
|
|
}
|
2015-08-19 04:05:58 +02:00
|
|
|
|
2015-09-14 01:46:16 +02:00
|
|
|
void set_gaps(swayc_t *view, void *_data) {
|
|
|
|
int *data = _data;
|
|
|
|
if (!ASSERT_NONNULL(view)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (view->type == C_WORKSPACE || view->type == C_VIEW) {
|
|
|
|
view->gaps = *data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_gaps(swayc_t *view, void *_data) {
|
|
|
|
int *data = _data;
|
|
|
|
if (!ASSERT_NONNULL(view)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (view->type == C_WORKSPACE || view->type == C_VIEW) {
|
|
|
|
if ((view->gaps += *data) < 0) {
|
|
|
|
view->gaps = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-29 13:00:35 +01:00
|
|
|
|
|
|
|
static void close_view(swayc_t *container, void *data) {
|
|
|
|
if (container->type == C_VIEW) {
|
|
|
|
wlc_view_close(container->handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void close_views(swayc_t *container) {
|
|
|
|
container_map(container, close_view, NULL);
|
|
|
|
}
|
2016-04-01 13:36:36 +02:00
|
|
|
|
2016-07-16 15:11:08 +02:00
|
|
|
swayc_t *swayc_tabbed_stacked_ancestor(swayc_t *view) {
|
2016-04-20 00:22:15 +02:00
|
|
|
swayc_t *parent = NULL;
|
|
|
|
if (!ASSERT_NONNULL(view)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-07-07 22:28:57 +02:00
|
|
|
while (view->type != C_WORKSPACE && view->parent && view->parent->type != C_WORKSPACE) {
|
2016-05-14 16:34:25 +02:00
|
|
|
view = view->parent;
|
2016-04-20 00:22:15 +02:00
|
|
|
if (view->layout == L_TABBED || view->layout == L_STACKED) {
|
|
|
|
parent = view;
|
|
|
|
}
|
2016-06-18 19:31:18 +02:00
|
|
|
}
|
2016-04-20 00:22:15 +02:00
|
|
|
|
|
|
|
return parent;
|
|
|
|
}
|
2016-07-16 15:11:08 +02:00
|
|
|
|
|
|
|
swayc_t *swayc_tabbed_stacked_parent(swayc_t *con) {
|
|
|
|
if (!ASSERT_NONNULL(con)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (con->parent && (con->parent->layout == L_TABBED || con->parent->layout == L_STACKED)) {
|
|
|
|
return con->parent;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|