Add RTTTL/eMelody/iMelody ringtones and separate notification/SMS sound config

This commit is contained in:
Luxferre committed 2026-10-30 12:11:16 +02:00
1 parent c766f6c53b
commit 9c28fa1e4c
46 files changed
+2452 -148

No files matched your search

+213
View File
@@ -0,0 +1,213 @@
// SPDX-License-Identifier: GPL-2.0-only
// Bananarchy Monophonic Ringtone CLI Synthesizer & Player (bananarchy-melody)
// Supports Nokia RTTTL (.nrt, .rtttl, .rtx), Ericsson eMelody (.emy), and
// IrDA iMelody (.imy).
#include "monotone.h"
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
namespace {
volatile sig_atomic_t gStopRequested = 0;
pid_t gChildPid = -1;
void handleSignal(int) {
gStopRequested = 1;
if (gChildPid > 0) {
::kill(gChildPid, SIGTERM);
}
}
void printUsage(const char* prog) {
std::fprintf(stderr,
"Usage:\n"
" %s --wav <input.{nrt,rtttl,rtx,emy,imy}> <output.wav> [--loops N]\n"
" %s --info <input.{nrt,rtttl,rtx,emy,imy}>\n"
" %s [--play] <input.{nrt,rtttl,rtx,emy,imy}> [--loops N] [--volume PCT]\n",
prog, prog, prog);
}
} // namespace
int main(int argc, char** argv) {
using namespace bananarchy;
if (argc < 2) {
printUsage(argv[0]);
return 1;
}
enum class Mode {
Play = 0,
Wav = 1,
Info = 2,
};
Mode mode = Mode::Play;
std::string inputPath;
std::string outputWavPath;
int loops = 1;
int volumePct = 100;
for (int i = 1; i < argc; ++i) {
const char* arg = argv[i];
if (!arg) continue;
if (std::strcmp(arg, "-h") == 0 || std::strcmp(arg, "--help") == 0) {
printUsage(argv[0]);
return 0;
} else if (std::strcmp(arg, "--wav") == 0) {
mode = Mode::Wav;
} else if (std::strcmp(arg, "--info") == 0) {
mode = Mode::Info;
} else if (std::strcmp(arg, "--play") == 0) {
mode = Mode::Play;
} else if (std::strcmp(arg, "--loops") == 0 && i + 1 < argc) {
loops = std::clamp(std::atoi(argv[++i]), 1, 100);
} else if (std::strncmp(arg, "--loops=", 8) == 0) {
loops = std::clamp(std::atoi(arg + 8), 1, 100);
} else if (std::strcmp(arg, "--volume") == 0 && i + 1 < argc) {
volumePct = std::clamp(std::atoi(argv[++i]), 0, 150);
} else if (std::strncmp(arg, "--volume=", 9) == 0) {
volumePct = std::clamp(std::atoi(arg + 9), 0, 150);
} else if (arg[0] != '-') {
if (inputPath.empty()) {
inputPath = arg;
} else if (outputWavPath.empty()) {
outputWavPath = arg;
}
}
}
if (inputPath.empty()) {
printUsage(argv[0]);
return 1;
}
MonotoneSong song;
if (!parseMonotoneFile(inputPath, &song)) {
std::fprintf(stderr, "bananarchy-melody: failed to parse '%s'\n",
inputPath.c_str());
return 2;
}
if (mode == Mode::Info) {
std::printf("NAME=%s\n", song.name.c_str());
std::printf("COMPOSER=%s\n", song.composer.c_str());
std::printf("FORMAT=%s\n", song.formatTag.c_str());
std::printf("FORMAT_LABEL=%s\n", monotoneFormatLabel(song.format));
std::printf("STYLE=%s\n", monotoneStyleLabel(song.style));
std::printf("BPM=%d\n", song.bpm);
std::printf("NOTES=%zu\n", song.notes.size());
std::printf("PITCHED_NOTES=%d\n", song.pitchedNoteCount);
std::printf("DURATION_MS=%d\n", song.totalDurationMs);
return 0;
}
if (mode == Mode::Wav) {
if (outputWavPath.empty()) {
std::fprintf(stderr, "bananarchy-melody: --wav requires output path\n");
return 1;
}
if (!synthesizeMonotoneWav(song, outputWavPath, loops)) {
std::fprintf(stderr, "bananarchy-melody: failed to write WAV '%s'\n",
outputWavPath.c_str());
return 3;
}
return 0;
}
// Play mode: synthesize single cycle to temp WAV and play with pw-play or mpv
char tmpWav[128];
std::snprintf(tmpWav, sizeof(tmpWav), "/tmp/bananarchy_melody_%d.wav",
static_cast<int>(::getpid()));
if (!synthesizeMonotoneWav(song, tmpWav, 1)) {
std::fprintf(stderr, "bananarchy-melody: failed to synthesize '%s'\n",
inputPath.c_str());
return 3;
}
struct sigaction sa {};
sa.sa_handler = handleSignal;
sigemptyset(&sa.sa_mask);
sigaction(SIGINT, &sa, nullptr);
sigaction(SIGTERM, &sa, nullptr);
std::string runtimeDir = "/run/user/" + std::to_string(::getuid());
const char* xdg = std::getenv("XDG_RUNTIME_DIR");
struct stat stRuntime {};
if (!xdg || !*xdg || ::stat(xdg, &stRuntime) != 0) {
::setenv("XDG_RUNTIME_DIR", runtimeDir.c_str(), 1);
}
bool playedWithPw = false;
if (::access("/usr/bin/pw-play", X_OK) == 0) {
char volBuf[32];
std::snprintf(volBuf, sizeof(volBuf), "--volume=%.2f",
std::clamp(volumePct, 0, 150) / 100.0);
for (int i = 0; i < loops && !gStopRequested; ++i) {
pid_t pid = ::fork();
if (pid == 0) {
int devNull = ::open("/dev/null", O_RDWR);
if (devNull >= 0) {
::dup2(devNull, STDIN_FILENO);
::dup2(devNull, STDOUT_FILENO);
::dup2(devNull, STDERR_FILENO);
if (devNull > 2) ::close(devNull);
}
::execl("/usr/bin/pw-play", "pw-play", volBuf, tmpWav,
static_cast<char*>(nullptr));
::_exit(127);
} else if (pid > 0) {
gChildPid = pid;
int st = 0;
::waitpid(pid, &st, 0);
gChildPid = -1;
if (WIFEXITED(st) && WEXITSTATUS(st) == 0) {
playedWithPw = true;
} else {
break;
}
if (i + 1 < loops && !gStopRequested) {
::usleep(180000);
}
}
}
}
if (!playedWithPw && !gStopRequested) {
std::string volArg = "--volume=" + std::to_string(volumePct);
std::string loopArg = "--loop=" + std::to_string(loops);
pid_t pid = ::fork();
if (pid == 0) {
int devNull = ::open("/dev/null", O_RDWR);
if (devNull >= 0) {
::dup2(devNull, STDIN_FILENO);
::dup2(devNull, STDOUT_FILENO);
::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(),
loopArg.c_str(), tmpWav, static_cast<char*>(nullptr));
::_exit(127);
} else if (pid > 0) {
gChildPid = pid;
int st = 0;
::waitpid(pid, &st, 0);
gChildPid = -1;
}
}
::unlink(tmpWav);
return 0;
}
+462 -1
View File
@@ -1,5 +1,6 @@
#include "phone_data.h"
#include "media_utils.h"
#include "monotone.h"
#include "../sxmo-dwm/dwm_plugin.h"
#include <X11/Xatom.h>
@@ -30,6 +31,7 @@ enum class ViewMode {
InputModal = 5,
ConfirmDelete = 6,
TextEdit = 7,
RingtoneView = 8,
};
enum class SortMode {
@@ -171,6 +173,10 @@ bool isImageExt(const std::string& ext) {
ext == "svg" || ext == "avif" || ext == "heic";
}
bool isRingtoneExt(const std::string& ext) {
return isMonotoneExt(ext);
}
bool isAudioExt(const std::string& ext) {
return ext == "mp3" || ext == "wav" || ext == "ogg" || ext == "oga" ||
ext == "opus" || ext == "flac" || ext == "m4a" || ext == "aac" ||
@@ -411,6 +417,17 @@ int runFilesApp(int argc, char** argv) {
bool imgValid = false;
bool imgFullscreen = false;
// Ringtone / audio preview viewer state
MonotoneSong ringPreviewSong;
bool ringPreviewValid = false;
bool ringPreviewIsMonotone = false;
std::string ringPreviewExtTag;
off_t ringPreviewSize = 0;
std::vector<std::string> ringNoteLines;
int ringNoteScroll = 0;
pid_t ringPreviewPid = -1;
std::string ringPreviewActivePath;
// Modal input state (New Folder / New File / Rename)
InputAction inputAction = InputAction::NewFolder;
std::string inputTitle;
@@ -673,6 +690,159 @@ int runFilesApp(int argc, char** argv) {
mode = ViewMode::ImageView;
};
auto stopRingPreview = [&]() {
if (ringPreviewPid > 0) {
::kill(ringPreviewPid, SIGTERM);
::waitpid(ringPreviewPid, nullptr, WNOHANG);
ringPreviewPid = -1;
runAsyncCmd("sxmo_audio.sh device apply >/dev/null 2>&1");
}
ringPreviewActivePath.clear();
};
auto checkRingPreviewAlive = [&]() -> bool {
if (ringPreviewPid > 0) {
int st = 0;
pid_t r = ::waitpid(ringPreviewPid, &st, WNOHANG);
if (r == ringPreviewPid || (r < 0 && errno == ECHILD)) {
ringPreviewPid = -1;
ringPreviewActivePath.clear();
return true;
}
}
return false;
};
auto readRingVolumePct = [&]() -> int {
std::string cfgDir = homeDir + "/.config/sxmo";
const char* xdgCfg = std::getenv("XDG_CONFIG_HOME");
if (xdgCfg && *xdgCfg) cfgDir = std::string(xdgCfg) + "/sxmo";
std::ifstream ifs(cfgDir + "/ringsettings");
std::string line;
int vol = 100;
while (std::getline(ifs, line)) {
line = trimStr(line);
auto eq = line.find('=');
if (eq == std::string::npos) continue;
if (trimStr(line.substr(0, eq)) == "SXMO_RINGVOL") {
int v = std::atoi(trimStr(line.substr(eq + 1)).c_str());
if (v >= 0 && v <= 100) vol = v;
}
}
return vol;
};
auto toggleRingPreview = [&](const std::string& path) {
checkRingPreviewAlive();
if (ringPreviewPid > 0 && ringPreviewActivePath == path) {
stopRingPreview();
statusBanner = "Preview stopped";
statusBannerUntilMs = nowMs() + 1800;
return;
}
stopRingPreview();
std::string playTarget = path;
if (isMonotoneFile(path)) {
playTarget = "/tmp/xfiles_ring_preview.wav";
if (!synthesizeMonotoneFileToWav(path, playTarget, 1)) {
statusBanner = "Invalid ringtone file";
statusBannerUntilMs = nowMs() + 2000;
return;
}
}
int rvol = std::clamp(readRingVolumePct(), 0, 100);
int rx3 = (rvol <= 0) ? 0 : (56 + (rvol * 32 + 50) / 100);
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; "
"amixer -c 0 cset \"name='SPK DAC Switch'\" 1 >/dev/null 2>&1; "
"amixer -c 0 cset \"name='RX3 MIX1 INP1'\" 3 >/dev/null 2>&1; "
"amixer -c 0 cset \"name='RX3 Digital Volume'\" " +
std::to_string(rx3) + " >/dev/null 2>&1; "
"wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 >/dev/null 2>&1; "
"wpctl set-volume @DEFAULT_AUDIO_SINK@ 100% >/dev/null 2>&1");
pid_t pid = ::fork();
if (pid == 0) {
std::string runtimeDir = "/run/user/" + std::to_string(::getuid());
const char* xdg = std::getenv("XDG_RUNTIME_DIR");
struct stat stRuntime {};
if (!xdg || !*xdg || ::stat(xdg, &stRuntime) != 0) {
::setenv("XDG_RUNTIME_DIR", runtimeDir.c_str(), 1);
}
int devNull = ::open("/dev/null", O_RDWR);
if (devNull >= 0) {
::dup2(devNull, STDIN_FILENO);
::dup2(devNull, STDOUT_FILENO);
::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", "--volume=100",
"--loop=2", playTarget.c_str(),
static_cast<char*>(nullptr));
::_exit(127);
} else if (pid > 0) {
ringPreviewPid = pid;
ringPreviewActivePath = path;
statusBanner = "Playing preview...";
statusBannerUntilMs = nowMs() + 1800;
}
};
auto openRingtoneViewer = [&](const FileItem& item, bool autoPlay = true) {
viewingFilePath = item.fullPath;
viewingFileName = item.name;
ringPreviewSize = item.size;
ringPreviewExtTag = monoToUpper(getExtLower(item.name));
ringPreviewIsMonotone = isMonotoneFile(item.name);
ringNoteLines.clear();
ringNoteScroll = 0;
if (ringPreviewIsMonotone) {
ringPreviewValid = parseMonotoneFile(item.fullPath, &ringPreviewSong);
if (ringPreviewValid) {
std::string curLine;
for (const auto& n : ringPreviewSong.notes) {
if (n.label.empty()) continue;
if (!curLine.empty() &&
curLine.size() + 1 + n.label.size() > 28) {
ringNoteLines.push_back(curLine);
curLine = n.label;
} else {
if (!curLine.empty()) curLine.push_back(' ');
curLine += n.label;
}
}
if (!curLine.empty()) {
ringNoteLines.push_back(curLine);
}
} else {
ringPreviewSong = MonotoneSong{};
ringPreviewSong.name = monoFilenameStem(item.name);
ringPreviewSong.formatTag = ringPreviewExtTag;
ringNoteLines.push_back("(Invalid or empty melody file)");
}
} else {
ringPreviewValid = true;
ringPreviewSong = MonotoneSong{};
ringPreviewSong.name = monoFilenameStem(item.name);
ringPreviewSong.formatTag = ringPreviewExtTag;
ringNoteLines.push_back("Format: " + ringPreviewExtTag + " Audio File");
ringNoteLines.push_back("Size: " + formatFileSize(item.size));
}
mode = ViewMode::RingtoneView;
if (autoPlay && ringPreviewValid) {
toggleRingPreview(item.fullPath);
}
};
auto installAsWallpaper = [&](const std::string& srcPath,
const std::string& fileName) {
std::string targetPath = srcPath;
@@ -750,6 +920,35 @@ int runFilesApp(int argc, char** argv) {
statusBannerUntilMs = nowMs() + 2200;
};
auto installAsNotifSound = [&](const std::string& srcPath,
const std::string& fileName) {
std::string targetPath = srcPath;
std::string ringDir = homeDir + "/Ringtones";
std::string musDir = homeDir + "/Music";
if (srcPath.rfind("/usr/share/sxmo/", 0) != 0 &&
srcPath.rfind(ringDir + "/", 0) != 0 &&
srcPath.rfind(musDir + "/", 0) != 0) {
::mkdir(ringDir.c_str(), 0755);
std::string dst = ringDir + "/" + fileName;
if (copyRecursive(srcPath, dst)) {
targetPath = dst;
}
}
std::string cfgDir = homeDir + "/.config/sxmo";
const char* xdgCfg = std::getenv("XDG_CONFIG_HOME");
if (xdgCfg && *xdgCfg) cfgDir = std::string(xdgCfg) + "/sxmo";
::mkdir((homeDir + "/.config").c_str(), 0755);
::mkdir(cfgDir.c_str(), 0755);
{
std::ofstream ofs(cfgDir + "/notif_sound", std::ios::trunc);
if (ofs) ofs << targetPath << "\n";
}
statusBanner = "Notif/SMS sound set: " + fileName;
statusBannerUntilMs = nowMs() + 2200;
};
auto isSdCardMounted = []() -> bool {
std::ifstream f("/proc/mounts");
std::string line;
@@ -773,9 +972,19 @@ int runFilesApp(int argc, char** argv) {
if (isImageExt(ext)) {
actionsList.push_back({1, kIconEye, "Preview Image"});
actionsList.push_back({14, kIconImage, "Set as Wallpaper"});
} else if (isRingtoneExt(ext)) {
actionsList.push_back({1, kIconBell, "Preview Ringtone"});
actionsList.push_back({15, kIconCheck, "Set as Ringtone"});
actionsList.push_back({24, kIconSms, "Set as Notif / SMS Sound"});
actionsList.push_back({21, kIconBell, "Open in Ringtones App"});
actionsList.push_back({22, kIconMusic, "Play in Music Player"});
actionsList.push_back({17, kIconEye, "View Ringtone Text"});
} else if (isAudioExt(ext)) {
actionsList.push_back({1, kIconMusic, "Play in Music Player"});
actionsList.push_back({23, kIconSpeaker, "Preview Audio / Ringtone"});
actionsList.push_back({15, kIconBell, "Set as Ringtone"});
actionsList.push_back({24, kIconSms, "Set as Notif / SMS Sound"});
actionsList.push_back({21, kIconBell, "Open in Ringtones App"});
} else if (isGameBoyExt(ext)) {
actionsList.push_back({1, kIconGamepad, "Play in Game Boy Emulator"});
} else if (isJ2meExt(ext)) {
@@ -832,6 +1041,7 @@ int runFilesApp(int argc, char** argv) {
};
auto hideWindow = [&]() {
stopRingPreview();
if (!visible) return;
writeSoftkeySuppress(nowMs() + 450);
XUngrabKeyboard(dpy, CurrentTime);
@@ -841,7 +1051,18 @@ int runFilesApp(int argc, char** argv) {
::unlink(activePidPath.c_str());
};
auto openInRingtonesApp = [&](const std::string& path) {
stopRingPreview();
hideWindow();
if (isPluginDaemonAlive("ringtones")) {
sendPluginCommand("ringtones", "OPEN " + path);
} else {
runAsyncArgv("xringtones", path.c_str());
}
};
auto openInMusicPlayer = [&](const std::string& path) {
stopRingPreview();
hideWindow();
if (isPluginDaemonAlive("music")) {
sendPluginCommand("music", "OPEN " + path);
@@ -877,6 +1098,8 @@ int runFilesApp(int argc, char** argv) {
if (isImageExt(ext)) {
imgFullscreen = false;
openImageViewer(item);
} else if (isRingtoneExt(ext)) {
openRingtoneViewer(item, true);
} else if (isAudioExt(ext)) {
openInMusicPlayer(item.fullPath);
return;
@@ -916,6 +1139,7 @@ int runFilesApp(int argc, char** argv) {
auto drawUI = [&]() {
if (!visible) return;
checkRingPreviewAlive();
pt.checkAndReload();
XSetForeground(dpy, gc, pt.spec.bgMain);
@@ -997,6 +1221,9 @@ int runFilesApp(int argc, char** argv) {
if (isImageExt(ext)) {
ic = kIconImage;
icCol = &colGreen;
} else if (isRingtoneExt(ext)) {
ic = kIconBell;
icCol = &colYellow;
} else if (isMediaExt(ext)) {
ic = kIconMusic;
icCol = &colBlue;
@@ -1366,6 +1593,147 @@ int runFilesApp(int argc, char** argv) {
(editLines.size() == 1 && editLines[0].empty() && !editModified);
drawSoftkeyBar("Menu/Save", "Enter", docEmpty ? "Close" : "Del");
}
} else if (mode == ViewMode::RingtoneView) {
bool isPl =
(ringPreviewPid > 0 && ringPreviewActivePath == viewingFilePath);
XSetForeground(dpy, gc, pt.spec.bgHeader);
XFillRectangle(dpy, pix, gc, 0, 0, kWinWidth, 34);
XSetForeground(dpy, gc, pt.spec.border);
XDrawLine(dpy, pix, gc, 0, 33, kWinWidth, 33);
drawPango(layoutIcon, &colYellow, 6, 0, 34, kIconBell);
drawPango(layoutMain, &colWhite, 28, 0, 34, viewingFileName, 140);
std::string stateBadge = isPl ? "[PLAYING]" : "[STOPPED]";
pango_layout_set_width(layoutSmall, -1);
pango_layout_set_text(layoutSmall, stateBadge.c_str(),
static_cast<int>(stateBadge.size()));
int sbw = 0, sbh = 0;
pango_layout_get_pixel_size(layoutSmall, &sbw, &sbh);
drawPango(layoutSmall, isPl ? &colGreen : &colMuted,
kWinWidth - sbw - 6, 0, 34, stateBadge);
// Metadata card (y=38..104)
XSetForeground(dpy, gc, pt.spec.bgAltEven);
XFillRectangle(dpy, pix, gc, 4, 38, kWinWidth - 8, 66);
XSetForeground(dpy, gc, pt.spec.border);
XDrawRectangle(dpy, pix, gc, 4, 38, kWinWidth - 9, 65);
std::string fmtTitle =
ringPreviewIsMonotone
? std::string(monotoneFormatLabel(ringPreviewSong.format))
: (ringPreviewExtTag + " Audio");
drawPango(layoutSmall, &colBlue, 10, 40, 18, fmtTitle, 160);
std::string szStr = formatFileSize(ringPreviewSize);
pango_layout_set_width(layoutSmall, -1);
pango_layout_set_text(layoutSmall, szStr.c_str(),
static_cast<int>(szStr.size()));
int szw = 0, szh = 0;
pango_layout_get_pixel_size(layoutSmall, &szw, &szh);
drawPango(layoutSmall, &colMuted, kWinWidth - szw - 10, 40, 18, szStr);
std::string nameLine = "Title: " + ringPreviewSong.name;
if (!ringPreviewSong.composer.empty()) {
nameLine += " (" + ringPreviewSong.composer + ")";
}
drawPango(layoutMain, &colWhite, 10, 58, 22, nameLine, kWinWidth - 20);
if (ringPreviewIsMonotone && ringPreviewValid) {
char statBuf[128];
std::snprintf(statBuf, sizeof(statBuf),
"%s | %d BPM | %d notes | %.1fs",
monotoneStyleLabel(ringPreviewSong.style),
ringPreviewSong.bpm, ringPreviewSong.pitchedNoteCount,
ringPreviewSong.totalDurationMs / 1000.0);
drawPango(layoutSmall, &colYellow, 10, 81, 18, statBuf, kWinWidth - 20);
} else {
drawPango(layoutSmall, &colYellow, 10, 81, 18,
"Press OK or [*] to toggle preview", kWinWidth - 20);
}
// Graphical Piano-Roll / Pitch Contour (y=108..164)
XSetForeground(dpy, gc, pt.spec.bgInput);
XFillRectangle(dpy, pix, gc, 4, 108, kWinWidth - 8, 56);
XSetForeground(dpy, gc, pt.spec.divider);
XDrawRectangle(dpy, pix, gc, 4, 108, kWinWidth - 9, 55);
if (ringPreviewIsMonotone && ringPreviewValid &&
!ringPreviewSong.notes.empty() &&
ringPreviewSong.totalDurationMs > 0) {
int minMidi = 127;
int maxMidi = 0;
for (const auto& n : ringPreviewSong.notes) {
if (n.midiNote >= 0) {
minMidi = std::min(minMidi, n.midiNote);
maxMidi = std::max(maxMidi, n.midiNote);
}
}
if (minMidi > maxMidi) {
minMidi = 60;
maxMidi = 84;
}
if (maxMidi - minMidi < 12) {
int mid = (minMidi + maxMidi) / 2;
minMidi = mid - 6;
maxMidi = mid + 6;
}
const int rollX = 8;
const int rollW = kWinWidth - 16;
const int rollY = 113;
const int rollH = 44;
int accumMs = 0;
int totalMs = std::max(1, ringPreviewSong.totalDurationMs);
for (size_t ni = 0; ni < ringPreviewSong.notes.size(); ++ni) {
const auto& n = ringPreviewSong.notes[ni];
int x0 = rollX + (accumMs * rollW) / totalMs;
int x1 = rollX + ((accumMs + n.durationMs) * rollW) / totalMs;
int bw = std::max(2, x1 - x0 - 1);
accumMs += n.durationMs;
if (n.midiNote >= 0) {
int rel = n.midiNote - minMidi;
int span = std::max(1, maxMidi - minMidi);
int ny = rollY + rollH - 4 - (rel * (rollH - 4)) / span;
XSetForeground(
dpy, gc,
isPl ? ((ni % 2 == 0) ? pt.spec.accent : pt.spec.success)
: pt.spec.accentAlt);
XFillRectangle(dpy, pix, gc, x0, ny, bw, 4);
} else {
XSetForeground(dpy, gc, pt.spec.divider);
XFillRectangle(dpy, pix, gc, x0, rollY + rollH - 2,
std::max(1, bw), 1);
}
}
} else {
drawPango(layoutSmall, &colMuted, 12, 126, 20,
ringPreviewIsMonotone ? "No melody notes parsed"
: "Audio ringtone preview",
kWinWidth - 24);
}
// Note sequence / details box (y=168..236)
XSetForeground(dpy, gc, pt.spec.bgAltOdd);
XFillRectangle(dpy, pix, gc, 4, 168, kWinWidth - 8, 68);
XSetForeground(dpy, gc, pt.spec.divider);
XDrawRectangle(dpy, pix, gc, 4, 168, kWinWidth - 9, 67);
const int maxNoteVis = 3;
for (int i = 0; i < maxNoteVis; ++i) {
int idx = ringNoteScroll + i;
if (idx >= static_cast<int>(ringNoteLines.size())) break;
drawPango(layoutSmall, &colLight, 8, 171 + i * 20, 20,
ringNoteLines[idx], kWinWidth - 16);
}
drawPango(layoutSmall, &colMuted, 6, 240, 20,
"*:Play #:Set Notif L/R:Step 1:Edit", kWinWidth - 12);
drawSoftkeyBar("Set Ring", isPl ? "Stop" : "Play [*]", "Back");
}
int64_t tNow = nowMs();
@@ -1385,8 +1753,33 @@ int runFilesApp(int argc, char** argv) {
auto showWindow = [&](const std::string& dirArg) {
writeIntFile(activePidPath, static_cast<int>(::getpid()));
closeOtherPlugins("files");
stopRingPreview();
mode = ViewMode::Browser;
loadDirectory(dirArg.empty() ? currentDir : dirArg);
if (dirArg.empty()) {
loadDirectory(currentDir);
} else {
struct stat st {};
if (::stat(dirArg.c_str(), &st) == 0 && S_ISREG(st.st_mode)) {
char resolved[4096];
std::string full = dirArg;
if (::realpath(dirArg.c_str(), resolved) != nullptr) {
full = resolved;
}
size_t sl = full.rfind('/');
std::string pDir =
(sl == 0 || sl == std::string::npos) ? "/" : full.substr(0, sl);
std::string fName =
(sl == std::string::npos) ? full : full.substr(sl + 1);
loadDirectory(pDir, fName);
if (!filteredItems.empty() &&
filteredItems[selected].name == fName &&
isRingtoneExt(getExtLower(fName))) {
openRingtoneViewer(filteredItems[selected], true);
}
} else {
loadDirectory(dirArg);
}
}
if (!visible) {
visible = true;
XMapRaised(dpy, win);
@@ -1682,6 +2075,16 @@ int runFilesApp(int argc, char** argv) {
installAsRingtone(filteredItems[selected].fullPath,
filteredItems[selected].name);
mode = ViewMode::Browser;
} else if (actId == 24 && !filteredItems.empty()) {
installAsNotifSound(filteredItems[selected].fullPath,
filteredItems[selected].name);
mode = ViewMode::Browser;
} else if (actId == 21 && !filteredItems.empty()) {
openInRingtonesApp(filteredItems[selected].fullPath);
} else if (actId == 22 && !filteredItems.empty()) {
openInMusicPlayer(filteredItems[selected].fullPath);
} else if (actId == 23 && !filteredItems.empty()) {
openRingtoneViewer(filteredItems[selected], true);
} else if (actId == 16 && !filteredItems.empty()) {
openTextEditor(filteredItems[selected].fullPath,
filteredItems[selected].name);
@@ -1732,6 +2135,22 @@ int runFilesApp(int argc, char** argv) {
}
};
auto stepRingtoneInFolder = [&](int delta) {
if (filteredItems.empty()) return;
int n = static_cast<int>(filteredItems.size());
for (int step = 1; step <= n; ++step) {
int idx = (selected + delta * step + n * 2) % n;
if (!filteredItems[idx].isDir) {
std::string ext = getExtLower(filteredItems[idx].name);
if (isRingtoneExt(ext) || isAudioExt(ext)) {
selected = idx;
openRingtoneViewer(filteredItems[selected], true);
return;
}
}
}
};
auto handleSoftkeyAction = [&](bool isLeft) {
if (mode == ViewMode::Browser) {
if (isLeft) {
@@ -1793,6 +2212,13 @@ int runFilesApp(int argc, char** argv) {
mode = ViewMode::Browser;
}
}
} else if (mode == ViewMode::RingtoneView) {
if (isLeft) {
installAsRingtone(viewingFilePath, viewingFileName);
} else {
stopRingPreview();
mode = ViewMode::Browser;
}
} else if (mode == ViewMode::PropsView) {
mode = ViewMode::Browser;
} else if (mode == ViewMode::InputModal) {
@@ -2113,6 +2539,35 @@ int runFilesApp(int argc, char** argv) {
stepImageInFolder(1);
drawUI();
}
} else if (mode == ViewMode::RingtoneView) {
char d = mapDialKey(sym, kc, ev.xkey.state);
if (d == '*' || sym == XK_Return || sym == XK_KP_Enter) {
toggleRingPreview(viewingFilePath);
drawUI();
} else if (d == '#') {
installAsNotifSound(viewingFilePath, viewingFileName);
drawUI();
} else if (d == '1') {
stopRingPreview();
openTextEditor(viewingFilePath, viewingFileName);
drawUI();
} else if (d == '2') {
openInRingtonesApp(viewingFilePath);
} else if (sym == XK_Left || sym == XK_KP_Left) {
stepRingtoneInFolder(-1);
drawUI();
} else if (sym == XK_Right || sym == XK_KP_Right) {
stepRingtoneInFolder(1);
drawUI();
} else if (sym == XK_Up || sym == XK_KP_Up) {
ringNoteScroll = std::max(0, ringNoteScroll - 1);
drawUI();
} else if (sym == XK_Down || sym == XK_KP_Down) {
int maxSc = std::max(
0, static_cast<int>(ringNoteLines.size()) - 3);
ringNoteScroll = std::min(maxSc, ringNoteScroll + 1);
drawUI();
}
} else if (mode == ViewMode::PropsView) {
if (sym == XK_Return || sym == XK_KP_Enter) {
mode = ViewMode::Browser;
@@ -2152,6 +2607,9 @@ int runFilesApp(int argc, char** argv) {
}
int64_t tNow = nowMs();
if (visible && checkRingPreviewAlive()) {
drawUI();
}
if (visible && softkeyPending != 0 && tNow >= softkeyDeadlineMs) {
if (querySoftkeysDown(dpy) == 3) {
softkeyPending = 0;
@@ -2195,6 +2653,9 @@ int runFilesApp(int argc, char** argv) {
timeoutMs = (timeoutMs < 0) ? banRem : std::min(timeoutMs, banRem);
}
}
if (visible && ringPreviewPid > 0) {
timeoutMs = (timeoutMs < 0) ? 400 : std::min(timeoutMs, 400);
}
struct pollfd pfds[2];
int nfds = 0;
+2 -1
View File
@@ -456,7 +456,8 @@ int irc_run_main(int argc, char** argv) {
buffers[bIdx].unreadCount++;
if (hl) {
buffers[bIdx].hasHighlight = true;
neoui_vibrate(60);
runAsyncCmd("PATH=\"$HOME/.config/sxmo/hooks:/usr/share/sxmo/default_hooks:$PATH\" "
"sxmo_hook_notification.sh >/dev/null 2>&1");
}
}
return;
File diff suppressed because it is too large. Load diff
+20 -4
View File
@@ -1,4 +1,5 @@
#include "phone_data.h"
#include "monotone.h"
#include "../sxmo-dwm/dwm_plugin.h"
#include <X11/Xatom.h>
@@ -104,7 +105,8 @@ bool isStandardAudioExt(const std::string& ext) {
}
bool isSupportedAudioExt(const std::string& ext) {
return isStandardAudioExt(ext) || isTrackerFormatExt(ext);
return isStandardAudioExt(ext) || isTrackerFormatExt(ext) ||
isMonotoneExt(ext);
}
std::string toUpperTag(const std::string& ext) {
@@ -504,13 +506,27 @@ int runMusicApp(int argc, char** argv) {
"amixer -c 0 cset \"name='RX3 MIX1 INP1'\" 3 >/dev/null 2>&1; "
"wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 >/dev/null 2>&1");
std::string loadTarget = tr.path;
if (isMonotoneFile(tr.path)) {
loadTarget = "/tmp/xmusic_monotone.wav";
MonotoneSong song;
if (!synthesizeMonotoneFileToWav(tr.path, loadTarget, 1, &song)) {
setBanner("Invalid melody file");
isPlaying = false;
return;
}
if (!song.name.empty()) {
mediaTitle = song.name;
}
}
ensureMpvRunning();
if (tryConnectIpc()) {
sendIpcRaw("{\"command\":[\"loadfile\",\"" + jsonEscape(tr.path) +
sendIpcRaw("{\"command\":[\"loadfile\",\"" + jsonEscape(loadTarget) +
"\",\"replace\"]}");
sendIpcRaw("{\"command\":[\"set_property\",\"pause\",false]}");
} else {
pendingLoadPath = tr.path;
pendingLoadPath = loadTarget;
}
};
@@ -808,7 +824,7 @@ int runMusicApp(int argc, char** argv) {
size_t end = line.find('"', start);
if (end != std::string::npos && end > start) {
std::string t = line.substr(start, end - start);
if (!t.empty()) {
if (!t.empty() && t.find("xmusic_monotone") == std::string::npos) {
mediaTitle = prettifyTrackName(t);
}
}
+486 -73
View File
@@ -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);
}
}
}
+4 -2
View File
@@ -230,7 +230,8 @@ void onFriendRequest(Tox*, const Tox_Public_Key publicKey,
req.pubKeyHex = hex;
req.message.assign(reinterpret_cast<const char*>(message), length);
ctx->pendingReqs.push_back(std::move(req));
neoui_vibrate(70);
bananarchy::runAsyncCmd("PATH=\"$HOME/.config/sxmo/hooks:/usr/share/sxmo/default_hooks:$PATH\" "
"sxmo_hook_notification.sh >/dev/null 2>&1");
ctx->uiDirty = true;
}
@@ -241,7 +242,8 @@ void onFriendMessage(Tox* tox, Tox_Friend_Number friendNum,
std::string pkHex = getFriendPubKeyHex(tox, friendNum);
std::string txt(reinterpret_cast<const char*>(message), length);
appendFriendChat(pkHex, false, txt);
neoui_vibrate(60);
bananarchy::runAsyncCmd("PATH=\"$HOME/.config/sxmo/hooks:/usr/share/sxmo/default_hooks:$PATH\" "
"sxmo_hook_notification.sh >/dev/null 2>&1");
ctx->uiDirty = true;
}