Merge pull request #1745 from mh21/configurable-tray-padding

Configurable tray padding.
This commit is contained in:
Michael Stapelberg 2015-06-29 00:19:44 -07:00
commit a853a8ef75
11 changed files with 60 additions and 12 deletions

View File

@ -1351,6 +1351,23 @@ Note that you might not have a primary output configured yet. To do so, run:
xrandr --output <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> [px]
-------------------------
*Example*:
-------------------------
# Obey Fitts's law
tray_padding 0
-------------------------
=== Font
Specifies the font to be used in the bar. See <<fonts>>.

View File

@ -43,6 +43,7 @@ typedef struct config_t {
char *fontname;
i3String *separator_symbol;
char *tray_output;
int tray_padding;
int num_outputs;
char **outputs;

View File

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

View File

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

View File

@ -255,6 +255,9 @@ struct Barconfig {
* disables the tray (its 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! */

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -690,7 +690,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', 'font', 'separator_symbol', 'binding_mode_indicator', 'workspace_buttons', 'strip_workspace_numbers', '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', 'strip_workspace_numbers', 'verbose', 'colors', '}'
ERROR: CONFIG: (in file <stdin>)
ERROR: CONFIG: Line 1: bar {
ERROR: CONFIG: Line 2: output LVDS-1