2015-12-18 11:01:02 +11:00
|
|
|
#include <ctype.h>
|
2015-08-15 05:42:19 +10:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <strings.h>
|
2015-09-18 21:27:35 +10:00
|
|
|
#include <string.h>
|
2016-09-01 22:18:37 +10: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-15 05:42:19 +10:00
|
|
|
#include "log.h"
|
2016-09-01 22:18:37 +10:00
|
|
|
#include "stringop.h"
|
2015-08-11 06:31:23 +10:00
|
|
|
|
2015-08-21 02:52:54 +10:00
|
|
|
#define ASSERT_NONNULL(PTR) \
|
2015-08-27 04:01:26 +10:00
|
|
|
sway_assert (PTR, #PTR "must be non-null")
|
2015-08-15 05:42:19 +10:00
|
|
|
|
2016-09-22 12:05:09 +10:00
|
|
|
|
2015-08-15 05:42:19 +10:00
|
|
|
static swayc_t *new_swayc(enum swayc_types type) {
|
2016-09-22 12:05:09 +10:00
|
|
|
// next id starts at 1 because 0 is assigned to root_container in layout.c
|
|
|
|
static size_t next_id = 1;
|
2015-08-15 05:42:19 +10:00
|
|
|
swayc_t *c = calloc(1, sizeof(swayc_t));
|
2016-12-16 10:26:53 +11:00
|
|
|
if (!c) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-09-22 12:05:09 +10:00
|
|
|
c->id = next_id++;
|
2015-08-15 05:42:19 +10:00
|
|
|
c->handle = -1;
|
2015-09-05 09:14:59 +10:00
|
|
|
c->gaps = -1;
|
2015-08-15 05:42:19 +10:00
|
|
|
c->layout = L_NONE;
|
2016-10-11 05:44:09 +11:00
|
|
|
c->workspace_layout = L_NONE;
|
2015-08-15 05:42:19 +10:00
|
|
|
c->type = type;
|
|
|
|
if (type != C_VIEW) {
|
|
|
|
c->children = create_list();
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2015-08-21 02:52:54 +10:00
|
|
|
static void free_swayc(swayc_t *cont) {
|
|
|
|
if (!ASSERT_NONNULL(cont)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (cont->children) {
|
2015-08-22 05:19:29 +10: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-19 04:22:52 +10:00
|
|
|
}
|
2015-08-21 02:52:54 +10:00
|
|
|
list_free(cont->children);
|
2015-08-15 05:42:19 +10:00
|
|
|
}
|
2015-12-17 11:20:34 +11:00
|
|
|
if (cont->unmanaged) {
|
|
|
|
list_free(cont->unmanaged);
|
|
|
|
}
|
2015-08-21 02:52:54 +10:00
|
|
|
if (cont->floating) {
|
2015-09-01 01:49:24 +10:00
|
|
|
while (cont->floating->length) {
|
|
|
|
free_swayc(cont->floating->items[0]);
|
2015-08-19 04:22:52 +10:00
|
|
|
}
|
2015-08-21 02:52:54 +10:00
|
|
|
list_free(cont->floating);
|
2015-08-19 04:22:52 +10:00
|
|
|
}
|
2015-08-21 02:52:54 +10:00
|
|
|
if (cont->parent) {
|
|
|
|
remove_child(cont);
|
2015-08-15 05:42:19 +10:00
|
|
|
}
|
2015-08-21 02:52:54 +10:00
|
|
|
if (cont->name) {
|
|
|
|
free(cont->name);
|
2015-08-17 06:38:54 +10:00
|
|
|
}
|
2015-11-23 08:05:00 +11:00
|
|
|
if (cont->class) {
|
|
|
|
free(cont->class);
|
|
|
|
}
|
2015-11-23 08:09:33 +11:00
|
|
|
if (cont->app_id) {
|
|
|
|
free(cont->app_id);
|
|
|
|
}
|
2015-12-19 04:02:39 +11:00
|
|
|
if (cont->bg_pid != 0) {
|
|
|
|
terminate_swaybg(cont->bg_pid);
|
|
|
|
}
|
2016-04-20 08:22:15 +10:00
|
|
|
if (cont->border) {
|
|
|
|
if (cont->border->buffer) {
|
|
|
|
free(cont->border->buffer);
|
|
|
|
}
|
|
|
|
free(cont->border);
|
|
|
|
}
|
2015-08-21 02:52:54 +10:00
|
|
|
free(cont);
|
2015-08-15 05:42:19 +10:00
|
|
|
}
|
|
|
|
|
2016-07-05 04:34:44 +10: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-21 02:52:54 +10:00
|
|
|
// New containers
|
2015-08-15 05:42:19 +10:00
|
|
|
|
|
|
|
swayc_t *new_output(wlc_handle handle) {
|
2016-07-17 00:04:18 +10:00
|
|
|
struct wlc_size size;
|
2016-07-19 06:21:45 +10:00
|
|
|
output_get_scaled_size(handle, &size);
|
2015-08-17 03:07:43 +10:00
|
|
|
const char *name = wlc_output_get_name(handle);
|
2015-08-28 13:32:56 +10:00
|
|
|
// Find current outputs to see if this already exists
|
2015-09-14 09:46:16 +10:00
|
|
|
{
|
|
|
|
int i, len = root_container.children->length;
|
2015-08-28 13:32:56 +10:00
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
swayc_t *op = root_container.children->items[i];
|
2015-09-14 09:46:16 +10:00
|
|
|
const char *op_name = op->name;
|
|
|
|
if (op_name && name && strcmp(op_name, name) == 0) {
|
2016-04-18 00:26:26 +10:00
|
|
|
sway_log(L_DEBUG, "restoring output %" PRIuPTR ":%s", handle, op_name);
|
2015-08-28 13:32:56 +10:00
|
|
|
return op;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-18 00:26:26 +10:00
|
|
|
sway_log(L_DEBUG, "New output %" PRIuPTR ":%s", handle, name);
|
2015-08-15 05:42:19 +10:00
|
|
|
|
2016-02-12 23:22:20 +11:00
|
|
|
struct output_config *oc = NULL, *all = NULL;
|
2015-09-14 09:46:16 +10:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < config->output_configs->length; ++i) {
|
2015-12-03 08:04:50 +11:00
|
|
|
struct output_config *cur = config->output_configs->items[i];
|
|
|
|
if (strcasecmp(name, cur->name) == 0) {
|
2015-08-23 01:18:55 +10:00
|
|
|
sway_log(L_DEBUG, "Matched output config for %s", name);
|
2015-12-03 08:04:50 +11:00
|
|
|
oc = cur;
|
2015-08-23 01:18:55 +10:00
|
|
|
}
|
2015-12-03 08:04:50 +11:00
|
|
|
if (strcasecmp("*", cur->name) == 0) {
|
2015-11-29 02:18:37 +11:00
|
|
|
sway_log(L_DEBUG, "Matched wildcard output config for %s", name);
|
2016-02-12 23:22:20 +11:00
|
|
|
all = cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oc && all) {
|
2015-11-29 02:18:37 +11:00
|
|
|
break;
|
|
|
|
}
|
2015-08-23 01:18:55 +10:00
|
|
|
}
|
|
|
|
|
2016-02-12 23:22:20 +11:00
|
|
|
if (!oc) {
|
|
|
|
oc = all;
|
|
|
|
}
|
|
|
|
|
2015-08-24 03:22:45 +10:00
|
|
|
if (oc && !oc->enabled) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-24 03:22:33 +10:00
|
|
|
|
2015-08-15 05:42:19 +10:00
|
|
|
swayc_t *output = new_swayc(C_OUTPUT);
|
2015-08-16 05:10:44 +10:00
|
|
|
output->handle = handle;
|
2015-08-18 03:02:09 +10:00
|
|
|
output->name = name ? strdup(name) : NULL;
|
2016-07-17 00:04:18 +10:00
|
|
|
output->width = size.w;
|
|
|
|
output->height = size.h;
|
2015-12-17 11:20:34 +11:00
|
|
|
output->unmanaged = create_list();
|
2015-12-19 03:43:03 +11:00
|
|
|
output->bg_pid = 0;
|
2015-09-14 09:46:16 +10:00
|
|
|
|
2015-10-22 01:34:12 +11:00
|
|
|
apply_output_config(oc, output);
|
2015-09-12 19:38:03 +10:00
|
|
|
add_child(&root_container, output);
|
2016-09-17 17:25:45 +10:00
|
|
|
load_swaybars();
|
2015-08-18 21:19:20 +10:00
|
|
|
|
2015-09-14 09:46:16 +10:00
|
|
|
// Create workspace
|
|
|
|
char *ws_name = NULL;
|
2016-05-29 09:18:46 +10:00
|
|
|
swayc_t *ws = NULL;
|
|
|
|
|
2015-09-14 09:46:16 +10: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 09:18:46 +10: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 09:46:16 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-29 09:18:46 +10: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 17:28:44 +10:00
|
|
|
|
2015-09-14 09:46:16 +10:00
|
|
|
free(ws_name);
|
2016-07-05 04:34:44 +10:00
|
|
|
update_root_geometry();
|
2015-08-15 05:42:19 +10:00
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2015-08-18 10:34:53 +10:00
|
|
|
swayc_t *new_workspace(swayc_t *output, const char *name) {
|
2015-09-14 09:46:16 +10:00
|
|
|
if (!ASSERT_NONNULL(output)) {
|
|
|
|
return NULL;
|
2015-08-21 02:52:54 +10:00
|
|
|
}
|
2015-09-14 09:46:16 +10:00
|
|
|
sway_log(L_DEBUG, "Added workspace %s for output %u", name, (unsigned int)output->handle);
|
2015-08-15 05:42:19 +10:00
|
|
|
swayc_t *workspace = new_swayc(C_WORKSPACE);
|
2015-09-14 09:46:16 +10:00
|
|
|
|
2016-04-03 01:29:31 +11:00
|
|
|
workspace->prev_layout = L_NONE;
|
2016-10-11 05:44:09 +11:00
|
|
|
workspace->layout = L_HORIZ;
|
|
|
|
workspace->workspace_layout = default_layout(output);
|
2016-04-02 00:58:29 +11:00
|
|
|
|
2015-08-19 07:53:57 +10:00
|
|
|
workspace->x = output->x;
|
|
|
|
workspace->y = output->y;
|
2015-08-16 05:10:44 +10:00
|
|
|
workspace->width = output->width;
|
|
|
|
workspace->height = output->height;
|
2016-12-16 10:17:36 +11:00
|
|
|
workspace->name = !name ? NULL : strdup(name);
|
2015-08-27 08:44:47 +10:00
|
|
|
workspace->visible = false;
|
2015-08-17 15:38:34 +10:00
|
|
|
workspace->floating = create_list();
|
2015-08-15 05:42:19 +10:00
|
|
|
|
2016-05-28 08:37:56 +10:00
|
|
|
add_child(output, workspace);
|
|
|
|
sort_workspaces(output);
|
2015-12-18 11:01:02 +11:00
|
|
|
|
2015-08-15 05:42:19 +10:00
|
|
|
return workspace;
|
|
|
|
}
|
|
|
|
|
|
|
|
swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) {
|
2015-08-22 03:28:37 +10:00
|
|
|
if (!ASSERT_NONNULL(child)
|
|
|
|
&& !sway_assert(!child->is_floating, "cannot create container around floating window")) {
|
2015-08-21 02:52:54 +10:00
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-15 05:42:19 +10:00
|
|
|
swayc_t *cont = new_swayc(C_CONTAINER);
|
|
|
|
|
|
|
|
sway_log(L_DEBUG, "creating container %p around %p", cont, child);
|
|
|
|
|
2016-04-03 01:29:31 +11:00
|
|
|
cont->prev_layout = L_NONE;
|
2015-08-16 05:10:44 +10:00
|
|
|
cont->layout = layout;
|
2015-08-16 05:12:42 +10:00
|
|
|
cont->width = child->width;
|
2015-08-16 05:10:44 +10:00
|
|
|
cont->height = child->height;
|
2015-08-18 03:02:09 +10:00
|
|
|
cont->x = child->x;
|
2015-08-16 05:10:44 +10:00
|
|
|
cont->y = child->y;
|
|
|
|
cont->visible = child->visible;
|
2016-04-20 08:22:15 +10:00
|
|
|
cont->cached_geometry = child->cached_geometry;
|
2016-04-23 06:44:02 +10:00
|
|
|
cont->gaps = child->gaps;
|
2015-08-15 05:42:19 +10:00
|
|
|
|
2015-08-16 04:19:44 +10:00
|
|
|
/* Container inherits all of workspaces children, layout and whatnot */
|
|
|
|
if (child->type == C_WORKSPACE) {
|
|
|
|
swayc_t *workspace = child;
|
2015-08-18 21:19:20 +10:00
|
|
|
// reorder focus
|
2015-08-16 04:19:44 +10:00
|
|
|
cont->focused = workspace->focused;
|
|
|
|
workspace->focused = cont;
|
2015-08-18 21:19:20 +10:00
|
|
|
// set all children focu to container
|
2015-08-18 19:46:14 +10:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < workspace->children->length; ++i) {
|
|
|
|
((swayc_t *)workspace->children->items[i])->parent = cont;
|
|
|
|
}
|
2015-08-18 21:19:20 +10:00
|
|
|
// Swap children
|
2015-08-16 04:19:44 +10:00
|
|
|
list_t *tmp_list = workspace->children;
|
|
|
|
workspace->children = cont->children;
|
|
|
|
cont->children = tmp_list;
|
2015-08-18 21:19:20 +10:00
|
|
|
// add container to workspace chidren
|
2015-08-16 04:19:44 +10:00
|
|
|
add_child(workspace, cont);
|
2015-08-18 21:19:20 +10:00
|
|
|
// give them proper layouts
|
2016-10-11 05:44:09 +11:00
|
|
|
cont->layout = workspace->workspace_layout;
|
2016-04-03 01:29:31 +11:00
|
|
|
cont->prev_layout = workspace->prev_layout;
|
2016-04-01 22:36:36 +11:00
|
|
|
/* TODO: might break shit in move_container!!! workspace->layout = layout; */
|
2015-08-20 09:15:17 +10:00
|
|
|
set_focused_container_for(workspace, get_focused_view(workspace));
|
2015-08-18 21:19:20 +10:00
|
|
|
} else { // Or is built around container
|
2015-08-16 04:19:44 +10:00
|
|
|
swayc_t *parent = replace_child(child, cont);
|
|
|
|
if (parent) {
|
|
|
|
add_child(cont, child);
|
|
|
|
}
|
2015-08-15 05:42:19 +10:00
|
|
|
}
|
|
|
|
return cont;
|
|
|
|
}
|
|
|
|
|
|
|
|
swayc_t *new_view(swayc_t *sibling, wlc_handle handle) {
|
2015-08-21 02:52:54 +10:00
|
|
|
if (!ASSERT_NONNULL(sibling)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-18 17:28:44 +10:00
|
|
|
const char *title = wlc_view_get_title(handle);
|
2015-08-15 05:42:19 +10:00
|
|
|
swayc_t *view = new_swayc(C_VIEW);
|
2016-04-18 00:26:26 +10:00
|
|
|
sway_log(L_DEBUG, "Adding new view %" PRIuPTR ":%s to container %p %d",
|
2015-08-18 17:28:44 +10:00
|
|
|
handle, title, sibling, sibling ? sibling->type : 0);
|
2015-08-18 21:19:20 +10:00
|
|
|
// Setup values
|
2015-08-16 05:10:44 +10:00
|
|
|
view->handle = handle;
|
2015-08-18 03:02:09 +10:00
|
|
|
view->name = title ? strdup(title) : NULL;
|
2015-11-23 08:05:00 +11:00
|
|
|
const char *class = wlc_view_get_class(handle);
|
|
|
|
view->class = class ? strdup(class) : NULL;
|
2015-11-23 08:09:33 +11:00
|
|
|
const char *app_id = wlc_view_get_app_id(handle);
|
|
|
|
view->app_id = app_id ? strdup(app_id) : NULL;
|
2015-08-15 05:42:19 +10:00
|
|
|
view->visible = true;
|
2015-08-18 17:28:44 +10:00
|
|
|
view->is_focused = true;
|
2015-11-27 09:53:20 +11:00
|
|
|
view->sticky = false;
|
2015-08-20 21:57:01 +10:00
|
|
|
view->width = 0;
|
|
|
|
view->height = 0;
|
2016-04-10 06:51:58 +10:00
|
|
|
view->desired_width = -1;
|
|
|
|
view->desired_height = -1;
|
2016-03-31 21:17:21 +11:00
|
|
|
// setup border
|
|
|
|
view->border_type = config->border;
|
|
|
|
view->border_thickness = config->border_thickness;
|
2015-08-15 05:42:19 +10:00
|
|
|
|
2015-08-17 15:38:34 +10:00
|
|
|
view->is_floating = false;
|
|
|
|
|
2015-08-15 05:42:19 +10:00
|
|
|
if (sibling->type == C_WORKSPACE) {
|
2015-08-18 21:19:20 +10:00
|
|
|
// Case of focused workspace, just create as child of it
|
2015-08-15 05:42:19 +10:00
|
|
|
add_child(sibling, view);
|
2015-08-18 21:19:20 +10:00
|
|
|
} else {
|
|
|
|
// Regular case, create as sibling of current container
|
2015-08-15 05:42:19 +10:00
|
|
|
add_sibling(sibling, view);
|
|
|
|
}
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2015-08-18 01:18:06 +10:00
|
|
|
swayc_t *new_floating_view(wlc_handle handle) {
|
2015-08-22 03:28:37 +10:00
|
|
|
if (swayc_active_workspace() == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-18 21:19:20 +10:00
|
|
|
const char *title = wlc_view_get_title(handle);
|
2015-08-18 01:18:06 +10:00
|
|
|
swayc_t *view = new_swayc(C_VIEW);
|
2016-04-18 00:26:26 +10:00
|
|
|
sway_log(L_DEBUG, "Adding new view %" PRIuPTR ":%x:%s as a floating view",
|
2015-08-18 17:28:44 +10:00
|
|
|
handle, wlc_view_get_type(handle), title);
|
2015-08-18 21:19:20 +10:00
|
|
|
// Setup values
|
2015-08-18 01:18:06 +10:00
|
|
|
view->handle = handle;
|
2015-08-18 03:02:09 +10:00
|
|
|
view->name = title ? strdup(title) : NULL;
|
2015-11-23 08:05:00 +11:00
|
|
|
const char *class = wlc_view_get_class(handle);
|
|
|
|
view->class = class ? strdup(class) : NULL;
|
2015-11-23 08:09:33 +11:00
|
|
|
const char *app_id = wlc_view_get_app_id(handle);
|
|
|
|
view->app_id = app_id ? strdup(app_id) : NULL;
|
2015-08-18 01:18:06 +10:00
|
|
|
view->visible = true;
|
2015-11-27 09:53:20 +11:00
|
|
|
view->sticky = false;
|
2015-08-18 01:18:06 +10:00
|
|
|
|
|
|
|
// Set the geometry of the floating view
|
2016-03-29 23:47:30 +11:00
|
|
|
struct wlc_geometry geometry;
|
|
|
|
wlc_view_get_visible_geometry(handle, &geometry);
|
2015-08-18 01:18:06 +10:00
|
|
|
|
2016-12-18 12:03:31 +11:00
|
|
|
// give it requested geometry, but place in center if possible
|
|
|
|
// in top left otherwise
|
|
|
|
if (geometry.size.w != 0) {
|
|
|
|
view->x = (swayc_active_workspace()->width - geometry.size.w) / 2;
|
|
|
|
} else {
|
|
|
|
view->x = 0;
|
|
|
|
}
|
|
|
|
if (geometry.size.h != 0) {
|
|
|
|
view->y = (swayc_active_workspace()->height - geometry.size.h) / 2;
|
|
|
|
} else {
|
|
|
|
view->y = 0;
|
|
|
|
}
|
2016-03-29 23:47:30 +11:00
|
|
|
view->width = geometry.size.w;
|
|
|
|
view->height = geometry.size.h;
|
2015-08-18 01:18:06 +10:00
|
|
|
|
2015-08-18 01:34:39 +10:00
|
|
|
view->desired_width = view->width;
|
|
|
|
view->desired_height = view->height;
|
2015-08-18 01:18:06 +10:00
|
|
|
|
2016-03-31 21:17:21 +11:00
|
|
|
// setup border
|
|
|
|
view->border_type = config->floating_border;
|
|
|
|
view->border_thickness = config->floating_border_thickness;
|
|
|
|
|
2015-08-18 01:18:06 +10:00
|
|
|
view->is_floating = true;
|
|
|
|
|
2015-08-18 21:19:20 +10:00
|
|
|
// Case of focused workspace, just create as child of it
|
2015-08-22 03:28:37 +10: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-18 01:18:06 +10:00
|
|
|
}
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2016-05-31 22:59:33 +10:00
|
|
|
void floating_view_sane_size(swayc_t *view) {
|
2016-06-03 01:35:02 +10:00
|
|
|
// floating_minimum is used as sane value.
|
|
|
|
// floating_maximum has priority in case of conflict
|
|
|
|
// TODO: implement total_outputs_dimensions()
|
2016-05-31 22:59:33 +10: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-03 01:35:02 +10: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 22:59:33 +10:00
|
|
|
view->desired_width > config->floating_maximum_width) {
|
|
|
|
view->desired_width = config->floating_maximum_width;
|
|
|
|
}
|
2016-06-03 01:35:02 +10:00
|
|
|
|
2016-07-05 04:34:44 +10:00
|
|
|
sway_log(L_DEBUG, "Sane values for view to %d x %d @ %.f, %.f",
|
2016-05-31 22:59:33 +10:00
|
|
|
view->desired_width, view->desired_height, view->x, view->y);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-21 02:52:54 +10:00
|
|
|
// Destroy container
|
2015-08-15 05:42:19 +10:00
|
|
|
|
|
|
|
swayc_t *destroy_output(swayc_t *output) {
|
2015-08-21 02:52:54 +10:00
|
|
|
if (!ASSERT_NONNULL(output)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-27 14:25:57 +10: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-09-01 01:49:24 +10:00
|
|
|
if (root_container.children->length > 1) {
|
2015-08-27 14:25:57 +10:00
|
|
|
int p = root_container.children->items[0] == output;
|
|
|
|
// Move workspace from this output to another output
|
2015-09-01 01:49:24 +10:00
|
|
|
while (output->children->length) {
|
|
|
|
swayc_t *child = output->children->items[0];
|
2015-08-27 14:25:57 +10:00
|
|
|
remove_child(child);
|
|
|
|
add_child(root_container.children->items[p], child);
|
|
|
|
}
|
2016-05-28 08:37:56 +10:00
|
|
|
sort_workspaces(root_container.children->items[p]);
|
2015-08-28 01:32:06 +10:00
|
|
|
update_visibility(root_container.children->items[p]);
|
|
|
|
arrange_windows(root_container.children->items[p], -1, -1);
|
2015-08-27 14:25:57 +10:00
|
|
|
}
|
2015-08-15 05:42:19 +10:00
|
|
|
}
|
2016-04-18 00:26:26 +10:00
|
|
|
sway_log(L_DEBUG, "OUTPUT: Destroying output '%" PRIuPTR "'", output->handle);
|
2015-08-15 05:42:19 +10:00
|
|
|
free_swayc(output);
|
2016-07-05 04:34:44 +10:00
|
|
|
update_root_geometry();
|
2015-08-15 05:42:19 +10:00
|
|
|
return &root_container;
|
|
|
|
}
|
|
|
|
|
|
|
|
swayc_t *destroy_workspace(swayc_t *workspace) {
|
2015-08-21 02:52:54 +10:00
|
|
|
if (!ASSERT_NONNULL(workspace)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-01-06 09:42:40 +11:00
|
|
|
|
2015-08-18 22:20:59 +10:00
|
|
|
// Do not destroy this if it's the last workspace on this output
|
2015-08-21 02:52:54 +10:00
|
|
|
swayc_t *output = swayc_parent_by_type(workspace, C_OUTPUT);
|
|
|
|
if (output && output->children->length == 1) {
|
|
|
|
return NULL;
|
2015-08-18 22:20:59 +10:00
|
|
|
}
|
|
|
|
|
2015-12-14 04:19:24 +11:00
|
|
|
swayc_t *parent = workspace->parent;
|
|
|
|
// destroy the WS if there are no children
|
2015-08-23 11:25:05 +10:00
|
|
|
if (workspace->children->length == 0 && workspace->floating->length == 0) {
|
2015-08-28 13:55:48 +10:00
|
|
|
sway_log(L_DEBUG, "destroying workspace '%s'", workspace->name);
|
2016-02-25 22:59:22 +11:00
|
|
|
ipc_event_workspace(workspace, NULL, "empty");
|
2015-12-14 04:19:24 +11: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-15 05:42:19 +10:00
|
|
|
}
|
2015-12-14 04:19:24 +11:00
|
|
|
|
|
|
|
free_swayc(workspace);
|
|
|
|
return parent;
|
2015-08-15 05:42:19 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
swayc_t *destroy_container(swayc_t *container) {
|
2015-08-21 02:52:54 +10:00
|
|
|
if (!ASSERT_NONNULL(container)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-15 05:42:19 +10: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-21 02:52:54 +10:00
|
|
|
if (!ASSERT_NONNULL(view)) {
|
2015-08-15 05:42:19 +10:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
sway_log(L_DEBUG, "Destroying view '%p'", view);
|
|
|
|
swayc_t *parent = view->parent;
|
|
|
|
free_swayc(view);
|
|
|
|
|
2015-08-18 21:19:20 +10:00
|
|
|
// Destroy empty containers
|
2015-08-15 05:42:19 +10:00
|
|
|
if (parent->type == C_CONTAINER) {
|
|
|
|
return destroy_container(parent);
|
|
|
|
}
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
2015-08-21 02:52:54 +10:00
|
|
|
// Container lookup
|
|
|
|
|
2015-08-22 03:28:37 +10:00
|
|
|
|
2015-09-14 09:46:16 +10:00
|
|
|
swayc_t *swayc_by_test(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data) {
|
2015-08-22 03:28:37 +10: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 09:46:16 +10:00
|
|
|
swayc_t *res = swayc_by_test(child, test, data);
|
2015-08-22 03:28:37 +10:00
|
|
|
if (res) {
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-14 09:46:16 +10:00
|
|
|
static bool test_name(swayc_t *view, void *data) {
|
2015-09-18 23:52:04 +10:00
|
|
|
if (!view || !view->name) {
|
2015-09-14 09:46:16 +10:00
|
|
|
return false;
|
2015-08-28 13:32:56 +10:00
|
|
|
}
|
2015-09-14 09:46:16 +10:00
|
|
|
return strcmp(view->name, data) == 0;
|
2015-08-28 13:32:56 +10:00
|
|
|
}
|
|
|
|
|
2015-09-14 09:46:16 +10:00
|
|
|
swayc_t *swayc_by_name(const char *name) {
|
|
|
|
return swayc_by_test(&root_container, test_name, (void *)name);
|
2015-08-28 13:32:56 +10:00
|
|
|
}
|
|
|
|
|
2015-08-21 02:52:54 +10:00
|
|
|
swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) {
|
|
|
|
if (!ASSERT_NONNULL(container)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-27 04:01:26 +10:00
|
|
|
if (!sway_assert(type < C_TYPES && type >= C_ROOT, "invalid type")) {
|
2015-08-21 02:52:54 +10:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
container = container->parent;
|
2015-08-22 05:41:54 +10:00
|
|
|
} while (container && container->type != type);
|
2015-08-21 02:52:54 +10:00
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
|
|
|
swayc_t *swayc_parent_by_layout(swayc_t *container, enum swayc_layouts layout) {
|
|
|
|
if (!ASSERT_NONNULL(container)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-27 04:01:26 +10:00
|
|
|
if (!sway_assert(layout < L_LAYOUTS && layout >= L_NONE, "invalid layout")) {
|
2015-08-21 02:52:54 +10:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
container = container->parent;
|
|
|
|
} while (container && container->layout != layout);
|
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
2015-08-24 18:11:21 +10:00
|
|
|
swayc_t *swayc_focus_by_type(swayc_t *container, enum swayc_types type) {
|
|
|
|
if (!ASSERT_NONNULL(container)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-27 04:01:26 +10:00
|
|
|
if (!sway_assert(type < C_TYPES && type >= C_ROOT, "invalid type")) {
|
2015-08-24 18:11:21 +10:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
container = container->focused;
|
|
|
|
} while (container && container->type != type);
|
|
|
|
return container;
|
|
|
|
}
|
2015-08-27 04:01:26 +10:00
|
|
|
|
2015-08-24 18:11:21 +10:00
|
|
|
swayc_t *swayc_focus_by_layout(swayc_t *container, enum swayc_layouts layout) {
|
|
|
|
if (!ASSERT_NONNULL(container)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-27 04:01:26 +10:00
|
|
|
if (!sway_assert(layout < L_LAYOUTS && layout >= L_NONE, "invalid layout")) {
|
2015-08-24 18:11:21 +10:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
container = container->focused;
|
|
|
|
} while (container && container->layout != layout);
|
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
2015-09-14 09:46:16 +10: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-22 03:28:37 +10: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-22 05:41:54 +10:00
|
|
|
if (!cont) {
|
2015-08-22 03:28:37 +10:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
switch (cont->type) {
|
2015-08-22 05:41:54 +10:00
|
|
|
case C_ROOT:
|
|
|
|
cont = cont->focused;
|
|
|
|
/* Fallthrough */
|
|
|
|
|
|
|
|
case C_OUTPUT:
|
2015-08-26 06:29:33 +10:00
|
|
|
cont = cont ? cont->focused : NULL;
|
2015-08-22 05:41:54 +10:00
|
|
|
/* Fallthrough */
|
|
|
|
|
|
|
|
case C_WORKSPACE:
|
|
|
|
return cont;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return swayc_parent_by_type(cont, C_WORKSPACE);
|
2015-08-22 03:28:37 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-28 10:22:52 +11:00
|
|
|
static bool pointer_test(swayc_t *view, void *_origin) {
|
2015-11-15 03:30:23 +11:00
|
|
|
const struct wlc_point *origin = _origin;
|
2015-10-28 10:22:52 +11: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-15 03:30:23 +11:00
|
|
|
struct wlc_point origin;
|
|
|
|
wlc_pointer_get_position(&origin);
|
2016-04-01 01:39:40 +11:00
|
|
|
while (lookup && lookup->type != C_VIEW) {
|
2015-10-28 10:22:52 +11: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-30 04:02:02 +11:00
|
|
|
if (pointer_test(lookup->floating->items[i], &origin)) {
|
2015-10-28 10:22:52 +11: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-30 04:02:02 +11:00
|
|
|
if (pointer_test(lookup->children->items[i], &origin)) {
|
2015-10-28 10:22:52 +11:00
|
|
|
lookup = lookup->children->items[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// when border and titles are done, this could happen
|
|
|
|
if (i == len) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lookup;
|
|
|
|
}
|
|
|
|
|
2016-10-07 05:23:46 +11: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 12:54:19 +11: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-07 05:23:46 +11:00
|
|
|
for (int i = 0; i < container->children->length; ++i) {
|
2016-10-13 12:54:19 +11:00
|
|
|
con = container->children->items[i];
|
|
|
|
if (f(con, data)) {
|
|
|
|
return con;
|
2016-10-07 05:23:46 +11:00
|
|
|
}
|
|
|
|
|
2016-10-13 12:54:19 +11:00
|
|
|
con = container_find(con, f, data);
|
|
|
|
if (con != NULL) {
|
|
|
|
return con;
|
2016-10-07 05:23:46 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-08-22 03:28:37 +10:00
|
|
|
// Container information
|
|
|
|
|
|
|
|
bool swayc_is_fullscreen(swayc_t *view) {
|
2015-09-14 09:46:16 +10:00
|
|
|
return view && view->type == C_VIEW && (wlc_view_get_state(view->handle) & WLC_BIT_FULLSCREEN);
|
2015-08-22 03:28:37 +10:00
|
|
|
}
|
|
|
|
|
2015-08-27 04:01:26 +10:00
|
|
|
bool swayc_is_active(swayc_t *view) {
|
2015-09-14 09:46:16 +10:00
|
|
|
return view && view->type == C_VIEW && (wlc_view_get_state(view->handle) & WLC_BIT_ACTIVATED);
|
2015-08-27 04:01:26 +10:00
|
|
|
}
|
|
|
|
|
2015-08-28 16:18:28 +10: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-08 06:28:57 +10:00
|
|
|
bool swayc_is_empty_workspace(swayc_t *container) {
|
|
|
|
return container->type == C_WORKSPACE && container->children->length == 0;
|
|
|
|
}
|
|
|
|
|
2015-09-05 09:14:59 +10:00
|
|
|
int swayc_gap(swayc_t *container) {
|
2016-04-23 06:44:02 +10:00
|
|
|
if (container->type == C_VIEW || container->type == C_CONTAINER) {
|
2015-09-05 09:14:59 +10:00
|
|
|
return container->gaps >= 0 ? container->gaps : config->gaps_inner;
|
|
|
|
} else if (container->type == C_WORKSPACE) {
|
2015-12-19 11:21:00 +11:00
|
|
|
int base = container->gaps >= 0 ? container->gaps : config->gaps_outer;
|
2016-03-20 22:29:47 +11:00
|
|
|
if (config->edge_gaps && !(config->smart_gaps && container->children->length == 1)) {
|
2015-12-19 11:21:00 +11: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-22 06:55:01 +10:00
|
|
|
} else if (config->smart_gaps && container->children->length == 1) {
|
|
|
|
return 0;
|
2015-12-19 11:21:00 +11:00
|
|
|
} else {
|
|
|
|
return base;
|
|
|
|
}
|
2015-09-05 09:14:59 +10:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-22 03:28:37 +10:00
|
|
|
// Mapping
|
|
|
|
|
2015-09-14 09:46:16 +10: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 16:18:28 +10: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-25 06:04:26 +10:00
|
|
|
if (parent->type == C_OUTPUT || parent->layout == L_TABBED ||
|
|
|
|
parent->layout == L_STACKED) {
|
2016-04-01 09:04:08 +11:00
|
|
|
container->visible = parent->focused == container && parent->visible;
|
2015-08-28 16:18:28 +10: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 16:42:26 +10: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 12:06:31 +10:00
|
|
|
}
|
|
|
|
}
|
2015-08-26 02:24:15 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
void update_visibility(swayc_t *container) {
|
2015-08-28 16:18:28 +10: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 13:55:48 +10:00
|
|
|
return;
|
2015-08-28 16:18:28 +10: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 13:55:48 +10:00
|
|
|
}
|
|
|
|
return;
|
2015-08-28 16:18:28 +10:00
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
swayc_t *op = swayc_parent_by_type(container, C_OUTPUT);
|
|
|
|
update_visibility_output(container, op->handle);
|
|
|
|
}
|
2015-08-28 13:55:48 +10:00
|
|
|
}
|
2015-08-17 12:06:31 +10:00
|
|
|
}
|
2015-08-19 12:05:58 +10:00
|
|
|
|
2015-09-14 09:46:16 +10: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 23:00:35 +11: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 22:36:36 +11:00
|
|
|
|
2016-07-16 23:11:08 +10:00
|
|
|
swayc_t *swayc_tabbed_stacked_ancestor(swayc_t *view) {
|
2016-04-20 08:22:15 +10:00
|
|
|
swayc_t *parent = NULL;
|
|
|
|
if (!ASSERT_NONNULL(view)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-07-08 06:28:57 +10:00
|
|
|
while (view->type != C_WORKSPACE && view->parent && view->parent->type != C_WORKSPACE) {
|
2016-05-15 00:34:25 +10:00
|
|
|
view = view->parent;
|
2016-04-20 08:22:15 +10:00
|
|
|
if (view->layout == L_TABBED || view->layout == L_STACKED) {
|
|
|
|
parent = view;
|
|
|
|
}
|
2016-06-19 03:31:18 +10:00
|
|
|
}
|
2016-04-20 08:22:15 +10:00
|
|
|
|
|
|
|
return parent;
|
|
|
|
}
|
2016-07-16 23:11:08 +10: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;
|
|
|
|
}
|
2016-10-11 05:44:09 +11:00
|
|
|
|
|
|
|
swayc_t *swayc_change_layout(swayc_t *container, enum swayc_layouts layout) {
|
|
|
|
if (container->type == C_WORKSPACE) {
|
|
|
|
container->workspace_layout = layout;
|
2016-11-17 16:49:12 +11:00
|
|
|
if (layout == L_HORIZ || layout == L_VERT) {
|
|
|
|
container->layout = layout;
|
|
|
|
}
|
2016-10-11 05:44:09 +11:00
|
|
|
} else {
|
|
|
|
container->layout = layout;
|
|
|
|
}
|
|
|
|
return container;
|
|
|
|
}
|