Skip to content

Commit

Permalink
feature: Implement 'height' config option
Browse files Browse the repository at this point in the history
  • Loading branch information
cmacrae committed Jul 17, 2020
1 parent d298631 commit 5ad8cea
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

[Unreleased]: https://github.com/cmacrae/spacebar/compare/master...HEAD

## [1.1.0](https://github.com/cmacrae/spacebar/releases/tag/v1.1.0) - 2020-07-17

**Added**
- Height configuration option

## [1.0.0](https://github.com/cmacrae/spacebar/releases/tag/v1.0.0) - 2020-07-16

**Added**
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<a href="https://builtwithnix.org">
<img src="https://img.shields.io/badge/Built_With-Nix-5277C3.svg?logo=nixos&labelColor=73C3D5" alt="Nix Badge">
</a>
<a href="https://github.com/cmacrae/spacebar/compare/v1.0.0...HEAD">
<a href="https://github.com/cmacrae/spacebar/compare/v1.1.0...HEAD">
<img src="https://img.shields.io/github/commits-since/cmacrae/spacebar/latest.svg?color=orange" alt="Version Badge">
</a>
</p>
Expand Down Expand Up @@ -62,6 +62,7 @@ Here's a configuration taken from [the examples directory](examples):
#!/usr/bin/env sh
spacebar -m config position top
spacebar -m config height 26
spacebar -m config text_font "Helvetica Neue:Bold:12.0"
spacebar -m config icon_font "Font Awesome 5 Free:Regular:12.0"
spacebar -m config background_color 0xff202020
Expand Down Expand Up @@ -92,6 +93,7 @@ If you're using the `services.spacebar` module from [nix-darwin](https://github.
services.spacebar.package = pkgs.spacebar;
services.spacebar.config = {
position = "top";
height = 26;
text_font = ''"Helvetica Neue:Bold:12.0"'';
icon_font = ''"Font Awesome 5 Free:Regular:12.0"'';
background_color = "0xff202020";
Expand Down Expand Up @@ -121,7 +123,13 @@ Take a look at this excerpt from the yabai man page
> off: Do not apply any special padding.

So, if you like having spacebar at the bottom, you'd use `yabai -m config external_bar all:0:26`
So, if you like having spacebar at the bottom, you'd use `yabai -m config external_bar all:0:26`

You can also use the command `spacebar -m config height` with no argument to get the current height, which you could then use in conjunction with `external_bar`:
```
SPACEBAR_HEIGHT=$(spacebar -m config height)
yabai -m config external_bar all:0:$SPACEBAR_HEIGHT
```

## Debug output and error reporting
In the case that something isn't working as you're expecting, please make sure to take a look in the output and error log. To enable debug output make sure that your configuration file contains `spacebar -m config debug_output on` or that spacebar is launched with the `--verbose` flag.
Expand Down
9 changes: 7 additions & 2 deletions doc/spacebar.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
.\" Title: spacebar
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.10
.\" Date: 2020-07-12
.\" Date: 2020-07-17
.\" Manual: Spacebar Manual
.\" Source: Spacebar
.\" Language: English
.\"
.TH "SPACEBAR" "1" "2020-07-12" "Spacebar" "Spacebar Manual"
.TH "SPACEBAR" "1" "2020-07-17" "Spacebar" "Spacebar Manual"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
Expand Down Expand Up @@ -77,6 +77,11 @@ Position on the screen to draw the bar.
Must be one of \fItop\fP or \fIbottom\fP.
.RE
.sp
\fBheight\fP [\fI<NUM>\fP]
.RS 4
Height in pixels to draw the bar.
.RE
.sp
\fBtext_font\fP [\fI<font_family>:<font_style>:<font_size>\fP]
.RS 4
Specify name, style and size of font to use for drawing text.
Expand Down
3 changes: 3 additions & 0 deletions doc/spacebar.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ Settings
Position on the screen to draw the bar. +
Must be one of 'top' or 'bottom'.

*height* ['<NUM>']::
Height in pixels to draw the bar.

*text_font* ['<font_family>:<font_style>:<font_size>']::
Specify name, style and size of font to use for drawing text. +
Use 'Font Book.app' to identify the correct name.
Expand Down
1 change: 1 addition & 0 deletions examples/spacebarrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env sh

spacebar -m config position top
spacebar -m config height 26
spacebar -m config text_font "Helvetica Neue:Bold:12.0"
spacebar -m config icon_font "Font Awesome 5 Free:Regular:12.0"
spacebar -m config background_color 0xff202020
Expand Down
4 changes: 2 additions & 2 deletions src/bar.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,10 @@ static CGPoint bar_create_frame(struct bar *bar, CFTypeRef *frame_region)
char *btm = "bottom";
CGFloat display_bottom = CGRectGetMaxY(bounds);
if (strcmp(g_bar_manager.position, btm) == 0) {
origin.y = display_bottom - 26;
origin.y = display_bottom - g_bar_manager.height;
}

bar->frame = (CGRect) {{0, 0},{bounds.size.width, 26}};
bar->frame = (CGRect) {{0, 0},{bounds.size.width, g_bar_manager.height}};
CGSNewRegionWithRect(&bar->frame, frame_region);

return origin;
Expand Down
7 changes: 7 additions & 0 deletions src/bar_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ void bar_manager_set_position(struct bar_manager *bar_manager, char *pos)
bar_manager_resize(bar_manager);
}

void bar_manager_set_height(struct bar_manager *bar_manager, uint32_t height)
{
bar_manager->height = height;
bar_manager_resize(bar_manager);
}

void bar_manager_display_changed(struct bar_manager *bar_manager)
{
for (int i = 0; i < bar_manager->bar_count; ++i)
Expand All @@ -239,6 +245,7 @@ void bar_manager_init(struct bar_manager *bar_manager)
bar_manager->bars = NULL;
bar_manager->bar_count = 0;
bar_manager_set_position(bar_manager, string_copy("top"));
bar_manager_set_height(bar_manager, 26);
bar_manager_set_text_font(bar_manager, string_copy("Helvetica Neue:Regular:10.0"));
bar_manager_set_icon_font(bar_manager, string_copy("Font Awesome 5 Free:Regular:10.0"));
bar_manager_set_background_color(bar_manager, 0xff202020);
Expand Down
2 changes: 2 additions & 0 deletions src/bar_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct bar_manager
char *_space_icon;
char *_dnd_icon;
char *position;
uint32_t height;
struct rgba_color foreground_color;
struct rgba_color background_color;
struct rgba_color space_icon_color;
Expand Down Expand Up @@ -48,6 +49,7 @@ void bar_manager_set_clock_format(struct bar_manager *bar_manager, char *format)
void bar_manager_set_space_icon(struct bar_manager *bar_manager, char *icon);
void bar_manager_set_dnd_icon(struct bar_manager *bar_manager, char *icon);
void bar_manager_set_position(struct bar_manager *bar_manager, char *pos);
void bar_manager_set_height(struct bar_manager *bar_manager, uint32_t height);

void bar_manager_display_changed(struct bar_manager *bar_manager);
void bar_manager_refresh(struct bar_manager *bar_manager);
Expand Down
8 changes: 8 additions & 0 deletions src/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extern bool g_verbose;
#define COMMAND_CONFIG_BAR_CLOCK_FORMAT "clock_format"
#define COMMAND_CONFIG_BAR_DND_ICON "dnd_icon"
#define COMMAND_CONFIG_BAR_POSITION "position"
#define COMMAND_CONFIG_BAR_HEIGHT "height"

/* --------------------------------COMMON ARGUMENTS----------------------------- */
#define ARGUMENT_COMMON_VAL_ON "on"
Expand Down Expand Up @@ -280,6 +281,13 @@ static void handle_domain_config(FILE *rsp, struct token domain, char *message)
} else {
daemon_fail(rsp, "value for '%.*s' must be either 'top' or 'bottom'.\n", command.length, command.text);
}
} else if (token_equals(command, COMMAND_CONFIG_BAR_HEIGHT)) {
struct token token = get_token(&message);
if (!token_is_valid(token)) {
fprintf(rsp, "%"PRIu32"\n", g_bar_manager.height ? g_bar_manager.height : 0);
} else {
bar_manager_set_height(&g_bar_manager, atoi(token_to_string(token)));
}
} else {
daemon_fail(rsp, "unknown command '%.*s' for domain '%.*s'\n", command.length, command.text, domain.length, domain.text);
}
Expand Down
2 changes: 1 addition & 1 deletion src/spacebar.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define CONFIG_OPT_SHRT "-c"

#define MAJOR 1
#define MINOR 0
#define MINOR 1
#define PATCH 0

extern int SLSMainConnectionID(void);
Expand Down

0 comments on commit 5ad8cea

Please sign in to comment.