diff options
| author | emersion <contact@emersion.fr> | 2018-05-23 22:54:52 +0100 |
|---|---|---|
| committer | emersion <contact@emersion.fr> | 2018-05-23 22:54:52 +0100 |
| commit | cd0fca2ebf81c252b3743c4474a5fdbcd3e2afad (patch) | |
| tree | 595f1e80551b64de0d4e24f5721bae27acc195d9 | |
| parent | b7ab7c0e66433aacaaccce08d6e40304e6f6593c (diff) | |
| parent | 12a12878b9883c345dd73752a9cf714aeb245b8a (diff) | |
Merge branch 'master' into fix-swaylock-hotplugging
| -rw-r--r-- | include/sway/input/cursor.h | 3 | ||||
| -rw-r--r-- | include/sway/input/seat.h | 6 | ||||
| -rw-r--r-- | include/sway/tree/container.h | 15 | ||||
| -rw-r--r-- | include/sway/tree/view.h | 6 | ||||
| -rw-r--r-- | include/swaylock/swaylock.h | 26 | ||||
| -rw-r--r-- | meson.build | 2 | ||||
| -rw-r--r-- | protocols/meson.build | 6 | ||||
| -rw-r--r-- | sway/commands/border.c | 2 | ||||
| -rw-r--r-- | sway/commands/layout.c | 4 | ||||
| -rw-r--r-- | sway/commands/seat/cursor.c | 4 | ||||
| -rw-r--r-- | sway/desktop/output.c | 518 | ||||
| -rw-r--r-- | sway/input/cursor.c | 31 | ||||
| -rw-r--r-- | sway/input/seat.c | 16 | ||||
| -rw-r--r-- | sway/ipc-server.c | 22 | ||||
| -rw-r--r-- | sway/tree/arrange.c | 64 | ||||
| -rw-r--r-- | sway/tree/container.c | 336 | ||||
| -rw-r--r-- | sway/tree/layout.c | 11 | ||||
| -rw-r--r-- | sway/tree/view.c | 86 | ||||
| -rw-r--r-- | swaylock/main.c | 158 | ||||
| -rw-r--r-- | swaylock/render.c | 2 |
20 files changed, 985 insertions, 333 deletions
diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index 20c1c903..42c894a4 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h @@ -29,7 +29,8 @@ struct sway_cursor { void sway_cursor_destroy(struct sway_cursor *cursor); struct sway_cursor *sway_cursor_create(struct sway_seat *seat); -void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec); +void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, + bool allow_refocusing); void dispatch_cursor_button(struct sway_cursor *cursor, uint32_t time_msec, uint32_t button, enum wlr_button_state state); diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h index ff76841e..2e4da438 100644 --- a/include/sway/input/seat.h +++ b/include/sway/input/seat.h @@ -95,6 +95,12 @@ struct sway_container *seat_get_focus_inactive_view(struct sway_seat *seat, struct sway_container *container); /** + * Return the immediate child of container which was most recently focused. + */ +struct sway_container *seat_get_active_child(struct sway_seat *seat, + struct sway_container *container); + +/** * Iterate over the focus-inactive children of the container calling the * function on each. */ diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index ec9e2385..493c70e2 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -11,6 +11,12 @@ extern struct sway_container root_container; struct sway_view; struct sway_seat; +#define TITLEBAR_BORDER_THICKNESS 1 + +// Padding includes titlebar border +#define TITLEBAR_H_PADDING 3 +#define TITLEBAR_V_PADDING 4 + /** * Different kinds of containers. * @@ -98,6 +104,8 @@ struct sway_container { // Passed the previous parent struct wl_signal reparent; } events; + + struct wl_listener reparent; }; struct sway_container *container_create(enum sway_container_type type); @@ -160,7 +168,7 @@ struct sway_container *container_parent(struct sway_container *container, * is a view and the view contains a surface at those coordinates. */ struct sway_container *container_at(struct sway_container *container, - double lx, double ly, struct wlr_surface **surface, + double ox, double oy, struct wlr_surface **surface, double *sx, double *sy); /** @@ -210,4 +218,9 @@ void container_calculate_title_height(struct sway_container *container); void container_notify_child_title_changed(struct sway_container *container); +/** + * Return the height of a regular title bar. + */ +size_t container_titlebar_height(void); + #endif diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 951912d0..0fb8f1b3 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -274,4 +274,10 @@ bool view_has_mark(struct sway_view *view, char *mark); void view_update_marks_textures(struct sway_view *view); +/** + * Returns true if there's a possibility the view may be rendered on screen. + * Intended for damage tracking. + */ +bool view_is_visible(struct sway_view *view); + #endif diff --git a/include/swaylock/swaylock.h b/include/swaylock/swaylock.h index 56ec0afb..27db67cd 100644 --- a/include/swaylock/swaylock.h +++ b/include/swaylock/swaylock.h @@ -10,13 +10,13 @@ #include "wlr-layer-shell-unstable-v1-client-protocol.h" enum auth_state { - AUTH_STATE_IDLE, - AUTH_STATE_CLEAR, - AUTH_STATE_INPUT, - AUTH_STATE_INPUT_NOP, - AUTH_STATE_BACKSPACE, - AUTH_STATE_VALIDATING, - AUTH_STATE_INVALID, + AUTH_STATE_IDLE, + AUTH_STATE_CLEAR, + AUTH_STATE_INPUT, + AUTH_STATE_INPUT_NOP, + AUTH_STATE_BACKSPACE, + AUTH_STATE_VALIDATING, + AUTH_STATE_INVALID, }; struct swaylock_args { @@ -37,12 +37,14 @@ struct swaylock_state { struct zwlr_input_inhibit_manager_v1 *input_inhibit_manager; struct wl_shm *shm; struct wl_list surfaces; + struct wl_list images; struct swaylock_args args; cairo_surface_t *background_image; struct swaylock_password password; struct swaylock_xkb xkb; enum auth_state auth_state; bool run_display; + struct zxdg_output_manager_v1 *zxdg_output_manager; }; struct swaylock_surface { @@ -50,12 +52,22 @@ struct swaylock_surface { struct swaylock_state *state; struct wl_output *output; uint32_t output_global_name; + struct zxdg_output_v1 *xdg_output; struct wl_surface *surface; struct zwlr_layer_surface_v1 *layer_surface; struct pool_buffer buffers[2]; struct pool_buffer *current_buffer; uint32_t width, height; int32_t scale; + char *output_name; + struct wl_list link; +}; + +// There is exactly one swaylock_image for each -i argument +struct swaylock_image { + char *path; + char *output_name; + cairo_surface_t *cairo_surface; struct wl_list link; }; diff --git a/meson.build b/meson.build index b943236f..d4ee1a11 100644 --- a/meson.build +++ b/meson.build @@ -29,7 +29,7 @@ wayland_server = dependency('wayland-server') wayland_client = dependency('wayland-client') wayland_cursor = dependency('wayland-cursor') wayland_egl = dependency('wayland-egl') -wayland_protos = dependency('wayland-protocols') +wayland_protos = dependency('wayland-protocols', version: '>=1.14') xkbcommon = dependency('xkbcommon') cairo = dependency('cairo') pango = dependency('pango') diff --git a/protocols/meson.build b/protocols/meson.build index 9966c02f..a031245c 100644 --- a/protocols/meson.build +++ b/protocols/meson.build @@ -29,16 +29,18 @@ wayland_scanner_server = generator( client_protocols = [ [wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'], + [wl_protocol_dir, 'unstable/xdg-output/xdg-output-unstable-v1.xml'], ['wlr-layer-shell-unstable-v1.xml'], ['idle.xml'], - ['wlr-input-inhibitor-unstable-v1.xml'] + ['wlr-input-inhibitor-unstable-v1.xml'], ] server_protocols = [ [wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'], [wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'], + [wl_protocol_dir, 'unstable/xdg-output/xdg-output-unstable-v1.xml'], ['wlr-layer-shell-unstable-v1.xml'], - ['wlr-input-inhibitor-unstable-v1.xml'] + ['wlr-input-inhibitor-unstable-v1.xml'], ] client_protos_src = [] diff --git a/sway/commands/border.c b/sway/commands/border.c index 1eb06a21..4ba361da 100644 --- a/sway/commands/border.c +++ b/sway/commands/border.c @@ -41,7 +41,7 @@ struct cmd_results *cmd_border(int argc, char **argv) { struct sway_seat *seat = input_manager_current_seat(input_manager); if (seat->cursor) { - cursor_send_pointer_motion(seat->cursor, 0); + cursor_send_pointer_motion(seat->cursor, 0, false); } return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/commands/layout.c b/sway/commands/layout.c index bb36bb18..58728f16 100644 --- a/sway/commands/layout.c +++ b/sway/commands/layout.c @@ -39,6 +39,10 @@ struct cmd_results *cmd_layout(int argc, char **argv) { parent->layout = L_HORIZ; } else if (strcasecmp(argv[0], "splitv") == 0) { parent->layout = L_VERT; + } else if (strcasecmp(argv[0], "tabbed") == 0) { + parent->layout = L_TABBED; + } else if (strcasecmp(argv[0], "stacking") == 0) { + parent->layout = L_STACKED; } else if (strcasecmp(argv[0], "toggle") == 0 && argc == 2 && strcasecmp(argv[1], "split") == 0) { if (parent->layout == L_HORIZ) { parent->layout = L_VERT; diff --git a/sway/commands/seat/cursor.c b/sway/commands/seat/cursor.c index 929384b0..4d0a22c7 100644 --- a/sway/commands/seat/cursor.c +++ b/sway/commands/seat/cursor.c @@ -36,7 +36,7 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { int delta_x = strtol(argv[1], NULL, 10); int delta_y = strtol(argv[2], NULL, 10); wlr_cursor_move(cursor->cursor, NULL, delta_x, delta_y); - cursor_send_pointer_motion(cursor, 0); + cursor_send_pointer_motion(cursor, 0, true); } else if (strcasecmp(argv[0], "set") == 0) { if (argc < 3) { return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); @@ -45,7 +45,7 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { float x = strtof(argv[1], NULL) / root_container.width; float y = strtof(argv[2], NULL) / root_container.height; wlr_cursor_warp_absolute(cursor->cursor, NULL, x, y); - cursor_send_pointer_motion(cursor, 0); + cursor_send_pointer_motion(cursor, 0, true); } else { if (argc < 2) { return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 94562052..765647fd 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -269,17 +269,6 @@ static void render_unmanaged(struct sway_output *output, render_surface_iterator, &data); } -static void render_view(struct sway_view *view, struct sway_output *output, - pixman_region32_t *damage) { - struct render_data data = { - .output = output, - .damage = damage, - .alpha = view->swayc->alpha, - }; - output_view_for_each_surface( - view, &data.root_geo, render_surface_iterator, &data); -} - static void render_rect(struct wlr_output *wlr_output, pixman_region32_t *output_damage, const struct wlr_box *_box, float color[static 4]) { @@ -310,93 +299,149 @@ damage_finish: pixman_region32_fini(&damage); } +static void premultiply_alpha(float color[4], float opacity) { + color[3] *= opacity; + color[0] *= color[3]; + color[1] *= color[3]; + color[2] *= color[3]; +} + +static void render_view_surfaces(struct sway_view *view, + struct sway_output *output, pixman_region32_t *damage) { + struct render_data data = { + .output = output, + .damage = damage, + .alpha = view->swayc->alpha, + }; + output_view_for_each_surface( + view, &data.root_geo, render_surface_iterator, &data); +} + /** - * Render decorations for a view with "border normal". - * - * Care must be taken not to render over the same pixel multiple times, - * otherwise the colors will be incorrect when using opacity. + * Render a view's surface and left/bottom/right borders. */ -static void render_container_simple_border_normal(struct sway_output *output, - pixman_region32_t *output_damage, - struct sway_container *con, struct border_colors *colors, - struct wlr_texture *title_texture, struct wlr_texture *marks_texture) { - struct wlr_box box; - float color[4]; +static void render_view(struct sway_output *output, pixman_region32_t *damage, + struct sway_container *con, struct border_colors *colors) { struct sway_view *view = con->sway_view; - float output_scale = output->wlr_output->scale; + render_view_surfaces(view, output, damage); - if (view->border_left) { - // Child border - left edge - memcpy(&color, colors->child_border, sizeof(float) * 4); - color[3] *= con->alpha; - box.x = con->x; - box.y = con->y + 1; - box.width = view->border_thickness; - box.height = con->height - 1 - - view->border_thickness * view->border_bottom; - scale_box(&box, output_scale); - render_rect(output->wlr_output, output_damage, &box, color); - } + struct wlr_box box; + float output_scale = output->wlr_output->scale; + float color[4]; - if (view->border_right) { - // Child border - right edge - if (con->parent->children->length == 1 - && con->parent->layout == L_HORIZ) { - memcpy(&color, colors->indicator, sizeof(float) * 4); - } else { + if (view->border != B_NONE) { + if (view->border_left) { memcpy(&color, colors->child_border, sizeof(float) * 4); + premultiply_alpha(color, con->alpha); + box.x = con->x; + box.y = view->y; + box.width = view->border_thickness; + box.height = view->height; + scale_box(&box, output_scale); + render_rect(output->wlr_output, damage, &box, color); } - color[3] *= con->alpha; - box.x = con->x + con->width - view->border_thickness; - box.y = con->y + 1; - box.width = view->border_thickness; - box.height = con->height - 1 - - view->border_thickness * view->border_bottom; - scale_box(&box, output_scale); - render_rect(output->wlr_output, output_damage, &box, color); - } - if (view->border_bottom) { - // Child border - bottom edge - if (con->parent->children->length == 1 - && con->parent->layout == L_VERT) { - memcpy(&color, colors->indicator, sizeof(float) * 4); - } else { - memcpy(&color, colors->child_border, sizeof(float) * 4); + if (view->border_right) { + if (con->parent->children->length == 1 + && con->parent->layout == L_HORIZ) { + memcpy(&color, colors->indicator, sizeof(float) * 4); + } else { + memcpy(&color, colors->child_border, sizeof(float) * 4); + } + premultiply_alpha(color, con->alpha); + box.x = view->x + view->width; + box.y = view->y; + box.width = view->border_thickness; + box.height = view->height; + scale_box(&box, output_scale); + render_rect(output->wlr_output, damage, &box, color); + } + + if (view->border_bottom) { + if (con->parent->children->length == 1 + && con->parent->layout == L_VERT) { + memcpy(&color, colors->indicator, sizeof(float) * 4); + } else { + memcpy(&color, colors->child_border, sizeof(float) * 4); + } + premultiply_alpha(color, con->alpha); + box.x = con->x; + box.y = view->y + view->height; + box.width = con->width; + box.height = view->border_thickness; + scale_box(&box, output_scale); + render_rect(output->wlr_output, damage, &box, color); } - color[3] *= con->alpha; - box.x = con->x; - box.y = con->y + con->height - view->border_thickness; - box.width = con->width; - box.height = view->border_thickness; - scale_box(&box, output_scale); - render_rect(output->wlr_output, output_damage, &box, color); } +} + +/** + * Render a titlebar. + * + * Care must be taken not to render over the same pixel multiple times, + * otherwise the colors will be incorrect when using opacity. + * + * The height is: 1px border, 3px padding, font height, 3px padding, 1px border + * The left side for L_TABBED is: 1px border, 2px padding, title + * The left side for other layouts is: 3px padding, title + */ +static void render_titlebar(struct sway_output *output, + pixman_region32_t *output_damage, struct sway_container *con, + int x, int y, int width, + struct border_colors *colors, struct wlr_texture *title_texture, + struct wlr_texture *marks_texture) { + struct wlr_box box; + float color[4]; + struct sway_view *view = con->type == C_VIEW ? con->sway_view : NULL; + float output_scale = output->wlr_output->scale; + enum sway_container_layout layout = con->parent->layout; + bool is_last_child = + con->parent->children->items[con->parent->children->length - 1] == con; // Single pixel bar above title memcpy(&color, colors->border, sizeof(float) * 4); - color[3] *= con->alpha; - box.x = con->x; - box.y = con->y; - box.width = con->width; - box.height = 1; + premultiply_alpha(color, con->alpha); + box.x = x; + box.y = y; + box.width = width; + box.height = TITLEBAR_BORDER_THICKNESS; scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); // Single pixel bar below title - memcpy(&color, colors->border, sizeof(float) * 4); - color[3] *= con->alpha; - box.x = con->x + view->border_thickness; - box.y = view->y - 1; - box.width = con->width - view->border_thickness * 2; - box.height = 1; + size_t left_offset = 0, right_offset = 0; + bool connects_sides = false; + if (layout == L_HORIZ || layout == L_VERT || + (layout == L_STACKED && is_last_child)) { + if (view) { + left_offset = view->border_left * view->border_thickness; + right_offset = view->border_right * view->border_thickness; + connects_sides = true; + } + } + box.x = x + left_offset; + box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS; + box.width = width - left_offset - right_offset; + box.height = TITLEBAR_BORDER_THICKNESS; scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); - // Setting these makes marks and title easier - size_t inner_x = con->x + view->border_thickness * view->border_left; - size_t inner_width = con->width - view->border_thickness * view->border_left - - view->border_thickness * view->border_right; + if (layout == L_TABBED) { + // Single pixel left edge + box.x = x; + box.y = y + TITLEBAR_BORDER_THICKNESS; + box.width = TITLEBAR_BORDER_THICKNESS; + box.height = + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS * 2; + scale_box(&box, output_scale); + render_rect(output->wlr_output, output_damage, &box, color); + + // Single pixel right edge + box.x = (x + width - TITLEBAR_BORDER_THICKNESS) * output_scale; + render_rect(output->wlr_output, output_damage, &box, color); + } + + size_t inner_width = width - TITLEBAR_H_PADDING * 2; // Marks size_t marks_width = 0; @@ -404,14 +449,18 @@ static void render_container_simple_border_normal(struct sway_output *output, struct wlr_box texture_box; wlr_texture_get_size(marks_texture, &texture_box.width, &texture_box.height); - texture_box.x = (inner_x + inner_width) * output_scale - texture_box.width; - texture_box.y = (con->y + view->border_thickness) * output_scale; + texture_box.x = + (x + width - TITLEBAR_H_PADDING) * output_scale - texture_box.width; + texture_box.y = (y + TITLEBAR_V_PADDING) * output_scale; float matrix[9]; wlr_matrix_project_box(matrix, &texture_box, WL_OUTPUT_TRANSFORM_NORMAL, 0.0, output->wlr_output->transform_matrix); + if (inner_width * output_scale < texture_box.width) { + texture_box.width = inner_width * output_scale; + } render_texture(output->wlr_output, output_damage, marks_texture, &texture_box, matrix, con->alpha); marks_width = texture_box.width; @@ -423,8 +472,8 @@ static void render_container_simple_border_normal(struct sway_output *output, struct wlr_box texture_box; wlr_texture_get_size(title_texture, &texture_box.width, &texture_box.height); - texture_box.x = inner_x * output_scale; - texture_box.y = (con->y + view->border_thickness) * output_scale; + texture_box.x = (x + TITLEBAR_H_PADDING) * output_scale; + texture_box.y = (y + TITLEBAR_V_PADDING) * output_scale; float matrix[9]; wlr_matrix_project_box(matrix, &texture_box, @@ -439,104 +488,89 @@ static void render_container_simple_border_normal(struct sway_output *output, title_width = texture_box.width; } - // Title background - above the text + // Padding above title memcpy(&color, colors->background, sizeof(float) * 4); - color[3] *= con->alpha; - box.x = inner_x; - box.y = con->y + 1; - box.width = inner_width; - box.height = view->border_thickness - 1; + premultiply_alpha(color, con->alpha); + box.x = x + (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS; + box.y = y + TITLEBAR_BORDER_THICKNESS; + box.width = width - (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS * 2; + box.height = TITLEBAR_V_PADDING - TITLEBAR_BORDER_THICKNESS; scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); - // Title background - below the text - box.y = (con->y + view->border_thickness + config->font_height) - * output_scale; + // Padding below title + box.y = (y + TITLEBAR_V_PADDING + config->font_height) * output_scale; render_rect(output->wlr_output, output_damage, &box, color); - // Title background - filler between title and marks + // Filler between title and marks box.width = inner_width * output_scale - title_width - marks_width; if (box.width > 0) { - box.x = inner_x * output_scale + title_width; - box.y = (con->y + view->border_thickness) * output_scale; + box.x = (x + TITLEBAR_H_PADDING) * output_scale + title_width; + box.y = (y + TITLEBAR_V_PADDING) * output_scale; box.height = config->font_height * output_scale; render_rect(output->wlr_output, output_damage, &box, color); } -} -/** - * Render decorations for a view with "border pixel". - * - * Care must be taken not to render over the same pixel multiple times, - * otherwise the colors will be incorrect when using opacity. - */ -static void render_container_simple_border_pixel(struct sway_output *output, - pixman_region32_t *output_damage, struct sway_container *con, - struct border_colors *colors) { - struct wlr_box box; - float color[4]; - struct sway_view *view = con->sway_view; - float output_scale = output->wlr_output->scale; + // Padding left of title + left_offset = (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS; + box.x = x + left_offset; + box.y = y + TITLEBAR_V_PADDING; + box.width = TITLEBAR_H_PADDING - left_offset; + box.height = config->font_height; + scale_box(&box, output_scale); + render_rect(output->wlr_output, output_damage, &box, color); - if (view->border_left) { - // Child border - left edge - memcpy(&color, colors->child_border, sizeof(float) * 4); - color[3] *= con->alpha; - box.x = con->x; - box.y = con->y + view->border_thickness * view->border_top; - box.width = view->border_thickness; - box.height = con->height - view->border_thickness - * (view->border_top + view->border_bottom); - scale_box(&box, output_scale); - render_rect(output->wlr_output, output_damage, &box, color); - } + // Padding right of marks + right_offset = (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS; + box.x = x + width - TITLEBAR_H_PADDING; + box.y = y + TITLEBAR_V_PADDING; + box.width = TITLEBAR_H_PADDING - right_offset; + box.height = config->font_height; + scale_box(&box, output_scale); + render_rect(output->wlr_output, output_damage, &box, color); - if (view->border_right) { - // Child border - right edge - if (con->parent->children->length == 1 - && con->parent->layout == L_HORIZ) { - memcpy(&color, colors->indicator, sizeof(float) * 4); - } else { - memcpy(&color, colors->child_border, sizeof(float) * 4); - } - color[3] *= con->alpha; - box.x = con->x + con->width - view->border_thickness; - box.y = con->y + view->border_thickness * view->border_top; - box.width = view->border_thickness; - box.height = con->height - view->border_thickness - * (view->border_top + view->border_bottom); + if (connects_sides) { + // Left pixel in line with bottom bar + box.x = x; + box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS; + box.width = view->border_thickness * view->border_left; + box.height = TITLEBAR_BORDER_THICKNESS; scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); - } - if (view->border_top) { - // Child border - top edge - memcpy(&color, colors->child_border, sizeof(float) * 4); - color[3] *= con->alpha; - box.x = con->x; - box.y = con->y; - box.width = con->width; - box.height = view->border_thickness; + // Right pixel in line with bottom bar + box.x = x + width - view->border_thickness * view->border_right; + box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS; + box.width = view->border_thickness * view->border_right; + box.height = TITLEBAR_BORDER_THICKNESS; scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); } +} - if (view->border_bottom) { - // Child border - bottom edge - if (con->parent->children->length == 1 - && con->parent->layout == L_VERT) { - memcpy(&color, colors->indicator, sizeof(float) * 4); - } else { - memcpy(&color, colors->child_border, sizeof(float) * 4); - } - color[3] *= con->alpha; - box.x = con->x; - box.y = con->y + con->height - view->border_thickness; - box.width = con->width; - box.height = view->border_thickness; - scale_box(&box, output_scale); - render_rect(output->wlr_output, output_damage, &box, color); +/** + * Render the top border line for a view using "border pixel". + */ +static void render_top_border(struct sway_output *output, + pixman_region32_t *output_damage, struct sway_container *con, + struct border_colors *colors) { + struct sway_view *view = con->sway_view; + if (!view->border_top) { + return; } + struct wlr_box box; + float color[4]; + float output_scale = output->wlr_output->scale; + + // Child border - top edge + memcpy(&color, colors->child_border, sizeof(float) * 4); + premultiply_alpha(color, con->alpha); + box.x = con->x; + box.y = con->y; + box.width = con->width; + box.height = view->border_thickness; + scale_box(&box, output_scale); + render_rect(output->wlr_output, output_damage, &box, color); } static void render_container(struct sway_output *output, @@ -558,33 +592,30 @@ static void render_container_simple(struct sway_output *output, struct sway_container *child = con->children->items[i]; if (child->type == C_VIEW) { - if (child->sway_view->border != B_NONE) { - struct border_colors *colors; - struct wlr_texture *title_texture; - struct wlr_texture *marks_texture; - if (focus == child || parent_focused) { - colors = &config->border_colors.focused; - title_texture = child->title_focused; - marks_texture = child->sway_view->marks_focused; - } else if (seat_get_focus_inactive(seat, con) == child) { - colors = &config->border_colors.focused_inactive; - title_texture = child->title_focused_inactive; - marks_texture = child->sway_view->marks_focused_inactive; - } else { - colors = &config->border_colors.unfocused; - title_texture = child->title_unfocused; - marks_texture = child->sway_view->marks_unfocused; - } - - if (child->sway_view->border == B_NORMAL) { - render_container_simple_border_normal(output, damage, - child, colors, title_texture, marks_texture); - } else { - render_container_simple_border_pixel(output, damage, child, - colors); - } + struct border_colors *colors; + struct wlr_texture *title_texture; + struct wlr_texture *marks_texture; + if (focus == child || parent_focused) { + colors = &config->border_colors.focused; + title_texture = child->title_focused; + marks_texture = child->sway_view->marks_focused; + } else if (seat_get_focus_inactive(seat, con) == child) { + colors = &config->border_colors.focused_inactive; + title_texture = child->title_focused_inactive; + marks_texture = child->sway_view->marks_focused_inactive; + } else { + colors = &config->border_colors.unfocused; + title_texture = child->title_unfocused; + marks_texture = child->sway_view->marks_unfocused; + } + + if (child->sway_view->border == B_NORMAL) { + render_titlebar(output, damage, child, child->x, child->y, + child->width, colors, title_texture, marks_texture); + } else { + render_top_border(output, damage, child, colors); } - render_view(child->sway_view, output, damage); + render_view(output, damage, child, colors); } else { render_container(output, damage, child, parent_focused || focus == child); @@ -596,16 +627,116 @@ static void render_container_simple(struct sway_output *output, * Render a container's children using the L_TABBED layout. */ static void render_container_tabbed(struct sway_output *output, - pixman_region32_t *damage, struct sway_container *con) { - // TODO + pixman_region32_t *damage, struct sway_container *con, + bool parent_focused) { + if (!con->children->length) { + return; + } + struct sway_seat *seat = input_manager_current_seat(input_manager); + struct sway_container *focus = seat_get_focus(seat); + struct sway_container *current = seat_get_active_child(seat, con); + struct border_colors *current_colors = NULL; + + // Render tabs + for (int i = 0; i < con->children->length; ++i) { + struct sway_container *child = con->children->items[i]; + struct border_colors *colors; + struct wlr_texture *title_texture; + struct wlr_texture *marks_texture; + struct sway_view *view = + child->type == C_VIEW ? child->sway_view : NULL; + + if (focus == child || parent_focused) { + colors = &config->border_colors.focused; + title_texture = child->title_focused; + marks_texture = view ? view->marks_focused : NULL; + } else if (child == current) { + colors = &config->border_colors.focused_inactive; + title_texture = child->title_focused_inactive; + marks_texture = view ? view->marks_focused : NULL; + } else { + colors = &config->border_colors.unfocused; + title_texture = child->title_unfocused; + marks_texture = view ? view->marks_unfocused : NULL; + } + + int tab_width = con->width / con->children->length; + int x = con->x + tab_width * i; + // Make last tab use the remaining width of the parent + if (i == con->children->length - 1) { + tab_width = con->width - tab_width * i; + } + + render_titlebar(output, damage, child, x, child->y, tab_width, colors, + title_texture, marks_texture); + + if (child == current) { + current_colors = colors; + } + } + + // Render surface and left/right/bottom borders + if (current->type == C_VIEW) { + render_view(output, damage, current, current_colors); + } else { + render_container(output, damage, current, + parent_focused || current == focus); + } } /** * Render a container's children using the L_STACKED layout. */ static void render_container_stacked(struct sway_output *output, - pixman_region32_t *damage, struct sway_container *con) { - // TODO + pixman_region32_t *damage, struct sway_container *con, + bool parent_focused) { + if (!con->children->length) { + return; + } + struct |
