tony / oxwm

Merge pull request #264 from tonybanters/fedesito Browse files
scrolling updates, gestures, new dependencies.
Tony, btw. committed 24d ago parents 472c767 81fac03 commit ee118ae23fe23bbc9df35b17a898aa36817feec1
Showing 18 changed files with 936 additions and 136 deletions. UnifiedSplit
+4 −2 README.md
@@ -70,7 +70,7 @@ This will automatically put a desktop session file into your xsessions directory
70 Manually, install the dependencies and see Building from Source: 70 Manually, install the dependencies and see Building from Source:
71 71
72 ```sh 72 ```sh
73 -sudo pacman -S zig libx11 libxft freetype2 fontconfig libxinerama 73 +sudo pacman -S zig libx11 libxft freetype2 fontconfig libxinerama libinput systemd-libs
74 ``` 74 ```
75 75
76 ### Building from Source 76 ### Building from Source
@@ -91,6 +91,8 @@ cd oxwm
91 zig build -Doptimize=ReleaseSmall --prefix /usr 91 zig build -Doptimize=ReleaseSmall --prefix /usr
92 ``` 92 ```
93 93
94 +Touchpad swipe gestures for the scrolling layout use libinput and libudev, which only exist on Linux. They are compiled in by default (needs the libinput and libudev development packages) and skipped automatically on BSD targets. At runtime they stay off until you uncomment `oxwm.scroll.set_gesture_enabled(true)` in your config. Pass `-Dno_gestures` to leave them out anywhere, or use `zig build openbsd` (also `freebsd`, `netbsd`, `bsd`) which does the same and installs the result.
95 +
94 ### Setting up OXWM 96 ### Setting up OXWM
95 97
96 #### Without a display manager (startx) 98 #### Without a display manager (startx)
@@ -236,7 +238,7 @@ Default keybindings (fully customizable in `~/.config/oxwm/config.lua`):
236 - Normie (floating-by-default) 238 - Normie (floating-by-default)
237 - Monocle (fullscreen stacking) 239 - Monocle (fullscreen stacking)
238 - Grid (equal-sized grid) 240 - Grid (equal-sized grid)
239 - - Scrolling (horizontal scroll) 241 + - Scrolling (niri-style horizontal strip with per-window widths and three-finger touchpad swipes)
240 - Dwindle (fibonacci spiral) 242 - Dwindle (fibonacci spiral)
241 - **Configurable Attach Method** for new windows: aside, top, bottom, above, or below 243 - **Configurable Attach Method** for new windows: aside, top, bottom, above, or below
242 - **Lua Configuration System** 244 - **Lua Configuration System**
+65 −24 build.zig
@@ -7,36 +7,28 @@ pub fn build(b: *std.Build) void {
7 const lua_dep = b.dependency("lua", .{}); 7 const lua_dep = b.dependency("lua", .{});
8 const lua_headers = lua_dep.path("src/"); 8 const lua_headers = lua_dep.path("src/");
9 9
10 - const exe = b.addExecutable(.{ 10 + const no_gestures = b.option(bool, "no_gestures", "Build without libinput touchpad gestures (implied on BSD targets)") orelse false;
11 - .name = "oxwm", 11 + const gestures = !no_gestures and !isBsd(target.result.os.tag);
12 - .root_module = b.createModule(.{
13 - .root_source_file = b.path("src/main.zig"),
14 - .target = target,
15 - .optimize = optimize,
16 - .link_libc = true,
17 - }),
18 - });
19 -
20 - const exe_options = b.addOptions();
21 - exe_options.addOption([]const u8, "version", zon.version);
22 - exe.root_module.addOptions("build_options", exe_options);
23 -
24 - exe.root_module.addAnonymousImport("templates/config.lua", .{
25 - .root_source_file = b.path("templates/config.lua"),
26 - });
27 -
28 - exe.use_lld = false;
29 12
30 const lua = buildLua(b, lua_dep, target, optimize); 13 const lua = buildLua(b, lua_dep, target, optimize);
31 14
32 - exe.root_module.linkLibrary(lua); 15 + const exe_options = b.addOptions();
33 - exe.root_module.linkSystemLibrary("X11", .{}); 16 + exe_options.addOption([]const u8, "version", zon.version);
34 - exe.root_module.linkSystemLibrary("Xinerama", .{}); 17 + exe_options.addOption(bool, "gestures", gestures);
35 - exe.root_module.linkSystemLibrary("Xft", .{});
36 - exe.root_module.linkSystemLibrary("fontconfig", .{});
37 18
19 + const exe = addOxwm(b, target, optimize, lua, exe_options, gestures);
38 b.installArtifact(exe); 20 b.installArtifact(exe);
39 21
22 + const bsd_options = b.addOptions();
23 + bsd_options.addOption([]const u8, "version", zon.version);
24 + bsd_options.addOption(bool, "gestures", false);
25 + const bsd_exe = addOxwm(b, target, optimize, lua, bsd_options, false);
26 + const bsd_install = b.addInstallArtifact(bsd_exe, .{});
27 + for ([_][]const u8{ "openbsd", "freebsd", "netbsd", "bsd" }) |name| {
28 + const bsd_step = b.step(name, "Build oxwm without Linux-only features (libinput gestures)");
29 + bsd_step.dependOn(&bsd_install.step);
30 + }
31 +
40 const run_step = b.step("run", "Run oxwm"); 32 const run_step = b.step("run", "Run oxwm");
41 const run_cmd = b.addRunArtifact(exe); 33 const run_cmd = b.addRunArtifact(exe);
42 run_step.dependOn(&run_cmd.step); 34 run_step.dependOn(&run_cmd.step);
@@ -71,6 +63,11 @@ pub fn build(b: *std.Build) void {
71 src_main_unit_tests.root_module.linkSystemLibrary("Xinerama", .{}); 63 src_main_unit_tests.root_module.linkSystemLibrary("Xinerama", .{});
72 src_main_unit_tests.root_module.linkSystemLibrary("Xft", .{}); 64 src_main_unit_tests.root_module.linkSystemLibrary("Xft", .{});
73 src_main_unit_tests.root_module.linkSystemLibrary("fontconfig", .{}); 65 src_main_unit_tests.root_module.linkSystemLibrary("fontconfig", .{});
66 + src_main_unit_tests.root_module.addOptions("build_options", exe_options);
67 + if (gestures) {
68 + src_main_unit_tests.root_module.linkSystemLibrary("libinput", .{});
69 + src_main_unit_tests.root_module.linkSystemLibrary("libudev", .{});
70 + }
74 test_step.dependOn(&b.addRunArtifact(src_main_unit_tests).step); 71 test_step.dependOn(&b.addRunArtifact(src_main_unit_tests).step);
75 72
76 const lua_config_tests = b.addTest(.{ 73 const lua_config_tests = b.addTest(.{
@@ -138,6 +135,50 @@ pub fn build(b: *std.Build) void {
138 }).step); 135 }).step);
139 } 136 }
140 137
138 +fn isBsd(tag: std.Target.Os.Tag) bool {
139 + return switch (tag) {
140 + .freebsd, .openbsd, .netbsd, .dragonfly => true,
141 + else => false,
142 + };
143 +}
144 +
145 +fn addOxwm(
146 + b: *std.Build,
147 + target: std.Build.ResolvedTarget,
148 + optimize: std.builtin.OptimizeMode,
149 + lua: *std.Build.Step.Compile,
150 + options: *std.Build.Step.Options,
151 + gestures: bool,
152 +) *std.Build.Step.Compile {
153 + const exe = b.addExecutable(.{
154 + .name = "oxwm",
155 + .root_module = b.createModule(.{
156 + .root_source_file = b.path("src/main.zig"),
157 + .target = target,
158 + .optimize = optimize,
159 + .link_libc = true,
160 + }),
161 + });
162 +
163 + exe.root_module.addOptions("build_options", options);
164 + exe.root_module.addAnonymousImport("templates/config.lua", .{
165 + .root_source_file = b.path("templates/config.lua"),
166 + });
167 +
168 + exe.use_lld = false;
169 +
170 + exe.root_module.linkLibrary(lua);
171 + exe.root_module.linkSystemLibrary("X11", .{});
172 + exe.root_module.linkSystemLibrary("Xinerama", .{});
173 + exe.root_module.linkSystemLibrary("Xft", .{});
174 + exe.root_module.linkSystemLibrary("fontconfig", .{});
175 + if (gestures) {
176 + exe.root_module.linkSystemLibrary("libinput", .{});
177 + exe.root_module.linkSystemLibrary("libudev", .{});
178 + }
179 + return exe;
180 +}
181 +
141 fn addXephyrRun(b: *std.Build, exe: *std.Build.Step.Compile, multimon: bool) *std.Build.Step.Run { 182 fn addXephyrRun(b: *std.Build, exe: *std.Build.Step.Compile, multimon: bool) *std.Build.Step.Run {
142 const kill_cmd = if (multimon) 183 const kill_cmd = if (multimon)
143 "pkill -9 Xephyr || true; Xephyr +xinerama -glamor -screen 640x480 -screen 640x480 :2 & sleep 1" 184 "pkill -9 Xephyr || true; Xephyr +xinerama -glamor -screen 640x480 -screen 640x480 :2 & sleep 1"
+4 −0 default.nix
@@ -10,6 +10,8 @@
10 lua5_4, 10 lua5_4,
11 freetype, 11 freetype,
12 fontconfig, 12 fontconfig,
13 + libinput,
14 + udev,
13 gitRev ? "unknown", 15 gitRev ? "unknown",
14 }: 16 }:
15 stdenv.mkDerivation (finalAttrs: { 17 stdenv.mkDerivation (finalAttrs: {
@@ -29,6 +31,8 @@ stdenv.mkDerivation (finalAttrs: {
29 lua5_4 31 lua5_4
30 freetype 32 freetype
31 fontconfig 33 fontconfig
34 + libinput
35 + udev
32 ]; 36 ];
33 37
34 postInstall = '' 38 postInstall = ''
+1 −1 resources/PKGBUILD
@@ -7,7 +7,7 @@ arch=('x86_64')
7 url="https://github.com/tonybanters/oxwm" 7 url="https://github.com/tonybanters/oxwm"
8 pkgdesc="DWM but better with sane defaults, and not suckless." 8 pkgdesc="DWM but better with sane defaults, and not suckless."
9 license=('GPL-3.0-or-later') 9 license=('GPL-3.0-or-later')
10 -depends=('libx11' 'libxft' 'libxcb' 'fontconfig' 'freetype2' 'libxrender') 10 +depends=('libx11' 'libxft' 'libxcb' 'fontconfig' 'freetype2' 'libxrender' 'libinput' 'systemd-libs')
11 makedepends=('cargo' 'git') 11 makedepends=('cargo' 'git')
12 provides=('oxwm') 12 provides=('oxwm')
13 conflicts=('oxwm') 13 conflicts=('oxwm')
+45 −0 src/animations.zig
@@ -22,6 +22,13 @@ pub const AnimationConfig = struct {
22 easing: Easing = .ease_out, 22 easing: Easing = .ease_out,
23 }; 23 };
24 24
25 +pub const SpringConfig = struct {
26 + stiffness: f64 = 800.0,
27 + damping_ratio: f64 = 1.0,
28 + epsilon: f64 = 0.5,
29 + max_duration_ms: i64 = 2000,
30 +};
31 +
25 pub const ScrollAnimation = struct { 32 pub const ScrollAnimation = struct {
26 start_value: i32 = 0, 33 start_value: i32 = 0,
27 end_value: i32 = 0, 34 end_value: i32 = 0,
@@ -29,6 +36,9 @@ pub const ScrollAnimation = struct {
29 duration_ms: u64 = 150, 36 duration_ms: u64 = 150,
30 easing: Easing = .ease_out, 37 easing: Easing = .ease_out,
31 active: bool = false, 38 active: bool = false,
39 + spring: bool = false,
40 + velocity: f64 = 0,
41 + spring_config: SpringConfig = .{},
32 42
33 pub fn start(self: *ScrollAnimation, io: std.Io, from: i32, to: i32, config: AnimationConfig) void { 43 pub fn start(self: *ScrollAnimation, io: std.Io, from: i32, to: i32, config: AnimationConfig) void {
34 if (from == to) { 44 if (from == to) {
@@ -40,15 +50,50 @@ pub const ScrollAnimation = struct {
40 self.start_time = std.Io.Timestamp.now(io, .awake).toMilliseconds(); 50 self.start_time = std.Io.Timestamp.now(io, .awake).toMilliseconds();
41 self.duration_ms = config.duration_ms; 51 self.duration_ms = config.duration_ms;
42 self.easing = config.easing; 52 self.easing = config.easing;
53 + self.spring = false;
54 + self.active = true;
55 + }
56 +
57 + /// Starts a critically damped spring from `from` to `to` that carries
58 + /// the initial `velocity` (in pixels per second) into the motion.
59 + pub fn startSpring(self: *ScrollAnimation, io: std.Io, from: i32, to: i32, velocity: f64, config: SpringConfig) void {
60 + if (from == to) {
61 + self.active = false;
62 + return;
63 + }
64 + self.start_value = from;
65 + self.end_value = to;
66 + self.start_time = std.Io.Timestamp.now(io, .awake).toMilliseconds();
67 + self.velocity = velocity;
68 + self.spring_config = config;
69 + self.spring = true;
43 self.active = true; 70 self.active = true;
44 } 71 }
45 72
73 + fn springPosition(self: *const ScrollAnimation, elapsed_ms: i64) f64 {
74 + const t = @as(f64, @floatFromInt(elapsed_ms)) / 1000.0;
75 + const beta = self.spring_config.damping_ratio * @sqrt(self.spring_config.stiffness);
76 + const to: f64 = @floatFromInt(self.end_value);
77 + const x0 = @as(f64, @floatFromInt(self.start_value)) - to;
78 + return to + @exp(-beta * t) * (x0 + (beta * x0 + self.velocity) * t);
79 + }
80 +
46 pub fn update(self: *ScrollAnimation, io: std.Io) ?i32 { 81 pub fn update(self: *ScrollAnimation, io: std.Io) ?i32 {
47 if (!self.active) return null; 82 if (!self.active) return null;
48 83
49 const now = std.Io.Timestamp.now(io, .awake).toMilliseconds(); 84 const now = std.Io.Timestamp.now(io, .awake).toMilliseconds();
50 const elapsed = now - self.start_time; 85 const elapsed = now - self.start_time;
51 86
87 + if (self.spring) {
88 + const pos = self.springPosition(elapsed);
89 + const settled = @abs(pos - @as(f64, @floatFromInt(self.end_value))) < self.spring_config.epsilon;
90 + if (settled or elapsed > self.spring_config.max_duration_ms) {
91 + self.active = false;
92 + return self.end_value;
93 + }
94 + return @intFromFloat(pos);
95 + }
96 +
52 if (elapsed >= @as(i64, @intCast(self.duration_ms))) { 97 if (elapsed >= @as(i64, @intCast(self.duration_ms))) {
53 self.active = false; 98 self.active = false;
54 return self.end_value; 99 return self.end_value;
+46 −0 src/bar/bar.zig
@@ -4,6 +4,8 @@ const monitor_mod = @import("../monitor.zig");
4 const blocks_mod = @import("blocks/blocks.zig"); 4 const blocks_mod = @import("blocks/blocks.zig");
5 const config_mod = @import("../config/config.zig"); 5 const config_mod = @import("../config/config.zig");
6 const systray_mod = @import("systray.zig"); 6 const systray_mod = @import("systray.zig");
7 +const client_mod = @import("../client.zig");
8 +const scrolling = @import("../layouts/scrolling.zig");
7 const ColorScheme = config_mod.ColorScheme; 9 const ColorScheme = config_mod.ColorScheme;
8 10
9 const Monitor = monitor_mod.Monitor; 11 const Monitor = monitor_mod.Monitor;
@@ -232,6 +234,10 @@ pub const Bar = struct {
232 self.drawText(display, x_position, @divTrunc(self.height + self.font_height, 2) - 4, layout_symbol, self.scheme_normal.foreground); 234 self.drawText(display, x_position, @divTrunc(self.height + self.font_height, 2) - 4, layout_symbol, self.scheme_normal.foreground);
233 x_position += self.textWidth(display, layout_symbol) + padding; 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 const systray_width: i32 = if (self.systray) |tray| tray.width() else 0; 241 const systray_width: i32 = if (self.systray) |tray| tray.width() else 0;
236 var block_x: i32 = self.width - padding - systray_width; 242 var block_x: i32 = self.width - padding - systray_width;
237 if (systray_width > 0) block_x -= padding; 243 if (systray_width > 0) block_x -= padding;
@@ -311,6 +317,46 @@ pub const Bar = struct {
311 if (changed) self.needs_redraw = true; 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 fn fillRect(self: *Bar, display: *xlib.Display, x: i32, y: i32, width: i32, height: i32, color: c_ulong) void { 360 fn fillRect(self: *Bar, display: *xlib.Display, x: i32, y: i32, width: i32, height: i32, color: c_ulong) void {
315 _ = xlib.XSetForeground(display, self.graphics_context, color); 361 _ = xlib.XSetForeground(display, self.graphics_context, color);
316 _ = xlib.XFillRectangle(display, self.pixmap, self.graphics_context, x, y, @intCast(width), @intCast(height)); 362 _ = xlib.XFillRectangle(display, self.pixmap, self.graphics_context, x, y, @intCast(width), @intCast(height));
+1 −0 src/client.zig
@@ -33,6 +33,7 @@ pub const Client = struct {
33 never_focus: bool = false, 33 never_focus: bool = false,
34 old_state: bool = false, 34 old_state: bool = false,
35 is_fullscreen: bool = false, 35 is_fullscreen: bool = false,
36 + scroll_width: f32 = 0,
36 rule_fullscreen: bool = false, 37 rule_fullscreen: bool = false,
37 next: ?*Client = null, 38 next: ?*Client = null,
38 stack_next: ?*Client = null, 39 stack_next: ?*Client = null,
+13 −0 src/config/config.zig
@@ -35,6 +35,8 @@ pub const Action = enum {
35 send_to_monitor, 35 send_to_monitor,
36 scroll_left, 36 scroll_left,
37 scroll_right, 37 scroll_right,
38 + cycle_width,
39 + set_width,
38 }; 40 };
39 41
40 pub const KeyPress = struct { 42 pub const KeyPress = struct {
@@ -59,6 +61,7 @@ pub const Rule = struct {
59 is_fullscreen: bool, 61 is_fullscreen: bool,
60 monitor: i32, 62 monitor: i32,
61 focus: bool, 63 focus: bool,
64 + width: f32 = 0,
62 }; 65 };
63 66
64 pub const BlockType = enum { 67 pub const BlockType = enum {
@@ -223,6 +226,16 @@ pub const Config = struct {
223 warp_cursor_to_monitor: bool = false, 226 warp_cursor_to_monitor: bool = false,
224 warp_cursor_on_send: bool = false, 227 warp_cursor_on_send: bool = false,
225 228
229 + scroll_default_width: f32 = 0.5,
230 + scroll_width_presets: [8]f32 = .{ 1.0 / 3.0, 0.5, 2.0 / 3.0, 0, 0, 0, 0, 0 },
231 + scroll_width_preset_count: u32 = 3,
232 + gesture_enabled: bool = false,
233 + gesture_fingers: u32 = 3,
234 + gesture_speed: f32 = 2.0,
235 + gesture_natural: bool = false,
236 + scroll_indicator: bool = true,
237 + scroll_indicator_width: i32 = 0,
238 +
226 layout_tile_symbol: []const u8 = "[]=", 239 layout_tile_symbol: []const u8 = "[]=",
227 layout_monocle_symbol: []const u8 = "[M]", 240 layout_monocle_symbol: []const u8 = "[M]",
228 layout_floating_symbol: []const u8 = "><>", 241 layout_floating_symbol: []const u8 = "><>",
+140 −0 src/config/lua.zig
@@ -89,6 +89,7 @@ fn registerApi() void {
89 registerBorderModule(state); 89 registerBorderModule(state);
90 registerClientModule(state); 90 registerClientModule(state);
91 registerLayoutModule(state); 91 registerLayoutModule(state);
92 + registerScrollModule(state);
92 registerTagModule(state); 93 registerTagModule(state);
93 registerMonitorModule(state); 94 registerMonitorModule(state);
94 registerRuleModule(state); 95 registerRuleModule(state);
@@ -193,9 +194,45 @@ fn registerLayoutModule(state: *c.lua_State) void {
193 c.lua_pushcfunction(state, luaLayoutScrollRight); 194 c.lua_pushcfunction(state, luaLayoutScrollRight);
194 c.lua_setfield(state, -2, "scroll_right"); 195 c.lua_setfield(state, -2, "scroll_right");
195 196
197 + c.lua_pushcfunction(state, luaLayoutCycleWidth);
198 + c.lua_setfield(state, -2, "cycle_width");
199 +
200 + c.lua_pushcfunction(state, luaLayoutSetWidth);
201 + c.lua_setfield(state, -2, "set_width");
202 +
196 c.lua_setfield(state, -2, "layout"); 203 c.lua_setfield(state, -2, "layout");
197 } 204 }
198 205
206 +fn registerScrollModule(state: *c.lua_State) void {
207 + c.lua_createtable(state, 0, 6);
208 +
209 + c.lua_pushcfunction(state, luaScrollSetDefaultWidth);
210 + c.lua_setfield(state, -2, "set_default_width");
211 +
212 + c.lua_pushcfunction(state, luaScrollSetWidthPresets);
213 + c.lua_setfield(state, -2, "set_width_presets");
214 +
215 + c.lua_pushcfunction(state, luaScrollSetGestureEnabled);
216 + c.lua_setfield(state, -2, "set_gesture_enabled");
217 +
218 + c.lua_pushcfunction(state, luaScrollSetGestureFingers);
219 + c.lua_setfield(state, -2, "set_gesture_fingers");
220 +
221 + c.lua_pushcfunction(state, luaScrollSetGestureSpeed);
222 + c.lua_setfield(state, -2, "set_gesture_speed");
223 +
224 + c.lua_pushcfunction(state, luaScrollSetGestureNatural);
225 + c.lua_setfield(state, -2, "set_gesture_natural");
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 +
233 + c.lua_setfield(state, -2, "scroll");
234 +}
235 +
199 fn registerTagModule(state: *c.lua_State) void { 236 fn registerTagModule(state: *c.lua_State) void {
200 c.lua_createtable(state, 0, 10); 237 c.lua_createtable(state, 0, 10);
201 238
@@ -639,6 +676,100 @@ fn luaLayoutScrollRight(state: ?*c.lua_State) callconv(.c) c_int {
639 return 1; 676 return 1;
640 } 677 }
641 678
679 +fn luaLayoutCycleWidth(state: ?*c.lua_State) callconv(.c) c_int {
680 + const s = state orelse return 0;
681 + var isnum: c_int = 0;
682 + const raw = c.lua_tointegerx(s, 1, &isnum);
683 + const dir: i32 = if (isnum != 0) @intCast(raw) else 1;
684 + createActionTableWithInt(s, "CycleWidth", dir);
685 + return 1;
686 +}
687 +
688 +fn luaLayoutSetWidth(state: ?*c.lua_State) callconv(.c) c_int {
689 + const s = state orelse return 0;
690 + var isnum: c_int = 0;
691 + const value = c.lua_tonumberx(s, 1, &isnum);
692 + const permille: i32 = if (isnum != 0 and value > 0) @intFromFloat(@round(value * 1000.0)) else 0;
693 + createActionTableWithInt(s, "SetWidth", permille);
694 + return 1;
695 +}
696 +
697 +fn luaScrollSetDefaultWidth(state: ?*c.lua_State) callconv(.c) c_int {
698 + const cfg = config orelse return 0;
699 + const s = state orelse return 0;
700 + var isnum: c_int = 0;
701 + const value = c.lua_tonumberx(s, 1, &isnum);
702 + if (isnum != 0 and value > 0) cfg.scroll_default_width = @floatCast(value);
703 + return 0;
704 +}
705 +
706 +fn luaScrollSetWidthPresets(state: ?*c.lua_State) callconv(.c) c_int {
707 + const cfg = config orelse return 0;
708 + const s = state orelse return 0;
709 + if (c.lua_type(s, 1) != c.LUA_TTABLE) return 0;
710 +
711 + const len = c.lua_rawlen(s, 1);
712 + var count: u32 = 0;
713 + var i: c_longlong = 1;
714 + while (i <= len and count < cfg.scroll_width_presets.len) : (i += 1) {
715 + _ = c.lua_rawgeti(s, 1, i);
716 + var isnum: c_int = 0;
717 + const value = c.lua_tonumberx(s, -1, &isnum);
718 + c.lua_settop(s, -2);
719 + if (isnum == 0 or value <= 0) continue;
720 + cfg.scroll_width_presets[count] = @floatCast(value);
721 + count += 1;
722 + }
723 + if (count > 0) cfg.scroll_width_preset_count = count;
724 + return 0;
725 +}
726 +
727 +fn luaScrollSetGestureEnabled(state: ?*c.lua_State) callconv(.c) c_int {
728 + const cfg = config orelse return 0;
729 + const s = state orelse return 0;
730 + cfg.gesture_enabled = c.lua_toboolean(s, 1) != 0;
731 + return 0;
732 +}
733 +
734 +fn luaScrollSetGestureFingers(state: ?*c.lua_State) callconv(.c) c_int {
735 + const cfg = config orelse return 0;
736 + const s = state orelse return 0;
737 + const value = c.lua_tointegerx(s, 1, null);
738 + if (value >= 3 and value <= 5) cfg.gesture_fingers = @intCast(value);
739 + return 0;
740 +}
741 +
742 +fn luaScrollSetGestureSpeed(state: ?*c.lua_State) callconv(.c) c_int {
743 + const cfg = config orelse return 0;
744 + const s = state orelse return 0;
745 + var isnum: c_int = 0;
746 + const value = c.lua_tonumberx(s, 1, &isnum);
747 + if (isnum != 0 and value > 0) cfg.gesture_speed = @floatCast(value);
748 + return 0;
749 +}
750 +
751 +fn luaScrollSetGestureNatural(state: ?*c.lua_State) callconv(.c) c_int {
752 + const cfg = config orelse return 0;
753 + const s = state orelse return 0;
754 + cfg.gesture_natural = c.lua_toboolean(s, 1) != 0;
755 + return 0;
756 +}
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 +
642 fn luaTagView(state: ?*c.lua_State) callconv(.c) c_int { 773 fn luaTagView(state: ?*c.lua_State) callconv(.c) c_int {
643 const s = state orelse return 0; 774 const s = state orelse return 0;
644 const idx: i32 = @intCast(c.lua_tointegerx(s, 1, null)); 775 const idx: i32 = @intCast(c.lua_tointegerx(s, 1, null));
@@ -794,6 +925,13 @@ fn luaRuleAdd(state: ?*c.lua_State) callconv(.c) c_int {
794 } 925 }
795 c.lua_settop(s, -2); 926 c.lua_settop(s, -2);
796 927
928 + _ = c.lua_getfield(s, 1, "width");
929 + if (c.lua_type(s, -1) == c.LUA_TNUMBER) {
930 + const width = c.lua_tonumberx(s, -1, null);
931 + if (width > 0) rule.width = @floatCast(width);
932 + }
933 + c.lua_settop(s, -2);
934 +
797 cfg.addRule(rule) catch return 0; 935 cfg.addRule(rule) catch return 0;
798 return 0; 936 return 0;
799 } 937 }
@@ -1428,6 +1566,8 @@ fn parseAction(name: []const u8) ?Action {
1428 .{ "TagMonitor", Action.send_to_monitor }, 1566 .{ "TagMonitor", Action.send_to_monitor },
1429 .{ "ScrollLeft", Action.scroll_left }, 1567 .{ "ScrollLeft", Action.scroll_left },
1430 .{ "ScrollRight", Action.scroll_right }, 1568 .{ "ScrollRight", Action.scroll_right },
1569 + .{ "CycleWidth", Action.cycle_width },
1570 + .{ "SetWidth", Action.set_width },
1431 }; 1571 };
1432 1572
1433 inline for (action_map) |entry| { 1573 inline for (action_map) |entry| {
+127 −0 src/input/gesture.zig new file mode 100644
@@ -0,0 +1,127 @@
1 +const std = @import("std");
2 +const build_options = @import("build_options");
3 +
4 +pub const enabled = build_options.gestures;
5 +
6 +const c = if (enabled) @cImport({
7 + @cInclude("libinput.h");
8 + @cInclude("libudev.h");
9 +}) else struct {};
10 +
11 +extern "c" fn open(path: [*:0]const u8, flags: c_int, ...) c_int;
12 +extern "c" fn close(fd: c_int) c_int;
13 +
14 +pub const Kind = enum {
15 + begin,
16 + update,
17 + end,
18 +};
19 +
20 +pub const Event = struct {
21 + kind: Kind,
22 + fingers: u32,
23 + dx: f64 = 0,
24 + dy: f64 = 0,
25 + cancelled: bool = false,
26 +};
27 +
28 +pub const GestureError = error{
29 + Disabled,
30 + UdevFailed,
31 + ContextFailed,
32 + SeatFailed,
33 +};
34 +
35 +pub const Gestures = if (enabled) LibinputGestures else StubGestures;
36 +
37 +fn openRestricted(path: [*c]const u8, flags: c_int, user_data: ?*anyopaque) callconv(.c) c_int {
38 + _ = user_data;
39 + const fd = open(path, flags);
40 + if (fd < 0) return -@as(c_int, @intCast(@intFromEnum(std.posix.errno(fd))));
41 + return fd;
42 +}
43 +
44 +fn closeRestricted(fd: c_int, user_data: ?*anyopaque) callconv(.c) void {
45 + _ = user_data;
46 + _ = close(fd);
47 +}
48 +
49 +var interface = if (enabled) c.struct_libinput_interface{
50 + .open_restricted = openRestricted,
51 + .close_restricted = closeRestricted,
52 +} else {};
53 +
54 +const LibinputGestures = struct {
55 + udev: *c.struct_udev,
56 + li: *c.struct_libinput,
57 + fd: c_int,
58 +
59 + pub fn init() GestureError!LibinputGestures {
60 + const udev = c.udev_new() orelse return GestureError.UdevFailed;
61 + const li = c.libinput_udev_create_context(&interface, null, udev) orelse {
62 + _ = c.udev_unref(udev);
63 + return GestureError.ContextFailed;
64 + };
65 + c.libinput_log_set_priority(li, c.LIBINPUT_LOG_PRIORITY_ERROR);
66 + if (c.libinput_udev_assign_seat(li, "seat0") != 0) {
67 + _ = c.libinput_unref(li);
68 + _ = c.udev_unref(udev);
69 + return GestureError.SeatFailed;
70 + }
71 + return LibinputGestures{
72 + .udev = udev,
73 + .li = li,
74 + .fd = c.libinput_get_fd(li),
75 + };
76 + }
77 +
78 + pub fn deinit(self: *LibinputGestures) void {
79 + _ = c.libinput_unref(self.li);
80 + _ = c.udev_unref(self.udev);
81 + }
82 +
83 + /// Drains pending libinput events and calls `callback` for every swipe.
84 + pub fn dispatch(self: *LibinputGestures, context: anytype, comptime callback: fn (@TypeOf(context), Event) void) void {
85 + if (c.libinput_dispatch(self.li) != 0) return;
86 + while (c.libinput_get_event(self.li)) |event| {
87 + defer c.libinput_event_destroy(event);
88 + const kind: Kind = switch (c.libinput_event_get_type(event)) {
89 + c.LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN => .begin,
90 + c.LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE => .update,
91 + c.LIBINPUT_EVENT_GESTURE_SWIPE_END => .end,
92 + else => continue,
93 + };
94 + const gesture = c.libinput_event_get_gesture_event(event) orelse continue;
95 + var ev = Event{
96 + .kind = kind,
97 + .fingers = @intCast(@max(0, c.libinput_event_gesture_get_finger_count(gesture))),
98 + };
99 + switch (kind) {
100 + .update => {
101 + ev.dx = c.libinput_event_gesture_get_dx(gesture);
102 + ev.dy = c.libinput_event_gesture_get_dy(gesture);
103 + },
104 + .end => ev.cancelled = c.libinput_event_gesture_get_cancelled(gesture) != 0,
105 + .begin => {},
106 + }
107 + callback(context, ev);
108 + }
109 + }
110 +};
111 +
112 +const StubGestures = struct {
113 + fd: c_int = -1,
114 +
115 + pub fn init() GestureError!StubGestures {
116 + return GestureError.Disabled;
117 + }
118 +
119 + pub fn deinit(self: *StubGestures) void {
120 + _ = self;
121 + }
122 +
123 + pub fn dispatch(self: *StubGestures, context: anytype, comptime callback: fn (@TypeOf(context), Event) void) void {
124 + _ = self;
125 + _ = callback;
126 + }
127 +};
+116 −82 src/layouts/scrolling.zig
@@ -1,7 +1,6 @@
1 const std = @import("std"); 1 const std = @import("std");
2 const client_mod = @import("../client.zig"); 2 const client_mod = @import("../client.zig");
3 const monitor_mod = @import("../monitor.zig"); 3 const monitor_mod = @import("../monitor.zig");
4 -const xlib = @import("../x11/xlib.zig");
5 const tiling = @import("tiling.zig"); 4 const tiling = @import("tiling.zig");
6 5
7 const Client = client_mod.Client; 6 const Client = client_mod.Client;
@@ -12,109 +11,144 @@ pub const layout = monitor_mod.Layout{
12 .arrange_fn = scroll, 11 .arrange_fn = scroll,
13 }; 12 };
14 13
15 -pub fn scroll(monitor: *Monitor) void { 14 +pub const Snap = struct {
16 - var client_count: u32 = 0; 15 + client: *Client,
17 - var current = client_mod.nextTiled(monitor.clients); 16 + offset: i32,
18 - while (current) |_| : (current = client_mod.nextTiled(current.?.next)) { 17 + width: i32,
19 - client_count += 1; 18 +};
20 - }
21 -
22 - if (client_count == 0) return;
23 19
24 - const gap_outer_h = if (monitor.smartgaps_enabled and client_count == 1) 0 else monitor.gap_outer_h; 20 +pub const Geometry = struct {
25 - const gap_outer_v = if (monitor.smartgaps_enabled and client_count == 1) 0 else monitor.gap_outer_v; 21 + outer_h: i32,
26 - const gap_inner_v = monitor.gap_inner_v; 22 + outer_v: i32,
23 + inner: i32,
24 + available_w: i32,
25 + available_h: i32,
26 + count: u32,
27 +};
27 28
28 - const visible_count: u32 = @intCast(@max(1, monitor.nmaster)); 29 +pub fn tiledCount(monitor: *Monitor) u32 {
29 - const available_width = monitor.win_w - 2 * gap_outer_v; 30 + var count: u32 = 0;
30 - const available_height = monitor.win_h - 2 * gap_outer_h; 31 + var current = client_mod.nextTiled(monitor.clients);
32 + while (current) |client| : (current = client_mod.nextTiled(client.next)) {
33 + count += 1;
34 + }
35 + return count;
36 +}
31 37
32 - const total_gaps = gap_inner_v * @as(i32, @intCast(if (visible_count > 1) visible_count - 1 else 0)); 38 +pub fn geometry(monitor: *Monitor) Geometry {
33 - const window_width = @divTrunc(available_width - total_gaps, @as(i32, @intCast(visible_count))); 39 + const count = tiledCount(monitor);
40 + const smart = monitor.smartgaps_enabled and count == 1;
41 + const outer_h = if (smart) 0 else monitor.gap_outer_h;
42 + const outer_v = if (smart) 0 else monitor.gap_outer_v;
43 + return .{
44 + .outer_h = outer_h,
45 + .outer_v = outer_v,
46 + .inner = monitor.gap_inner_v,
47 + .available_w = monitor.win_w - 2 * outer_v,
48 + .available_h = monitor.win_h - 2 * outer_h,
49 + .count = count,
50 + };
51 +}
34 52
35 - var x_pos: i32 = monitor.win_x + gap_outer_v - monitor.scroll_offset; 53 +pub fn windowWidth(monitor: *Monitor, client: *Client, geo: Geometry) i32 {
36 - const y_pos: i32 = monitor.win_y + gap_outer_h; 54 + const value: f32 = if (client.scroll_width > 0) client.scroll_width else monitor.scroll_default_width;
37 - const height = available_height; 55 + const available: f32 = @floatFromInt(geo.available_w);
56 + const inner: f32 = @floatFromInt(geo.inner);
57 + const width: i32 = if (value > 1.0)
58 + @intFromFloat(value)
59 + else
60 + @intFromFloat((available + inner) * value - inner);
61 + return @max(1, @min(width, geo.available_w));
62 +}
38 63
39 - var index: u32 = 0; 64 +pub fn contentWidth(monitor: *Monitor) i32 {
40 - current = client_mod.nextTiled(monitor.clients); 65 + const geo = geometry(monitor);
66 + var offset: i32 = 0;
67 + var current = client_mod.nextTiled(monitor.clients);
41 while (current) |client| : (current = client_mod.nextTiled(client.next)) { 68 while (current) |client| : (current = client_mod.nextTiled(client.next)) {
42 - const window_right = x_pos + window_width; 69 + offset += windowWidth(monitor, client, geo) + geo.inner;
43 - const screen_left = monitor.win_x;
44 - const screen_right = monitor.win_x + monitor.win_w;
45 - const is_visible = window_right > screen_left and x_pos < screen_right;
46 -
47 - if (is_visible) {
48 - tiling.resize(
49 - client,
50 - x_pos,
51 - y_pos,
52 - window_width - 2 * client.border_width,
53 - height - 2 * client.border_width,
54 - false,
55 - );
56 - } else {
57 - tiling.resizeClient(
58 - client,
59 - -2 * window_width,
60 - y_pos,
61 - window_width - 2 * client.border_width,
62 - height - 2 * client.border_width,
63 - );
64 - }
65 - x_pos += window_width + gap_inner_v;
66 - index += 1;
67 } 70 }
71 + return @max(0, offset - geo.inner);
72 +}
73 +
74 +pub fn maxScroll(monitor: *Monitor) i32 {
75 + const geo = geometry(monitor);
76 + return @max(0, contentWidth(monitor) - geo.available_w);
68 } 77 }
69 78
70 -pub fn getScrollStep(monitor: *Monitor) i32 { 79 +pub fn snapFor(monitor: *Monitor, target: *Client) ?Snap {
71 - var client_count: u32 = 0; 80 + const geo = geometry(monitor);
81 + const max = maxScroll(monitor);
82 + var offset: i32 = 0;
72 var current = client_mod.nextTiled(monitor.clients); 83 var current = client_mod.nextTiled(monitor.clients);
73 - while (current) |_| : (current = client_mod.nextTiled(current.?.next)) { 84 + while (current) |client| : (current = client_mod.nextTiled(client.next)) {
74 - client_count += 1; 85 + const width = windowWidth(monitor, client, geo);
86 + if (client == target) return .{ .client = client, .offset = @min(offset, max), .width = width };
87 + offset += width + geo.inner;
75 } 88 }
76 - 89 + return null;
77 - const gap_outer_v = if (monitor.smartgaps_enabled and client_count == 1) 0 else monitor.gap_outer_v;
78 - const gap_inner_v = monitor.gap_inner_v;
79 - const visible_count: u32 = @intCast(@max(1, monitor.nmaster));
80 - const available_width = monitor.win_w - 2 * gap_outer_v;
81 - const total_gaps = gap_inner_v * @as(i32, @intCast(if (visible_count > 1) visible_count - 1 else 0));
82 - const window_width = @divTrunc(available_width - total_gaps, @as(i32, @intCast(visible_count)));
83 - return window_width + gap_inner_v;
84 } 90 }
85 91
86 -pub fn getMaxScroll(monitor: *Monitor) i32 { 92 +pub fn offsetToReveal(monitor: *Monitor, offset: i32, target: *Client) i32 {
87 - var client_count: u32 = 0; 93 + const geo = geometry(monitor);
94 + const max = maxScroll(monitor);
95 + var left: i32 = 0;
88 var current = client_mod.nextTiled(monitor.clients); 96 var current = client_mod.nextTiled(monitor.clients);
89 - while (current) |_| : (current = client_mod.nextTiled(current.?.next)) { 97 + while (current) |client| : (current = client_mod.nextTiled(client.next)) {
90 - client_count += 1; 98 + const width = windowWidth(monitor, client, geo);
99 + if (client == target) {
100 + var result = offset;
101 + if (left < offset) {
102 + result = left;
103 + } else if (left + width > offset + geo.available_w) {
104 + result = left + width - geo.available_w;
105 + }
106 + return @max(0, @min(result, max));
107 + }
108 + left += width + geo.inner;
91 } 109 }
92 - 110 + return @max(0, @min(offset, max));
93 - const visible_count: u32 = @intCast(@max(1, monitor.nmaster));
94 - if (client_count <= visible_count) return 0;
95 -
96 - const scroll_step = getScrollStep(monitor);
97 - const scrollable = client_count - visible_count;
98 - return scroll_step * @as(i32, @intCast(scrollable));
99 } 111 }
100 112
101 -pub fn getWindowIndex(monitor: *Monitor, target: *Client) ?u32 { 113 +pub fn nearestSnap(monitor: *Monitor, position: f64) ?Snap {
102 - var index: u32 = 0; 114 + const geo = geometry(monitor);
115 + const max = maxScroll(monitor);
116 + var best: ?Snap = null;
117 + var best_dist: f64 = std.math.inf(f64);
118 + var offset: i32 = 0;
103 var current = client_mod.nextTiled(monitor.clients); 119 var current = client_mod.nextTiled(monitor.clients);
104 while (current) |client| : (current = client_mod.nextTiled(client.next)) { 120 while (current) |client| : (current = client_mod.nextTiled(client.next)) {
105 - if (client == target) return index; 121 + const width = windowWidth(monitor, client, geo);
106 - index += 1; 122 + const dist = @abs(@as(f64, @floatFromInt(offset)) - position);
123 + if (dist < best_dist) {
124 + best_dist = dist;
125 + best = .{ .client = client, .offset = @min(offset, max), .width = width };
126 + }
127 + offset += width + geo.inner;
107 } 128 }
108 - return null; 129 + return best;
109 } 130 }
110 131
111 -pub fn getTargetScrollForWindow(monitor: *Monitor, target: *Client) i32 { 132 +pub fn scroll(monitor: *Monitor) void {
112 - const index = getWindowIndex(monitor, target) orelse return 0; 133 + const geo = geometry(monitor);
113 - if (index == 0) return 0; 134 + if (geo.count == 0) return;
135 +
136 + var x_pos: i32 = monitor.win_x + geo.outer_v - monitor.scroll_offset;
137 + const y_pos: i32 = monitor.win_y + geo.outer_h;
138 + const screen_left = monitor.win_x;
139 + const screen_right = monitor.win_x + monitor.win_w;
114 140
115 - const scroll_step = getScrollStep(monitor); 141 + var current = client_mod.nextTiled(monitor.clients);
116 - const max_scroll = getMaxScroll(monitor); 142 + while (current) |client| : (current = client_mod.nextTiled(client.next)) {
143 + const width = windowWidth(monitor, client, geo);
144 + const border = 2 * client.border_width;
145 + const is_visible = x_pos + width > screen_left and x_pos < screen_right;
117 146
118 - const target_scroll = scroll_step * @as(i32, @intCast(index)); 147 + if (is_visible) {
119 - return @min(target_scroll, max_scroll); 148 + tiling.resize(client, x_pos, y_pos, width - border, geo.available_h - border, false);
149 + } else {
150 + tiling.resizeClient(client, -2 * (width + border), y_pos, width - border, geo.available_h - border);
151 + }
152 + x_pos += width + geo.inner;
153 + }
120 } 154 }
+1 −1 src/main.zig
@@ -81,7 +81,7 @@ pub fn main(init: std.process.Init) !void {
81 81
82 try runAutostartCommands(&wm); 82 try runAutostartCommands(&wm);
83 std.debug.print("entering event loop\n", .{}); 83 std.debug.print("entering event loop\n", .{});
84 - wm.run(handlers.handleEvent, window_manager.core.tickAnimations); 84 + wm.run(handlers.handleEvent, window_manager.core.tickAnimations, window_manager.core.handleGesture);
85 85
86 lua.deinit(); 86 lua.deinit();
87 std.debug.print("oxwm exiting\n", .{}); 87 std.debug.print("oxwm exiting\n", .{});
+1 −0 src/monitor.zig
@@ -39,6 +39,7 @@ pub const Monitor = struct {
39 gap_outer_v: i32 = 0, 39 gap_outer_v: i32 = 0,
40 smartgaps_enabled: bool = false, 40 smartgaps_enabled: bool = false,
41 scroll_offset: i32 = 0, 41 scroll_offset: i32 = 0,
42 + scroll_default_width: f32 = 0.5,
42 sel_tags: u32 = 0, 43 sel_tags: u32 = 0,
43 sel_lt: u32 = 0, 44 sel_lt: u32 = 0,
44 tagset: [2]u32 = .{ 1, 1 }, 45 tagset: [2]u32 = .{ 1, 1 },
+85 −0 src/wm/actions.zig
@@ -377,8 +377,91 @@ pub fn incnmaster(delta: i32, wm: *WindowManager) void {
377 std.debug.print("incnmaster: nmaster={d}\n", .{monitor.nmaster}); 377 std.debug.print("incnmaster: nmaster={d}\n", .{monitor.nmaster});
378 } 378 }
379 379
380 +fn focusedScrollClient(wm: *WindowManager) ?*Client {
381 + const monitor = wm.selected_monitor orelse return null;
382 + if (!core.isScrollingLayout(monitor)) return null;
383 + const client = monitor.sel orelse return null;
384 + if (client.is_floating) return null;
385 + return client;
386 +}
387 +
388 +fn effectiveScrollWidth(client: *Client) f32 {
389 + if (client.scroll_width > 0) return client.scroll_width;
390 + if (client.monitor) |monitor| return monitor.scroll_default_width;
391 + return 0.5;
392 +}
393 +
394 +pub fn cycleWidth(direction: i32, wm: *WindowManager) void {
395 + const client = focusedScrollClient(wm) orelse return;
396 + const monitor = client.monitor orelse return;
397 + const count: usize = @intCast(wm.config.scroll_width_preset_count);
398 + if (count == 0) return;
399 + const presets = wm.config.scroll_width_presets[0..count];
400 + const current = effectiveScrollWidth(client);
401 +
402 + var matched: ?usize = null;
403 + for (presets, 0..) |preset, index| {
404 + if (@abs(preset - current) < 0.001) matched = index;
405 + }
406 +
407 + var next: usize = 0;
408 + if (matched) |index| {
409 + const step: i32 = if (direction >= 0) 1 else -1;
410 + next = @intCast(@mod(@as(i32, @intCast(index)) + step, @as(i32, @intCast(count))));
411 + } else if (direction >= 0) {
412 + next = 0;
413 + for (presets, 0..) |preset, index| {
414 + if (preset > current) {
415 + next = index;
416 + break;
417 + }
418 + }
419 + } else {
420 + next = count - 1;
421 + var index: usize = count;
422 + while (index > 0) {
423 + index -= 1;
424 + if (presets[index] < current) {
425 + next = index;
426 + break;
427 + }
428 + }
429 + }
430 +
431 + client.scroll_width = presets[next];
432 + core.arrange(monitor, wm);
433 + std.debug.print("cycle_width: width={d:.3}\n", .{client.scroll_width});
434 +}
435 +
436 +pub fn setWidth(permille: i32, wm: *WindowManager) void {
437 + if (permille <= 0) return;
438 + const client = focusedScrollClient(wm) orelse return;
439 + const monitor = client.monitor orelse return;
440 + client.scroll_width = @as(f32, @floatFromInt(permille)) / 1000.0;
441 + core.arrange(monitor, wm);
442 + std.debug.print("set_width: width={d:.3}\n", .{client.scroll_width});
443 +}
444 +
445 +fn adjustScrollWidth(delta: f32, wm: *WindowManager) void {
446 + const client = focusedScrollClient(wm) orelse return;
447 + const monitor = client.monitor orelse return;
448 + const current = effectiveScrollWidth(client);
449 + if (current > 1.0) {
450 + const available: f32 = @floatFromInt(monitor.win_w - 2 * monitor.gap_outer_v);
451 + client.scroll_width = @max(100.0, @min(current + delta * available, available));
452 + } else {
453 + client.scroll_width = @max(0.1, @min(current + delta, 1.0));
454 + }
455 + core.arrange(monitor, wm);
456 + std.debug.print("adjust_width: width={d:.3}\n", .{client.scroll_width});
457 +}
458 +
380 pub fn setmfact(delta: f32, wm: *WindowManager) void { 459 pub fn setmfact(delta: f32, wm: *WindowManager) void {
381 const monitor = wm.selected_monitor orelse return; 460 const monitor = wm.selected_monitor orelse return;
461 + if (core.isScrollingLayout(monitor)) {
462 + adjustScrollWidth(delta, wm);
463 + return;
464 + }
382 const new_mfact = monitor.mfact + delta; 465 const new_mfact = monitor.mfact + delta;
383 if (new_mfact < 0.05 or new_mfact > 0.95) { 466 if (new_mfact < 0.05 or new_mfact > 0.95) {
384 return; 467 return;
@@ -856,5 +939,7 @@ pub fn executeAction(action: config_mod.Action, int_arg: i32, str_arg: ?[]const
856 .send_to_monitor => sendmon(int_arg, wm), 939 .send_to_monitor => sendmon(int_arg, wm),
857 .scroll_left => core.scrollLayout(-1, wm), 940 .scroll_left => core.scrollLayout(-1, wm),
858 .scroll_right => core.scrollLayout(1, wm), 941 .scroll_right => core.scrollLayout(1, wm),
942 + .cycle_width => cycleWidth(if (int_arg == 0) 1 else int_arg, wm),
943 + .set_width => setWidth(int_arg, wm),
859 } 944 }
860 } 945 }
+130 −22 src/wm/core.zig
@@ -4,6 +4,7 @@ const client_mod = @import("../client.zig");
4 const monitor_mod = @import("../monitor.zig"); 4 const monitor_mod = @import("../monitor.zig");
5 const tiling = @import("../layouts/tiling.zig"); 5 const tiling = @import("../layouts/tiling.zig");
6 const scrolling = @import("../layouts/scrolling.zig"); 6 const scrolling = @import("../layouts/scrolling.zig");
7 +const gesture_mod = @import("../input/gesture.zig");
7 const window_manager = @import("wm.zig"); 8 const window_manager = @import("wm.zig");
8 9
9 const config_mod = @import("../config/config.zig"); 10 const config_mod = @import("../config/config.zig");
@@ -104,7 +105,7 @@ pub fn manage(win: xlib.Window, window_attrs: *xlib.XWindowAttributes, wm: *Wind
104 monitor.sel = client; 105 monitor.sel = client;
105 106
106 if (isScrollingLayout(monitor)) { 107 if (isScrollingLayout(monitor)) {
107 - monitor.scroll_offset = 0; 108 + scrollToWindow(client, true, wm);
108 } 109 }
109 110
110 arrange(monitor, wm); 111 arrange(monitor, wm);
@@ -148,12 +149,9 @@ pub fn unmanage(client: *Client, destroyed: bool, wm: *WindowManager) void {
148 monitor.sel = if (next_focus) |nf| nf else monitor.stack; 149 monitor.sel = if (next_focus) |nf| nf else monitor.stack;
149 } 150 }
150 if (isScrollingLayout(monitor)) { 151 if (isScrollingLayout(monitor)) {
151 - const target = if (monitor.sel) |sel| scrolling.getTargetScrollForWindow(monitor, sel) else 0; 152 + if (wm.animation_monitor == monitor) wm.scroll_animation.stop();
152 - if (target == 0) { 153 + monitor.scroll_offset = @max(0, @min(monitor.scroll_offset, scrolling.maxScroll(monitor)));
153 - monitor.scroll_offset = scrolling.getScrollStep(monitor); 154 + if (monitor.sel) |sel| scrollToWindow(sel, true, wm);
154 - } else {
155 - monitor.scroll_offset = 0;
156 - }
157 } 155 }
158 arrange(monitor, wm); 156 arrange(monitor, wm);
159 } 157 }
@@ -267,12 +265,22 @@ pub fn restack(monitor: *Monitor, wm: *WindowManager) void {
267 265
268 pub fn arrange(monitor: *Monitor, wm: *WindowManager) void { 266 pub fn arrange(monitor: *Monitor, wm: *WindowManager) void {
269 showhide(monitor, wm); 267 showhide(monitor, wm);
268 + if (isScrollingLayout(monitor) and !scrollInMotion(monitor, wm)) {
269 + var offset: i32 = @max(0, @min(monitor.scroll_offset, scrolling.maxScroll(monitor)));
270 + if (monitor.sel) |sel| {
271 + if (!sel.is_floating and client_mod.isVisible(sel)) {
272 + offset = scrolling.offsetToReveal(monitor, offset, sel);
273 + }
274 + }
275 + monitor.scroll_offset = offset;
276 + }
270 if (monitor.lt[monitor.sel_lt]) |layout| { 277 if (monitor.lt[monitor.sel_lt]) |layout| {
271 if (layout.arrange_fn) |arrange_fn| { 278 if (layout.arrange_fn) |arrange_fn| {
272 arrange_fn(monitor); 279 arrange_fn(monitor);
273 } 280 }
274 } 281 }
275 restack(monitor, wm); 282 restack(monitor, wm);
283 + if (isScrollingLayout(monitor) and wm.config.scroll_indicator) wm.invalidateBars();
276 } 284 }
277 285
278 pub fn showhide(monitor: *Monitor, wm: *WindowManager) void { 286 pub fn showhide(monitor: *Monitor, wm: *WindowManager) void {
@@ -404,7 +412,7 @@ pub fn focusTopClient(monitor: *Monitor, wm: *WindowManager) void {
404 pub fn tickAnimations(wm: *WindowManager) void { 412 pub fn tickAnimations(wm: *WindowManager) void {
405 if (!wm.scroll_animation.isActive()) return; 413 if (!wm.scroll_animation.isActive()) return;
406 414
407 - const monitor = wm.selected_monitor orelse return; 415 + const monitor = wm.animation_monitor orelse return;
408 if (wm.scroll_animation.update(wm.io)) |new_offset| { 416 if (wm.scroll_animation.update(wm.io)) |new_offset| {
409 monitor.scroll_offset = new_offset; 417 monitor.scroll_offset = new_offset;
410 arrange(monitor, wm); 418 arrange(monitor, wm);
@@ -418,38 +426,137 @@ pub fn isScrollingLayout(monitor: *Monitor) bool {
418 return false; 426 return false;
419 } 427 }
420 428
421 -pub fn scrollLayout(direction: i32, wm: *WindowManager) void { 429 +fn animationActiveOn(monitor: *Monitor, wm: *WindowManager) bool {
422 - const monitor = wm.selected_monitor orelse return; 430 + return wm.scroll_animation.isActive() and wm.animation_monitor == monitor;
423 - if (!isScrollingLayout(monitor)) return; 431 +}
424 -
425 - const scroll_step = scrolling.getScrollStep(monitor);
426 - const max_scroll = scrolling.getMaxScroll(monitor);
427 432
428 - const current = if (wm.scroll_animation.isActive()) 433 +fn scrollInMotion(monitor: *Monitor, wm: *WindowManager) bool {
429 - wm.scroll_animation.target() 434 + return animationActiveOn(monitor, wm) or (wm.gesture.active and wm.gesture.monitor == monitor);
430 - else 435 +}
431 - monitor.scroll_offset;
432 436
433 - var target = current + direction * scroll_step; 437 +fn scrollTarget(monitor: *Monitor, wm: *WindowManager) i32 {
434 - target = @max(0, @min(target, max_scroll)); 438 + return if (animationActiveOn(monitor, wm)) wm.scroll_animation.target() else monitor.scroll_offset;
439 +}
435 440
441 +fn startScrollAnimation(monitor: *Monitor, target: i32, wm: *WindowManager) void {
442 + wm.animation_monitor = monitor;
436 wm.scroll_animation.start(wm.io, monitor.scroll_offset, target, wm.animation_config); 443 wm.scroll_animation.start(wm.io, monitor.scroll_offset, target, wm.animation_config);
437 } 444 }
438 445
446 +pub fn scrollLayout(direction: i32, wm: *WindowManager) void {
447 + const monitor = wm.selected_monitor orelse return;
448 + if (!isScrollingLayout(monitor) or wm.gesture.active) return;
449 +
450 + const first = client_mod.nextTiled(monitor.clients) orelse return;
451 + var target: ?*Client = null;
452 + if (monitor.sel) |sel| {
453 + if (!sel.is_floating and client_mod.isVisible(sel)) {
454 + if (direction > 0) {
455 + target = client_mod.nextTiled(sel.next);
456 + } else {
457 + var previous: ?*Client = null;
458 + var current: ?*Client = first;
459 + while (current) |client| : (current = client_mod.nextTiled(client.next)) {
460 + if (client == sel) break;
461 + previous = client;
462 + }
463 + target = previous;
464 + }
465 + }
466 + }
467 + const client = target orelse (if (monitor.sel == null or monitor.sel.?.is_floating) first else return);
468 +
469 + focus(client, wm);
470 + scrollToWindow(client, true, wm);
471 +}
472 +
439 pub fn scrollToWindow(client: *Client, animate: bool, wm: *WindowManager) void { 473 pub fn scrollToWindow(client: *Client, animate: bool, wm: *WindowManager) void {
440 const monitor = client.monitor orelse return; 474 const monitor = client.monitor orelse return;
441 if (!isScrollingLayout(monitor)) return; 475 if (!isScrollingLayout(monitor)) return;
476 + if (wm.gesture.active and wm.gesture.monitor == monitor) return;
442 477
443 - const target = scrolling.getTargetScrollForWindow(monitor, client); 478 + const base = scrollTarget(monitor, wm);
479 + const target = scrolling.offsetToReveal(monitor, base, client);
444 480
445 if (animate) { 481 if (animate) {
446 - wm.scroll_animation.start(wm.io, monitor.scroll_offset, target, wm.animation_config); 482 + if (target == base and animationActiveOn(monitor, wm)) return;
483 + startScrollAnimation(monitor, target, wm);
447 } else { 484 } else {
448 monitor.scroll_offset = target; 485 monitor.scroll_offset = target;
449 arrange(monitor, wm); 486 arrange(monitor, wm);
450 } 487 }
451 } 488 }
452 489
490 +fn nowMs(wm: *WindowManager) i64 {
491 + return std.Io.Timestamp.now(wm.io, .awake).toMilliseconds();
492 +}
493 +
494 +pub fn handleGesture(wm: *WindowManager, event: gesture_mod.Event) void {
495 + switch (event.kind) {
496 + .begin => gestureBegin(event, wm),
497 + .update => gestureUpdate(event, wm),
498 + .end => gestureEnd(event, wm),
499 + }
500 +}
501 +
502 +fn gestureBegin(event: gesture_mod.Event, wm: *WindowManager) void {
503 + if (event.fingers != wm.config.gesture_fingers) return;
504 + const monitor = wm.selected_monitor orelse return;
505 + if (!isScrollingLayout(monitor)) return;
506 +
507 + if (animationActiveOn(monitor, wm)) wm.scroll_animation.stop();
508 +
509 + wm.gesture = .{
510 + .active = true,
511 + .monitor = monitor,
512 + .position = @floatFromInt(monitor.scroll_offset),
513 + };
514 +}
515 +
516 +fn gestureUpdate(event: gesture_mod.Event, wm: *WindowManager) void {
517 + if (!wm.gesture.active) return;
518 + const monitor = wm.gesture.monitor orelse return;
519 + if (!isScrollingLayout(monitor)) {
520 + wm.gesture.active = false;
521 + return;
522 + }
523 +
524 + const sign: f64 = if (wm.config.gesture_natural) -1.0 else 1.0;
525 + const delta = event.dx * @as(f64, wm.config.gesture_speed) * sign;
526 +
527 + const geo = scrolling.geometry(monitor);
528 + const min_position: f64 = @floatFromInt(-geo.available_w);
529 + const max_position: f64 = @floatFromInt(scrolling.contentWidth(monitor));
530 +
531 + wm.gesture.position = @max(min_position, @min(wm.gesture.position + delta, max_position));
532 + wm.gesture.push(delta, nowMs(wm));
533 +
534 + monitor.scroll_offset = @intFromFloat(@round(wm.gesture.position));
535 + arrange(monitor, wm);
536 +}
537 +
538 +fn gestureEnd(event: gesture_mod.Event, wm: *WindowManager) void {
539 + _ = event;
540 + if (!wm.gesture.active) return;
541 + wm.gesture.active = false;
542 + const monitor = wm.gesture.monitor orelse return;
543 + if (!isScrollingLayout(monitor)) return;
544 +
545 + const velocity = wm.gesture.velocity(nowMs(wm));
546 + const deceleration = 1000.0 * @log(window_manager.gesture_deceleration);
547 + const projected = wm.gesture.position - velocity / deceleration;
548 +
549 + const snap = scrolling.nearestSnap(monitor, projected) orelse {
550 + arrange(monitor, wm);
551 + return;
552 + };
553 +
554 + focus(snap.client, wm);
555 + wm.animation_monitor = monitor;
556 + wm.scroll_animation.startSpring(wm.io, monitor.scroll_offset, snap.offset, velocity, .{});
557 + if (!wm.scroll_animation.isActive()) arrange(monitor, wm);
558 +}
559 +
453 fn positionFloating(client: *Client, monitor: *Monitor, pos: config_mod.FloatingPosition) void { 560 fn positionFloating(client: *Client, monitor: *Monitor, pos: config_mod.FloatingPosition) void {
454 const bw = 2 * client.border_width; 561 const bw = 2 * client.border_width;
455 const x: i32 = switch (pos) { 562 const x: i32 = switch (pos) {
@@ -522,6 +629,7 @@ pub fn applyRules(client: *Client, wm: *WindowManager) void {
522 client.rule_fullscreen = true; 629 client.rule_fullscreen = true;
523 } 630 }
524 client.tags |= rule.tags; 631 client.tags |= rule.tags;
632 + if (rule.width > 0) client.scroll_width = rule.width;
525 if (rule.monitor >= 0) { 633 if (rule.monitor >= 0) {
526 var target = wm.monitors; 634 var target = wm.monitors;
527 var index: i32 = 0; 635 var index: i32 = 0;
+86 −3 src/wm/wm.zig
@@ -18,6 +18,7 @@ const floating = @import("../layouts/floating.zig");
18 const scrolling = @import("../layouts/scrolling.zig"); 18 const scrolling = @import("../layouts/scrolling.zig");
19 const grid = @import("../layouts/grid.zig"); 19 const grid = @import("../layouts/grid.zig");
20 const dwindle = @import("../layouts/dwindle.zig"); 20 const dwindle = @import("../layouts/dwindle.zig");
21 +const gesture_mod = @import("../input/gesture.zig");
21 22
22 pub const core = @import("core.zig"); 23 pub const core = @import("core.zig");
23 pub const actions = @import("actions.zig"); 24 pub const actions = @import("actions.zig");
@@ -36,6 +37,50 @@ pub const WithdrawnState: c_long = 0;
36 pub const IconicState: c_long = 3; 37 pub const IconicState: c_long = 3;
37 pub const IsViewable: c_int = 2; 38 pub const IsViewable: c_int = 2;
38 39
40 +pub const gesture_deceleration: f64 = 0.997;
41 +pub const gesture_history_size = 32;
42 +pub const gesture_history_ms: i64 = 150;
43 +
44 +pub const GestureSample = struct {
45 + dx: f64,
46 + time_ms: i64,
47 +};
48 +
49 +pub const GestureState = struct {
50 + active: bool = false,
51 + monitor: ?*Monitor = null,
52 + position: f64 = 0,
53 + history: [gesture_history_size]GestureSample = undefined,
54 + history_len: usize = 0,
55 +
56 + pub fn push(self: *GestureState, dx: f64, time_ms: i64) void {
57 + if (self.history_len == gesture_history_size) {
58 + std.mem.copyForwards(GestureSample, self.history[0 .. gesture_history_size - 1], self.history[1..]);
59 + self.history_len -= 1;
60 + }
61 + self.history[self.history_len] = .{ .dx = dx, .time_ms = time_ms };
62 + self.history_len += 1;
63 + }
64 +
65 + pub fn velocity(self: *const GestureState, now_ms: i64) f64 {
66 + if (self.history_len < 2) return 0.0;
67 + const cutoff = now_ms - gesture_history_ms;
68 + var total: f64 = 0.0;
69 + var first: ?i64 = null;
70 + var last: i64 = 0;
71 + for (self.history[0..self.history_len]) |sample| {
72 + if (sample.time_ms < cutoff) continue;
73 + total += sample.dx;
74 + if (first == null) first = sample.time_ms;
75 + last = sample.time_ms;
76 + }
77 + const start = first orelse return 0.0;
78 + const span = last - start;
79 + if (span <= 0) return 0.0;
80 + return total / @as(f64, @floatFromInt(span)) * 1000.0;
81 + }
82 +};
83 +
39 pub const Cursors = struct { 84 pub const Cursors = struct {
40 normal: xlib.Cursor, 85 normal: xlib.Cursor,
41 resize: xlib.Cursor, 86 resize: xlib.Cursor,
@@ -86,6 +131,9 @@ pub const WindowManager = struct {
86 131
87 scroll_animation: animations.ScrollAnimation, 132 scroll_animation: animations.ScrollAnimation,
88 animation_config: animations.AnimationConfig, 133 animation_config: animations.AnimationConfig,
134 + animation_monitor: ?*Monitor,
135 + gesture: GestureState,
136 + gestures: ?gesture_mod.Gestures,
89 137
90 running: bool, 138 running: bool,
91 next_spawn_floating: bool = false, 139 next_spawn_floating: bool = false,
@@ -130,6 +178,9 @@ pub const WindowManager = struct {
130 .overlay = null, 178 .overlay = null,
131 .scroll_animation = .{}, 179 .scroll_animation = .{},
132 .animation_config = .{ .duration_ms = 150, .easing = .ease_out }, 180 .animation_config = .{ .duration_ms = 150, .easing = .ease_out },
181 + .animation_monitor = null,
182 + .gesture = .{},
183 + .gestures = null,
133 .running = true, 184 .running = true,
134 .last_motion_monitor = null, 185 .last_motion_monitor = null,
135 }; 186 };
@@ -137,12 +188,33 @@ pub const WindowManager = struct {
137 wm.setupMonitors(); 188 wm.setupMonitors();
138 wm.setupBars(); 189 wm.setupBars();
139 wm.setupOverlay(); 190 wm.setupOverlay();
191 + wm.syncGestures();
140 192
141 return wm; 193 return wm;
142 } 194 }
143 195
196 + pub fn syncGestures(self: *WindowManager) void {
197 + if (!gesture_mod.enabled) return;
198 + if (self.config.gesture_enabled and self.gestures == null) {
199 + self.gestures = gesture_mod.Gestures.init() catch |err| blk: {
200 + std.debug.print("touchpad gestures unavailable: {s}\n", .{@errorName(err)});
201 + break :blk null;
202 + };
203 + if (self.gestures != null) std.debug.print("touchpad gestures enabled\n", .{});
204 + } else if (!self.config.gesture_enabled and self.gestures != null) {
205 + self.gestures.?.deinit();
206 + self.gestures = null;
207 + self.gesture = .{};
208 + }
209 + }
210 +
144 /// Release all allocated memory owned by the WM. 211 /// Release all allocated memory owned by the WM.
145 pub fn deinit(self: *WindowManager) void { 212 pub fn deinit(self: *WindowManager) void {
213 + if (self.gestures) |*gestures| {
214 + gestures.deinit();
215 + self.gestures = null;
216 + }
217 +
146 bar_mod.destroyBars(self.bars, self.display.handle); 218 bar_mod.destroyBars(self.bars, self.display.handle);
147 self.bars = null; 219 self.bars = null;
148 220
@@ -416,6 +488,7 @@ pub const WindowManager = struct {
416 cfg.gap_outer_h != 0 or cfg.gap_outer_v != 0; 488 cfg.gap_outer_h != 0 or cfg.gap_outer_v != 0;
417 489
418 mon.smartgaps_enabled = cfg.smartgaps_enabled; 490 mon.smartgaps_enabled = cfg.smartgaps_enabled;
491 + mon.scroll_default_width = cfg.scroll_default_width;
419 492
420 if (cfg.gaps_enabled and any_gap_nonzero) { 493 if (cfg.gaps_enabled and any_gap_nonzero) {
421 mon.gap_inner_h = cfg.gap_inner_h; 494 mon.gap_inner_h = cfg.gap_inner_h;
@@ -665,16 +738,15 @@ pub const WindowManager = struct {
665 } 738 }
666 739
667 /// Run the event loop until `self.running` is set to false. 740 /// Run the event loop until `self.running` is set to false.
668 - ///
669 - /// `eventFn` dispatches a single XEvent
670 - /// `tickFn` is called once per loop iteration to advance animations
671 pub fn run( 741 pub fn run(
672 self: *WindowManager, 742 self: *WindowManager,
673 eventFn: fn (*xlib.XEvent, *WindowManager) void, 743 eventFn: fn (*xlib.XEvent, *WindowManager) void,
674 tickFn: fn (*WindowManager) void, 744 tickFn: fn (*WindowManager) void,
745 + gestureFn: fn (*WindowManager, gesture_mod.Event) void,
675 ) void { 746 ) void {
676 var fds = [_]std.posix.pollfd{ 747 var fds = [_]std.posix.pollfd{
677 .{ .fd = self.x11_fd, .events = std.posix.POLL.IN, .revents = 0 }, 748 .{ .fd = self.x11_fd, .events = std.posix.POLL.IN, .revents = 0 },
749 + .{ .fd = -1, .events = std.posix.POLL.IN, .revents = 0 },
678 }; 750 };
679 751
680 _ = xlib.XSync(self.display.handle, xlib.False); 752 _ = xlib.XSync(self.display.handle, xlib.False);
@@ -685,6 +757,10 @@ pub const WindowManager = struct {
685 eventFn(&event, self); 757 eventFn(&event, self);
686 } 758 }
687 759
760 + if (self.gestures) |*gestures| {
761 + gestures.dispatch(self, gestureFn);
762 + }
763 +
688 tickFn(self); 764 tickFn(self);
689 765
690 var current_bar = self.bars; 766 var current_bar = self.bars;
@@ -694,6 +770,7 @@ pub const WindowManager = struct {
694 current_bar = bar.next; 770 current_bar = bar.next;
695 } 771 }
696 772
773 + fds[1].fd = if (self.gestures) |gestures| gestures.fd else -1;
697 const poll_timeout: i32 = if (self.scroll_animation.isActive()) 16 else 1000; 774 const poll_timeout: i32 = if (self.scroll_animation.isActive()) 16 else 1000;
698 _ = std.posix.poll(&fds, poll_timeout) catch 0; 775 _ = std.posix.poll(&fds, poll_timeout) catch 0;
699 } 776 }
@@ -718,6 +795,12 @@ pub const WindowManager = struct {
718 795
719 loadFn(self); 796 loadFn(self);
720 797
798 + var mon = self.monitors;
799 + while (mon) |m| : (mon = m.next) {
800 + m.scroll_default_width = self.config.scroll_default_width;
801 + }
802 + self.syncGestures();
803 +
721 bar_mod.destroyBars(self.bars, self.display.handle); 804 bar_mod.destroyBars(self.bars, self.display.handle);
722 self.bars = null; 805 self.bars = null;
723 self.setupBars(); 806 self.setupBars();
+24 −0 templates/config.lua
@@ -129,6 +129,21 @@ oxwm.set_layout_symbol("tabbed", "[=]")
129 -- Unset value uses oxwm.set_layout value 129 -- Unset value uses oxwm.set_layout value
130 -- oxwm.set_tag_layout(1, "grid") 130 -- oxwm.set_tag_layout(1, "grid")
131 131
132 +-- Scrolling layout: windows sit side by side in an infinite strip (like niri)
133 +-- Widths at or below 1 are a proportion of the screen, larger values are pixels
134 +-- oxwm.scroll.set_default_width(0.5)
135 +-- oxwm.scroll.set_width_presets({ 1 / 3, 1 / 2, 2 / 3 })
136 +-- Three-finger touchpad swipes scroll the strip and snap to the nearest window
137 +-- Off by default. Uncomment this to enable trackpad gestures
138 +-- (needs libinput at build time and read access to /dev/input, usually the "input" group)
139 +-- oxwm.scroll.set_gesture_enabled(true)
140 +-- oxwm.scroll.set_gesture_fingers(3)
141 +-- oxwm.scroll.set_gesture_speed(2.0)
142 +-- oxwm.scroll.set_gesture_natural(false)
143 +-- Minimap of the strip in the bar (one box per window, focused highlighted)
144 +-- oxwm.scroll.set_indicator(true)
145 +-- oxwm.scroll.set_indicator_width(0) -- pixels, 0 = 4x bar height
146 +
132 -- Set the default attach method, similar to the patches from dwm 147 -- Set the default attach method, similar to the patches from dwm
133 -- Available methods: "aside" (default), "top", "bottom", "above", "below" 148 -- Available methods: "aside" (default), "top", "bottom", "above", "below"
134 -- For example "above" makes new clients appear above the currently selected one 149 -- For example "above" makes new clients appear above the currently selected one
@@ -239,6 +254,15 @@ oxwm.key.bind({ modkey }, "C", oxwm.layout.set("tiling"))
239 -- Cycle through layouts 254 -- Cycle through layouts
240 oxwm.key.bind({ modkey }, "N", oxwm.layout.cycle()) 255 oxwm.key.bind({ modkey }, "N", oxwm.layout.cycle())
241 256
257 +-- Scrolling layout controls
258 +-- oxwm.key.bind({ modkey }, "G", oxwm.layout.set("scrolling"))
259 +-- oxwm.key.bind({ modkey }, "Left", oxwm.layout.scroll_left())
260 +-- oxwm.key.bind({ modkey }, "Right", oxwm.layout.scroll_right())
261 +-- oxwm.key.bind({ modkey }, "R", oxwm.layout.cycle_width(1))
262 +-- oxwm.key.bind({ modkey, "Shift" }, "R", oxwm.layout.cycle_width(-1))
263 +-- oxwm.key.bind({ modkey }, "M", oxwm.layout.set_width(1))
264 +-- In the scrolling layout set_master_factor resizes the focused window instead
265 +
242 -- Master area controls (tiling layout) 266 -- Master area controls (tiling layout)
243 267
244 -- Decrease/Increase master area width 268 -- Decrease/Increase master area width
+47 −1 templates/oxwm.lua
@@ -76,7 +76,7 @@ function oxwm.toggle_bar() end
76 oxwm.rule = {} 76 oxwm.rule = {}
77 77
78 ---Add a window rule 78 ---Add a window rule
79 ----@param rule {class: string?, instance: string?, title: string?, role: string?, floating: boolean?, tag: integer?, fullscreen: boolean?, focus: boolean?} Rule configuration 79 +---@param rule {class: string?, instance: string?, title: string?, role: string?, floating: boolean?, tag: integer?, fullscreen: boolean?, focus: boolean?, width: number?} Rule configuration (`width` is the scrolling layout column width: a proportion at or below 1, otherwise pixels)
80 function oxwm.rule.add(rule) end 80 function oxwm.rule.add(rule) end
81 81
82 ---Quit the window manager 82 ---Quit the window manager
@@ -237,6 +237,52 @@ function oxwm.layout.scroll_left() end
237 ---@return table Action table for keybinding 237 ---@return table Action table for keybinding
238 function oxwm.layout.scroll_right() end 238 function oxwm.layout.scroll_right() end
239 239
240 +---Cycle the focused window through the scrolling width presets
241 +---@param direction integer? 1 for the next preset, -1 for the previous (default 1)
242 +---@return table Action table for keybinding
243 +function oxwm.layout.cycle_width(direction) end
244 +
245 +---Set the focused window's width in the scrolling layout
246 +---@param width number Proportion of the screen (0-1) or pixels (> 1)
247 +---@return table Action table for keybinding
248 +function oxwm.layout.set_width(width) end
249 +
250 +---Scrolling layout module
251 +---@class oxwm.scroll
252 +oxwm.scroll = {}
253 +
254 +---Set the default column width for new windows in the scrolling layout
255 +---@param width number Proportion of the screen (0-1) or pixels (> 1), default 0.5
256 +function oxwm.scroll.set_default_width(width) end
257 +
258 +---Set the width presets cycled by oxwm.layout.cycle_width
259 +---@param presets number[] Up to 8 widths, default { 1/3, 1/2, 2/3 }
260 +function oxwm.scroll.set_width_presets(presets) end
261 +
262 +---Enable or disable touchpad swipe gestures (requires read access to /dev/input)
263 +---@param enabled boolean Default false
264 +function oxwm.scroll.set_gesture_enabled(enabled) end
265 +
266 +---Set how many fingers a swipe needs to scroll the layout
267 +---@param fingers integer 3, 4 or 5 (default 3)
268 +function oxwm.scroll.set_gesture_fingers(fingers) end
269 +
270 +---Set how far the view moves per unit of finger travel
271 +---@param speed number Multiplier, default 2.0
272 +function oxwm.scroll.set_gesture_speed(speed) end
273 +
274 +---Invert the swipe direction so the windows follow the fingers
275 +---@param natural boolean Default false
276 +function oxwm.scroll.set_gesture_natural(natural) end
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 +
240 ---Tag/workspace management module 286 ---Tag/workspace management module
241 ---@class oxwm.tag 287 ---@class oxwm.tag
242 oxwm.tag = {} 288 oxwm.tag = {}