From: Michael Hofmann Date: Tue, 9 Jun 2015 08:06:45 +0000 (+0200) Subject: Configurable tray padding. X-Git-Tag: 4.11~88^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=refs%2Fpull%2F1745%2Fhead;p=i3%2Fi3 Configurable tray padding. --- diff --git a/docs/userguide b/docs/userguide index 11772b69..e0d38835 100644 --- a/docs/userguide +++ b/docs/userguide @@ -1351,6 +1351,23 @@ Note that you might not have a primary output configured yet. To do so, run: xrandr --output --primary ------------------------- +=== Tray padding + +The tray is shown on the right-hand side of the bar. By default, a padding of 2 +pixels is used for the upper, lower and right-hand side of the tray area and +between the individual icons. + +*Syntax*: +------------------------- +tray_padding [px] +------------------------- + +*Example*: +------------------------- +# Obey Fitts's law +tray_padding 0 +------------------------- + === Font Specifies the font to be used in the bar. See <>. diff --git a/i3bar/include/config.h b/i3bar/include/config.h index d0291917..1ce5dfa6 100644 --- a/i3bar/include/config.h +++ b/i3bar/include/config.h @@ -43,6 +43,7 @@ typedef struct config_t { char *fontname; i3String *separator_symbol; char *tray_output; + int tray_padding; int num_outputs; char **outputs; diff --git a/i3bar/src/config.c b/i3bar/src/config.c index a59dd5c1..65447e7e 100644 --- a/i3bar/src/config.c +++ b/i3bar/src/config.c @@ -288,6 +288,12 @@ static int config_integer_cb(void *params_, long long val) { return 0; } + if (!strcmp(cur_key, "tray_padding")) { + DLOG("tray_padding = %lld\n", val); + config.tray_padding = val; + return 1; + } + return 0; } diff --git a/i3bar/src/xcb.c b/i3bar/src/xcb.c index 365ea366..0b6abac6 100644 --- a/i3bar/src/xcb.c +++ b/i3bar/src/xcb.c @@ -128,9 +128,6 @@ static const int sb_hoff_px = 4; /* Additional offset between the tray and the statusline, if the tray is not empty */ static const int tray_loff_px = 2; -/* Padding around the tray icons */ -static const int tray_spacing_px = 2; - /* Vertical offset between the bar and a separator */ static const int sep_voff_px = 4; @@ -157,7 +154,7 @@ int get_tray_width(struct tc_head *trayclients) { TAILQ_FOREACH_REVERSE(trayclient, trayclients, tc_head, tailq) { if (!trayclient->mapped) continue; - tray_width += icon_size + logical_px(tray_spacing_px); + tray_width += icon_size + logical_px(config.tray_padding); } if (tray_width > 0) tray_width += logical_px(tray_loff_px); @@ -607,8 +604,8 @@ static void configure_trayclients(void) { clients++; DLOG("Configuring tray window %08x to x=%d\n", - trayclient->win, output->rect.w - (clients * (icon_size + logical_px(tray_spacing_px)))); - uint32_t x = output->rect.w - (clients * (icon_size + logical_px(tray_spacing_px))); + trayclient->win, output->rect.w - (clients * (icon_size + logical_px(config.tray_padding)))); + uint32_t x = output->rect.w - (clients * (icon_size + logical_px(config.tray_padding))); xcb_configure_window(xcb_connection, trayclient->win, XCB_CONFIG_WINDOW_X, @@ -718,8 +715,8 @@ static void handle_client_message(xcb_client_message_event_t *event) { xcb_reparent_window(xcb_connection, client, output->bar, - output->rect.w - icon_size - logical_px(tray_spacing_px), - logical_px(tray_spacing_px)); + output->rect.w - icon_size - logical_px(config.tray_padding), + logical_px(config.tray_padding)); /* We reconfigure the window to use a reasonable size. The systray * specification explicitly says: * Tray icons may be assigned any size by the system tray, and @@ -957,8 +954,8 @@ static void handle_configure_request(xcb_configure_request_event_t *event) { continue; xcb_rectangle_t rect; - rect.x = output->rect.w - (clients * (icon_size + logical_px(tray_spacing_px))); - rect.y = logical_px(tray_spacing_px); + rect.x = output->rect.w - (clients * (icon_size + logical_px(config.tray_padding))); + rect.y = logical_px(config.tray_padding); rect.width = icon_size; rect.height = icon_size; @@ -1231,7 +1228,7 @@ void init_xcb_late(char *fontname) { set_font(&font); DLOG("Calculated font height: %d\n", font.height); bar_height = font.height + 2 * logical_px(ws_voff_px); - icon_size = bar_height - 2 * logical_px(tray_spacing_px); + icon_size = bar_height - 2 * logical_px(config.tray_padding); if (config.separator_symbol) separator_symbol_width = predict_text_width(config.separator_symbol); diff --git a/include/config.h b/include/config.h index 9e881cc3..ff360bb5 100644 --- a/include/config.h +++ b/include/config.h @@ -255,6 +255,9 @@ struct Barconfig { * disables the tray (it’s enabled by default). */ char *tray_output; + /* Padding around the tray icons. */ + int tray_padding; + /** Path to the i3 IPC socket. This option is discouraged since programs * can find out the path by looking for the I3_SOCKET_PATH property on the * root window! */ diff --git a/include/config_directives.h b/include/config_directives.h index a7da4914..fc34a85f 100644 --- a/include/config_directives.h +++ b/include/config_directives.h @@ -86,6 +86,7 @@ CFGFUN(bar_i3bar_command, const char *i3bar_command); CFGFUN(bar_color, const char *colorclass, const char *border, const char *background, const char *text); CFGFUN(bar_socket_path, const char *socket_path); CFGFUN(bar_tray_output, const char *output); +CFGFUN(bar_tray_padding, const long spacing_px); CFGFUN(bar_color_single, const char *colorclass, const char *color); CFGFUN(bar_status_command, const char *command); CFGFUN(bar_binding_mode_indicator, const char *value); diff --git a/parser-specs/config.spec b/parser-specs/config.spec index e0d422c8..932be5fc 100644 --- a/parser-specs/config.spec +++ b/parser-specs/config.spec @@ -413,6 +413,7 @@ state BAR: 'position' -> BAR_POSITION 'output' -> BAR_OUTPUT 'tray_output' -> BAR_TRAY_OUTPUT + 'tray_padding' -> BAR_TRAY_PADDING 'font' -> BAR_FONT 'separator_symbol' -> BAR_SEPARATOR_SYMBOL 'binding_mode_indicator' -> BAR_BINDING_MODE_INDICATOR @@ -484,6 +485,16 @@ state BAR_TRAY_OUTPUT: output = word -> call cfg_bar_tray_output($output); BAR +state BAR_TRAY_PADDING: + padding_px = number + -> BAR_TRAY_PADDING_PX + +state BAR_TRAY_PADDING_PX: + 'px' + -> + end + -> call cfg_bar_tray_padding(&padding_px); BAR + state BAR_FONT: font = string -> call cfg_bar_font($font); BAR diff --git a/src/config_directives.c b/src/config_directives.c index cf72a4db..0e477b70 100644 --- a/src/config_directives.c +++ b/src/config_directives.c @@ -615,6 +615,10 @@ CFGFUN(bar_tray_output, const char *output) { current_bar.tray_output = sstrdup(output); } +CFGFUN(bar_tray_padding, const long padding_px) { + current_bar.tray_padding = padding_px; +} + CFGFUN(bar_color_single, const char *colorclass, const char *color) { if (strcmp(colorclass, "background") == 0) current_bar.colors.background = sstrdup(color); @@ -643,6 +647,7 @@ CFGFUN(bar_strip_workspace_numbers, const char *value) { CFGFUN(bar_start) { TAILQ_INIT(&(current_bar.bar_bindings)); + current_bar.tray_padding = 2; } CFGFUN(bar_finish) { diff --git a/src/ipc.c b/src/ipc.c index be600978..9d3cf363 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -514,6 +514,10 @@ static void dump_bar_config(yajl_gen gen, Barconfig *config) { } while (0) YSTR_IF_SET(tray_output); + + ystr("tray_padding"); + y(integer, config->tray_padding); + YSTR_IF_SET(socket_path); ystr("mode"); diff --git a/testcases/t/177-bar-config.t b/testcases/t/177-bar-config.t index 4e7d988b..cc4826c1 100644 --- a/testcases/t/177-bar-config.t +++ b/testcases/t/177-bar-config.t @@ -66,6 +66,7 @@ ok($bar_config->{workspace_buttons}, 'workspace buttons enabled per default'); ok($bar_config->{binding_mode_indicator}, 'mode indicator enabled per default'); is($bar_config->{mode}, 'dock', 'dock mode by default'); is($bar_config->{position}, 'bottom', 'position bottom by default'); +is($bar_config->{tray_padding}, 2, 'tray_padding ok'); ##################################################################### # ensure that reloading cleans up the old bar configs @@ -96,6 +97,7 @@ bar { tray_output LVDS1 tray_output HDMI2 + tray_padding 0 position top mode dock font Terminus @@ -134,6 +136,7 @@ is($bar_config->{mode}, 'dock', 'dock mode'); is($bar_config->{position}, 'top', 'position top'); is_deeply($bar_config->{outputs}, [ 'HDMI1', 'HDMI2' ], 'outputs ok'); is($bar_config->{tray_output}, 'HDMI2', 'tray_output ok'); +is($bar_config->{tray_padding}, 0, 'tray_padding ok'); is($bar_config->{font}, 'Terminus', 'font ok'); is($bar_config->{socket_path}, '/tmp/foobar', 'socket_path ok'); is_deeply($bar_config->{colors}, diff --git a/testcases/t/201-config-parser.t b/testcases/t/201-config-parser.t index faf2f0db..fbcc586a 100644 --- a/testcases/t/201-config-parser.t +++ b/testcases/t/201-config-parser.t @@ -690,7 +690,7 @@ EOT $expected = <<'EOT'; cfg_bar_start() cfg_bar_output(LVDS-1) -ERROR: CONFIG: Expected one of these tokens: , '#', 'set', 'i3bar_command', 'status_command', 'socket_path', 'mode', 'hidden_state', 'id', 'modifier', 'wheel_up_cmd', 'wheel_down_cmd', 'bindsym', 'position', 'output', 'tray_output', 'font', 'separator_symbol', 'binding_mode_indicator', 'workspace_buttons', 'strip_workspace_numbers', 'verbose', 'colors', '}' +ERROR: CONFIG: Expected one of these tokens: , '#', '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', 'strip_workspace_numbers', 'verbose', 'colors', '}' ERROR: CONFIG: (in file ) ERROR: CONFIG: Line 1: bar { ERROR: CONFIG: Line 2: output LVDS-1