Skip to content

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

power and battery fixes

oxydizerb9a884329f19
diff --git a/src/control_center/sections/power.zig b/src/control_center/sections/power.zig
index 28f9cd1..6d0068d 100644
--- a/src/control_center/sections/power.zig
+++ b/src/control_center/sections/power.zig
@@ -14,6 +14,8 @@ pub const Section = struct {
arena: std.heap.ArenaAllocator = .init(gpa),
root: W = undefined,
source: ?power.Source = null,
+ /// The real source `source` was last aligned to; a change snaps the tab to it.
+ live: ?power.Source = null,
pending: ?struct { field: Field, value: usize } = null,
values: [@typeInfo(Field).@"enum".field_names.len][]const u32 = @splat(&.{}),
message: []const u8 = "",
@@ -21,7 +23,11 @@ pub const Section = struct {
pub fn build(s: *Section, cc: *panel.ControlCenter) void {
_ = s.arena.reset(.retain_capacity);
- if (s.source == null) s.source = cc.server.power_policy.source orelse .plugged_in;
+ // The tab starts on the active source and follows plug/unplug; a tab the
+ // user picked stays until the source next changes.
+ const live = cc.server.power_policy.source orelse .plugged_in;
+ if (s.source == null or s.live != live) s.source = live;
+ s.live = live;
if (!cc.server.power_policy.state.present) s.source = .plugged_in;
s.root = tree(s, cc, s.arena.allocator()) catch panel.outOfMemory();
}
diff --git a/tests/power_settings.py b/tests/power_settings.py
index a6d081f..bd995a2 100644
--- a/tests/power_settings.py
+++ b/tests/power_settings.py
@@ -189,6 +189,17 @@ def exercise(ipc, root, supply, pp, logind, pp_log, login_log, event_path, batte
ui.click(ui.find('power', panel='control_center'))
ui.wait_settled('control_center')
assert ui.find('power_brightness')['selected_index'] == 45
+ # The tab follows the real source while Settings stays open.
+ supply(True)
+ wait_for(lambda: not any('On Battery' in str(w.get('label') or '') for w in ui.widgets()), 'status leaves On Battery')
+ ui.wait_settled('control_center')
+ assert ui.find('power_source')['selected_index'] == 0
+ assert ui.find('power_brightness')['selected_index'] == 80
+ supply(False)
+ wait_for(lambda: any('On Battery' in str(w.get('label') or '') for w in ui.widgets()), 'status says On Battery')
+ ui.wait_settled('control_center')
+ assert ui.find('power_source')['selected_index'] == 1
+ assert ui.find('power_brightness')['selected_index'] == 45
ui.click(ui.find('power_source'), fraction=.2)
ui.wait_settled('control_center')
assert ui.find('power_brightness')['selected_index'] == 80