Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change border size around workspaces (swaybar) #324

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/sway/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ sway_cmd cmd_xwayland;
sway_cmd bar_cmd_bindcode;
sway_cmd bar_cmd_binding_mode_indicator;
sway_cmd bar_cmd_bindsym;
sway_cmd bar_cmd_border_size;
sway_cmd bar_cmd_colors;
sway_cmd bar_cmd_font;
sway_cmd bar_cmd_gaps;
Expand Down
1 change: 1 addition & 0 deletions include/sway/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ struct bar_config {
enum pango_markup_config pango_markup;
char *font;
int height; // -1 not defined
int border_size;
bool workspace_buttons;
bool wrap_scroll;
char *separator_symbol;
Expand Down
1 change: 1 addition & 0 deletions include/swaybar/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct swaybar_config {
list_t *bindings;
struct wl_list outputs; // config_output::link
int height;
int border_size;
int status_padding;
int status_edge_padding;
struct {
Expand Down
1 change: 1 addition & 0 deletions sway/commands/bar.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ static const struct cmd_handler bar_handlers[] = {
{ "bindcode", bar_cmd_bindcode },
{ "binding_mode_indicator", bar_cmd_binding_mode_indicator },
{ "bindsym", bar_cmd_bindsym },
{ "border_size", bar_cmd_border_size },
{ "colors", bar_cmd_colors },
{ "font", bar_cmd_font },
{ "gaps", bar_cmd_gaps },
Expand Down
20 changes: 20 additions & 0 deletions sway/commands/bar/border_size.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdlib.h>
#include <string.h>
#include "sway/commands.h"
#include "log.h"

struct cmd_results *bar_cmd_border_size(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "border_size", EXPECTED_EQUAL_TO, 1))) {
return error;
}
int border_size = atoi(argv[0]);
if (border_size < 0) {
return cmd_results_new(CMD_INVALID,
"Invalid border_size value: %s", argv[0]);
}
config->current_bar->border_size = border_size;
sway_log(SWAY_DEBUG, "Setting bar border_size to %d on bar: %s",
border_size, config->current_bar->id);
return cmd_results_new(CMD_SUCCESS, NULL);
}
1 change: 1 addition & 0 deletions sway/config/bar.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ struct bar_config *default_bar_config(void) {
bar->swaybar_command = NULL;
bar->font = NULL;
bar->height = 0;
bar->border_size = 1;
bar->workspace_buttons = true;
bar->wrap_scroll = false;
bar->separator_symbol = NULL;
Expand Down
2 changes: 2 additions & 0 deletions sway/ipc-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,8 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) {
}
json_object_object_add(json, "bar_height",
json_object_new_int(bar->height));
json_object_object_add(json, "border_size",
json_object_new_int(bar->border_size));
json_object_object_add(json, "status_padding",
json_object_new_int(bar->status_padding));
json_object_object_add(json, "status_edge_padding",
Expand Down
1 change: 1 addition & 0 deletions sway/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ sway_sources = files(
'commands/bar/colors.c',
'commands/bar/font.c',
'commands/bar/gaps.c',
'commands/bar/border_size.c',
'commands/bar/height.c',
'commands/bar/hidden_state.c',
'commands/bar/icon_theme.c',
Expand Down
3 changes: 3 additions & 0 deletions sway/sway-bar.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ runtime.
*height* <height>
Sets the height of the bar. Default height (0) will match the font size.

*border_size* <size>
Sets the size of the border around the workspaces. Default is 1

*hidden_state* hide|show [<bar-id>]
Specifies the behaviour of the bar when it is in _hide_ mode. When the
hidden state is _hide_, then it is normally hidden, and only unhidden by
Expand Down
2 changes: 2 additions & 0 deletions swaybar/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ struct swaybar_config *init_config(void) {

/* height */
config->height = 0;
/* border */
config->border_size = 1;

/* gaps */
config->gaps.top = 0;
Expand Down
5 changes: 5 additions & 0 deletions swaybar/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ static bool ipc_parse_config(
config->height = json_object_get_int(bar_height);
}

json_object *border_size = json_object_object_get(bar_config, "border_size");
if (border_size) {
config->border_size = json_object_get_int(border_size);
}

json_object *binding_mode_indicator =
json_object_object_get(bar_config, "binding_mode_indicator");
if (binding_mode_indicator) {
Expand Down
9 changes: 4 additions & 5 deletions swaybar/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

static const int WS_HORIZONTAL_PADDING = 5;
static const double WS_VERTICAL_PADDING = 1.5;
static const double BORDER_WIDTH = 1;

struct render_context {
cairo_t *cairo;
Expand Down Expand Up @@ -431,7 +430,7 @@ static uint32_t predict_workspace_button_length(cairo_t *cairo,

int ws_vertical_padding = WS_VERTICAL_PADDING;
int ws_horizontal_padding = WS_HORIZONTAL_PADDING;
int border_width = BORDER_WIDTH;
int border_width = config->border_size;

uint32_t ideal_height = ws_vertical_padding * 2 + text_height
+ border_width * 2;
Expand Down Expand Up @@ -480,7 +479,7 @@ static uint32_t predict_binding_mode_indicator_length(cairo_t *cairo,

int ws_vertical_padding = WS_VERTICAL_PADDING;
int ws_horizontal_padding = WS_HORIZONTAL_PADDING;
int border_width = BORDER_WIDTH;
int border_width = config->border_size;

uint32_t ideal_height = text_height + ws_vertical_padding * 2
+ border_width * 2;
Expand Down Expand Up @@ -557,7 +556,7 @@ static uint32_t render_binding_mode_indicator(struct render_context *ctx,

int ws_vertical_padding = WS_VERTICAL_PADDING;
int ws_horizontal_padding = WS_HORIZONTAL_PADDING;
int border_width = BORDER_WIDTH;
int border_width = config->border_size;

uint32_t ideal_height = text_height + ws_vertical_padding * 2
+ border_width * 2;
Expand Down Expand Up @@ -636,7 +635,7 @@ static uint32_t render_workspace_button(struct render_context *ctx,

int ws_vertical_padding = WS_VERTICAL_PADDING;
int ws_horizontal_padding = WS_HORIZONTAL_PADDING;
int border_width = BORDER_WIDTH;
int border_width = config->border_size;

uint32_t ideal_height = ws_vertical_padding * 2 + text_height
+ border_width * 2;
Expand Down