]> git.sur5r.net Git - i3/i3/commitdiff
Add new bar.binding_mode_indicator configuration.
authorsyl20bnr <sylvain.benner@gmail.com>
Fri, 9 Aug 2013 03:30:14 +0000 (23:30 -0400)
committerMichael Stapelberg <michael@stapelberg.de>
Tue, 24 Sep 2013 04:59:26 +0000 (06:59 +0200)
i3 current behavior hides the binding mode indicator when
workspace buttons are disabled.
This patch adds a new configuration for i3bar called
'binding_mode_indicator' which acts like the workspace_buttons.
It is now possible to configure i3bar to hide the
workspace buttons and keep showing the binding mode indicator.
This should make the hide workspace buttons configuration
more convenient for those who are heavily using binding
modes.
Default value for binding_mode_indicator is true.

12 files changed:
docs/ipc
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 913899cc8a7955ba08b6d9ff48d6ee74474ff01e..85e5e77e3e7966122f2835c716ac31d07ee35aef 100644 (file)
--- a/docs/ipc
+++ b/docs/ipc
@@ -494,6 +494,8 @@ font (string)::
        The font to use for text on the bar.
 workspace_buttons (boolean)::
        Display workspace buttons or not? Defaults to true.
+binding_mode_indicator (boolean)::
+       Display the mode indicator or not? Defaults to true.
 verbose (boolean)::
        Should the bar enable verbose output for debugging? Defaults to false.
 colors (map)::
@@ -539,6 +541,7 @@ urgent_workspace_text/urgent_workspace_bar::
  "status_command": "i3status",
  "font": "-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1",
  "workspace_buttons": true,
+ "binding_mode_indicator": true,
  "verbose": false,
  "colors": {
    "background": "#c0c0c0",
index ae3bda2e9068cc19141a2dffcaea2374ea6eed7c..0cc147cae847e513c0fbf0f84f2841d53b509656 100644 (file)
@@ -1180,11 +1180,32 @@ workspace_buttons <yes|no>
 --------------------------
 
 *Example*:
---------------------
+------------------------
 bar {
     workspace_buttons no
 }
---------------------
+------------------------
+
+=== Binding Mode indicator
+
+Specifies whether the current binding mode indicator should be shown or not.
+This is useful if you want to hide the workspace buttons but still be able
+to see the current binding mode indicator.
+For an example of a +mode+ definition, see <<resizingconfig>>.
+
+The default is to show the mode indicator.
+
+*Syntax*:
+-------------------------------
+binding_mode_indicator <yes|no>
+-------------------------------
+
+*Example*:
+-----------------------------
+bar {
+    binding_mode_indicator no
+}
+-----------------------------
 
 === Colors
 
index 4c01d68cec4d8aeb03be106081dd4f9576f034ab..c648671259e3c1d8d9ddeeaed81ed75fce967f82 100644 (file)
@@ -23,7 +23,8 @@ typedef struct config_t {
     position_t   position;
     int          verbose;
     struct xcb_color_strings_t colors;
-    int          disable_ws;
+    bool         disable_binding_mode_indicator;
+    bool         disable_ws;
     char         *bar_id;
     char         *command;
     char         *fontname;
index f5a2a342f48d756adca0ac79a238addac134fc7e..5ac31b1f3a16d53a3a2d2488377b7b22374c62fd 100644 (file)
@@ -193,6 +193,12 @@ static int config_string_cb(void *params_, const unsigned char *val, unsigned in
  *
  */
 static int config_boolean_cb(void *params_, int val) {
+    if (!strcmp(cur_key, "binding_mode_indicator")) {
+        DLOG("binding_mode_indicator = %d\n", val);
+        config.disable_binding_mode_indicator = !val;
+        return 1;
+    }
+
     if (!strcmp(cur_key, "workspace_buttons")) {
         DLOG("workspace_buttons = %d\n", val);
         config.disable_ws = !val;
index 36c2e470c3d86dac2d5a7f657152f6c2fa6b4aa4..f407c9b1fc2741f27cb31cb319b62c1260ecc583 100644 (file)
@@ -1670,72 +1670,71 @@ void draw_bars(bool unhide) {
                           MIN(outputs_walk->rect.w - traypx - 4, statusline_width), font.height + 2);
         }
 
-        if (config.disable_ws) {
-            continue;
-        }
-
-        i3_ws *ws_walk;
-
-        TAILQ_FOREACH(ws_walk, outputs_walk->workspaces, tailq) {
-            DLOG("Drawing Button for WS %s at x = %d, len = %d\n", i3string_as_utf8(ws_walk->name), i, ws_walk->name_width);
-            uint32_t fg_color = colors.inactive_ws_fg;
-            uint32_t bg_color = colors.inactive_ws_bg;
-            uint32_t border_color = colors.inactive_ws_border;
-            if (ws_walk->visible) {
-                if (!ws_walk->focused) {
-                    fg_color = colors.active_ws_fg;
-                    bg_color = colors.active_ws_bg;
-                    border_color = colors.active_ws_border;
-                } else {
-                    fg_color = colors.focus_ws_fg;
-                    bg_color = colors.focus_ws_bg;
-                    border_color = colors.focus_ws_border;
-                    if (last_urgent_ws && strcmp(i3string_as_utf8(ws_walk->name), last_urgent_ws) == 0)
-                        walks_away = false;
+        if (!config.disable_ws) {
+            i3_ws *ws_walk;
+            TAILQ_FOREACH(ws_walk, outputs_walk->workspaces, tailq) {
+                DLOG("Drawing Button for WS %s at x = %d, len = %d\n",
+                     i3string_as_utf8(ws_walk->name), i, ws_walk->name_width);
+                uint32_t fg_color = colors.inactive_ws_fg;
+                uint32_t bg_color = colors.inactive_ws_bg;
+                uint32_t border_color = colors.inactive_ws_border;
+                if (ws_walk->visible) {
+                    if (!ws_walk->focused) {
+                        fg_color = colors.active_ws_fg;
+                        bg_color = colors.active_ws_bg;
+                        border_color = colors.active_ws_border;
+                    } else {
+                        fg_color = colors.focus_ws_fg;
+                        bg_color = colors.focus_ws_bg;
+                        border_color = colors.focus_ws_border;
+                        if (last_urgent_ws && strcmp(i3string_as_utf8(ws_walk->name),
+                                                     last_urgent_ws) == 0)
+                            walks_away = false;
+                    }
                 }
-            }
-            if (ws_walk->urgent) {
-                DLOG("WS %s is urgent!\n", i3string_as_utf8(ws_walk->name));
-                fg_color = colors.urgent_ws_fg;
-                bg_color = colors.urgent_ws_bg;
-                border_color = colors.urgent_ws_border;
-                unhide = true;
-                if (!ws_walk->focused) {
-                    FREE(last_urgent_ws);
-                    last_urgent_ws = sstrdup(i3string_as_utf8(ws_walk->name));
+                if (ws_walk->urgent) {
+                    DLOG("WS %s is urgent!\n", i3string_as_utf8(ws_walk->name));
+                    fg_color = colors.urgent_ws_fg;
+                    bg_color = colors.urgent_ws_bg;
+                    border_color = colors.urgent_ws_border;
+                    unhide = true;
+                    if (!ws_walk->focused) {
+                        FREE(last_urgent_ws);
+                        last_urgent_ws = sstrdup(i3string_as_utf8(ws_walk->name));
+                    }
                 }
-            }
-            uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND;
-            uint32_t vals_border[] = { border_color, border_color };
-            xcb_change_gc(xcb_connection,
-                          outputs_walk->bargc,
-                          mask,
-                          vals_border);
-            xcb_rectangle_t rect_border = { i, 1, ws_walk->name_width + 10, font.height + 4 };
-            xcb_poly_fill_rectangle(xcb_connection,
-                                    outputs_walk->buffer,
-                                    outputs_walk->bargc,
-                                    1,
-                                    &rect_border);
-            uint32_t vals[] = { bg_color, bg_color };
-            xcb_change_gc(xcb_connection,
-                          outputs_walk->bargc,
-                          mask,
-                          vals);
-            xcb_rectangle_t rect = { i + 1, 2, ws_walk->name_width + 8, font.height + 2 };
-            xcb_poly_fill_rectangle(xcb_connection,
-                                    outputs_walk->buffer,
-                                    outputs_walk->bargc,
-                                    1,
-                                    &rect);
-            set_font_colors(outputs_walk->bargc, fg_color, bg_color);
-            draw_text(ws_walk->name, outputs_walk->buffer, outputs_walk->bargc, i + 5, 3, ws_walk->name_width);
-            i += 10 + ws_walk->name_width + 1;
+                uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND;
+                uint32_t vals_border[] = { border_color, border_color };
+                xcb_change_gc(xcb_connection,
+                              outputs_walk->bargc,
+                              mask,
+                              vals_border);
+                xcb_rectangle_t rect_border = { i, 1, ws_walk->name_width + 10, font.height + 4 };
+                xcb_poly_fill_rectangle(xcb_connection,
+                                        outputs_walk->buffer,
+                                        outputs_walk->bargc,
+                                        1,
+                                        &rect_border);
+                uint32_t vals[] = { bg_color, bg_color };
+                xcb_change_gc(xcb_connection,
+                              outputs_walk->bargc,
+                              mask,
+                              vals);
+                xcb_rectangle_t rect = { i + 1, 2, ws_walk->name_width + 8, font.height + 2 };
+                xcb_poly_fill_rectangle(xcb_connection,
+                                        outputs_walk->buffer,
+                                        outputs_walk->bargc,
+                                        1,
+                                        &rect);
+                set_font_colors(outputs_walk->bargc, fg_color, bg_color);
+                draw_text(ws_walk->name, outputs_walk->buffer, outputs_walk->bargc,
+                          i + 5, 3, ws_walk->name_width);
+                i += 10 + ws_walk->name_width + 1;
 
+            }
         }
 
-        if (binding.name) {
-
+        if (binding.name && !config.disable_binding_mode_indicator) {
             uint32_t fg_color = colors.urgent_ws_fg;
             uint32_t bg_color = colors.urgent_ws_bg;
             uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND;
index c7479b3afeabec83ac8d3a32096f6a300c762e98..4267dcfe3d335875452193578c5196029de9b983 100644 (file)
@@ -267,6 +267,10 @@ struct Barconfig {
      * zero. */
     bool hide_workspace_buttons;
 
+    /** Hide mode button? Configuration option is 'binding_mode_indicator no'
+     * but we invert the bool for the same reason as hide_workspace_buttons.*/
+    bool hide_binding_mode_indicator;
+
     /** Enable verbose mode? Useful for debugging purposes. */
     bool verbose;
 
index f9b7a47fdf2493c5b2af6101750b35f772b05932..9569a7b0af5b1d5904a5405f1bacc9161bb45d79 100644 (file)
@@ -74,6 +74,7 @@ CFGFUN(bar_socket_path, const char *socket_path);
 CFGFUN(bar_tray_output, const char *output);
 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);
 CFGFUN(bar_workspace_buttons, const char *value);
 CFGFUN(bar_finish);
 
index fd13797b15d22710d12f8c5001b2463e6a6a0519..dfd6401d4893ff9458e3a58aaf14bac64598cdd4 100644 (file)
@@ -345,20 +345,21 @@ state BAR:
   error ->
   '#' -> BAR_IGNORE_LINE
   'set' -> BAR_IGNORE_LINE
-  'i3bar_command'     -> BAR_BAR_COMMAND
-  'status_command'    -> BAR_STATUS_COMMAND
-  'socket_path'       -> BAR_SOCKET_PATH
-  'mode'              -> BAR_MODE
-  'hidden_state'      -> BAR_HIDDEN_STATE
-  'id'                -> BAR_ID
-  'modifier'          -> BAR_MODIFIER
-  'position'          -> BAR_POSITION
-  'output'            -> BAR_OUTPUT
-  'tray_output'       -> BAR_TRAY_OUTPUT
-  'font'              -> BAR_FONT
-  'workspace_buttons' -> BAR_WORKSPACE_BUTTONS
-  'verbose'           -> BAR_VERBOSE
-  'colors'            -> BAR_COLORS_BRACE
+  'i3bar_command'          -> BAR_BAR_COMMAND
+  'status_command'         -> BAR_STATUS_COMMAND
+  'socket_path'            -> BAR_SOCKET_PATH
+  'mode'                   -> BAR_MODE
+  'hidden_state'           -> BAR_HIDDEN_STATE
+  'id'                     -> BAR_ID
+  'modifier'               -> BAR_MODIFIER
+  'position'               -> BAR_POSITION
+  'output'                 -> BAR_OUTPUT
+  'tray_output'            -> BAR_TRAY_OUTPUT
+  'font'                   -> BAR_FONT
+  'binding_mode_indicator' -> BAR_BINDING_MODE_INDICATOR
+  'workspace_buttons'      -> BAR_WORKSPACE_BUTTONS
+  'verbose'                -> BAR_VERBOSE
+  'colors'                 -> BAR_COLORS_BRACE
   '}'
       -> call cfg_bar_finish(); INITIAL
 
@@ -411,6 +412,10 @@ state BAR_FONT:
   font = string
       -> call cfg_bar_font($font); BAR
 
+state BAR_BINDING_MODE_INDICATOR:
+  value = word
+      -> call cfg_bar_binding_mode_indicator($value); BAR
+
 state BAR_WORKSPACE_BUTTONS:
   value = word
       -> call cfg_bar_workspace_buttons($value); BAR
index 0fac7006b807c4ae1b549e0fa0b2a4fe381cb276..2bd4c90f279761d273eb9a25009004f9f536375d 100644 (file)
@@ -550,6 +550,10 @@ CFGFUN(bar_status_command, const char *command) {
     current_bar.status_command = sstrdup(command);
 }
 
+CFGFUN(bar_binding_mode_indicator, const char *value) {
+    current_bar.hide_binding_mode_indicator = !eval_boolstr(value);
+}
+
 CFGFUN(bar_workspace_buttons, const char *value) {
     current_bar.hide_workspace_buttons = !eval_boolstr(value);
 }
index 4c41465b7636aa0766429747ecf1cc41462c58af..a928dba9007a8c0cd79d56417d60dc8b332e6051 100644 (file)
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -686,6 +686,9 @@ IPC_HANDLER(get_bar_config) {
         ystr("workspace_buttons");
         y(bool, !config->hide_workspace_buttons);
 
+        ystr("binding_mode_indicator");
+        y(bool, !config->hide_binding_mode_indicator);
+
         ystr("verbose");
         y(bool, config->verbose);
 
index 762e52b87af6e1598da68583c64cccc8c2b4abde..8675dd7183c003c335753308d140eef89b050867 100644 (file)
@@ -63,6 +63,7 @@ my $bar_config = $i3->get_bar_config($bar_id)->recv;
 is($bar_config->{status_command}, 'i3status --foo', 'status_command correct');
 ok(!$bar_config->{verbose}, 'verbose off by default');
 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');
 
@@ -85,7 +86,8 @@ $config = <<EOT;
 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
 
 bar {
-    # Start a default instance of i3bar which provides workspace buttons.
+    # Start a default instance of i3bar which does not provide
+    # workspace buttons.
     # Additionally, i3status will provide a statusline.
     status_command i3status --bar
 
@@ -98,6 +100,7 @@ bar {
     mode dock
     font Terminus
     workspace_buttons no
+    binding_mode_indicator no
     verbose yes
     socket_path /tmp/foobar
 
@@ -125,6 +128,7 @@ $bar_config = $i3->get_bar_config($bar_id)->recv;
 is($bar_config->{status_command}, 'i3status --bar', 'status_command correct');
 ok($bar_config->{verbose}, 'verbose on');
 ok(!$bar_config->{workspace_buttons}, 'workspace buttons disabled');
+ok(!$bar_config->{binding_mode_indicator}, 'mode indicator disabled');
 is($bar_config->{mode}, 'dock', 'dock mode');
 is($bar_config->{position}, 'top', 'position top');
 is_deeply($bar_config->{outputs}, [ 'HDMI1', 'HDMI2' ], 'outputs ok');
@@ -230,7 +234,8 @@ $config = <<EOT;
 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
 
 bar {
-    # Start a default instance of i3bar which provides workspace buttons.
+    # Start a default instance of i3bar which does not provide
+    # workspace buttons.
     # Additionally, i3status will provide a statusline.
     status_command i3status --bar
 
@@ -243,6 +248,7 @@ bar {
     mode dock
     font Terminus
     workspace_buttons no
+    binding_mode_indicator yes
     verbose yes
     socket_path /tmp/foobar
 
@@ -271,6 +277,7 @@ $bar_config = $i3->get_bar_config($bar_id)->recv;
 is($bar_config->{status_command}, 'i3status --bar', 'status_command correct');
 ok($bar_config->{verbose}, 'verbose on');
 ok(!$bar_config->{workspace_buttons}, 'workspace buttons disabled');
+ok($bar_config->{binding_mode_indicator}, 'mode indicator enabled');
 is($bar_config->{mode}, 'dock', 'dock mode');
 is($bar_config->{position}, 'top', 'position top');
 is_deeply($bar_config->{outputs}, [ 'HDMI1', 'HDMI2' ], 'outputs ok');
index 06588b111a617b10bdab7382eeadeca1bef692ac..55239c62d749405f0a51bc8bf1515b7c4f2be3a0 100644 (file)
@@ -627,7 +627,7 @@ EOT
 
 $expected = <<'EOT';
 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', 'position', 'output', 'tray_output', 'font', 'workspace_buttons', 'verbose', 'colors', '}'
+ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'i3bar_command', 'status_command', 'socket_path', 'mode', 'hidden_state', 'id', 'modifier', 'position', 'output', 'tray_output', 'font', 'binding_mode_indicator', 'workspace_buttons', 'verbose', 'colors', '}'
 ERROR: CONFIG: (in file <stdin>)
 ERROR: CONFIG: Line   1: bar {
 ERROR: CONFIG: Line   2:     output LVDS-1