Add toggle mode for i3bar
Patch status: needinfo
Patch by philipdexter
Long description:
Implementation works best when modifier key for the toggle is not the normal modifier key for i3 commands. Plan to add a i3-msg for the possiblity of binding better keys for hiding/showing the i3bar.
Implements feature-request #833
To apply this patch, use:
curl http://cr.i3wm.org/patch/88/raw.patch | git am
b/i3bar/include/config.h
22 |
@@ -20,6 +20,7 @@ typedef enum {
|
23 |
|
24 |
typedef struct config_t {
|
25 |
int hide_on_modifier;
|
26 |
+ int toggle_on_modifier;
|
27 |
int modifier;
|
28 |
position_t position;
|
29 |
int verbose;
|
b/i3bar/src/config.c
34 |
@@ -74,6 +74,8 @@ static int config_string_cb(void *params_, const unsigned char *val, unsigned in
|
35 |
if (!strcmp(cur_key, "mode")) {
|
36 |
DLOG("mode = %.*s, len = %d\n", len, val, len);
|
37 |
config.hide_on_modifier = (len == 4 && !strncmp((const char*)val, "hide", strlen("hide")));
|
38 |
+ config.toggle_on_modifier = (len == 6 && !strncmp((const char*)val, "toggle", strlen("toggle")));
|
39 |
+ config.hide_on_modifier |= config.toggle_on;
|
40 |
return 1;
|
41 |
}
|
42 |
|
b/i3bar/src/xcb.c
47 |
@@ -215,8 +215,16 @@ void hide_bars(void) {
|
48 |
*/
|
49 |
void unhide_bars(void) {
|
50 |
if (!config.hide_on_modifier) {
|
51 |
+ if(config.toggle_on_modifier) {
|
52 |
+ config.hide_on_modifier = 1;
|
53 |
+ }
|
54 |
return;
|
55 |
}
|
56 |
+ else {
|
57 |
+ if(config.toggle_on_modifier) {
|
58 |
+ config.hide_on_modifier = 0;
|
59 |
+ }
|
60 |
+ }
|
61 |
|
62 |
i3_output *walk;
|
63 |
xcb_void_cookie_t cookie;
|
b/include/config.h
68 |
@@ -227,7 +227,7 @@ struct Barconfig {
|
69 |
char *socket_path;
|
70 |
|
71 |
/** Bar display mode (hide unless modifier is pressed or show in dock mode) */
|
72 |
- enum { M_DOCK = 0, M_HIDE = 1 } mode;
|
73 |
+ enum { M_DOCK = 0, M_HIDE = 1, M_TOGGLE = 2 } mode;
|
74 |
|
75 |
/** Bar modifier (to show bar when in hide mode). */
|
76 |
enum {
|
b/parser-specs/config.spec
81 |
@@ -378,7 +378,7 @@ state BAR_SOCKET_PATH:
|
82 |
-> call cfg_bar_socket_path($path); BAR
|
83 |
|
84 |
state BAR_MODE:
|
85 |
- mode = 'dock', 'hide'
|
86 |
+ mode = 'dock', 'hide', 'toggle'
|
87 |
-> call cfg_bar_mode($mode); BAR
|
88 |
|
89 |
state BAR_MODIFIER:
|
b/src/config_directives.c
94 |
@@ -452,7 +452,7 @@ CFGFUN(bar_font, const char *font) {
|
95 |
}
|
96 |
|
97 |
CFGFUN(bar_mode, const char *mode) {
|
98 |
- current_bar.mode = (strcmp(mode, "hide") == 0 ? M_HIDE : M_DOCK);
|
99 |
+ current_bar.mode = (strcmp(mode, "hide") == 0 ? M_HIDE : (strcmp(mode, "toggle") == 0) ? M_TOGGLE : M_DOCK);
|
100 |
}
|
101 |
|
102 |
CFGFUN(bar_output, const char *output) {
|
b/src/ipc.c
107 |
@@ -618,7 +618,10 @@ IPC_HANDLER(get_bar_config) {
|
108 |
ystr("mode");
|
109 |
if (config->mode == M_HIDE)
|
110 |
ystr("hide");
|
111 |
- else ystr("dock");
|
112 |
+ else if(config->mode == M_TOGGLE)
|
113 |
+ ystr("toggle");
|
114 |
+ else
|
115 |
+ ystr("dock");
|
116 |
|
117 |
ystr("modifier");
|
118 |
switch (config->modifier) {
|