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.
This commit is contained in:
Michael Stapelberg 2022-10-30 20:12:02 +01:00 committed by Michael Stapelberg
parent 62eb0033b1
commit c45342e74f
9 changed files with 41 additions and 8 deletions

View File

@ -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;

View File

@ -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,

View File

@ -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);
}
/*

View File

@ -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);

View File

@ -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;

View File

@ -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
->

View File

@ -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;
}

View File

@ -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);

View File

@ -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