diff --git a/CHANGELOG.md b/CHANGELOG.md index d1d54b6..82baa45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,11 +11,12 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Fixed a bug introduced in Big Sur where buffer reads were incorrect **Added** +- New `left|center|right` shell sections: display custom text based on shell pipelines - Option to turn focused window title display on or off (thanks [@Norviah](https://github.com/Norviah)!) - Option to turn the spaces indicator on or off - Option to turn the clock on or off - Option to turn the power indicator on or off -- New `left|center|right` shell sections: display custom text based on shell pipelines +- Option to set the padding between the first/last item and the left/right edge of the display ## [1.2.1](https://github.com/cmacrae/spacebar/releases/tag/v1.2.1) - 2020-11-18 diff --git a/README.md b/README.md index f5b3064..c0bae0a 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,8 @@ spacebar -m config title on spacebar -m config spaces on spacebar -m config clock on spacebar -m config power on +spacebar -m config padding_left 20 +spacebar -m config padding_right 20 spacebar -m config spacing_left 25 spacebar -m config spacing_right 15 spacebar -m config text_font "Helvetica Neue:Bold:12.0" @@ -115,6 +117,8 @@ If you're using the `services.spacebar` module from [nix-darwin](https://github. spaces = "on"; clock = "on"; power = "on"; + padding_left = 20; + padding_right = 20; spacing_left = 25; spacing_right = 15; text_font = ''"Helvetica Neue:Bold:12.0"''; diff --git a/doc/spacebar.1 b/doc/spacebar.1 index 1d5093a..c59dae9 100644 --- a/doc/spacebar.1 +++ b/doc/spacebar.1 @@ -104,6 +104,16 @@ Enable clock on the right of the bar. Enable power indicator on the right of the bar. .RE .sp +\fBpadding_left\fP [\fI\fP] +.RS 4 +Padding in pixels between the left edge of the display and the first item. +.RE +.sp +\fBpadding_right\fP [\fI\fP] +.RS 4 +Padding in pixels between the right edge of the display and the last item. +.RE +.sp \fBspacing_left\fP [\fI\fP] .RS 4 Spacing in pixels between the left space indicators. diff --git a/doc/spacebar.asciidoc b/doc/spacebar.asciidoc index b422307..0691fb4 100644 --- a/doc/spacebar.asciidoc +++ b/doc/spacebar.asciidoc @@ -80,6 +80,12 @@ Settings *power* ['']:: Enable power indicator on the right of the bar. +*padding_left* ['']:: + Padding in pixels between the left edge of the display and the first item. + +*padding_right* ['']:: + Padding in pixels between the right edge of the display and the last item. + *spacing_left* ['']:: Spacing in pixels between the left space indicators. diff --git a/examples/spacebarrc b/examples/spacebarrc index 96facaa..125516a 100755 --- a/examples/spacebarrc +++ b/examples/spacebarrc @@ -6,6 +6,8 @@ spacebar -m config title on spacebar -m config spaces on spacebar -m config clock on spacebar -m config power on +spacebar -m config padding_left 20 +spacebar -m config padding_right 20 spacebar -m config spacing_left 25 spacebar -m config spacing_right 15 spacebar -m config text_font "Helvetica Neue:Bold:12.0" diff --git a/src/bar.c b/src/bar.c index 8d2c970..35d6fe6 100644 --- a/src/bar.c +++ b/src/bar.c @@ -267,7 +267,7 @@ void bar_refresh(struct bar *bar) // BAR LEFT // - int bar_left_final_item_x = 20; + int bar_left_final_item_x = g_bar_manager.padding_left; if (g_bar_manager.spaces) { int space_count; uint64_t *space_list = display_space_list(bar->did, &space_count); @@ -323,7 +323,7 @@ void bar_refresh(struct bar *bar) // This is used to calculate overlap for the cetner bar. // It is updated to represent the X position of the first item, depending on what's displayed. - int bar_right_first_item_x = bar->frame.size.width - 20; + int bar_right_first_item_x = bar->frame.size.width - g_bar_manager.padding_right; if (g_bar_manager.clock) { time_t rawtime; time(&rawtime); diff --git a/src/bar_manager.c b/src/bar_manager.c index 5a081bc..da637db 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -294,6 +294,18 @@ void bar_manager_set_height(struct bar_manager *bar_manager, uint32_t height) bar_manager_resize(bar_manager); } +void bar_manager_set_padding_left(struct bar_manager *bar_manager, uint32_t padding) +{ + bar_manager->padding_left = padding; + bar_manager_refresh(bar_manager); +} + +void bar_manager_set_padding_right(struct bar_manager *bar_manager, uint32_t padding) +{ + bar_manager->padding_right = padding; + bar_manager_refresh(bar_manager); +} + void bar_manager_set_spacing_left(struct bar_manager *bar_manager, uint32_t spacing) { bar_manager->spacing_left = spacing; @@ -381,6 +393,8 @@ void bar_manager_init(struct bar_manager *bar_manager) bar_manager_set_spaces(bar_manager, true); bar_manager_set_clock(bar_manager, true); bar_manager_set_power(bar_manager, true); + bar_manager_set_padding_left(bar_manager, 20); + bar_manager_set_padding_right(bar_manager, 20); bar_manager_set_spacing_left(bar_manager, 25); bar_manager_set_spacing_right(bar_manager, 15); bar_manager_set_text_font(bar_manager, string_copy("Helvetica Neue:Regular:10.0")); diff --git a/src/bar_manager.h b/src/bar_manager.h index a33542c..b5d0cbf 100644 --- a/src/bar_manager.h +++ b/src/bar_manager.h @@ -19,6 +19,8 @@ struct bar_manager char *_right_shell_icon; char *position; uint32_t height; + uint32_t padding_left; + uint32_t padding_right; uint32_t spacing_left; uint32_t spacing_right; bool title; @@ -82,6 +84,8 @@ void bar_manager_set_spaces(struct bar_manager *bar_manager, bool value); void bar_manager_set_clock(struct bar_manager *bar_manager, bool value); void bar_manager_set_power(struct bar_manager *bar_manager, bool value); void bar_manager_set_height(struct bar_manager *bar_manager, uint32_t height); +void bar_manager_set_padding_left(struct bar_manager *bar_manager, uint32_t padding); +void bar_manager_set_padding_right(struct bar_manager *bar_manager, uint32_t padding); void bar_manager_set_spacing_left(struct bar_manager *bar_manager, uint32_t spacing); void bar_manager_set_spacing_right(struct bar_manager *bar_manager, uint32_t spacing); void bar_manager_set_left_shell(struct bar_manager *bar_manager, bool value); diff --git a/src/message.c b/src/message.c index 97798ba..94de7db 100644 --- a/src/message.c +++ b/src/message.c @@ -29,6 +29,8 @@ extern bool g_verbose; #define COMMAND_CONFIG_BAR_DND_ICON "dnd_icon" #define COMMAND_CONFIG_BAR_POSITION "position" #define COMMAND_CONFIG_BAR_HEIGHT "height" +#define COMMAND_CONFIG_BAR_PADDING_LEFT "padding_left" +#define COMMAND_CONFIG_BAR_PADDING_RIGHT "padding_right" #define COMMAND_CONFIG_BAR_SPACING_LEFT "spacing_left" #define COMMAND_CONFIG_BAR_SPACING_RIGHT "spacing_right" #define COMMAND_CONFIG_BAR_TITLE "title" @@ -313,6 +315,20 @@ static void handle_domain_config(FILE *rsp, struct token domain, char *message) } else { bar_manager_set_height(&g_bar_manager, atoi(token_to_string(token))); } + } else if (token_equals(command, COMMAND_CONFIG_BAR_PADDING_LEFT)) { + struct token token = get_token(&message); + if (!token_is_valid(token)) { + fprintf(rsp, "%"PRIu32"\n", g_bar_manager.padding_left ? g_bar_manager.padding_left : 0); + } else { + bar_manager_set_padding_left(&g_bar_manager, atoi(token_to_string(token))); + } + } else if (token_equals(command, COMMAND_CONFIG_BAR_PADDING_RIGHT)) { + struct token token = get_token(&message); + if (!token_is_valid(token)) { + fprintf(rsp, "%"PRIu32"\n", g_bar_manager.padding_right ? g_bar_manager.padding_right : 0); + } else { + bar_manager_set_padding_right(&g_bar_manager, atoi(token_to_string(token))); + } } else if (token_equals(command, COMMAND_CONFIG_BAR_SPACING_LEFT)) { struct token token = get_token(&message); if (!token_is_valid(token)) {