Skip to content

Commit f516dbf

Browse files
authored
Merge pull request #2286 from RyanDwyer/default-floating-border
Implement default_floating_border command and adjust CSD behaviour
2 parents db3a363 + 10fc7a5 commit f516dbf

File tree

7 files changed

+72
-21
lines changed

7 files changed

+72
-21
lines changed

include/sway/tree/view.h

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct sway_view {
6969
bool border_bottom;
7070
bool border_left;
7171
bool border_right;
72+
bool using_csd;
7273

7374
struct timespec urgent;
7475
bool allow_request_urgent;

sway/commands.c

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ static struct cmd_handler handlers[] = {
9898
{ "client.unfocused", cmd_client_unfocused },
9999
{ "client.urgent", cmd_client_urgent },
100100
{ "default_border", cmd_default_border },
101+
{ "default_floating_border", cmd_default_floating_border },
101102
{ "exec", cmd_exec },
102103
{ "exec_always", cmd_exec_always },
103104
{ "floating_maximum_size", cmd_floating_maximum_size },
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "log.h"
2+
#include "sway/commands.h"
3+
#include "sway/config.h"
4+
#include "sway/tree/container.h"
5+
6+
struct cmd_results *cmd_default_floating_border(int argc, char **argv) {
7+
struct cmd_results *error = NULL;
8+
if ((error = checkarg(argc, "default_floating_border",
9+
EXPECTED_AT_LEAST, 1))) {
10+
return error;
11+
}
12+
13+
if (strcmp(argv[0], "none") == 0) {
14+
config->floating_border = B_NONE;
15+
} else if (strcmp(argv[0], "normal") == 0) {
16+
config->floating_border = B_NORMAL;
17+
} else if (strcmp(argv[0], "pixel") == 0) {
18+
config->floating_border = B_PIXEL;
19+
} else {
20+
return cmd_results_new(CMD_INVALID, "default_floating_border",
21+
"Expected 'default_floating_border <none|normal|pixel>' "
22+
"or 'default_floating_border <normal|pixel> <px>'");
23+
}
24+
if (argc == 2) {
25+
config->floating_border_thickness = atoi(argv[1]);
26+
}
27+
28+
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
29+
}

sway/desktop/render.c

+20-12
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
256256
render_view_surfaces(view, output, damage, view->swayc->alpha);
257257
}
258258

259+
if (view->using_csd) {
260+
return;
261+
}
262+
259263
struct wlr_box box;
260264
float output_scale = output->wlr_output->scale;
261265
float color[4];
@@ -571,12 +575,14 @@ static void render_container_simple(struct sway_output *output,
571575
marks_texture = view->marks_unfocused;
572576
}
573577

574-
if (state->border == B_NORMAL) {
575-
render_titlebar(output, damage, child, state->swayc_x,
576-
state->swayc_y, state->swayc_width, colors,
577-
title_texture, marks_texture);
578-
} else {
579-
render_top_border(output, damage, child, colors);
578+
if (!view->using_csd) {
579+
if (state->border == B_NORMAL) {
580+
render_titlebar(output, damage, child, state->swayc_x,
581+
state->swayc_y, state->swayc_width, colors,
582+
title_texture, marks_texture);
583+
} else {
584+
render_top_border(output, damage, child, colors);
585+
}
580586
}
581587
render_view(output, damage, child, colors);
582588
} else {
@@ -761,12 +767,14 @@ static void render_floating_container(struct sway_output *soutput,
761767
marks_texture = view->marks_unfocused;
762768
}
763769

764-
if (con->current.border == B_NORMAL) {
765-
render_titlebar(soutput, damage, con, con->current.swayc_x,
766-
con->current.swayc_y, con->current.swayc_width, colors,
767-
title_texture, marks_texture);
768-
} else if (con->current.border != B_NONE) {
769-
render_top_border(soutput, damage, con, colors);
770+
if (!view->using_csd) {
771+
if (con->current.border == B_NORMAL) {
772+
render_titlebar(soutput, damage, con, con->current.swayc_x,
773+
con->current.swayc_y, con->current.swayc_width, colors,
774+
title_texture, marks_texture);
775+
} else if (con->current.border != B_NONE) {
776+
render_top_border(soutput, damage, con, colors);
777+
}
770778
}
771779
render_view(soutput, damage, con, colors);
772780
} else {

sway/meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ sway_sources = files(
3535
'commands/border.c',
3636
'commands/client.c',
3737
'commands/default_border.c',
38+
'commands/default_floating_border.c',
3839
'commands/default_orientation.c',
3940
'commands/exit.c',
4041
'commands/exec.c',

sway/tree/container.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -967,9 +967,14 @@ void container_set_geometry_from_floating_view(struct sway_container *con) {
967967
return;
968968
}
969969
struct sway_view *view = con->sway_view;
970-
size_t border_width = view->border_thickness * (view->border != B_NONE);
971-
size_t top =
972-
view->border == B_NORMAL ? container_titlebar_height() : border_width;
970+
size_t border_width = 0;
971+
size_t top = 0;
972+
973+
if (!view->using_csd) {
974+
border_width = view->border_thickness * (view->border != B_NONE);
975+
top = view->border == B_NORMAL ?
976+
container_titlebar_height() : border_width;
977+
}
973978

974979
con->x = view->x - border_width;
975980
con->y = view->y - top;

sway/tree/view.c

+12-6
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,15 @@ void view_set_activated(struct sway_view *view, bool activated) {
316316
}
317317

318318
void view_set_tiled(struct sway_view *view, bool tiled) {
319-
bool csd = true;
320-
if (view->impl->has_client_side_decorations) {
321-
csd = view->impl->has_client_side_decorations(view);
319+
if (!tiled) {
320+
view->using_csd = true;
321+
if (view->impl->has_client_side_decorations) {
322+
view->using_csd = view->impl->has_client_side_decorations(view);
323+
}
324+
} else {
325+
view->using_csd = false;
322326
}
323-
view->border = tiled || !csd ? config->border : B_NONE;
327+
324328
if (view->impl->set_tiled) {
325329
view->impl->set_tiled(view, tiled);
326330
}
@@ -573,8 +577,6 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
573577

574578
view->surface = wlr_surface;
575579
view->swayc = cont;
576-
view->border = config->border;
577-
view->border_thickness = config->border_thickness;
578580

579581
view_init_subsurfaces(view, wlr_surface);
580582
wl_signal_add(&wlr_surface->events.new_subsurface,
@@ -585,8 +587,12 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
585587
view->container_reparent.notify = view_handle_container_reparent;
586588

587589
if (view->impl->wants_floating && view->impl->wants_floating(view)) {
590+
view->border = config->floating_border;
591+
view->border_thickness = config->floating_border_thickness;
588592
container_set_floating(view->swayc, true);
589593
} else {
594+
view->border = config->border;
595+
view->border_thickness = config->border_thickness;
590596
view_set_tiled(view, true);
591597
}
592598

0 commit comments

Comments
 (0)