aboutsummaryrefslogtreecommitdiff
path: root/sway/tree
diff options
context:
space:
mode:
Diffstat (limited to 'sway/tree')
-rw-r--r--sway/tree/container.c170
-rw-r--r--sway/tree/output.c22
-rw-r--r--sway/tree/view.c216
-rw-r--r--sway/tree/workspace.c10
4 files changed, 207 insertions, 211 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 58d3df34..458ed7ff 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -39,6 +39,7 @@ struct sway_container *container_create(struct sway_view *view) {
c->children = create_list();
c->current.children = create_list();
}
+ c->marks = create_list();
c->outputs = create_list();
wl_signal_init(&c->events.destroy);
@@ -66,6 +67,13 @@ void container_destroy(struct sway_container *con) {
list_free(con->current.children);
list_free(con->outputs);
+ list_foreach(con->marks, free);
+ list_free(con->marks);
+ wlr_texture_destroy(con->marks_focused);
+ wlr_texture_destroy(con->marks_focused_inactive);
+ wlr_texture_destroy(con->marks_unfocused);
+ wlr_texture_destroy(con->marks_urgent);
+
if (con->view) {
if (con->view->container == con) {
con->view->container = NULL;
@@ -639,8 +647,8 @@ void container_init_floating(struct sway_container *con) {
view->y = ws->y + (ws->height - view->height) / 2;
// If the view's border is B_NONE then these properties are ignored.
- view->border_top = view->border_bottom = true;
- view->border_left = view->border_right = true;
+ con->border_top = con->border_bottom = true;
+ con->border_left = con->border_right = true;
container_set_geometry_from_floating_view(con);
}
@@ -662,7 +670,7 @@ void container_set_floating(struct sway_container *container, bool enable) {
if (container->view) {
view_set_tiled(container->view, false);
if (container->view->using_csd) {
- container->view->border = B_CSD;
+ container->border = B_CSD;
}
}
if (old_parent) {
@@ -676,11 +684,8 @@ void container_set_floating(struct sway_container *container, bool enable) {
container_detach(container);
struct sway_container *reference =
seat_get_focus_inactive_tiling(seat, workspace);
- if (reference && reference->view) {
- reference = reference->parent;
- }
if (reference) {
- container_add_child(reference, container);
+ container_add_sibling(reference, container, 1);
container->width = reference->width;
container->height = reference->height;
} else {
@@ -691,7 +696,7 @@ void container_set_floating(struct sway_container *container, bool enable) {
if (container->view) {
view_set_tiled(container->view, true);
if (container->view->using_csd) {
- container->view->border = container->view->saved_border;
+ container->border = container->saved_border;
}
}
container->is_sticky = false;
@@ -713,9 +718,9 @@ void container_set_geometry_from_floating_view(struct sway_container *con) {
size_t border_width = 0;
size_t top = 0;
- if (view->border != B_CSD) {
- border_width = view->border_thickness * (view->border != B_NONE);
- top = view->border == B_NORMAL ?
+ if (con->border != B_CSD) {
+ border_width = con->border_thickness * (con->border != B_NONE);
+ top = con->border == B_NORMAL ?
container_titlebar_height() : border_width;
}
@@ -999,9 +1004,7 @@ void container_discover_outputs(struct sway_container *con) {
double new_scale = new_output ? new_output->wlr_output->scale : -1;
if (old_scale != new_scale) {
container_update_title_textures(con);
- if (con->view) {
- view_update_marks_textures(con->view);
- }
+ container_update_marks_textures(con);
}
}
@@ -1221,3 +1224,142 @@ bool container_is_transient_for(struct sway_container *child,
child->view && ancestor->view &&
view_is_transient_for(child->view, ancestor->view);
}
+
+static bool find_by_mark_iterator(struct sway_container *con, void *data) {
+ char *mark = data;
+ return container_has_mark(con, mark);
+}
+
+struct sway_container *container_find_mark(char *mark) {
+ return root_find_container(find_by_mark_iterator, mark);
+}
+
+bool container_find_and_unmark(char *mark) {
+ struct sway_container *con = root_find_container(
+ find_by_mark_iterator, mark);
+ if (!con) {
+ return false;
+ }
+
+ for (int i = 0; i < con->marks->length; ++i) {
+ char *con_mark = con->marks->items[i];
+ if (strcmp(con_mark, mark) == 0) {
+ free(con_mark);
+ list_del(con->marks, i);
+ container_update_marks_textures(con);
+ ipc_event_window(con, "mark");
+ return true;
+ }
+ }
+ return false;
+}
+
+void container_clear_marks(struct sway_container *con) {
+ list_foreach(con->marks, free);
+ con->marks->length = 0;
+ ipc_event_window(con, "mark");
+}
+
+bool container_has_mark(struct sway_container *con, char *mark) {
+ for (int i = 0; i < con->marks->length; ++i) {
+ char *item = con->marks->items[i];
+ if (strcmp(item, mark) == 0) {
+ return true;
+ }
+ }
+ return false;
+}
+
+void container_add_mark(struct sway_container *con, char *mark) {
+ list_add(con->marks, strdup(mark));
+ ipc_event_window(con, "mark");
+}
+
+static void update_marks_texture(struct sway_container *con,
+ struct wlr_texture **texture, struct border_colors *class) {
+ struct sway_output *output = container_get_effective_output(con);
+ if (!output) {
+ return;
+ }
+ if (*texture) {
+ wlr_texture_destroy(*texture);
+ *texture = NULL;
+ }
+ if (!con->marks->length) {
+ return;
+ }
+
+ size_t len = 0;
+ for (int i = 0; i < con->marks->length; ++i) {
+ char *mark = con->marks->items[i];
+ if (mark[0] != '_') {
+ len += strlen(mark) + 2;
+ }
+ }
+ char *buffer = calloc(len + 1, 1);
+ char *part = malloc(len + 1);
+
+ if (!sway_assert(buffer && part, "Unable to allocate memory")) {
+ free(buffer);
+ return;
+ }
+
+ for (int i = 0; i < con->marks->length; ++i) {
+ char *mark = con->marks->items[i];
+ if (mark[0] != '_') {
+ sprintf(part, "[%s]", mark);
+ strcat(buffer, part);
+ }
+ }
+ free(part);
+
+ double scale = output->wlr_output->scale;
+ int width = 0;
+ int height = con->title_height * scale;
+
+ cairo_t *c = cairo_create(NULL);
+ get_text_size(c, config->font, &width, NULL, NULL, scale, false,
+ "%s", buffer);
+ cairo_destroy(c);
+
+ cairo_surface_t *surface = cairo_image_surface_create(
+ CAIRO_FORMAT_ARGB32, width, height);
+ cairo_t *cairo = cairo_create(surface);
+ cairo_set_source_rgba(cairo, class->background[0], class->background[1],
+ class->background[2], class->background[3]);
+ cairo_paint(cairo);
+ PangoContext *pango = pango_cairo_create_context(cairo);
+ cairo_set_antialias(cairo, CAIRO_ANTIALIAS_BEST);
+ cairo_set_source_rgba(cairo, class->text[0], class->text[1],
+ class->text[2], class->text[3]);
+ cairo_move_to(cairo, 0, 0);
+
+ pango_printf(cairo, config->font, scale, false, "%s", buffer);
+
+ cairo_surface_flush(surface);
+ unsigned char *data = cairo_image_surface_get_data(surface);
+ int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
+ struct wlr_renderer *renderer = wlr_backend_get_renderer(
+ output->wlr_output->backend);
+ *texture = wlr_texture_from_pixels(
+ renderer, WL_SHM_FORMAT_ARGB8888, stride, width, height, data);
+ cairo_surface_destroy(surface);
+ g_object_unref(pango);
+ cairo_destroy(cairo);
+ free(buffer);
+}
+
+void container_update_marks_textures(struct sway_container *con) {
+ if (!config->show_marks) {
+ return;
+ }
+ update_marks_texture(con, &con->marks_focused,
+ &config->border_colors.focused);
+ update_marks_texture(con, &con->marks_focused_inactive,
+ &config->border_colors.focused_inactive);
+ update_marks_texture(con, &con->marks_unfocused,
+ &config->border_colors.unfocused);
+ update_marks_texture(con, &con->marks_urgent,
+ &config->border_colors.urgent);
+ container_damage_whole(con);
+}
diff --git a/sway/tree/output.c b/sway/tree/output.c
index e5794b8a..2704920d 100644
--- a/sway/tree/output.c
+++ b/sway/tree/output.c
@@ -65,8 +65,13 @@ void output_enable(struct sway_output *output, struct output_config *oc) {
return;
}
struct wlr_output *wlr_output = output->wlr_output;
+ 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);
+
output->enabled = true;
- apply_output_config(oc, output);
list_add(root->outputs, output);
output->lx = wlr_output->lx;
@@ -92,11 +97,8 @@ void output_enable(struct sway_output *output, struct output_config *oc) {
ipc_event_workspace(NULL, ws, "init");
}
- 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);
+
+ apply_output_config(oc, output);
input_manager_configure_xcursor();
@@ -274,16 +276,14 @@ struct sway_output *output_from_wlr_output(struct wlr_output *output) {
}
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)) {
+ enum wlr_direction direction) {
+ if (!sway_assert(direction, "got invalid direction: %d", direction)) {
return NULL;
}
int lx = reference->wlr_output->lx + reference->width / 2;
int ly = reference->wlr_output->ly + reference->height / 2;
struct wlr_output *wlr_adjacent = wlr_output_layout_adjacent_output(
- root->output_layout, wlr_dir, reference->wlr_output, lx, ly);
+ root->output_layout, direction, reference->wlr_output, lx, ly);
if (!wlr_adjacent) {
return NULL;
}
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 4bc9e0f3..1aa59e68 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -35,7 +35,6 @@ void view_init(struct sway_view *view, enum sway_view_type type,
view->type = type;
view->impl = impl;
view->executed_criteria = create_list();
- view->marks = create_list();
view->allow_request_urgent = true;
wl_signal_init(&view->events.unmap);
}
@@ -55,13 +54,6 @@ void view_destroy(struct sway_view *view) {
}
list_free(view->executed_criteria);
- list_foreach(view->marks, free);
- list_free(view->marks);
-
- wlr_texture_destroy(view->marks_focused);
- 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) {
@@ -225,21 +217,21 @@ void view_autoconfigure(struct sway_view *view) {
bool no_gaps = config->hide_edge_borders != E_SMART_NO_GAPS
|| !gaps_to_edge(view);
- view->border_top = view->border_bottom = true;
- view->border_left = view->border_right = true;
+ con->border_top = con->border_bottom = true;
+ con->border_left = con->border_right = true;
if (config->hide_edge_borders == E_BOTH
|| config->hide_edge_borders == E_VERTICAL
|| (smart && !other_views && no_gaps)) {
- view->border_left = con->x - con->current_gaps != ws->x;
+ con->border_left = con->x - con->current_gaps != ws->x;
int right_x = con->x + con->width + con->current_gaps;
- view->border_right = right_x != ws->x + ws->width;
+ con->border_right = right_x != ws->x + ws->width;
}
if (config->hide_edge_borders == E_BOTH
|| config->hide_edge_borders == E_HORIZONTAL
|| (smart && !other_views && no_gaps)) {
- view->border_top = con->y - con->current_gaps != ws->y;
+ con->border_top = con->y - con->current_gaps != ws->y;
int bottom_y = con->y + con->height + con->current_gaps;
- view->border_bottom = bottom_y != ws->y + ws->height;
+ con->border_bottom = bottom_y != ws->y + ws->height;
}
double x, y, width, height;
@@ -252,14 +244,14 @@ void view_autoconfigure(struct sway_view *view) {
enum sway_container_layout layout = container_parent_layout(con);
if (layout == L_TABBED && !container_is_floating(con)) {
y_offset = container_titlebar_height();
- view->border_top = false;
+ con->border_top = false;
} else if (layout == L_STACKED && !container_is_floating(con)) {
list_t *siblings = container_get_siblings(con);
y_offset = container_titlebar_height() * siblings->length;
- view->border_top = false;
+ con->border_top = false;
}
- switch (view->border) {
+ switch (con->border) {
case B_CSD:
case B_NONE:
x = con->x;
@@ -268,29 +260,29 @@ void view_autoconfigure(struct sway_view *view) {
height = con->height - y_offset;
break;
case B_PIXEL:
- x = con->x + view->border_thickness * view->border_left;
- y = con->y + view->border_thickness * view->border_top + y_offset;
+ x = con->x + con->border_thickness * con->border_left;
+ y = con->y + con->border_thickness * con->border_top + y_offset;
width = con->width
- - view->border_thickness * view->border_left
- - view->border_thickness * view->border_right;
+ - con->border_thickness * con->border_left
+ - con->border_thickness * con->border_right;
height = con->height - y_offset
- - view->border_thickness * view->border_top
- - view->border_thickness * view->border_bottom;
+ - con->border_thickness * con->border_top
+ - con->border_thickness * con->border_bottom;
break;
case B_NORMAL:
// Height is: 1px border + 3px pad + title height + 3px pad + 1px border
- x = con->x + view->border_thickness * view->border_left;
+ x = con->x + con->border_thickness * con->border_left;
width = con->width
- - view->border_thickness * view->border_left
- - view->border_thickness * view->border_right;
+ - con->border_thickness * con->border_left
+ - con->border_thickness * con->border_right;
if (y_offset) {
y = con->y + y_offset;
height = con->height - y_offset
- - view->border_thickness * view->border_bottom;
+ - con->border_thickness * con->border_bottom;
} else {
y = con->y + container_titlebar_height();
height = con->height - container_titlebar_height()
- - view->border_thickness * view->border_bottom;
+ - con->border_thickness * con->border_bottom;
}
break;
}
@@ -347,13 +339,14 @@ void view_set_csd_from_server(struct sway_view *view, bool enabled) {
void view_update_csd_from_client(struct sway_view *view, bool enabled) {
wlr_log(WLR_DEBUG, "View %p updated CSD to %i", view, enabled);
- if (enabled && view->border != B_CSD) {
- view->saved_border = view->border;
- if (view->container && container_is_floating(view->container)) {
- view->border = B_CSD;
+ struct sway_container *con = view->container;
+ if (enabled && con && con->border != B_CSD) {
+ con->saved_border = con->border;
+ if (container_is_floating(con)) {
+ con->border = B_CSD;
}
- } else if (!enabled && view->border == B_CSD) {
- view->border = view->saved_border;
+ } else if (!enabled && con && con->border == B_CSD) {
+ con->border = con->saved_border;
}
view->using_csd = enabled;
}
@@ -584,12 +577,12 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface,
view->surface_new_subsurface.notify = view_handle_surface_new_subsurface;
if (view->impl->wants_floating && view->impl->wants_floating(view)) {
- view->border = config->floating_border;
- view->border_thickness = config->floating_border_thickness;
+ view->container->border = config->floating_border;
+ view->container->border_thickness = config->floating_border_thickness;
container_set_floating(view->container, true);
} else {
- view->border = config->border;
- view->border_thickness = config->border_thickness;
+ view->container->border = config->border;
+ view->container->border_thickness = config->border_thickness;
view_set_tiled(view, true);
}
@@ -936,153 +929,6 @@ void view_update_title(struct sway_view *view, bool force) {
ipc_event_window(view->container, "title");
}
-static bool find_by_mark_iterator(struct sway_container *con,
- void *data) {
- char *mark = data;
- return con->view && view_has_mark(con->view, mark);
-}
-
-struct sway_view *view_find_mark(char *mark) {
- struct sway_container *container = root_find_container(
- find_by_mark_iterator, mark);
- if (!container) {
- return NULL;
- }
- return container->view;
-}
-
-bool view_find_and_unmark(char *mark) {
- struct sway_container *container = root_find_container(
- find_by_mark_iterator, mark);
- if (!container) {
- return false;
- }
- struct sway_view *view = container->view;
-
- for (int i = 0; i < view->marks->length; ++i) {
- char *view_mark = view->marks->items[i];
- if (strcmp(view_mark, mark) == 0) {
- free(view_mark);
- list_del(view->marks, i);
- view_update_marks_textures(view);
- ipc_event_window(container, "mark");
- return true;
- }
- }
- return false;
-}
-
-void view_clear_marks(struct sway_view *view) {
- 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) {
- for (int i = 0; i < view->marks->length; ++i) {
- char *item = view->marks->items[i];
- if (strcmp(item, mark) == 0) {
- return true;
- }
- }
- return false;
-}
-
-void view_add_mark(struct sway_view *view, char *mark) {
- list_add(view->marks, strdup(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->container);
- if (!output) {
- return;
- }
- if (*texture) {
- wlr_texture_destroy(*texture);
- *texture = NULL;
- }
- if (!view->marks->length) {
- return;
- }
-
- size_t len = 0;
- for (int i = 0; i < view->marks->length; ++i) {
- char *mark = view->marks->items[i];
- if (mark[0] != '_') {
- len += strlen(mark) + 2;
- }
- }
- char *buffer = calloc(len + 1, 1);
- char *part = malloc(len + 1);
-
- if (!sway_assert(buffer && part, "Unable to allocate memory")) {
- free(buffer);
- return;
- }
-
- for (int i = 0; i < view->marks->length; ++i) {
- char *mark = view->marks->items[i];
- if (mark[0] != '_') {
- sprintf(part, "[%s]", mark);
- strcat(buffer, part);
- }
- }
- free(part);
-
- double scale = output->wlr_output->scale;
- int width = 0;
- int height = view->container->title_height * scale;
-
- cairo_t *c = cairo_create(NULL);
- get_text_size(c, config->font, &width, NULL, NULL, scale, false,
- "%s", buffer);
- cairo_destroy(c);
-
- cairo_surface_t *surface = cairo_image_surface_create(
- CAIRO_FORMAT_ARGB32, width, height);
- cairo_t *cairo = cairo_create(surface);
- cairo_set_source_rgba(cairo, class->background[0], class->background[1],
- class->background[2], class->background[3]);
- cairo_paint(cairo);
- PangoContext *pango = pango_cairo_create_context(cairo);
- cairo_set_antialias(cairo, CAIRO_ANTIALIAS_BEST);
- cairo_set_source_rgba(cairo, class->text[0], class->text[1],
- class->text[2], class->text[3]);
- cairo_move_to(cairo, 0, 0);
-
- pango_printf(cairo, config->font, scale, false, "%s", buffer);
-
- cairo_surface_flush(surface);
- unsigned char *data = cairo_image_surface_get_data(surface);
- int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
- struct wlr_renderer *renderer = wlr_backend_get_renderer(
- output->wlr_output->backend);
- *texture = wlr_texture_from_pixels(
- renderer, WL_SHM_FORMAT_ARGB8888, stride, width, height, data);
- cairo_surface_destroy(surface);
- g_object_unref(pango);
- cairo_destroy(cairo);
- free(buffer);
-}
-
-void view_update_marks_textures(struct sway_view *view) {
- if (!config->show_marks) {
- return;
- }
- update_marks_texture(view, &view->marks_focused,
- &config->border_colors.focused);
- update_marks_texture(view, &view->marks_focused_inactive,
- &config->border_colors.focused_inactive);
- update_marks_texture(view, &view->marks_unfocused,
- &config->border_colors.unfocused);
- update_marks_texture(view, &view->marks_urgent,
- &config->border_colors.urgent);
- container_damage_whole(view->container);
-}
-
bool view_is_visible(struct sway_view *view) {
if (view->container->node.destroying) {
return false;
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index 27e9ac7a..05cda5c0 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -35,6 +35,10 @@ struct sway_output *workspace_get_initial_output(const char *name) {
struct workspace_config *wsc = workspace_find_config(name);
if (wsc && wsc->output) {
struct sway_output *output = output_by_name(wsc->output);
+ if (!output) {
+ output = output_by_identifier(wsc->output);
+ }
+
if (output) {
return output;
}
@@ -143,7 +147,11 @@ void workspace_consider_destroy(struct sway_workspace *ws) {
static bool workspace_valid_on_output(const char *output_name,
const char *ws_name) {
struct workspace_config *wsc = workspace_find_config(ws_name);
- return !wsc || !wsc->output || strcmp(wsc->output, output_name) == 0;
+ char identifier[128];
+ struct sway_output *output = output_by_name(output_name);
+ output_get_identifier(identifier, sizeof(identifier), output);
+
+ return !wsc || !wsc->output || strcmp(wsc->output, output_name) == 0 || strcasecmp(identifier, output_name) == 0;
}
static void workspace_name_from_binding(const struct sway_binding * binding,