Skip to content

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

feat(taskbar): add auto-hide option

vgxlee635312176c
diff --git a/docs/wiki/Configuration.md b/docs/wiki/Configuration.md
index c148832..92ad825 100644
--- a/docs/wiki/Configuration.md
+++ b/docs/wiki/Configuration.md
@@ -180,6 +180,7 @@ time and date (`clock_bold` and `clock_italic` in `[theme]`, or
| `window_tab_apps` | `[]` | app IDs that get tabs |
| `default_file_manager`, `default_terminal` | `""` | desktop IDs, empty means Files / auto terminal |
| `taskbar_position` | `"bottom"` | `top` or `bottom` |
+| `taskbar_auto_hide` | `false` | `true` hides the taskbar until the pointer reaches its edge, and frees its strip for windows; `false` reserves it |
| `dock_position` | `"bottom"` | `top`, `bottom`, `left` or `right`; inside the usable area beside the taskbar |
| `dock_auto_hide` | `false` | `true` hides the dock until the pointer reaches its edge, and frees its strip for windows; `false` reserves it |
| `dock_opacity` | unset | 0.0 to 1.0, the dock background's alpha; unset keeps the theme's |
diff --git a/src/Output.zig b/src/Output.zig
index 8f83d65..25601e0 100644
--- a/src/Output.zig
+++ b/src/Output.zig
@@ -353,8 +353,11 @@ pub fn dockAreaBox(output: *Output) wlr.Box {
break :blk b;
};
if (output.taskbar) |bar| {
- if (output.server.config.compositor.taskbar_position == .top) box.y += bar.reserved;
- box.height = @max(1, box.height - bar.reserved);
+ // An auto-hiding bar floats over the strip: windows (and the dock) use the whole edge.
+ if (!output.server.config.compositor.taskbar_auto_hide) {
+ if (output.server.config.compositor.taskbar_position == .top) box.y += bar.reserved;
+ box.height = @max(1, box.height - bar.reserved);
+ }
}
return box;
}
diff --git a/src/Taskbar.zig b/src/Taskbar.zig
index f1ddd98..605318d 100644
--- a/src/Taskbar.zig
+++ b/src/Taskbar.zig
@@ -38,6 +38,7 @@ const taskbar_layout = @import("taskbar/layout.zig");
const taskbar_reconcile = @import("taskbar/reconcile.zig");
const taskbar_tick = @import("taskbar/tick.zig");
const taskbar_pointer = @import("taskbar/pointer.zig");
+const taskbar_reveal = @import("taskbar/reveal.zig");
const taskbar_classify = @import("taskbar/classify.zig");
const taskbar_paint_util = @import("taskbar/paint_util.zig");
const taskbar_paint = @import("taskbar/paint.zig");
@@ -172,6 +173,18 @@ capture_hover: Anim = .{},
capture_press: Anim = .{ .to = 1 },
hover_target: Target = .none,
+// Auto-hide. `pointer_near` is where the pointer wants the bar (at the edge,
+// or on it once shown); `shown` is what the reveal heads for, which follows
+// after a delay (`reveal_timer` armed for `timer_target`). `reveal` runs 0
+// (away) to 1 and drives the fade and slide; `parked` is hidden and settled,
+// so the tree is disabled and no frames are scheduled. See taskbar/reveal.zig.
+reveal: Anim = .{},
+shown: bool = false,
+pointer_near: bool = false,
+parked: bool = false,
+reveal_timer: ?*wl.EventSource = null,
+timer_target: ?bool = null,
+
// Cached master-volume display state, refreshed from `server.audio` only
// when its `generation` counter has moved since we last looked (see
// audio/pipewire.zig's module doc comment) — checked once per `tick()`
@@ -549,6 +562,12 @@ pub const InsertionTarget = taskbar_pointer.InsertionTarget;
pub const insertionTarget = taskbar_pointer.insertionTarget;
pub const scrollVolume = taskbar_pointer.scrollVolume;
+// taskbar/reveal.zig
+pub const syncReveal = taskbar_reveal.syncReveal;
+pub const applyReveal = taskbar_reveal.applyReveal;
+pub const pointerAt = taskbar_reveal.pointerAt;
+pub const disarmReveal = taskbar_reveal.disarm;
+
// taskbar/classify.zig
pub const containsIgnoreCase = taskbar_classify.containsIgnoreCase;
pub const matchesAny = taskbar_classify.matchesAny;
diff --git a/src/config/default.zig b/src/config/default.zig
index be25ef0..9a9cc6e 100644
--- a/src/config/default.zig
+++ b/src/config/default.zig
@@ -153,6 +153,7 @@ pub const source =
\\dock_pinned_apps = [] # desktop entry IDs pinned by dragging them from the start menu
\\# Taskbar sections, ordered within each section; prefix with - to hide an item.
\\taskbar_position = "bottom" # top or bottom
+ \\taskbar_auto_hide = false # show the taskbar only when the pointer reaches its edge; false reserves its space
\\taskbar_alignment = "center" # left, center or right; visible below 100% length
\\taskbar_items = ["left:start", "left:windows", "right:capture", "right:tray", "right:battery", "~right:wifi", "~right:wired", "~right:input_source", "right:volume", "right:clock", "-right:power"]
\\# A ~ prefix (~right:wifi, ~right:wired) shows the item only while a wireless adapter
diff --git a/src/config/loader.zig b/src/config/loader.zig
index f46d42e..bdae980 100644
--- a/src/config/loader.zig
+++ b/src/config/loader.zig
@@ -200,6 +200,7 @@ pub const CompositorConfig = struct {
dock_pinned_apps: []const []const u8 = &.{},
taskbar_items: TaskbarItems = .{},
taskbar_position: types.TaskbarPosition = .bottom,
+ taskbar_auto_hide: bool = false,
taskbar_alignment: types.TaskbarAlignment = .center,
/// App identities opted into compositor tabs. Only + launches join a group.
window_tab_apps: []const []const u8 = &.{},
diff --git a/src/config/loader_fields.zig b/src/config/loader_fields.zig
index 12bfc88..e022855 100644
--- a/src/config/loader_fields.zig
+++ b/src/config/loader_fields.zig
@@ -122,6 +122,7 @@ pub const compositor_rules: std.enums.EnumFieldStruct(std.meta.FieldEnum(Composi
.dock_pinned_apps = .json_string_list,
.taskbar_items = .taskbar_items,
.taskbar_position = .enumeration,
+ .taskbar_auto_hide = .boolean,
.taskbar_alignment = .enumeration,
.icon_theme = .string,
.window_tab_apps = .json_string_list,
diff --git a/src/config_runtime/apply.zig b/src/config_runtime/apply.zig
index 6f93485..f2bd483 100644
--- a/src/config_runtime/apply.zig
+++ b/src/config_runtime/apply.zig
@@ -247,6 +247,13 @@ pub fn applyDiff(server: *Server, old: Config, new: Config) void {
old.compositor.dock_height != new.compositor.dock_height);
if (old.compositor.taskbar_position != new.compositor.taskbar_position or dock_strip_moved) server.applyTaskbarPosition();
+ // An auto-hiding taskbar floats over its strip: refit windows as it comes
+ // or goes, and schedule a frame so a parked bar can reappear.
+ if (old.compositor.taskbar_auto_hide != new.compositor.taskbar_auto_hide) {
+ server.applyTaskbarPosition();
+ server.scheduleFrames();
+ }
+
if (old.compositor.dock_enabled != new.compositor.dock_enabled) {
server.scheduleFrames();
if (server.input.open_control_center) |cc| cc.refresh();
diff --git a/src/control_center/search_index.zig b/src/control_center/search_index.zig
index 2ff7e09..8c76ab0 100644
--- a/src/control_center/search_index.zig
+++ b/src/control_center/search_index.zig
@@ -112,6 +112,7 @@ const source_entries = [_]SourceEntry{
.{ .page = .appearance, .title = i18n.msg("Inactive window opacity"), .target = "inactive_opacity", .keywords = i18n.msg("transparency unfocused") },
.{ .page = .appearance, .title = i18n.msg("Terminal opacity"), .target = "terminal_opacity", .keywords = i18n.msg("transparency") },
.{ .page = .appearance, .title = i18n.msg("Taskbar position"), .target = "taskbar_position", .keywords = i18n.msg("panel top bottom") },
+ .{ .page = .appearance, .title = i18n.msg("Taskbar auto hide"), .target = "taskbar_auto_hide", .keywords = i18n.msg("panel hide automatically") },
.{ .page = .appearance, .title = i18n.msg("Taskbar alignment"), .target = "taskbar_alignment", .keywords = i18n.msg("panel left center right") },
.{ .page = .appearance, .title = i18n.msg("Taskbar edge gap"), .target = "taskbar_edge_gap", .keywords = i18n.msg("panel margin") },
.{ .page = .appearance, .title = i18n.msg("Taskbar length"), .target = "taskbar_length", .keywords = i18n.msg("panel width") },
diff --git a/src/control_center/sections/appearance.zig b/src/control_center/sections/appearance.zig
index 14c2e6f..be3b34e 100644
--- a/src/control_center/sections/appearance.zig
+++ b/src/control_center/sections/appearance.zig
@@ -295,8 +295,9 @@ pub const Section = struct {
terminal_opacity_group_children: [2]Widget = undefined,
terminal_opacity_value_buf: [16]u8 = undefined,
px: [22]PxControl = undefined,
- taskbar_section_children: [14]Widget = undefined,
+ taskbar_section_children: [15]Widget = undefined,
taskbar_position_children: [2]Widget = undefined,
+ taskbar_auto_hide_children: [2]Widget = undefined,
taskbar_alignment_children: [2]Widget = undefined,
clock_bold_children: [2]Widget = undefined,
clock_italic_children: [2]Widget = undefined,
diff --git a/src/control_center/sections/appearance_chrome.zig b/src/control_center/sections/appearance_chrome.zig
index 02d0c48..c136434 100644
--- a/src/control_center/sections/appearance_chrome.zig
+++ b/src/control_center/sections/appearance_chrome.zig
@@ -211,6 +211,21 @@ pub fn onTaskbarPositionChanged(owner: ?*anyopaque, _: usize, index: usize) void
server.applyTaskbarPosition();
}
+pub fn onTaskbarAutoHideChanged(owner: ?*anyopaque, _: usize, on: bool) void {
+ const s = section(owner);
+ const server = s.cc.server;
+ setting_save.saveCompositor(main.gpa, server.io, server.config.path, "taskbar_auto_hide", on) catch |err| {
+ std.log.warn("could not save taskbar auto-hide: {}", .{err});
+ s.taskbar_auto_hide_children[1].kind.toggle.on = server.config.compositor.taskbar_auto_hide;
+ s.taskbar_auto_hide_children[1].markDirty();
+ return;
+ };
+ server.config.compositor.taskbar_auto_hide = on;
+ // A hidden bar keeps windows out of no strip; a parked one needs a frame to show again.
+ server.applyTaskbarPosition();
+ server.scheduleFrames();
+}
+
pub fn onTaskbarAlignmentChanged(owner: ?*anyopaque, _: usize, index: usize) void {
if (index > 2) return;
const s = section(owner);
diff --git a/src/control_center/sections/appearance_sections.zig b/src/control_center/sections/appearance_sections.zig
index d143e99..202afae 100644
--- a/src/control_center/sections/appearance_sections.zig
+++ b/src/control_center/sections/appearance_sections.zig
@@ -87,6 +87,11 @@ pub fn buildTaskbarSection(out: *Section, t: theme.Theme, pal: theme.Theme) Widg
.{ .name = "taskbar_position", .kind = .{ .segmented = .{ .labels = panel.translatedLabels(&.{ i18n.msg("Top"), i18n.msg("Bottom") }), .selected = @intFromEnum(out.cc.server.config.compositor.taskbar_position), .owner = out, .on_change = &onTaskbarPositionChanged } }, .width = .{ .fixed = segmented_width } },
};
const position_row: Widget = .{ .kind = .container, .direction = .row, .justify = .space_between, .@"align" = .center, .children = &out.taskbar_position_children };
+ out.taskbar_auto_hide_children = .{
+ labelWidget(i18n.tr("Auto-hide taskbar")),
+ .{ .name = "taskbar_auto_hide", .kind = .{ .toggle = .{ .on = out.cc.server.config.compositor.taskbar_auto_hide, .owner = out, .on_change = &appearance_chrome.onTaskbarAutoHideChanged } } },
+ };
+ const auto_hide_row: Widget = .{ .kind = .container, .direction = .row, .justify = .space_between, .@"align" = .center, .children = &out.taskbar_auto_hide_children };
out.taskbar_alignment_children = .{
labelWidget(i18n.tr("Taskbar alignment")),
.{ .name = "taskbar_alignment", .kind = .{ .segmented = .{ .labels = panel.translatedLabels(&.{ i18n.msg("Left"), i18n.msg("Center"), i18n.msg("Right") }), .selected = @intFromEnum(out.cc.server.config.compositor.taskbar_alignment), .owner = out, .on_change = &appearance_chrome.onTaskbarAlignmentChanged } }, .width = .{ .fixed = segmented_width } },
@@ -155,7 +160,7 @@ pub fn buildTaskbarSection(out: *Section, t: theme.Theme, pal: theme.Theme) Widg
i18n.tr("Warning: Screen capture is hidden. Recording and screen sharing can continue without a visible indicator or Stop sharing button. Hiding it is not recommended."), .font_size = theme.global.settings_description_size, .color = pal.dim } } },
};
const items_group: Widget = .{ .kind = .container, .direction = .column, .gap = 8, .@"align" = .stretch, .children = &out.items_children };
- out.taskbar_section_children = .{ panel.sectionTitle(i18n.tr("Taskbar")), position_row, alignment_row, taskbar_row, edge_gap_row, length_row, radius_row, chip_width_row, chip_gap_row, start_gap_row, start_icon_row, clock_bold_row, clock_italic_row, items_group };
+ out.taskbar_section_children = .{ panel.sectionTitle(i18n.tr("Taskbar")), position_row, auto_hide_row, alignment_row, taskbar_row, edge_gap_row, length_row, radius_row, chip_width_row, chip_gap_row, start_gap_row, start_icon_row, clock_bold_row, clock_italic_row, items_group };
const taskbar_section: Widget = .{ .kind = .container, .direction = .column, .gap = 12, .children = &out.taskbar_section_children };
return taskbar_section;
}
diff --git a/src/input/motion.zig b/src/input/motion.zig
index ee8de1b..816e600 100644
--- a/src/input/motion.zig
+++ b/src/input/motion.zig
@@ -185,7 +185,10 @@ fn draggingFiles(input: *const Input) bool {
pub fn updateDockReveal(input: *Input) void {
const engaged = input.cursor_mode == .passthrough and (input.active_buttons == 0 or input.dock_drag.active() or draggingFiles(input));
var it = input.server.outputs.iterator(.forward);
- while (it.next()) |output| output.dock.pointerAt(input.cursor.x, input.cursor.y, engaged);
+ while (it.next()) |output| {
+ output.dock.pointerAt(input.cursor.x, input.cursor.y, engaged);
+ if (output.taskbar) |bar| bar.pointerAt(input.cursor.x, input.cursor.y, engaged);
+ }
}
fn updateWidgetProximity(input: *Input) void {
diff --git a/src/taskbar/layout.zig b/src/taskbar/layout.zig
index d824d34..357dad1 100644
--- a/src/taskbar/layout.zig
+++ b/src/taskbar/layout.zig
@@ -122,6 +122,8 @@ pub fn relayout(bar: *Taskbar, output_box: wlr.Box) void {
glass.Effect.configure(bar.glass_effect, barRadius(), 1);
bar.applyClip();
bar.tree.node.setPosition(bar.box.x, bar.box.y);
+ // An auto-hiding bar starts away; one that is shown (or never hides) is in place.
+ if (bar.server.config.compositor.taskbar_auto_hide and !bar.shown) bar.reveal.cancel(0);
const now_ms = nowMs();
bar.pointerLeave();
_ = bar.reconcile(now_ms);
diff --git a/src/taskbar/reveal.zig b/src/taskbar/reveal.zig
new file mode 100644
index 0000000..0ff3936
--- /dev/null
+++ b/src/taskbar/reveal.zig
@@ -0,0 +1,134 @@
+//! Taskbar auto-hide: reveal/hide timing, pointer proximity and the slide/fade.
+//! Mirrors the dock's mechanism (dock/reveal.zig): the reveal animates the
+//! tree's position and the buffers' opacity, and the parked bar disables its
+//! tree so it neither paints nor takes hits.
+
+const std = @import("std");
+const Taskbar = @import("../Taskbar.zig");
+const Output = @import("../Output.zig");
+const glass = @import("../glass.zig");
+const wl = @import("wayland").server.wl;
+const anim = @import("ui").anim;
+
+const Self = Taskbar;
+/// The outermost pixels of the edge that reveal the bar, and the tolerance
+/// around a shown one; timing and travel mirror the dock's.
+const pointer_margin = 5;
+const edge_band = 2;
+const reveal_delay_ms = 120;
+const hide_delay_ms = 400;
+const slide_distance = 20;
+
+/// Whether a panel the bar anchors keeps it shown: the window picker on this
+/// bar, the start menu, or a popup (calendar, battery, network) on the output.
+pub fn menuOpen(bar: *const Self) bool {
+ const input = bar.server.input;
+ if (input.window_menu.bar == bar) return true;
+ if (input.open_start_menu) |sm| {
+ if (sm.wlr_output == bar.wlr_output) return true;
+ }
+ if (Output.fromWlr(bar.wlr_output)) |output| {
+ if (output.calendar != null or output.battery_popup != null or output.wifi_popup != null) return true;
+ }
+ return false;
+}
+
+/// Auto-hide: lets `reveal` follow the pointer's wish. True while it still moves.
+pub fn syncReveal(bar: *Self, now_ms: i64) bool {
+ var target: f32 = 1;
+ if (bar.server.config.compositor.taskbar_auto_hide) {
+ retime(bar);
+ if (!bar.shown) target = 0;
+ } else {
+ disarm(bar);
+ bar.pointer_near = false;
+ bar.shown = false;
+ }
+ if (bar.reveal.to != target) bar.reveal.retargetTo(now_ms, target, anim.curveFor(.taskbar_hover));
+ const moving = !bar.reveal.settled(now_ms);
+ bar.parked = target == 0 and !moving;
+ return moving;
+}
+
+/// The bar fades and slides toward its edge as `reveal` falls. The rasters do
+/// not change: only the tree's position and every buffer's opacity. Glass
+/// follows the position as part of the tree, but its opacity is its own and is
+/// given here, or the blurred backdrop would stay solid until the bar parks.
+pub fn applyReveal(bar: *Self, now_ms: i64) void {
+ const t = std.math.clamp(bar.reveal.value(now_ms), 0, 1);
+ const x = bar.box.x;
+ var y = bar.box.y;
+ if (t < 1 and !anim.reducedMotion()) {
+ const away: i32 = @intFromFloat(@round((1 - t) * slide_distance));
+ if (bar.server.config.compositor.taskbar_position == .top) y -= away else y += away;
+ }
+ bar.tree.node.setPosition(x, y);
+ bar.buffer_node.setOpacity(t);
+ bar.start_node.setOpacity(t);
+ bar.clock_node.setOpacity(t);
+ for (bar.tray_nodes) |node| node.setOpacity(t);
+ bar.app_tray_node.setOpacity(t);
+ bar.capture_node.setOpacity(t);
+ bar.battery_node.setOpacity(t);
+ glass.Effect.configure(bar.glass_effect, Taskbar.barRadius(), t);
+}
+
+/// Whether the pointer at layout position `x`, `y` wants the bar: it is at the
+/// output edge the bar sits on, or on the bar once shown.
+pub fn nearPointer(bar: *const Self, output: *Output, x: f64, y: f64) bool {
+ const c = &bar.server.config.compositor;
+ if (!c.taskbar_auto_hide) return false;
+ const full = output.cached_box;
+ const px: i32 = @intFromFloat(@floor(x));
+ const py: i32 = @intFromFloat(@floor(y));
+ if (px < full.x or py < full.y or px >= full.x + full.width or py >= full.y + full.height) return false;
+ const at_edge = if (c.taskbar_position == .top)
+ py < full.y + edge_band
+ else
+ py >= full.y + full.height - edge_band;
+ if (at_edge) return true;
+ // Only a bar that is out can be pointed at: where it would be is windows.
+ if (!bar.shown) return false;
+ return px >= bar.box.x - pointer_margin and px < bar.box.x + bar.box.width + pointer_margin and
+ py >= bar.box.y - pointer_margin and py < bar.box.y + bar.box.height + pointer_margin;
+}
+
+/// Every pointer motion. `engaged` is false while a window is moved or resized
+/// or a button is held, none of which should raise the bar.
+pub fn pointerAt(bar: *Self, x: f64, y: f64, engaged: bool) void {
+ const output = Output.fromWlr(bar.wlr_output) orelse return;
+ const near = engaged and nearPointer(bar, output, x, y);
+ if (near == bar.pointer_near) return;
+ bar.pointer_near = near;
+ retime(bar);
+}
+
+/// Starts (or drops) the delay before `shown` follows what the pointer wants.
+pub fn retime(bar: *Self) void {
+ const wanted = bar.pointer_near or menuOpen(bar);
+ if (wanted == bar.shown) return disarm(bar);
+ if (bar.timer_target == wanted) return;
+ bar.timer_target = wanted;
+ const delay: i32 = if (wanted) reveal_delay_ms else hide_delay_ms;
+ if (bar.reveal_timer == null) {
+ bar.reveal_timer = bar.server.wl_server.getEventLoop().addTimer(*Self, onTimer, bar) catch null;
+ }
+ if (bar.reveal_timer) |timer| {
+ if (timer.timerUpdate(delay)) return else |_| {}
+ }
+ // No timer: follow at once.
+ _ = onTimer(bar);
+}
+
+pub fn disarm(bar: *Self) void {
+ if (bar.timer_target == null) return;
+ bar.timer_target = null;
+ if (bar.reveal_timer) |timer| timer.timerUpdate(0) catch {};
+}
+
+pub fn onTimer(bar: *Self) c_int {
+ if (bar.timer_target) |wanted| bar.shown = wanted;
+ bar.timer_target = null;
+ bar.wlr_output.scheduleFrame();
+ return 0;
+}
diff --git a/src/taskbar/tick.zig b/src/taskbar/tick.zig
index 936d4f0..721c679 100644
--- a/src/taskbar/tick.zig
+++ b/src/taskbar/tick.zig
@@ -4,6 +4,7 @@ const std = @import("std");
const Taskbar = @import("../Taskbar.zig");
const anim = @import("ui").anim;
const battery = @import("../taskbar/battery.zig");
+const reveal = @import("../taskbar/reveal.zig");
const taskbar_items = @import("config").taskbar_items;
const start_button = @import("../taskbar/start_button.zig");
const protocol = @import("../ipc/protocol.zig");
@@ -24,6 +25,15 @@ const trayHit = Taskbar.trayHit;
// Runs once per output frame while anything is unsettled. Returns whether
// the caller should schedule another frame to keep the animation going.
pub fn tick(bar: *Taskbar, now_ms: i64) bool {
+ const revealing = reveal.syncReveal(bar, now_ms);
+ if (bar.parked) {
+ // Away: the tree stays off, so nothing paints or takes hits; its
+ // pending dirt is kept and renders once the bar is revealed again.
+ bar.tree.node.setEnabled(false);
+ return revealing;
+ }
+ bar.tree.node.setEnabled(true);
+
var causes = bar.paint_causes;
bar.paint_causes = 0;
@@ -117,7 +127,8 @@ pub fn tick(bar: *Taskbar, now_ms: i64) bool {
// it; say the picture moved or the frame reads as a wasted wakeup.
anim.observeNoteChanged();
}
- return animating;
+ reveal.applyReveal(bar, now_ms);
+ return animating or revealing;
}
pub fn captureAnimations(