fix(input): add sliding-window multi-tap candidate bar and input tail-scrolling across plugins and fcitx5-t9
This commit is contained in:
1 parent
a53a331111
commit
1f9138f0c6
24 files changed
+394
-125
No files matched your search
@@ -2721,6 +2721,112 @@ inline bool qrtrWriteSimContacts(
|
||||
return outExported > 0;
|
||||
}
|
||||
|
||||
inline constexpr const char* kMultiTapPunct1 =
|
||||
".,-_!?/@:;'\"+=*#$%^&()[]{}<>|\\~`1";
|
||||
inline constexpr const char* kMultiTapStar =
|
||||
"*#+-=_/\\|~`@$%^&()[]{}<>'\".,!?:;";
|
||||
|
||||
inline std::string formatMultiTapBar(const std::string& prefix,
|
||||
const char* table, int activeIdx,
|
||||
bool makeUpper,
|
||||
int maxItems = 7,
|
||||
size_t maxChars = 21) {
|
||||
if (!table || !table[0]) return "";
|
||||
int total = static_cast<int>(std::strlen(table));
|
||||
if (total <= 0) return "";
|
||||
activeIdx = std::clamp(activeIdx, 0, total - 1);
|
||||
|
||||
std::vector<std::string> labels;
|
||||
labels.reserve(total);
|
||||
for (int i = 0; i < total; ++i) {
|
||||
char c = table[i];
|
||||
if (c == ' ') {
|
||||
labels.push_back("SPC");
|
||||
} else if (c == '\n') {
|
||||
labels.push_back("NL");
|
||||
} else if (c == '\t') {
|
||||
labels.push_back("TAB");
|
||||
} else {
|
||||
if (makeUpper && std::isalpha(static_cast<unsigned char>(c))) {
|
||||
c = static_cast<char>(std::toupper(static_cast<unsigned char>(c)));
|
||||
}
|
||||
labels.push_back(std::string(1, c));
|
||||
}
|
||||
}
|
||||
|
||||
int halfWin = std::max(1, maxItems / 2);
|
||||
int start = std::max(0, activeIdx - halfWin);
|
||||
int end = start;
|
||||
size_t width = 0;
|
||||
int count = 0;
|
||||
|
||||
while (start <= activeIdx) {
|
||||
width = 0;
|
||||
count = 0;
|
||||
end = start;
|
||||
while (end < total && count < maxItems) {
|
||||
size_t iw = labels[end].size() + 2;
|
||||
if (count > 0 && width + iw > maxChars) break;
|
||||
width += iw;
|
||||
++end;
|
||||
++count;
|
||||
}
|
||||
if (activeIdx < end) break;
|
||||
++start;
|
||||
}
|
||||
|
||||
while (start > 0 && count < maxItems) {
|
||||
size_t iw = labels[start - 1].size() + 2;
|
||||
if (width + iw > maxChars) break;
|
||||
--start;
|
||||
width += iw;
|
||||
++count;
|
||||
}
|
||||
|
||||
std::string out = prefix;
|
||||
out += (start > 0) ? "<" : " ";
|
||||
for (int i = start; i < end; ++i) {
|
||||
if (i == activeIdx) {
|
||||
out += "[" + labels[i] + "]";
|
||||
} else {
|
||||
out += " " + labels[i] + " ";
|
||||
}
|
||||
}
|
||||
if (end < total) {
|
||||
out += ">";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
inline std::string tailFitPangoText(PangoLayout* layout,
|
||||
const std::string& text,
|
||||
int maxWidthPx) {
|
||||
if (!layout || text.empty() || maxWidthPx <= 0) return text;
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
|
||||
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
|
||||
int w = 0, h = 0;
|
||||
pango_layout_get_pixel_size(layout, &w, &h);
|
||||
if (w <= maxWidthPx) return text;
|
||||
|
||||
size_t pos = 0;
|
||||
while (pos < text.size()) {
|
||||
pos++;
|
||||
while (pos < text.size() &&
|
||||
(static_cast<unsigned char>(text[pos]) & 0xC0) == 0x80) {
|
||||
pos++;
|
||||
}
|
||||
std::string candidate = ".." + text.substr(pos);
|
||||
pango_layout_set_text(layout, candidate.c_str(),
|
||||
static_cast<int>(candidate.size()));
|
||||
pango_layout_get_pixel_size(layout, &w, &h);
|
||||
if (w <= maxWidthPx) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
} // namespace bananarchy
|
||||
|
||||
#endif // DWM_PLUGINS_PHONE_DATA_H
|
||||
Reference in new issue
Block a user