]> git.sur5r.net Git - i3/i3/commitdiff
Merge pull request #1745 from mh21/configurable-tray-padding
authorMichael Stapelberg <stapelberg@users.noreply.github.com>
Mon, 29 Jun 2015 07:19:44 +0000 (00:19 -0700)
committerMichael Stapelberg <stapelberg@users.noreply.github.com>
Mon, 29 Jun 2015 07:19:44 +0000 (00:19 -0700)
Configurable tray padding.

docs/userguide
i3bar/include/config.h
i3bar/src/config.c
i3bar/src/xcb.c
include/config.h
include/config_directives.h
parser-specs/config.spec
src/config_directives.c
src/ipc.c
testcases/t/177-bar-config.t
testcases/t/201-config-parser.t

index 11772b69afa2b3cd4da21cddeac63e6c09981b1c..e0d3883557169d366785b066abff38f106d69f93 100644 (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>>.
index d0291917f1e812c967fda03ec24df2e8baf26dd2..1ce5dfa6e4bebaaf930114d61081498a1f77ce55 100644 (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;
 
index a59dd5c1edfcf9bf3f400ee795588befe0f63a7a..65447e7ecaa14bf0f11af8d634f262261c29c28f 100644 (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;
 }
 
index 365ea3663438cefec11f4dd638f52a45c0c3febc..0b6abac68cb9031fc7a91dd0984e5fd8e69963dc 100644 (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);
index 9e881cc3e403947f2e675bb28073e2b300747dee..ff360bb5d126e348fa393abf428d415d21a83b36 100644 (file)
@@ -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! */
index a7da4914250dd1bbee771291fe7c7980c1552190..fc34a85f751e3862796915e9fc5462a7b5e12078 100644 (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);
index e0d422c8a2a85c4d92be11dd4c64299bf2d8438f..932be5fc600f7c635a0b18238231079b587414c7 100644 (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
index cf72a4db059110803abee390c751e1818b3f80f5..0e477b703928ba11d44631141406c1b718c4ba8e 100644 (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) {
index be6009788c47f9bfec06574ff94ff6eacd9d9d3c..9d3cf363085c7473585e40dcf24a04183d69276c 100644 (file)
--- 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");
index 4e7d988be8b6b4b6b093e57efb62646e3374b057..cc4826c15766be171d652b4a102e813001d52da6 100644 (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},
index faf2f0db7e907e7c1fcc76101044ef6cb23e7f29..fbcc586a5d0952cde9020d899b9c56d01e137909 100644 (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