Add RTTTL/eMelody/iMelody ringtones and separate notification/SMS sound config
This commit is contained in:
1 parent
c766f6c53b
commit
9c28fa1e4c
46 files changed
+2452
-148
No files matched your search
@@ -2,6 +2,7 @@
|
||||
// Bananarchy Ringtone & Ringer Manager Plugin (ringtones.so / xringtones)
|
||||
|
||||
#include "phone_data.h"
|
||||
#include "monotone.h"
|
||||
#include "../sxmo-dwm/dwm_plugin.h"
|
||||
|
||||
#include <X11/Xatom.h>
|
||||
@@ -30,7 +31,8 @@ void handleSignal(int) {
|
||||
|
||||
enum class TabId {
|
||||
Ringtones = 0,
|
||||
Settings = 1,
|
||||
NotifSound = 1,
|
||||
Settings = 2,
|
||||
};
|
||||
|
||||
struct RingtoneEntry {
|
||||
@@ -39,6 +41,10 @@ struct RingtoneEntry {
|
||||
std::string formatTag;
|
||||
std::string sourceTag;
|
||||
off_t sizeBytes = 0;
|
||||
bool isMonotone = false;
|
||||
int bpm = 0;
|
||||
int noteCount = 0;
|
||||
int durationMs = 0;
|
||||
};
|
||||
|
||||
struct RingSettings {
|
||||
@@ -66,6 +72,9 @@ std::string getConfigDir() {
|
||||
}
|
||||
|
||||
bool isAudioExtension(const std::string& name, std::string* extUpperOut = nullptr) {
|
||||
if (isMonotoneFile(name, extUpperOut)) {
|
||||
return true;
|
||||
}
|
||||
size_t dot = name.rfind('.');
|
||||
if (dot == std::string::npos || dot + 1 >= name.size()) return false;
|
||||
std::string ext = toLowerStr(name.substr(dot + 1));
|
||||
@@ -97,6 +106,32 @@ std::string prettifyFilename(const std::string& filename) {
|
||||
return trimStr(stem);
|
||||
}
|
||||
|
||||
RingtoneEntry makeRingtoneEntry(const std::string& fullPath,
|
||||
const std::string& name,
|
||||
const std::string& extTag,
|
||||
const std::string& sourceTag,
|
||||
off_t sizeBytes) {
|
||||
RingtoneEntry e;
|
||||
e.path = fullPath;
|
||||
e.displayName = prettifyFilename(name);
|
||||
e.formatTag = extTag;
|
||||
e.sourceTag = sourceTag;
|
||||
e.sizeBytes = sizeBytes;
|
||||
if (isMonotoneFile(name)) {
|
||||
e.isMonotone = true;
|
||||
MonotoneSong song;
|
||||
if (parseMonotoneFile(fullPath, &song)) {
|
||||
e.bpm = song.bpm;
|
||||
e.noteCount = song.pitchedNoteCount;
|
||||
e.durationMs = song.totalDurationMs;
|
||||
if (!song.formatTag.empty()) {
|
||||
e.formatTag = song.formatTag;
|
||||
}
|
||||
}
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
void scanDirectoryForRingtones(const std::string& dirPath,
|
||||
const std::string& sourceTag,
|
||||
std::vector<RingtoneEntry>& out) {
|
||||
@@ -116,13 +151,8 @@ void scanDirectoryForRingtones(const std::string& dirPath,
|
||||
std::string fullPath = dirPath + "/" + name;
|
||||
struct stat st {};
|
||||
if (::stat(fullPath.c_str(), &st) != 0 || !S_ISREG(st.st_mode)) continue;
|
||||
RingtoneEntry e;
|
||||
e.path = fullPath;
|
||||
e.displayName = prettifyFilename(name);
|
||||
e.formatTag = extTag;
|
||||
e.sourceTag = sourceTag;
|
||||
e.sizeBytes = st.st_size;
|
||||
out.push_back(e);
|
||||
out.push_back(makeRingtoneEntry(fullPath, name, extTag, sourceTag,
|
||||
st.st_size));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,6 +170,15 @@ std::vector<RingtoneEntry> discoverRingtones() {
|
||||
defEntry.sizeBytes = st.st_size;
|
||||
list.push_back(defEntry);
|
||||
}
|
||||
if (::stat("/usr/share/sxmo/notify.ogg", &st) == 0 && S_ISREG(st.st_mode)) {
|
||||
RingtoneEntry notifEntry;
|
||||
notifEntry.path = "/usr/share/sxmo/notify.ogg";
|
||||
notifEntry.displayName = "Sxmo Default Notify";
|
||||
notifEntry.formatTag = "OGG";
|
||||
notifEntry.sourceTag = "System";
|
||||
notifEntry.sizeBytes = st.st_size;
|
||||
list.push_back(notifEntry);
|
||||
}
|
||||
|
||||
std::string home = getHomeDirPath();
|
||||
scanDirectoryForRingtones(home + "/Ringtones", "User", list);
|
||||
@@ -180,6 +219,75 @@ bool saveActiveRingtonePath(const std::string& path) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string loadActiveNotifSoundPath() {
|
||||
std::string cfgDir = getConfigDir();
|
||||
{
|
||||
std::ifstream ifs(cfgDir + "/notif_sound");
|
||||
if (ifs) {
|
||||
std::string line;
|
||||
if (std::getline(ifs, line)) {
|
||||
line = trimStr(line);
|
||||
if (line == "NONE" || line == "none") {
|
||||
return "NONE";
|
||||
}
|
||||
struct stat st {};
|
||||
if (!line.empty() && ::stat(line.c_str(), &st) == 0) {
|
||||
return line;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
std::ifstream ifs(cfgDir + "/ringsettings");
|
||||
std::string line;
|
||||
while (std::getline(ifs, line)) {
|
||||
line = trimStr(line);
|
||||
if (line.empty() || line[0] == '#') continue;
|
||||
auto eq = line.find('=');
|
||||
if (eq == std::string::npos) continue;
|
||||
std::string k = trimStr(line.substr(0, eq));
|
||||
std::string v = trimStr(line.substr(eq + 1));
|
||||
if (v.size() >= 2 && ((v.front() == '"' && v.back() == '"') ||
|
||||
(v.front() == '\'' && v.back() == '\''))) {
|
||||
v = v.substr(1, v.size() - 2);
|
||||
}
|
||||
if (k == "SXMO_TEXTSOUND") {
|
||||
if (v == "NONE" || v == "none") return "NONE";
|
||||
struct stat st {};
|
||||
if (!v.empty() && ::stat(v.c_str(), &st) == 0) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
struct stat stDef {};
|
||||
if (::stat("/usr/share/sxmo/ringtones/Soft_Bell.wav", &stDef) == 0) {
|
||||
return "/usr/share/sxmo/ringtones/Soft_Bell.wav";
|
||||
}
|
||||
const char* envTxt = std::getenv("SXMO_TEXTSOUND");
|
||||
if (envTxt && *envTxt && ::stat(envTxt, &stDef) == 0) {
|
||||
return envTxt;
|
||||
}
|
||||
if (::stat("/usr/share/sxmo/notify.ogg", &stDef) == 0) {
|
||||
return "/usr/share/sxmo/notify.ogg";
|
||||
}
|
||||
return "/usr/share/sxmo/ringtones/Banana_Chime.wav";
|
||||
}
|
||||
|
||||
void saveRingSettings(const RingSettings& s);
|
||||
|
||||
bool saveActiveNotifSoundPath(const std::string& path,
|
||||
const RingSettings& curSettings) {
|
||||
std::string cfgDir = getConfigDir();
|
||||
::mkdir(cfgDir.c_str(), 0755);
|
||||
std::ofstream ofs(cfgDir + "/notif_sound", std::ios::trunc);
|
||||
if (!ofs) return false;
|
||||
ofs << path << "\n";
|
||||
ofs.close();
|
||||
saveRingSettings(curSettings);
|
||||
return true;
|
||||
}
|
||||
|
||||
RingSettings loadRingSettings() {
|
||||
RingSettings s;
|
||||
std::string cfgDir = getConfigDir();
|
||||
@@ -237,12 +345,14 @@ void saveRingSettings(const RingSettings& s) {
|
||||
writeIntFile(noVibPath, 1);
|
||||
}
|
||||
|
||||
std::string notifPath = loadActiveNotifSoundPath();
|
||||
std::ofstream ofs(cfgDir + "/ringsettings", std::ios::trunc);
|
||||
if (ofs) {
|
||||
ofs << "SXMO_RINGTIME=" << s.ringTimeSec << "\n";
|
||||
ofs << "SXMO_RINGNUMBER=" << s.ringLoops << "\n";
|
||||
ofs << "SXMO_VIBRATE_STRENGTH=" << s.vibrateStrength << "\n";
|
||||
ofs << "SXMO_RINGVOL=" << std::clamp(s.ringVol, 0, 100) << "\n";
|
||||
ofs << "SXMO_TEXTSOUND=\"" << notifPath << "\"\n";
|
||||
}
|
||||
runAsyncCmd("sxmo_hook_statusbar.sh audio >/dev/null 2>&1");
|
||||
}
|
||||
@@ -253,9 +363,17 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
XSetLocaleModifiers("");
|
||||
|
||||
bool isPreload = false;
|
||||
bool initNotifTab = false;
|
||||
std::string initTarget;
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (argv[i] && std::strcmp(argv[i], "--preload") == 0) {
|
||||
if (!argv[i]) continue;
|
||||
if (std::strcmp(argv[i], "--preload") == 0) {
|
||||
isPreload = true;
|
||||
} else if (std::strcmp(argv[i], "--notif") == 0 ||
|
||||
std::strcmp(argv[i], "notif") == 0) {
|
||||
initNotifTab = true;
|
||||
} else if (argv[i][0] != '-' && initTarget.empty()) {
|
||||
initTarget = argv[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,7 +382,14 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
|
||||
if (isPluginDaemonAlive("ringtones")) {
|
||||
if (!isPreload) {
|
||||
sendPluginCommand("ringtones", "OPEN");
|
||||
if (initNotifTab && !initTarget.empty()) {
|
||||
sendPluginCommand("ringtones", "OPEN --notif " + initTarget);
|
||||
} else if (initNotifTab) {
|
||||
sendPluginCommand("ringtones", "OPEN --notif");
|
||||
} else {
|
||||
sendPluginCommand(
|
||||
"ringtones", initTarget.empty() ? "OPEN" : ("OPEN " + initTarget));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -301,10 +426,14 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
|
||||
TabId activeTab = TabId::Ringtones;
|
||||
std::vector<RingtoneEntry> tones;
|
||||
std::vector<RingtoneEntry> notifTones;
|
||||
std::string activePath;
|
||||
std::string activeNotifPath;
|
||||
RingSettings settings;
|
||||
int selIdx = 0;
|
||||
int notifSelIdx = 0;
|
||||
int settingsRow = 0;
|
||||
constexpr int kTotalSettingsRows = 7;
|
||||
pid_t previewPid = -1;
|
||||
std::string previewPath;
|
||||
|
||||
@@ -345,18 +474,34 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
return false;
|
||||
};
|
||||
|
||||
auto togglePreview = [&](const std::string& path) {
|
||||
auto togglePreview = [&](const std::string& path, bool singleShot = false) {
|
||||
checkPreviewAlive();
|
||||
if (path.empty() || path == "NONE") {
|
||||
stopPreview();
|
||||
setBanner("Notification sound is muted (None)");
|
||||
return;
|
||||
}
|
||||
if (previewPid > 0 && previewPath == path) {
|
||||
stopPreview();
|
||||
setBanner("Preview stopped");
|
||||
return;
|
||||
}
|
||||
stopPreview();
|
||||
|
||||
std::string playTarget = path;
|
||||
if (isMonotoneFile(path)) {
|
||||
playTarget = "/tmp/xringtones_preview.wav";
|
||||
if (!synthesizeMonotoneFileToWav(path, playTarget, 1)) {
|
||||
setBanner("Invalid melody ringtone");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
settings = loadRingSettings();
|
||||
int rvol = std::clamp(settings.ringVol, 0, 100);
|
||||
int rx3 = (rvol <= 0) ? 0 : (56 + (rvol * 32 + 50) / 100);
|
||||
std::string volArg = "--volume=100";
|
||||
std::string loopArg = singleShot ? "--loop=no" : "--loop=2";
|
||||
runAsyncCmd("amixer -c 0 cset \"name='EAR_S'\" 0 >/dev/null 2>&1; "
|
||||
"amixer -c 0 cset \"name='RX1 MIX1 INP1'\" 0 >/dev/null 2>&1; "
|
||||
"amixer -c 0 cset \"name='PRI_MI2S_RX Audio Mixer MultiMedia1'\" 1 >/dev/null 2>&1; "
|
||||
@@ -384,12 +529,21 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
::dup2(devNull, STDERR_FILENO);
|
||||
if (devNull > 2) ::close(devNull);
|
||||
}
|
||||
::execlp("mpv", "mpv", "--no-config", "--no-terminal",
|
||||
"--no-resume-playback", "--quiet", "--vo=null",
|
||||
"--no-video", "--ao=pipewire,pulse,alsa",
|
||||
"--audio-channels=stereo", "--audio-samplerate=48000",
|
||||
"--volume-max=150", volArg.c_str(),
|
||||
"--loop=2", path.c_str(), nullptr);
|
||||
if (singleShot) {
|
||||
::execlp("mpv", "mpv", "--no-config", "--no-terminal",
|
||||
"--no-resume-playback", "--quiet", "--vo=null",
|
||||
"--no-video", "--ao=pipewire,pulse,alsa",
|
||||
"--audio-channels=stereo", "--audio-samplerate=48000",
|
||||
"--volume-max=150", volArg.c_str(),
|
||||
"--end=6", loopArg.c_str(), playTarget.c_str(), nullptr);
|
||||
} else {
|
||||
::execlp("mpv", "mpv", "--no-config", "--no-terminal",
|
||||
"--no-resume-playback", "--quiet", "--vo=null",
|
||||
"--no-video", "--ao=pipewire,pulse,alsa",
|
||||
"--audio-channels=stereo", "--audio-samplerate=48000",
|
||||
"--volume-max=150", volArg.c_str(),
|
||||
loopArg.c_str(), playTarget.c_str(), nullptr);
|
||||
}
|
||||
::_exit(127);
|
||||
} else if (pid > 0) {
|
||||
previewPid = pid;
|
||||
@@ -398,13 +552,40 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
}
|
||||
};
|
||||
|
||||
auto rebuildNotifTones = [&]() {
|
||||
notifTones.clear();
|
||||
RingtoneEntry noneEntry;
|
||||
noneEntry.path = "NONE";
|
||||
noneEntry.displayName = "None (Mute Sound)";
|
||||
noneEntry.formatTag = "OFF";
|
||||
noneEntry.sourceTag = "Silent";
|
||||
notifTones.push_back(noneEntry);
|
||||
for (const auto& t : tones) {
|
||||
notifTones.push_back(t);
|
||||
}
|
||||
};
|
||||
|
||||
auto refreshData = [&]() {
|
||||
tones = discoverRingtones();
|
||||
rebuildNotifTones();
|
||||
activePath = loadActiveRingtonePath();
|
||||
activeNotifPath = loadActiveNotifSoundPath();
|
||||
settings = loadRingSettings();
|
||||
if (selIdx >= static_cast<int>(tones.size())) {
|
||||
selIdx = std::max(0, static_cast<int>(tones.size()) - 1);
|
||||
}
|
||||
if (notifSelIdx >= static_cast<int>(notifTones.size())) {
|
||||
notifSelIdx = std::max(0, static_cast<int>(notifTones.size()) - 1);
|
||||
}
|
||||
};
|
||||
|
||||
auto formatToneShortName = [&](const std::string& path) -> std::string {
|
||||
if (path.empty() || path == "NONE") return "None (Silent)";
|
||||
for (const auto& t : tones) {
|
||||
if (t.path == path) return t.displayName;
|
||||
}
|
||||
size_t sl = path.rfind('/');
|
||||
return prettifyFilename(sl == std::string::npos ? path : path.substr(sl + 1));
|
||||
};
|
||||
|
||||
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y,
|
||||
@@ -427,32 +608,31 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
XSetForeground(dpy, gc, pt.spec.bgMain);
|
||||
XFillRectangle(dpy, pix, gc, 0, 0, kWinWidth, kWinHeight);
|
||||
|
||||
// Top tab header (0..26)
|
||||
// Top 3-tab header (0..26)
|
||||
XSetForeground(dpy, gc, pt.spec.bgHeader);
|
||||
XFillRectangle(dpy, pix, gc, 0, 0, kWinWidth, 26);
|
||||
|
||||
const char* tabNames[2] = {"1:Ringtones", "2:Settings"};
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
int tx = i * 120;
|
||||
const char* tabNames[3] = {"1:Ringtone", "2:Notif/SMS", "3:Settings"};
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
int tx = i * 80;
|
||||
bool isAct = (static_cast<int>(activeTab) == i);
|
||||
if (isAct) {
|
||||
XSetForeground(dpy, gc, pt.spec.selBg);
|
||||
XFillRectangle(dpy, pix, gc, tx, 0, 120, 26);
|
||||
XFillRectangle(dpy, pix, gc, tx, 0, 80, 26);
|
||||
XSetForeground(dpy, gc, pt.spec.accent);
|
||||
XFillRectangle(dpy, pix, gc, tx, 24, 120, 2);
|
||||
XFillRectangle(dpy, pix, gc, tx, 24, 80, 2);
|
||||
}
|
||||
drawPango(layoutSmall, isAct ? &colWhite : &colMuted, tx + 4, 0, 24,
|
||||
tabNames[i], 112, 1);
|
||||
drawPango(layoutSmall, isAct ? &colWhite : &colMuted, tx + 2, 0, 24,
|
||||
tabNames[i], 76, 1);
|
||||
}
|
||||
|
||||
if (activeTab == TabId::Ringtones) {
|
||||
// Active ringtone summary banner (y=28..50)
|
||||
// Active call ringtone summary banner (y=28..50)
|
||||
XSetForeground(dpy, gc, pt.spec.bgAltEven);
|
||||
XFillRectangle(dpy, pix, gc, 4, 28, kWinWidth - 8, 22);
|
||||
std::string actName = prettifyFilename(
|
||||
activePath.substr(activePath.rfind('/') + 1));
|
||||
std::string actName = formatToneShortName(activePath);
|
||||
drawPango(layoutSmall, &colGreen, 8, 28, 22,
|
||||
std::string(kIconBell) + " Active: " + actName,
|
||||
std::string(kIconBell) + " Ring: " + actName,
|
||||
kWinWidth - 16);
|
||||
|
||||
// List area (y=52..246, 5 rows of 38px)
|
||||
@@ -470,36 +650,52 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
const auto& e = tones[idx];
|
||||
int ry = 54 + i * 38;
|
||||
bool isSel = (idx == selIdx);
|
||||
bool isActive = (e.path == activePath);
|
||||
bool isActiveRing = (e.path == activePath);
|
||||
bool isActiveNotif = (e.path == activeNotifPath);
|
||||
bool isPlaying = (previewPid > 0 && previewPath == e.path);
|
||||
|
||||
XSetForeground(dpy, gc, isSel ? pt.spec.selBg
|
||||
: (i % 2 == 0 ? pt.spec.bgAltEven
|
||||
: pt.spec.bgAltOdd));
|
||||
XFillRectangle(dpy, pix, gc, 4, ry, kWinWidth - 8, 36);
|
||||
if (isActive) {
|
||||
if (isActiveRing) {
|
||||
XSetForeground(dpy, gc, pt.spec.accent);
|
||||
XFillRectangle(dpy, pix, gc, 4, ry, 3, 36);
|
||||
} else if (isActiveNotif) {
|
||||
XSetForeground(dpy, gc, pt.spec.info);
|
||||
XFillRectangle(dpy, pix, gc, 4, ry, 3, 36);
|
||||
}
|
||||
|
||||
drawPango(layoutMain, isSel ? &colWhite : &colLight, 10, ry + 1, 19,
|
||||
e.displayName, 152);
|
||||
e.displayName, 148);
|
||||
|
||||
std::string badge;
|
||||
XftColor* badgeCol = &colMuted;
|
||||
if (isPlaying) {
|
||||
badge = "[PLAYING]";
|
||||
badgeCol = &colYellow;
|
||||
} else if (isActive) {
|
||||
badge = "[ACTIVE]";
|
||||
} else if (isActiveRing && isActiveNotif) {
|
||||
badge = "[RING+SMS]";
|
||||
badgeCol = &colGreen;
|
||||
} else if (isActiveRing) {
|
||||
badge = "[RING]";
|
||||
badgeCol = &colGreen;
|
||||
} else if (isActiveNotif) {
|
||||
badge = "[NOTIF]";
|
||||
badgeCol = &colBlue;
|
||||
}
|
||||
if (!badge.empty()) {
|
||||
drawPango(layoutSmall, badgeCol, 162, ry + 2, 18, badge, 70, 2);
|
||||
drawPango(layoutSmall, badgeCol, 158, ry + 2, 18, badge, 74, 2);
|
||||
}
|
||||
|
||||
std::string sub = e.formatTag + " | " + formatFileSize(e.sizeBytes) +
|
||||
" | " + e.sourceTag + " ([*] Preview)";
|
||||
std::string sub;
|
||||
if (e.isMonotone && e.bpm > 0) {
|
||||
sub = e.formatTag + " " + std::to_string(e.bpm) + "bpm | " +
|
||||
std::to_string(e.noteCount) + "n | [*]Play [#]SMS";
|
||||
} else {
|
||||
sub = e.formatTag + " | " + formatFileSize(e.sizeBytes) +
|
||||
" | " + e.sourceTag + " ([*]Play [#]SMS)";
|
||||
}
|
||||
drawPango(layoutSmall, isSel ? &colLight : &colMuted, 10, ry + 19, 16,
|
||||
sub, kWinWidth - 20);
|
||||
}
|
||||
@@ -509,8 +705,84 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
previewPid > 0 &&
|
||||
previewPath == tones[selIdx].path);
|
||||
drawSoftkeyBar(curPlaying ? "Stop" : "Play [*]", "Set Ring", "Close");
|
||||
} else if (activeTab == TabId::NotifSound) {
|
||||
// Active notification/SMS sound summary banner (y=28..50)
|
||||
XSetForeground(dpy, gc, pt.spec.bgAltEven);
|
||||
XFillRectangle(dpy, pix, gc, 4, 28, kWinWidth - 8, 22);
|
||||
std::string actNotifName = formatToneShortName(activeNotifPath);
|
||||
drawPango(layoutSmall, &colBlue, 8, 28, 22,
|
||||
std::string(kIconSms) + " Notif/SMS: " + actNotifName,
|
||||
kWinWidth - 16);
|
||||
|
||||
// List area (y=52..246, 5 rows of 38px)
|
||||
constexpr int kVisibleRows = 5;
|
||||
int total = static_cast<int>(notifTones.size());
|
||||
int startIdx = 0;
|
||||
if (total > kVisibleRows) {
|
||||
startIdx = std::clamp(notifSelIdx - kVisibleRows / 2, 0,
|
||||
total - kVisibleRows);
|
||||
}
|
||||
|
||||
for (int i = 0; i < kVisibleRows; ++i) {
|
||||
int idx = startIdx + i;
|
||||
if (idx >= total) break;
|
||||
const auto& e = notifTones[idx];
|
||||
int ry = 54 + i * 38;
|
||||
bool isSel = (idx == notifSelIdx);
|
||||
bool isActiveNotif = (e.path == activeNotifPath);
|
||||
bool isActiveRing = (e.path != "NONE" && e.path == activePath);
|
||||
bool isPlaying = (previewPid > 0 && previewPath == e.path);
|
||||
|
||||
XSetForeground(dpy, gc, isSel ? pt.spec.selBg
|
||||
: (i % 2 == 0 ? pt.spec.bgAltEven
|
||||
: pt.spec.bgAltOdd));
|
||||
XFillRectangle(dpy, pix, gc, 4, ry, kWinWidth - 8, 36);
|
||||
if (isActiveNotif) {
|
||||
XSetForeground(dpy, gc, pt.spec.accent);
|
||||
XFillRectangle(dpy, pix, gc, 4, ry, 3, 36);
|
||||
}
|
||||
|
||||
drawPango(layoutMain, isSel ? &colWhite : &colLight, 10, ry + 1, 19,
|
||||
e.displayName, 148);
|
||||
|
||||
std::string badge;
|
||||
XftColor* badgeCol = &colMuted;
|
||||
if (isPlaying) {
|
||||
badge = "[PLAYING]";
|
||||
badgeCol = &colYellow;
|
||||
} else if (isActiveNotif) {
|
||||
badge = "[ACTIVE]";
|
||||
badgeCol = &colGreen;
|
||||
} else if (isActiveRing) {
|
||||
badge = "[RING]";
|
||||
badgeCol = &colBlue;
|
||||
}
|
||||
if (!badge.empty()) {
|
||||
drawPango(layoutSmall, badgeCol, 158, ry + 2, 18, badge, 74, 2);
|
||||
}
|
||||
|
||||
std::string sub;
|
||||
if (e.path == "NONE") {
|
||||
sub = "Silent notifications & SMS (vibration only)";
|
||||
} else if (e.isMonotone && e.bpm > 0) {
|
||||
sub = e.formatTag + " " + std::to_string(e.bpm) + "bpm | " +
|
||||
std::to_string(e.noteCount) + "n | " + e.sourceTag +
|
||||
" ([*] Play)";
|
||||
} else {
|
||||
sub = e.formatTag + " | " + formatFileSize(e.sizeBytes) +
|
||||
" | " + e.sourceTag + " ([*] Preview)";
|
||||
}
|
||||
drawPango(layoutSmall, isSel ? &colLight : &colMuted, 10, ry + 19, 16,
|
||||
sub, kWinWidth - 20);
|
||||
}
|
||||
|
||||
bool curPlaying = (!notifTones.empty() && notifSelIdx >= 0 &&
|
||||
notifSelIdx < static_cast<int>(notifTones.size()) &&
|
||||
previewPid > 0 &&
|
||||
previewPath == notifTones[notifSelIdx].path);
|
||||
drawSoftkeyBar(curPlaying ? "Stop" : "Play [*]", "Set Notif", "Close");
|
||||
} else {
|
||||
// Tab 2: Settings
|
||||
// Tab 3: Settings (scrollable 6 visible rows of 35px out of 7)
|
||||
const char* modeLabels[4] = {
|
||||
"Ring + Vibrate",
|
||||
"Ring Only",
|
||||
@@ -519,23 +791,31 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
};
|
||||
const char* vibLabels[3] = {"1 (Light)", "2 (Medium)", "3 (Strong)"};
|
||||
int vIdx = std::clamp(settings.vibrateStrength, 1, 3) - 1;
|
||||
std::string rows[6][2] = {
|
||||
std::string rows[kTotalSettingsRows][2] = {
|
||||
{"Ringer Mode",
|
||||
"< " + std::string(modeLabels[settings.ringerMode % 4]) + " >"},
|
||||
{"Ring Volume",
|
||||
{"Notif / SMS Sound",
|
||||
"< " + formatToneShortName(activeNotifPath) + " >"},
|
||||
{"Call Ringtone",
|
||||
"< " + formatToneShortName(activePath) + " >"},
|
||||
{"Ring & Alert Volume",
|
||||
"< " + std::to_string(settings.ringVol) + "% >"},
|
||||
{"Ring Duration",
|
||||
{"Call Ring Duration",
|
||||
"< " + std::to_string(settings.ringTimeSec) + " sec >"},
|
||||
{"Ring Loop Count",
|
||||
{"Call Ring Loop Count",
|
||||
"< " + std::to_string(settings.ringLoops) + " loops >"},
|
||||
{"Vibrate Strength",
|
||||
{"Vibrate Strength (OK: Test)",
|
||||
"< Level " + std::string(vibLabels[vIdx]) + " >"},
|
||||
{"Test Vibration", "Press OK to vibrate"},
|
||||
};
|
||||
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
constexpr int kVisibleSettings = 6;
|
||||
int startRow = std::clamp(settingsRow - kVisibleSettings / 2, 0,
|
||||
kTotalSettingsRows - kVisibleSettings);
|
||||
for (int i = 0; i < kVisibleSettings; ++i) {
|
||||
int rIdx = startRow + i;
|
||||
if (rIdx >= kTotalSettingsRows) break;
|
||||
int ry = 30 + i * 35;
|
||||
bool isSel = (settingsRow == i);
|
||||
bool isSel = (settingsRow == rIdx);
|
||||
XSetForeground(dpy, gc, isSel ? pt.spec.selBg : pt.spec.bgAltEven);
|
||||
XFillRectangle(dpy, pix, gc, 4, ry, kWinWidth - 8, 33);
|
||||
if (isSel) {
|
||||
@@ -543,11 +823,14 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
XDrawRectangle(dpy, pix, gc, 4, ry, kWinWidth - 9, 32);
|
||||
}
|
||||
drawPango(layoutSmall, isSel ? &colWhite : &colMuted, 10, ry + 1, 15,
|
||||
rows[i][0], kWinWidth - 20);
|
||||
rows[rIdx][0], kWinWidth - 20);
|
||||
drawPango(layoutMain, isSel ? &colYellow : &colBlue, 10, ry + 15, 17,
|
||||
rows[i][1], kWinWidth - 20);
|
||||
rows[rIdx][1], kWinWidth - 20);
|
||||
}
|
||||
drawSoftkeyBar("Change", "Select", "Close");
|
||||
std::string midLbl = "Select";
|
||||
if (settingsRow == 1 || settingsRow == 2) midLbl = "Browse";
|
||||
else if (settingsRow == 6) midLbl = "Test Vib";
|
||||
drawSoftkeyBar("Change", midLbl, "Close");
|
||||
}
|
||||
|
||||
if (!statusBanner.empty()) {
|
||||
@@ -564,16 +847,63 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
XFlush(dpy);
|
||||
};
|
||||
|
||||
auto showWindow = [&]() {
|
||||
auto showWindow = [&](const std::string& openTarget = "",
|
||||
bool openNotif = false) {
|
||||
writeIntFile(activePidPath, static_cast<int>(::getpid()));
|
||||
closeOtherPlugins("ringtones");
|
||||
refreshData();
|
||||
if (openNotif) {
|
||||
activeTab = TabId::NotifSound;
|
||||
}
|
||||
std::string selectPath = activePath;
|
||||
std::string selectNotifPath = activeNotifPath;
|
||||
if (!openTarget.empty()) {
|
||||
char resolved[4096];
|
||||
std::string target = openTarget;
|
||||
if (::realpath(openTarget.c_str(), resolved) != nullptr) {
|
||||
target = resolved;
|
||||
}
|
||||
struct stat st {};
|
||||
std::string extTag;
|
||||
if (::stat(target.c_str(), &st) == 0 && S_ISREG(st.st_mode) &&
|
||||
isAudioExtension(target, &extTag)) {
|
||||
bool found = false;
|
||||
for (const auto& t : tones) {
|
||||
if (t.path == target) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
size_t sl = target.rfind('/');
|
||||
std::string fname =
|
||||
(sl == std::string::npos) ? target : target.substr(sl + 1);
|
||||
tones.insert(tones.begin(),
|
||||
makeRingtoneEntry(target, fname, extTag, "File",
|
||||
st.st_size));
|
||||
rebuildNotifTones();
|
||||
}
|
||||
if (openNotif) {
|
||||
selectNotifPath = target;
|
||||
activeTab = TabId::NotifSound;
|
||||
} else {
|
||||
selectPath = target;
|
||||
activeTab = TabId::Ringtones;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < tones.size(); ++i) {
|
||||
if (tones[i].path == activePath) {
|
||||
if (tones[i].path == selectPath) {
|
||||
selIdx = static_cast<int>(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < notifTones.size(); ++i) {
|
||||
if (notifTones[i].path == selectNotifPath) {
|
||||
notifSelIdx = static_cast<int>(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!visible) {
|
||||
visible = true;
|
||||
XMapRaised(dpy, win);
|
||||
@@ -618,6 +948,36 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
saveRingSettings(settings);
|
||||
setBanner("Ringer mode updated");
|
||||
} else if (settingsRow == 1) {
|
||||
if (notifTones.empty()) return;
|
||||
int curIdx = 0;
|
||||
for (size_t i = 0; i < notifTones.size(); ++i) {
|
||||
if (notifTones[i].path == activeNotifPath) {
|
||||
curIdx = static_cast<int>(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
curIdx = (curIdx + static_cast<int>(notifTones.size()) + delta) %
|
||||
static_cast<int>(notifTones.size());
|
||||
notifSelIdx = curIdx;
|
||||
activeNotifPath = notifTones[curIdx].path;
|
||||
saveActiveNotifSoundPath(activeNotifPath, settings);
|
||||
setBanner("Notif/SMS: " + notifTones[curIdx].displayName);
|
||||
} else if (settingsRow == 2) {
|
||||
if (tones.empty()) return;
|
||||
int curIdx = 0;
|
||||
for (size_t i = 0; i < tones.size(); ++i) {
|
||||
if (tones[i].path == activePath) {
|
||||
curIdx = static_cast<int>(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
curIdx = (curIdx + static_cast<int>(tones.size()) + delta) %
|
||||
static_cast<int>(tones.size());
|
||||
selIdx = curIdx;
|
||||
activePath = tones[curIdx].path;
|
||||
saveActiveRingtonePath(activePath);
|
||||
setBanner("Ringtone: " + tones[curIdx].displayName);
|
||||
} else if (settingsRow == 3) {
|
||||
settings.ringVol = std::clamp(settings.ringVol + delta * 5, 0, 100);
|
||||
saveRingSettings(settings);
|
||||
if (previewPid > 0) {
|
||||
@@ -627,7 +987,7 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
"wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1");
|
||||
}
|
||||
setBanner("Ring volume: " + std::to_string(settings.ringVol) + "%");
|
||||
} else if (settingsRow == 2) {
|
||||
} else if (settingsRow == 4) {
|
||||
int curIdx = 2;
|
||||
for (int i = 0; i < kNumRingTimeSteps; ++i) {
|
||||
if (kRingTimeSteps[i] == settings.ringTimeSec) {
|
||||
@@ -638,7 +998,7 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
curIdx = (curIdx + kNumRingTimeSteps + delta) % kNumRingTimeSteps;
|
||||
settings.ringTimeSec = kRingTimeSteps[curIdx];
|
||||
saveRingSettings(settings);
|
||||
} else if (settingsRow == 3) {
|
||||
} else if (settingsRow == 5) {
|
||||
int curIdx = 2;
|
||||
for (int i = 0; i < kNumRingLoopSteps; ++i) {
|
||||
if (kRingLoopSteps[i] == settings.ringLoops) {
|
||||
@@ -649,23 +1009,18 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
curIdx = (curIdx + kNumRingLoopSteps + delta) % kNumRingLoopSteps;
|
||||
settings.ringLoops = kRingLoopSteps[curIdx];
|
||||
saveRingSettings(settings);
|
||||
} else if (settingsRow == 4) {
|
||||
} else if (settingsRow == 6) {
|
||||
settings.vibrateStrength =
|
||||
((settings.vibrateStrength - 1 + 3 + delta) % 3) + 1;
|
||||
saveRingSettings(settings);
|
||||
runAsyncCmd("SXMO_VIBRATE_FORCE=1 sxmo_vibrate 450 " +
|
||||
std::to_string(settings.vibrateStrength) + " >/dev/null 2>&1");
|
||||
setBanner("Vibration level: " + std::to_string(settings.vibrateStrength));
|
||||
} else if (settingsRow == 5) {
|
||||
runAsyncCmd("SXMO_VIBRATE_FORCE=1 sxmo_vibrate 800 " +
|
||||
std::to_string(settings.vibrateStrength) + " >/dev/null 2>&1");
|
||||
setBanner("Testing vibration (Level " +
|
||||
std::to_string(settings.vibrateStrength) + ")...");
|
||||
}
|
||||
};
|
||||
|
||||
if (!isPreload) {
|
||||
showWindow();
|
||||
showWindow(initTarget, initNotifTab);
|
||||
}
|
||||
|
||||
int xfd = ConnectionNumber(dpy);
|
||||
@@ -729,45 +1084,77 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
render();
|
||||
continue;
|
||||
} else if (dch == '2') {
|
||||
activeTab = TabId::NotifSound;
|
||||
render();
|
||||
continue;
|
||||
} else if (dch == '3') {
|
||||
activeTab = TabId::Settings;
|
||||
render();
|
||||
continue;
|
||||
} else if (dch == '*' && activeTab == TabId::Ringtones &&
|
||||
} else if (dch == '*') {
|
||||
if (activeTab == TabId::Ringtones && !tones.empty()) {
|
||||
togglePreview(tones[selIdx].path, false);
|
||||
} else if (activeTab == TabId::NotifSound && !notifTones.empty()) {
|
||||
togglePreview(notifTones[notifSelIdx].path, true);
|
||||
} else if (activeTab == TabId::Settings && settingsRow == 1) {
|
||||
togglePreview(activeNotifPath, true);
|
||||
} else if (activeTab == TabId::Settings && settingsRow == 2) {
|
||||
togglePreview(activePath, false);
|
||||
}
|
||||
render();
|
||||
continue;
|
||||
} else if (dch == '#' && activeTab == TabId::Ringtones &&
|
||||
!tones.empty()) {
|
||||
togglePreview(tones[selIdx].path);
|
||||
activeNotifPath = tones[selIdx].path;
|
||||
saveActiveNotifSoundPath(activeNotifPath, settings);
|
||||
for (size_t i = 0; i < notifTones.size(); ++i) {
|
||||
if (notifTones[i].path == activeNotifPath) {
|
||||
notifSelIdx = static_cast<int>(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
setBanner("Notif/SMS set: " + tones[selIdx].displayName);
|
||||
render();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sym == XK_Left || sym == XK_KP_Left) {
|
||||
if (activeTab == TabId::Settings && settingsRow < 5) {
|
||||
if (activeTab == TabId::Settings) {
|
||||
adjustSettingRow(-1);
|
||||
} else {
|
||||
activeTab = (activeTab == TabId::Ringtones) ? TabId::Settings
|
||||
: TabId::Ringtones;
|
||||
int nextTab = (static_cast<int>(activeTab) + 2) % 3;
|
||||
activeTab = static_cast<TabId>(nextTab);
|
||||
}
|
||||
render();
|
||||
} else if (sym == XK_Right || sym == XK_KP_Right) {
|
||||
if (activeTab == TabId::Settings && settingsRow < 5) {
|
||||
if (activeTab == TabId::Settings) {
|
||||
adjustSettingRow(1);
|
||||
} else {
|
||||
activeTab = (activeTab == TabId::Ringtones) ? TabId::Settings
|
||||
: TabId::Ringtones;
|
||||
int nextTab = (static_cast<int>(activeTab) + 1) % 3;
|
||||
activeTab = static_cast<TabId>(nextTab);
|
||||
}
|
||||
render();
|
||||
} else if (sym == XK_Up || sym == XK_KP_Up) {
|
||||
if (activeTab == TabId::Ringtones && !tones.empty()) {
|
||||
selIdx = (selIdx + static_cast<int>(tones.size()) - 1) %
|
||||
static_cast<int>(tones.size());
|
||||
} else if (activeTab == TabId::NotifSound && !notifTones.empty()) {
|
||||
notifSelIdx =
|
||||
(notifSelIdx + static_cast<int>(notifTones.size()) - 1) %
|
||||
static_cast<int>(notifTones.size());
|
||||
} else if (activeTab == TabId::Settings) {
|
||||
settingsRow = (settingsRow + 5) % 6;
|
||||
settingsRow =
|
||||
(settingsRow + kTotalSettingsRows - 1) % kTotalSettingsRows;
|
||||
}
|
||||
render();
|
||||
} else if (sym == XK_Down || sym == XK_KP_Down) {
|
||||
if (activeTab == TabId::Ringtones && !tones.empty()) {
|
||||
selIdx = (selIdx + 1) % static_cast<int>(tones.size());
|
||||
} else if (activeTab == TabId::NotifSound && !notifTones.empty()) {
|
||||
notifSelIdx =
|
||||
(notifSelIdx + 1) % static_cast<int>(notifTones.size());
|
||||
} else if (activeTab == TabId::Settings) {
|
||||
settingsRow = (settingsRow + 1) % 6;
|
||||
settingsRow = (settingsRow + 1) % kTotalSettingsRows;
|
||||
}
|
||||
render();
|
||||
} else if (sym == XK_Return || sym == XK_KP_Enter) {
|
||||
@@ -775,8 +1162,24 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
activePath = tones[selIdx].path;
|
||||
saveActiveRingtonePath(activePath);
|
||||
setBanner("Ringtone set: " + tones[selIdx].displayName);
|
||||
} else if (activeTab == TabId::NotifSound && !notifTones.empty()) {
|
||||
activeNotifPath = notifTones[notifSelIdx].path;
|
||||
saveActiveNotifSoundPath(activeNotifPath, settings);
|
||||
setBanner("Notif/SMS set: " + notifTones[notifSelIdx].displayName);
|
||||
} else if (activeTab == TabId::Settings) {
|
||||
adjustSettingRow(1);
|
||||
if (settingsRow == 1) {
|
||||
activeTab = TabId::NotifSound;
|
||||
} else if (settingsRow == 2) {
|
||||
activeTab = TabId::Ringtones;
|
||||
} else if (settingsRow == 6) {
|
||||
runAsyncCmd("SXMO_VIBRATE_FORCE=1 sxmo_vibrate 800 " +
|
||||
std::to_string(settings.vibrateStrength) +
|
||||
" >/dev/null 2>&1");
|
||||
setBanner("Testing vibration (Level " +
|
||||
std::to_string(settings.vibrateStrength) + ")...");
|
||||
} else {
|
||||
adjustSettingRow(1);
|
||||
}
|
||||
}
|
||||
render();
|
||||
}
|
||||
@@ -800,7 +1203,9 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
sendPluginCommand("xdrawer", "TOGGLE");
|
||||
} else if (pend == 1) {
|
||||
if (activeTab == TabId::Ringtones && !tones.empty()) {
|
||||
togglePreview(tones[selIdx].path);
|
||||
togglePreview(tones[selIdx].path, false);
|
||||
} else if (activeTab == TabId::NotifSound && !notifTones.empty()) {
|
||||
togglePreview(notifTones[notifSelIdx].path, true);
|
||||
} else if (activeTab == TabId::Settings) {
|
||||
adjustSettingRow(1);
|
||||
}
|
||||
@@ -843,8 +1248,16 @@ int runRingtonesApp(int argc, char** argv) {
|
||||
} else if (cmd == "TOGGLE") {
|
||||
if (visible) hideWindow();
|
||||
else showWindow();
|
||||
} else if (cmd.rfind("OPEN", 0) == 0) {
|
||||
} else if (cmd == "OPEN") {
|
||||
showWindow();
|
||||
} else if (cmd == "OPEN --notif" || cmd == "OPEN notif") {
|
||||
showWindow("", true);
|
||||
} else if (cmd.rfind("OPEN --notif ", 0) == 0) {
|
||||
showWindow(trimStr(cmd.substr(13)), true);
|
||||
} else if (cmd.rfind("OPEN notif ", 0) == 0) {
|
||||
showWindow(trimStr(cmd.substr(11)), true);
|
||||
} else if (cmd.rfind("OPEN ", 0) == 0) {
|
||||
showWindow(trimStr(cmd.substr(5)), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user