aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stapelberg <michael@stapelberg.de>2022-10-30 20:12:02 +0100
committerMichael Stapelberg <stapelberg@users.noreply.github.com>2022-10-30 22:22:08 +0100
commitc45342e74f1377d8fb85a0962c182f2c3e55108a (patch)
treed3a34efd316d531a1c6e5640a64c6414bbb8cfda
parent62eb0033b1313f58c8daa4c27821fb6cebf409de (diff)
downloadi3-c45342e74f1377d8fb85a0962c182f2c3e55108a.tar.gz
i3-c45342e74f1377d8fb85a0962c182f2c3e55108a.zip
Merge support for the bar { height } option as-is from i3-gaps
related to https://github.com/i3/i3/issues/3724 related to https://github.com/i3/i3/issues/3721 In a follow-up commit, we can evolve this into the padding directive as discussed on issue #3721.
-rw-r--r--i3bar/include/configuration.h1
-rw-r--r--i3bar/src/config.c8
-rw-r--r--i3bar/src/xcb.c20
-rw-r--r--include/config_directives.h1
-rw-r--r--include/configuration.h3
-rw-r--r--parser-specs/config.spec5
-rw-r--r--src/config_directives.c4
-rw-r--r--src/ipc.c5
-rw-r--r--testcases/t/201-config-parser.t2
9 files changed, 41 insertions, 8 deletions
diff --git a/i3bar/include/configuration.h b/i3bar/include/configuration.h
index e39fe99a..346d5b26 100644
--- a/i3bar/include/configuration.h
+++ b/i3bar/include/configuration.h
@@ -43,6 +43,7 @@ typedef struct config_t {
TAILQ_HEAD(bindings_head, binding_t) bindings;
position_t position;
bool verbose;
+ uint32_t bar_height;
bool transparency;
struct xcb_color_strings_t colors;
bool disable_binding_mode_indicator;
diff --git a/i3bar/src/config.c b/i3bar/src/config.c
index 14d54ed6..efc2f514 100644
--- a/i3bar/src/config.c
+++ b/i3bar/src/config.c
@@ -329,6 +329,12 @@ static int config_integer_cb(void *params_, long long val) {
return 0;
}
+ if (!strcmp(cur_key, "bar_height")) {
+ DLOG("bar_height = %lld", val);
+ config.bar_height = (uint32_t)val;
+ return 1;
+ }
+
if (!strcmp(cur_key, "tray_padding")) {
DLOG("tray_padding = %lld\n", val);
config.tray_padding = val;
@@ -353,8 +359,8 @@ static int config_integer_cb(void *params_, long long val) {
/* A datastructure to pass all these callbacks to yajl */
static yajl_callbacks outputs_callbacks = {
.yajl_null = config_null_cb,
- .yajl_boolean = config_boolean_cb,
.yajl_integer = config_integer_cb,
+ .yajl_boolean = config_boolean_cb,
.yajl_string = config_string_cb,
.yajl_end_array = config_end_array_cb,
.yajl_map_key = config_map_key_cb,
diff --git a/i3bar/src/xcb.c b/i3bar/src/xcb.c
index 1cfd457b..7010f90c 100644
--- a/i3bar/src/xcb.c
+++ b/i3bar/src/xcb.c
@@ -59,7 +59,7 @@ xcb_visualtype_t *visual_type;
uint8_t depth;
xcb_colormap_t colormap;
-/* Overall height of the bar (based on font size) */
+/* Overall height of the size */
int bar_height;
/* These are only relevant for XKB, which we only need for grabbing modifiers */
@@ -180,7 +180,7 @@ static void draw_separator(i3_output *output, uint32_t x, struct status_block *b
/* Draw a custom separator. */
uint32_t separator_x = MAX(x - block->sep_block_width, center_x - separator_symbol_width / 2);
draw_util_text(config.separator_symbol, &output->statusline_buffer, sep_fg, bar_bg,
- separator_x, logical_px(ws_voff_px), x - separator_x);
+ separator_x, bar_height / 2 - font.height / 2, x - separator_x);
}
}
@@ -1354,8 +1354,16 @@ void init_xcb_late(char *fontname) {
/* Load the font */
font = load_font(fontname, true);
set_font(&font);
- DLOG("Calculated font height: %d\n", font.height);
- bar_height = font.height + 2 * logical_px(ws_voff_px);
+ DLOG("Calculated font-height: %d\n", font.height);
+
+ /*
+ * If the bar height was explicitly set, use it. Otherwise, calculate it
+ * based on the font size.
+ */
+ if (config.bar_height <= 0)
+ bar_height = font.height + 2 * logical_px(ws_voff_px);
+ else
+ bar_height = config.bar_height;
icon_size = bar_height - 2 * logical_px(config.tray_padding);
if (config.separator_symbol)
@@ -1973,7 +1981,7 @@ void reconfig_windows(bool redraw_bars) {
*/
static void draw_button(surface_t *surface, color_t fg_color, color_t bg_color, color_t border_color,
int x, int width, int text_width, i3String *text) {
- int height = font.height + 2 * logical_px(ws_voff_px) - 2 * logical_px(1);
+ int height = bar_height - 2 * logical_px(1);
/* Draw the border of the button. */
draw_util_rectangle(surface, border_color, x, logical_px(1), width, height);
@@ -1983,7 +1991,7 @@ static void draw_button(surface_t *surface, color_t fg_color, color_t bg_color,
width - 2 * logical_px(1), height - 2 * logical_px(1));
draw_util_text(text, surface, fg_color, bg_color, x + (width - text_width) / 2,
- logical_px(ws_voff_px), text_width);
+ bar_height / 2 - font.height / 2, text_width);
}
/*
diff --git a/include/config_directives.h b/include/config_directives.h
index 015154d5..a1fc57be 100644
--- a/include/config_directives.h
+++ b/include/config_directives.h
@@ -85,6 +85,7 @@ CFGFUN(bar_hidden_state, const char *hidden_state);
CFGFUN(bar_id, const char *bar_id);
CFGFUN(bar_output, const char *output);
CFGFUN(bar_verbose, const char *verbose);
+CFGFUN(bar_height, const long height);
CFGFUN(bar_modifier, const char *modifiers);
CFGFUN(bar_wheel_up_cmd, const char *command);
CFGFUN(bar_wheel_down_cmd, const char *command);
diff --git a/include/configuration.h b/include/configuration.h
index 63d504de..b184a7b1 100644
--- a/include/configuration.h
+++ b/include/configuration.h
@@ -355,6 +355,9 @@ struct Barconfig {
/** Enable verbose mode? Useful for debugging purposes. */
bool verbose;
+ /** Defines the height of the bar in pixels. */
+ uint32_t bar_height;
+
struct bar_colors {
char *background;
char *statusline;
diff --git a/parser-specs/config.spec b/parser-specs/config.spec
index dfe8008d..846b6a26 100644
--- a/parser-specs/config.spec
+++ b/parser-specs/config.spec
@@ -510,6 +510,7 @@ state BAR:
'strip_workspace_numbers' -> BAR_STRIP_WORKSPACE_NUMBERS
'strip_workspace_name' -> BAR_STRIP_WORKSPACE_NAME
'verbose' -> BAR_VERBOSE
+ 'height' -> BAR_HEIGHT
'colors' -> BAR_COLORS_BRACE
'}'
-> call cfg_bar_finish(); INITIAL
@@ -633,6 +634,10 @@ state BAR_VERBOSE:
value = word
-> call cfg_bar_verbose($value); BAR
+state BAR_HEIGHT:
+ value = number
+ -> call cfg_bar_height(&value); BAR
+
state BAR_COLORS_BRACE:
end
->
diff --git a/src/config_directives.c b/src/config_directives.c
index 39fe7410..361399b9 100644
--- a/src/config_directives.c
+++ b/src/config_directives.c
@@ -613,6 +613,10 @@ CFGFUN(bar_verbose, const char *verbose) {
current_bar->verbose = boolstr(verbose);
}
+CFGFUN(bar_height, const long height) {
+ current_bar->bar_height = (uint32_t)height;
+}
+
CFGFUN(bar_modifier, const char *modifiers) {
current_bar->modifier = modifiers ? event_state_from_str(modifiers) : XCB_NONE;
}
diff --git a/src/ipc.c b/src/ipc.c
index 084d171e..fee012b0 100644
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -797,6 +797,11 @@ static void dump_bar_config(yajl_gen gen, Barconfig *config) {
YSTR_IF_SET(status_command);
YSTR_IF_SET(font);
+ if (config->bar_height) {
+ ystr("bar_height");
+ y(integer, config->bar_height);
+ }
+
if (config->separator_symbol) {
ystr("separator_symbol");
ystr(config->separator_symbol);
diff --git a/testcases/t/201-config-parser.t b/testcases/t/201-config-parser.t
index 11efdf84..7d81b17e 100644
--- a/testcases/t/201-config-parser.t
+++ b/testcases/t/201-config-parser.t
@@ -773,7 +773,7 @@ EOT
$expected = <<'EOT';
cfg_bar_start()
cfg_bar_output(LVDS-1)
-ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'i3bar_command', 'status_command', 'socket_path', 'mode', 'hidden_state', 'id', 'modifier', 'wheel_up_cmd', 'wheel_down_cmd', 'bindsym', 'position', 'output', 'tray_output', 'tray_padding', 'font', 'separator_symbol', 'binding_mode_indicator', 'workspace_buttons', 'workspace_min_width', 'strip_workspace_numbers', 'strip_workspace_name', 'verbose', 'colors', '}'
+ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'i3bar_command', 'status_command', 'socket_path', 'mode', 'hidden_state', 'id', 'modifier', 'wheel_up_cmd', 'wheel_down_cmd', 'bindsym', 'position', 'output', 'tray_output', 'tray_padding', 'font', 'separator_symbol', 'binding_mode_indicator', 'workspace_buttons', 'workspace_min_width', 'strip_workspace_numbers', 'strip_workspace_name', 'verbose', 'height', 'colors', '}'
ERROR: CONFIG: (in file <stdin>)
ERROR: CONFIG: Line 1: bar {
ERROR: CONFIG: Line 2: output LVDS-1