|
|
@@ -4,6 +4,7 @@ const monitor_mod = @import("../monitor.zig"); |
| 4 |
4 |
const client_mod = @import("../client.zig"); |
| 5 |
5 |
const blocks_mod = @import("blocks/blocks.zig"); |
| 6 |
6 |
const config_mod = @import("../config/config.zig"); |
|
7 |
+const ColorScheme = config_mod.ColorScheme; |
| 7 |
8 |
|
| 8 |
9 |
const Monitor = monitor_mod.Monitor; |
| 9 |
10 |
const Block = blocks_mod.Block; |
|
|
@@ -30,12 +31,6 @@ fn get_layout_symbol(layout_index: u32) []const u8 { |
| 30 |
31 |
}; |
| 31 |
32 |
} |
| 32 |
33 |
|
| 33 |
|
-pub const ColorScheme = struct { |
| 34 |
|
- foreground: c_ulong, |
| 35 |
|
- background: c_ulong, |
| 36 |
|
- border: c_ulong, |
| 37 |
|
-}; |
| 38 |
|
- |
| 39 |
34 |
pub const Bar = struct { |
| 40 |
35 |
window: xlib.Window, |
| 41 |
36 |
pixmap: xlib.Pixmap, |
|
|
@@ -52,6 +47,7 @@ pub const Bar = struct { |
| 52 |
47 |
scheme_selected: ColorScheme, |
| 53 |
48 |
scheme_occupied: ColorScheme, |
| 54 |
49 |
scheme_urgent: ColorScheme, |
|
50 |
+ hide_vacant_tags: bool, |
| 55 |
51 |
|
| 56 |
52 |
allocator: std.mem.Allocator, |
| 57 |
53 |
blocks: std.ArrayList(Block), |
|
|
@@ -63,7 +59,7 @@ pub const Bar = struct { |
| 63 |
59 |
display: *xlib.Display, |
| 64 |
60 |
screen: c_int, |
| 65 |
61 |
monitor: *Monitor, |
| 66 |
|
- font_name: []const u8, |
|
62 |
+ config: config_mod.Config, |
| 67 |
63 |
) ?*Bar { |
| 68 |
64 |
const bar = allocator.create(Bar) catch return null; |
| 69 |
65 |
|
|
|
@@ -72,7 +68,7 @@ pub const Bar = struct { |
| 72 |
68 |
const depth = xlib.XDefaultDepth(display, screen); |
| 73 |
69 |
const root = xlib.XRootWindow(display, screen); |
| 74 |
70 |
|
| 75 |
|
- const font_name_z = allocator.dupeZ(u8, font_name) catch return null; |
|
71 |
+ const font_name_z = allocator.dupeZ(u8, config.font) catch return null; |
| 76 |
72 |
defer allocator.free(font_name_z); |
| 77 |
73 |
|
| 78 |
74 |
const font = xlib.XftFontOpenName(display, screen, font_name_z); |
|
|
@@ -116,12 +112,6 @@ pub const Bar = struct { |
| 116 |
112 |
|
| 117 |
113 |
_ = xlib.XMapWindow(display, window); |
| 118 |
114 |
|
| 119 |
|
- const cfg = config_mod.get_config(); |
| 120 |
|
- const scheme_normal = if (cfg) |c| ColorScheme{ .foreground = c.scheme_normal.fg, .background = c.scheme_normal.bg, .border = c.scheme_normal.border } else ColorScheme{ .foreground = 0xbbbbbb, .background = 0x1a1b26, .border = 0x444444 }; |
| 121 |
|
- const scheme_selected = if (cfg) |c| ColorScheme{ .foreground = c.scheme_selected.fg, .background = c.scheme_selected.bg, .border = c.scheme_selected.border } else ColorScheme{ .foreground = 0x0db9d7, .background = 0x1a1b26, .border = 0xad8ee6 }; |
| 122 |
|
- const scheme_occupied = if (cfg) |c| ColorScheme{ .foreground = c.scheme_occupied.fg, .background = c.scheme_occupied.bg, .border = c.scheme_occupied.border } else ColorScheme{ .foreground = 0x0db9d7, .background = 0x1a1b26, .border = 0x0db9d7 }; |
| 123 |
|
- const scheme_urgent = if (cfg) |c| ColorScheme{ .foreground = c.scheme_urgent.fg, .background = c.scheme_urgent.bg, .border = c.scheme_urgent.border } else ColorScheme{ .foreground = 0xf7768e, .background = 0x1a1b26, .border = 0xf7768e }; |
| 124 |
|
- |
| 125 |
115 |
bar.* = Bar{ |
| 126 |
116 |
.window = window, |
| 127 |
117 |
.pixmap = pixmap, |
|
|
@@ -132,10 +122,11 @@ pub const Bar = struct { |
| 132 |
122 |
.monitor = monitor, |
| 133 |
123 |
.font = font, |
| 134 |
124 |
.font_height = font_height, |
| 135 |
|
- .scheme_normal = scheme_normal, |
| 136 |
|
- .scheme_selected = scheme_selected, |
| 137 |
|
- .scheme_occupied = scheme_occupied, |
| 138 |
|
- .scheme_urgent = scheme_urgent, |
|
125 |
+ .scheme_normal = config.scheme_normal, |
|
126 |
+ .scheme_selected = config.scheme_selected, |
|
127 |
+ .scheme_occupied = config.scheme_occupied, |
|
128 |
+ .scheme_urgent = config.scheme_urgent, |
|
129 |
+ .hide_vacant_tags = config.hide_vacant_tags, |
| 139 |
130 |
.allocator = allocator, |
| 140 |
131 |
.blocks = .{}, |
| 141 |
132 |
.needs_redraw = true, |
|
|
@@ -186,6 +177,8 @@ pub const Bar = struct { |
| 186 |
177 |
const is_selected = (current_tags & tag_mask) != 0; |
| 187 |
178 |
const is_occupied = has_clients_on_tag(monitor, tag_mask); |
| 188 |
179 |
|
|
180 |
+ if (self.hide_vacant_tags and !is_occupied and !is_selected) continue; |
|
181 |
+ |
| 189 |
182 |
const scheme = if (is_selected) self.scheme_selected else if (is_occupied) self.scheme_occupied else self.scheme_normal; |
| 190 |
183 |
|
| 191 |
184 |
const tag_text_width = self.text_width(display, tag); |
|
|
@@ -267,7 +260,15 @@ pub const Bar = struct { |
| 267 |
260 |
const display = xlib.c.XOpenDisplay(null) orelse return null; |
| 268 |
261 |
defer _ = xlib.XCloseDisplay(display); |
| 269 |
262 |
|
|
263 |
+ const monitor = self.monitor; |
|
264 |
+ const current_tags = monitor.tagset[monitor.sel_tags]; |
| 270 |
265 |
for (tags, 0..) |tag, index| { |
|
266 |
+ const tag_mask = @as(u32, 1) << @intCast(index); |
|
267 |
+ const is_selected = (current_tags & tag_mask) != 0; |
|
268 |
+ const is_occupied = has_clients_on_tag(monitor, tag_mask); |
|
269 |
+ |
|
270 |
+ if (self.hide_vacant_tags and !is_occupied and !is_selected) continue; |
|
271 |
+ |
| 271 |
272 |
const tag_text_width = self.text_width(display, tag); |
| 272 |
273 |
const tag_width = tag_text_width + padding * 2; |
| 273 |
274 |
|