feat: improve session switching, fractional DPI/GTK theming, XDG launcher, CPU/RAM status, and power policy
This commit is contained in:
1 parent
72b05b650e
commit
07d9134d2d
28 files changed
+2670
-302
No files matched your search
@@ -135,13 +135,18 @@ static void apply_scale_now(disp_state_t *st, const char *scale_arg, int touch_o
|
||||
snprintf(sbuf, sizeof(sbuf), "%s", scale_arg);
|
||||
int t = (touch_override >= 0) ? touch_override : (st->touch_mode ? 1 : 0);
|
||||
snprintf(tbuf, sizeof(tbuf), "--touch=%d", t);
|
||||
unsetenv("ANODE_SCALE");
|
||||
unsetenv("ANODE_TOUCH");
|
||||
const char *av[] = {"anode-apply-scale", sbuf, tbuf, NULL};
|
||||
if (anode_run_cmd_timeout(av, NULL, 0, 5000) == 0) {
|
||||
gemui_theme_reload(st->app);
|
||||
const gemui_theme_t *th = gemui_theme(st->app);
|
||||
st->scale = th ? th->scale : st->scale;
|
||||
st->touch_mode = th ? th->touch_mode : (t != 0);
|
||||
gemui_show_toast(st->app, "Display scale updated", 1800);
|
||||
char msg[64];
|
||||
snprintf(msg, sizeof(msg), "Display scale: %.2fx (%d DPI)",
|
||||
st->scale, th ? th->dpi : (int)(96.0 * st->scale + 0.5));
|
||||
gemui_show_toast(st->app, msg, 1800);
|
||||
} else {
|
||||
gemui_show_toast(st->app, "Scale update failed", 2000);
|
||||
}
|
||||
|
||||
+126
-1
@@ -23,6 +23,14 @@
|
||||
#include <sys/wait.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
|
||||
#include <sys/sysctl.h>
|
||||
#if defined(__OpenBSD__)
|
||||
#include <uvm/uvmexp.h>
|
||||
#elif defined(__NetBSD__)
|
||||
#include <uvm/uvm_extern.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ANODE_PREFIX
|
||||
#define ANODE_PREFIX "/usr/local"
|
||||
@@ -34,6 +42,21 @@ static uint64_t plat_now_ms(void) {
|
||||
return (uint64_t)ts.tv_sec * 1000ULL + (uint64_t)(ts.tv_nsec / 1000000L);
|
||||
}
|
||||
|
||||
static int plat_read_buf(const char *path, char *buf, size_t sz) {
|
||||
if (!path || !buf || sz < 2) return -1;
|
||||
int fd = open(path, O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0) return -1;
|
||||
size_t off = 0;
|
||||
while (off + 1 < sz) {
|
||||
ssize_t n = read(fd, buf + off, sz - 1 - off);
|
||||
if (n <= 0) break;
|
||||
off += (size_t)n;
|
||||
}
|
||||
close(fd);
|
||||
buf[off] = '\0';
|
||||
return off > 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
static int plat_read_line(const char *path, char *buf, size_t sz) {
|
||||
if (!path || !buf || sz == 0) return -1;
|
||||
FILE *f = fopen(path, "r");
|
||||
@@ -525,7 +548,7 @@ bool anode_backlight_get(int *cur_out, int *max_out, char *backend_out, size_t b
|
||||
if (plat_read_line(p, b, sizeof(b)) == 0 && atoi(b) > 0) {
|
||||
mx = atoi(b);
|
||||
snprintf(p, sizeof(p), "/sys/class/backlight/%s/brightness", de->d_name);
|
||||
if (plat_read_line(p, b, sizeof(b)) == 0) {
|
||||
if (access(p, W_OK) == 0 && plat_read_line(p, b, sizeof(b)) == 0) {
|
||||
cur = atoi(b);
|
||||
if (cur_out) *cur_out = cur;
|
||||
if (max_out) *max_out = mx;
|
||||
@@ -1037,3 +1060,105 @@ bool anode_find_wifi_iface(char *out, size_t sz) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool anode_read_cpu_sample(anode_cpu_sample_t *out) {
|
||||
if (!out) return false;
|
||||
#if defined(__linux__) || defined(__linux)
|
||||
char buf[512];
|
||||
if (plat_read_buf("/proc/stat", buf, sizeof(buf)) == 0) {
|
||||
return anode_parse_proc_stat_cpu(buf, out);
|
||||
}
|
||||
return false;
|
||||
#elif defined(__FreeBSD__)
|
||||
long cp[5];
|
||||
size_t len = sizeof(cp);
|
||||
if (sysctlbyname("kern.cp_time", cp, &len, NULL, 0) == 0 && len >= sizeof(cp)) {
|
||||
unsigned long long tot = 0;
|
||||
for (int i = 0; i < 5; i++) tot += (unsigned long long)cp[i];
|
||||
out->total = tot;
|
||||
out->idle = (unsigned long long)cp[4];
|
||||
return tot > 0;
|
||||
}
|
||||
return false;
|
||||
#elif defined(__OpenBSD__)
|
||||
int mib[2] = {CTL_KERN, KERN_CPTIME};
|
||||
long cp[5];
|
||||
size_t len = sizeof(cp);
|
||||
if (sysctl(mib, 2, cp, &len, NULL, 0) == 0 && len >= sizeof(cp)) {
|
||||
unsigned long long tot = 0;
|
||||
for (int i = 0; i < 5; i++) tot += (unsigned long long)cp[i];
|
||||
out->total = tot;
|
||||
out->idle = (unsigned long long)cp[4];
|
||||
return tot > 0;
|
||||
}
|
||||
return false;
|
||||
#elif defined(__NetBSD__)
|
||||
uint64_t cp[5];
|
||||
size_t len = sizeof(cp);
|
||||
if (sysctlbyname("kern.cp_time", cp, &len, NULL, 0) == 0 && len >= sizeof(cp)) {
|
||||
unsigned long long tot = 0;
|
||||
for (int i = 0; i < 5; i++) tot += (unsigned long long)cp[i];
|
||||
out->total = tot;
|
||||
out->idle = (unsigned long long)cp[4];
|
||||
return tot > 0;
|
||||
}
|
||||
return false;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool anode_read_mem_usage_pct(int *pct_out) {
|
||||
if (!pct_out) return false;
|
||||
#if defined(__linux__) || defined(__linux)
|
||||
char buf[4096];
|
||||
if (plat_read_buf("/proc/meminfo", buf, sizeof(buf)) == 0) {
|
||||
return anode_parse_proc_meminfo_pct(buf, pct_out);
|
||||
}
|
||||
return false;
|
||||
#elif defined(__FreeBSD__)
|
||||
unsigned long phys = 0;
|
||||
unsigned int pg = 0, vfree = 0, vinact = 0;
|
||||
size_t s_phys = sizeof(phys), s_u = sizeof(pg);
|
||||
if (sysctlbyname("hw.physmem", &phys, &s_phys, NULL, 0) != 0 || phys == 0) return false;
|
||||
if (sysctlbyname("vm.stats.vm.v_page_size", &pg, &s_u, NULL, 0) != 0 || pg == 0) return false;
|
||||
s_u = sizeof(vfree);
|
||||
sysctlbyname("vm.stats.vm.v_free_count", &vfree, &s_u, NULL, 0);
|
||||
s_u = sizeof(vinact);
|
||||
sysctlbyname("vm.stats.vm.v_inactive_count", &vinact, &s_u, NULL, 0);
|
||||
unsigned long long avail = (unsigned long long)(vfree + vinact) * (unsigned long long)pg;
|
||||
if (avail > phys) avail = phys;
|
||||
int pct = (int)(((phys - avail) * 100ULL + phys / 2ULL) / phys);
|
||||
if (pct < 0) pct = 0;
|
||||
if (pct > 100) pct = 100;
|
||||
*pct_out = pct;
|
||||
return true;
|
||||
#elif defined(__OpenBSD__)
|
||||
int mib[2] = {CTL_VM, VM_UVMEXP};
|
||||
struct uvmexp uvm;
|
||||
size_t len = sizeof(uvm);
|
||||
if (sysctl(mib, 2, &uvm, &len, NULL, 0) != 0 || uvm.npages <= 0) return false;
|
||||
unsigned long long tot = (unsigned long long)uvm.npages;
|
||||
unsigned long long avail = (unsigned long long)(uvm.free + uvm.inactive);
|
||||
if (avail > tot) avail = tot;
|
||||
int pct = (int)(((tot - avail) * 100ULL + tot / 2ULL) / tot);
|
||||
if (pct < 0) pct = 0;
|
||||
if (pct > 100) pct = 100;
|
||||
*pct_out = pct;
|
||||
return true;
|
||||
#elif defined(__NetBSD__)
|
||||
struct uvmexp_sysctl uvm;
|
||||
size_t len = sizeof(uvm);
|
||||
if (sysctlbyname("vm.uvmexp2", &uvm, &len, NULL, 0) != 0 || uvm.npages <= 0) return false;
|
||||
unsigned long long tot = (unsigned long long)uvm.npages;
|
||||
unsigned long long avail = (unsigned long long)(uvm.free + uvm.inactive);
|
||||
if (avail > tot) avail = tot;
|
||||
int pct = (int)(((tot - avail) * 100ULL + tot / 2ULL) / tot);
|
||||
if (pct < 0) pct = 0;
|
||||
if (pct > 100) pct = 100;
|
||||
*pct_out = pct;
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "anode_sys_parse.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -77,6 +79,10 @@ int anode_power_action(const char *action); /* suspend, hibernate, reboot, power
|
||||
int anode_list_net_ifaces(anode_net_iface_t *out, int max_ifaces);
|
||||
bool anode_find_wifi_iface(char *out, size_t sz);
|
||||
|
||||
/* System telemetry (CPU & RAM usage) */
|
||||
bool anode_read_cpu_sample(anode_cpu_sample_t *out);
|
||||
bool anode_read_mem_usage_pct(int *pct_out);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -32,9 +32,9 @@ typedef struct {
|
||||
|
||||
static inline anode_power_cfg_t anode_power_cfg_default(void) {
|
||||
anode_power_cfg_t c;
|
||||
c.dim_ms = 60000U;
|
||||
c.lock_ms = 180000U;
|
||||
c.suspend_ms = 600000U;
|
||||
c.dim_ms = 300000U; /* 5 min */
|
||||
c.lock_ms = 600000U; /* 10 min */
|
||||
c.suspend_ms = 1800000U; /* 30 min (battery only) */
|
||||
c.crit_batt_pct = 5;
|
||||
c.suspend_on_ac = false;
|
||||
return c;
|
||||
@@ -67,9 +67,10 @@ static inline void anode_power_policy_step(const anode_power_cfg_t *cfg,
|
||||
}
|
||||
}
|
||||
|
||||
/* User activity resumes from dimmed/suspended */
|
||||
if (idle_ms < cfg->dim_ms) {
|
||||
if (*state == ANODE_PWR_DIMMED || *state == ANODE_PWR_SUSPENDED) {
|
||||
/* 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) {
|
||||
if (*state == ANODE_PWR_DIMMED || *state == ANODE_PWR_LOCKED || *state == ANODE_PWR_SUSPENDED) {
|
||||
a.restore_brightness = true;
|
||||
}
|
||||
*state = screen_locked ? ANODE_PWR_LOCKED : ANODE_PWR_ACTIVE;
|
||||
|
||||
@@ -131,12 +131,15 @@ static inline void anode_read_xres_scale_from_db(XrmDatabase db, Display *dpy,
|
||||
dpi = anode_clamp_dpi(v);
|
||||
have_dpi = 1;
|
||||
}
|
||||
if (XrmGetResource(db, "anode.scale", "Anode.Scale", &type, &val) && val.addr &&
|
||||
anode_parse_positive_double(val.addr, &v)) {
|
||||
if ((XrmGetResource(db, "anode.scale", "Anode.Scale", &type, &val) && val.addr &&
|
||||
anode_parse_positive_double(val.addr, &v)) ||
|
||||
(XrmGetResource(db, "theme.scale", "Theme.Scale", &type, &val) && val.addr &&
|
||||
anode_parse_positive_double(val.addr, &v))) {
|
||||
scale = anode_clamp_scale(v);
|
||||
have_scale = 1;
|
||||
}
|
||||
if (XrmGetResource(db, "anode.touchMode", "Anode.TouchMode", &type, &val) && val.addr) {
|
||||
if ((XrmGetResource(db, "anode.touchMode", "Anode.TouchMode", &type, &val) && val.addr) ||
|
||||
(XrmGetResource(db, "theme.touchMode", "Theme.TouchMode", &type, &val) && val.addr)) {
|
||||
touch = anode_parse_bool_str(val.addr, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* ANODE Cross-Unix CPU & Memory Parsers
|
||||
*/
|
||||
#ifndef ANODE_SYS_PARSE_H
|
||||
#define ANODE_SYS_PARSE_H
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct {
|
||||
unsigned long long total;
|
||||
unsigned long long idle;
|
||||
} anode_cpu_sample_t;
|
||||
|
||||
static inline bool anode_parse_proc_stat_cpu(const char *text, anode_cpu_sample_t *out) {
|
||||
if (!text || !out) return false;
|
||||
out->total = 0;
|
||||
out->idle = 0;
|
||||
|
||||
const char *p = text;
|
||||
while (*p) {
|
||||
const char *nl = strchr(p, '\n');
|
||||
size_t len = nl ? (size_t)(nl - p) : strlen(p);
|
||||
if (len >= 4 && strncmp(p, "cpu", 3) == 0 && isspace((unsigned char)p[3])) {
|
||||
const char *cur = p + 3;
|
||||
const char *end = p + len;
|
||||
unsigned long long vals[10];
|
||||
int count = 0;
|
||||
while (cur < end && count < 10) {
|
||||
while (cur < end && isspace((unsigned char)*cur)) cur++;
|
||||
if (cur >= end || !isdigit((unsigned char)*cur)) break;
|
||||
char *next = NULL;
|
||||
unsigned long long v = strtoull(cur, &next, 10);
|
||||
if (next == cur || next > end) break;
|
||||
vals[count++] = v;
|
||||
cur = next;
|
||||
}
|
||||
if (count < 4) return false;
|
||||
unsigned long long tot = 0;
|
||||
for (int i = 0; i < count; i++) tot += vals[i];
|
||||
unsigned long long idl = vals[3] + (count > 4 ? vals[4] : 0ULL);
|
||||
out->total = tot;
|
||||
out->idle = idl;
|
||||
return tot > 0;
|
||||
}
|
||||
if (!nl) break;
|
||||
p = nl + 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline int anode_cpu_usage_pct(const anode_cpu_sample_t *prev,
|
||||
const anode_cpu_sample_t *cur) {
|
||||
if (!prev || !cur || cur->total <= prev->total) return 0;
|
||||
unsigned long long dt = cur->total - prev->total;
|
||||
unsigned long long di = (cur->idle >= prev->idle) ? (cur->idle - prev->idle) : 0ULL;
|
||||
if (di > dt) di = dt;
|
||||
unsigned long long used = dt - di;
|
||||
int pct = (int)((used * 100ULL + dt / 2ULL) / dt);
|
||||
if (pct < 0) pct = 0;
|
||||
if (pct > 100) pct = 100;
|
||||
return pct;
|
||||
}
|
||||
|
||||
static inline bool anode_parse_proc_meminfo_pct(const char *text, int *pct_out) {
|
||||
if (!text || !pct_out) return false;
|
||||
unsigned long long mem_total = 0;
|
||||
unsigned long long mem_avail = 0;
|
||||
unsigned long long mem_free = 0;
|
||||
unsigned long long buffers = 0;
|
||||
unsigned long long cached = 0;
|
||||
unsigned long long srecl = 0;
|
||||
bool has_total = false;
|
||||
bool has_avail = false;
|
||||
|
||||
const char *p = text;
|
||||
while (*p) {
|
||||
const char *nl = strchr(p, '\n');
|
||||
size_t len = nl ? (size_t)(nl - p) : strlen(p);
|
||||
const char *colon = memchr(p, ':', len);
|
||||
if (colon) {
|
||||
size_t klen = (size_t)(colon - p);
|
||||
const char *vp = colon + 1;
|
||||
const char *end = p + len;
|
||||
while (vp < end && isspace((unsigned char)*vp)) vp++;
|
||||
if (vp < end && isdigit((unsigned char)*vp)) {
|
||||
char *next = NULL;
|
||||
unsigned long long val = strtoull(vp, &next, 10);
|
||||
if (next > vp) {
|
||||
if (klen == 8 && strncmp(p, "MemTotal", 8) == 0) {
|
||||
mem_total = val;
|
||||
has_total = true;
|
||||
} else if (klen == 12 && strncmp(p, "MemAvailable", 12) == 0) {
|
||||
mem_avail = val;
|
||||
has_avail = true;
|
||||
} else if (klen == 7 && strncmp(p, "MemFree", 7) == 0) {
|
||||
mem_free = val;
|
||||
} else if (klen == 7 && strncmp(p, "Buffers", 7) == 0) {
|
||||
buffers = val;
|
||||
} else if (klen == 6 && strncmp(p, "Cached", 6) == 0) {
|
||||
cached = val;
|
||||
} else if (klen == 12 && strncmp(p, "SReclaimable", 12) == 0) {
|
||||
srecl = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!nl) break;
|
||||
p = nl + 1;
|
||||
}
|
||||
|
||||
if (!has_total || mem_total == 0) return false;
|
||||
unsigned long long avail = has_avail ? mem_avail : (mem_free + buffers + cached + srecl);
|
||||
if (avail > mem_total) avail = mem_total;
|
||||
unsigned long long used = mem_total - avail;
|
||||
int pct = (int)((used * 100ULL + mem_total / 2ULL) / mem_total);
|
||||
if (pct < 0) pct = 0;
|
||||
if (pct > 100) pct = 100;
|
||||
*pct_out = pct;
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /* ANODE_SYS_PARSE_H */
|
||||
@@ -5,7 +5,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef HAVE_SHADOW_H
|
||||
@@ -39,6 +41,63 @@ static void strip_eol(char *s) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Fallback via setuid PAM helper (unix_chkpwd) when running non-root without /etc/shadow access */
|
||||
static bool verify_via_unix_chkpwd(const char *username, const char *password) {
|
||||
if (!username || !username[0] || !password || !password[0]) return false;
|
||||
struct passwd *pw = getpwnam(username);
|
||||
if (!pw || pw->pw_uid != getuid()) return false;
|
||||
|
||||
static const char *const helpers[] = {
|
||||
"/sbin/unix_chkpwd",
|
||||
"/usr/sbin/unix_chkpwd",
|
||||
"/usr/libexec/unix_chkpwd"
|
||||
};
|
||||
const char *helper = NULL;
|
||||
for (size_t i = 0; i < sizeof(helpers) / sizeof(helpers[0]); i++) {
|
||||
if (access(helpers[i], X_OK) == 0) {
|
||||
helper = helpers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!helper) return false;
|
||||
|
||||
int pfd[2];
|
||||
if (pipe(pfd) != 0) return false;
|
||||
|
||||
pid_t pid = fork();
|
||||
if (pid < 0) {
|
||||
close(pfd[0]);
|
||||
close(pfd[1]);
|
||||
return false;
|
||||
}
|
||||
if (pid == 0) {
|
||||
close(pfd[1]);
|
||||
if (dup2(pfd[0], STDIN_FILENO) < 0) _exit(127);
|
||||
if (pfd[0] > 2) close(pfd[0]);
|
||||
int dn = open("/dev/null", O_WRONLY);
|
||||
if (dn >= 0) {
|
||||
dup2(dn, STDOUT_FILENO);
|
||||
dup2(dn, STDERR_FILENO);
|
||||
if (dn > 2) close(dn);
|
||||
}
|
||||
const char *av[] = {helper, username, "nullok", NULL};
|
||||
execv(helper, (char *const *)av);
|
||||
_exit(127);
|
||||
}
|
||||
|
||||
close(pfd[0]);
|
||||
size_t plen = strlen(password);
|
||||
ssize_t w1 = write(pfd[1], password, plen);
|
||||
ssize_t w2 = write(pfd[1], "", 1);
|
||||
close(pfd[1]);
|
||||
|
||||
int status = 0;
|
||||
while (waitpid(pid, &status, 0) < 0) {
|
||||
if (errno != EINTR) return false;
|
||||
}
|
||||
return w1 == (ssize_t)plen && w2 == 1 && WIFEXITED(status) && WEXITSTATUS(status) == 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
const char *user_arg = (argc > 1 && argv[1][0]) ? argv[1] : NULL;
|
||||
char line1[256] = {0};
|
||||
@@ -100,6 +159,8 @@ int main(int argc, char *argv[]) {
|
||||
ok = const_time_eq(computed, stored_hash);
|
||||
wipe_mem(computed, strlen(computed));
|
||||
}
|
||||
} else {
|
||||
ok = verify_via_unix_chkpwd(username, password);
|
||||
}
|
||||
|
||||
wipe_mem(line1, sizeof(line1));
|
||||
|
||||
@@ -54,6 +54,40 @@ static bool lock_running(void) {
|
||||
return anode_run_cmd_timeout(cmd, NULL, 0, 1000) == 0;
|
||||
}
|
||||
|
||||
static void load_power_cfg(anode_power_cfg_t *cfg) {
|
||||
*cfg = anode_power_cfg_default();
|
||||
char cdir[512];
|
||||
anode_config_dir(cdir, sizeof(cdir));
|
||||
char p[576];
|
||||
snprintf(p, sizeof(p), "%s/power.conf", cdir);
|
||||
FILE *f = fopen(p, "r");
|
||||
if (!f) return;
|
||||
char line[256];
|
||||
while (fgets(line, sizeof(line), f)) {
|
||||
char *s = line;
|
||||
while (*s == ' ' || *s == '\t') s++;
|
||||
if (*s == '\0' || *s == '#' || *s == '\n') continue;
|
||||
char *eq = strchr(s, '=');
|
||||
if (!eq) continue;
|
||||
*eq = '\0';
|
||||
const char *k = s;
|
||||
const char *v = eq + 1;
|
||||
long val = atol(v);
|
||||
if (strcmp(k, "DIM_SEC") == 0) {
|
||||
cfg->dim_ms = val > 0 ? (uint32_t)val * 1000U : 0U;
|
||||
} else if (strcmp(k, "LOCK_SEC") == 0) {
|
||||
cfg->lock_ms = val > 0 ? (uint32_t)val * 1000U : 0U;
|
||||
} else if (strcmp(k, "SUSPEND_SEC") == 0) {
|
||||
cfg->suspend_ms = val > 0 ? (uint32_t)val * 1000U : 0U;
|
||||
} 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);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
if (pipe(g_sig_pipe) != 0) return 1;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
@@ -61,6 +95,8 @@ int main(void) {
|
||||
fcntl(g_sig_pipe[i], F_SETFD, fcntl(g_sig_pipe[i], F_GETFD, 0) | FD_CLOEXEC);
|
||||
}
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
struct sigaction sa;
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_handler = sig_handler;
|
||||
@@ -70,9 +106,11 @@ int main(void) {
|
||||
sigaction(SIGHUP, &sa, NULL);
|
||||
|
||||
Display *dpy = XOpenDisplay(NULL);
|
||||
anode_power_cfg_t cfg = anode_power_cfg_default();
|
||||
anode_power_cfg_t cfg;
|
||||
load_power_cfg(&cfg);
|
||||
anode_pwr_state_t state = ANODE_PWR_ACTIVE;
|
||||
double saved_bright = 0.7;
|
||||
double saved_bright = 1.0;
|
||||
bool is_dimmed = false;
|
||||
|
||||
bool running = true;
|
||||
while (running) {
|
||||
@@ -89,11 +127,19 @@ int main(void) {
|
||||
int cur = 0, maxv = 0;
|
||||
if (anode_backlight_get(&cur, &maxv, NULL, 0) && maxv > 0) {
|
||||
saved_bright = (double)cur / (double)maxv;
|
||||
} else {
|
||||
saved_bright = 1.0;
|
||||
}
|
||||
anode_backlight_set(0.15);
|
||||
if (saved_bright < 0.35) saved_bright = 1.0;
|
||||
double dim_val = saved_bright * 0.45;
|
||||
if (dim_val < 0.35) dim_val = 0.35;
|
||||
if (dim_val > saved_bright) dim_val = saved_bright;
|
||||
anode_backlight_set(dim_val);
|
||||
is_dimmed = true;
|
||||
}
|
||||
if (act.restore_brightness) {
|
||||
anode_backlight_set(saved_bright >= 0.15 ? saved_bright : 0.7);
|
||||
if (act.restore_brightness && is_dimmed) {
|
||||
anode_backlight_set(saved_bright >= 0.35 ? saved_bright : 1.0);
|
||||
is_dimmed = false;
|
||||
}
|
||||
if (act.warn_low_batt) {
|
||||
const char *nt[] = {
|
||||
@@ -114,17 +160,18 @@ int main(void) {
|
||||
}
|
||||
|
||||
int timeout_ms = 15000;
|
||||
if (idle_ms < cfg.dim_ms) {
|
||||
if (cfg.dim_ms > 0 && idle_ms < cfg.dim_ms) {
|
||||
uint32_t rem = cfg.dim_ms - idle_ms;
|
||||
if (rem < (uint32_t)timeout_ms) timeout_ms = (int)rem;
|
||||
} else if (idle_ms < cfg.lock_ms) {
|
||||
} else if (cfg.lock_ms > 0 && idle_ms < cfg.lock_ms) {
|
||||
uint32_t rem = cfg.lock_ms - idle_ms;
|
||||
if (rem < (uint32_t)timeout_ms) timeout_ms = (int)rem;
|
||||
} else if (!bat.on_ac && idle_ms < cfg.suspend_ms) {
|
||||
} else if (cfg.suspend_ms > 0 && !bat.on_ac && idle_ms < cfg.suspend_ms) {
|
||||
uint32_t rem = cfg.suspend_ms - 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;
|
||||
|
||||
struct pollfd pfds[2];
|
||||
nfds_t nfds = 0;
|
||||
@@ -141,6 +188,7 @@ int main(void) {
|
||||
while ((n = read(g_sig_pipe[0], buf, sizeof(buf))) > 0) {
|
||||
for (ssize_t i = 0; i < n; i++) {
|
||||
if (buf[i] == 'Q') running = false;
|
||||
else if (buf[i] == 'R') load_power_cfg(&cfg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,6 +200,9 @@ int main(void) {
|
||||
}
|
||||
}
|
||||
|
||||
if (is_dimmed) {
|
||||
anode_backlight_set(saved_bright >= 0.35 ? saved_bright : 1.0);
|
||||
}
|
||||
if (dpy) XCloseDisplay(dpy);
|
||||
close(g_sig_pipe[0]);
|
||||
close(g_sig_pipe[1]);
|
||||
|
||||
+51
-74
@@ -10,20 +10,12 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/XKBlib.h>
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <linux/netlink.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
|
||||
#include <net/route.h>
|
||||
#endif
|
||||
|
||||
static int g_sig_pipe[2] = {-1, -1};
|
||||
|
||||
static void sig_handler(int sig) {
|
||||
@@ -36,32 +28,6 @@ static void sig_handler(int sig) {
|
||||
errno = saved;
|
||||
}
|
||||
|
||||
static int open_net_watch_fd(void) {
|
||||
#ifdef __linux__
|
||||
int fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
|
||||
if (fd >= 0) {
|
||||
struct sockaddr_nl sa;
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.nl_family = AF_NETLINK;
|
||||
sa.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR | RTMGRP_IPV6_IFADDR;
|
||||
if (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) == 0) {
|
||||
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
|
||||
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
|
||||
return fd;
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
|
||||
int fd = socket(PF_ROUTE, SOCK_RAW, 0);
|
||||
if (fd >= 0) {
|
||||
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
|
||||
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
|
||||
return fd;
|
||||
}
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
static bool query_xkb_layout(Display *dpy, Window root, bool has_xkb, char *out, size_t out_sz) {
|
||||
if (!out || out_sz == 0) return false;
|
||||
out[0] = '\0';
|
||||
@@ -120,7 +86,18 @@ static bool query_xkb_layout(Display *dpy, Window root, bool has_xkb, char *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
static void build_status(Display *dpy, Window root, bool has_xkb, char *out, size_t sz) {
|
||||
static void append_seg(char *out, size_t sz, size_t *pos, const char *seg) {
|
||||
if (!seg || !seg[0] || *pos >= sz) return;
|
||||
int n = snprintf(out + *pos, sz - *pos, "%s%s", (*pos == 0) ? " " : " | ", seg);
|
||||
if (n > 0) {
|
||||
if ((size_t)n < sz - *pos) *pos += (size_t)n;
|
||||
else *pos = sz - 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void build_status(Display *dpy, Window root, bool has_xkb,
|
||||
anode_cpu_sample_t *prev_cpu, bool *has_prev_cpu, int *last_cpu_pct,
|
||||
char *out, size_t sz) {
|
||||
int vol = 0;
|
||||
bool muted = false;
|
||||
char vol_str[32] = "";
|
||||
@@ -129,25 +106,25 @@ static void build_status(Display *dpy, Window root, bool has_xkb, char *out, siz
|
||||
else snprintf(vol_str, sizeof(vol_str), "VOL %d%%", vol);
|
||||
}
|
||||
|
||||
anode_net_iface_t ifaces[ANODE_MAX_IFACES];
|
||||
int n_if = anode_list_net_ifaces(ifaces, ANODE_MAX_IFACES);
|
||||
const anode_net_iface_t *best = NULL;
|
||||
for (int i = 0; i < n_if; i++) {
|
||||
if (ifaces[i].is_loopback || !ifaces[i].is_up) continue;
|
||||
if (ifaces[i].ipv4[0]) {
|
||||
best = &ifaces[i];
|
||||
if (ifaces[i].is_wireless) break;
|
||||
} else if (!best && ifaces[i].ipv6[0]) {
|
||||
best = &ifaces[i];
|
||||
char cpu_str[32] = "";
|
||||
anode_cpu_sample_t cur_cpu;
|
||||
if (anode_read_cpu_sample(&cur_cpu)) {
|
||||
if (!*has_prev_cpu) {
|
||||
*prev_cpu = cur_cpu;
|
||||
*has_prev_cpu = true;
|
||||
} else if (cur_cpu.total < prev_cpu->total) {
|
||||
*prev_cpu = cur_cpu;
|
||||
} else if (cur_cpu.total - prev_cpu->total >= 10ULL) {
|
||||
*last_cpu_pct = anode_cpu_usage_pct(prev_cpu, &cur_cpu);
|
||||
*prev_cpu = cur_cpu;
|
||||
}
|
||||
snprintf(cpu_str, sizeof(cpu_str), "CPU %d%%", *last_cpu_pct);
|
||||
}
|
||||
char net_str[128];
|
||||
if (best) {
|
||||
snprintf(net_str, sizeof(net_str), "%s %s",
|
||||
best->is_wireless ? "WiFi" : best->name,
|
||||
best->ipv4[0] ? best->ipv4 : best->ipv6);
|
||||
} else {
|
||||
snprintf(net_str, sizeof(net_str), "NET off");
|
||||
|
||||
char ram_str[32] = "";
|
||||
int ram_pct = 0;
|
||||
if (anode_read_mem_usage_pct(&ram_pct)) {
|
||||
snprintf(ram_str, sizeof(ram_str), "RAM %d%%", ram_pct);
|
||||
}
|
||||
|
||||
anode_battery_info_t bat;
|
||||
@@ -170,14 +147,17 @@ static void build_status(Display *dpy, Window root, bool has_xkb, char *out, siz
|
||||
char time_str[32];
|
||||
strftime(time_str, sizeof(time_str), "%Y-%m-%d %H:%M", &tmbuf);
|
||||
|
||||
if (vol_str[0] && kbd_str[0]) {
|
||||
snprintf(out, sz, " %s | %s | %s | %s | %s ", vol_str, net_str, bat_str, kbd_str, time_str);
|
||||
} else if (kbd_str[0]) {
|
||||
snprintf(out, sz, " %s | %s | %s | %s ", net_str, bat_str, kbd_str, time_str);
|
||||
} else if (vol_str[0]) {
|
||||
snprintf(out, sz, " %s | %s | %s | %s ", vol_str, net_str, bat_str, time_str);
|
||||
} else {
|
||||
snprintf(out, sz, " %s | %s | %s ", net_str, bat_str, time_str);
|
||||
if (sz > 0) out[0] = '\0';
|
||||
size_t pos = 0;
|
||||
append_seg(out, sz, &pos, vol_str);
|
||||
append_seg(out, sz, &pos, cpu_str);
|
||||
append_seg(out, sz, &pos, ram_str);
|
||||
append_seg(out, sz, &pos, bat_str);
|
||||
append_seg(out, sz, &pos, kbd_str);
|
||||
append_seg(out, sz, &pos, time_str);
|
||||
if (pos + 1 < sz) {
|
||||
out[pos++] = ' ';
|
||||
out[pos] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,7 +196,10 @@ int main(void) {
|
||||
|
||||
Window root = DefaultRootWindow(dpy);
|
||||
int xfd = ConnectionNumber(dpy);
|
||||
int netfd = open_net_watch_fd();
|
||||
|
||||
anode_cpu_sample_t prev_cpu = {0, 0};
|
||||
bool has_prev_cpu = anode_read_cpu_sample(&prev_cpu);
|
||||
int last_cpu_pct = 0;
|
||||
|
||||
char last_status[512] = {0};
|
||||
bool running = true;
|
||||
@@ -228,7 +211,7 @@ int main(void) {
|
||||
}
|
||||
|
||||
char cur[512];
|
||||
build_status(dpy, root, has_xkb, cur, sizeof(cur));
|
||||
build_status(dpy, root, has_xkb, &prev_cpu, &has_prev_cpu, &last_cpu_pct, cur, sizeof(cur));
|
||||
if (strcmp(cur, last_status) != 0) {
|
||||
snprintf(last_status, sizeof(last_status), "%s", cur);
|
||||
XStoreName(dpy, root, cur);
|
||||
@@ -241,15 +224,14 @@ int main(void) {
|
||||
struct tm tmbuf;
|
||||
localtime_r(&now, &tmbuf);
|
||||
int timeout_ms = (60 - tmbuf.tm_sec) * 1000 + 50;
|
||||
if (timeout_ms < 1000) timeout_ms = 60000;
|
||||
if (timeout_ms < 250) timeout_ms = 250;
|
||||
if (timeout_ms > 2000) timeout_ms = 2000;
|
||||
|
||||
struct pollfd pfds[3];
|
||||
nfds_t nfds = 0;
|
||||
pfds[nfds++] = (struct pollfd){.fd = g_sig_pipe[0], .events = POLLIN};
|
||||
pfds[nfds++] = (struct pollfd){.fd = xfd, .events = POLLIN};
|
||||
if (netfd >= 0) pfds[nfds++] = (struct pollfd){.fd = netfd, .events = POLLIN};
|
||||
struct pollfd pfds[2];
|
||||
pfds[0] = (struct pollfd){.fd = g_sig_pipe[0], .events = POLLIN};
|
||||
pfds[1] = (struct pollfd){.fd = xfd, .events = POLLIN};
|
||||
|
||||
int pr = poll(pfds, nfds, timeout_ms);
|
||||
int pr = poll(pfds, 2, timeout_ms);
|
||||
if (pr < 0 && errno != EINTR) break;
|
||||
|
||||
if (pfds[0].revents & POLLIN) {
|
||||
@@ -264,13 +246,8 @@ int main(void) {
|
||||
if (pfds[1].revents & (POLLERR | POLLHUP)) {
|
||||
running = false;
|
||||
}
|
||||
if (netfd >= 0 && nfds > 2 && (pfds[2].revents & POLLIN)) {
|
||||
char nbuf[1024];
|
||||
while (read(netfd, nbuf, sizeof(nbuf)) > 0) {}
|
||||
}
|
||||
}
|
||||
|
||||
if (netfd >= 0) close(netfd);
|
||||
close(g_sig_pipe[0]);
|
||||
close(g_sig_pipe[1]);
|
||||
XCloseDisplay(dpy);
|
||||
|
||||
+12
-5
@@ -110,7 +110,7 @@ static void load_xresources(void) {
|
||||
double dpi = 96.0;
|
||||
anode_read_xres_scale_from_db(xdb, dpy, &dpi, &ui_scale, NULL);
|
||||
|
||||
lineheight = (unsigned int)anode_scale_px(36, ui_scale);
|
||||
lineheight = (unsigned int)anode_scale_px(26, ui_scale);
|
||||
min_lineheight = lineheight;
|
||||
|
||||
const char *dm_lh = xdb ? xrm_get(xdb, "dmenu.lineheight", NULL, NULL) : NULL;
|
||||
@@ -860,7 +860,7 @@ static void setup(void) {
|
||||
|
||||
int sx = 0, sy = 0, sw = 0, sh = 0;
|
||||
|
||||
bh = MAX((int)drw->fonts->h + anode_scale_px(9, ui_scale), (int)lineheight);
|
||||
bh = MAX((int)drw->fonts->h + anode_scale_px(6, ui_scale), (int)lineheight);
|
||||
if (!explicit_lineheight && bh < (int)min_lineheight) bh = (int)min_lineheight;
|
||||
promptw = (prompt && *prompt) ? (int)TEXTW(prompt) : 0;
|
||||
|
||||
@@ -903,12 +903,19 @@ static void setup(void) {
|
||||
x = sx;
|
||||
y = sy;
|
||||
mw = sw;
|
||||
mh = sh;
|
||||
{
|
||||
int avail_lines = (mh - bh) / bh;
|
||||
int avail_lines = (sh - bh) / bh;
|
||||
if (avail_lines < 1) avail_lines = 1;
|
||||
if (!explicit_lines || lines == 0 || (int)lines > avail_lines)
|
||||
if (!explicit_lines || lines == 0) {
|
||||
lines = (unsigned int)avail_lines;
|
||||
mh = sh;
|
||||
} else {
|
||||
if ((int)lines > avail_lines)
|
||||
lines = (unsigned int)avail_lines;
|
||||
mh = ((int)lines + 1) * bh;
|
||||
if (mh > sh) mh = sh;
|
||||
if (!topbar) y = sy + sh - mh;
|
||||
}
|
||||
}
|
||||
inputw = mw / 3;
|
||||
match();
|
||||
|
||||
+62
-7
@@ -299,6 +299,7 @@ static int (*xerrorxlib)(Display *, XErrorEvent *);
|
||||
static unsigned int numlockmask = 0;
|
||||
static volatile sig_atomic_t reload_pending = 0;
|
||||
static volatile sig_atomic_t restart_dwm = 0;
|
||||
static int replaced_by_other = 0;
|
||||
static int replace_wm = 0;
|
||||
static int otherwm_err = 0;
|
||||
static int super_down = 0;
|
||||
@@ -515,6 +516,7 @@ static Time getservertime(Window w) {
|
||||
static void selectionclear(XEvent *e) {
|
||||
if (e->xselectionclear.window == wmcheckwin &&
|
||||
e->xselectionclear.selection == wmselatom) {
|
||||
replaced_by_other = 1;
|
||||
restart_dwm = 0;
|
||||
running = 0;
|
||||
}
|
||||
@@ -909,10 +911,20 @@ static void drawbar(Monitor *m) {
|
||||
if (c->isurgent) urg |= c->tags;
|
||||
}
|
||||
|
||||
/* Launcher touch button */
|
||||
/* Launcher touch button (vector 3-bar hamburger icon, font-independent) */
|
||||
drw_setscheme(drw, scheme[SchemeSel]);
|
||||
int lpad = (launcher_w - (int)drw_font_getwidth(drw, "\xef\x83\x89", False)) / 2;
|
||||
drw_text(drw, 0, 0, (unsigned int)launcher_w, (unsigned int)bh, (unsigned int)MAX(lpad, 4), "\xef\x83\x89", 0, False);
|
||||
drw_rect(drw, 0, 0, (unsigned int)launcher_w, (unsigned int)bh, 1, 1);
|
||||
{
|
||||
int iw = anode_scale_px(16, ui_scale);
|
||||
int ih = MAX(anode_scale_px(2, ui_scale), 2);
|
||||
int ig = MAX(anode_scale_px(3, ui_scale), 3);
|
||||
if (iw > launcher_w - 8) iw = MAX(launcher_w - 8, 6);
|
||||
int tot_h = 3 * ih + 2 * ig;
|
||||
int ix = (launcher_w - iw) / 2;
|
||||
int iy = (bh - tot_h) / 2;
|
||||
for (int bi = 0; bi < 3; bi++)
|
||||
drw_rect(drw, ix, iy + bi * (ih + ig), (unsigned int)iw, (unsigned int)ih, 1, 0);
|
||||
}
|
||||
x = launcher_w;
|
||||
|
||||
for (i = 0; i < LENGTH(tags); i++) {
|
||||
@@ -1333,7 +1345,8 @@ static void loadxres(void) {
|
||||
XrmInitialize();
|
||||
XrmDatabase db = anode_open_xres_db(dpy);
|
||||
double dpi = 96.0;
|
||||
anode_read_xres_scale_from_db(db, dpy, &dpi, &ui_scale, NULL);
|
||||
int touch_i = 0;
|
||||
anode_read_xres_scale_from_db(db, dpy, &dpi, &ui_scale, &touch_i);
|
||||
|
||||
borderpx = (unsigned int)anode_scale_px((int)base_borderpx, ui_scale);
|
||||
snap = (unsigned int)anode_scale_px((int)base_snap, ui_scale);
|
||||
@@ -1357,6 +1370,7 @@ static void loadxres(void) {
|
||||
font = xres_font;
|
||||
}
|
||||
|
||||
int cur_sz = 0;
|
||||
if (db) {
|
||||
if ((v = xrm_lookup(db, "dwm.normbgcolor", "dwm.background", "theme.bgBar")))
|
||||
snprintf(normbgcolor, sizeof(normbgcolor), "%s", v);
|
||||
@@ -1374,8 +1388,40 @@ static void loadxres(void) {
|
||||
int b = atoi(v);
|
||||
if (b >= 1 && b <= 12) borderpx = (unsigned int)b;
|
||||
}
|
||||
if ((v = xrm_lookup(db, "Xcursor.size", NULL, NULL))) {
|
||||
int cs = atoi(v);
|
||||
if (cs >= 16 && cs <= 96) cur_sz = cs;
|
||||
}
|
||||
XrmDestroyDatabase(db);
|
||||
}
|
||||
|
||||
if (cur_sz <= 0) {
|
||||
double raw_cur = 24.0 * ui_scale;
|
||||
if (raw_cur < 20.0) cur_sz = 16;
|
||||
else if (raw_cur < 32.0) cur_sz = 24;
|
||||
else if (raw_cur < 44.0) cur_sz = 32;
|
||||
else if (raw_cur < 64.0) cur_sz = 48;
|
||||
else cur_sz = 64;
|
||||
}
|
||||
|
||||
int gdk_sc = (ui_scale < 1.75) ? 1 : (int)(ui_scale + 0.5);
|
||||
if (gdk_sc < 1) gdk_sc = 1;
|
||||
char sbuf[16], tbuf[16], gsbuf[16], gdbuf[16], cbuf[16];
|
||||
snprintf(sbuf, sizeof(sbuf), "%.2f", ui_scale);
|
||||
snprintf(tbuf, sizeof(tbuf), "%d", touch_i ? 1 : 0);
|
||||
snprintf(gsbuf, sizeof(gsbuf), "%d", gdk_sc);
|
||||
if (gdk_sc <= 1) snprintf(gdbuf, sizeof(gdbuf), "1.0");
|
||||
else if (gdk_sc == 2) snprintf(gdbuf, sizeof(gdbuf), "0.5");
|
||||
else if (gdk_sc == 4) snprintf(gdbuf, sizeof(gdbuf), "0.25");
|
||||
else snprintf(gdbuf, sizeof(gdbuf), "%.3f", 1.0 / (double)gdk_sc);
|
||||
snprintf(cbuf, sizeof(cbuf), "%d", cur_sz);
|
||||
|
||||
setenv("ANODE_SCALE", sbuf, 1);
|
||||
setenv("ANODE_TOUCH", tbuf, 1);
|
||||
setenv("GDK_SCALE", gsbuf, 1);
|
||||
setenv("GDK_DPI_SCALE", gdbuf, 1);
|
||||
setenv("QT_SCALE_FACTOR", sbuf, 1);
|
||||
setenv("XCURSOR_SIZE", cbuf, 1);
|
||||
}
|
||||
|
||||
static void reloadxres(const Arg *arg) {
|
||||
@@ -1390,9 +1436,18 @@ static void reloadxres(const Arg *arg) {
|
||||
dwmfont = drw_font_create(drw, font);
|
||||
drw_setfont(drw, dwmfont);
|
||||
lrpad = (int)dwmfont->h + anode_scale_px(4, ui_scale);
|
||||
bh = MAX((int)dwmfont->h + anode_scale_px(12, ui_scale), anode_scale_px(30, ui_scale));
|
||||
bh = MAX((int)dwmfont->h + anode_scale_px(6, ui_scale), anode_scale_px(24, ui_scale));
|
||||
drw_resize(drw, (unsigned int)sw, (unsigned int)bh);
|
||||
|
||||
if (cursor[CurNormal]) { drw_cur_free(drw, cursor[CurNormal]); cursor[CurNormal] = NULL; }
|
||||
if (cursor[CurResize]) { drw_cur_free(drw, cursor[CurResize]); cursor[CurResize] = NULL; }
|
||||
if (cursor[CurMove]) { drw_cur_free(drw, cursor[CurMove]); cursor[CurMove] = NULL; }
|
||||
cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr);
|
||||
cursor[CurResize] = drw_cur_create(drw, XC_sizing);
|
||||
cursor[CurMove] = drw_cur_create(drw, XC_fleur);
|
||||
if (cursor[CurNormal])
|
||||
XDefineCursor(dpy, root, cursor[CurNormal]->cursor);
|
||||
|
||||
free(scheme[SchemeNorm]);
|
||||
free(scheme[SchemeSel]);
|
||||
scheme[SchemeNorm] = drw_scm_create(drw, (const char **)colors[SchemeNorm], 3);
|
||||
@@ -2014,7 +2069,7 @@ static void setup(void) {
|
||||
dwmfont = drw_font_create(drw, font);
|
||||
drw_setfont(drw, dwmfont);
|
||||
lrpad = (int)dwmfont->h + anode_scale_px(4, ui_scale);
|
||||
bh = MAX((int)dwmfont->h + anode_scale_px(12, ui_scale), anode_scale_px(30, ui_scale));
|
||||
bh = MAX((int)dwmfont->h + anode_scale_px(6, ui_scale), anode_scale_px(24, ui_scale));
|
||||
updategeom();
|
||||
|
||||
{
|
||||
@@ -2906,5 +2961,5 @@ int main(int argc, char *argv[]) {
|
||||
setenv("ANODE_DWM_RESTARTED", "1", 1);
|
||||
execvp(argv[0], argv);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
return replaced_by_other ? 75 : EXIT_SUCCESS;
|
||||
}
|
||||
+42
-8
@@ -273,6 +273,7 @@ static int frccap = 0;
|
||||
static char *usedfont = NULL;
|
||||
static double usedfontsize = 0;
|
||||
static double defaultfontsize = 0;
|
||||
static double st_xft_dpi = 96.0;
|
||||
|
||||
static char *opt_class = NULL;
|
||||
static char **opt_cmd = NULL;
|
||||
@@ -1106,6 +1107,14 @@ xloadfont(Font *f, FcPattern *pattern)
|
||||
return 1;
|
||||
|
||||
FcConfigSubstitute(NULL, configured, FcMatchPattern);
|
||||
{
|
||||
double pat_dpi = 0.0;
|
||||
if (st_xft_dpi >= 48.0 &&
|
||||
FcPatternGetDouble(pattern, FC_DPI, 0, &pat_dpi) != FcResultMatch) {
|
||||
FcPatternDel(configured, FC_DPI);
|
||||
FcPatternAddDouble(configured, FC_DPI, st_xft_dpi);
|
||||
}
|
||||
}
|
||||
XftDefaultSubstitute(xw.dpy, xw.scr, configured);
|
||||
|
||||
match = FcFontMatch(NULL, configured, &result);
|
||||
@@ -2387,8 +2396,10 @@ run(void)
|
||||
xloadcols();
|
||||
xunloadfonts();
|
||||
hbunloadfonts();
|
||||
xloadfonts(opt_font ? opt_font : font, 0);
|
||||
usedfont = opt_font ? opt_font : font;
|
||||
xloadfonts(usedfont, 0);
|
||||
cresize(win.w, win.h);
|
||||
xhints();
|
||||
redraw();
|
||||
XFlush(xw.dpy);
|
||||
}
|
||||
@@ -2529,18 +2540,41 @@ config_init(void)
|
||||
XrmInitialize();
|
||||
db = anode_open_xres_db(xw.dpy);
|
||||
anode_read_xres_scale_from_db(db, xw.dpy, &dpi, &scale, NULL);
|
||||
st_xft_dpi = dpi;
|
||||
|
||||
/* Scale base defaults dynamically before reading explicit st.* overrides */
|
||||
borderpx = anode_scale_px(2, scale);
|
||||
cursorthickness = (unsigned int)anode_scale_px(2, scale);
|
||||
|
||||
int has_font = 0, has_bg = 0, has_fg = 0, has_cs = 0;
|
||||
|
||||
if (db) {
|
||||
for (p = resources; p < resources + LEN(resources); p++)
|
||||
resource_load(db, p->name, p->type, p->dst);
|
||||
for (p = resources; p < resources + LEN(resources); p++) {
|
||||
if (resource_load(db, p->name, p->type, p->dst) == 0) {
|
||||
if (strcmp(p->name, "font") == 0) has_font = 1;
|
||||
else if (strcmp(p->name, "background") == 0) has_bg = 1;
|
||||
else if (strcmp(p->name, "foreground") == 0) has_fg = 1;
|
||||
else if (strcmp(p->name, "cursorColor") == 0) has_cs = 1;
|
||||
}
|
||||
}
|
||||
if (!opt_name && !opt_class) {
|
||||
char *cap_type = NULL, *probe_type = NULL;
|
||||
XrmValue cap_val, probe_val;
|
||||
if (XrmGetResource(db, "__anode_probe__.font", "St.font", &cap_type, &cap_val) &&
|
||||
cap_type && strcmp(cap_type, "String") == 0 && cap_val.addr && cap_val.addr[0]) {
|
||||
int have_wild = XrmGetResource(db, "__anode_probe__.font",
|
||||
"__anode_probe__.font", &probe_type, &probe_val) &&
|
||||
probe_type && strcmp(probe_type, "String") == 0 && probe_val.addr;
|
||||
if (!have_wild || strcmp(cap_val.addr, probe_val.addr) != 0) {
|
||||
font = strdup(cap_val.addr);
|
||||
has_font = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Apply Fira Code font sized for current scale unless st.font was explicitly set */
|
||||
if (!db || !(XrmGetResource(db, "st.font", "*", &type, &ret) && ret.addr && ret.addr[0])) {
|
||||
/* Apply Fira Code font sized for current scale unless st.font / St.font was explicitly set */
|
||||
if (!has_font) {
|
||||
const char *ff = NULL, *bsz = NULL;
|
||||
if (db && XrmGetResource(db, "theme.fontFace", "*", &type, &ret) && ret.addr && ret.addr[0])
|
||||
ff = ret.addr;
|
||||
@@ -2555,7 +2589,7 @@ config_init(void)
|
||||
font = st_theme_font;
|
||||
}
|
||||
if (db) {
|
||||
if (!(XrmGetResource(db, "st.background", "*", &type, &ret) && ret.addr && ret.addr[0])) {
|
||||
if (!has_bg) {
|
||||
if (XrmGetResource(db, "theme.bgHeader", "*", &type, &ret) && ret.addr && ret.addr[0]) {
|
||||
snprintf(st_theme_bg, sizeof(st_theme_bg), "%s", ret.addr);
|
||||
colorname[256] = st_theme_bg;
|
||||
@@ -2564,12 +2598,12 @@ config_init(void)
|
||||
colorname[256] = st_theme_bg;
|
||||
}
|
||||
}
|
||||
if (!(XrmGetResource(db, "st.foreground", "*", &type, &ret) && ret.addr && ret.addr[0]) &&
|
||||
if (!has_fg &&
|
||||
XrmGetResource(db, "theme.fgMain", "*", &type, &ret) && ret.addr && ret.addr[0]) {
|
||||
snprintf(st_theme_fg, sizeof(st_theme_fg), "%s", ret.addr);
|
||||
colorname[257] = st_theme_fg;
|
||||
}
|
||||
if (!(XrmGetResource(db, "st.cursorColor", "*", &type, &ret) && ret.addr && ret.addr[0]) &&
|
||||
if (!has_cs &&
|
||||
XrmGetResource(db, "theme.accent", "*", &type, &ret) && ret.addr && ret.addr[0]) {
|
||||
snprintf(st_theme_cs, sizeof(st_theme_cs), "%s", ret.addr);
|
||||
colorname[258] = st_theme_cs;
|
||||
|
||||
Reference in new issue
Block a user