Files
MeowOS-For-R3P2/patch_v2/sdk/meow_ui_vol.c
T
MeowOS e6f0b665e3 refactor(launcher): 拆分 meow_launcherd.c(9778行)→meow_launcherd/ 多文件(agent-149)
- 14 模块 .c + meow_launcher_internal.h(642): util/font_theme/fb_compositor/settings_page/power_menu/notif_center/app_launcher/main_menu/audio/backlight/net/keys/about/statusbar; meow_launcherd.c 已删
- 按行逐字搬移(0-diff), 118函数提升非static+47组extern(内部头), #if0退役区不编入(源码留.pre_split.bak)
- 关于本机小改: 作者 AskaEth/17 + info/item[13]防越界 + s_dd_modal 超高滚动(clamp/触摸滚动/音量键跟随/裁剪, 仅超高启用)
- build_launcher.sh 编译列表→模块; 文档/注释引用 meow_launcherd.c→模块/目录
- 编译0warning/-Wall -Wextra告警集与原文一致(77条无新增)/qemu-mipsel冒烟一致(--scan/--sysdump); launcher=c0799357(505KB; md5因多文件重编译与原文异,非回归依据)
- 备份 meow_launcherd.c.pre_split.bak/meow_launcherd.pre_split.bak; M2.69(0.7.64)已推卡并用户验证OK
2026-08-30 21:38:30 +08:00

53 lines
2.0 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* meow_ui_vol.c — SDK 状态栏音量换算纯函数 + settings.conf 读取(A-0 核心数源)。
*
* 单独成 TU 的目的:
* 1. 纯函数(clamp / 键读取)不依赖 meow_ui 其它子系统,宿主 gcc 直接可测
* (test_meow_ui_vol.c),无需链整库/stub。
* 2. 把「音量从 settings 读数并 clamp 到 volume_max」这一语义钉死在单点,
* 与 launcher 的 vol_clamp(audio.c)口径对齐,杜绝两端音量漂移。
*
* 数据源:/usr/data/meow/settings.conf 扁平 key=value。launcher meow_settings.c
* 落盘为 "key = value"(带空格),本解析兼容无空格/多空格,与 launcher 读循环
* 及 sdk meow_ui_theme.c 的 get_setting_str 同款解析。
*/
#include "meow_ui_vol.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int meow_ui_vol_clamp(int vol, int vol_max)
{
if (vol < 0) vol = 0;
if (vol > MEOW_UI_VOL_MAX) vol = MEOW_UI_VOL_MAX;
if (vol_max < 0) vol_max = 0; /* 异常上限兜底:不进负值 */
if (vol > vol_max) vol = vol_max;
return vol;
}
int meow_ui_vol_read(const char *path, const char *key, int def)
{
if (!path || !key) return def;
FILE *f = fopen(path, "r");
if (!f) return def;
int kl = (int)strlen(key);
char line[160];
char *found = NULL;
while (fgets(line, sizeof line, f)) {
char *eq = strchr(line, '=');
if (!eq) continue; /* 非 key=value 行(注释/空行)跳过 */
char *k = line;
while (*k == ' ' || *k == '\t') k++; /* key 左去空白 */
int n = (int)(eq - k);
while (n > 0 && (k[n-1] == ' ' || k[n-1] == '\t')) n--; /* key 右去空白 */
if (n != kl || strncmp(k, key, (size_t)kl) != 0) continue; /* key 不精确匹配 */
found = eq + 1; /* 命中所求键 */
break;
}
fclose(f);
if (!found) return def;
while (*found == ' ' || *found == '\t') found++; /* value 左去空白;atoi 天然停于非数字 */
return atoi(found);
}