Fix mobile data static IP bearer, call recording, earpiece audio, and ringtone/vibration
This commit is contained in:
1 parent
21dfb187be
commit
a8a28fa685
23 files changed
+624
-212
No files matched your search
+63
-16
@@ -43,7 +43,7 @@ constexpr int kWinX = 0;
|
||||
constexpr int kWinY = kTopBarHeight;
|
||||
constexpr int kWinWidth = kScreenWidth;
|
||||
constexpr int kWinHeight = kScreenHeight - kTopBarHeight; // 296px flush below 24px dwm bar
|
||||
constexpr int kRowCount = 9;
|
||||
constexpr int kRowCount = 10;
|
||||
|
||||
// Nerd Font PUA icons matching sxmo_hook_icons.sh & dwm ("Fira Code, DejaVuSansM Nerd Font")
|
||||
constexpr const char* kIconSpeaker = "\xef\x80\xa8"; // U+F028 speaker
|
||||
@@ -242,11 +242,12 @@ enum class ControlId {
|
||||
EarpieceVol = 1,
|
||||
RingVol = 2,
|
||||
RingerMode = 3,
|
||||
Flashlight = 4,
|
||||
SoundMute = 5,
|
||||
MicMute = 6,
|
||||
ScreenBright = 7,
|
||||
KbdBright = 8,
|
||||
VibrateStrength = 4,
|
||||
Flashlight = 5,
|
||||
SoundMute = 6,
|
||||
MicMute = 7,
|
||||
ScreenBright = 8,
|
||||
KbdBright = 9,
|
||||
};
|
||||
|
||||
struct ControlItem {
|
||||
@@ -300,15 +301,15 @@ class PhoneController {
|
||||
items_.push_back({ControlId::SpeakerVol, kIconSpeaker, kIconSoundOff,
|
||||
"Speaker", true, 0, 100, 5, spkPct});
|
||||
|
||||
// 2. Earpiece volume (0..100%, mapped to ALSA RX1 Digital Volume 58..90)
|
||||
long rx1 = alsa_.getInteger("RX1 Digital Volume", 84);
|
||||
int earPct = 100;
|
||||
// 2. Earpiece volume (0..100%, mapped to ALSA RX1 Digital Volume 68..92)
|
||||
long rx1 = alsa_.getInteger("RX1 Digital Volume", 88);
|
||||
int earPct = 85;
|
||||
if (rx1 <= 0) {
|
||||
earPct = 0;
|
||||
} else if (rx1 < 84) {
|
||||
earPct = std::clamp(static_cast<int>(std::lround((rx1 * 100.0) / 84.0)), 5, 100);
|
||||
} else if (rx1 >= 68) {
|
||||
earPct = std::clamp(static_cast<int>(std::lround(((rx1 - 68) * 100.0) / 24.0)), 5, 100);
|
||||
}
|
||||
earPct = (earPct / 5) * 5;
|
||||
earPct = ((earPct + 2) / 5) * 5;
|
||||
items_.push_back({ControlId::EarpieceVol, kIconEarpiece, kIconEarpiece,
|
||||
"Earpiece", true, 0, 100, 5, earPct});
|
||||
|
||||
@@ -322,6 +323,11 @@ class PhoneController {
|
||||
items_.push_back({ControlId::RingerMode, kIconBell, kIconBellSlash,
|
||||
"Ringer", false, 0, 3, 1, ringerVal});
|
||||
|
||||
// 5. Vibration Strength (1=Light, 2=Medium, 3=Strong)
|
||||
int vibVal = readVibrateStrength();
|
||||
items_.push_back({ControlId::VibrateStrength, kIconBell, kIconBell,
|
||||
"Vibration", false, 1, 3, 1, vibVal});
|
||||
|
||||
// 5. Flashlight on/off (toggle)
|
||||
int torchCur = readIntFile(torchDir_ + "/brightness", 0);
|
||||
items_.push_back({ControlId::Flashlight, kIconFlashlight, kIconFlashlight,
|
||||
@@ -373,6 +379,8 @@ class PhoneController {
|
||||
it.value = std::clamp(it.value + dir * it.stepVal, it.minVal, it.maxVal);
|
||||
} else if (it.id == ControlId::RingerMode) {
|
||||
it.value = (it.value + dir + 4) % 4;
|
||||
} else if (it.id == ControlId::VibrateStrength) {
|
||||
it.value = ((it.value - 1 + dir + 3) % 3) + 1;
|
||||
} else {
|
||||
it.value = it.value ? 0 : 1;
|
||||
}
|
||||
@@ -387,6 +395,9 @@ class PhoneController {
|
||||
if (it.id == ControlId::RingerMode) {
|
||||
it.value = (it.value + 1) % 4;
|
||||
apply(it);
|
||||
} else if (it.id == ControlId::VibrateStrength) {
|
||||
it.value = (it.value % 3) + 1;
|
||||
apply(it);
|
||||
} else if (!it.isSlider) {
|
||||
it.value = it.value ? 0 : 1;
|
||||
apply(it);
|
||||
@@ -432,13 +443,30 @@ class PhoneController {
|
||||
return 100;
|
||||
}
|
||||
|
||||
static void writeRingVolume(int ringVol) {
|
||||
static int readVibrateStrength() {
|
||||
std::ifstream ifs(getSxmoCfgDir() + "/ringsettings");
|
||||
std::string line;
|
||||
while (std::getline(ifs, line)) {
|
||||
auto eq = line.find('=');
|
||||
if (eq == std::string::npos) continue;
|
||||
std::string k = line.substr(0, eq);
|
||||
std::string v = line.substr(eq + 1);
|
||||
if (k == "SXMO_VIBRATE_STRENGTH") {
|
||||
int val = std::atoi(v.c_str());
|
||||
if (val >= 1 && val <= 3) return val;
|
||||
}
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
static void writeRingAndVibSettings(int newRingVol, int newVibStrength) {
|
||||
std::string cfg = getSxmoCfgDir();
|
||||
::mkdir(cfg.c_str(), 0755);
|
||||
std::string path = cfg + "/ringsettings";
|
||||
int ringTime = 20;
|
||||
int ringLoops = 10;
|
||||
int vibStrength = 2;
|
||||
int ringVol = 100;
|
||||
{
|
||||
std::ifstream ifs(path);
|
||||
std::string line;
|
||||
@@ -450,14 +478,17 @@ class PhoneController {
|
||||
if (k == "SXMO_RINGTIME" && val >= 5 && val <= 120) ringTime = val;
|
||||
else if (k == "SXMO_RINGNUMBER" && val >= 1 && val <= 100) ringLoops = val;
|
||||
else if (k == "SXMO_VIBRATE_STRENGTH" && val >= 1 && val <= 3) vibStrength = val;
|
||||
else if (k == "SXMO_RINGVOL" && val >= 0 && val <= 100) ringVol = val;
|
||||
}
|
||||
}
|
||||
if (newRingVol >= 0) ringVol = std::clamp(newRingVol, 0, 100);
|
||||
if (newVibStrength >= 1 && newVibStrength <= 3) vibStrength = newVibStrength;
|
||||
std::ofstream ofs(path, std::ios::trunc);
|
||||
if (ofs) {
|
||||
ofs << "SXMO_RINGTIME=" << ringTime << "\n";
|
||||
ofs << "SXMO_RINGNUMBER=" << ringLoops << "\n";
|
||||
ofs << "SXMO_VIBRATE_STRENGTH=" << vibStrength << "\n";
|
||||
ofs << "SXMO_RINGVOL=" << std::clamp(ringVol, 0, 100) << "\n";
|
||||
ofs << "SXMO_RINGVOL=" << ringVol << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -484,12 +515,21 @@ class PhoneController {
|
||||
break;
|
||||
}
|
||||
case ControlId::EarpieceVol: {
|
||||
long hw = (it.value <= 0) ? 0 : (58 + std::lround((it.value * 32.0) / 100.0));
|
||||
long hw = (it.value <= 0) ? 0 : (68 + std::lround((it.value * 24.0) / 100.0));
|
||||
alsa_.setInteger("RX1 Digital Volume", hw);
|
||||
break;
|
||||
}
|
||||
case ControlId::RingVol: {
|
||||
writeRingVolume(it.value);
|
||||
writeRingAndVibSettings(it.value, -1);
|
||||
break;
|
||||
}
|
||||
case ControlId::VibrateStrength: {
|
||||
writeRingAndVibSettings(-1, it.value);
|
||||
char cmd[96];
|
||||
std::snprintf(cmd, sizeof(cmd),
|
||||
"SXMO_VIBRATE_FORCE=1 sxmo_vibrate 400 %d >/dev/null 2>&1",
|
||||
it.value);
|
||||
runAsyncCmd(cmd);
|
||||
break;
|
||||
}
|
||||
case ControlId::Flashlight: {
|
||||
@@ -792,6 +832,13 @@ static int xdrawer_run_main(int argc, char** argv) {
|
||||
XftColor* rCol = (it.value == 0) ? (isSel ? &colYellow : &colGreen)
|
||||
: ((it.value == 1) ? &colYellow : &colMuted);
|
||||
drawPango(layoutSmall, rCol, kWinWidth - stW - 6, ry, rowH, stStr);
|
||||
} else if (it.id == ControlId::VibrateStrength) {
|
||||
const char* vModes[3] = {"Light", "Medium", "Strong"};
|
||||
int vIdx = std::clamp(it.value, 1, 3) - 1;
|
||||
std::string stStr = std::string("< ") + vModes[vIdx] + " >";
|
||||
int stW = pangoWidth(layoutSmall, stStr);
|
||||
XftColor* vCol = isSel ? &colYellow : &colGreen;
|
||||
drawPango(layoutSmall, vCol, kWinWidth - stW - 6, ry, rowH, stStr);
|
||||
} else {
|
||||
bool on = (it.value != 0);
|
||||
std::string stStr = on ? "ON" : "OFF";
|
||||
|
||||
Reference in new issue
Block a user