This commit is contained in:
Ryan Dwyer 2018-09-24 09:37:33 +00:00 committed by GitHub
commit fb8dfd00a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 94 additions and 81 deletions

View file

@ -5,6 +5,7 @@
struct sway_server_decoration {
struct wlr_server_decoration *wlr_server_decoration;
struct sway_view *view;
struct wl_list link;
struct wl_listener destroy;

View file

@ -28,6 +28,7 @@ enum sway_container_border {
B_NONE,
B_PIXEL,
B_NORMAL,
B_CSD,
};
struct sway_root;
@ -63,7 +64,6 @@ struct sway_container_state {
bool border_bottom;
bool border_left;
bool border_right;
bool using_csd;
};
struct sway_container {

View file

@ -60,6 +60,7 @@ struct sway_view {
struct sway_container *container; // NULL if unmapped and transactions finished
struct wlr_surface *surface; // NULL for unmapped views
struct sway_server_decoration *decoration;
pid_t pid;
@ -81,7 +82,6 @@ struct sway_view {
bool border_bottom;
bool border_left;
bool border_right;
bool using_csd;
struct timespec urgent;
bool allow_request_urgent;
@ -268,6 +268,8 @@ void view_set_activated(struct sway_view *view, bool activated);
*/
void view_request_activate(struct sway_view *view);
void view_set_csd(struct sway_view *view, bool enabled);
void view_set_tiled(struct sway_view *view, bool tiled);
void view_close(struct sway_view *view);

View file

@ -7,6 +7,16 @@
#include "sway/tree/container.h"
#include "sway/tree/view.h"
static void set_border(struct sway_view *view,
enum sway_container_border new_border) {
if (view->border == B_CSD && new_border != B_CSD) {
view_set_csd(view, false);
} else if (view->border != B_CSD && new_border == B_CSD) {
view_set_csd(view, true);
}
view->border = new_border;
}
struct cmd_results *cmd_border(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "border", EXPECTED_AT_LEAST, 1))) {
@ -21,13 +31,15 @@ struct cmd_results *cmd_border(int argc, char **argv) {
struct sway_view *view = container->view;
if (strcmp(argv[0], "none") == 0) {
view->border = B_NONE;
set_border(view, B_NONE);
} else if (strcmp(argv[0], "normal") == 0) {
view->border = B_NORMAL;
set_border(view, B_NORMAL);
} else if (strcmp(argv[0], "pixel") == 0) {
view->border = B_PIXEL;
set_border(view, B_PIXEL);
} else if (strcmp(argv[0], "csd") == 0) {
set_border(view, B_CSD);
} else if (strcmp(argv[0], "toggle") == 0) {
view->border = (view->border + 1) % 3;
set_border(view, (view->border + 1) % 4);
} else {
return cmd_results_new(CMD_INVALID, "border",
"Expected 'border <none|normal|pixel|toggle>' "

View file

@ -8,6 +8,7 @@ static void server_decoration_handle_destroy(struct wl_listener *listener,
void *data) {
struct sway_server_decoration *deco =
wl_container_of(listener, deco, destroy);
deco->view->decoration = NULL;
wl_list_remove(&deco->destroy.link);
wl_list_remove(&deco->mode.link);
wl_list_remove(&deco->link);
@ -49,6 +50,8 @@ void handle_server_decoration(struct wl_listener *listener, void *data) {
}
deco->wlr_server_decoration = wlr_deco;
deco->view = view_from_wlr_surface(wlr_deco->surface);
deco->view->decoration = deco;
wl_signal_add(&wlr_deco->events.destroy, &deco->destroy);
deco->destroy.notify = server_decoration_handle_destroy;

View file

@ -272,7 +272,7 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
render_view_toplevels(view, output, damage, view->container->alpha);
}
if (view->container->current.using_csd) {
if (con->current.border == B_NONE || con->current.border == B_CSD) {
return;
}
@ -281,7 +281,6 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
float color[4];
struct sway_container_state *state = &con->current;
if (state->border != B_NONE) {
if (state->border_left) {
memcpy(&color, colors->child_border, sizeof(float) * 4);
premultiply_alpha(color, con->alpha);
@ -327,7 +326,6 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
render_rect(output->wlr_output, damage, &box, color);
}
}
}
/**
* Render a titlebar.
@ -645,15 +643,13 @@ static void render_containers_linear(struct sway_output *output,
marks_texture = view->marks_unfocused;
}
if (!view->container->current.using_csd) {
if (state->border == B_NORMAL) {
render_titlebar(output, damage, child, state->con_x,
state->con_y, state->con_width, colors,
title_texture, marks_texture);
} else {
} else if (state->border == B_PIXEL) {
render_top_border(output, damage, child, colors);
}
}
render_view(output, damage, child, colors);
} else {
render_container(output, damage, child,
@ -859,15 +855,13 @@ static void render_floating_container(struct sway_output *soutput,
marks_texture = view->marks_unfocused;
}
if (!view->container->current.using_csd) {
if (con->current.border == B_NORMAL) {
render_titlebar(soutput, damage, con, con->current.con_x,
con->current.con_y, con->current.con_width, colors,
title_texture, marks_texture);
} else if (con->current.border != B_NONE) {
} else if (con->current.border == B_PIXEL) {
render_top_border(soutput, damage, con, colors);
}
}
render_view(soutput, damage, con, colors);
} else {
render_container(soutput, damage, con, con->current.focused);

View file

@ -167,7 +167,6 @@ static void copy_container_state(struct sway_container *container,
state->border_left = view->border_left;
state->border_right = view->border_right;
state->border_bottom = view->border_bottom;
state->using_csd = view->using_csd;
} else {
state->children = create_list();
list_cat(state->children, container->children);

View file

@ -175,7 +175,8 @@ static enum wlr_edges find_edge(struct sway_container *cont,
return WLR_EDGE_NONE;
}
struct sway_view *view = cont->view;
if (view->border == B_NONE || !view->border_thickness || view->using_csd) {
if (view->border == B_NONE || !view->border_thickness ||
view->border == B_CSD) {
return WLR_EDGE_NONE;
}

View file

@ -216,6 +216,8 @@ static const char *describe_container_border(enum sway_container_border border)
return "pixel";
case B_NORMAL:
return "normal";
case B_CSD:
return "csd";
}
return "unknown";
}

View file

@ -717,7 +717,7 @@ void container_set_geometry_from_floating_view(struct sway_container *con) {
size_t border_width = 0;
size_t top = 0;
if (!view->using_csd) {
if (view->border != B_CSD) {
border_width = view->border_thickness * (view->border != B_NONE);
top = view->border == B_NORMAL ?
container_titlebar_height() : border_width;

View file

@ -5,6 +5,7 @@
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_buffer.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_server_decoration.h>
#include "config.h"
#ifdef HAVE_XWAYLAND
#include <wlr/xwayland.h>
@ -13,6 +14,7 @@
#include "log.h"
#include "sway/criteria.h"
#include "sway/commands.h"
#include "sway/decoration.h"
#include "sway/desktop/transaction.h"
#include "sway/input/cursor.h"
#include "sway/ipc-server.h"
@ -231,12 +233,8 @@ void view_autoconfigure(struct sway_view *view) {
view->border_top = false;
}
enum sway_container_border border = view->border;
if (view->using_csd) {
border = B_NONE;
}
switch (border) {
switch (view->border) {
case B_CSD:
case B_NONE:
x = con->x;
y = con->y + y_offset;
@ -309,16 +307,17 @@ void view_request_activate(struct sway_view *view) {
}
}
void view_set_tiled(struct sway_view *view, bool tiled) {
if (!tiled) {
view->using_csd = true;
if (view->impl->has_client_side_decorations) {
view->using_csd = view->impl->has_client_side_decorations(view);
void view_set_csd(struct sway_view *view, bool enabled) {
if (view->decoration) {
uint32_t mode = enabled ? WLR_SERVER_DECORATION_MANAGER_MODE_CLIENT :
WLR_SERVER_DECORATION_MANAGER_MODE_SERVER;
wlr_log(WLR_INFO, "decoration mode %i", mode);
wlr_server_decoration_set_mode(
view->decoration->wlr_server_decoration, mode);
}
} else {
view->using_csd = false;
}
void view_set_tiled(struct sway_view *view, bool tiled) {
if (view->impl->set_tiled) {
view->impl->set_tiled(view, tiled);
}