Optimize kernel-to-userspace battery life across CAMSS, SPI runtime PM, dwm, NeoUI, and plugins
This commit is contained in:
1 parent
f112b6ae72
commit
456d3fbc42
61 files changed
+466
-148
No files matched your search
@@ -772,6 +772,26 @@ gboolean onPermissionRequest(WebKitWebView*,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
gboolean onWebProcessTerminated(WebKitWebView* webView,
|
||||
WebKitWebProcessTerminationReason,
|
||||
gpointer userData) {
|
||||
@@ -806,6 +826,8 @@ bool initBrowserEngine(BrowserRuntimeState& st, const std::string& userAgent) {
|
||||
// Hardware acceleration & Cortex-A7 / 512 MB RAM environment tuning
|
||||
::setenv("GDK_BACKEND", "x11", 1);
|
||||
::setenv("GTK_THEME", "Adwaita:dark", 1);
|
||||
::setenv("NO_AT_BRIDGE", "1", 1);
|
||||
::setenv("GTK_A11Y", "none", 1);
|
||||
::setenv("WEBKIT_DISABLE_SANDBOX_THIS_IS_DANGEROUS", "1", 1);
|
||||
::setenv("WEBKIT_DISABLE_COMPOSITING_MODE", "0", 0);
|
||||
::setenv("WEBKIT_DISABLE_DMABUF_RENDERER", "0", 0);
|
||||
@@ -844,8 +866,6 @@ bool initBrowserEngine(BrowserRuntimeState& st, const std::string& userAgent) {
|
||||
g_object_unref(cssProv);
|
||||
}
|
||||
|
||||
ensureAlsaMultimediaRouting();
|
||||
|
||||
// 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);
|
||||
@@ -954,6 +974,7 @@ bool initBrowserEngine(BrowserRuntimeState& st, const std::string& userAgent) {
|
||||
st.webView = WEBKIT_WEB_VIEW(wvWidget);
|
||||
|
||||
g_signal_connect(st.webView, "load-changed", G_CALLBACK(onLoadChanged), &st);
|
||||
g_signal_connect(st.webView, "load-failed", G_CALLBACK(onLoadFailed), &st);
|
||||
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",
|
||||
@@ -1346,6 +1367,10 @@ int webarchy_run_main(int argc, char** argv) {
|
||||
infoModalOpen = false;
|
||||
chordPrefix.clear();
|
||||
if (br.initialized && br.webView) {
|
||||
if (br.isLoading) {
|
||||
webkit_web_view_stop_loading(br.webView);
|
||||
br.isLoading = false;
|
||||
}
|
||||
evalJs(br, "try{document.querySelectorAll('audio,video').forEach(function(m){m.pause();});}catch(e){}");
|
||||
webkit_web_view_set_is_muted(br.webView, TRUE);
|
||||
}
|
||||
@@ -1864,16 +1889,81 @@ int webarchy_run_main(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
|
||||
struct pollfd pfds[2] {};
|
||||
pfds[0] = { ConnectionNumber(neo.dpy), POLLIN, 0 };
|
||||
pfds[1] = { fifoFd, POLLIN, 0 };
|
||||
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 });
|
||||
}
|
||||
|
||||
int timeoutMs = -1;
|
||||
if (visible) {
|
||||
timeoutMs = 25;
|
||||
} else if (br.initialized && br.isLoading) {
|
||||
timeoutMs = 100;
|
||||
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();
|
||||
}
|
||||
}
|
||||
::poll(pfds, (fifoFd >= 0) ? 2 : 1, timeoutMs);
|
||||
}
|
||||
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
|
||||
Reference in new issue
Block a user