feat(theme,display,wm,power,make): add Anodized theme, editors, multi-monitor arrangement, power timeouts, bar compaction, and replace state preservation
- Replace deprecated AnodeDefault with dark-silvery Anodized default theme - Add interactive theme editor, duplicator, and non-standard .xth importer to anode-themes (+ CLI --install) - Fix multi-monitor dwm/lock/vkbd/EDID edge cases and integrate monitor arrangement + 15s revert into anode-display and anode-apply-display - Gate anode-touchd behind WITH_TOUCHD=1 (keeping anode-vkbd unconditional) and add help/rebuild/install-touch/install-system targets to Makefile - Add idle screen dim, lock, suspend, and suspend-on-AC timeout controls to anode-power and anode-display backed by power.conf + SIGUSR1 - Prevent lockscreen subtitle overflow and progressively compact status bar segments so focused window titles remain visible - Preserve workspaces, active desktop, monitor state, floating/fullscreen states, and focus across anode-replace and restarts
This commit is contained in:
1 parent
bb81541b42
commit
4ec3f59e02
40 files changed
+5843
-768
No files matched your search
@@ -1,11 +1,15 @@
|
||||
/*
|
||||
* ANODE Power Policy State Machine (shared across anode-powerd and tests)
|
||||
* ANODE Power Policy State Machine & Configuration Persistence
|
||||
* (shared across anode-powerd, anode-power, anode-display, and unit tests)
|
||||
*/
|
||||
#ifndef ANODE_POWER_POLICY_H
|
||||
#define ANODE_POWER_POLICY_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef enum {
|
||||
ANODE_PWR_ACTIVE = 0,
|
||||
@@ -67,9 +71,16 @@ static inline void anode_power_policy_step(const anode_power_cfg_t *cfg,
|
||||
}
|
||||
}
|
||||
|
||||
/* User activity resumes from dimmed/locked/suspended */
|
||||
uint32_t resume_thresh = cfg->dim_ms > 0 ? cfg->dim_ms : (cfg->lock_ms > 0 ? cfg->lock_ms : cfg->suspend_ms);
|
||||
if (resume_thresh == 0 || idle_ms < resume_thresh) {
|
||||
/* User activity resumes from dimmed/locked/suspended before the earliest enabled timeout */
|
||||
uint32_t eff_susp_ms = (cfg->suspend_ms > 0U && (cfg->suspend_on_ac || !on_ac)) ? cfg->suspend_ms : 0U;
|
||||
uint32_t resume_thresh = 0U;
|
||||
uint32_t cands[3] = {cfg->dim_ms, cfg->lock_ms, eff_susp_ms};
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (cands[i] > 0U && (resume_thresh == 0U || cands[i] < resume_thresh)) {
|
||||
resume_thresh = cands[i];
|
||||
}
|
||||
}
|
||||
if (resume_thresh == 0U || idle_ms < resume_thresh) {
|
||||
if (*state == ANODE_PWR_DIMMED || *state == ANODE_PWR_LOCKED || *state == ANODE_PWR_SUSPENDED) {
|
||||
a.restore_brightness = true;
|
||||
}
|
||||
@@ -105,4 +116,141 @@ static inline void anode_power_policy_step(const anode_power_cfg_t *cfg,
|
||||
if (out) *out = a;
|
||||
}
|
||||
|
||||
static inline int anode_power_policy_next_wake_ms(const anode_power_cfg_t *cfg,
|
||||
uint32_t idle_ms,
|
||||
bool on_ac,
|
||||
bool is_dimmed) {
|
||||
int timeout_ms = 15000;
|
||||
if (cfg) {
|
||||
uint32_t eff_susp_ms = (cfg->suspend_ms > 0U && (cfg->suspend_on_ac || !on_ac)) ? cfg->suspend_ms : 0U;
|
||||
uint32_t cands[3] = {cfg->dim_ms, cfg->lock_ms, eff_susp_ms};
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (cands[i] > 0U && idle_ms < cands[i]) {
|
||||
uint32_t rem = cands[i] - idle_ms;
|
||||
if (rem < (uint32_t)timeout_ms) timeout_ms = (int)rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (timeout_ms < 1000) timeout_ms = 1000;
|
||||
if (is_dimmed && timeout_ms > 500) timeout_ms = 500;
|
||||
return timeout_ms;
|
||||
}
|
||||
|
||||
static inline bool anode_power_cfg_load(const char *path, anode_power_cfg_t *cfg) {
|
||||
if (!cfg) return false;
|
||||
*cfg = anode_power_cfg_default();
|
||||
if (!path || !path[0]) return false;
|
||||
FILE *f = fopen(path, "r");
|
||||
if (!f) return false;
|
||||
|
||||
char line[256];
|
||||
while (fgets(line, sizeof(line), f)) {
|
||||
char *s = line;
|
||||
while (*s == ' ' || *s == '\t') s++;
|
||||
if (*s == '\0' || *s == '#' || *s == '\n' || *s == '\r') continue;
|
||||
char *eq = strchr(s, '=');
|
||||
if (!eq) continue;
|
||||
*eq = '\0';
|
||||
|
||||
char *kend = eq;
|
||||
while (kend > s && (kend[-1] == ' ' || kend[-1] == '\t')) {
|
||||
*--kend = '\0';
|
||||
}
|
||||
const char *k = s;
|
||||
const char *v = eq + 1;
|
||||
while (*v == ' ' || *v == '\t') v++;
|
||||
if (!*v) continue;
|
||||
|
||||
char *endp = NULL;
|
||||
long val = strtol(v, &endp, 10);
|
||||
if (endp == v) continue;
|
||||
|
||||
if (strcmp(k, "DIM_SEC") == 0 || strcmp(k, "LOCK_SEC") == 0 || strcmp(k, "SUSPEND_SEC") == 0) {
|
||||
long clamped = val < 0 ? 0L : (val > 86400L ? 86400L : val);
|
||||
uint32_t ms = (uint32_t)clamped * 1000U;
|
||||
if (strcmp(k, "DIM_SEC") == 0) cfg->dim_ms = ms;
|
||||
else if (strcmp(k, "LOCK_SEC") == 0) cfg->lock_ms = ms;
|
||||
else cfg->suspend_ms = ms;
|
||||
} else if (strcmp(k, "SUSPEND_ON_AC") == 0) {
|
||||
cfg->suspend_on_ac = (val != 0);
|
||||
} else if (strcmp(k, "CRIT_BATT_PCT") == 0) {
|
||||
if (val >= 1 && val <= 30) cfg->crit_batt_pct = (int)val;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool anode_power_cfg_save(const char *path, const anode_power_cfg_t *cfg) {
|
||||
if (!path || !path[0] || !cfg) return false;
|
||||
char tmp[1088];
|
||||
int tn = snprintf(tmp, sizeof(tmp), "%s.tmp", path);
|
||||
if (tn <= 0 || (size_t)tn >= sizeof(tmp)) return false;
|
||||
|
||||
FILE *f = fopen(tmp, "w");
|
||||
if (!f) return false;
|
||||
int wn = fprintf(
|
||||
f,
|
||||
"# ANODE idle power policy (0 disables dim/lock/suspend)\n"
|
||||
"DIM_SEC=%u\n"
|
||||
"LOCK_SEC=%u\n"
|
||||
"SUSPEND_SEC=%u\n"
|
||||
"SUSPEND_ON_AC=%d\n"
|
||||
"CRIT_BATT_PCT=%d\n",
|
||||
(unsigned)(cfg->dim_ms / 1000U),
|
||||
(unsigned)(cfg->lock_ms / 1000U),
|
||||
(unsigned)(cfg->suspend_ms / 1000U),
|
||||
cfg->suspend_on_ac ? 1 : 0,
|
||||
cfg->crit_batt_pct);
|
||||
bool bad = (wn < 0) || ferror(f);
|
||||
if (fclose(f) != 0) bad = true;
|
||||
if (bad || rename(tmp, path) != 0) {
|
||||
remove(tmp);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline uint32_t anode_power_step_presets(uint32_t cur_ms, int dir, const uint32_t *presets, size_t count) {
|
||||
if (!presets || count == 0) return cur_ms;
|
||||
uint32_t cur_sec = cur_ms / 1000U;
|
||||
if (dir > 0) {
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
if (presets[i] > cur_sec) return presets[i] * 1000U;
|
||||
}
|
||||
return presets[count - 1] * 1000U;
|
||||
}
|
||||
if (dir < 0) {
|
||||
for (size_t i = count; i > 0; i--) {
|
||||
if (presets[i - 1] < cur_sec) return presets[i - 1] * 1000U;
|
||||
}
|
||||
return presets[0] * 1000U;
|
||||
}
|
||||
return cur_ms;
|
||||
}
|
||||
|
||||
static inline uint32_t anode_power_step_screen_timeout_ms(uint32_t cur_ms, int dir) {
|
||||
static const uint32_t PRESETS_SEC[] = {0U, 30U, 60U, 120U, 180U, 300U, 600U, 900U, 1200U, 1800U, 3600U};
|
||||
return anode_power_step_presets(cur_ms, dir, PRESETS_SEC, sizeof(PRESETS_SEC) / sizeof(PRESETS_SEC[0]));
|
||||
}
|
||||
|
||||
static inline uint32_t anode_power_step_suspend_timeout_ms(uint32_t cur_ms, int dir) {
|
||||
static const uint32_t PRESETS_SEC[] = {0U, 300U, 600U, 900U, 1200U, 1800U, 2700U, 3600U, 7200U};
|
||||
return anode_power_step_presets(cur_ms, dir, PRESETS_SEC, sizeof(PRESETS_SEC) / sizeof(PRESETS_SEC[0]));
|
||||
}
|
||||
|
||||
static inline void anode_power_format_timeout(uint32_t ms, char *out, size_t sz) {
|
||||
if (!out || sz == 0) return;
|
||||
uint32_t sec = ms / 1000U;
|
||||
if (sec == 0U) {
|
||||
snprintf(out, sz, "Off");
|
||||
} else if (sec >= 3600U && (sec % 3600U) == 0U) {
|
||||
snprintf(out, sz, "%uh", (unsigned)(sec / 3600U));
|
||||
} else if (sec >= 60U && (sec % 60U) == 0U) {
|
||||
snprintf(out, sz, "%um", (unsigned)(sec / 60U));
|
||||
} else {
|
||||
snprintf(out, sz, "%us", (unsigned)sec);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* ANODE_POWER_POLICY_H */
|
||||
Reference in new issue
Block a user