tony / oxwm

fixed bug where window was not snapping to the right on scroll mode, and also added toggle-able indicator for scroll mode in bar. Browse files
tonybanters committed 2026-09-22 parent 86288f6 commit 9ae47bda206817c80add59b8ae1afc28fb0b6329
Showing 7 changed files with 103 additions and 27 deletions. UnifiedSplit
+46 −0 src/bar/bar.zig
@@ -4,6 +4,8 @@ const monitor_mod = @import("../monitor.zig");
4 4 const blocks_mod = @import("blocks/blocks.zig");
5 5 const config_mod = @import("../config/config.zig");
6 6 const systray_mod = @import("systray.zig");
7 +const client_mod = @import("../client.zig");
8 +const scrolling = @import("../layouts/scrolling.zig");
7 9 const ColorScheme = config_mod.ColorScheme;
8 10
9 11 const Monitor = monitor_mod.Monitor;
@@ -232,6 +234,10 @@ pub const Bar = struct {
232 234 self.drawText(display, x_position, @divTrunc(self.height + self.font_height, 2) - 4, layout_symbol, self.scheme_normal.foreground);
233 235 x_position += self.textWidth(display, layout_symbol) + padding;
234 236
237 + if (config.scroll_indicator and monitor.sel_lt == @intFromEnum(config_mod.Layouts.scrolling)) {
238 + x_position += self.drawScrollIndicator(display, x_position, config.scroll_indicator_width) + padding;
239 + }
240 +
235 241 const systray_width: i32 = if (self.systray) |tray| tray.width() else 0;
236 242 var block_x: i32 = self.width - padding - systray_width;
237 243 if (systray_width > 0) block_x -= padding;
@@ -311,6 +317,46 @@ pub const Bar = struct {
311 317 if (changed) self.needs_redraw = true;
312 318 }
313 319
320 + /// toggle-able minimap on bar to indicate your scrolling position
321 + /// (similar to waybar per Fedesito's request)
322 + fn drawScrollIndicator(
323 + self: *Bar,
324 + display: *xlib.Display,
325 + x: i32,
326 + configured_width: i32
327 + ) i32 {
328 + const monitor = self.monitor;
329 + const geo = scrolling.geometry(monitor);
330 + const content = scrolling.contentWidth(monitor);
331 + if (geo.count == 0 or content <= 0) return 0;
332 +
333 + const total: i32 = if (configured_width > 0) configured_width else self.height * 4;
334 + const scale = @as(f32, @floatFromInt(total)) / @as(f32, @floatFromInt(@max(content, geo.available_w)));
335 + const box_height = @max(4, @divTrunc(self.height, 3));
336 + const box_y = @divTrunc(self.height - box_height, 2);
337 +
338 + var current = client_mod.nextTiled(monitor.clients);
339 + var left: i32 = 0;
340 + while (current) |client| : (current = client_mod.nextTiled(client.next)) {
341 + const width = scrolling.windowWidth(monitor, client, geo);
342 + const box_x = x + @as(i32, @intFromFloat(@as(f32, @floatFromInt(left)) * scale));
343 + const box_w = @max(2, @as(i32, @intFromFloat(@as(f32, @floatFromInt(width)) * scale)) - 1);
344 + const color = if (client == monitor.sel) self.scheme_selected.border else self.scheme_normal.border;
345 + self.fillRect(display, box_x, box_y, box_w, box_height, color);
346 + left += width + geo.inner;
347 + }
348 +
349 + const view_left = @max(0, monitor.scroll_offset);
350 + const view_right = @min(@max(content, geo.available_w), monitor.scroll_offset + geo.available_w);
351 + if (view_right > view_left) {
352 + const line_x = x + @as(i32, @intFromFloat(@as(f32, @floatFromInt(view_left)) * scale));
353 + const line_w = @max(1, @as(i32, @intFromFloat(@as(f32, @floatFromInt(view_right - view_left)) * scale)));
354 + self.fillRect(display, line_x, self.height - 3, line_w, 2, self.scheme_occupied.border);
355 + }
356 +
357 + return total;
358 + }
359 +
314 360 fn fillRect(self: *Bar, display: *xlib.Display, x: i32, y: i32, width: i32, height: i32, color: c_ulong) void {
315 361 _ = xlib.XSetForeground(display, self.graphics_context, color);
316 362 _ = xlib.XFillRectangle(display, self.pixmap, self.graphics_context, x, y, @intCast(width), @intCast(height));
+2 −0 src/config/config.zig
@@ -232,6 +232,8 @@ pub const Config = struct {
232 232 gesture_fingers: u32 = 3,
233 233 gesture_speed: f32 = 2.0,
234 234 gesture_natural: bool = false,
235 + scroll_indicator: bool = true,
236 + scroll_indicator_width: i32 = 0,
235 237
236 238 layout_tile_symbol: []const u8 = "[]=",
237 239 layout_monocle_symbol: []const u8 = "[M]",
+21 −0 src/config/lua.zig
@@ -224,6 +224,12 @@ fn registerScrollModule(state: *c.lua_State) void {
224 224 c.lua_pushcfunction(state, luaScrollSetGestureNatural);
225 225 c.lua_setfield(state, -2, "set_gesture_natural");
226 226
227 + c.lua_pushcfunction(state, luaScrollSetIndicator);
228 + c.lua_setfield(state, -2, "set_indicator");
229 +
230 + c.lua_pushcfunction(state, luaScrollSetIndicatorWidth);
231 + c.lua_setfield(state, -2, "set_indicator_width");
232 +
227 233 c.lua_setfield(state, -2, "scroll");
228 234 }
229 235
@@ -749,6 +755,21 @@ fn luaScrollSetGestureNatural(state: ?*c.lua_State) callconv(.c) c_int {
749 755 return 0;
750 756 }
751 757
758 +fn luaScrollSetIndicator(state: ?*c.lua_State) callconv(.c) c_int {
759 + const cfg = config orelse return 0;
760 + const s = state orelse return 0;
761 + cfg.scroll_indicator = c.lua_toboolean(s, 1) != 0;
762 + return 0;
763 +}
764 +
765 +fn luaScrollSetIndicatorWidth(state: ?*c.lua_State) callconv(.c) c_int {
766 + const cfg = config orelse return 0;
767 + const s = state orelse return 0;
768 + const value = c.lua_tointegerx(s, 1, null);
769 + if (value >= 0) cfg.scroll_indicator_width = @intCast(value);
770 + return 0;
771 +}
772 +
752 773 fn luaTagView(state: ?*c.lua_State) callconv(.c) c_int {
753 774 const s = state orelse return 0;
754 775 const idx: i32 = @intCast(c.lua_tointegerx(s, 1, null));
+2 −23 src/layouts/scrolling.zig
@@ -119,37 +119,16 @@ pub fn nearestSnap(monitor: *Monitor, position: f64) ?Snap {
119 119 var current = client_mod.nextTiled(monitor.clients);
120 120 while (current) |client| : (current = client_mod.nextTiled(client.next)) {
121 121 const width = windowWidth(monitor, client, geo);
122 - const snap_offset = @min(offset, max);
123 - const dist = @abs(@as(f64, @floatFromInt(snap_offset)) - position);
122 + const dist = @abs(@as(f64, @floatFromInt(offset)) - position);
124 123 if (dist < best_dist) {
125 124 best_dist = dist;
126 - best = .{ .client = client, .offset = snap_offset, .width = width };
125 + best = .{ .client = client, .offset = @min(offset, max), .width = width };
127 126 }
128 127 offset += width + geo.inner;
129 128 }
130 129 return best;
131 130 }
132 131
133 -pub fn adjacentSnap(monitor: *Monitor, position: i32, direction: i32) ?Snap {
134 - const geo = geometry(monitor);
135 - const max = maxScroll(monitor);
136 - var result: ?Snap = null;
137 - var offset: i32 = 0;
138 - var current = client_mod.nextTiled(monitor.clients);
139 - while (current) |client| : (current = client_mod.nextTiled(client.next)) {
140 - const width = windowWidth(monitor, client, geo);
141 - const snap_offset = @min(offset, max);
142 - const snap = Snap{ .client = client, .offset = snap_offset, .width = width };
143 - if (direction > 0) {
144 - if (snap_offset > position) return snap;
145 - } else if (snap_offset < position) {
146 - result = snap;
147 - }
148 - offset += width + geo.inner;
149 - }
150 - return result;
151 -}
152 -
153 132 pub fn scroll(monitor: *Monitor) void {
154 133 const geo = geometry(monitor);
155 134 if (geo.count == 0) return;
+21 −4 src/wm/core.zig
@@ -272,6 +272,7 @@ pub fn arrange(monitor: *Monitor, wm: *WindowManager) void {
272 272 }
273 273 }
274 274 restack(monitor, wm);
275 + if (isScrollingLayout(monitor) and wm.config.scroll_indicator) wm.invalidateBars();
275 276 }
276 277
277 278 pub fn showhide(monitor: *Monitor, wm: *WindowManager) void {
@@ -443,11 +444,27 @@ pub fn scrollLayout(direction: i32, wm: *WindowManager) void {
443 444 const monitor = wm.selected_monitor orelse return;
444 445 if (!isScrollingLayout(monitor) or wm.gesture.active) return;
445 446
446 - const current = scrollTarget(monitor, wm);
447 - const snap = scrolling.adjacentSnap(monitor, current, direction) orelse return;
447 + const first = client_mod.nextTiled(monitor.clients) orelse return;
448 + var target: ?*Client = null;
449 + if (monitor.sel) |sel| {
450 + if (!sel.is_floating and client_mod.isVisible(sel)) {
451 + if (direction > 0) {
452 + target = client_mod.nextTiled(sel.next);
453 + } else {
454 + var previous: ?*Client = null;
455 + var current: ?*Client = first;
456 + while (current) |client| : (current = client_mod.nextTiled(client.next)) {
457 + if (client == sel) break;
458 + previous = client;
459 + }
460 + target = previous;
461 + }
462 + }
463 + }
464 + const client = target orelse (if (monitor.sel == null or monitor.sel.?.is_floating) first else return);
448 465
449 - focus(snap.client, wm);
450 - startScrollAnimation(monitor, snap.offset, wm);
466 + focus(client, wm);
467 + scrollToWindow(client, true, wm);
451 468 }
452 469
453 470 pub fn scrollToWindow(client: *Client, animate: bool, wm: *WindowManager) void {
+3 −0 templates/config.lua
@@ -139,6 +139,9 @@ oxwm.set_layout_symbol("tabbed", "[=]")
139 139 -- oxwm.scroll.set_gesture_fingers(3)
140 140 -- oxwm.scroll.set_gesture_speed(2.0)
141 141 -- oxwm.scroll.set_gesture_natural(false)
142 +-- Minimap of the strip in the bar (one box per window, focused highlighted)
143 +-- oxwm.scroll.set_indicator(true)
144 +-- oxwm.scroll.set_indicator_width(0) -- pixels, 0 = 4x bar height
142 145
143 146 -- Set the default attach method, similar to the patches from dwm
144 147 -- Available methods: "aside" (default), "top", "bottom", "above", "below"
+8 −0 templates/oxwm.lua
@@ -275,6 +275,14 @@ function oxwm.scroll.set_gesture_speed(speed) end
275 275 ---@param natural boolean Default false
276 276 function oxwm.scroll.set_gesture_natural(natural) end
277 277
278 +---Show a minimap of the scrolling strip in the bar next to the layout symbol
279 +---@param enabled boolean Default true
280 +function oxwm.scroll.set_indicator(enabled) end
281 +
282 +---Set the minimap width
283 +---@param width integer Pixels, 0 = four times the bar height (default)
284 +function oxwm.scroll.set_indicator_width(width) end
285 +
278 286 ---Tag/workspace management module
279 287 ---@class oxwm.tag
280 288 oxwm.tag = {}