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
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user