implements #131 : toggle bar action
Browse files
+1 −0 src/config/config.zig
| @@ -18,6 +18,7 @@ pub const Action = enum { | ||
| 18 | 18 | toggle_floating, |
| 19 | 19 | toggle_fullscreen, |
| 20 | 20 | toggle_gaps, |
| 21 | + toggle_bar, | |
| 21 | 22 | cycle_layout, |
| 22 | 23 | set_layout, |
| 23 | 24 | set_layout_tiling, |
+10 −0 src/config/lua.zig
| @@ -330,6 +330,9 @@ fn registerMiscFunctions(state: *c.lua_State) void { | ||
| 330 | 330 | c.lua_pushcfunction(state, luaToggleGaps); |
| 331 | 331 | c.lua_setfield(state, -2, "toggle_gaps"); |
| 332 | 332 | |
| 333 | + c.lua_pushcfunction(state, luaToggleBar); | |
| 334 | + c.lua_setfield(state, -2, "toggle_bar"); | |
| 335 | + | |
| 333 | 336 | c.lua_pushcfunction(state, luaShowKeybinds); |
| 334 | 337 | c.lua_setfield(state, -2, "show_keybinds"); |
| 335 | 338 | |
| @@ -1131,6 +1134,12 @@ fn luaToggleGaps(state: ?*c.lua_State) callconv(.c) c_int { | ||
| 1131 | 1134 | return 1; |
| 1132 | 1135 | } |
| 1133 | 1136 | |
| 1137 | +fn luaToggleBar(state: ?*c.lua_State) callconv(.c) c_int { | |
| 1138 | + const s = state orelse return 0; | |
| 1139 | + createActionTable(s, "ToggleBar"); | |
| 1140 | + return 1; | |
| 1141 | +} | |
| 1142 | + | |
| 1134 | 1143 | fn luaShowKeybinds(state: ?*c.lua_State) callconv(.c) c_int { |
| 1135 | 1144 | const s = state orelse return 0; |
| 1136 | 1145 | createActionTable(s, "ShowKeybinds"); |
| @@ -1281,6 +1290,7 @@ fn parseAction(name: []const u8) ?Action { | ||
| 1281 | 1290 | .{ "ToggleFloating", Action.toggle_floating }, |
| 1282 | 1291 | .{ "ToggleFullScreen", Action.toggle_fullscreen }, |
| 1283 | 1292 | .{ "ToggleGaps", Action.toggle_gaps }, |
| 1293 | + .{ "ToggleBar", Action.toggle_bar }, | |
| 1284 | 1294 | .{ "CycleLayout", Action.cycle_layout }, |
| 1285 | 1295 | .{ "ChangeLayout", Action.set_layout }, |
| 1286 | 1296 | .{ "ViewTag", Action.view_tag }, |
+37 −0 src/wm/actions.zig
| @@ -6,6 +6,7 @@ const lua = @import("../config/lua.zig"); | ||
| 6 | 6 | const core = @import("core.zig"); |
| 7 | 7 | const tiling = @import("../layouts/tiling.zig"); |
| 8 | 8 | const monitor_mod = @import("../monitor.zig"); |
| 9 | +const bar_mod = @import("../bar/bar.zig"); | |
| 9 | 10 | const wm_mod = @import("wm.zig"); |
| 10 | 11 | const xlib = @import("../x11/xlib.zig"); |
| 11 | 12 | |
| @@ -148,6 +149,12 @@ pub fn toggleView(tag_mask: u32, wm: *WindowManager) void { | ||
| 148 | 149 | monitor.mfact = monitor.pertag.mfacts[monitor.pertag.curtag]; |
| 149 | 150 | monitor.sel_lt = monitor.pertag.sellts[monitor.pertag.curtag]; |
| 150 | 151 | |
| 152 | + const new_show_bar = monitor.pertag.showbars[monitor.pertag.curtag]; | |
| 153 | + if (new_show_bar != monitor.show_bar) { | |
| 154 | + monitor.show_bar = new_show_bar; | |
| 155 | + updateBarVisibility(monitor, wm); | |
| 156 | + } | |
| 157 | + | |
| 151 | 158 | core.focusTopClient(monitor, wm); |
| 152 | 159 | core.arrange(monitor, wm); |
| 153 | 160 | wm.invalidateBars(); |
| @@ -182,6 +189,35 @@ pub fn toggleGaps(wm: *WindowManager) void { | ||
| 182 | 189 | core.arrange(monitor, wm); |
| 183 | 190 | } |
| 184 | 191 | |
| 192 | +pub fn updateBarVisibility(monitor: *Monitor, wm: *WindowManager) void { | |
| 193 | + const bar = bar_mod.windowToBar(wm.bars, monitor.bar_win) orelse return; | |
| 194 | + | |
| 195 | + if (monitor.show_bar) { | |
| 196 | + _ = xlib.XMapWindow(wm.display.handle, bar.window); | |
| 197 | + monitor.win_h -= bar.height; | |
| 198 | + if (std.mem.eql(u8, wm.config.bar_position, "top")) { | |
| 199 | + monitor.mon_y += bar.height; | |
| 200 | + } | |
| 201 | + } else { | |
| 202 | + _ = xlib.c.XUnmapWindow(wm.display.handle, bar.window); | |
| 203 | + monitor.win_h += bar.height; | |
| 204 | + if (std.mem.eql(u8, wm.config.bar_position, "top")) { | |
| 205 | + monitor.mon_y -= bar.height; | |
| 206 | + } | |
| 207 | + } | |
| 208 | +} | |
| 209 | + | |
| 210 | +pub fn toggleBar(wm: *WindowManager) void { | |
| 211 | + const monitor = wm.selected_monitor orelse return; | |
| 212 | + monitor.show_bar = !monitor.show_bar; | |
| 213 | + monitor.pertag.showbars[monitor.pertag.curtag] = monitor.show_bar; | |
| 214 | + | |
| 215 | + updateBarVisibility(monitor, wm); | |
| 216 | + | |
| 217 | + core.arrange(monitor, wm); | |
| 218 | + wm.invalidateBars(); | |
| 219 | +} | |
| 220 | + | |
| 185 | 221 | pub fn killFocused(wm: *WindowManager) void { |
| 186 | 222 | const selected = wm.selected_monitor orelse return; |
| 187 | 223 | const client = selected.sel orelse return; |
| @@ -680,6 +716,7 @@ pub fn executeAction(action: config_mod.Action, int_arg: i32, str_arg: ?[]const | ||
| 680 | 716 | .toggle_floating => toggleFloating(wm), |
| 681 | 717 | .toggle_fullscreen => toggleFullscreen(wm), |
| 682 | 718 | .toggle_gaps => toggleGaps(wm), |
| 719 | + .toggle_bar => toggleBar(wm), | |
| 683 | 720 | .cycle_layout => cycleLayout(wm), |
| 684 | 721 | .set_layout => setLayout(str_arg, wm), |
| 685 | 722 | .set_layout_tiling => setLayoutIndex(0, wm), |
+6 −0 src/wm/core.zig
| @@ -729,6 +729,12 @@ pub fn view(tag_mask: u32, wm: *WindowManager) void { | ||
| 729 | 729 | monitor.mfact = monitor.pertag.mfacts[monitor.pertag.curtag]; |
| 730 | 730 | monitor.sel_lt = monitor.pertag.sellts[monitor.pertag.curtag]; |
| 731 | 731 | |
| 732 | + const new_show_bar = monitor.pertag.showbars[monitor.pertag.curtag]; | |
| 733 | + if (new_show_bar != monitor.show_bar) { | |
| 734 | + monitor.show_bar = new_show_bar; | |
| 735 | + window_manager.actions.updateBarVisibility(monitor, wm); | |
| 736 | + } | |
| 737 | + | |
| 732 | 738 | focusTopClient(monitor, wm); |
| 733 | 739 | arrange(monitor, wm); |
| 734 | 740 | wm.invalidateBars(); |
+2 −0 templates/config.lua
| @@ -230,6 +230,8 @@ oxwm.key.bind({ modkey }, "P", oxwm.inc_num_master(-1)) | ||
| 230 | 230 | |
| 231 | 231 | -- Gaps toggle |
| 232 | 232 | oxwm.key.bind({ modkey }, "A", oxwm.toggle_gaps()) |
| 233 | +-- Bar toggle | |
| 234 | +oxwm.key.bind({ modkey }, "B", oxwm.toggle_bar()) | |
| 233 | 235 | |
| 234 | 236 | -- Window manager controls |
| 235 | 237 | oxwm.key.bind({ modkey, "Shift" }, "Q", oxwm.quit()) |