Skip to content

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

calculator and theme updates

oxydizerc32513c8c865
diff --git a/README.md b/README.md
index 4fa2d8f..c7cdda0 100644
--- a/README.md
+++ b/README.md
@@ -62,8 +62,11 @@ Xwayland, `foot`, `brightnessctl`, `gio`/`xdg-open`, `git` (optional).
Printer support uses an existing CUPS server (`cups`).
-Run from a checkout, `scripts/install.sh` builds that checkout (dependencies,
-then `install-session.sh` with the arguments you give it).
+Run from a checkout, or invoke its `scripts/install.sh` by path, to build the
+files currently in that checkout, including uncommitted edits and new files
+(dependencies, then `install-session.sh` with the arguments you give it).
+Source builds also reuse an existing `REDIWM_SRC_DIR` as-is; update it manually
+when you want newer upstream changes. The installer never resets local source.
```sh
zig build run -- foot # nested in your current Wayland session
diff --git a/assets/themes/redi-blue.toml b/assets/themes/redi-blue.toml
index 97144c3..5ebba79 100644
--- a/assets/themes/redi-blue.toml
+++ b/assets/themes/redi-blue.toml
@@ -114,6 +114,7 @@ start_button_radius = 4
[layout]
taskbar_position = "bottom"
+taskbar_items = ["left:start", "left:windows", "right:capture", "right:tray", "right:battery", "~right:wifi", "~right:wired", "right:volume", "right:clock", "-right:power"]
dock_enabled = false
[assets]
diff --git a/assets/themes/redi-mocha.toml b/assets/themes/redi-mocha.toml
index a3bfa6d..138004f 100644
--- a/assets/themes/redi-mocha.toml
+++ b/assets/themes/redi-mocha.toml
@@ -144,6 +144,7 @@ pdf_search_match_active = "rgba(250,179,135,0.65)"
[layout]
taskbar_position = "bottom"
+taskbar_items = ["left:start", "left:windows", "right:capture", "right:tray", "right:battery", "~right:wifi", "~right:wired", "right:volume", "right:clock", "-right:power"]
dock_enabled = false
[assets]
diff --git a/assets/themes/rediwm-dark.toml b/assets/themes/rediwm-dark.toml
index 4f6bb18..4a8f917 100644
--- a/assets/themes/rediwm-dark.toml
+++ b/assets/themes/rediwm-dark.toml
@@ -92,6 +92,7 @@ start_menu_selected_marker = "rgba(237,27,46,1.000)"
[layout]
taskbar_position = "bottom"
+taskbar_items = ["left:start", "left:windows", "right:capture", "right:tray", "right:battery", "~right:wifi", "~right:wired", "right:volume", "right:clock", "-right:power"]
dock_enabled = false
[assets]
diff --git a/assets/themes/rediwm-light.toml b/assets/themes/rediwm-light.toml
index fa28be6..150991b 100644
--- a/assets/themes/rediwm-light.toml
+++ b/assets/themes/rediwm-light.toml
@@ -136,6 +136,7 @@ desktop_notice_bg = "rgba(8,42,36,0.95)"
[layout]
taskbar_position = "bottom"
+taskbar_items = ["left:start", "left:windows", "right:capture", "right:tray", "right:battery", "~right:wifi", "~right:wired", "right:volume", "right:clock", "-right:power"]
dock_enabled = false
[assets]
diff --git a/scripts/install.sh b/scripts/install.sh
index a89bd08..6f7bafc 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -60,8 +60,21 @@ while [ "$n" -gt 0 ]; do
*) set -- "$@" "$arg" ;;
esac
done
-# Running from a checkout means the user wants that checkout built.
-if [ -f ./build.zig.zon ] && grep -q '\.name = \.rediwm,' ./build.zig.zon 2>/dev/null; then
+# Build the working files, including uncommitted edits and new files. Also
+# recognize an installer invoked by path from outside the checkout.
+is_source_dir() {
+ [ -f "$1/build.zig.zon" ] && grep -q '\.name = \.rediwm,' "$1/build.zig.zon" 2>/dev/null
+}
+LOCAL_SRC_DIR=""
+if is_source_dir .; then
+ LOCAL_SRC_DIR=$(pwd)
+elif [ -f "$0" ]; then
+ script_repo=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
+ if is_source_dir "$script_repo"; then
+ LOCAL_SRC_DIR=$script_repo
+ fi
+fi
+if [ -n "$LOCAL_SRC_DIR" ]; then
BUILD=yes
fi
@@ -304,17 +317,13 @@ default_ref() {
echo "$ref"
}
-if [ -f ./build.zig.zon ] && grep -q '\.name = \.rediwm,' ./build.zig.zon 2>/dev/null; then
- SRC_DIR=$(pwd)
- log "Running from an existing checkout at $SRC_DIR"
-elif [ -d "$SRC_DIR/.git" ]; then
- [ -n "$REPO_REF" ] || REPO_REF=$(default_ref)
- log "Updating existing checkout at $SRC_DIR"
- git -C "$SRC_DIR" fetch --depth 1 origin "$REPO_REF"
- git -C "$SRC_DIR" checkout "$REPO_REF"
- git -C "$SRC_DIR" reset --hard "origin/$REPO_REF"
+if [ -n "$LOCAL_SRC_DIR" ]; then
+ SRC_DIR=$LOCAL_SRC_DIR
+ log "Building working files at $SRC_DIR (including local changes)"
+elif is_source_dir "$SRC_DIR"; then
+ log "Building working files at $SRC_DIR (including local changes; update this source manually if needed)"
elif [ -e "$SRC_DIR" ]; then
- die "$SRC_DIR exists but isn't a git checkout; move it aside or set REDIWM_SRC_DIR and re-run"
+ die "$SRC_DIR exists but isn't a RediWM source directory; move it aside or set REDIWM_SRC_DIR and re-run"
else
[ -n "$REPO_REF" ] || REPO_REF=$(default_ref)
log "Cloning $REPO_URL ($REPO_REF) into $SRC_DIR"
diff --git a/src/calculator/model.zig b/src/calculator/model.zig
index 64662f0..8d8d947 100644
--- a/src/calculator/model.zig
+++ b/src/calculator/model.zig
@@ -10,6 +10,7 @@ pub const Model = struct {
result_len: usize = 0,
notice: []const u8 = "",
evaluated: bool = false,
+ repeat: ?Operation = null,
pub fn expression(self: *const Model) []const u8 {
return self.buffer[0..self.len];
@@ -26,11 +27,13 @@ pub const Model = struct {
pub fn backspace(self: *Model) void {
self.notice = "";
self.evaluated = false;
+ self.repeat = null;
self.len -|= 1;
}
pub fn input(self: *Model, char: u8) void {
if (std.mem.indexOfScalar(u8, "0123456789.+-*/()%", char) == null) return;
+ self.repeat = null;
if (self.evaluated and (std.ascii.isDigit(char) or char == '.' or char == '(')) self.len = 0;
self.evaluated = false;
self.notice = "";
@@ -59,6 +62,7 @@ pub const Model = struct {
pub fn negate(self: *Model) void {
self.notice = "";
self.evaluated = false;
+ self.repeat = null;
var start = self.len;
while (start > 0 and self.buffer[start - 1] == '%') start -= 1;
if (start > 0 and self.buffer[start - 1] == ')') {
@@ -95,9 +99,20 @@ pub const Model = struct {
}
pub fn equals(self: *Model) void {
- if (self.len == 0 or self.evaluated) return;
+ if (self.len == 0) return;
+ if (self.evaluated) {
+ const operation = self.repeat orelse return;
+ var operand: [64]u8 = undefined;
+ const rhs = formatNumber(&operand, operation.number) catch unreachable;
+ const expression_text = std.fmt.bufPrint(&self.history, "{s}{c}{s}{s}", .{
+ self.expression(), operation.operator, rhs, if (operation.percent) "%" else "",
+ }) catch unreachable;
+ @memcpy(self.buffer[0..expression_text.len], expression_text);
+ self.len = expression_text.len;
+ self.evaluated = false;
+ }
var parser: Parser = .{ .text = self.expression() };
- const value = parser.evaluate() catch |err| {
+ const evaluation = parser.evaluate() catch |err| {
self.notice = switch (err) {
error.DivisionByZero => @import("i18n").tr("Cannot divide by zero"),
error.Overflow => @import("i18n").tr("Result is too large"),
@@ -105,6 +120,7 @@ pub const Model = struct {
};
return;
};
+ const value = evaluation.number;
@memcpy(self.history[0..self.len], self.expression());
self.history_len = self.len;
// General formatting stays short for very large/small values and
@@ -125,6 +141,7 @@ pub const Model = struct {
self.result_len = readout.len;
self.notice = "";
self.evaluated = true;
+ self.repeat = evaluation.repeat;
}
};
@@ -136,6 +153,21 @@ fn formatNumber(buffer: []u8, number: f64) ![]const u8 {
const EvalError = error{ InvalidExpression, DivisionByZero, Overflow };
+/// The final binary operation, with its right-hand expression already resolved.
+const Operation = struct {
+ operator: u8,
+ number: f64,
+ percent: bool = false,
+
+ fn init(operator: u8, rhs: Parser.Value) Operation {
+ return .{
+ .operator = operator,
+ .number = if (rhs.percent) rhs.number * 100 else rhs.number,
+ .percent = rhs.percent,
+ };
+ }
+};
+
const Parser = struct {
text: []const u8,
pos: usize = 0,
@@ -146,12 +178,13 @@ const Parser = struct {
/// A percentage operand keeps its meaning through signs and grouping.
/// Products and sums produce ordinary numbers.
percent: bool = false,
+ repeat: ?Operation = null,
};
- fn evaluate(self: *Parser) EvalError!f64 {
+ fn evaluate(self: *Parser) EvalError!Value {
const value = try self.sum();
if (self.pos != self.text.len) return error.InvalidExpression;
- return value.number;
+ return value;
}
fn take(self: *Parser, char: u8) bool {
@@ -173,7 +206,10 @@ const Parser = struct {
// Calculator-style increases/discounts: 200 + 10% = 220.
// Resolve multiplication/division first, using fractional rates.
const amount = if (rhs.percent) try finite(value.number * rhs.number) else rhs.number;
- value = .{ .number = try finite(if (subtract) value.number - amount else value.number + amount) };
+ value = .{
+ .number = try finite(if (subtract) value.number - amount else value.number + amount),
+ .repeat = Operation.init(if (subtract) '-' else '+', rhs),
+ };
}
return value;
}
@@ -182,11 +218,12 @@ const Parser = struct {
var value = try self.operand();
while (self.pos < self.text.len) {
if (self.take('*')) {
- value = .{ .number = try finite(value.number * (try self.operand()).number) };
+ const rhs = try self.operand();
+ value = .{ .number = try finite(value.number * rhs.number), .repeat = Operation.init('*', rhs) };
} else if (self.take('/')) {
- const divisor = (try self.operand()).number;
- if (divisor == 0) return error.DivisionByZero;
- value = .{ .number = try finite(value.number / divisor) };
+ const rhs = try self.operand();
+ if (rhs.number == 0) return error.DivisionByZero;
+ value = .{ .number = try finite(value.number / rhs.number), .repeat = Operation.init('/', rhs) };
} else break;
}
return value;
@@ -216,7 +253,9 @@ const Parser = struct {
while (self.take('%')) {
value.number /= 100;
value.percent = true;
+ value.repeat = null;
}
+ if (negative) value.repeat = null;
value.number = try finite(if (negative) -value.number else value.number);
return value;
}
diff --git a/src/calculator/model_tests.zig b/src/calculator/model_tests.zig
index 32f0461..c4f0362 100644
--- a/src/calculator/model_tests.zig
+++ b/src/calculator/model_tests.zig
@@ -72,7 +72,6 @@ test "calculator continues from results and starts fresh on numeric entry" {
var model: Model = .{};
enter(&model, "200+10%");
try expectResult(&model, "220");
- try expectResult(&model, "220"); // A repeated equals keeps the result.
enter(&model, "-5%");
try expectResult(&model, "209");
enter(&model, "1/10000000000");
@@ -85,6 +84,64 @@ test "calculator continues from results and starts fresh on numeric entry" {
try expectResult(&model, "3");
}
+test "calculator repeats the final operation with precedence and percentages" {
+ const cases = [_][4][]const u8{
+ .{ "2+3", "5", "8", "11" },
+ .{ "10-2", "8", "6", "4" },
+ .{ "3*2", "6", "12", "24" },
+ .{ "16/2", "8", "4", "2" },
+ .{ "2+3*4", "14", "26", "38" },
+ .{ "(2+3)*4", "20", "80", "320" },
+ .{ "20-5-2", "13", "11", "9" },
+ .{ "2*(3+4)", "14", "98", "686" },
+ .{ "2*-3", "-6", "18", "-54" },
+ .{ "200+10%", "220", "242", "266.2" },
+ .{ "200-10%", "180", "162", "145.8" },
+ .{ "200*10%", "20", "2", "0.2" },
+ .{ "200/10%", "2000", "20000", "200000" },
+ .{ "200+(5+5)%", "220", "242", "266.2" },
+ .{ "7", "7", "7", "7" },
+ .{ "5%", "0.05", "0.05", "0.05" },
+ };
+ for (cases) |case| {
+ var model: Model = .{};
+ enter(&model, case[0]);
+ errdefer std.debug.print("expression: {s}\n", .{case[0]});
+ for (case[1..]) |expected| try expectResult(&model, expected);
+ }
+ var model: Model = .{};
+ enter(&model, "2+3");
+ try expectResult(&model, "5");
+ try expectResult(&model, "8");
+ try std.testing.expectEqualStrings("5+3", model.history[0..model.history_len]);
+}
+
+test "calculator resets repeated equals when entering or editing a calculation" {
+ var model: Model = .{};
+ enter(&model, "2+3");
+ try expectResult(&model, "5");
+ enter(&model, "7");
+ try expectResult(&model, "7");
+ try expectResult(&model, "7");
+ enter(&model, "*2");
+ try expectResult(&model, "14");
+ try expectResult(&model, "28");
+ model.backspace();
+ try expectResult(&model, "2");
+ try expectResult(&model, "2");
+ enter(&model, "+3");
+ try expectResult(&model, "5");
+ model.negate();
+ try expectResult(&model, "-5");
+ try expectResult(&model, "-5");
+ model.clear();
+ model.equals();
+ try std.testing.expectEqualStrings("", model.display());
+ enter(&model, "4");
+ try expectResult(&model, "4");
+ try expectResult(&model, "4");
+}
+
test "calculator sign toggle handles numbers, percentages and groups" {
const cases = [_][2][]const u8{
.{ "200+10%", "180" }, .{ "200+(5+5)%", "180" },
diff --git a/src/control_center/sections/appearance.zig b/src/control_center/sections/appearance.zig
index 3860be4..752d622 100644
--- a/src/control_center/sections/appearance.zig
+++ b/src/control_center/sections/appearance.zig
@@ -306,8 +306,8 @@ pub const Section = struct {
items_placeholder_body: [3][3]Widget = undefined,
/// Rows follow `order`; `syncItems` hands each well its run of them.
item_rows: [taskbar_items.count]Widget = undefined,
- /// Grip, label, visibility toggle.
- item_controls: [taskbar_items.count][3]Widget = undefined,
+ /// Grip, label, section selector, visibility toggle.
+ item_controls: [taskbar_items.count][4]Widget = undefined,
item_drag: ?struct { index: usize, press_y: f32, moved: bool = false, items: taskbar_items.Config } = null,
item_focus: ?taskbar_items.Item = null,
start_menu_section_children: [9]Widget = undefined,
diff --git a/src/control_center/sections/appearance_items.zig b/src/control_center/sections/appearance_items.zig
index 0d5bfd3..2deffd8 100644
--- a/src/control_center/sections/appearance_items.zig
+++ b/src/control_center/sections/appearance_items.zig
@@ -23,6 +23,21 @@ pub fn saveItems(s: *Section, items: taskbar_items.Config) void {
}
pub const item_row_height: f32 = 40;
+pub const item_section_width: f32 = 170;
+
+/// The row's Left/Center/Right buttons: the item moves to the end of that
+/// section, the same result as dropping it there.
+pub fn onItemSectionChanged(owner: ?*anyopaque, id: usize, index: usize) void {
+ if (index > 2 or id >= taskbar_items.count) return;
+ const s = section(owner);
+ var items = s.cc.server.config.compositor.taskbar_items;
+ const zone: taskbar_items.Section = @enumFromInt(index);
+ const item = items.order[id];
+ if (items.section(item) == zone) return;
+ _ = items.place(id, zone, taskbar_items.count);
+ s.item_focus = item;
+ saveItems(s, items);
+}
pub fn itemRowStyle(lifted: bool) layout.RectStyle {
const pal = panel.palette();
@@ -57,8 +72,10 @@ pub fn syncItems(out: *Section, items: taskbar_items.Config, dragged: ?usize) bo
const shown = items.resolved(item, presence);
controls[1].kind.text.weight = if (shown) 600 else 400;
controls[1].kind.text.color = if (shown) pal.fg else pal.dim;
- controls[2].name = itemName(item, "_visible");
- controls[2].kind.toggle.on = shown;
+ controls[2].name = itemName(item, "_section");
+ controls[2].kind.segmented.selected = @intFromEnum(items.section(item));
+ controls[3].name = itemName(item, "_visible");
+ controls[3].kind.toggle.on = shown;
for (controls) |*control| control.markDirty();
row.markDirty();
}
diff --git a/src/control_center/sections/appearance_sections.zig b/src/control_center/sections/appearance_sections.zig
index e1d9666..d143e99 100644
--- a/src/control_center/sections/appearance_sections.zig
+++ b/src/control_center/sections/appearance_sections.zig
@@ -124,6 +124,7 @@ pub fn buildTaskbarSection(out: *Section, t: theme.Theme, pal: theme.Theme) Widg
out.item_controls[i] = .{
.{ .kind = .{ .button = .{ .label = i18n.tr("Drag to move"), .icon = .drag_handle, .variant = .ghost, .owner = out, .id = i } }, .width = .{ .fixed = 28 }, .height = .{ .fixed = 28 } },
.{ .kind = .{ .text = .{ .content = "", .font_size = theme.global.app_text_size, .weight = 600, .color = pal.fg } }, .width = .{ .flex = 1 } },
+ .{ .kind = .{ .segmented = .{ .labels = panel.translatedLabels(&.{ i18n.msg("Left"), i18n.msg("Center"), i18n.msg("Right") }), .selected = 0, .owner = out, .id = i, .on_change = &appearance_items.onItemSectionChanged } }, .width = .{ .fixed = appearance_items.item_section_width } },
.{ .kind = .{ .toggle = .{ .on = false, .owner = out, .on_change = &ItemToggle(i).changed } } },
};
out.item_rows[i] = .{ .kind = .{ .rect = itemRowStyle(false) }, .direction = .row, .gap = 8, .@"align" = .center, .padding = .{ .top = 6, .right = 10, .bottom = 6, .left = 6 }, .children = &out.item_controls[i] };
diff --git a/src/desktop/watcher.zig b/src/desktop/watcher.zig
index 21ed398..00f2d93 100644
--- a/src/desktop/watcher.zig
+++ b/src/desktop/watcher.zig
@@ -292,7 +292,8 @@ pub const Worker = struct {
.{ .kind = .home, .name = i18n.tr("Home"), .path = home, .glyph = .home },
.{ .kind = .trash, .name = i18n.tr("Trash"), .path = trash_files, .glyph = .trash_can },
};
- for (entries) |e| try list.append(mem, .{ .path = try mem.dupe(u8, e.path), .name = e.name, .icon = icons.get(self.theme_cfg, self.io, if (e.kind == .home) "user-home" else "user-trash", size) orelse builtinIcon(e.glyph, size, self.theme_cfg.generation), .folder = true, .cell = config.lookup(mem, saved, e.path), .builtin = e.kind });
+ // Only a pack's own artwork replaces the glyph, as in the Files sidebar; an installed theme's user-home is a folder.
+ for (entries) |e| try list.append(mem, .{ .path = try mem.dupe(u8, e.path), .name = e.name, .icon = icons.getPack(self.theme_cfg, self.io, if (e.kind == .home) "user-home" else "user-trash", size) orelse builtinIcon(e.glyph, size, self.theme_cfg.generation), .folder = true, .cell = config.lookup(mem, saved, e.path), .builtin = e.kind });
}
fn scan(self: *Worker) !*Snapshot {
_ = c.pthread_mutex_lock(&self.mutex);
diff --git a/tests/calculator.py b/tests/calculator.py
index 7825d00..999a3c3 100644
--- a/tests/calculator.py
+++ b/tests/calculator.py
@@ -76,7 +76,7 @@ def run(scale):
("(2+3)*4", "20"), ("0.1+0.2", "0.3"),
]
references = {"0": zero}
- for expected in dict.fromkeys(value for _, value in cases):
+ for expected in dict.fromkeys([value for _, value in cases] + ["5", "8", "11", "110.25", "115.7625"]):
clear()
ipc.type_text(expected)
wait_for(lambda: not same(zero, readout()), "numeric entry was not painted")
@@ -88,6 +88,14 @@ def run(scale):
wait_for(lambda: same(references[expected], readout()),
f"{expression} did not display {expected}")
+ clear()
+ ipc.type_text("2+3=")
+ wait_for(lambda: same(references["5"], readout()), "equals key failed")
+ ipc.type_text("=")
+ wait_for(lambda: same(references["8"], readout()), "repeated equals key failed")
+ ipc.key_down_up(28)
+ wait_for(lambda: same(references["11"], readout()), "repeated Enter failed")
+
def click_button(row, column):
b = box()
cell_w = (b["width"] - 56) / 4
@@ -100,6 +108,10 @@ def run(scale):
click_button(row, column) # 100+5%=
ipc.move_cursor(0, 0)
wait_for(lambda: same(references["105"], readout()), "keypad percentage failed")
+ for expected in ("110.25", "115.7625"):
+ click_button(4, 3)
+ ipc.move_cursor(0, 0)
+ wait_for(lambda: same(references[expected], readout()), "keypad repeated equals failed")
clear()
ipc.type_text("200+10%")
diff --git a/tests/taskbar_sections.py b/tests/taskbar_sections.py
index 5604747..a53724e 100644
--- a/tests/taskbar_sections.py
+++ b/tests/taskbar_sections.py
@@ -97,6 +97,13 @@ def run():
return zone
for name, expected in (('start', 0), ('windows', 0), ('capture', 2), ('tray', 2), ('clock', 2), ('power', 2), ('wifi', 2), ('wired', 2)):
assert zone_of(name) == expected, name
+ # Each row's Left/Center/Right buttons move the item like a drop.
+ for zone, fraction in ((0, 1 / 6), (1, 0.5), (2, 5 / 6)):
+ segmented = ui.scroll_into_view('taskbar_wired_section')['global_box']
+ ipc.click_at(int(segmented['x'] + segmented['width'] * fraction), int(segmented['y'] + segmented['height'] / 2))
+ ipc.wait_for_panel_settled('control_center')
+ assert zone_of('wired') == zone, f'wired moved to {zones[zone]} by its buttons'
+ assert f'{zones[zone]}:wired' in [entry.lstrip('-~') for entry in tomllib.loads(cfg.read_text())['compositor']['taskbar_items']]
for name in ('wifi', 'wired'):
assert not ui.scroll_into_view(f'taskbar_{name}_visible')['on'], f'{name} is off without its hardware'
toggle = ui.scroll_into_view('taskbar_capture_visible')