mirror of
https://github.com/swaywm/sway.git
synced 2026-04-29 06:46:22 -04:00
Add CSD to border modes
This commit is contained in:
parent
0bc9dc192f
commit
97c0a56ce3
11 changed files with 94 additions and 81 deletions
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
struct sway_server_decoration {
|
struct sway_server_decoration {
|
||||||
struct wlr_server_decoration *wlr_server_decoration;
|
struct wlr_server_decoration *wlr_server_decoration;
|
||||||
|
struct sway_view *view;
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
|
|
||||||
struct wl_listener destroy;
|
struct wl_listener destroy;
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ enum sway_container_border {
|
||||||
B_NONE,
|
B_NONE,
|
||||||
B_PIXEL,
|
B_PIXEL,
|
||||||
B_NORMAL,
|
B_NORMAL,
|
||||||
|
B_CSD,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sway_root;
|
struct sway_root;
|
||||||
|
|
@ -63,7 +64,6 @@ struct sway_container_state {
|
||||||
bool border_bottom;
|
bool border_bottom;
|
||||||
bool border_left;
|
bool border_left;
|
||||||
bool border_right;
|
bool border_right;
|
||||||
bool using_csd;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sway_container {
|
struct sway_container {
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ struct sway_view {
|
||||||
|
|
||||||
struct sway_container *container; // NULL if unmapped and transactions finished
|
struct sway_container *container; // NULL if unmapped and transactions finished
|
||||||
struct wlr_surface *surface; // NULL for unmapped views
|
struct wlr_surface *surface; // NULL for unmapped views
|
||||||
|
struct sway_server_decoration *decoration;
|
||||||
|
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
|
|
@ -81,7 +82,6 @@ struct sway_view {
|
||||||
bool border_bottom;
|
bool border_bottom;
|
||||||
bool border_left;
|
bool border_left;
|
||||||
bool border_right;
|
bool border_right;
|
||||||
bool using_csd;
|
|
||||||
|
|
||||||
struct timespec urgent;
|
struct timespec urgent;
|
||||||
bool allow_request_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_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_set_tiled(struct sway_view *view, bool tiled);
|
||||||
|
|
||||||
void view_close(struct sway_view *view);
|
void view_close(struct sway_view *view);
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,16 @@
|
||||||
#include "sway/tree/container.h"
|
#include "sway/tree/container.h"
|
||||||
#include "sway/tree/view.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 *cmd_border(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
if ((error = checkarg(argc, "border", EXPECTED_AT_LEAST, 1))) {
|
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;
|
struct sway_view *view = container->view;
|
||||||
|
|
||||||
if (strcmp(argv[0], "none") == 0) {
|
if (strcmp(argv[0], "none") == 0) {
|
||||||
view->border = B_NONE;
|
set_border(view, B_NONE);
|
||||||
} else if (strcmp(argv[0], "normal") == 0) {
|
} else if (strcmp(argv[0], "normal") == 0) {
|
||||||
view->border = B_NORMAL;
|
set_border(view, B_NORMAL);
|
||||||
} else if (strcmp(argv[0], "pixel") == 0) {
|
} 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) {
|
} else if (strcmp(argv[0], "toggle") == 0) {
|
||||||
view->border = (view->border + 1) % 3;
|
set_border(view, (view->border + 1) % 4);
|
||||||
} else {
|
} else {
|
||||||
return cmd_results_new(CMD_INVALID, "border",
|
return cmd_results_new(CMD_INVALID, "border",
|
||||||
"Expected 'border <none|normal|pixel|toggle>' "
|
"Expected 'border <none|normal|pixel|toggle>' "
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ static void server_decoration_handle_destroy(struct wl_listener *listener,
|
||||||
void *data) {
|
void *data) {
|
||||||
struct sway_server_decoration *deco =
|
struct sway_server_decoration *deco =
|
||||||
wl_container_of(listener, deco, destroy);
|
wl_container_of(listener, deco, destroy);
|
||||||
|
deco->view->decoration = NULL;
|
||||||
wl_list_remove(&deco->destroy.link);
|
wl_list_remove(&deco->destroy.link);
|
||||||
wl_list_remove(&deco->mode.link);
|
wl_list_remove(&deco->mode.link);
|
||||||
wl_list_remove(&deco->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->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);
|
wl_signal_add(&wlr_deco->events.destroy, &deco->destroy);
|
||||||
deco->destroy.notify = server_decoration_handle_destroy;
|
deco->destroy.notify = server_decoration_handle_destroy;
|
||||||
|
|
|
||||||
|
|
@ -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);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -281,7 +281,6 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
|
||||||
float color[4];
|
float color[4];
|
||||||
struct sway_container_state *state = &con->current;
|
struct sway_container_state *state = &con->current;
|
||||||
|
|
||||||
if (state->border != B_NONE) {
|
|
||||||
if (state->border_left) {
|
if (state->border_left) {
|
||||||
memcpy(&color, colors->child_border, sizeof(float) * 4);
|
memcpy(&color, colors->child_border, sizeof(float) * 4);
|
||||||
premultiply_alpha(color, con->alpha);
|
premultiply_alpha(color, con->alpha);
|
||||||
|
|
@ -326,7 +325,6 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
|
||||||
scale_box(&box, output_scale);
|
scale_box(&box, output_scale);
|
||||||
render_rect(output->wlr_output, damage, &box, color);
|
render_rect(output->wlr_output, damage, &box, color);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -645,15 +643,13 @@ static void render_containers_linear(struct sway_output *output,
|
||||||
marks_texture = view->marks_unfocused;
|
marks_texture = view->marks_unfocused;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!view->container->current.using_csd) {
|
|
||||||
if (state->border == B_NORMAL) {
|
if (state->border == B_NORMAL) {
|
||||||
render_titlebar(output, damage, child, state->con_x,
|
render_titlebar(output, damage, child, state->con_x,
|
||||||
state->con_y, state->con_width, colors,
|
state->con_y, state->con_width, colors,
|
||||||
title_texture, marks_texture);
|
title_texture, marks_texture);
|
||||||
} else {
|
} else if (state->border == B_PIXEL) {
|
||||||
render_top_border(output, damage, child, colors);
|
render_top_border(output, damage, child, colors);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
render_view(output, damage, child, colors);
|
render_view(output, damage, child, colors);
|
||||||
} else {
|
} else {
|
||||||
render_container(output, damage, child,
|
render_container(output, damage, child,
|
||||||
|
|
@ -859,15 +855,13 @@ static void render_floating_container(struct sway_output *soutput,
|
||||||
marks_texture = view->marks_unfocused;
|
marks_texture = view->marks_unfocused;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!view->container->current.using_csd) {
|
|
||||||
if (con->current.border == B_NORMAL) {
|
if (con->current.border == B_NORMAL) {
|
||||||
render_titlebar(soutput, damage, con, con->current.con_x,
|
render_titlebar(soutput, damage, con, con->current.con_x,
|
||||||
con->current.con_y, con->current.con_width, colors,
|
con->current.con_y, con->current.con_width, colors,
|
||||||
title_texture, marks_texture);
|
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_top_border(soutput, damage, con, colors);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
render_view(soutput, damage, con, colors);
|
render_view(soutput, damage, con, colors);
|
||||||
} else {
|
} else {
|
||||||
render_container(soutput, damage, con, con->current.focused);
|
render_container(soutput, damage, con, con->current.focused);
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,6 @@ static void copy_container_state(struct sway_container *container,
|
||||||
state->border_left = view->border_left;
|
state->border_left = view->border_left;
|
||||||
state->border_right = view->border_right;
|
state->border_right = view->border_right;
|
||||||
state->border_bottom = view->border_bottom;
|
state->border_bottom = view->border_bottom;
|
||||||
state->using_csd = view->using_csd;
|
|
||||||
} else {
|
} else {
|
||||||
state->children = create_list();
|
state->children = create_list();
|
||||||
list_cat(state->children, container->children);
|
list_cat(state->children, container->children);
|
||||||
|
|
|
||||||
|
|
@ -175,7 +175,8 @@ static enum wlr_edges find_edge(struct sway_container *cont,
|
||||||
return WLR_EDGE_NONE;
|
return WLR_EDGE_NONE;
|
||||||
}
|
}
|
||||||
struct sway_view *view = cont->view;
|
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;
|
return WLR_EDGE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -216,6 +216,8 @@ static const char *describe_container_border(enum sway_container_border border)
|
||||||
return "pixel";
|
return "pixel";
|
||||||
case B_NORMAL:
|
case B_NORMAL:
|
||||||
return "normal";
|
return "normal";
|
||||||
|
case B_CSD:
|
||||||
|
return "csd";
|
||||||
}
|
}
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -717,7 +717,7 @@ void container_set_geometry_from_floating_view(struct sway_container *con) {
|
||||||
size_t border_width = 0;
|
size_t border_width = 0;
|
||||||
size_t top = 0;
|
size_t top = 0;
|
||||||
|
|
||||||
if (!view->using_csd) {
|
if (view->border != B_CSD) {
|
||||||
border_width = view->border_thickness * (view->border != B_NONE);
|
border_width = view->border_thickness * (view->border != B_NONE);
|
||||||
top = view->border == B_NORMAL ?
|
top = view->border == B_NORMAL ?
|
||||||
container_titlebar_height() : border_width;
|
container_titlebar_height() : border_width;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include <wlr/render/wlr_renderer.h>
|
#include <wlr/render/wlr_renderer.h>
|
||||||
#include <wlr/types/wlr_buffer.h>
|
#include <wlr/types/wlr_buffer.h>
|
||||||
#include <wlr/types/wlr_output_layout.h>
|
#include <wlr/types/wlr_output_layout.h>
|
||||||
|
#include <wlr/types/wlr_server_decoration.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#ifdef HAVE_XWAYLAND
|
#ifdef HAVE_XWAYLAND
|
||||||
#include <wlr/xwayland.h>
|
#include <wlr/xwayland.h>
|
||||||
|
|
@ -13,6 +14,7 @@
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "sway/criteria.h"
|
#include "sway/criteria.h"
|
||||||
#include "sway/commands.h"
|
#include "sway/commands.h"
|
||||||
|
#include "sway/decoration.h"
|
||||||
#include "sway/desktop/transaction.h"
|
#include "sway/desktop/transaction.h"
|
||||||
#include "sway/input/cursor.h"
|
#include "sway/input/cursor.h"
|
||||||
#include "sway/ipc-server.h"
|
#include "sway/ipc-server.h"
|
||||||
|
|
@ -231,12 +233,8 @@ void view_autoconfigure(struct sway_view *view) {
|
||||||
view->border_top = false;
|
view->border_top = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum sway_container_border border = view->border;
|
switch (view->border) {
|
||||||
if (view->using_csd) {
|
case B_CSD:
|
||||||
border = B_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (border) {
|
|
||||||
case B_NONE:
|
case B_NONE:
|
||||||
x = con->x;
|
x = con->x;
|
||||||
y = con->y + y_offset;
|
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) {
|
void view_set_csd(struct sway_view *view, bool enabled) {
|
||||||
if (!tiled) {
|
if (view->decoration) {
|
||||||
view->using_csd = true;
|
uint32_t mode = enabled ? WLR_SERVER_DECORATION_MANAGER_MODE_CLIENT :
|
||||||
if (view->impl->has_client_side_decorations) {
|
WLR_SERVER_DECORATION_MANAGER_MODE_SERVER;
|
||||||
view->using_csd = view->impl->has_client_side_decorations(view);
|
wlr_log(WLR_INFO, "decoration mode %i", mode);
|
||||||
}
|
wlr_server_decoration_set_mode(
|
||||||
} else {
|
view->decoration->wlr_server_decoration, mode);
|
||||||
view->using_csd = false;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void view_set_tiled(struct sway_view *view, bool tiled) {
|
||||||
if (view->impl->set_tiled) {
|
if (view->impl->set_tiled) {
|
||||||
view->impl->set_tiled(view, tiled);
|
view->impl->set_tiled(view, tiled);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue