Skip to content

RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process

Add taskbar scroll focus cycling

Melb5b83a0d9b42
diff --git a/src/Input.zig b/src/Input.zig
index 6fd73e6..43d6aaf 100644
--- a/src/Input.zig
+++ b/src/Input.zig
@@ -228,6 +228,7 @@ gesture: enum { none, client_pinch, client_swipe, compositor_pinch, compositor_s
/// Two-finger touchpad scroll over empty desktop, distinct from middle-drag.
finger_pan: bool = false,
zoom_scroll: @import("camera.zig").ZoomScroll = .{},
+taskbar_focus_scroll: @import("camera.zig").ZoomScroll = .{},
zoom_device: ?*wlr.InputDevice = null,
zoom_target_id: u64 = 0,
active_buttons: u32 = 0,
diff --git a/src/input/axis.zig b/src/input/axis.zig
index adfcc50..9a58eac 100644
--- a/src/input/axis.zig
+++ b/src/input/axis.zig
@@ -77,9 +77,12 @@ pub fn processAxis(
if (scroll_hit == .taskbar) {
const hit = scroll_hit.taskbar;
if (hit.bar.appTrayAt(hit.sx, hit.sy)) |index| {
+ input.taskbar_focus_scroll.reset();
if (input.server.tray) |tray| tray.scroll(index, if (delta_discrete != 0) delta_discrete else @intFromFloat(delta), orientation == .horizontal_scroll);
return;
}
+ } else {
+ input.taskbar_focus_scroll.reset();
}
if (scroll_hit == .chrome and !input.isAltHeld() and !input.isDesktopZoomHeld()) {
const res = scroll_hit.chrome;
@@ -176,7 +179,23 @@ pub fn processAxis(
},
.taskbar => |hit| {
if (orientation == .vertical_scroll) {
- hit.bar.scrollVolume(hit.sx, hit.sy, ui_scroll.axisDeltaPx(delta, delta_discrete), notch);
+ const delta_px = ui_scroll.axisDeltaPx(delta, delta_discrete);
+ if (!hit.bar.scrollVolume(hit.sx, hit.sy, delta_px, notch)) {
+ const steps = input.taskbar_focus_scroll.feed(
+ delta_discrete,
+ delta,
+ @intCast(@intFromEnum(source)),
+ );
+ var remaining = steps;
+ while (remaining > 0) : (remaining -= 1) {
+ input.server.world.cycleFocus();
+ }
+ while (remaining < 0) : (remaining += 1) {
+ input.server.world.cycleFocusPrev();
+ }
+ }
+ } else {
+ input.taskbar_focus_scroll.reset();
}
return;
},
diff --git a/src/taskbar/pointer.zig b/src/taskbar/pointer.zig
index 3b695e0..fc30648 100644
--- a/src/taskbar/pointer.zig
+++ b/src/taskbar/pointer.zig
@@ -172,34 +172,35 @@ pub fn pointerPress(bar: *Taskbar, sx: f64, sy: f64) void {
if (did_mutate) bar.wlr_output.scheduleFrame();
}
-/// Scroll wheel over the volume tray icon: ±`volume_scroll_step` per tick;
-/// over the input source item, the next or previous source per notch (a
-/// touchpad steps every `source_scroll_step` px). Called from
-/// Input.processAxis's scroll-hit switch.
-pub fn scrollVolume(bar: *Taskbar, sx: f64, sy: f64, delta_px: f32, notch: bool) void {
+/// Handle scrolling over volume and input-source tray items. Returns true
+/// when the tray item consumes the scroll; false lets the caller handle it.
+/// Volume changes by ±`volume_scroll_step` per tick; input sources cycle per
+/// notch (a touchpad steps every `source_scroll_step` px).
+pub fn scrollVolume(bar: *Taskbar, sx: f64, sy: f64, delta_px: f32, notch: bool) bool {
const idx = switch (bar.hitTest(sx, sy)) {
.tray => |i| i,
- else => return,
+ else => return false,
};
if (@as(TrayKind, @enumFromInt(idx)) == .input_source) {
- const sources = bar.server.input_sources orelse return;
+ const sources = bar.server.input_sources orelse return true;
if (notch) {
if (delta_px != 0) sources.cycle(delta_px > 0);
- return;
+ return true;
}
bar.source_scroll += delta_px;
while (@abs(bar.source_scroll) >= source_scroll_step) {
sources.cycle(bar.source_scroll > 0);
bar.source_scroll -= std.math.copysign(source_scroll_step, bar.source_scroll);
}
- return;
+ return true;
}
- if (@as(TrayKind, @enumFromInt(idx)) != .volume) return;
- const mgr = bar.server.audio orelse return;
+ if (@as(TrayKind, @enumFromInt(idx)) != .volume) return false;
+ const mgr = bar.server.audio orelse return true;
// Natural convention: scrolling up (negative delta) raises volume.
const direction: f32 = if (delta_px < 0) 1 else -1;
mgr.setMasterVolume(std.math.clamp(mgr.getMasterVolume() + direction * volume_scroll_step, 0, 1));
bar.tray_dirty[@intFromEnum(TrayKind.volume)] = true;
bar.markDirty(paint_tray);
bar.wlr_output.scheduleFrame();
+ return true;
}
diff --git a/tests/focus_zoom.py b/tests/focus_zoom.py
index 2f49d4f..ab3844a 100644
--- a/tests/focus_zoom.py
+++ b/tests/focus_zoom.py
@@ -77,6 +77,12 @@ def run():
box = next(chip["box"] for chip in bar["chips"] if chip["window_id"] == wid)
ipc.click_at(box["x"] + box["width"] // 2, box["y"] + box["height"] // 2)
+ def taskbar_scroll(wid, dy):
+ bar = ipc.get_shell_state()["taskbars"][0]
+ box = next(chip["box"] for chip in bar["chips"] if chip["window_id"] == wid)
+ ipc.move_cursor(box["x"] + box["width"] // 2, box["y"] + box["height"] // 2)
+ ipc.scroll(0, dy)
+
def reset():
ipc.action('reset_camera')
tick()
@@ -86,6 +92,14 @@ def run():
ipc.focus_window(target)
ipc.focus_window(other)
reset()
+
+ # Scrolling over a taskbar window chip cycles focus; reversing
+ # the scroll restores the previous active window.
+ taskbar_scroll(target, 40)
+ assert ipc.get_focused_window()["id"] != other, "taskbar scroll changes focus"
+ taskbar_scroll(target, -40)
+ assert ipc.get_focused_window()["id"] == other, "reverse taskbar scroll restores focus"
+
ipc.action('move_window_to', {"id": target, "x": width + 200, "y": 100})
switch_to(target)
samples = []