implements #135 : set bar position
Browse files
+13 −2 src/bar/bar.zig
| @@ -73,11 +73,23 @@ pub const Bar = struct { | |||
| 73 | const font_height = font.*.ascent + font.*.descent; | 73 | const font_height = font.*.ascent + font.*.descent; |
| 74 | const bar_height: i32 = @intCast(@as(i32, font_height) + 8); | 74 | const bar_height: i32 = @intCast(@as(i32, font_height) + 8); |
| 75 | 75 | ||
| 76 | + var bar_y: i32 = 0; | ||
| 77 | + | ||
| 78 | + if (std.mem.eql(u8, config.bar_position, "top")) { | ||
| 79 | + bar_y = monitor.mon_y; | ||
| 80 | + monitor.mon_y = monitor.mon_y + bar_height; | ||
| 81 | + } else if (std.mem.eql(u8, config.bar_position, "bottom")) { | ||
| 82 | + bar_y = monitor.mon_h - bar_height; | ||
| 83 | + monitor.mon_y = 0; | ||
| 84 | + } else { | ||
| 85 | + return null; | ||
| 86 | + } | ||
| 87 | + | ||
| 76 | const window = xlib.c.XCreateSimpleWindow( | 88 | const window = xlib.c.XCreateSimpleWindow( |
| 77 | display, | 89 | display, |
| 78 | root, | 90 | root, |
| 79 | monitor.mon_x, | 91 | monitor.mon_x, |
| 80 | - monitor.mon_y, | 92 | + bar_y, |
| 81 | @intCast(monitor.mon_w), | 93 | @intCast(monitor.mon_w), |
| 82 | @intCast(bar_height), | 94 | @intCast(bar_height), |
| 83 | 0, | 95 | 0, |
| @@ -125,7 +137,6 @@ pub const Bar = struct { | |||
| 125 | }; | 137 | }; |
| 126 | 138 | ||
| 127 | monitor.bar_win = window; | 139 | monitor.bar_win = window; |
| 128 | - monitor.win_y = monitor.mon_y + bar_height; | ||
| 129 | monitor.win_h = monitor.mon_h - bar_height; | 140 | monitor.win_h = monitor.mon_h - bar_height; |
| 130 | 141 | ||
| 131 | return bar; | 142 | return bar; |
+1 −0 src/config/config.zig
| @@ -122,6 +122,7 @@ pub const Config = struct { | |||
| 122 | 122 | ||
| 123 | terminal: []const u8 = "st", | 123 | terminal: []const u8 = "st", |
| 124 | font: []const u8 = "monospace:size=10", | 124 | font: []const u8 = "monospace:size=10", |
| 125 | + bar_position: []const u8 = "top", | ||
| 125 | tags: [9][]const u8 = .{ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, | 126 | tags: [9][]const u8 = .{ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, |
| 126 | layout: []const u8 = "tiling", | 127 | layout: []const u8 = "tiling", |
| 127 | 128 | ||
+12 −0 src/config/lua.zig
| @@ -274,6 +274,9 @@ fn registerBarModule(state: *c.lua_State) void { | |||
| 274 | c.lua_pushcfunction(state, luaBarSetHideVacantTags); | 274 | c.lua_pushcfunction(state, luaBarSetHideVacantTags); |
| 275 | c.lua_setfield(state, -2, "set_hide_vacant_tags"); | 275 | c.lua_setfield(state, -2, "set_hide_vacant_tags"); |
| 276 | 276 | ||
| 277 | + c.lua_pushcfunction(state, luaBarSetPosition); | ||
| 278 | + c.lua_setfield(state, -2, "set_position"); | ||
| 279 | + | ||
| 277 | c.lua_createtable(state, 0, 6); | 280 | c.lua_createtable(state, 0, 6); |
| 278 | 281 | ||
| 279 | c.lua_pushcfunction(state, luaBarBlockRam); | 282 | c.lua_pushcfunction(state, luaBarBlockRam); |
| @@ -755,6 +758,15 @@ fn luaBarSetFont(state: ?*c.lua_State) callconv(.c) c_int { | |||
| 755 | return 0; | 758 | return 0; |
| 756 | } | 759 | } |
| 757 | 760 | ||
| 761 | +fn luaBarSetPosition(state: ?*c.lua_State) callconv(.c) c_int { | ||
| 762 | + const cfg = config orelse return 0; | ||
| 763 | + const s = state orelse return 0; | ||
| 764 | + if (dupeLuaString(s, 1)) |position| { | ||
| 765 | + cfg.bar_position = position; | ||
| 766 | + } | ||
| 767 | + return 0; | ||
| 768 | +} | ||
| 769 | + | ||
| 758 | fn luaBarSetBlocks(state: ?*c.lua_State) callconv(.c) c_int { | 770 | fn luaBarSetBlocks(state: ?*c.lua_State) callconv(.c) c_int { |
| 759 | const cfg = config orelse return 0; | 771 | const cfg = config orelse return 0; |
| 760 | const s = state orelse return 0; | 772 | const s = state orelse return 0; |
+3 −0 templates/config.lua
| @@ -161,6 +161,9 @@ oxwm.rule.add({ instance = "gimp", floating = true }) | |||
| 161 | -- Font configuration | 161 | -- Font configuration |
| 162 | oxwm.bar.set_font(bar_font) | 162 | oxwm.bar.set_font(bar_font) |
| 163 | 163 | ||
| 164 | +-- Position configuration (top/bottom, top is default) | ||
| 165 | +-- oxwm.bar.set_position("bottom") | ||
| 166 | + | ||
| 164 | -- Set your blocks here (defined above) | 167 | -- Set your blocks here (defined above) |
| 165 | oxwm.bar.set_blocks(blocks) | 168 | oxwm.bar.set_blocks(blocks) |
| 166 | 169 | ||