2026-10-31 17:34:43 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
// Webarchy Full-Featured Web Browser DWM Plugin (webarchy.so / webarchy / xwebarchy)
|
|
|
|
|
// Features:
|
|
|
|
|
// 1. WPE / WebKit (webkit2gtk-4.1 + libwpe-1.0 + libwpebackend-fdo-1.0) backend
|
|
|
|
|
// with hardware-accelerated compositing/WebGL/2D-canvas and 512 MB RAM tuning.
|
|
|
|
|
// 2. Default KaiOS 4.0 User-Agent:
|
|
|
|
|
// Mozilla/5.0 (Mobile; rv:123.0) Gecko/123.0 Firefox/123.0 KAIOS/4.0
|
|
|
|
|
// with runtime preset & custom User-Agent override persisted in ~/.config/sxmo/.
|
|
|
|
|
// 3. UTF-8 default character encoding when the server specifies none.
|
|
|
|
|
// 4. Full multimedia playback enabled by default (MediaSource/MSE, WebAudio,
|
|
|
|
|
// EME, inline playback, no user-gesture restriction, ALSA MultiMedia1 routing).
|
|
|
|
|
// 5. Unobtrusive bookmarking system (header star badge, Kopher *0-9 / #0-9
|
|
|
|
|
// quick chords, and Bookmarks modal stored in ~/.config/sxmo/webarchy_bookmarks.tsv).
|
|
|
|
|
// 6. Dual navigation:
|
|
|
|
|
// - Keypad Link Navigation Mode (default): Kopher-style 2/5 or Left/Right link
|
|
|
|
|
// cycling, Up/Down scrolling, Center OK activation, and NeoUI multi-tap
|
|
|
|
|
// modal for HTML <input>/<textarea> fields.
|
|
|
|
|
// - Mouse Cursor Emulation Mode (optional, off by default, toggled via Menu
|
|
|
|
|
// or *# chord): virtual pointer moved by D-pad or 2/4/6/8 (diagonals 1/3/7/9)
|
|
|
|
|
// with edge auto-scrolling, hover inspection, and DOM/X11 click synthesis.
|
|
|
|
|
|
|
|
|
|
#include "../sxmo-dwm/dwm_plugin.h"
|
|
|
|
|
#include "phone_data.h"
|
|
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
#include <gdk/gdkx.h>
|
|
|
|
|
#include <webkit2/webkit2.h>
|
|
|
|
|
#include <jsc/jsc.h>
|
|
|
|
|
#include <wpe/wpe.h>
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
using namespace bananarchy;
|
|
|
|
|
|
|
|
|
|
volatile sig_atomic_t gRunning = 1;
|
|
|
|
|
|
|
|
|
|
void handleSignal(int) {
|
|
|
|
|
gRunning = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr const char* kDefaultUserAgent =
|
|
|
|
|
"Mozilla/5.0 (Mobile; rv:123.0) Gecko/123.0 Firefox/123.0 KAIOS/4.0";
|
|
|
|
|
|
|
|
|
|
constexpr const char* kDefaultHomepage = "https://lite.duckduckgo.com/lite/";
|
|
|
|
|
|
|
|
|
|
struct WebarchyControls {
|
|
|
|
|
char keyBack = '1';
|
|
|
|
|
char keyPrevLink = '2';
|
|
|
|
|
char keyForward = '3';
|
|
|
|
|
char keyToggleTheme = '4';
|
|
|
|
|
char keyNextLink = '5';
|
|
|
|
|
char keyToggleFit = '6';
|
|
|
|
|
char keyZoomOut = '7';
|
|
|
|
|
char keyPageTop = '8';
|
|
|
|
|
char keyZoomIn = '9';
|
|
|
|
|
char keyPageEnd = '0';
|
|
|
|
|
|
|
|
|
|
void resetDefaults() {
|
|
|
|
|
keyBack = '1';
|
|
|
|
|
keyPrevLink = '2';
|
|
|
|
|
keyForward = '3';
|
|
|
|
|
keyToggleTheme = '4';
|
|
|
|
|
keyNextLink = '5';
|
|
|
|
|
keyToggleFit = '6';
|
|
|
|
|
keyZoomOut = '7';
|
|
|
|
|
keyPageTop = '8';
|
|
|
|
|
keyZoomIn = '9';
|
|
|
|
|
keyPageEnd = '0';
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct BookmarkEntry {
|
|
|
|
|
int slot = 0; // 0 = Homepage (*), 1..9 = #1..#9, 10 = #0, >10 = extra
|
|
|
|
|
std::string title;
|
|
|
|
|
std::string url;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::string getControlsPath() {
|
|
|
|
|
return getHomeDirPath() + "/.config/sxmo/webarchy_controls.tsv";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string getBookmarksPath() {
|
|
|
|
|
return getHomeDirPath() + "/.config/sxmo/webarchy_bookmarks.tsv";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string getUserAgentPath() {
|
|
|
|
|
return getHomeDirPath() + "/.config/sxmo/webarchy_ua.txt";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebarchyControls loadControls() {
|
|
|
|
|
WebarchyControls c;
|
|
|
|
|
std::ifstream in(getControlsPath());
|
|
|
|
|
std::string k, v;
|
|
|
|
|
while (in >> k >> v) {
|
|
|
|
|
if (v.empty()) continue;
|
|
|
|
|
char ch = v[0];
|
|
|
|
|
if (k == "back") c.keyBack = ch;
|
|
|
|
|
else if (k == "prev_link") c.keyPrevLink = ch;
|
|
|
|
|
else if (k == "forward") c.keyForward = ch;
|
|
|
|
|
else if (k == "toggle_theme") c.keyToggleTheme = ch;
|
|
|
|
|
else if (k == "next_link") c.keyNextLink = ch;
|
|
|
|
|
else if (k == "toggle_fit") c.keyToggleFit = ch;
|
|
|
|
|
else if (k == "zoom_out") c.keyZoomOut = ch;
|
|
|
|
|
else if (k == "page_top") c.keyPageTop = ch;
|
|
|
|
|
else if (k == "zoom_in") c.keyZoomIn = ch;
|
|
|
|
|
else if (k == "page_end") c.keyPageEnd = ch;
|
|
|
|
|
}
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void saveControls(const WebarchyControls& c) {
|
|
|
|
|
std::string path = getControlsPath();
|
|
|
|
|
ContactBook::ensureParentDir(path);
|
|
|
|
|
std::ofstream out(path, std::ios::trunc);
|
|
|
|
|
if (!out.is_open()) return;
|
|
|
|
|
out << "back\t" << c.keyBack << "\n"
|
|
|
|
|
<< "prev_link\t" << c.keyPrevLink << "\n"
|
|
|
|
|
<< "forward\t" << c.keyForward << "\n"
|
|
|
|
|
<< "toggle_theme\t" << c.keyToggleTheme << "\n"
|
|
|
|
|
<< "next_link\t" << c.keyNextLink << "\n"
|
|
|
|
|
<< "toggle_fit\t" << c.keyToggleFit << "\n"
|
|
|
|
|
<< "zoom_out\t" << c.keyZoomOut << "\n"
|
|
|
|
|
<< "page_top\t" << c.keyPageTop << "\n"
|
|
|
|
|
<< "zoom_in\t" << c.keyZoomIn << "\n"
|
|
|
|
|
<< "page_end\t" << c.keyPageEnd << "\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string loadUserAgent() {
|
|
|
|
|
std::ifstream in(getUserAgentPath());
|
|
|
|
|
std::string line;
|
|
|
|
|
if (in.is_open() && std::getline(in, line)) {
|
|
|
|
|
line = trimStr(line);
|
|
|
|
|
if (!line.empty()) return line;
|
|
|
|
|
}
|
|
|
|
|
return kDefaultUserAgent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void saveUserAgent(const std::string& ua) {
|
|
|
|
|
std::string path = getUserAgentPath();
|
|
|
|
|
ContactBook::ensureParentDir(path);
|
|
|
|
|
std::ofstream out(path, std::ios::trunc);
|
|
|
|
|
if (out.is_open()) {
|
|
|
|
|
out << ua << "\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<BookmarkEntry> createDefaultBookmarks() {
|
|
|
|
|
std::vector<BookmarkEntry> bm(11);
|
|
|
|
|
for (int i = 0; i <= 10; ++i) bm[i].slot = i;
|
|
|
|
|
bm[0] = {0, "DuckDuckGo Lite", kDefaultHomepage};
|
|
|
|
|
bm[1] = {1, "Wikipedia Mobile", "https://en.m.wikipedia.org/"};
|
|
|
|
|
bm[2] = {2, "YouTube Mobile", "https://m.youtube.com/"};
|
|
|
|
|
bm[3] = {3, "Hacker News", "https://news.ycombinator.com/"};
|
|
|
|
|
bm[4] = {4, "NPR Text", "https://text.npr.org/"};
|
|
|
|
|
bm[5] = {5, "CNN Lite", "https://lite.cnn.com/"};
|
|
|
|
|
bm[6] = {6, "Wttr Weather", "https://wttr.in/?m"};
|
|
|
|
|
return bm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<BookmarkEntry> loadBookmarks() {
|
|
|
|
|
std::string path = getBookmarksPath();
|
|
|
|
|
std::ifstream in(path);
|
|
|
|
|
if (!in.is_open()) {
|
|
|
|
|
auto def = createDefaultBookmarks();
|
|
|
|
|
return def;
|
|
|
|
|
}
|
|
|
|
|
std::vector<BookmarkEntry> bm(11);
|
|
|
|
|
for (int i = 0; i <= 10; ++i) bm[i].slot = i;
|
|
|
|
|
|
|
|
|
|
std::string line;
|
|
|
|
|
int lineIdx = 0;
|
|
|
|
|
while (std::getline(in, line)) {
|
|
|
|
|
if (!line.empty() && line.back() == '\r') line.pop_back();
|
|
|
|
|
if (line.empty()) {
|
|
|
|
|
++lineIdx;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
std::vector<std::string> cols;
|
|
|
|
|
std::stringstream ss(line);
|
|
|
|
|
std::string col;
|
|
|
|
|
while (std::getline(ss, col, '\t')) cols.push_back(col);
|
|
|
|
|
if (cols.size() >= 3) {
|
|
|
|
|
int slot = std::atoi(cols[0].c_str());
|
|
|
|
|
if (slot >= 0 && slot <= 10) {
|
|
|
|
|
bm[slot] = {slot, trimStr(cols[1]), trimStr(cols[2])};
|
|
|
|
|
} else {
|
|
|
|
|
bm.push_back({static_cast<int>(bm.size()), trimStr(cols[1]), trimStr(cols[2])});
|
|
|
|
|
}
|
|
|
|
|
} else if (cols.size() == 2) {
|
|
|
|
|
int slot = std::min(lineIdx, 10);
|
|
|
|
|
bm[slot] = {slot, trimStr(cols[0]), trimStr(cols[1])};
|
|
|
|
|
} else if (cols.size() == 1 && lineIdx <= 10) {
|
|
|
|
|
bm[lineIdx] = {lineIdx, trimStr(cols[0]), trimStr(cols[0])};
|
|
|
|
|
}
|
|
|
|
|
++lineIdx;
|
|
|
|
|
}
|
|
|
|
|
if (bm[0].url.empty()) {
|
|
|
|
|
bm[0] = {0, "DuckDuckGo Lite", kDefaultHomepage};
|
|
|
|
|
}
|
|
|
|
|
return bm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void saveBookmarks(const std::vector<BookmarkEntry>& bm) {
|
|
|
|
|
std::string path = getBookmarksPath();
|
|
|
|
|
ContactBook::ensureParentDir(path);
|
|
|
|
|
std::ofstream out(path, std::ios::trunc);
|
|
|
|
|
if (!out.is_open()) return;
|
|
|
|
|
for (size_t i = 0; i < bm.size(); ++i) {
|
|
|
|
|
out << i << "\t" << bm[i].title << "\t" << bm[i].url << "\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string urlEncodeQuery(const std::string& s) {
|
|
|
|
|
std::string out;
|
|
|
|
|
char hex[4];
|
|
|
|
|
for (unsigned char c : s) {
|
|
|
|
|
if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {
|
|
|
|
|
out.push_back(static_cast<char>(c));
|
|
|
|
|
} else if (c == ' ') {
|
|
|
|
|
out.push_back('+');
|
|
|
|
|
} else {
|
|
|
|
|
std::snprintf(hex, sizeof(hex), "%%%02X", c);
|
|
|
|
|
out += hex;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string normalizeInputUrlOrSearch(const std::string& rawInput) {
|
|
|
|
|
std::string s = trimStr(rawInput);
|
|
|
|
|
if (s.empty()) return kDefaultHomepage;
|
|
|
|
|
std::string low = toLowerStr(s);
|
|
|
|
|
if (low.rfind("http://", 0) == 0 ||
|
|
|
|
|
low.rfind("https://", 0) == 0 ||
|
|
|
|
|
low.rfind("file://", 0) == 0 ||
|
|
|
|
|
low.rfind("data:", 0) == 0 ||
|
|
|
|
|
low.rfind("about:", 0) == 0) {
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
// If input contains spaces or has no dot (and isn't localhost), treat as search query
|
|
|
|
|
if (s.find(' ') != std::string::npos ||
|
|
|
|
|
(s.find('.') == std::string::npos && low != "localhost" &&
|
|
|
|
|
low.rfind("localhost:", 0) != 0)) {
|
|
|
|
|
return "https://lite.duckduckgo.com/lite/?q=" + urlEncodeQuery(s);
|
|
|
|
|
}
|
|
|
|
|
return "https://" + s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string extractHostFromUrl(const std::string& url) {
|
|
|
|
|
size_t pos = url.find("://");
|
|
|
|
|
std::string rest = (pos != std::string::npos) ? url.substr(pos + 3) : url;
|
|
|
|
|
size_t slash = rest.find('/');
|
|
|
|
|
if (slash != std::string::npos) rest = rest.substr(0, slash);
|
|
|
|
|
if (rest.rfind("www.", 0) == 0 && rest.size() > 4) rest = rest.substr(4);
|
|
|
|
|
return rest.empty() ? "Webarchy" : rest;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string jsEscapeString(const std::string& s) {
|
|
|
|
|
std::string out;
|
|
|
|
|
out.reserve(s.size() + 8);
|
|
|
|
|
for (unsigned char c : s) {
|
|
|
|
|
if (c == '\\') out += "\\\\";
|
|
|
|
|
else if (c == '"') out += "\\\"";
|
|
|
|
|
else if (c == '\'') out += "\\'";
|
|
|
|
|
else if (c == '\n') out += "\\n";
|
|
|
|
|
else if (c == '\r') out += "\\r";
|
|
|
|
|
else if (c == '\t') out += "\\t";
|
|
|
|
|
else if (c >= 0x20) out.push_back(static_cast<char>(c));
|
|
|
|
|
}
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Engine-level UserStyleSheet (bypasses site Content-Security-Policy)
|
|
|
|
|
constexpr const char* kWebarchyInjectedCss = R"CSS(
|
|
|
|
|
:root {
|
|
|
|
|
color-scheme: light dark;
|
|
|
|
|
}
|
|
|
|
|
.__wa_focus__ {
|
|
|
|
|
outline: 2px solid #ffcc00 !important;
|
|
|
|
|
outline-offset: 1px !important;
|
|
|
|
|
background-color: rgba(255, 204, 0, 0.18) !important;
|
|
|
|
|
}
|
|
|
|
|
#__webarchy_cursor__ {
|
|
|
|
|
position: fixed !important;
|
|
|
|
|
left: 120px;
|
|
|
|
|
top: 110px;
|
|
|
|
|
width: 14px !important;
|
|
|
|
|
height: 14px !important;
|
|
|
|
|
margin-left: -2px !important;
|
|
|
|
|
margin-top: -2px !important;
|
|
|
|
|
z-index: 2147483647 !important;
|
|
|
|
|
pointer-events: none !important;
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
html.__wa_dark__ {
|
|
|
|
|
filter: invert(0.92) hue-rotate(180deg) !important;
|
|
|
|
|
background: #111 !important;
|
|
|
|
|
}
|
|
|
|
|
html.__wa_dark__ img, html.__wa_dark__ video {
|
|
|
|
|
filter: invert(1) hue-rotate(180deg) !important;
|
|
|
|
|
}
|
|
|
|
|
html.__wa_fit__, html.__wa_fit__ body {
|
|
|
|
|
max-width: 100vw !important;
|
|
|
|
|
overflow-x: hidden !important;
|
|
|
|
|
word-wrap: break-word !important;
|
|
|
|
|
}
|
|
|
|
|
html.__wa_fit__ img, html.__wa_fit__ video, html.__wa_fit__ iframe, html.__wa_fit__ table, html.__wa_fit__ pre {
|
|
|
|
|
max-width: 100% !important;
|
|
|
|
|
height: auto !important;
|
|
|
|
|
}
|
|
|
|
|
button, input, select, textarea, optgroup {
|
|
|
|
|
font-family: "Noto Sans", sans-serif;
|
|
|
|
|
}
|
|
|
|
|
code, pre, kbd, samp, tt {
|
|
|
|
|
font-family: "Fira Code", monospace;
|
|
|
|
|
font-variant-ligatures: contextual common-ligatures;
|
|
|
|
|
font-feature-settings: "calt" 1, "liga" 1;
|
|
|
|
|
}
|
|
|
|
|
)CSS";
|
|
|
|
|
|
|
|
|
|
// Injected user script for Keypad Link Navigation, Mouse Cursor Emulation,
|
|
|
|
|
// Mobile 240px Reader Fit, Dark Inverter, and HTML Form Input bridging.
|
|
|
|
|
constexpr const char* kWebarchyInjectedJs = R"JS(
|
|
|
|
|
(function() {
|
|
|
|
|
if (window.__webarchy) return;
|
|
|
|
|
const W = {
|
|
|
|
|
idx: -1,
|
|
|
|
|
mouseMode: false,
|
|
|
|
|
cx: 120,
|
|
|
|
|
cy: 110,
|
|
|
|
|
darkMode: false,
|
|
|
|
|
mobileFit: false,
|
|
|
|
|
activeInput: null,
|
|
|
|
|
links: [],
|
|
|
|
|
|
|
|
|
|
post: function(msg) {
|
|
|
|
|
try {
|
|
|
|
|
if (window.webkit && window.webkit.messageHandlers &&
|
|
|
|
|
window.webkit.messageHandlers.webarchy) {
|
|
|
|
|
window.webkit.messageHandlers.webarchy.postMessage(String(msg));
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
ensureStyles: function() {
|
|
|
|
|
if (!document.getElementById('__webarchy_cursor__') && (document.body || document.documentElement)) {
|
|
|
|
|
const cur = document.createElement('div');
|
|
|
|
|
cur.id = '__webarchy_cursor__';
|
|
|
|
|
cur.innerHTML = '<svg width="14" height="14" viewBox="0 0 14 14"><path d="M1,1 L1,12 L4.2,9.2 L6.8,13 L8.6,12 L6,8.2 L10.5,8.2 Z" fill="#ffcc00" stroke="#000000" stroke-width="1.3"/></svg>';
|
|
|
|
|
(document.body || document.documentElement).appendChild(cur);
|
|
|
|
|
}
|
|
|
|
|
this.applyVisualFlags();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
applyVisualFlags: function() {
|
|
|
|
|
if (!document.documentElement) return;
|
|
|
|
|
document.documentElement.classList.toggle('__wa_dark__', !!this.darkMode);
|
|
|
|
|
document.documentElement.classList.toggle('__wa_fit__', !!this.mobileFit);
|
|
|
|
|
const cur = document.getElementById('__webarchy_cursor__');
|
|
|
|
|
if (cur) {
|
|
|
|
|
cur.style.position = 'fixed';
|
|
|
|
|
cur.style.width = '14px';
|
|
|
|
|
cur.style.height = '14px';
|
|
|
|
|
cur.style.marginLeft = '-2px';
|
|
|
|
|
cur.style.marginTop = '-2px';
|
|
|
|
|
cur.style.zIndex = '2147483647';
|
|
|
|
|
cur.style.pointerEvents = 'none';
|
|
|
|
|
cur.style.display = this.mouseMode ? 'block' : 'none';
|
|
|
|
|
cur.style.left = this.cx + 'px';
|
|
|
|
|
cur.style.top = this.cy + 'px';
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
isEditable: function(el) {
|
|
|
|
|
if (!el) return false;
|
|
|
|
|
const tag = (el.tagName || '').toUpperCase();
|
|
|
|
|
if (tag === 'TEXTAREA') return !el.disabled && !el.readOnly;
|
|
|
|
|
if (tag === 'INPUT') {
|
|
|
|
|
const t = (el.type || 'text').toLowerCase();
|
|
|
|
|
const nonText = ['button','submit','reset','checkbox','radio','file','image','range','color','hidden'];
|
|
|
|
|
return nonText.indexOf(t) === -1 && !el.disabled && !el.readOnly;
|
|
|
|
|
}
|
|
|
|
|
return !!el.isContentEditable;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
collectLinks: function() {
|
|
|
|
|
const sel = 'a[href], button, input:not([type="hidden"]), select, textarea, summary, video, audio, [role="button"], [role="link"], [onclick], [tabindex]:not([tabindex="-1"])';
|
|
|
|
|
const raw = Array.from(document.querySelectorAll(sel));
|
|
|
|
|
this.links = raw.filter(function(el) {
|
|
|
|
|
const r = el.getBoundingClientRect();
|
|
|
|
|
if (r.width < 2 && r.height < 2) return false;
|
|
|
|
|
const cs = window.getComputedStyle(el);
|
|
|
|
|
return cs.visibility !== 'hidden' && cs.display !== 'none';
|
|
|
|
|
});
|
|
|
|
|
return this.links;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
clearFocusHighlight: function() {
|
|
|
|
|
const prev = document.querySelectorAll('.__wa_focus__');
|
|
|
|
|
for (let i = 0; i < prev.length; ++i) prev[i].classList.remove('__wa_focus__');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
describeEl: function(el, prefix) {
|
|
|
|
|
if (!el) return prefix || '';
|
|
|
|
|
const tag = (el.tagName || '').toLowerCase();
|
|
|
|
|
let txt = (el.innerText || el.value || el.placeholder || el.title || el.getAttribute('aria-label') || '').replace(/\s+/g, ' ').trim();
|
|
|
|
|
if (txt.length > 36) txt = txt.substring(0, 36) + '...';
|
|
|
|
|
let href = el.href || el.action || '';
|
|
|
|
|
if (tag === 'input' || tag === 'textarea') {
|
|
|
|
|
const t = (el.type || 'text').toLowerCase();
|
|
|
|
|
return (prefix ? prefix + ' ' : '') + '<' + t + '> ' + (txt || 'Input field');
|
|
|
|
|
}
|
|
|
|
|
if (tag === 'video' || tag === 'audio') {
|
|
|
|
|
return (prefix ? prefix + ' ' : '') + '<' + tag + '> ' + (el.paused ? 'Paused (OK=Play)' : 'Playing (OK=Pause)');
|
|
|
|
|
}
|
|
|
|
|
if (href) {
|
|
|
|
|
return (prefix ? prefix + ' ' : '') + (txt ? txt + ' -> ' : '') + href;
|
|
|
|
|
}
|
|
|
|
|
return (prefix ? prefix + ' ' : '') + (txt || ('<' + tag + '>'));
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
stepLink: function(delta) {
|
|
|
|
|
this.ensureStyles();
|
|
|
|
|
const list = this.collectLinks();
|
|
|
|
|
this.clearFocusHighlight();
|
|
|
|
|
if (!list.length) {
|
|
|
|
|
this.idx = -1;
|
|
|
|
|
this.post('STATUS:No interactive links on page');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (this.idx < 0 || this.idx >= list.length) {
|
|
|
|
|
// Pick first link currently visible in or below viewport top
|
|
|
|
|
let start = 0;
|
|
|
|
|
for (let i = 0; i < list.length; ++i) {
|
|
|
|
|
const r = list[i].getBoundingClientRect();
|
|
|
|
|
if (r.bottom >= 0) { start = i; break; }
|
|
|
|
|
}
|
|
|
|
|
this.idx = delta >= 0 ? start : Math.max(0, start - 1);
|
|
|
|
|
} else {
|
|
|
|
|
this.idx = (this.idx + delta + list.length) % list.length;
|
|
|
|
|
}
|
|
|
|
|
const el = list[this.idx];
|
|
|
|
|
el.classList.add('__wa_focus__');
|
|
|
|
|
try {
|
|
|
|
|
el.scrollIntoView({ behavior: 'auto', block: 'nearest', inline: 'nearest' });
|
|
|
|
|
} catch (e) {}
|
|
|
|
|
const badge = '[' + (this.idx + 1) + '/' + list.length + ']';
|
|
|
|
|
this.post('STATUS:' + this.describeEl(el, badge));
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
activateElement: function(el) {
|
|
|
|
|
if (!el) return;
|
|
|
|
|
const clickable = el.closest('a[href], button, input, select, textarea, summary, video, audio, label, [role="button"], [role="link"], [onclick]') || el;
|
|
|
|
|
this.clearFocusHighlight();
|
|
|
|
|
clickable.classList.add('__wa_focus__');
|
|
|
|
|
const tag = (clickable.tagName || '').toUpperCase();
|
|
|
|
|
if (this.isEditable(clickable)) {
|
|
|
|
|
this.activeInput = clickable;
|
|
|
|
|
try { clickable.focus(); } catch (e) {}
|
|
|
|
|
const val = clickable.isContentEditable ? (clickable.innerText || '') : (clickable.value || '');
|
|
|
|
|
const label = clickable.placeholder || clickable.name || clickable.id || clickable.type || 'Input';
|
|
|
|
|
const isPass = (clickable.type || '').toLowerCase() === 'password' ? '1' : '0';
|
|
|
|
|
this.post('INPUT:' + isPass + ':' + encodeURIComponent(label) + ':' + encodeURIComponent(val));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (tag === 'VIDEO' || tag === 'AUDIO') {
|
|
|
|
|
clickable.muted = false;
|
|
|
|
|
if (clickable.paused) clickable.play();
|
|
|
|
|
else clickable.pause();
|
|
|
|
|
this.post('STATUS:' + this.describeEl(clickable, '[MEDIA]'));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (tag === 'SELECT') {
|
|
|
|
|
const n = clickable.options ? clickable.options.length : 0;
|
|
|
|
|
if (n > 0) {
|
|
|
|
|
clickable.selectedIndex = (clickable.selectedIndex + 1) % n;
|
|
|
|
|
clickable.dispatchEvent(new Event('change', { bubbles: true }));
|
|
|
|
|
const optTxt = clickable.options[clickable.selectedIndex].text || '';
|
|
|
|
|
this.post('STATUS:Selected: ' + optTxt);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try { clickable.focus(); } catch (e) {}
|
|
|
|
|
clickable.click();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
activateFocused: function() {
|
|
|
|
|
this.ensureStyles();
|
|
|
|
|
const list = this.collectLinks();
|
|
|
|
|
if (this.idx < 0 || this.idx >= list.length) {
|
|
|
|
|
if (list.length > 0) this.stepLink(1);
|
|
|
|
|
else return;
|
|
|
|
|
}
|
|
|
|
|
this.activateElement(this.links[this.idx]);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
setMouseMode: function(on) {
|
|
|
|
|
this.mouseMode = !!on;
|
|
|
|
|
this.ensureStyles();
|
|
|
|
|
if (this.mouseMode) {
|
|
|
|
|
this.moveCursor(0, 0);
|
|
|
|
|
} else {
|
|
|
|
|
this.clearFocusHighlight();
|
|
|
|
|
this.post('STATUS:Keypad link navigation mode');
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
moveCursor: function(dx, dy) {
|
|
|
|
|
this.ensureStyles();
|
|
|
|
|
const vw = window.innerWidth || 240;
|
|
|
|
|
const vh = window.innerHeight || 217;
|
|
|
|
|
let nx = this.cx + dx;
|
|
|
|
|
let ny = this.cy + dy;
|
|
|
|
|
if (ny < 4) { window.scrollBy(0, ny - 4 - 24); ny = 4; }
|
|
|
|
|
else if (ny > vh - 6) { window.scrollBy(0, (ny - (vh - 6)) + 24); ny = vh - 6; }
|
|
|
|
|
if (nx < 4) { window.scrollBy(nx - 4 - 20, 0); nx = 4; }
|
|
|
|
|
else if (nx > vw - 6) { window.scrollBy((nx - (vw - 6)) + 20, 0); nx = vw - 6; }
|
|
|
|
|
this.cx = Math.max(2, Math.min(vw - 4, nx));
|
|
|
|
|
this.cy = Math.max(2, Math.min(vh - 4, ny));
|
|
|
|
|
const cur = document.getElementById('__webarchy_cursor__');
|
|
|
|
|
if (cur) {
|
|
|
|
|
cur.style.display = 'block';
|
|
|
|
|
cur.style.left = this.cx + 'px';
|
|
|
|
|
cur.style.top = this.cy + 'px';
|
|
|
|
|
}
|
|
|
|
|
const el = document.elementFromPoint(this.cx, this.cy);
|
|
|
|
|
this.clearFocusHighlight();
|
|
|
|
|
if (el) {
|
|
|
|
|
const interactive = el.closest('a[href], button, input, select, textarea, summary, video, audio, [role="button"], [onclick]');
|
|
|
|
|
if (interactive) interactive.classList.add('__wa_focus__');
|
|
|
|
|
try {
|
|
|
|
|
el.dispatchEvent(new MouseEvent('mousemove', { view: window, bubbles: true, cancelable: true, clientX: this.cx, clientY: this.cy }));
|
|
|
|
|
el.dispatchEvent(new MouseEvent('mouseover', { view: window, bubbles: true, cancelable: true, clientX: this.cx, clientY: this.cy }));
|
|
|
|
|
} catch (e) {}
|
|
|
|
|
this.post('STATUS:(' + this.cx + ',' + this.cy + ') ' + this.describeEl(interactive || el, ''));
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
clickCursor: function() {
|
|
|
|
|
this.ensureStyles();
|
|
|
|
|
const el = document.elementFromPoint(this.cx, this.cy);
|
|
|
|
|
if (!el) return;
|
|
|
|
|
const target = el.closest('a[href], button, input, select, textarea, summary, video, audio, label, [role="button"], [role="link"], [onclick]') || el;
|
|
|
|
|
if (this.isEditable(target)) {
|
|
|
|
|
this.activateElement(target);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
const opts = { view: window, bubbles: true, cancelable: true, clientX: this.cx, clientY: this.cy, button: 0, buttons: 1 };
|
|
|
|
|
el.dispatchEvent(new MouseEvent('mousedown', opts));
|
|
|
|
|
el.dispatchEvent(new MouseEvent('mouseup', opts));
|
|
|
|
|
el.dispatchEvent(new MouseEvent('click', opts));
|
|
|
|
|
} catch (e) {}
|
|
|
|
|
if (target && target !== el && typeof target.click === 'function') {
|
|
|
|
|
try { target.click(); } catch (e) {}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
setInputValue: function(val, submitForm) {
|
|
|
|
|
const el = this.activeInput || document.activeElement;
|
|
|
|
|
if (!el) return;
|
|
|
|
|
if (el.isContentEditable) {
|
|
|
|
|
el.innerText = val;
|
|
|
|
|
} else {
|
|
|
|
|
const proto = Object.getPrototypeOf(el);
|
|
|
|
|
const desc = proto ? Object.getOwnPropertyDescriptor(proto, 'value') : null;
|
|
|
|
|
if (desc && desc.set) desc.set.call(el, val);
|
|
|
|
|
else el.value = val;
|
|
|
|
|
}
|
|
|
|
|
el.dispatchEvent(new Event('input', { bubbles: true }));
|
|
|
|
|
el.dispatchEvent(new Event('change', { bubbles: true }));
|
|
|
|
|
if (submitForm) {
|
|
|
|
|
const kOpts = { key: 'Enter', code: 'Enter', keyCode: 13, which: 13, bubbles: true, cancelable: true };
|
|
|
|
|
el.dispatchEvent(new KeyboardEvent('keydown', kOpts));
|
|
|
|
|
el.dispatchEvent(new KeyboardEvent('keypress', kOpts));
|
|
|
|
|
el.dispatchEvent(new KeyboardEvent('keyup', kOpts));
|
|
|
|
|
if (el.form) {
|
|
|
|
|
if (typeof el.form.requestSubmit === 'function') el.form.requestSubmit();
|
|
|
|
|
else el.form.submit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
setFlags: function(dark, fit, mouse) {
|
|
|
|
|
this.darkMode = !!dark;
|
|
|
|
|
this.mobileFit = !!fit;
|
|
|
|
|
this.mouseMode = !!mouse;
|
|
|
|
|
this.ensureStyles();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.__webarchy = W;
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() { W.ensureStyles(); });
|
|
|
|
|
window.addEventListener('load', function() { W.ensureStyles(); });
|
|
|
|
|
})();
|
|
|
|
|
)JS";
|
|
|
|
|
|
|
|
|
|
struct BrowserRuntimeState {
|
|
|
|
|
NeoWindow* neo = nullptr;
|
|
|
|
|
GtkWidget* gtkWin = nullptr;
|
|
|
|
|
WebKitWebView* webView = nullptr;
|
|
|
|
|
WebKitSettings* wkSettings = nullptr;
|
|
|
|
|
Window webkitXid = None;
|
|
|
|
|
bool initialized = false;
|
|
|
|
|
|
|
|
|
|
std::string currentUrl = kDefaultHomepage;
|
|
|
|
|
std::string currentTitle = "Webarchy";
|
|
|
|
|
std::string statusMsg = "Ready";
|
|
|
|
|
double loadProgress = 1.0;
|
|
|
|
|
bool isLoading = false;
|
|
|
|
|
|
|
|
|
|
bool mouseMode = false;
|
|
|
|
|
bool darkMode = false;
|
|
|
|
|
bool mobileFit = true;
|
|
|
|
|
double zoomLevel = 1.0;
|
|
|
|
|
int64_t lastCursorMoveMs = 0;
|
|
|
|
|
int cursorStep = 8;
|
|
|
|
|
|
|
|
|
|
// Triggered when user activates an HTML <input> or <textarea>
|
|
|
|
|
bool htmlInputPending = false;
|
|
|
|
|
bool htmlInputPassword = false;
|
|
|
|
|
std::string htmlInputLabel;
|
|
|
|
|
std::string htmlInputValue;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::string urlDecodePercent(const std::string& s) {
|
|
|
|
|
std::string out;
|
|
|
|
|
out.reserve(s.size());
|
|
|
|
|
for (size_t i = 0; i < s.size(); ++i) {
|
|
|
|
|
if (s[i] == '%' && i + 2 < s.size()) {
|
|
|
|
|
char hex[3] = { s[i + 1], s[i + 2], '\0' };
|
|
|
|
|
char* endp = nullptr;
|
|
|
|
|
long v = std::strtol(hex, &endp, 16);
|
|
|
|
|
if (endp == hex + 2) {
|
|
|
|
|
out.push_back(static_cast<char>(v));
|
|
|
|
|
i += 2;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
out.push_back(s[i]);
|
|
|
|
|
}
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void evalJs(BrowserRuntimeState& st, const std::string& code) {
|
|
|
|
|
if (!st.initialized || !st.webView) return;
|
|
|
|
|
webkit_web_view_evaluate_javascript(st.webView, code.c_str(), -1,
|
|
|
|
|
nullptr, nullptr, nullptr, nullptr, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void syncJsFlags(BrowserRuntimeState& st) {
|
|
|
|
|
std::ostringstream oss;
|
|
|
|
|
oss << "if(window.__webarchy)window.__webarchy.setFlags("
|
|
|
|
|
<< (st.darkMode ? "true" : "false") << ","
|
|
|
|
|
<< (st.mobileFit ? "true" : "false") << ","
|
|
|
|
|
<< (st.mouseMode ? "true" : "false") << ");";
|
|
|
|
|
evalJs(st, oss.str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
|
|
|
void onScriptMessage(WebKitUserContentManager*,
|
|
|
|
|
WebKitJavascriptResult* jsResult,
|
|
|
|
|
gpointer userData) {
|
|
|
|
|
auto* st = static_cast<BrowserRuntimeState*>(userData);
|
|
|
|
|
if (!st || !jsResult) return;
|
|
|
|
|
JSCValue* val = webkit_javascript_result_get_js_value(jsResult);
|
|
|
|
|
if (!val) return;
|
|
|
|
|
char* rawStr = jsc_value_to_string(val);
|
|
|
|
|
if (!rawStr) return;
|
|
|
|
|
std::string msg(rawStr);
|
|
|
|
|
g_free(rawStr);
|
|
|
|
|
|
|
|
|
|
if (msg.rfind("STATUS:", 0) == 0) {
|
|
|
|
|
st->statusMsg = msg.substr(7);
|
|
|
|
|
} else if (msg.rfind("INPUT:", 0) == 0) {
|
|
|
|
|
// Format: INPUT:<isPass>:<encodedLabel>:<encodedValue>
|
|
|
|
|
std::string rest = msg.substr(6);
|
|
|
|
|
size_t c1 = rest.find(':');
|
|
|
|
|
size_t c2 = (c1 != std::string::npos) ? rest.find(':', c1 + 1) : std::string::npos;
|
|
|
|
|
if (c1 != std::string::npos && c2 != std::string::npos) {
|
|
|
|
|
st->htmlInputPassword = (rest.substr(0, c1) == "1");
|
|
|
|
|
st->htmlInputLabel = urlDecodePercent(rest.substr(c1 + 1, c2 - c1 - 1));
|
|
|
|
|
st->htmlInputValue = urlDecodePercent(rest.substr(c2 + 1));
|
|
|
|
|
st->htmlInputPending = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
|
|
|
|
|
|
void onLoadChanged(WebKitWebView* webView,
|
|
|
|
|
WebKitLoadEvent loadEvent,
|
|
|
|
|
gpointer userData) {
|
|
|
|
|
auto* st = static_cast<BrowserRuntimeState*>(userData);
|
|
|
|
|
if (!st) return;
|
|
|
|
|
const char* uri = webkit_web_view_get_uri(webView);
|
|
|
|
|
if (uri && uri[0]) st->currentUrl = uri;
|
|
|
|
|
const char* title = webkit_web_view_get_title(webView);
|
|
|
|
|
if (title && title[0]) st->currentTitle = title;
|
|
|
|
|
else st->currentTitle = extractHostFromUrl(st->currentUrl);
|
|
|
|
|
|
|
|
|
|
if (loadEvent == WEBKIT_LOAD_STARTED || loadEvent == WEBKIT_LOAD_REDIRECTED) {
|
|
|
|
|
st->isLoading = true;
|
|
|
|
|
st->statusMsg = "Loading " + extractHostFromUrl(st->currentUrl) + "...";
|
|
|
|
|
} else if (loadEvent == WEBKIT_LOAD_COMMITTED) {
|
|
|
|
|
st->isLoading = true;
|
|
|
|
|
syncJsFlags(*st);
|
|
|
|
|
} else if (loadEvent == WEBKIT_LOAD_FINISHED) {
|
|
|
|
|
st->isLoading = false;
|
|
|
|
|
st->loadProgress = 1.0;
|
|
|
|
|
syncJsFlags(*st);
|
|
|
|
|
st->statusMsg = st->currentUrl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void onNotifyUriOrTitle(GObject* obj, GParamSpec*, gpointer userData) {
|
|
|
|
|
auto* st = static_cast<BrowserRuntimeState*>(userData);
|
|
|
|
|
auto* wv = WEBKIT_WEB_VIEW(obj);
|
|
|
|
|
if (!st || !wv) return;
|
|
|
|
|
const char* uri = webkit_web_view_get_uri(wv);
|
|
|
|
|
if (uri && uri[0]) st->currentUrl = uri;
|
|
|
|
|
const char* title = webkit_web_view_get_title(wv);
|
|
|
|
|
if (title && title[0]) st->currentTitle = title;
|
|
|
|
|
else st->currentTitle = extractHostFromUrl(st->currentUrl);
|
|
|
|
|
st->loadProgress = webkit_web_view_get_estimated_load_progress(wv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean onDecidePolicy(WebKitWebView* webView,
|
|
|
|
|
WebKitPolicyDecision* decision,
|
|
|
|
|
WebKitPolicyDecisionType type,
|
|
|
|
|
gpointer) {
|
|
|
|
|
if (type == WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION) {
|
|
|
|
|
auto* navDec = WEBKIT_NAVIGATION_POLICY_DECISION(decision);
|
|
|
|
|
WebKitNavigationAction* action =
|
|
|
|
|
webkit_navigation_policy_decision_get_navigation_action(navDec);
|
|
|
|
|
WebKitURIRequest* req = webkit_navigation_action_get_request(action);
|
|
|
|
|
const char* uri = req ? webkit_uri_request_get_uri(req) : nullptr;
|
|
|
|
|
if (uri && uri[0]) {
|
|
|
|
|
webkit_web_view_load_uri(webView, uri);
|
|
|
|
|
}
|
|
|
|
|
webkit_policy_decision_ignore(decision);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GtkWidget* onCreatePopupWebView(WebKitWebView* webView,
|
|
|
|
|
WebKitNavigationAction* action,
|
|
|
|
|
gpointer) {
|
|
|
|
|
WebKitURIRequest* req = webkit_navigation_action_get_request(action);
|
|
|
|
|
const char* uri = req ? webkit_uri_request_get_uri(req) : nullptr;
|
|
|
|
|
if (uri && uri[0]) {
|
|
|
|
|
webkit_web_view_load_uri(webView, uri);
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean onPermissionRequest(WebKitWebView*,
|
|
|
|
|
WebKitPermissionRequest* request,
|
|
|
|
|
gpointer) {
|
|
|
|
|
webkit_permission_request_allow(request);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-01 11:56:28 +02:00
|
|
|
gboolean onLoadFailed(WebKitWebView* webView,
|
|
|
|
|
WebKitLoadEvent,
|
|
|
|
|
gchar* failingUri,
|
|
|
|
|
GError* error,
|
|
|
|
|
gpointer userData) {
|
|
|
|
|
auto* st = static_cast<BrowserRuntimeState*>(userData);
|
|
|
|
|
if (st) {
|
|
|
|
|
st->isLoading = false;
|
|
|
|
|
if (error && error->message) {
|
|
|
|
|
st->statusMsg = std::string("Load failed: ") + error->message;
|
|
|
|
|
} else if (failingUri) {
|
|
|
|
|
st->statusMsg = std::string("Failed: ") + failingUri;
|
|
|
|
|
} else {
|
|
|
|
|
st->statusMsg = "Load failed";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
(void)webView;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-31 17:34:43 +02:00
|
|
|
gboolean onWebProcessTerminated(WebKitWebView* webView,
|
|
|
|
|
WebKitWebProcessTerminationReason,
|
|
|
|
|
gpointer userData) {
|
|
|
|
|
auto* st = static_cast<BrowserRuntimeState*>(userData);
|
|
|
|
|
if (st) {
|
|
|
|
|
st->isLoading = false;
|
|
|
|
|
st->statusMsg = "Web process restarted";
|
|
|
|
|
}
|
|
|
|
|
(void)webView;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ensureAlsaMultimediaRouting() {
|
2026-10-31 19:39:28 +02:00
|
|
|
if (isCallActiveOrRingingFast()) return;
|
|
|
|
|
runAsyncCmd(
|
|
|
|
|
"outdev=$(cat /tmp/sxmo_audio_out_device 2>/dev/null); "
|
|
|
|
|
"if [ \"$outdev\" = \"Earpiece\" ] || [ -z \"$outdev\" ]; then "
|
2026-11-04 15:42:58 +02:00
|
|
|
" if [ -n \"$(pactl list short sinks 2>/dev/null | awk '$2 ~ /^bluez_output\\./ { print $2; exit }')\" ]; then "
|
|
|
|
|
" sxmo_audio.sh out set Bluetooth >/dev/null 2>&1; "
|
|
|
|
|
" elif [ \"$(cat /tmp/sxmo_jack_plugged 2>/dev/null)\" = \"1\" ]; then "
|
2026-10-31 19:39:28 +02:00
|
|
|
" sxmo_audio.sh out set Headphones >/dev/null 2>&1; "
|
|
|
|
|
" else "
|
|
|
|
|
" sxmo_audio.sh out set Speaker >/dev/null 2>&1; "
|
|
|
|
|
" fi; "
|
2026-11-04 15:42:58 +02:00
|
|
|
"else "
|
|
|
|
|
" sxmo_audio.sh device apply >/dev/null 2>&1; "
|
|
|
|
|
"fi");
|
2026-10-31 17:34:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool initBrowserEngine(BrowserRuntimeState& st, const std::string& userAgent) {
|
|
|
|
|
if (st.initialized) return true;
|
|
|
|
|
|
|
|
|
|
// Hardware acceleration & Cortex-A7 / 512 MB RAM environment tuning
|
|
|
|
|
::setenv("GDK_BACKEND", "x11", 1);
|
|
|
|
|
::setenv("GTK_THEME", "Adwaita:dark", 1);
|
2026-11-01 11:56:28 +02:00
|
|
|
::setenv("NO_AT_BRIDGE", "1", 1);
|
|
|
|
|
::setenv("GTK_A11Y", "none", 1);
|
2026-10-31 19:39:28 +02:00
|
|
|
::setenv("WEBKIT_DISABLE_SANDBOX_THIS_IS_DANGEROUS", "1", 1);
|
2026-10-31 17:34:43 +02:00
|
|
|
::setenv("WEBKIT_DISABLE_COMPOSITING_MODE", "0", 0);
|
|
|
|
|
::setenv("WEBKIT_DISABLE_DMABUF_RENDERER", "0", 0);
|
|
|
|
|
::setenv("WEBKIT_SKIA_ENABLE_CPU_RENDERING", "0", 0);
|
|
|
|
|
::setenv("JSC_useJIT", "1", 0);
|
|
|
|
|
::setenv("JSC_useDFGJIT", "1", 0);
|
|
|
|
|
::setenv("JSC_useFTLJIT", "0", 0);
|
|
|
|
|
|
|
|
|
|
// Touch libwpe symbol so linker keeps libwpe-1.0 loaded for WPE backend support
|
|
|
|
|
(void)wpe_loader_get_loaded_implementation_library_name();
|
|
|
|
|
|
|
|
|
|
int dummyArgc = 0;
|
|
|
|
|
char** dummyArgv = nullptr;
|
|
|
|
|
if (!gtk_init_check(&dummyArgc, &dummyArgv)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (GtkSettings* gtkSet = gtk_settings_get_default()) {
|
|
|
|
|
g_object_set(gtkSet,
|
|
|
|
|
"gtk-application-prefer-dark-theme", TRUE,
|
|
|
|
|
"gtk-theme-name", "Adwaita:dark",
|
|
|
|
|
"gtk-font-name", "Noto Sans 10",
|
|
|
|
|
nullptr);
|
|
|
|
|
}
|
|
|
|
|
if (GdkScreen* scr = gdk_screen_get_default()) {
|
|
|
|
|
GtkCssProvider* cssProv = gtk_css_provider_new();
|
|
|
|
|
gtk_css_provider_load_from_data(
|
|
|
|
|
cssProv,
|
|
|
|
|
"@define-color theme_base_color #1e1e1e;\n"
|
|
|
|
|
"@define-color theme_bg_color #1e1e1e;\n"
|
|
|
|
|
"@define-color theme_fg_color #eeeeee;\n"
|
|
|
|
|
"@define-color theme_text_color #eeeeee;\n",
|
|
|
|
|
-1, nullptr);
|
|
|
|
|
gtk_style_context_add_provider_for_screen(
|
|
|
|
|
scr, GTK_STYLE_PROVIDER(cssProv),
|
|
|
|
|
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
|
|
|
|
g_object_unref(cssProv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Configure 160 MB memory pressure limit for WebKit processes on 512 MB phone
|
|
|
|
|
WebKitMemoryPressureSettings* mp = webkit_memory_pressure_settings_new();
|
|
|
|
|
webkit_memory_pressure_settings_set_memory_limit(mp, 160);
|
|
|
|
|
webkit_memory_pressure_settings_set_kill_threshold(mp, 0.92);
|
|
|
|
|
webkit_memory_pressure_settings_set_strict_threshold(mp, 0.75);
|
|
|
|
|
webkit_memory_pressure_settings_set_conservative_threshold(mp, 0.50);
|
|
|
|
|
webkit_website_data_manager_set_memory_pressure_settings(mp);
|
|
|
|
|
webkit_memory_pressure_settings_free(mp);
|
|
|
|
|
|
|
|
|
|
std::string dataDir = getHomeDirPath() + "/.local/share/sxmo/webarchy/data";
|
|
|
|
|
std::string cacheDir = getHomeDirPath() + "/.cache/sxmo/webarchy";
|
|
|
|
|
std::string cookieFile = getHomeDirPath() + "/.local/share/sxmo/webarchy/cookies.sqlite";
|
|
|
|
|
ContactBook::ensureParentDir(cookieFile);
|
|
|
|
|
|
|
|
|
|
WebKitWebsiteDataManager* dataMgr = webkit_website_data_manager_new(
|
|
|
|
|
"base-data-directory", dataDir.c_str(),
|
|
|
|
|
"base-cache-directory", cacheDir.c_str(),
|
|
|
|
|
nullptr);
|
|
|
|
|
webkit_website_data_manager_set_tls_errors_policy(
|
|
|
|
|
dataMgr, WEBKIT_TLS_ERRORS_POLICY_IGNORE);
|
|
|
|
|
WebKitWebContext* webCtx = webkit_web_context_new_with_website_data_manager(dataMgr);
|
|
|
|
|
g_object_unref(dataMgr);
|
|
|
|
|
|
2026-10-31 19:39:28 +02:00
|
|
|
webkit_web_context_set_sandbox_enabled(webCtx, FALSE);
|
2026-10-31 17:34:43 +02:00
|
|
|
webkit_web_context_set_cache_model(webCtx, WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER);
|
|
|
|
|
|
|
|
|
|
WebKitCookieManager* cookieMgr = webkit_web_context_get_cookie_manager(webCtx);
|
|
|
|
|
webkit_cookie_manager_set_persistent_storage(
|
|
|
|
|
cookieMgr, cookieFile.c_str(), WEBKIT_COOKIE_PERSISTENT_STORAGE_SQLITE);
|
|
|
|
|
webkit_cookie_manager_set_accept_policy(
|
|
|
|
|
cookieMgr, WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY);
|
|
|
|
|
|
|
|
|
|
// UserContentManager with engine-level stylesheet & injected keypad/mouse/form script
|
|
|
|
|
WebKitUserContentManager* ucm = webkit_user_content_manager_new();
|
|
|
|
|
WebKitUserStyleSheet* cssSheet = webkit_user_style_sheet_new(
|
|
|
|
|
kWebarchyInjectedCss,
|
|
|
|
|
WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
|
|
|
|
|
WEBKIT_USER_STYLE_LEVEL_USER,
|
|
|
|
|
nullptr, nullptr);
|
|
|
|
|
webkit_user_content_manager_add_style_sheet(ucm, cssSheet);
|
|
|
|
|
webkit_user_style_sheet_unref(cssSheet);
|
|
|
|
|
|
|
|
|
|
WebKitUserScript* script = webkit_user_script_new(
|
|
|
|
|
kWebarchyInjectedJs,
|
|
|
|
|
WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
|
|
|
|
|
WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START,
|
|
|
|
|
nullptr, nullptr);
|
|
|
|
|
webkit_user_content_manager_add_script(ucm, script);
|
|
|
|
|
webkit_user_script_unref(script);
|
|
|
|
|
|
|
|
|
|
g_signal_connect(ucm, "script-message-received::webarchy",
|
|
|
|
|
G_CALLBACK(onScriptMessage), &st);
|
|
|
|
|
webkit_user_content_manager_register_script_message_handler(ucm, "webarchy");
|
|
|
|
|
|
|
|
|
|
// WebKitSettings:
|
|
|
|
|
// 1) Hardware acceleration & low-RAM optimizations
|
|
|
|
|
// 2) Default KaiOS 4.0 User-Agent (overridable)
|
|
|
|
|
// 3) UTF-8 default encoding
|
|
|
|
|
// 4) All multimedia playback enabled by default
|
|
|
|
|
WebKitSettings* s = webkit_settings_new();
|
|
|
|
|
webkit_settings_set_user_agent(s, userAgent.c_str());
|
|
|
|
|
webkit_settings_set_default_charset(s, "UTF-8");
|
|
|
|
|
webkit_settings_set_default_font_family(s, "Noto Sans");
|
|
|
|
|
webkit_settings_set_sans_serif_font_family(s, "Noto Sans");
|
|
|
|
|
webkit_settings_set_serif_font_family(s, "Noto Serif");
|
|
|
|
|
webkit_settings_set_cursive_font_family(s, "Noto Sans");
|
|
|
|
|
webkit_settings_set_fantasy_font_family(s, "Noto Sans");
|
|
|
|
|
webkit_settings_set_monospace_font_family(s, "Fira Code");
|
|
|
|
|
webkit_settings_set_default_font_size(s, 13);
|
|
|
|
|
webkit_settings_set_default_monospace_font_size(s, 11);
|
|
|
|
|
webkit_settings_set_minimum_font_size(s, 9);
|
|
|
|
|
|
|
|
|
|
webkit_settings_set_hardware_acceleration_policy(
|
|
|
|
|
s, WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS);
|
|
|
|
|
webkit_settings_set_enable_webgl(s, TRUE);
|
|
|
|
|
webkit_settings_set_enable_smooth_scrolling(s, FALSE);
|
|
|
|
|
webkit_settings_set_enable_page_cache(s, TRUE);
|
|
|
|
|
webkit_settings_set_enable_site_specific_quirks(s, TRUE);
|
|
|
|
|
webkit_settings_set_enable_javascript(s, TRUE);
|
|
|
|
|
|
|
|
|
|
webkit_settings_set_enable_media(s, TRUE);
|
|
|
|
|
webkit_settings_set_enable_mediasource(s, TRUE);
|
|
|
|
|
webkit_settings_set_enable_media_stream(s, TRUE);
|
|
|
|
|
webkit_settings_set_enable_media_capabilities(s, TRUE);
|
|
|
|
|
webkit_settings_set_enable_webaudio(s, TRUE);
|
|
|
|
|
webkit_settings_set_enable_encrypted_media(s, TRUE);
|
|
|
|
|
webkit_settings_set_media_playback_requires_user_gesture(s, FALSE);
|
|
|
|
|
webkit_settings_set_media_playback_allows_inline(s, TRUE);
|
|
|
|
|
webkit_settings_set_enable_fullscreen(s, TRUE);
|
|
|
|
|
|
|
|
|
|
WebKitWebsitePolicies* policies = webkit_website_policies_new_with_policies(
|
|
|
|
|
"autoplay", WEBKIT_AUTOPLAY_ALLOW, nullptr);
|
|
|
|
|
|
|
|
|
|
GtkWidget* wvWidget = GTK_WIDGET(g_object_new(
|
|
|
|
|
WEBKIT_TYPE_WEB_VIEW,
|
|
|
|
|
"web-context", webCtx,
|
|
|
|
|
"user-content-manager", ucm,
|
|
|
|
|
"settings", s,
|
|
|
|
|
"website-policies", policies,
|
|
|
|
|
nullptr));
|
|
|
|
|
g_object_unref(policies);
|
|
|
|
|
g_object_unref(ucm);
|
|
|
|
|
g_object_unref(webCtx);
|
|
|
|
|
|
|
|
|
|
st.wkSettings = s;
|
|
|
|
|
st.webView = WEBKIT_WEB_VIEW(wvWidget);
|
|
|
|
|
|
|
|
|
|
g_signal_connect(st.webView, "load-changed", G_CALLBACK(onLoadChanged), &st);
|
2026-11-01 11:56:28 +02:00
|
|
|
g_signal_connect(st.webView, "load-failed", G_CALLBACK(onLoadFailed), &st);
|
2026-10-31 17:34:43 +02:00
|
|
|
g_signal_connect(st.webView, "notify::uri", G_CALLBACK(onNotifyUriOrTitle), &st);
|
|
|
|
|
g_signal_connect(st.webView, "notify::title", G_CALLBACK(onNotifyUriOrTitle), &st);
|
|
|
|
|
g_signal_connect(st.webView, "notify::estimated-load-progress",
|
|
|
|
|
G_CALLBACK(onNotifyUriOrTitle), &st);
|
|
|
|
|
g_signal_connect(st.webView, "decide-policy", G_CALLBACK(onDecidePolicy), &st);
|
|
|
|
|
g_signal_connect(st.webView, "create", G_CALLBACK(onCreatePopupWebView), &st);
|
|
|
|
|
g_signal_connect(st.webView, "permission-request", G_CALLBACK(onPermissionRequest), &st);
|
|
|
|
|
g_signal_connect(st.webView, "web-process-terminated",
|
|
|
|
|
G_CALLBACK(onWebProcessTerminated), &st);
|
|
|
|
|
|
|
|
|
|
// Create offscreen-popup GtkWindow sized to Webarchy's 240x217 viewport
|
|
|
|
|
// and reparent its X11 Window into NeoWindow at (X=0, Y=35).
|
|
|
|
|
st.gtkWin = gtk_window_new(GTK_WINDOW_POPUP);
|
|
|
|
|
gtk_window_set_default_size(GTK_WINDOW(st.gtkWin), 240, 217);
|
|
|
|
|
gtk_widget_set_size_request(st.gtkWin, 240, 217);
|
|
|
|
|
gtk_widget_set_size_request(wvWidget, 240, 217);
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(st.gtkWin), wvWidget);
|
|
|
|
|
gtk_widget_realize(st.gtkWin);
|
|
|
|
|
gtk_widget_show_all(st.gtkWin);
|
|
|
|
|
|
|
|
|
|
GdkWindow* gdkWin = gtk_widget_get_window(st.gtkWin);
|
|
|
|
|
if (gdkWin && st.neo && st.neo->dpy && st.neo->win != None) {
|
|
|
|
|
st.webkitXid = GDK_WINDOW_XID(gdkWin);
|
|
|
|
|
XReparentWindow(st.neo->dpy, st.webkitXid, st.neo->win, 0, 35);
|
|
|
|
|
XMoveResizeWindow(st.neo->dpy, st.webkitXid, 0, 35, 240, 217);
|
|
|
|
|
XMapRaised(st.neo->dpy, st.webkitXid);
|
|
|
|
|
XFlush(st.neo->dpy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
st.initialized = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int findBookmarkSlotForUrl(const std::vector<BookmarkEntry>& bm,
|
|
|
|
|
const std::string& url) {
|
|
|
|
|
if (url.empty()) return -1;
|
|
|
|
|
for (size_t i = 0; i < bm.size(); ++i) {
|
|
|
|
|
if (!bm[i].url.empty() && bm[i].url == url) {
|
|
|
|
|
return static_cast<int>(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int webarchy_run_main(int argc, char** argv) {
|
|
|
|
|
gRunning = 1;
|
|
|
|
|
bool isPreload = false;
|
|
|
|
|
std::string initUrl;
|
|
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
|
|
|
if (!argv[i] || !argv[i][0]) continue;
|
|
|
|
|
if (std::strcmp(argv[i], "--preload") == 0) isPreload = true;
|
|
|
|
|
else if (initUrl.empty()) initUrl = argv[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string forwarded =
|
|
|
|
|
isPreload ? "NOP" : (initUrl.empty() ? "OPEN" : ("OPEN " + initUrl));
|
|
|
|
|
if (sendPluginCommand("webarchy", forwarded)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string daemonPidPath = getPluginDaemonPidPath("webarchy");
|
|
|
|
|
std::string activePidPath = getRuntimeFile("xwebarchy.pid");
|
|
|
|
|
writeIntFile(daemonPidPath, static_cast<int>(::getpid()));
|
|
|
|
|
int fifoFd = setupPluginDaemonFifo("webarchy");
|
|
|
|
|
|
|
|
|
|
struct sigaction sa {};
|
|
|
|
|
sa.sa_handler = handleSignal;
|
|
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
|
sigaction(SIGTERM, &sa, nullptr);
|
|
|
|
|
sigaction(SIGINT, &sa, nullptr);
|
|
|
|
|
|
|
|
|
|
NeoWindow neo;
|
|
|
|
|
if (!neo.create("xwebarchy", "XWebarchy", "Webarchy Browser")) {
|
|
|
|
|
if (fifoFd >= 0) ::close(fifoFd);
|
|
|
|
|
::unlink(daemonPidPath.c_str());
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
neo.bindAsActiveContext();
|
|
|
|
|
|
|
|
|
|
WebarchyControls ctrls = loadControls();
|
|
|
|
|
std::vector<BookmarkEntry> bookmarks = loadBookmarks();
|
|
|
|
|
std::string userAgent = loadUserAgent();
|
|
|
|
|
|
|
|
|
|
BrowserRuntimeState br;
|
|
|
|
|
br.neo = &neo;
|
|
|
|
|
br.currentUrl = !bookmarks[0].url.empty() ? bookmarks[0].url : kDefaultHomepage;
|
|
|
|
|
|
|
|
|
|
bool visible = false;
|
|
|
|
|
bool menuOpen = false;
|
|
|
|
|
int menuSel = 0;
|
|
|
|
|
|
|
|
|
|
bool promptModalOpen = false;
|
|
|
|
|
bool promptIsAddressBar = true;
|
|
|
|
|
bool promptIsCustomUa = false;
|
|
|
|
|
std::string promptTitle = "Address or Search:";
|
|
|
|
|
|
|
|
|
|
bool bookmarksModalOpen = false;
|
|
|
|
|
int bookmarksSelRow = 0;
|
|
|
|
|
|
|
|
|
|
bool uaModalOpen = false;
|
|
|
|
|
int uaSelRow = 0;
|
|
|
|
|
|
|
|
|
|
bool controlsModalOpen = false;
|
|
|
|
|
int controlsSelRow = 0;
|
|
|
|
|
|
|
|
|
|
bool infoModalOpen = false;
|
|
|
|
|
std::string chordPrefix;
|
|
|
|
|
|
|
|
|
|
struct UaPreset {
|
|
|
|
|
const char* name;
|
|
|
|
|
const char* ua;
|
|
|
|
|
};
|
|
|
|
|
static const UaPreset kUaPresets[] = {
|
|
|
|
|
{ "KaiOS 4.0 (Default)",
|
|
|
|
|
kDefaultUserAgent },
|
|
|
|
|
{ "Firefox Android Mobile",
|
|
|
|
|
"Mozilla/5.0 (Android 14; Mobile; rv:128.0) Gecko/128.0 Firefox/128.0" },
|
|
|
|
|
{ "Safari iPhone iOS 17",
|
|
|
|
|
"Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Mobile/15E148 Safari/604.1" },
|
|
|
|
|
{ "Firefox Linux Desktop",
|
|
|
|
|
"Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0" },
|
|
|
|
|
{ "Custom User-Agent...", "" }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto anyModalOpen = [&]() -> bool {
|
|
|
|
|
return menuOpen || promptModalOpen || bookmarksModalOpen ||
|
|
|
|
|
uaModalOpen || controlsModalOpen || infoModalOpen;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto showFeedback = [&](const std::string& msg, int ms = 1500) {
|
|
|
|
|
br.statusMsg = msg;
|
|
|
|
|
if (anyModalOpen()) {
|
|
|
|
|
neoui_show_toast(msg.c_str(), ms);
|
|
|
|
|
} else {
|
|
|
|
|
neoui_clear_toast();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto syncWebkitVisibility = [&]() {
|
|
|
|
|
if (!br.initialized || br.webkitXid == None) return;
|
2026-11-01 10:39:40 +02:00
|
|
|
if (visible && !anyModalOpen() && !isPhonePasscodeLocked()) {
|
2026-10-31 17:34:43 +02:00
|
|
|
XMoveResizeWindow(neo.dpy, br.webkitXid, 0, 35, 240, 217);
|
|
|
|
|
XMapRaised(neo.dpy, br.webkitXid);
|
|
|
|
|
} else if (visible) {
|
|
|
|
|
// Shift subwindow outside 240px parent clip while modal is open so media continues playing
|
|
|
|
|
XMoveResizeWindow(neo.dpy, br.webkitXid, 240, 35, 240, 217);
|
|
|
|
|
}
|
|
|
|
|
XFlush(neo.dpy);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto navigateTo = [&](const std::string& rawTarget) {
|
|
|
|
|
std::string url = normalizeInputUrlOrSearch(rawTarget);
|
|
|
|
|
br.currentUrl = url;
|
|
|
|
|
br.statusMsg = "Loading " + extractHostFromUrl(url) + "...";
|
|
|
|
|
if (br.initialized && br.webView) {
|
|
|
|
|
webkit_web_view_load_uri(br.webView, url.c_str());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto bookmarkCurrentPageToSlot = [&](int slot) {
|
|
|
|
|
std::string title = br.currentTitle.empty()
|
|
|
|
|
? extractHostFromUrl(br.currentUrl)
|
|
|
|
|
: br.currentTitle;
|
|
|
|
|
if (slot >= 0 && slot < static_cast<int>(bookmarks.size())) {
|
|
|
|
|
bookmarks[slot] = {slot, title, br.currentUrl};
|
|
|
|
|
} else {
|
|
|
|
|
bookmarks.push_back({static_cast<int>(bookmarks.size()), title, br.currentUrl});
|
|
|
|
|
}
|
|
|
|
|
saveBookmarks(bookmarks);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto render = [&]() {
|
|
|
|
|
if (!visible) return;
|
|
|
|
|
syncWebkitVisibility();
|
|
|
|
|
neo.bindAsActiveContext();
|
|
|
|
|
neoui_begin_frame();
|
|
|
|
|
|
|
|
|
|
// Header badge: subtle '*' prefix when current page is bookmarked,
|
|
|
|
|
// plus protocol/mode/progress indicator.
|
|
|
|
|
int bmSlot = findBookmarkSlotForUrl(bookmarks, br.currentUrl);
|
|
|
|
|
std::string badge = (bmSlot >= 0) ? "*" : "";
|
|
|
|
|
if (br.isLoading && br.loadProgress < 0.99) {
|
|
|
|
|
int pct = std::clamp(static_cast<int>(br.loadProgress * 100.0), 1, 99);
|
|
|
|
|
badge += std::to_string(pct) + "%";
|
|
|
|
|
} else if (br.mouseMode) {
|
|
|
|
|
badge += "MOUSE";
|
|
|
|
|
} else if (br.currentUrl.rfind("https:", 0) == 0) {
|
|
|
|
|
badge += "HTTPS";
|
|
|
|
|
} else if (br.currentUrl.rfind("http:", 0) == 0) {
|
|
|
|
|
badge += "HTTP";
|
|
|
|
|
} else {
|
|
|
|
|
badge += "WEB";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string hdrTitle = br.currentTitle.empty()
|
|
|
|
|
? extractHostFromUrl(br.currentUrl)
|
|
|
|
|
: br.currentTitle;
|
|
|
|
|
neoui_draw_header(kIconGlobe, NEO_TEXT_GREEN, hdrTitle.c_str(), badge.c_str());
|
|
|
|
|
|
|
|
|
|
if (!anyModalOpen()) {
|
|
|
|
|
// Kopher-style bottom status bar at Y=252..270 (above the 26px softkey bar)
|
|
|
|
|
constexpr int kStatusY = 296 - NEO_SOFTBAR_H - 18;
|
|
|
|
|
neoui_fill_rect(0, kStatusY, 240, 18, neoui_color(NEO_COLOR_BG_ALT_EVEN));
|
|
|
|
|
std::string stText = !chordPrefix.empty()
|
|
|
|
|
? ("Key chord: " + chordPrefix + "_")
|
|
|
|
|
: br.statusMsg;
|
|
|
|
|
neoui_draw_text(NEO_FONT_SMALL, NEO_TEXT_YELLOW, 5, kStatusY, 18,
|
|
|
|
|
stText.c_str(), 230);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* centerLbl = br.mouseMode ? "CLICK" : "OPEN";
|
|
|
|
|
const char* rightLbl =
|
|
|
|
|
(br.initialized && br.webView && webkit_web_view_can_go_back(br.webView))
|
|
|
|
|
? "Back"
|
|
|
|
|
: "Close";
|
|
|
|
|
neoui_draw_softkeys("Menu", centerLbl, rightLbl);
|
|
|
|
|
|
|
|
|
|
if (promptModalOpen) {
|
|
|
|
|
neoui_draw_modal_box(4, 38, 232, 224, kIconGlobe, NEO_TEXT_YELLOW,
|
|
|
|
|
promptTitle.c_str());
|
|
|
|
|
const char* subHint = promptIsCustomUa
|
|
|
|
|
? "User-Agent string:"
|
|
|
|
|
: (promptIsAddressBar
|
|
|
|
|
? "URL or DuckDuckGo search:"
|
|
|
|
|
: "Web page field text:");
|
|
|
|
|
neoui_draw_input_box(10, 72, 220, 46, 1, subHint,
|
|
|
|
|
neoui_input_get_text(),
|
|
|
|
|
promptIsAddressBar ? "https://..." : "",
|
|
|
|
|
(!promptIsAddressBar && !promptIsCustomUa && br.htmlInputPassword) ? 1 : 0);
|
|
|
|
|
neoui_draw_multitap_bar(10, 126, 220, 22,
|
|
|
|
|
promptIsAddressBar
|
|
|
|
|
? "*/#:Mode Call:Clear"
|
|
|
|
|
: "*/#:Mode Call:Send");
|
|
|
|
|
neoui_draw_text(NEO_FONT_SMALL, NEO_TEXT_MUTED, 12, 160, 18,
|
|
|
|
|
promptIsAddressBar
|
|
|
|
|
? "OK/Left: Go to URL or search"
|
|
|
|
|
: "Left/Call: Submit OK: Set text",
|
|
|
|
|
216);
|
|
|
|
|
neoui_draw_text(NEO_FONT_SMALL, NEO_TEXT_MUTED, 12, 182, 18,
|
|
|
|
|
"Hold 0: + BackSpace: Delete", 216);
|
|
|
|
|
neoui_draw_softkeys(promptIsAddressBar ? "Go" : "Submit",
|
|
|
|
|
promptIsAddressBar ? "GO" : "SET", "Cancel");
|
|
|
|
|
} else if (bookmarksModalOpen) {
|
|
|
|
|
neoui_draw_modal_box(0, 34, 240, 236, kIconStar, NEO_TEXT_YELLOW,
|
|
|
|
|
"Bookmarks ([Call] Clear)");
|
|
|
|
|
int total = static_cast<int>(bookmarks.size());
|
|
|
|
|
bookmarksSelRow = std::clamp(bookmarksSelRow, 0, std::max(0, total - 1));
|
|
|
|
|
int startIdx = std::max(0, std::min(bookmarksSelRow - 2, std::max(0, total - 5)));
|
|
|
|
|
for (int i = 0; i < 5 && (startIdx + i) < total; ++i) {
|
|
|
|
|
int idx = startIdx + i;
|
|
|
|
|
const auto& b = bookmarks[idx];
|
|
|
|
|
std::string slotTag;
|
|
|
|
|
if (idx == 0) slotTag = "[*] ";
|
|
|
|
|
else if (idx <= 9) slotTag = "[" + std::to_string(idx) + "] ";
|
|
|
|
|
else if (idx == 10) slotTag = "[0] ";
|
|
|
|
|
else slotTag = "[+] ";
|
|
|
|
|
std::string rowTitle = slotTag + (b.title.empty() ? "(Empty Slot)" : b.title);
|
|
|
|
|
std::string rowSub = b.url.empty() ? "Empty - press Save Here"
|
|
|
|
|
: extractHostFromUrl(b.url);
|
|
|
|
|
neoui_draw_list_row(idx, 64 + i * 38, 38, idx == bookmarksSelRow ? 1 : 0,
|
|
|
|
|
b.url.empty() ? kIconCircle : kIconStar,
|
|
|
|
|
b.url.empty() ? NEO_TEXT_MUTED : NEO_TEXT_YELLOW,
|
|
|
|
|
rowTitle.c_str(), rowSub.c_str(), "");
|
|
|
|
|
}
|
|
|
|
|
neoui_draw_rect(0, 34, 240, 236, neoui_color(NEO_COLOR_ACCENT));
|
|
|
|
|
neoui_draw_scrollbar(234, 64, 190, total, 5, startIdx);
|
|
|
|
|
neoui_draw_softkeys("Save Here", "OPEN", "Close");
|
|
|
|
|
} else if (uaModalOpen) {
|
|
|
|
|
neoui_draw_modal_box(0, 34, 240, 236, kIconSliders, NEO_TEXT_YELLOW,
|
|
|
|
|
"User-Agent Override");
|
|
|
|
|
static const char* kUaSubs[5] = {
|
|
|
|
|
"Firefox 123 / KAIOS 4.0",
|
|
|
|
|
"Firefox 128 / Android 14",
|
|
|
|
|
"Mobile Safari / iOS 17.5",
|
|
|
|
|
"Firefox 128 / Linux x86_64",
|
|
|
|
|
"Enter custom UA string"
|
|
|
|
|
};
|
|
|
|
|
for (int i = 0; i < 5; ++i) {
|
|
|
|
|
bool active = (i < 4 && userAgent == kUaPresets[i].ua) ||
|
|
|
|
|
(i == 4 && userAgent != kUaPresets[0].ua &&
|
|
|
|
|
userAgent != kUaPresets[1].ua &&
|
|
|
|
|
userAgent != kUaPresets[2].ua &&
|
|
|
|
|
userAgent != kUaPresets[3].ua);
|
|
|
|
|
neoui_draw_list_row(i, 64 + i * 38, 38, i == uaSelRow ? 1 : 0,
|
|
|
|
|
active ? kIconCheck : kIconGlobe,
|
|
|
|
|
active ? NEO_TEXT_GREEN : NEO_TEXT_LIGHT,
|
|
|
|
|
kUaPresets[i].name, kUaSubs[i], active ? "ON" : "");
|
|
|
|
|
}
|
|
|
|
|
neoui_draw_rect(0, 34, 240, 236, neoui_color(NEO_COLOR_ACCENT));
|
|
|
|
|
neoui_draw_softkeys("Select", "APPLY", "Close");
|
|
|
|
|
} else if (controlsModalOpen) {
|
|
|
|
|
neoui_draw_modal_box(0, 34, 240, 236, kIconSliders, NEO_TEXT_YELLOW,
|
|
|
|
|
"Keys (Press 0-9 to bind)");
|
|
|
|
|
const char* names[10] = {
|
|
|
|
|
"Go Back", "Prev Link", "Go Forward", "Dark Mode", "Next Link",
|
|
|
|
|
"Mobile Fit", "Zoom Out", "Page Top", "Zoom In", "Page Bottom"
|
|
|
|
|
};
|
|
|
|
|
char curKeys[10] = {
|
|
|
|
|
ctrls.keyBack, ctrls.keyPrevLink, ctrls.keyForward, ctrls.keyToggleTheme,
|
|
|
|
|
ctrls.keyNextLink, ctrls.keyToggleFit, ctrls.keyZoomOut,
|
|
|
|
|
ctrls.keyPageTop, ctrls.keyZoomIn, ctrls.keyPageEnd
|
|
|
|
|
};
|
|
|
|
|
int startIdx = std::max(0, std::min(controlsSelRow - 2, 4));
|
|
|
|
|
for (int i = 0; i < 6 && (startIdx + i) < 10; ++i) {
|
|
|
|
|
int r = startIdx + i;
|
|
|
|
|
std::string kstr = std::string("[") + curKeys[r] + "]";
|
|
|
|
|
neoui_draw_list_row(r, 64 + i * 32, 32, r == controlsSelRow ? 1 : 0,
|
|
|
|
|
kIconKey, r == controlsSelRow ? NEO_TEXT_YELLOW : NEO_TEXT_LIGHT,
|
|
|
|
|
names[r], "", kstr.c_str());
|
|
|
|
|
}
|
|
|
|
|
neoui_draw_rect(0, 34, 240, 236, neoui_color(NEO_COLOR_ACCENT));
|
|
|
|
|
neoui_draw_scrollbar(234, 64, 192, 10, 6, startIdx);
|
|
|
|
|
neoui_draw_softkeys("Save", "RESET", "Cancel");
|
|
|
|
|
} else if (infoModalOpen) {
|
|
|
|
|
neoui_draw_modal_box(0, 34, 240, 236, kIconInfo, NEO_TEXT_YELLOW,
|
|
|
|
|
"Webarchy Help & Info");
|
|
|
|
|
std::string modeLine = std::string("Mode: ") +
|
|
|
|
|
(br.mouseMode ? "Mouse Cursor (*#)" : "Keypad Links (*#)") +
|
|
|
|
|
" " +
|
|
|
|
|
std::to_string(static_cast<int>(std::round(br.zoomLevel * 100))) + "%";
|
|
|
|
|
std::string hostLine = "Host: " + extractHostFromUrl(br.currentUrl);
|
|
|
|
|
const char* helpLines[7] = {
|
|
|
|
|
"Up/Down: Scroll (or Move Cursor)",
|
|
|
|
|
"Left/Right or 2/5: Prev/Next Link",
|
|
|
|
|
"OK / 5: Open Link or Edit Input",
|
|
|
|
|
"*#: Toggle Mouse Cursor Mode",
|
|
|
|
|
"*1-*0: Save BM #1-#0: Open BM",
|
|
|
|
|
"**: Set Home #*: Open Home",
|
|
|
|
|
"4:Dark 6:Fit 7/9:Zoom 8/0:Top/End"
|
|
|
|
|
};
|
|
|
|
|
neoui_draw_text(NEO_FONT_SMALL, NEO_TEXT_GREEN, 8, 66, 20, modeLine.c_str(), 224);
|
|
|
|
|
neoui_draw_text(NEO_FONT_SMALL, NEO_TEXT_YELLOW, 8, 86, 20, hostLine.c_str(), 224);
|
|
|
|
|
for (int i = 0; i < 7; ++i) {
|
|
|
|
|
neoui_draw_text(NEO_FONT_SMALL, NEO_TEXT_LIGHT, 8, 110 + i * 21, 20,
|
|
|
|
|
helpLines[i], 224);
|
|
|
|
|
}
|
|
|
|
|
neoui_draw_softkeys("Keys", "OK", "Close");
|
|
|
|
|
} else if (menuOpen) {
|
|
|
|
|
std::string menuItems =
|
|
|
|
|
std::string("Address / Search|") +
|
|
|
|
|
(br.mouseMode ? "Mouse Cursor (*#): ON|" : "Mouse Cursor (*#): OFF|") +
|
|
|
|
|
"Bookmarks (#1-#0)|"
|
|
|
|
|
"Bookmark Page (*1-*0)|"
|
|
|
|
|
"User-Agent Override|" +
|
|
|
|
|
(br.mobileFit ? "Mobile Fit (6): ON|" : "Mobile Fit (6): OFF|") +
|
|
|
|
|
(br.darkMode ? "Dark Mode (4): ON|" : "Dark Mode (4): OFF|") +
|
|
|
|
|
"Reload Page (Call)|"
|
|
|
|
|
"Customize Keys (#6)|"
|
|
|
|
|
"Page Info & Help (##)";
|
|
|
|
|
neoui_draw_menu_popup(menuItems.c_str(), nullptr, menuSel, 6);
|
|
|
|
|
neoui_draw_softkeys("Close", "SELECT", "Cancel");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
neoui_end_frame();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto openWindow = [&]() {
|
|
|
|
|
if (isPhonePasscodeLocked()) return;
|
|
|
|
|
writeIntFile(activePidPath, static_cast<int>(::getpid()));
|
|
|
|
|
closeOtherPlugins("webarchy");
|
2026-10-31 19:39:28 +02:00
|
|
|
ensureAlsaMultimediaRouting();
|
2026-10-31 17:34:43 +02:00
|
|
|
visible = true;
|
|
|
|
|
neoui_show();
|
2026-10-31 19:39:28 +02:00
|
|
|
grabPluginKeyboard(neo.dpy, neo.win);
|
2026-10-31 17:34:43 +02:00
|
|
|
if (!br.initialized) {
|
|
|
|
|
br.statusMsg = "Starting WPE/WebKit engine...";
|
|
|
|
|
render();
|
|
|
|
|
if (initBrowserEngine(br, userAgent)) {
|
|
|
|
|
webkit_web_view_load_uri(br.webView, br.currentUrl.c_str());
|
|
|
|
|
} else {
|
|
|
|
|
br.statusMsg = "Failed to initialize WebKit display";
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-10-31 19:39:28 +02:00
|
|
|
if (br.initialized && br.webView) {
|
|
|
|
|
webkit_web_view_set_is_muted(br.webView, FALSE);
|
|
|
|
|
}
|
2026-10-31 17:34:43 +02:00
|
|
|
syncWebkitVisibility();
|
|
|
|
|
grabPluginKeyboard(neo.dpy, neo.win);
|
|
|
|
|
render();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto closeWindow = [&]() {
|
|
|
|
|
if (!visible) return;
|
|
|
|
|
visible = false;
|
|
|
|
|
menuOpen = false;
|
|
|
|
|
promptModalOpen = false;
|
|
|
|
|
bookmarksModalOpen = false;
|
|
|
|
|
uaModalOpen = false;
|
|
|
|
|
controlsModalOpen = false;
|
|
|
|
|
infoModalOpen = false;
|
|
|
|
|
chordPrefix.clear();
|
2026-10-31 19:39:28 +02:00
|
|
|
if (br.initialized && br.webView) {
|
2026-11-01 11:56:28 +02:00
|
|
|
if (br.isLoading) {
|
|
|
|
|
webkit_web_view_stop_loading(br.webView);
|
|
|
|
|
br.isLoading = false;
|
|
|
|
|
}
|
2026-10-31 19:39:28 +02:00
|
|
|
evalJs(br, "try{document.querySelectorAll('audio,video').forEach(function(m){m.pause();});}catch(e){}");
|
|
|
|
|
webkit_web_view_set_is_muted(br.webView, TRUE);
|
|
|
|
|
}
|
2026-10-31 17:34:43 +02:00
|
|
|
syncWebkitVisibility();
|
|
|
|
|
neoui_hide();
|
|
|
|
|
::unlink(activePidPath.c_str());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!isPreload) {
|
|
|
|
|
openWindow();
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-01 10:39:40 +02:00
|
|
|
bool mutedByLock = false;
|
2026-10-31 17:34:43 +02:00
|
|
|
while (gRunning) {
|
|
|
|
|
for (const std::string& cmd : readFifoLines(fifoFd)) {
|
|
|
|
|
if (cmd == "NOP") continue;
|
|
|
|
|
if (cmd == "CLOSE") {
|
|
|
|
|
closeWindow();
|
|
|
|
|
} else if (cmd == "RELOAD_THEME") {
|
|
|
|
|
neo.reloadTheme();
|
|
|
|
|
if (visible) render();
|
|
|
|
|
} else if (cmd == "OPEN" || cmd.rfind("OPEN ", 0) == 0) {
|
2026-10-31 19:39:28 +02:00
|
|
|
std::string newUrl;
|
2026-10-31 17:34:43 +02:00
|
|
|
if (cmd.size() > 5) {
|
|
|
|
|
std::string arg = trimStr(cmd.substr(5));
|
|
|
|
|
if (!arg.empty()) {
|
2026-10-31 19:39:28 +02:00
|
|
|
newUrl = normalizeInputUrlOrSearch(arg);
|
|
|
|
|
br.currentUrl = newUrl;
|
2026-10-31 17:34:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
2026-10-31 19:39:28 +02:00
|
|
|
bool wasInitialized = br.initialized;
|
2026-10-31 17:34:43 +02:00
|
|
|
openWindow();
|
2026-10-31 19:39:28 +02:00
|
|
|
if (wasInitialized && !newUrl.empty() && br.initialized && br.webView) {
|
|
|
|
|
webkit_web_view_load_uri(br.webView, newUrl.c_str());
|
|
|
|
|
}
|
2026-10-31 17:34:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (br.initialized) {
|
|
|
|
|
std::string prevUrl = br.currentUrl;
|
|
|
|
|
std::string prevTitle = br.currentTitle;
|
|
|
|
|
std::string prevStatus = br.statusMsg;
|
|
|
|
|
bool prevLoading = br.isLoading;
|
|
|
|
|
while (g_main_context_pending(nullptr)) {
|
|
|
|
|
g_main_context_iteration(nullptr, FALSE);
|
|
|
|
|
}
|
|
|
|
|
if (br.htmlInputPending) {
|
|
|
|
|
br.htmlInputPending = false;
|
|
|
|
|
promptModalOpen = true;
|
|
|
|
|
promptIsAddressBar = false;
|
|
|
|
|
promptIsCustomUa = false;
|
|
|
|
|
promptTitle = "Input: " + br.htmlInputLabel;
|
|
|
|
|
neoui_input_reset(br.htmlInputValue.c_str());
|
|
|
|
|
if (visible) render();
|
|
|
|
|
} else if (visible &&
|
|
|
|
|
(br.currentUrl != prevUrl || br.currentTitle != prevTitle ||
|
|
|
|
|
br.statusMsg != prevStatus || br.isLoading != prevLoading)) {
|
|
|
|
|
render();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (visible) {
|
2026-11-01 10:39:40 +02:00
|
|
|
if (isPhonePasscodeLocked()) {
|
|
|
|
|
if (!mutedByLock) {
|
|
|
|
|
mutedByLock = true;
|
|
|
|
|
XUngrabKeyboard(neo.dpy, CurrentTime);
|
|
|
|
|
XFlush(neo.dpy);
|
|
|
|
|
if (br.initialized && br.webView) {
|
|
|
|
|
webkit_web_view_set_is_muted(br.webView, TRUE);
|
|
|
|
|
}
|
|
|
|
|
syncWebkitVisibility();
|
|
|
|
|
}
|
|
|
|
|
} else if (mutedByLock) {
|
|
|
|
|
mutedByLock = false;
|
|
|
|
|
if (br.initialized && br.webView) {
|
|
|
|
|
webkit_web_view_set_is_muted(br.webView, FALSE);
|
|
|
|
|
}
|
|
|
|
|
render();
|
|
|
|
|
}
|
2026-10-31 17:34:43 +02:00
|
|
|
neo.bindAsActiveContext();
|
|
|
|
|
int ev = neoui_poll_event(0);
|
|
|
|
|
while (ev != NEO_EV_NONE) {
|
|
|
|
|
if (ev == NEO_EV_EXPOSE || ev == NEO_EV_THEME_RELOAD) {
|
|
|
|
|
render();
|
|
|
|
|
} else if (ev == NEO_EV_CLOSE_REQ) {
|
|
|
|
|
closeWindow();
|
|
|
|
|
break;
|
|
|
|
|
} else if (ev == NEO_EV_SOFTKEY_LEFT) {
|
|
|
|
|
if (promptModalOpen) {
|
|
|
|
|
neoui_input_commit_tap();
|
|
|
|
|
std::string val = neoui_input_get_text();
|
|
|
|
|
promptModalOpen = false;
|
|
|
|
|
if (promptIsCustomUa) {
|
|
|
|
|
val = trimStr(val);
|
|
|
|
|
if (!val.empty()) {
|
|
|
|
|
userAgent = val;
|
|
|
|
|
saveUserAgent(userAgent);
|
|
|
|
|
if (br.wkSettings) {
|
|
|
|
|
webkit_settings_set_user_agent(br.wkSettings, userAgent.c_str());
|
|
|
|
|
}
|
|
|
|
|
if (br.webView) webkit_web_view_reload(br.webView);
|
|
|
|
|
showFeedback("Custom User-Agent set", 1600);
|
|
|
|
|
}
|
|
|
|
|
} else if (promptIsAddressBar) {
|
|
|
|
|
if (!trimStr(val).empty()) navigateTo(val);
|
|
|
|
|
} else {
|
|
|
|
|
evalJs(br, "if(window.__webarchy)window.__webarchy.setInputValue(\"" +
|
|
|
|
|
jsEscapeString(val) + "\", true);");
|
|
|
|
|
}
|
|
|
|
|
render();
|
|
|
|
|
} else if (bookmarksModalOpen) {
|
|
|
|
|
bookmarkCurrentPageToSlot(bookmarksSelRow);
|
|
|
|
|
showFeedback("Bookmark saved", 1500);
|
|
|
|
|
render();
|
|
|
|
|
} else if (uaModalOpen) {
|
|
|
|
|
if (uaSelRow >= 0 && uaSelRow < 4) {
|
|
|
|
|
userAgent = kUaPresets[uaSelRow].ua;
|
|
|
|
|
saveUserAgent(userAgent);
|
|
|
|
|
if (br.wkSettings) {
|
|
|
|
|
webkit_settings_set_user_agent(br.wkSettings, userAgent.c_str());
|
|
|
|
|
}
|
|
|
|
|
uaModalOpen = false;
|
|
|
|
|
if (br.webView) webkit_web_view_reload(br.webView);
|
|
|
|
|
showFeedback(kUaPresets[uaSelRow].name, 1600);
|
|
|
|
|
} else {
|
|
|
|
|
uaModalOpen = false;
|
|
|
|
|
promptModalOpen = true;
|
|
|
|
|
promptIsAddressBar = false;
|
|
|
|
|
promptIsCustomUa = true;
|
|
|
|
|
promptTitle = "Custom User-Agent:";
|
|
|
|
|
neoui_input_reset(userAgent.c_str());
|
|
|
|
|
}
|
|
|
|
|
render();
|
|
|
|
|
} else if (controlsModalOpen) {
|
|
|
|
|
saveControls(ctrls);
|
|
|
|
|
controlsModalOpen = false;
|
|
|
|
|
showFeedback("Controls saved", 1500);
|
|
|
|
|
render();
|
|
|
|
|
} else if (infoModalOpen) {
|
|
|
|
|
infoModalOpen = false;
|
|
|
|
|
controlsModalOpen = true;
|
|
|
|
|
render();
|
|
|
|
|
} else {
|
|
|
|
|
menuOpen = !menuOpen;
|
|
|
|
|
menuSel = 0;
|
|
|
|
|
render();
|
|
|
|
|
}
|
|
|
|
|
} else if (ev == NEO_EV_SOFTKEY_RIGHT) {
|
|
|
|
|
if (promptModalOpen) {
|
|
|
|
|
promptModalOpen = false;
|
|
|
|
|
render();
|
|
|
|
|
} else if (bookmarksModalOpen) {
|
|
|
|
|
bookmarksModalOpen = false;
|
|
|
|
|
render();
|
|
|
|
|
} else if (uaModalOpen) {
|
|
|
|
|
uaModalOpen = false;
|
|
|
|
|
render();
|
|
|
|
|
} else if (controlsModalOpen) {
|
|
|
|
|
controlsModalOpen = false;
|
|
|
|
|
render();
|
|
|
|
|
} else if (infoModalOpen) {
|
|
|
|
|
infoModalOpen = false;
|
|
|
|
|
render();
|
|
|
|
|
} else if (menuOpen) {
|
|
|
|
|
menuOpen = false;
|
|
|
|
|
render();
|
|
|
|
|
} else if (br.initialized && br.webView &&
|
|
|
|
|
webkit_web_view_can_go_back(br.webView)) {
|
|
|
|
|
webkit_web_view_go_back(br.webView);
|
|
|
|
|
render();
|
|
|
|
|
} else {
|
|
|
|
|
closeWindow();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else if (ev == NEO_EV_KEY_PRESS) {
|
|
|
|
|
int k = neoui_event_key();
|
|
|
|
|
int ks = neoui_event_keysym();
|
|
|
|
|
|
|
|
|
|
if (menuOpen) {
|
|
|
|
|
if (k == NEO_KEY_UP) menuSel = (menuSel + 9) % 10;
|
|
|
|
|
else if (k == NEO_KEY_DOWN) menuSel = (menuSel + 1) % 10;
|
|
|
|
|
else if (k == NEO_KEY_BACK || k == NEO_KEY_END) menuOpen = false;
|
|
|
|
|
else if (k == NEO_KEY_OK) {
|
|
|
|
|
menuOpen = false;
|
|
|
|
|
if (menuSel == 0) {
|
|
|
|
|
promptModalOpen = true;
|
|
|
|
|
promptIsAddressBar = true;
|
|
|
|
|
promptIsCustomUa = false;
|
|
|
|
|
promptTitle = "Address or Search:";
|
|
|
|
|
neoui_input_reset(br.currentUrl.c_str());
|
|
|
|
|
} else if (menuSel == 1) {
|
|
|
|
|
br.mouseMode = !br.mouseMode;
|
|
|
|
|
evalJs(br, std::string("if(window.__webarchy)window.__webarchy.setMouseMode(") +
|
|
|
|
|
(br.mouseMode ? "true);" : "false);"));
|
|
|
|
|
showFeedback(br.mouseMode ? "Mouse Cursor: ON" : "Mouse Cursor: OFF", 1500);
|
|
|
|
|
} else if (menuSel == 2) {
|
|
|
|
|
bookmarksModalOpen = true;
|
|
|
|
|
} else if (menuSel == 3) {
|
|
|
|
|
int targetSlot = -1;
|
|
|
|
|
for (int s = 1; s <= 10; ++s) {
|
|
|
|
|
if (bookmarks[s].url.empty()) { targetSlot = s; break; }
|
|
|
|
|
}
|
|
|
|
|
bookmarkCurrentPageToSlot(targetSlot);
|
|
|
|
|
showFeedback("Page bookmarked", 1500);
|
|
|
|
|
} else if (menuSel == 4) {
|
|
|
|
|
uaModalOpen = true;
|
|
|
|
|
} else if (menuSel == 5) {
|
|
|
|
|
br.mobileFit = !br.mobileFit;
|
|
|
|
|
syncJsFlags(br);
|
|
|
|
|
showFeedback(br.mobileFit ? "Mobile Fit: ON" : "Mobile Fit: OFF", 1500);
|
|
|
|
|
} else if (menuSel == 6) {
|
|
|
|
|
br.darkMode = !br.darkMode;
|
|
|
|
|
syncJsFlags(br);
|
|
|
|
|
showFeedback(br.darkMode ? "Dark Mode: ON" : "Dark Mode: OFF", 1500);
|
|
|
|
|
} else if (menuSel == 7) {
|
|
|
|
|
if (br.webView) webkit_web_view_reload(br.webView);
|
|
|
|
|
} else if (menuSel == 8) {
|
|
|
|
|
controlsModalOpen = true;
|
|
|
|
|
} else if (menuSel == 9) {
|
|
|
|
|
infoModalOpen = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
render();
|
|
|
|
|
} else if (promptModalOpen) {
|
|
|
|
|
if (k == NEO_KEY_OK) {
|
|
|
|
|
if (neoui_input_is_tap_active()) {
|
|
|
|
|
neoui_input_commit_tap();
|
|
|
|
|
} else {
|
|
|
|
|
std::string val = neoui_input_get_text();
|
|
|
|
|
promptModalOpen = false;
|
|
|
|
|
if (promptIsCustomUa) {
|
|
|
|
|
val = trimStr(val);
|
|
|
|
|
if (!val.empty()) {
|
|
|
|
|
userAgent = val;
|
|
|
|
|
saveUserAgent(userAgent);
|
|
|
|
|
if (br.wkSettings) {
|
|
|
|
|
webkit_settings_set_user_agent(br.wkSettings, userAgent.c_str());
|
|
|
|
|
}
|
|
|
|
|
if (br.webView) webkit_web_view_reload(br.webView);
|
|
|
|
|
showFeedback("Custom User-Agent set", 1600);
|
|
|
|
|
}
|
|
|
|
|
} else if (promptIsAddressBar) {
|
|
|
|
|
if (!trimStr(val).empty()) navigateTo(val);
|
|
|
|
|
} else {
|
|
|
|
|
evalJs(br, "if(window.__webarchy)window.__webarchy.setInputValue(\"" +
|
|
|
|
|
jsEscapeString(val) + "\", false);");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (k == NEO_KEY_CALL) {
|
|
|
|
|
if (promptIsAddressBar || promptIsCustomUa) {
|
|
|
|
|
neoui_input_reset("");
|
|
|
|
|
} else {
|
|
|
|
|
neoui_input_commit_tap();
|
|
|
|
|
std::string val = neoui_input_get_text();
|
|
|
|
|
promptModalOpen = false;
|
|
|
|
|
evalJs(br, "if(window.__webarchy)window.__webarchy.setInputValue(\"" +
|
|
|
|
|
jsEscapeString(val) + "\", true);");
|
|
|
|
|
}
|
|
|
|
|
} else if (k == NEO_KEY_RIGHT && neoui_input_is_tap_active()) {
|
|
|
|
|
neoui_input_commit_tap();
|
|
|
|
|
} else if (k == NEO_KEY_STAR || k == NEO_KEY_HASH) {
|
|
|
|
|
neoui_input_cycle_mode();
|
|
|
|
|
} else if (k == NEO_KEY_BACK) {
|
|
|
|
|
neoui_input_backspace();
|
|
|
|
|
} else if ((k >= NEO_KEY_0 && k <= NEO_KEY_9) || k == NEO_KEY_PLUS) {
|
|
|
|
|
neoui_input_feed_key(k);
|
|
|
|
|
} else if (k == NEO_KEY_NONE && ks >= 0x20 && ks <= 0x7e) {
|
|
|
|
|
std::string cur = neoui_input_get_text();
|
|
|
|
|
cur.push_back(static_cast<char>(ks));
|
|
|
|
|
neoui_input_set_text(cur.c_str());
|
|
|
|
|
}
|
|
|
|
|
render();
|
|
|
|
|
} else if (bookmarksModalOpen) {
|
|
|
|
|
int total = static_cast<int>(bookmarks.size());
|
|
|
|
|
if (k == NEO_KEY_UP) {
|
|
|
|
|
bookmarksSelRow = (bookmarksSelRow + total - 1) % std::max(1, total);
|
|
|
|
|
} else if (k == NEO_KEY_DOWN) {
|
|
|
|
|
bookmarksSelRow = (bookmarksSelRow + 1) % std::max(1, total);
|
|
|
|
|
} else if (k == NEO_KEY_OK) {
|
|
|
|
|
if (bookmarksSelRow >= 0 && bookmarksSelRow < total &&
|
|
|
|
|
!bookmarks[bookmarksSelRow].url.empty()) {
|
|
|
|
|
std::string target = bookmarks[bookmarksSelRow].url;
|
|
|
|
|
bookmarksModalOpen = false;
|
|
|
|
|
navigateTo(target);
|
|
|
|
|
}
|
|
|
|
|
} else if (k == NEO_KEY_CALL) {
|
|
|
|
|
if (bookmarksSelRow >= 0 && bookmarksSelRow < total) {
|
|
|
|
|
if (bookmarksSelRow <= 10) {
|
|
|
|
|
bookmarks[bookmarksSelRow].title.clear();
|
|
|
|
|
bookmarks[bookmarksSelRow].url.clear();
|
|
|
|
|
} else {
|
|
|
|
|
bookmarks.erase(bookmarks.begin() + bookmarksSelRow);
|
|
|
|
|
}
|
|
|
|
|
saveBookmarks(bookmarks);
|
|
|
|
|
showFeedback("Bookmark cleared", 1400);
|
|
|
|
|
}
|
|
|
|
|
} else if (k == NEO_KEY_BACK || k == NEO_KEY_END) {
|
|
|
|
|
bookmarksModalOpen = false;
|
|
|
|
|
}
|
|
|
|
|
render();
|
|
|
|
|
} else if (uaModalOpen) {
|
|
|
|
|
if (k == NEO_KEY_UP) uaSelRow = (uaSelRow + 4) % 5;
|
|
|
|
|
else if (k == NEO_KEY_DOWN) uaSelRow = (uaSelRow + 1) % 5;
|
|
|
|
|
else if (k == NEO_KEY_BACK || k == NEO_KEY_END) uaModalOpen = false;
|
|
|
|
|
else if (k == NEO_KEY_OK) {
|
|
|
|
|
if (uaSelRow >= 0 && uaSelRow < 4) {
|
|
|
|
|
userAgent = kUaPresets[uaSelRow].ua;
|
|
|
|
|
saveUserAgent(userAgent);
|
|
|
|
|
if (br.wkSettings) {
|
|
|
|
|
webkit_settings_set_user_agent(br.wkSettings, userAgent.c_str());
|
|
|
|
|
}
|
|
|
|
|
uaModalOpen = false;
|
|
|
|
|
if (br.webView) webkit_web_view_reload(br.webView);
|
|
|
|
|
showFeedback(kUaPresets[uaSelRow].name, 1600);
|
|
|
|
|
} else {
|
|
|
|
|
uaModalOpen = false;
|
|
|
|
|
promptModalOpen = true;
|
|
|
|
|
promptIsAddressBar = false;
|
|
|
|
|
promptIsCustomUa = true;
|
|
|
|
|
promptTitle = "Custom User-Agent:";
|
|
|
|
|
neoui_input_reset(userAgent.c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
render();
|
|
|
|
|
} else if (controlsModalOpen) {
|
|
|
|
|
if (k == NEO_KEY_UP) controlsSelRow = (controlsSelRow + 9) % 10;
|
|
|
|
|
else if (k == NEO_KEY_DOWN) controlsSelRow = (controlsSelRow + 1) % 10;
|
|
|
|
|
else if (k == NEO_KEY_OK) {
|
|
|
|
|
ctrls.resetDefaults();
|
|
|
|
|
saveControls(ctrls);
|
|
|
|
|
showFeedback("Reset to Kopher defaults", 1500);
|
|
|
|
|
} else if (k >= NEO_KEY_0 && k <= NEO_KEY_9) {
|
|
|
|
|
char ch = static_cast<char>(k);
|
|
|
|
|
if (controlsSelRow == 0) ctrls.keyBack = ch;
|
|
|
|
|
else if (controlsSelRow == 1) ctrls.keyPrevLink = ch;
|
|
|
|
|
else if (controlsSelRow == 2) ctrls.keyForward = ch;
|
|
|
|
|
else if (controlsSelRow == 3) ctrls.keyToggleTheme = ch;
|
|
|
|
|
else if (controlsSelRow == 4) ctrls.keyNextLink = ch;
|
|
|
|
|
else if (controlsSelRow == 5) ctrls.keyToggleFit = ch;
|
|
|
|
|
else if (controlsSelRow == 6) ctrls.keyZoomOut = ch;
|
|
|
|
|
else if (controlsSelRow == 7) ctrls.keyPageTop = ch;
|
|
|
|
|
else if (controlsSelRow == 8) ctrls.keyZoomIn = ch;
|
|
|
|
|
else if (controlsSelRow == 9) ctrls.keyPageEnd = ch;
|
|
|
|
|
} else if (k == NEO_KEY_BACK || k == NEO_KEY_END) {
|
|
|
|
|
controlsModalOpen = false;
|
|
|
|
|
}
|
|
|
|
|
render();
|
|
|
|
|
} else if (infoModalOpen) {
|
|
|
|
|
infoModalOpen = false;
|
|
|
|
|
render();
|
|
|
|
|
} else {
|
|
|
|
|
// Main browser view: handle Kopher * and # chords first
|
|
|
|
|
if (!chordPrefix.empty()) {
|
|
|
|
|
std::string prefix = chordPrefix;
|
|
|
|
|
chordPrefix.clear();
|
|
|
|
|
if (prefix == "*") {
|
|
|
|
|
if (k == NEO_KEY_STAR) {
|
|
|
|
|
bookmarkCurrentPageToSlot(0);
|
|
|
|
|
showFeedback("Saved as Homepage", 1600);
|
|
|
|
|
} else if (k == NEO_KEY_HASH) {
|
|
|
|
|
br.mouseMode = !br.mouseMode;
|
|
|
|
|
evalJs(br, std::string("if(window.__webarchy)window.__webarchy.setMouseMode(") +
|
|
|
|
|
(br.mouseMode ? "true);" : "false);"));
|
|
|
|
|
showFeedback(br.mouseMode ? "Mouse Cursor: ON" : "Mouse Cursor: OFF", 1500);
|
|
|
|
|
} else if (k >= NEO_KEY_0 && k <= NEO_KEY_9) {
|
|
|
|
|
int bIdx = (k == NEO_KEY_0) ? 10 : (k - NEO_KEY_0);
|
|
|
|
|
bookmarkCurrentPageToSlot(bIdx);
|
|
|
|
|
showFeedback("Bookmarked #" + std::to_string(bIdx), 1600);
|
|
|
|
|
} else if (k == NEO_KEY_CALL) {
|
|
|
|
|
std::ofstream sf("/tmp/shared_url.txt", std::ios::trunc);
|
|
|
|
|
if (sf.is_open()) sf << br.currentUrl << "\n";
|
|
|
|
|
showFeedback("Shared URL -> /tmp/shared_url.txt", 1800);
|
|
|
|
|
}
|
|
|
|
|
} else if (prefix == "#") {
|
|
|
|
|
if (k == NEO_KEY_STAR) {
|
|
|
|
|
navigateTo(!bookmarks[0].url.empty() ? bookmarks[0].url : kDefaultHomepage);
|
|
|
|
|
} else if (k == NEO_KEY_HASH) {
|
|
|
|
|
infoModalOpen = true;
|
|
|
|
|
} else if (k == NEO_KEY_CALL) {
|
|
|
|
|
bookmarksModalOpen = true;
|
|
|
|
|
} else if (k >= NEO_KEY_0 && k <= NEO_KEY_9) {
|
|
|
|
|
int bIdx = (k == NEO_KEY_0) ? 10 : (k - NEO_KEY_0);
|
|
|
|
|
if (bIdx < static_cast<int>(bookmarks.size()) &&
|
|
|
|
|
!bookmarks[bIdx].url.empty()) {
|
|
|
|
|
navigateTo(bookmarks[bIdx].url);
|
|
|
|
|
} else if (bIdx == 6) {
|
|
|
|
|
controlsModalOpen = true;
|
|
|
|
|
} else {
|
|
|
|
|
showFeedback("Empty bookmark #" + std::to_string(bIdx), 1500);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
render();
|
|
|
|
|
} else if (k == NEO_KEY_STAR) {
|
|
|
|
|
chordPrefix = "*";
|
|
|
|
|
render();
|
|
|
|
|
} else if (k == NEO_KEY_HASH) {
|
|
|
|
|
chordPrefix = "#";
|
|
|
|
|
render();
|
|
|
|
|
} else if (k == NEO_KEY_CALL) {
|
|
|
|
|
if (br.webView) webkit_web_view_reload(br.webView);
|
|
|
|
|
render();
|
|
|
|
|
} else if (k == NEO_KEY_END) {
|
|
|
|
|
closeWindow();
|
|
|
|
|
break;
|
|
|
|
|
} else if (k == NEO_KEY_BACK) {
|
|
|
|
|
if (br.initialized && br.webView &&
|
|
|
|
|
webkit_web_view_can_go_back(br.webView)) {
|
|
|
|
|
webkit_web_view_go_back(br.webView);
|
|
|
|
|
render();
|
|
|
|
|
} else {
|
|
|
|
|
closeWindow();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else if (br.mouseMode) {
|
|
|
|
|
// Mouse Cursor Emulation Mode controls:
|
|
|
|
|
// D-pad or 2/4/6/8 (plus diagonals 1/3/7/9) move pointer with acceleration;
|
|
|
|
|
// OK or 5 clicks at cursor; 0 scrolls page down.
|
|
|
|
|
int64_t now = nowMs();
|
|
|
|
|
if (now - br.lastCursorMoveMs < 220) {
|
|
|
|
|
br.cursorStep = std::min(18, br.cursorStep + 3);
|
|
|
|
|
} else {
|
|
|
|
|
br.cursorStep = 8;
|
|
|
|
|
}
|
|
|
|
|
br.lastCursorMoveMs = now;
|
|
|
|
|
int s = br.cursorStep;
|
|
|
|
|
|
|
|
|
|
if (k == NEO_KEY_UP || k == NEO_KEY_2) {
|
|
|
|
|
evalJs(br, "if(window.__webarchy)window.__webarchy.moveCursor(0," +
|
|
|
|
|
std::to_string(-s) + ");");
|
|
|
|
|
} else if (k == NEO_KEY_DOWN || k == NEO_KEY_8) {
|
|
|
|
|
evalJs(br, "if(window.__webarchy)window.__webarchy.moveCursor(0," +
|
|
|
|
|
std::to_string(s) + ");");
|
|
|
|
|
} else if (k == NEO_KEY_LEFT || k == NEO_KEY_4) {
|
|
|
|
|
evalJs(br, "if(window.__webarchy)window.__webarchy.moveCursor(" +
|
|
|
|
|
std::to_string(-s) + ",0);");
|
|
|
|
|
} else if (k == NEO_KEY_RIGHT || k == NEO_KEY_6) {
|
|
|
|
|
evalJs(br, "if(window.__webarchy)window.__webarchy.moveCursor(" +
|
|
|
|
|
std::to_string(s) + ",0);");
|
|
|
|
|
} else if (k == NEO_KEY_1) {
|
|
|
|
|
evalJs(br, "if(window.__webarchy)window.__webarchy.moveCursor(" +
|
|
|
|
|
std::to_string(-s) + "," + std::to_string(-s) + ");");
|
|
|
|
|
} else if (k == NEO_KEY_3) {
|
|
|
|
|
evalJs(br, "if(window.__webarchy)window.__webarchy.moveCursor(" +
|
|
|
|
|
std::to_string(s) + "," + std::to_string(-s) + ");");
|
|
|
|
|
} else if (k == NEO_KEY_7) {
|
|
|
|
|
evalJs(br, "if(window.__webarchy)window.__webarchy.moveCursor(" +
|
|
|
|
|
std::to_string(-s) + "," + std::to_string(s) + ");");
|
|
|
|
|
} else if (k == NEO_KEY_9) {
|
|
|
|
|
evalJs(br, "if(window.__webarchy)window.__webarchy.moveCursor(" +
|
|
|
|
|
std::to_string(s) + "," + std::to_string(s) + ");");
|
|
|
|
|
} else if (k == NEO_KEY_OK || k == NEO_KEY_5) {
|
|
|
|
|
evalJs(br, "if(window.__webarchy)window.__webarchy.clickCursor();");
|
|
|
|
|
} else if (k == NEO_KEY_0) {
|
|
|
|
|
evalJs(br, "window.scrollBy(0, 140);");
|
|
|
|
|
}
|
|
|
|
|
render();
|
|
|
|
|
} else {
|
|
|
|
|
// Keypad Link Navigation Mode (default):
|
|
|
|
|
if (k == NEO_KEY_UP) {
|
|
|
|
|
evalJs(br, "window.scrollBy(0, -52);");
|
|
|
|
|
} else if (k == NEO_KEY_DOWN) {
|
|
|
|
|
evalJs(br, "window.scrollBy(0, 52);");
|
|
|
|
|
} else if (k == NEO_KEY_LEFT) {
|
|
|
|
|
evalJs(br, "if(window.__webarchy)window.__webarchy.stepLink(-1);");
|
|
|
|
|
} else if (k == NEO_KEY_RIGHT) {
|
|
|
|
|
evalJs(br, "if(window.__webarchy)window.__webarchy.stepLink(1);");
|
|
|
|
|
} else if (k == NEO_KEY_OK) {
|
|
|
|
|
evalJs(br, "if(window.__webarchy)window.__webarchy.activateFocused();");
|
|
|
|
|
} else if (k >= NEO_KEY_0 && k <= NEO_KEY_9) {
|
|
|
|
|
char ch = static_cast<char>(k);
|
|
|
|
|
if (ch == ctrls.keyBack) {
|
|
|
|
|
if (br.webView && webkit_web_view_can_go_back(br.webView)) {
|
|
|
|
|
webkit_web_view_go_back(br.webView);
|
|
|
|
|
}
|
|
|
|
|
} else if (ch == ctrls.keyForward) {
|
|
|
|
|
if (br.webView && webkit_web_view_can_go_forward(br.webView)) {
|
|
|
|
|
webkit_web_view_go_forward(br.webView);
|
|
|
|
|
}
|
|
|
|
|
} else if (ch == ctrls.keyPrevLink) {
|
|
|
|
|
evalJs(br, "if(window.__webarchy)window.__webarchy.stepLink(-1);");
|
|
|
|
|
} else if (ch == ctrls.keyNextLink) {
|
|
|
|
|
evalJs(br, "if(window.__webarchy)window.__webarchy.stepLink(1);");
|
|
|
|
|
} else if (ch == ctrls.keyToggleTheme) {
|
|
|
|
|
br.darkMode = !br.darkMode;
|
|
|
|
|
syncJsFlags(br);
|
|
|
|
|
showFeedback(br.darkMode ? "Dark Mode: ON" : "Dark Mode: OFF", 1400);
|
|
|
|
|
} else if (ch == ctrls.keyToggleFit) {
|
|
|
|
|
br.mobileFit = !br.mobileFit;
|
|
|
|
|
syncJsFlags(br);
|
|
|
|
|
showFeedback(br.mobileFit ? "Mobile Fit: ON" : "Mobile Fit: OFF", 1400);
|
|
|
|
|
} else if (ch == ctrls.keyZoomOut) {
|
|
|
|
|
br.zoomLevel = std::max(0.5, br.zoomLevel - 0.1);
|
|
|
|
|
if (br.webView) webkit_web_view_set_zoom_level(br.webView, br.zoomLevel);
|
|
|
|
|
showFeedback("Zoom: " + std::to_string(static_cast<int>(std::round(br.zoomLevel * 100))) + "%", 1200);
|
|
|
|
|
} else if (ch == ctrls.keyZoomIn) {
|
|
|
|
|
br.zoomLevel = std::min(2.5, br.zoomLevel + 0.1);
|
|
|
|
|
if (br.webView) webkit_web_view_set_zoom_level(br.webView, br.zoomLevel);
|
|
|
|
|
showFeedback("Zoom: " + std::to_string(static_cast<int>(std::round(br.zoomLevel * 100))) + "%", 1200);
|
|
|
|
|
} else if (ch == ctrls.keyPageTop) {
|
|
|
|
|
evalJs(br, "window.scrollTo(0, 0);");
|
|
|
|
|
} else if (ch == ctrls.keyPageEnd) {
|
|
|
|
|
evalJs(br, "window.scrollTo(0, document.documentElement.scrollHeight || document.body.scrollHeight);");
|
|
|
|
|
}
|
|
|
|
|
render();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ev = neoui_poll_event(0);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
while (XPending(neo.dpy) > 0) {
|
|
|
|
|
XEvent xev;
|
|
|
|
|
XNextEvent(neo.dpy, &xev);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-01 11:56:28 +02:00
|
|
|
GMainContext* gctx = g_main_context_default();
|
|
|
|
|
gint maxPriority = 0;
|
|
|
|
|
gint glibTimeout = -1;
|
|
|
|
|
std::vector<GPollFD> gpfds;
|
|
|
|
|
bool useGlibPoll = br.initialized && (visible || br.isLoading);
|
|
|
|
|
if (useGlibPoll) {
|
|
|
|
|
if (g_main_context_prepare(gctx, &maxPriority)) {
|
|
|
|
|
glibTimeout = 0;
|
|
|
|
|
}
|
|
|
|
|
gpfds.resize(16);
|
|
|
|
|
gint nf = g_main_context_query(gctx, maxPriority, &glibTimeout,
|
|
|
|
|
gpfds.data(), static_cast<gint>(gpfds.size()));
|
|
|
|
|
if (nf > static_cast<gint>(gpfds.size())) {
|
|
|
|
|
gpfds.resize(nf);
|
|
|
|
|
nf = g_main_context_query(gctx, maxPriority, &glibTimeout,
|
|
|
|
|
gpfds.data(), nf);
|
|
|
|
|
}
|
|
|
|
|
gpfds.resize(std::max(0, nf));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<struct pollfd> pfds;
|
|
|
|
|
pfds.reserve(2 + gpfds.size());
|
|
|
|
|
pfds.push_back({ ConnectionNumber(neo.dpy), POLLIN, 0 });
|
|
|
|
|
if (fifoFd >= 0) {
|
|
|
|
|
pfds.push_back({ fifoFd, POLLIN, 0 });
|
|
|
|
|
}
|
|
|
|
|
size_t glibOffset = pfds.size();
|
|
|
|
|
for (const GPollFD& gp : gpfds) {
|
|
|
|
|
pfds.push_back({ gp.fd, static_cast<short>(gp.events), 0 });
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-31 17:34:43 +02:00
|
|
|
int timeoutMs = -1;
|
|
|
|
|
if (visible) {
|
2026-11-01 11:56:28 +02:00
|
|
|
neo.bindAsActiveContext();
|
|
|
|
|
timeoutMs = neoui_next_timeout_ms(-1);
|
|
|
|
|
if (isPhonePasscodeLocked() && !mutedByLock) {
|
|
|
|
|
timeoutMs = 0;
|
|
|
|
|
} else if (mutedByLock && (timeoutMs < 0 || timeoutMs > 250)) {
|
|
|
|
|
timeoutMs = 250;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (useGlibPoll && glibTimeout >= 0) {
|
|
|
|
|
if (timeoutMs < 0 || glibTimeout < timeoutMs) {
|
|
|
|
|
timeoutMs = glibTimeout;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
::poll(pfds.data(), static_cast<nfds_t>(pfds.size()), timeoutMs);
|
|
|
|
|
|
|
|
|
|
if (useGlibPoll) {
|
|
|
|
|
for (size_t i = 0; i < gpfds.size(); ++i) {
|
|
|
|
|
gpfds[i].revents = static_cast<gushort>(pfds[glibOffset + i].revents);
|
|
|
|
|
}
|
|
|
|
|
std::string prevUrl = br.currentUrl;
|
|
|
|
|
std::string prevTitle = br.currentTitle;
|
|
|
|
|
std::string prevStatus = br.statusMsg;
|
|
|
|
|
bool prevLoading = br.isLoading;
|
|
|
|
|
if (g_main_context_check(gctx, maxPriority, gpfds.data(),
|
|
|
|
|
static_cast<gint>(gpfds.size()))) {
|
|
|
|
|
g_main_context_dispatch(gctx);
|
|
|
|
|
}
|
|
|
|
|
if (br.htmlInputPending) {
|
|
|
|
|
br.htmlInputPending = false;
|
|
|
|
|
promptModalOpen = true;
|
|
|
|
|
promptIsAddressBar = false;
|
|
|
|
|
promptIsCustomUa = false;
|
|
|
|
|
promptTitle = "Input: " + br.htmlInputLabel;
|
|
|
|
|
neoui_input_reset(br.htmlInputValue.c_str());
|
|
|
|
|
if (visible) render();
|
|
|
|
|
} else if (visible &&
|
|
|
|
|
(br.currentUrl != prevUrl || br.currentTitle != prevTitle ||
|
|
|
|
|
br.statusMsg != prevStatus || br.isLoading != prevLoading)) {
|
|
|
|
|
render();
|
|
|
|
|
}
|
2026-10-31 17:34:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fifoFd >= 0) ::close(fifoFd);
|
|
|
|
|
::unlink(getPluginFifoPath("webarchy").c_str());
|
|
|
|
|
::unlink(daemonPidPath.c_str());
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int webarchy_plugin_init(const DwmHostApi* host) {
|
|
|
|
|
if (host && host->spawn_plugin) {
|
|
|
|
|
host->spawn_plugin("webarchy", "--preload");
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
extern "C" __attribute__((visibility("default"))) const DwmPlugin dwm_plugin_entry = {
|
|
|
|
|
DWM_PLUGIN_API_VERSION,
|
|
|
|
|
"webarchy",
|
|
|
|
|
"Webarchy WPE/WebKit full-featured browser with KaiOS UA, multimedia, and mouse mode",
|
|
|
|
|
webarchy_plugin_init,
|
|
|
|
|
nullptr,
|
|
|
|
|
nullptr,
|
|
|
|
|
nullptr,
|
|
|
|
|
nullptr,
|
|
|
|
|
webarchy_run_main
|
|
|
|
|
};
|