2026-11-23 12:46:34 +02:00
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
|
// Webarchy WebKit2GTK Browser for Geminux (Gemini PDA 2160x1080 Ultrawide)
|
|
|
|
|
|
//
|
|
|
|
|
|
// Ported from Bananarchy's Webarchy with:
|
|
|
|
|
|
// - Right-side collapsible vertical tab bar tailored for the 2160x1080 2:1 panel
|
|
|
|
|
|
// - Multi-tab WebKitWebView stack (Ctrl+T/Ctrl+W/Ctrl+Tab/Alt+1..9, middle-click & target=_blank tabs)
|
|
|
|
|
|
// - Live .Xresources theming + SIGUSR1 live reload (geminux-apply-theme)
|
|
|
|
|
|
// - Omnibar (URL / DuckDuckGo search), persistent SQLite cookies & bookmarks, UA presets,
|
|
|
|
|
|
// dark inverter, reader width fit toggle, find-in-page, zoom controls, and single-instance FIFO
|
|
|
|
|
|
// - GPU/Panfrost profile with automatic CPU renderer fallback on WebProcess crash
|
|
|
|
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
#include <gdk/gdkx.h>
|
|
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
|
|
#include <webkit2/webkit2.h>
|
|
|
|
|
|
#include <jsc/jsc.h>
|
|
|
|
|
|
#include <glib-unix.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
#include <cctype>
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
|
|
constexpr const char* kDefaultUserAgent =
|
|
|
|
|
|
"Mozilla/5.0 (X11; Linux aarch64; rv:128.0) Gecko/20100101 Firefox/128.0";
|
|
|
|
|
|
|
|
|
|
|
|
constexpr const char* kDefaultHomepage = "https://lite.duckduckgo.com/lite/";
|
|
|
|
|
|
|
|
|
|
|
|
// WebKitGTK reads WEBKIT_DISABLE_* / WEBKIT_SKIA_* variables as presence flags,
|
|
|
|
|
|
// not as booleans. Never leave them set to "0" in the environment.
|
|
|
|
|
|
constexpr const char* kSoftwareRendererFlag =
|
|
|
|
|
|
"/.config/geminux/webarchy/software_renderer";
|
|
|
|
|
|
|
|
|
|
|
|
std::string getHomeDirPath() {
|
|
|
|
|
|
const char* home = std::getenv("HOME");
|
|
|
|
|
|
if (home && home[0]) return std::string(home);
|
|
|
|
|
|
return "/home/user";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string deviceTreeCompatibles() {
|
|
|
|
|
|
FILE* f = std::fopen("/proc/device-tree/compatible", "rb");
|
|
|
|
|
|
if (!f) return {};
|
|
|
|
|
|
char buf[512];
|
|
|
|
|
|
size_t n = std::fread(buf, 1, sizeof(buf), f);
|
|
|
|
|
|
std::fclose(f);
|
|
|
|
|
|
std::string raw(buf, n);
|
|
|
|
|
|
std::replace(raw.begin(), raw.end(), '\0', ' ');
|
|
|
|
|
|
return raw;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool webarchySoftwareRendererPreferred() {
|
|
|
|
|
|
if (deviceTreeCompatibles().find("nokia,beatles") != std::string::npos)
|
|
|
|
|
|
return true;
|
|
|
|
|
|
return ::access((getHomeDirPath() + kSoftwareRendererFlag).c_str(), F_OK) == 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void configureWebkitRenderer(bool software) {
|
|
|
|
|
|
// Presence flags: never leave them defined as "0" in the browser's environment.
|
|
|
|
|
|
::unsetenv("WEBKIT_DISABLE_DMABUF_RENDERER");
|
|
|
|
|
|
::unsetenv("WEBKIT_DISABLE_COMPOSITING_MODE");
|
|
|
|
|
|
::unsetenv("WEBKIT_SKIA_ENABLE_CPU_RENDERING");
|
|
|
|
|
|
::setenv("GDK_BACKEND", "x11", 1);
|
|
|
|
|
|
::setenv("NO_AT_BRIDGE", "1", 1);
|
|
|
|
|
|
::setenv("GTK_A11Y", "none", 1);
|
|
|
|
|
|
::setenv("WEBKIT_DISABLE_SANDBOX_THIS_IS_DANGEROUS", "1", 1);
|
|
|
|
|
|
if (software) {
|
|
|
|
|
|
::setenv("WEBKIT_DISABLE_DMABUF_RENDERER", "1", 1);
|
|
|
|
|
|
::setenv("WEBKIT_SKIA_ENABLE_CPU_RENDERING", "1", 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
// JSC options are value-based and must not override a session setting.
|
|
|
|
|
|
if (!::getenv("JSC_useJIT")) ::setenv("JSC_useJIT", "1", 1);
|
|
|
|
|
|
if (!::getenv("JSC_useDFGJIT")) ::setenv("JSC_useDFGJIT", "1", 1);
|
|
|
|
|
|
if (!::getenv("JSC_useFTLJIT")) ::setenv("JSC_useFTLJIT", "0", 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string trimStr(const std::string& s) {
|
|
|
|
|
|
size_t b = 0;
|
|
|
|
|
|
while (b < s.size() && std::isspace(static_cast<unsigned char>(s[b]))) ++b;
|
|
|
|
|
|
size_t e = s.size();
|
|
|
|
|
|
while (e > b && std::isspace(static_cast<unsigned char>(s[e - 1]))) --e;
|
|
|
|
|
|
return s.substr(b, e - b);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string toLowerStr(std::string s) {
|
|
|
|
|
|
for (char& c : s) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
|
|
|
|
|
|
return s;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ensureParentDir(const std::string& filePath) {
|
|
|
|
|
|
size_t pos = 0;
|
|
|
|
|
|
while ((pos = filePath.find('/', pos + 1)) != std::string::npos) {
|
|
|
|
|
|
std::string dir = filePath.substr(0, pos);
|
|
|
|
|
|
if (!dir.empty()) ::mkdir(dir.c_str(), 0755);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string configDirPath() {
|
|
|
|
|
|
return getHomeDirPath() + "/.config/geminux/webarchy";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string bookmarksPath() {
|
|
|
|
|
|
return configDirPath() + "/bookmarks.tsv";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string userAgentPath() {
|
|
|
|
|
|
return configDirPath() + "/ua.txt";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string fifoRuntimePath() {
|
|
|
|
|
|
std::ostringstream oss;
|
|
|
|
|
|
oss << "/tmp/webarchy-" << static_cast<unsigned long>(::getuid()) << ".fifo";
|
|
|
|
|
|
return oss.str();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string pidRuntimePath() {
|
|
|
|
|
|
std::ostringstream oss;
|
|
|
|
|
|
oss << "/tmp/webarchy-" << static_cast<unsigned long>(::getuid()) << ".pid";
|
|
|
|
|
|
return oss.str();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct BookmarkEntry {
|
|
|
|
|
|
std::string title;
|
|
|
|
|
|
std::string url;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<BookmarkEntry> createDefaultBookmarks() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
{"DuckDuckGo Lite", kDefaultHomepage},
|
|
|
|
|
|
{"Wikipedia", "https://en.wikipedia.org/"},
|
|
|
|
|
|
{"Hacker News", "https://news.ycombinator.com/"},
|
|
|
|
|
|
{"GitHub", "https://github.com/"},
|
|
|
|
|
|
{"YouTube", "https://www.youtube.com/"},
|
|
|
|
|
|
{"Lobsters", "https://lobste.rs/"},
|
|
|
|
|
|
{"NPR Text", "https://text.npr.org/"},
|
|
|
|
|
|
{"Wttr Weather", "https://wttr.in/"},
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<BookmarkEntry> loadBookmarks() {
|
|
|
|
|
|
std::ifstream in(bookmarksPath());
|
|
|
|
|
|
if (!in.is_open()) {
|
|
|
|
|
|
return createDefaultBookmarks();
|
|
|
|
|
|
}
|
|
|
|
|
|
std::vector<BookmarkEntry> out;
|
|
|
|
|
|
std::string line;
|
|
|
|
|
|
while (std::getline(in, line)) {
|
|
|
|
|
|
if (!line.empty() && line.back() == '\r') line.pop_back();
|
|
|
|
|
|
if (line.empty()) 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 && !trimStr(cols[2]).empty()) {
|
|
|
|
|
|
out.push_back({trimStr(cols[1]), trimStr(cols[2])});
|
|
|
|
|
|
} else if (cols.size() == 2 && !trimStr(cols[1]).empty()) {
|
|
|
|
|
|
out.push_back({trimStr(cols[0]), trimStr(cols[1])});
|
|
|
|
|
|
} else if (cols.size() == 1 && !trimStr(cols[0]).empty()) {
|
|
|
|
|
|
out.push_back({trimStr(cols[0]), trimStr(cols[0])});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (out.empty()) return createDefaultBookmarks();
|
|
|
|
|
|
return out;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void saveBookmarks(const std::vector<BookmarkEntry>& bm) {
|
|
|
|
|
|
std::string path = bookmarksPath();
|
|
|
|
|
|
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 loadUserAgent() {
|
|
|
|
|
|
std::ifstream in(userAgentPath());
|
|
|
|
|
|
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 = userAgentPath();
|
|
|
|
|
|
ensureParentDir(path);
|
|
|
|
|
|
std::ofstream out(path, std::ios::trunc);
|
|
|
|
|
|
if (out.is_open()) out << ua << "\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 (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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Engine-level UserStyleSheet (bypasses site Content-Security-Policy)
|
|
|
|
|
|
constexpr const char* kWebarchyInjectedCss = R"CSS(
|
|
|
|
|
|
:root {
|
|
|
|
|
|
color-scheme: light dark;
|
|
|
|
|
|
}
|
|
|
|
|
|
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";
|
|
|
|
|
|
|
|
|
|
|
|
constexpr const char* kWebarchyInjectedJs = R"JS(
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
if (window.__webarchy) return;
|
|
|
|
|
|
const W = {
|
|
|
|
|
|
darkMode: false,
|
|
|
|
|
|
mobileFit: false,
|
|
|
|
|
|
applyVisualFlags: function() {
|
|
|
|
|
|
if (!document.documentElement) return;
|
|
|
|
|
|
document.documentElement.classList.toggle('__wa_dark__', !!this.darkMode);
|
|
|
|
|
|
document.documentElement.classList.toggle('__wa_fit__', !!this.mobileFit);
|
|
|
|
|
|
},
|
|
|
|
|
|
setFlags: function(dark, fit) {
|
|
|
|
|
|
this.darkMode = !!dark;
|
|
|
|
|
|
this.mobileFit = !!fit;
|
|
|
|
|
|
this.applyVisualFlags();
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
window.__webarchy = W;
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() { W.applyVisualFlags(); });
|
|
|
|
|
|
window.addEventListener('load', function() { W.applyVisualFlags(); });
|
|
|
|
|
|
})();
|
|
|
|
|
|
)JS";
|
|
|
|
|
|
|
|
|
|
|
|
struct UaPreset {
|
|
|
|
|
|
const char* name;
|
|
|
|
|
|
const char* ua;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const UaPreset kUaPresets[] = {
|
|
|
|
|
|
{ "Firefox Linux Desktop (Default)",
|
|
|
|
|
|
"Mozilla/5.0 (X11; Linux aarch64; rv:128.0) Gecko/20100101 Firefox/128.0" },
|
|
|
|
|
|
{ "Chromium Linux Desktop",
|
|
|
|
|
|
"Mozilla/5.0 (X11; Linux aarch64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36" },
|
|
|
|
|
|
{ "Firefox Android Mobile",
|
|
|
|
|
|
"Mozilla/5.0 (Android 14; Mobile; rv:128.0) Gecko/128.0 Firefox/128.0" },
|
|
|
|
|
|
{ "Safari iPadOS Tablet",
|
|
|
|
|
|
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Safari/605.1.15" },
|
|
|
|
|
|
{ "KaiOS 4.0 Ultra-Light",
|
|
|
|
|
|
"Mozilla/5.0 (Mobile; rv:123.0) Gecko/123.0 Firefox/123.0 KAIOS/4.0" },
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct XresTheme {
|
2026-11-25 19:01:45 +02:00
|
|
|
|
std::string name = "GeminuxHelio";
|
2026-11-23 12:46:34 +02:00
|
|
|
|
std::string fontFace = "Fira Code, Noto Sans";
|
|
|
|
|
|
std::string bgMain = "#0f1419";
|
|
|
|
|
|
std::string bgBar = "#0b0e14";
|
|
|
|
|
|
std::string bgHeader = "#131922";
|
|
|
|
|
|
std::string bgOverlay = "#161d26";
|
|
|
|
|
|
std::string bgAltEven = "#121820";
|
|
|
|
|
|
std::string bgAltOdd = "#18202a";
|
|
|
|
|
|
std::string bgInput = "#0b0e14";
|
|
|
|
|
|
std::string bgInputFocus = "#1b2838";
|
|
|
|
|
|
std::string bgButton = "#1d2633";
|
|
|
|
|
|
std::string fgMain = "#e6e1cf";
|
|
|
|
|
|
std::string fgBright = "#ffffff";
|
|
|
|
|
|
std::string fgMuted = "#7b8898";
|
|
|
|
|
|
std::string selBg = "#2b5278";
|
|
|
|
|
|
std::string selFg = "#ffffff";
|
|
|
|
|
|
std::string accent = "#59c2ff";
|
|
|
|
|
|
std::string accentAlt = "#ffb454";
|
|
|
|
|
|
std::string border = "#283444";
|
|
|
|
|
|
std::string divider = "#364559";
|
|
|
|
|
|
std::string danger = "#f07178";
|
|
|
|
|
|
std::string dangerBg = "#4c1d24";
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
XresTheme loadXresourcesTheme() {
|
|
|
|
|
|
XresTheme t;
|
|
|
|
|
|
std::string path = getHomeDirPath() + "/.Xresources";
|
|
|
|
|
|
std::ifstream in(path);
|
|
|
|
|
|
if (!in.is_open()) {
|
|
|
|
|
|
in.open("/etc/skel/.Xresources");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!in.is_open()) return t;
|
|
|
|
|
|
|
|
|
|
|
|
std::map<std::string, std::string> kv;
|
|
|
|
|
|
std::string line;
|
|
|
|
|
|
while (std::getline(in, line)) {
|
|
|
|
|
|
std::string s = trimStr(line);
|
|
|
|
|
|
if (s.empty() || s[0] == '!' || s[0] == '#') continue;
|
|
|
|
|
|
size_t colon = s.find(':');
|
|
|
|
|
|
if (colon == std::string::npos) continue;
|
|
|
|
|
|
std::string key = trimStr(s.substr(0, colon));
|
|
|
|
|
|
std::string val = trimStr(s.substr(colon + 1));
|
|
|
|
|
|
if (!key.empty() && !val.empty()) kv[key] = val;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto pick = [&](const char* k, std::string& dst) {
|
|
|
|
|
|
auto it = kv.find(k);
|
|
|
|
|
|
if (it != kv.end() && !it->second.empty()) dst = it->second;
|
|
|
|
|
|
};
|
2026-11-25 19:01:45 +02:00
|
|
|
|
pick("theme.name", t.name);
|
2026-11-23 12:46:34 +02:00
|
|
|
|
pick("theme.fontFace", t.fontFace);
|
|
|
|
|
|
pick("theme.bgMain", t.bgMain);
|
|
|
|
|
|
pick("theme.bgBar", t.bgBar);
|
|
|
|
|
|
pick("theme.bgHeader", t.bgHeader);
|
|
|
|
|
|
pick("theme.bgOverlay", t.bgOverlay);
|
|
|
|
|
|
pick("theme.bgAltEven", t.bgAltEven);
|
|
|
|
|
|
pick("theme.bgAltOdd", t.bgAltOdd);
|
|
|
|
|
|
pick("theme.bgInput", t.bgInput);
|
|
|
|
|
|
pick("theme.bgInputFocus", t.bgInputFocus);
|
|
|
|
|
|
pick("theme.bgButton", t.bgButton);
|
|
|
|
|
|
pick("theme.fgMain", t.fgMain);
|
|
|
|
|
|
pick("theme.fgBright", t.fgBright);
|
|
|
|
|
|
pick("theme.fgMuted", t.fgMuted);
|
|
|
|
|
|
pick("theme.selBg", t.selBg);
|
|
|
|
|
|
pick("theme.selFg", t.selFg);
|
|
|
|
|
|
pick("theme.accent", t.accent);
|
|
|
|
|
|
pick("theme.accentAlt", t.accentAlt);
|
|
|
|
|
|
pick("theme.border", t.border);
|
|
|
|
|
|
pick("theme.divider", t.divider);
|
|
|
|
|
|
pick("theme.danger", t.danger);
|
|
|
|
|
|
pick("theme.dangerBg", t.dangerBg);
|
|
|
|
|
|
return t;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct BrowserApp;
|
|
|
|
|
|
|
|
|
|
|
|
struct TabEntry {
|
|
|
|
|
|
int id = 0;
|
|
|
|
|
|
BrowserApp* app = nullptr;
|
|
|
|
|
|
WebKitWebView* webView = nullptr;
|
|
|
|
|
|
std::string stackName;
|
|
|
|
|
|
std::string url = kDefaultHomepage;
|
|
|
|
|
|
std::string title = "New Tab";
|
|
|
|
|
|
double progress = 1.0;
|
|
|
|
|
|
bool loading = false;
|
|
|
|
|
|
bool playingAudio = false;
|
|
|
|
|
|
bool darkMode = false;
|
|
|
|
|
|
bool mobileFit = false;
|
|
|
|
|
|
|
|
|
|
|
|
// Widgets in right-side vertical tab bar
|
|
|
|
|
|
GtkWidget* rowBox = nullptr;
|
|
|
|
|
|
GtkWidget* activateBtn = nullptr;
|
|
|
|
|
|
GtkWidget* idxLabel = nullptr;
|
|
|
|
|
|
GtkWidget* titleLabel = nullptr;
|
|
|
|
|
|
GtkWidget* domainLabel = nullptr;
|
|
|
|
|
|
GtkWidget* closeBtn = nullptr;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct BrowserApp {
|
|
|
|
|
|
GtkWidget* window = nullptr;
|
|
|
|
|
|
GtkCssProvider* cssProvider = nullptr;
|
|
|
|
|
|
|
|
|
|
|
|
WebKitWebContext* webCtx = nullptr;
|
|
|
|
|
|
WebKitUserContentManager* ucm = nullptr;
|
|
|
|
|
|
WebKitSettings* wkSettings = nullptr;
|
|
|
|
|
|
WebKitWebsitePolicies* wkPolicies = nullptr;
|
|
|
|
|
|
|
|
|
|
|
|
GtkWidget* backBtn = nullptr;
|
|
|
|
|
|
GtkWidget* fwdBtn = nullptr;
|
|
|
|
|
|
GtkWidget* reloadBtn = nullptr;
|
|
|
|
|
|
GtkWidget* homeBtn = nullptr;
|
|
|
|
|
|
GtkEntry* urlEntry = nullptr;
|
|
|
|
|
|
GtkWidget* bookmarkBtn = nullptr;
|
|
|
|
|
|
GtkWidget* menuBtn = nullptr;
|
|
|
|
|
|
GtkWidget* toggleTabsBtn = nullptr;
|
|
|
|
|
|
GtkProgressBar* progressBar = nullptr;
|
|
|
|
|
|
|
|
|
|
|
|
GtkRevealer* findRevealer = nullptr;
|
|
|
|
|
|
GtkEntry* findEntry = nullptr;
|
|
|
|
|
|
GtkLabel* findCountLabel = nullptr;
|
|
|
|
|
|
|
|
|
|
|
|
GtkStack* webStack = nullptr;
|
|
|
|
|
|
GtkLabel* statusLabel = nullptr;
|
|
|
|
|
|
GtkLabel* modeBadgeLabel = nullptr;
|
|
|
|
|
|
|
|
|
|
|
|
// Right-side vertical tab bar (tailored for 2160x1080 ultrawide)
|
|
|
|
|
|
GtkWidget* tabSidebar = nullptr;
|
|
|
|
|
|
GtkLabel* tabHeaderLabel = nullptr;
|
|
|
|
|
|
GtkWidget* tabListBox = nullptr;
|
|
|
|
|
|
GtkWidget* tabDarkBtn = nullptr;
|
|
|
|
|
|
GtkLabel* zoomLabel = nullptr;
|
|
|
|
|
|
|
|
|
|
|
|
// Menu popover widgets
|
|
|
|
|
|
GtkWidget* toolsPopover = nullptr;
|
|
|
|
|
|
GtkWidget* bookmarksPopover = nullptr;
|
|
|
|
|
|
GtkWidget* bookmarksListBox = nullptr;
|
|
|
|
|
|
GtkWidget* darkCheckBtn = nullptr;
|
|
|
|
|
|
GtkWidget* fitCheckBtn = nullptr;
|
|
|
|
|
|
GtkWidget* swCheckBtn = nullptr;
|
|
|
|
|
|
GtkWidget* uaCombo = nullptr;
|
|
|
|
|
|
|
|
|
|
|
|
bool softwareRenderer = false;
|
|
|
|
|
|
bool tabBarVisible = true;
|
|
|
|
|
|
bool fullscreen = false;
|
|
|
|
|
|
int nextTabId = 1;
|
|
|
|
|
|
int activeTabIndex = -1;
|
|
|
|
|
|
int fifoFd = -1;
|
|
|
|
|
|
guint fifoWatchId = 0;
|
|
|
|
|
|
|
|
|
|
|
|
std::string userAgent = kDefaultUserAgent;
|
|
|
|
|
|
std::string statusMsg = "Ready";
|
|
|
|
|
|
std::string hoveredUri;
|
|
|
|
|
|
std::vector<BookmarkEntry> bookmarks;
|
|
|
|
|
|
std::vector<std::unique_ptr<TabEntry>> tabs;
|
|
|
|
|
|
std::vector<std::string> closedTabUrls;
|
|
|
|
|
|
bool syncingUiFlags = false;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-11-25 19:01:45 +02:00
|
|
|
|
bool isDarkHexColor(const std::string& hex) {
|
|
|
|
|
|
if (hex.size() != 7 || hex[0] != '#') return true;
|
|
|
|
|
|
auto hexByte = [&](size_t pos, int& out) -> bool {
|
|
|
|
|
|
auto nib = [](char c) -> int {
|
|
|
|
|
|
if (c >= '0' && c <= '9') return c - '0';
|
|
|
|
|
|
if (c >= 'a' && c <= 'f') return 10 + (c - 'a');
|
|
|
|
|
|
if (c >= 'A' && c <= 'F') return 10 + (c - 'A');
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
};
|
|
|
|
|
|
int hi = nib(hex[pos]);
|
|
|
|
|
|
int lo = nib(hex[pos + 1]);
|
|
|
|
|
|
if (hi < 0 || lo < 0) return false;
|
|
|
|
|
|
out = (hi << 4) | lo;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
};
|
|
|
|
|
|
int r = 0, g = 0, b = 0;
|
|
|
|
|
|
if (!hexByte(1, r) || !hexByte(3, g) || !hexByte(5, b)) return true;
|
|
|
|
|
|
double lum = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
|
|
|
|
return lum < 128.0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string sanitizeGtkThemeSuffix(const std::string& raw) {
|
|
|
|
|
|
std::string out;
|
|
|
|
|
|
for (unsigned char ch : raw) {
|
|
|
|
|
|
if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') ||
|
|
|
|
|
|
(ch >= '0' && ch <= '9') || ch == '.' || ch == '_' || ch == '-') {
|
|
|
|
|
|
out.push_back(static_cast<char>(ch));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return out.empty() ? "GeminuxHelio" : out;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-23 12:46:34 +02:00
|
|
|
|
void applyGtkThemeCss(BrowserApp* app) {
|
|
|
|
|
|
if (!app || !app->cssProvider) return;
|
|
|
|
|
|
XresTheme t = loadXresourcesTheme();
|
|
|
|
|
|
std::string gtkFont = t.fontFace + ", Noto Sans 9";
|
2026-11-25 19:01:45 +02:00
|
|
|
|
bool preferDark = isDarkHexColor(t.bgMain);
|
|
|
|
|
|
std::string candidateTheme = "Geminux-" + sanitizeGtkThemeSuffix(t.name);
|
|
|
|
|
|
std::string homeThemeCss = getHomeDirPath() + "/.themes/" + candidateTheme + "/gtk-3.0/gtk.css";
|
|
|
|
|
|
std::string sysThemeCss = "/usr/share/themes/" + candidateTheme + "/gtk-3.0/gtk.css";
|
|
|
|
|
|
std::string gtkThemeName =
|
|
|
|
|
|
(::access(homeThemeCss.c_str(), R_OK) == 0 || ::access(sysThemeCss.c_str(), R_OK) == 0)
|
|
|
|
|
|
? candidateTheme
|
|
|
|
|
|
: "Adwaita";
|
2026-11-23 12:46:34 +02:00
|
|
|
|
if (GtkSettings* gs = gtk_settings_get_default()) {
|
|
|
|
|
|
g_object_set(gs,
|
2026-11-25 19:01:45 +02:00
|
|
|
|
"gtk-application-prefer-dark-theme", preferDark ? TRUE : FALSE,
|
|
|
|
|
|
"gtk-theme-name", gtkThemeName.c_str(),
|
2026-11-23 12:46:34 +02:00
|
|
|
|
"gtk-font-name", gtkFont.c_str(),
|
|
|
|
|
|
nullptr);
|
|
|
|
|
|
}
|
|
|
|
|
|
std::ostringstream css;
|
|
|
|
|
|
css << "* { font-family: \"" << t.fontFace << "\", \"Noto Sans\", sans-serif; }\n"
|
|
|
|
|
|
<< "window, #wa-root, #wa-main-pane { background-color: " << t.bgMain << "; color: " << t.fgMain << "; }\n"
|
|
|
|
|
|
<< "#wa-navbar { background-color: " << t.bgBar << "; border-bottom: 1px solid " << t.border
|
|
|
|
|
|
<< "; padding: 5px 8px; }\n"
|
|
|
|
|
|
<< "#wa-navbar button, #wa-tabbar button, #wa-findbar button { "
|
|
|
|
|
|
<< "background-image: none; background-color: " << t.bgButton << "; color: " << t.fgBright
|
|
|
|
|
|
<< "; border: 1px solid " << t.border << "; border-radius: 5px; box-shadow: none; "
|
|
|
|
|
|
<< "padding: 4px 9px; font-size: 9pt; min-height: 32px; min-width: 32px; }\n"
|
|
|
|
|
|
<< "#wa-navbar button:hover, #wa-tabbar button:hover, #wa-findbar button:hover { "
|
|
|
|
|
|
<< "background-color: " << t.bgInputFocus << "; border-color: " << t.accent << "; }\n"
|
|
|
|
|
|
<< "#wa-navbar button:disabled { color: " << t.fgMuted << "; background-color: " << t.bgBar << "; }\n"
|
|
|
|
|
|
<< "#wa-navbar button.active-accent, #wa-tabbar button.active-accent { "
|
|
|
|
|
|
<< "background-color: " << t.selBg << "; color: " << t.selFg << "; border-color: " << t.accent << "; }\n"
|
|
|
|
|
|
<< "#wa-urlbar, #wa-findbar entry { background-image: none; background-color: " << t.bgInput
|
|
|
|
|
|
<< "; color: " << t.fgBright << "; border: 1px solid " << t.border << "; border-radius: 5px; "
|
|
|
|
|
|
<< "padding: 4px 10px; font-size: 9pt; min-height: 32px; caret-color: " << t.accent << "; }\n"
|
|
|
|
|
|
<< "#wa-urlbar:focus, #wa-findbar entry:focus { background-color: " << t.bgInputFocus
|
|
|
|
|
|
<< "; border-color: " << t.accent << "; }\n"
|
|
|
|
|
|
<< "#wa-progress progressbar, #wa-progress { min-height: 2px; background-color: " << t.bgBar << "; border: none; }\n"
|
|
|
|
|
|
<< "#wa-progress trough { min-height: 2px; background-color: " << t.bgBar << "; border: none; }\n"
|
|
|
|
|
|
<< "#wa-progress progress { min-height: 2px; background-color: " << t.accent << "; }\n"
|
|
|
|
|
|
<< "#wa-findbar { background-color: " << t.bgHeader << "; border-bottom: 1px solid " << t.border
|
|
|
|
|
|
<< "; padding: 4px 8px; }\n"
|
|
|
|
|
|
<< "#wa-tabbar { background-color: " << t.bgBar << "; border-left: 1px solid " << t.border << "; }\n"
|
|
|
|
|
|
<< "#wa-tabbar-header { background-color: " << t.bgHeader << "; border-bottom: 1px solid " << t.border
|
|
|
|
|
|
<< "; padding: 6px 8px; }\n"
|
|
|
|
|
|
<< "#wa-tabbar-header label { font-size: 8.5pt; font-weight: bold; color: " << t.accent << "; }\n"
|
|
|
|
|
|
<< "#wa-newtab-btn { background-color: " << t.selBg << "; color: " << t.selFg
|
|
|
|
|
|
<< "; border-color: " << t.accent << "; font-weight: bold; font-size: 8.5pt; padding: 4px 9px; min-height: 28px; }\n"
|
|
|
|
|
|
<< "#wa-tablist { padding: 5px; background-color: " << t.bgBar << "; }\n"
|
|
|
|
|
|
<< ".wa-tab-row { background-color: " << t.bgAltEven << "; border: 1px solid " << t.border
|
|
|
|
|
|
<< "; border-radius: 6px; margin-bottom: 4px; }\n"
|
|
|
|
|
|
<< ".wa-tab-row.active { background-color: " << t.selBg << "; border: 1px solid " << t.accent << "; }\n"
|
|
|
|
|
|
<< ".wa-tab-btn { background: transparent; border: none; box-shadow: none; padding: 5px 6px; min-height: 38px; }\n"
|
|
|
|
|
|
<< ".wa-tab-btn:hover { background-color: rgba(255,255,255,0.05); border-color: transparent; }\n"
|
|
|
|
|
|
<< ".wa-tab-idx { font-size: 8.5pt; font-weight: bold; color: " << t.accentAlt << "; min-width: 20px; }\n"
|
|
|
|
|
|
<< ".wa-tab-row.active .wa-tab-idx { color: " << t.selFg << "; }\n"
|
|
|
|
|
|
<< ".wa-tab-title { font-size: 8.5pt; color: " << t.fgMain << "; }\n"
|
|
|
|
|
|
<< ".wa-tab-row.active .wa-tab-title { font-weight: bold; color: " << t.selFg << "; }\n"
|
|
|
|
|
|
<< ".wa-tab-domain { font-size: 7.2pt; color: " << t.fgMuted << "; }\n"
|
|
|
|
|
|
<< ".wa-tab-row.active .wa-tab-domain { color: " << t.fgBright << "; }\n"
|
|
|
|
|
|
<< ".wa-tab-close { background: transparent; border: none; color: " << t.fgMuted
|
|
|
|
|
|
<< "; padding: 3px 7px; min-width: 28px; min-height: 28px; font-size: 9pt; }\n"
|
|
|
|
|
|
<< ".wa-tab-close:hover { background-color: " << t.dangerBg << "; color: " << t.danger << "; }\n"
|
|
|
|
|
|
<< "#wa-tabbar-footer { background-color: " << t.bgHeader << "; border-top: 1px solid " << t.border
|
|
|
|
|
|
<< "; padding: 5px 8px; }\n"
|
|
|
|
|
|
<< "#wa-tabbar-footer button { font-size: 8.5pt; padding: 3px 8px; min-height: 28px; min-width: 28px; }\n"
|
|
|
|
|
|
<< "#wa-tabbar-footer label { font-size: 8.5pt; font-weight: bold; color: " << t.fgBright << "; }\n"
|
|
|
|
|
|
<< "#wa-statusbar { background-color: " << t.bgBar << "; border-top: 1px solid " << t.border
|
|
|
|
|
|
<< "; padding: 3px 8px; }\n"
|
|
|
|
|
|
<< "#wa-statusbar label { font-size: 7.5pt; color: " << t.fgMuted << "; }\n"
|
|
|
|
|
|
<< "popover, popover box { background-color: " << t.bgOverlay << "; color: " << t.fgMain
|
|
|
|
|
|
<< "; border: 1px solid " << t.border << "; }\n"
|
|
|
|
|
|
<< "popover checkbutton, popover label, popover button, combobox, menu, menuitem { "
|
|
|
|
|
|
<< "color: " << t.fgMain << "; font-size: 8.5pt; }\n";
|
|
|
|
|
|
|
|
|
|
|
|
gtk_css_provider_load_from_data(app->cssProvider, css.str().c_str(), -1, nullptr);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TabEntry* currentTab(BrowserApp* app) {
|
|
|
|
|
|
if (!app || app->activeTabIndex < 0 ||
|
|
|
|
|
|
app->activeTabIndex >= static_cast<int>(app->tabs.size())) {
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
return app->tabs[app->activeTabIndex].get();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int findBookmarkIndex(const BrowserApp* app, const std::string& url) {
|
|
|
|
|
|
if (!app || url.empty()) return -1;
|
|
|
|
|
|
for (size_t i = 0; i < app->bookmarks.size(); ++i) {
|
|
|
|
|
|
if (app->bookmarks[i].url == url) return static_cast<int>(i);
|
|
|
|
|
|
}
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void evalJsOnTab(TabEntry* tab, const std::string& code) {
|
|
|
|
|
|
if (!tab || !tab->webView) return;
|
|
|
|
|
|
webkit_web_view_evaluate_javascript(tab->webView, code.c_str(), -1,
|
|
|
|
|
|
nullptr, nullptr, nullptr, nullptr, nullptr);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void syncJsFlags(TabEntry* tab) {
|
|
|
|
|
|
if (!tab) return;
|
|
|
|
|
|
std::ostringstream oss;
|
|
|
|
|
|
oss << "if(window.__webarchy)window.__webarchy.setFlags("
|
|
|
|
|
|
<< (tab->darkMode ? "true" : "false") << ","
|
|
|
|
|
|
<< (tab->mobileFit ? "true" : "false") << ");";
|
|
|
|
|
|
evalJsOnTab(tab, oss.str());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void updateTabRowVisual(TabEntry* tab, int index, bool active) {
|
|
|
|
|
|
if (!tab || !tab->rowBox) return;
|
|
|
|
|
|
GtkStyleContext* ctx = gtk_widget_get_style_context(tab->rowBox);
|
|
|
|
|
|
if (active) gtk_style_context_add_class(ctx, "active");
|
|
|
|
|
|
else gtk_style_context_remove_class(ctx, "active");
|
|
|
|
|
|
|
|
|
|
|
|
std::string badge;
|
|
|
|
|
|
if (tab->loading) badge = "◌";
|
|
|
|
|
|
else if (tab->playingAudio) badge = "♪";
|
|
|
|
|
|
else if (index < 9) badge = std::to_string(index + 1);
|
|
|
|
|
|
else badge = "•";
|
|
|
|
|
|
gtk_label_set_text(GTK_LABEL(tab->idxLabel), badge.c_str());
|
|
|
|
|
|
|
|
|
|
|
|
std::string title = tab->title.empty() ? extractHostFromUrl(tab->url) : tab->title;
|
|
|
|
|
|
gtk_label_set_text(GTK_LABEL(tab->titleLabel), title.c_str());
|
|
|
|
|
|
|
|
|
|
|
|
std::string host = extractHostFromUrl(tab->url);
|
|
|
|
|
|
gtk_label_set_text(GTK_LABEL(tab->domainLabel), host.c_str());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void refreshBookmarksPopover(BrowserApp* app);
|
|
|
|
|
|
|
|
|
|
|
|
void refreshChromeUi(BrowserApp* app) {
|
|
|
|
|
|
if (!app) return;
|
|
|
|
|
|
TabEntry* tab = currentTab(app);
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < app->tabs.size(); ++i) {
|
|
|
|
|
|
updateTabRowVisual(app->tabs[i].get(), static_cast<int>(i),
|
|
|
|
|
|
static_cast<int>(i) == app->activeTabIndex);
|
|
|
|
|
|
}
|
|
|
|
|
|
std::string tabHdr = "TABS (" + std::to_string(app->tabs.size()) + ")";
|
|
|
|
|
|
if (app->tabHeaderLabel) gtk_label_set_text(app->tabHeaderLabel, tabHdr.c_str());
|
|
|
|
|
|
|
|
|
|
|
|
if (!tab) return;
|
|
|
|
|
|
|
|
|
|
|
|
if (!gtk_widget_has_focus(GTK_WIDGET(app->urlEntry))) {
|
|
|
|
|
|
gtk_entry_set_text(app->urlEntry, tab->url.c_str());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive(app->backBtn, webkit_web_view_can_go_back(tab->webView));
|
|
|
|
|
|
gtk_widget_set_sensitive(app->fwdBtn, webkit_web_view_can_go_forward(tab->webView));
|
|
|
|
|
|
gtk_button_set_label(GTK_BUTTON(app->reloadBtn), tab->loading ? "✕" : "↻");
|
|
|
|
|
|
|
|
|
|
|
|
bool bookmarked = findBookmarkIndex(app, tab->url) >= 0;
|
|
|
|
|
|
gtk_button_set_label(GTK_BUTTON(app->bookmarkBtn), bookmarked ? "★" : "☆");
|
|
|
|
|
|
GtkStyleContext* bmCtx = gtk_widget_get_style_context(app->bookmarkBtn);
|
|
|
|
|
|
if (bookmarked) gtk_style_context_add_class(bmCtx, "active-accent");
|
|
|
|
|
|
else gtk_style_context_remove_class(bmCtx, "active-accent");
|
|
|
|
|
|
|
|
|
|
|
|
if (tab->loading && tab->progress < 0.99) {
|
|
|
|
|
|
gtk_progress_bar_set_fraction(app->progressBar, std::clamp(tab->progress, 0.05, 0.98));
|
|
|
|
|
|
gtk_widget_show(GTK_WIDGET(app->progressBar));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
gtk_widget_hide(GTK_WIDGET(app->progressBar));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string stLine = !app->hoveredUri.empty()
|
|
|
|
|
|
? ("Link: " + app->hoveredUri)
|
|
|
|
|
|
: app->statusMsg;
|
|
|
|
|
|
gtk_label_set_text(app->statusLabel, stLine.c_str());
|
|
|
|
|
|
|
|
|
|
|
|
int zoomPct = static_cast<int>(std::round(webkit_web_view_get_zoom_level(tab->webView) * 100.0));
|
|
|
|
|
|
std::string badge = std::string(app->softwareRenderer ? "SW" : "GPU") +
|
|
|
|
|
|
(tab->darkMode ? " • DARK" : "") +
|
|
|
|
|
|
(tab->mobileFit ? " • FIT" : "") +
|
|
|
|
|
|
" • " + std::to_string(zoomPct) + "%";
|
|
|
|
|
|
gtk_label_set_text(app->modeBadgeLabel, badge.c_str());
|
|
|
|
|
|
|
|
|
|
|
|
if (app->zoomLabel) {
|
|
|
|
|
|
std::string zTxt = std::to_string(zoomPct) + "%";
|
|
|
|
|
|
gtk_label_set_text(app->zoomLabel, zTxt.c_str());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (app->tabDarkBtn) {
|
|
|
|
|
|
GtkStyleContext* dc = gtk_widget_get_style_context(app->tabDarkBtn);
|
|
|
|
|
|
if (tab->darkMode) gtk_style_context_add_class(dc, "active-accent");
|
|
|
|
|
|
else gtk_style_context_remove_class(dc, "active-accent");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
app->syncingUiFlags = true;
|
|
|
|
|
|
if (app->darkCheckBtn)
|
|
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(app->darkCheckBtn), tab->darkMode);
|
|
|
|
|
|
if (app->fitCheckBtn)
|
|
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(app->fitCheckBtn), tab->mobileFit);
|
|
|
|
|
|
if (app->swCheckBtn)
|
|
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(app->swCheckBtn), app->softwareRenderer);
|
|
|
|
|
|
app->syncingUiFlags = false;
|
|
|
|
|
|
|
|
|
|
|
|
std::string winTitle =
|
|
|
|
|
|
(tab->title.empty() ? extractHostFromUrl(tab->url) : tab->title) + " — Webarchy";
|
|
|
|
|
|
gtk_window_set_title(GTK_WINDOW(app->window), winTitle.c_str());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void selectTab(BrowserApp* app, int index) {
|
|
|
|
|
|
if (!app || app->tabs.empty()) return;
|
|
|
|
|
|
index = std::clamp(index, 0, static_cast<int>(app->tabs.size()) - 1);
|
|
|
|
|
|
app->activeTabIndex = index;
|
|
|
|
|
|
TabEntry* tab = app->tabs[index].get();
|
|
|
|
|
|
gtk_stack_set_visible_child_name(app->webStack, tab->stackName.c_str());
|
|
|
|
|
|
app->hoveredUri.clear();
|
|
|
|
|
|
app->statusMsg = tab->loading ? ("Loading " + extractHostFromUrl(tab->url) + "...") : tab->url;
|
|
|
|
|
|
refreshChromeUi(app);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int indexOfTab(BrowserApp* app, TabEntry* target) {
|
|
|
|
|
|
if (!app || !target) return -1;
|
|
|
|
|
|
for (size_t i = 0; i < app->tabs.size(); ++i) {
|
|
|
|
|
|
if (app->tabs[i].get() == target) return static_cast<int>(i);
|
|
|
|
|
|
}
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void closeTabAt(BrowserApp* app, int index) {
|
|
|
|
|
|
if (!app || index < 0 || index >= static_cast<int>(app->tabs.size())) return;
|
|
|
|
|
|
if (app->tabs.size() == 1) {
|
|
|
|
|
|
TabEntry* sole = app->tabs[0].get();
|
|
|
|
|
|
if (!sole->url.empty() && sole->url != kDefaultHomepage) {
|
|
|
|
|
|
app->closedTabUrls.push_back(sole->url);
|
|
|
|
|
|
if (app->closedTabUrls.size() > 16) app->closedTabUrls.erase(app->closedTabUrls.begin());
|
|
|
|
|
|
}
|
|
|
|
|
|
webkit_web_view_load_uri(sole->webView, kDefaultHomepage);
|
|
|
|
|
|
refreshChromeUi(app);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TabEntry* doomed = app->tabs[index].get();
|
|
|
|
|
|
if (!doomed->url.empty()) {
|
|
|
|
|
|
app->closedTabUrls.push_back(doomed->url);
|
|
|
|
|
|
if (app->closedTabUrls.size() > 16) app->closedTabUrls.erase(app->closedTabUrls.begin());
|
|
|
|
|
|
}
|
|
|
|
|
|
gtk_container_remove(GTK_CONTAINER(app->tabListBox), doomed->rowBox);
|
|
|
|
|
|
gtk_container_remove(GTK_CONTAINER(app->webStack), GTK_WIDGET(doomed->webView));
|
|
|
|
|
|
app->tabs.erase(app->tabs.begin() + index);
|
|
|
|
|
|
|
|
|
|
|
|
int nextIdx = app->activeTabIndex;
|
|
|
|
|
|
if (index < nextIdx) --nextIdx;
|
|
|
|
|
|
nextIdx = std::clamp(nextIdx, 0, static_cast<int>(app->tabs.size()) - 1);
|
|
|
|
|
|
selectTab(app, nextIdx);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TabEntry* createTab(BrowserApp* app, const std::string& initialUrl, bool switchTo,
|
|
|
|
|
|
WebKitWebView* relatedTo = nullptr);
|
|
|
|
|
|
|
|
|
|
|
|
void onLoadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent, gpointer ud) {
|
|
|
|
|
|
auto* tab = static_cast<TabEntry*>(ud);
|
|
|
|
|
|
if (!tab || !tab->app) return;
|
|
|
|
|
|
const char* uri = webkit_web_view_get_uri(webView);
|
|
|
|
|
|
if (uri && uri[0]) tab->url = uri;
|
|
|
|
|
|
const char* title = webkit_web_view_get_title(webView);
|
|
|
|
|
|
if (title && title[0]) tab->title = title;
|
|
|
|
|
|
else tab->title = extractHostFromUrl(tab->url);
|
|
|
|
|
|
|
|
|
|
|
|
if (loadEvent == WEBKIT_LOAD_STARTED || loadEvent == WEBKIT_LOAD_REDIRECTED) {
|
|
|
|
|
|
tab->loading = true;
|
|
|
|
|
|
tab->progress = 0.08;
|
|
|
|
|
|
if (tab == currentTab(tab->app)) {
|
|
|
|
|
|
tab->app->statusMsg = "Loading " + extractHostFromUrl(tab->url) + "...";
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (loadEvent == WEBKIT_LOAD_COMMITTED) {
|
|
|
|
|
|
tab->loading = true;
|
|
|
|
|
|
syncJsFlags(tab);
|
|
|
|
|
|
} else if (loadEvent == WEBKIT_LOAD_FINISHED) {
|
|
|
|
|
|
tab->loading = false;
|
|
|
|
|
|
tab->progress = 1.0;
|
|
|
|
|
|
syncJsFlags(tab);
|
|
|
|
|
|
if (tab == currentTab(tab->app)) {
|
|
|
|
|
|
tab->app->statusMsg = tab->url;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
refreshChromeUi(tab->app);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onNotifyWebViewProp(GObject* obj, GParamSpec*, gpointer ud) {
|
|
|
|
|
|
auto* tab = static_cast<TabEntry*>(ud);
|
|
|
|
|
|
auto* wv = WEBKIT_WEB_VIEW(obj);
|
|
|
|
|
|
if (!tab || !tab->app || !wv) return;
|
|
|
|
|
|
const char* uri = webkit_web_view_get_uri(wv);
|
|
|
|
|
|
if (uri && uri[0]) tab->url = uri;
|
|
|
|
|
|
const char* title = webkit_web_view_get_title(wv);
|
|
|
|
|
|
if (title && title[0]) tab->title = title;
|
|
|
|
|
|
else tab->title = extractHostFromUrl(tab->url);
|
|
|
|
|
|
tab->progress = webkit_web_view_get_estimated_load_progress(wv);
|
|
|
|
|
|
tab->playingAudio = webkit_web_view_is_playing_audio(wv);
|
|
|
|
|
|
refreshChromeUi(tab->app);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onMouseTargetChanged(WebKitWebView*, WebKitHitTestResult* hit, guint, gpointer ud) {
|
|
|
|
|
|
auto* tab = static_cast<TabEntry*>(ud);
|
|
|
|
|
|
if (!tab || !tab->app || tab != currentTab(tab->app)) return;
|
|
|
|
|
|
if (hit && webkit_hit_test_result_context_is_link(hit)) {
|
|
|
|
|
|
const char* link = webkit_hit_test_result_get_link_uri(hit);
|
|
|
|
|
|
tab->app->hoveredUri = (link && link[0]) ? link : "";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
tab->app->hoveredUri.clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
refreshChromeUi(tab->app);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean onDecidePolicy(WebKitWebView*,
|
|
|
|
|
|
WebKitPolicyDecision* decision,
|
|
|
|
|
|
WebKitPolicyDecisionType type,
|
|
|
|
|
|
gpointer ud) {
|
|
|
|
|
|
auto* tab = static_cast<TabEntry*>(ud);
|
|
|
|
|
|
if (!tab || !tab->app) return FALSE;
|
|
|
|
|
|
|
|
|
|
|
|
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]) {
|
|
|
|
|
|
createTab(tab->app, uri, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
webkit_policy_decision_ignore(decision);
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (type == WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION) {
|
|
|
|
|
|
auto* navDec = WEBKIT_NAVIGATION_POLICY_DECISION(decision);
|
|
|
|
|
|
WebKitNavigationAction* action =
|
|
|
|
|
|
webkit_navigation_policy_decision_get_navigation_action(navDec);
|
|
|
|
|
|
WebKitNavigationType navType = webkit_navigation_action_get_navigation_type(action);
|
|
|
|
|
|
guint btn = webkit_navigation_action_get_mouse_button(action);
|
|
|
|
|
|
guint mods = webkit_navigation_action_get_modifiers(action);
|
|
|
|
|
|
if (navType == WEBKIT_NAVIGATION_TYPE_LINK_CLICKED &&
|
|
|
|
|
|
(btn == 2 || (mods & GDK_CONTROL_MASK) != 0)) {
|
|
|
|
|
|
WebKitURIRequest* req = webkit_navigation_action_get_request(action);
|
|
|
|
|
|
const char* uri = req ? webkit_uri_request_get_uri(req) : nullptr;
|
|
|
|
|
|
if (uri && uri[0]) {
|
|
|
|
|
|
createTab(tab->app, uri, (mods & GDK_SHIFT_MASK) == 0);
|
|
|
|
|
|
webkit_policy_decision_ignore(decision);
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GtkWidget* onCreatePopupWebView(WebKitWebView* parentWv,
|
|
|
|
|
|
WebKitNavigationAction* action,
|
|
|
|
|
|
gpointer ud) {
|
|
|
|
|
|
auto* tab = static_cast<TabEntry*>(ud);
|
|
|
|
|
|
if (!tab || !tab->app) return nullptr;
|
|
|
|
|
|
WebKitURIRequest* req = action ? webkit_navigation_action_get_request(action) : nullptr;
|
|
|
|
|
|
const char* uri = req ? webkit_uri_request_get_uri(req) : nullptr;
|
|
|
|
|
|
if (uri && uri[0] && std::strcmp(uri, "about:blank") != 0) {
|
|
|
|
|
|
createTab(tab->app, uri, true);
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
TabEntry* child = createTab(tab->app, "", true, parentWv);
|
|
|
|
|
|
return child ? GTK_WIDGET(child->webView) : nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean onPermissionRequest(WebKitWebView*, WebKitPermissionRequest* req, gpointer) {
|
|
|
|
|
|
webkit_permission_request_allow(req);
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean onLoadFailed(WebKitWebView*, WebKitLoadEvent, gchar* failingUri, GError* error, gpointer ud) {
|
|
|
|
|
|
auto* tab = static_cast<TabEntry*>(ud);
|
|
|
|
|
|
if (!tab || !tab->app) return FALSE;
|
|
|
|
|
|
tab->loading = false;
|
|
|
|
|
|
tab->progress = 1.0;
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
std::ostringstream oss;
|
|
|
|
|
|
oss << "Load failed: " << (error->message ? error->message : "WebKit error");
|
|
|
|
|
|
if (error->domain)
|
|
|
|
|
|
oss << " [" << g_quark_to_string(error->domain) << "/" << error->code << "]";
|
|
|
|
|
|
if (tab->app->softwareRenderer) oss << " (SW)";
|
|
|
|
|
|
tab->app->statusMsg = oss.str();
|
|
|
|
|
|
} else if (failingUri) {
|
|
|
|
|
|
tab->app->statusMsg = std::string("Failed: ") + failingUri;
|
|
|
|
|
|
}
|
|
|
|
|
|
refreshChromeUi(tab->app);
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean onWebProcessTerminated(WebKitWebView*,
|
|
|
|
|
|
WebKitWebProcessTerminationReason reason,
|
|
|
|
|
|
gpointer ud) {
|
|
|
|
|
|
auto* tab = static_cast<TabEntry*>(ud);
|
|
|
|
|
|
if (!tab || !tab->app) return TRUE;
|
|
|
|
|
|
BrowserApp* app = tab->app;
|
|
|
|
|
|
tab->loading = false;
|
|
|
|
|
|
tab->progress = 1.0;
|
|
|
|
|
|
if (!app->softwareRenderer && app->wkSettings &&
|
|
|
|
|
|
reason == WEBKIT_WEB_PROCESS_CRASHED) {
|
|
|
|
|
|
app->softwareRenderer = true;
|
|
|
|
|
|
configureWebkitRenderer(true);
|
|
|
|
|
|
webkit_settings_set_hardware_acceleration_policy(
|
|
|
|
|
|
app->wkSettings, WEBKIT_HARDWARE_ACCELERATION_POLICY_NEVER);
|
|
|
|
|
|
app->statusMsg = "GPU renderer crashed; switched to software rendering";
|
|
|
|
|
|
if (!tab->url.empty()) {
|
|
|
|
|
|
webkit_web_view_load_uri(tab->webView, tab->url.c_str());
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
app->statusMsg = "Web process restarted";
|
|
|
|
|
|
}
|
|
|
|
|
|
refreshChromeUi(app);
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean onTabButtonPress(GtkWidget*, GdkEventButton* ev, gpointer ud) {
|
|
|
|
|
|
auto* tab = static_cast<TabEntry*>(ud);
|
|
|
|
|
|
if (!tab || !tab->app) return FALSE;
|
|
|
|
|
|
int idx = indexOfTab(tab->app, tab);
|
|
|
|
|
|
if (idx < 0) return FALSE;
|
|
|
|
|
|
if (ev->type == GDK_BUTTON_PRESS && ev->button == 2) {
|
|
|
|
|
|
closeTabAt(tab->app, idx);
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onTabActivateClicked(GtkButton*, gpointer ud) {
|
|
|
|
|
|
auto* tab = static_cast<TabEntry*>(ud);
|
|
|
|
|
|
if (!tab || !tab->app) return;
|
|
|
|
|
|
int idx = indexOfTab(tab->app, tab);
|
|
|
|
|
|
if (idx >= 0) selectTab(tab->app, idx);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onTabCloseClicked(GtkButton*, gpointer ud) {
|
|
|
|
|
|
auto* tab = static_cast<TabEntry*>(ud);
|
|
|
|
|
|
if (!tab || !tab->app) return;
|
|
|
|
|
|
int idx = indexOfTab(tab->app, tab);
|
|
|
|
|
|
if (idx >= 0) closeTabAt(tab->app, idx);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TabEntry* createTab(BrowserApp* app, const std::string& initialUrl, bool switchTo,
|
|
|
|
|
|
WebKitWebView* relatedTo) {
|
|
|
|
|
|
auto tab = std::make_unique<TabEntry>();
|
|
|
|
|
|
tab->id = app->nextTabId++;
|
|
|
|
|
|
tab->app = app;
|
|
|
|
|
|
tab->stackName = "tab-" + std::to_string(tab->id);
|
|
|
|
|
|
tab->url = initialUrl.empty() ? kDefaultHomepage : initialUrl;
|
|
|
|
|
|
|
|
|
|
|
|
if (relatedTo) {
|
|
|
|
|
|
tab->webView = WEBKIT_WEB_VIEW(g_object_new(
|
|
|
|
|
|
WEBKIT_TYPE_WEB_VIEW,
|
|
|
|
|
|
"related-view", relatedTo,
|
|
|
|
|
|
nullptr));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
tab->webView = WEBKIT_WEB_VIEW(g_object_new(
|
|
|
|
|
|
WEBKIT_TYPE_WEB_VIEW,
|
|
|
|
|
|
"web-context", app->webCtx,
|
|
|
|
|
|
"user-content-manager", app->ucm,
|
|
|
|
|
|
"settings", app->wkSettings,
|
|
|
|
|
|
"website-policies", app->wkPolicies,
|
|
|
|
|
|
nullptr));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
g_signal_connect(tab->webView, "load-changed", G_CALLBACK(onLoadChanged), tab.get());
|
|
|
|
|
|
g_signal_connect(tab->webView, "load-failed", G_CALLBACK(onLoadFailed), tab.get());
|
|
|
|
|
|
g_signal_connect(tab->webView, "notify::uri", G_CALLBACK(onNotifyWebViewProp), tab.get());
|
|
|
|
|
|
g_signal_connect(tab->webView, "notify::title", G_CALLBACK(onNotifyWebViewProp), tab.get());
|
|
|
|
|
|
g_signal_connect(tab->webView, "notify::estimated-load-progress",
|
|
|
|
|
|
G_CALLBACK(onNotifyWebViewProp), tab.get());
|
|
|
|
|
|
g_signal_connect(tab->webView, "notify::is-playing-audio",
|
|
|
|
|
|
G_CALLBACK(onNotifyWebViewProp), tab.get());
|
|
|
|
|
|
g_signal_connect(tab->webView, "mouse-target-changed",
|
|
|
|
|
|
G_CALLBACK(onMouseTargetChanged), tab.get());
|
|
|
|
|
|
g_signal_connect(tab->webView, "decide-policy", G_CALLBACK(onDecidePolicy), tab.get());
|
|
|
|
|
|
g_signal_connect(tab->webView, "create", G_CALLBACK(onCreatePopupWebView), tab.get());
|
|
|
|
|
|
g_signal_connect(tab->webView, "permission-request", G_CALLBACK(onPermissionRequest), tab.get());
|
|
|
|
|
|
g_signal_connect(tab->webView, "web-process-terminated",
|
|
|
|
|
|
G_CALLBACK(onWebProcessTerminated), tab.get());
|
|
|
|
|
|
|
|
|
|
|
|
// Build vertical tab row widget for the right sidebar
|
|
|
|
|
|
tab->rowBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
|
|
|
|
|
|
gtk_style_context_add_class(gtk_widget_get_style_context(tab->rowBox), "wa-tab-row");
|
|
|
|
|
|
|
|
|
|
|
|
tab->activateBtn = gtk_button_new();
|
|
|
|
|
|
gtk_widget_set_can_focus(tab->activateBtn, FALSE);
|
|
|
|
|
|
gtk_style_context_add_class(gtk_widget_get_style_context(tab->activateBtn), "wa-tab-btn");
|
|
|
|
|
|
|
|
|
|
|
|
GtkWidget* btnInner = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
|
|
|
|
|
|
tab->idxLabel = gtk_label_new("1");
|
|
|
|
|
|
gtk_style_context_add_class(gtk_widget_get_style_context(tab->idxLabel), "wa-tab-idx");
|
|
|
|
|
|
gtk_label_set_xalign(GTK_LABEL(tab->idxLabel), 0.5f);
|
|
|
|
|
|
|
|
|
|
|
|
GtkWidget* textCol = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
|
|
|
|
|
|
tab->titleLabel = gtk_label_new("New Tab");
|
|
|
|
|
|
gtk_style_context_add_class(gtk_widget_get_style_context(tab->titleLabel), "wa-tab-title");
|
|
|
|
|
|
gtk_label_set_xalign(GTK_LABEL(tab->titleLabel), 0.0f);
|
|
|
|
|
|
gtk_label_set_ellipsize(GTK_LABEL(tab->titleLabel), PANGO_ELLIPSIZE_END);
|
|
|
|
|
|
gtk_label_set_single_line_mode(GTK_LABEL(tab->titleLabel), TRUE);
|
|
|
|
|
|
|
|
|
|
|
|
tab->domainLabel = gtk_label_new("Webarchy");
|
|
|
|
|
|
gtk_style_context_add_class(gtk_widget_get_style_context(tab->domainLabel), "wa-tab-domain");
|
|
|
|
|
|
gtk_label_set_xalign(GTK_LABEL(tab->domainLabel), 0.0f);
|
|
|
|
|
|
gtk_label_set_ellipsize(GTK_LABEL(tab->domainLabel), PANGO_ELLIPSIZE_END);
|
|
|
|
|
|
gtk_label_set_single_line_mode(GTK_LABEL(tab->domainLabel), TRUE);
|
|
|
|
|
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(textCol), tab->titleLabel, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(textCol), tab->domainLabel, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(btnInner), tab->idxLabel, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(btnInner), textCol, TRUE, TRUE, 0);
|
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(tab->activateBtn), btnInner);
|
|
|
|
|
|
|
|
|
|
|
|
tab->closeBtn = gtk_button_new_with_label("×");
|
|
|
|
|
|
gtk_widget_set_can_focus(tab->closeBtn, FALSE);
|
|
|
|
|
|
gtk_style_context_add_class(gtk_widget_get_style_context(tab->closeBtn), "wa-tab-close");
|
|
|
|
|
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(tab->rowBox), tab->activateBtn, TRUE, TRUE, 0);
|
|
|
|
|
|
gtk_box_pack_end(GTK_BOX(tab->rowBox), tab->closeBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
|
|
|
|
g_signal_connect(tab->activateBtn, "clicked", G_CALLBACK(onTabActivateClicked), tab.get());
|
|
|
|
|
|
g_signal_connect(tab->activateBtn, "button-press-event", G_CALLBACK(onTabButtonPress), tab.get());
|
|
|
|
|
|
g_signal_connect(tab->closeBtn, "clicked", G_CALLBACK(onTabCloseClicked), tab.get());
|
|
|
|
|
|
|
|
|
|
|
|
gtk_widget_show_all(tab->rowBox);
|
|
|
|
|
|
gtk_widget_show(GTK_WIDGET(tab->webView));
|
|
|
|
|
|
gtk_stack_add_named(app->webStack, GTK_WIDGET(tab->webView), tab->stackName.c_str());
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(app->tabListBox), tab->rowBox, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
|
|
|
|
TabEntry* raw = tab.get();
|
|
|
|
|
|
app->tabs.push_back(std::move(tab));
|
|
|
|
|
|
int newIdx = static_cast<int>(app->tabs.size()) - 1;
|
|
|
|
|
|
|
|
|
|
|
|
if (!initialUrl.empty()) {
|
|
|
|
|
|
webkit_web_view_load_uri(raw->webView, initialUrl.c_str());
|
|
|
|
|
|
}
|
|
|
|
|
|
if (switchTo || app->tabs.size() == 1) {
|
|
|
|
|
|
selectTab(app, newIdx);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
refreshChromeUi(app);
|
|
|
|
|
|
}
|
|
|
|
|
|
return raw;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void navigateCurrentTab(BrowserApp* app, const std::string& rawInput) {
|
|
|
|
|
|
TabEntry* tab = currentTab(app);
|
|
|
|
|
|
if (!tab || !tab->webView) return;
|
|
|
|
|
|
std::string url = normalizeInputUrlOrSearch(rawInput);
|
|
|
|
|
|
tab->url = url;
|
|
|
|
|
|
app->statusMsg = "Loading " + extractHostFromUrl(url) + "...";
|
|
|
|
|
|
webkit_web_view_load_uri(tab->webView, url.c_str());
|
|
|
|
|
|
gtk_widget_grab_focus(GTK_WIDGET(tab->webView));
|
|
|
|
|
|
refreshChromeUi(app);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void toggleBookmarkCurrent(BrowserApp* app) {
|
|
|
|
|
|
TabEntry* tab = currentTab(app);
|
|
|
|
|
|
if (!tab || tab->url.empty()) return;
|
|
|
|
|
|
int idx = findBookmarkIndex(app, tab->url);
|
|
|
|
|
|
if (idx >= 0) {
|
|
|
|
|
|
app->bookmarks.erase(app->bookmarks.begin() + idx);
|
|
|
|
|
|
app->statusMsg = "Removed bookmark";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
std::string title = tab->title.empty() ? extractHostFromUrl(tab->url) : tab->title;
|
|
|
|
|
|
app->bookmarks.push_back({title, tab->url});
|
|
|
|
|
|
app->statusMsg = "Saved bookmark: " + title;
|
|
|
|
|
|
}
|
|
|
|
|
|
saveBookmarks(app->bookmarks);
|
|
|
|
|
|
refreshBookmarksPopover(app);
|
|
|
|
|
|
refreshChromeUi(app);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void adjustZoom(BrowserApp* app, double delta) {
|
|
|
|
|
|
TabEntry* tab = currentTab(app);
|
|
|
|
|
|
if (!tab || !tab->webView) return;
|
|
|
|
|
|
double cur = webkit_web_view_get_zoom_level(tab->webView);
|
|
|
|
|
|
double next = (delta == 0.0) ? 1.0 : std::clamp(cur + delta, 0.5, 2.5);
|
|
|
|
|
|
webkit_web_view_set_zoom_level(tab->webView, next);
|
|
|
|
|
|
app->statusMsg = "Zoom: " + std::to_string(static_cast<int>(std::round(next * 100.0))) + "%";
|
|
|
|
|
|
refreshChromeUi(app);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void toggleDarkMode(BrowserApp* app) {
|
|
|
|
|
|
TabEntry* tab = currentTab(app);
|
|
|
|
|
|
if (!tab) return;
|
|
|
|
|
|
tab->darkMode = !tab->darkMode;
|
|
|
|
|
|
syncJsFlags(tab);
|
|
|
|
|
|
app->statusMsg = tab->darkMode ? "Dark mode enabled" : "Dark mode disabled";
|
|
|
|
|
|
refreshChromeUi(app);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void toggleMobileFit(BrowserApp* app) {
|
|
|
|
|
|
TabEntry* tab = currentTab(app);
|
|
|
|
|
|
if (!tab) return;
|
|
|
|
|
|
tab->mobileFit = !tab->mobileFit;
|
|
|
|
|
|
syncJsFlags(tab);
|
|
|
|
|
|
app->statusMsg = tab->mobileFit ? "Reader width fit enabled" : "Reader width fit disabled";
|
|
|
|
|
|
refreshChromeUi(app);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void toggleTabSidebar(BrowserApp* app) {
|
|
|
|
|
|
if (!app || !app->tabSidebar) return;
|
|
|
|
|
|
app->tabBarVisible = !app->tabBarVisible;
|
|
|
|
|
|
gtk_widget_set_visible(app->tabSidebar, app->tabBarVisible);
|
|
|
|
|
|
GtkStyleContext* ctx = gtk_widget_get_style_context(app->toggleTabsBtn);
|
|
|
|
|
|
if (app->tabBarVisible) gtk_style_context_add_class(ctx, "active-accent");
|
|
|
|
|
|
else gtk_style_context_remove_class(ctx, "active-accent");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void openFindBar(BrowserApp* app) {
|
|
|
|
|
|
if (!app || !app->findRevealer) return;
|
|
|
|
|
|
gtk_revealer_set_reveal_child(app->findRevealer, TRUE);
|
|
|
|
|
|
gtk_widget_grab_focus(GTK_WIDGET(app->findEntry));
|
|
|
|
|
|
gtk_editable_select_region(GTK_EDITABLE(app->findEntry), 0, -1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void closeFindBar(BrowserApp* app) {
|
|
|
|
|
|
if (!app || !app->findRevealer) return;
|
|
|
|
|
|
gtk_revealer_set_reveal_child(app->findRevealer, FALSE);
|
|
|
|
|
|
if (TabEntry* tab = currentTab(app)) {
|
|
|
|
|
|
WebKitFindController* fc = webkit_web_view_get_find_controller(tab->webView);
|
|
|
|
|
|
webkit_find_controller_search_finish(fc);
|
|
|
|
|
|
gtk_widget_grab_focus(GTK_WIDGET(tab->webView));
|
|
|
|
|
|
}
|
|
|
|
|
|
gtk_label_set_text(app->findCountLabel, "");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void runFindSearch(BrowserApp* app, const char* text) {
|
|
|
|
|
|
TabEntry* tab = currentTab(app);
|
|
|
|
|
|
if (!tab) return;
|
|
|
|
|
|
WebKitFindController* fc = webkit_web_view_get_find_controller(tab->webView);
|
|
|
|
|
|
if (!text || !text[0]) {
|
|
|
|
|
|
webkit_find_controller_search_finish(fc);
|
|
|
|
|
|
gtk_label_set_text(app->findCountLabel, "");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
webkit_find_controller_search(fc, text, WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | WEBKIT_FIND_OPTIONS_WRAP_AROUND, 256);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct BookmarkClickCtx {
|
|
|
|
|
|
BrowserApp* app;
|
|
|
|
|
|
size_t idx;
|
|
|
|
|
|
bool newTab;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void destroyCtx(gpointer data, GClosure*) {
|
|
|
|
|
|
delete static_cast<BookmarkClickCtx*>(data);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onBookmarkOpenClicked(GtkButton*, gpointer ud) {
|
|
|
|
|
|
auto* ctx = static_cast<BookmarkClickCtx*>(ud);
|
|
|
|
|
|
if (!ctx || !ctx->app || ctx->idx >= ctx->app->bookmarks.size()) return;
|
|
|
|
|
|
std::string url = ctx->app->bookmarks[ctx->idx].url;
|
|
|
|
|
|
gtk_popover_popdown(GTK_POPOVER(ctx->app->bookmarksPopover));
|
|
|
|
|
|
if (ctx->newTab) {
|
|
|
|
|
|
createTab(ctx->app, url, true);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
navigateCurrentTab(ctx->app, url);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onBookmarkDeleteClicked(GtkButton*, gpointer ud) {
|
|
|
|
|
|
auto* ctx = static_cast<BookmarkClickCtx*>(ud);
|
|
|
|
|
|
if (!ctx || !ctx->app || ctx->idx >= ctx->app->bookmarks.size()) return;
|
|
|
|
|
|
BrowserApp* app = ctx->app;
|
|
|
|
|
|
app->bookmarks.erase(app->bookmarks.begin() + static_cast<long>(ctx->idx));
|
|
|
|
|
|
saveBookmarks(app->bookmarks);
|
|
|
|
|
|
refreshBookmarksPopover(app);
|
|
|
|
|
|
refreshChromeUi(app);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void refreshBookmarksPopover(BrowserApp* app) {
|
|
|
|
|
|
if (!app || !app->bookmarksListBox) return;
|
|
|
|
|
|
GList* children = gtk_container_get_children(GTK_CONTAINER(app->bookmarksListBox));
|
|
|
|
|
|
for (GList* l = children; l != nullptr; l = l->next) {
|
|
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(l->data));
|
|
|
|
|
|
}
|
|
|
|
|
|
g_list_free(children);
|
|
|
|
|
|
|
|
|
|
|
|
if (app->bookmarks.empty()) {
|
|
|
|
|
|
GtkWidget* emptyLbl = gtk_label_new("No bookmarks saved yet. Press ☆ or Ctrl+D.");
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(app->bookmarksListBox), emptyLbl, FALSE, FALSE, 4);
|
|
|
|
|
|
gtk_widget_show(emptyLbl);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < app->bookmarks.size(); ++i) {
|
|
|
|
|
|
const auto& bm = app->bookmarks[i];
|
|
|
|
|
|
GtkWidget* row = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
|
|
|
|
|
|
std::string label = (bm.title.empty() ? extractHostFromUrl(bm.url) : bm.title) +
|
|
|
|
|
|
" [" + extractHostFromUrl(bm.url) + "]";
|
|
|
|
|
|
GtkWidget* openBtn = gtk_button_new_with_label(label.c_str());
|
|
|
|
|
|
if (GtkWidget* lbl = gtk_bin_get_child(GTK_BIN(openBtn))) {
|
|
|
|
|
|
gtk_label_set_xalign(GTK_LABEL(lbl), 0.0f);
|
|
|
|
|
|
gtk_label_set_ellipsize(GTK_LABEL(lbl), PANGO_ELLIPSIZE_END);
|
|
|
|
|
|
}
|
|
|
|
|
|
GtkWidget* tabBtn = gtk_button_new_with_label("+Tab");
|
|
|
|
|
|
GtkWidget* delBtn = gtk_button_new_with_label("×");
|
|
|
|
|
|
|
|
|
|
|
|
g_signal_connect_data(openBtn, "clicked", G_CALLBACK(onBookmarkOpenClicked),
|
|
|
|
|
|
new BookmarkClickCtx{app, i, false}, destroyCtx, GConnectFlags(0));
|
|
|
|
|
|
g_signal_connect_data(tabBtn, "clicked", G_CALLBACK(onBookmarkOpenClicked),
|
|
|
|
|
|
new BookmarkClickCtx{app, i, true}, destroyCtx, GConnectFlags(0));
|
|
|
|
|
|
g_signal_connect_data(delBtn, "clicked", G_CALLBACK(onBookmarkDeleteClicked),
|
|
|
|
|
|
new BookmarkClickCtx{app, i, false}, destroyCtx, GConnectFlags(0));
|
|
|
|
|
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(row), openBtn, TRUE, TRUE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(row), tabBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(row), delBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(app->bookmarksListBox), row, FALSE, FALSE, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
gtk_widget_show_all(app->bookmarksListBox);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void promptCustomUserAgent(BrowserApp* app) {
|
|
|
|
|
|
GtkWidget* dlg = gtk_dialog_new_with_buttons(
|
|
|
|
|
|
"Custom User-Agent",
|
|
|
|
|
|
GTK_WINDOW(app->window),
|
|
|
|
|
|
static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
|
|
|
|
|
|
"Cancel", GTK_RESPONSE_CANCEL,
|
|
|
|
|
|
"Apply", GTK_RESPONSE_ACCEPT,
|
|
|
|
|
|
nullptr);
|
|
|
|
|
|
GtkWidget* area = gtk_dialog_get_content_area(GTK_DIALOG(dlg));
|
|
|
|
|
|
GtkWidget* entry = gtk_entry_new();
|
|
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(entry), app->userAgent.c_str());
|
|
|
|
|
|
gtk_entry_set_width_chars(GTK_ENTRY(entry), 56);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(area), entry, TRUE, TRUE, 8);
|
|
|
|
|
|
gtk_widget_show_all(dlg);
|
|
|
|
|
|
if (gtk_dialog_run(GTK_DIALOG(dlg)) == GTK_RESPONSE_ACCEPT) {
|
|
|
|
|
|
std::string val = trimStr(gtk_entry_get_text(GTK_ENTRY(entry)));
|
|
|
|
|
|
if (!val.empty()) {
|
|
|
|
|
|
app->userAgent = val;
|
|
|
|
|
|
saveUserAgent(val);
|
|
|
|
|
|
webkit_settings_set_user_agent(app->wkSettings, val.c_str());
|
|
|
|
|
|
if (TabEntry* tab = currentTab(app)) webkit_web_view_reload(tab->webView);
|
|
|
|
|
|
app->statusMsg = "Updated custom User-Agent";
|
|
|
|
|
|
refreshChromeUi(app);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
gtk_widget_destroy(dlg);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onUaComboChanged(GtkComboBox* combo, gpointer ud) {
|
|
|
|
|
|
auto* app = static_cast<BrowserApp*>(ud);
|
|
|
|
|
|
if (!app || app->syncingUiFlags) return;
|
|
|
|
|
|
int active = gtk_combo_box_get_active(combo);
|
|
|
|
|
|
constexpr int numPresets = static_cast<int>(sizeof(kUaPresets) / sizeof(kUaPresets[0]));
|
|
|
|
|
|
if (active >= 0 && active < numPresets) {
|
|
|
|
|
|
app->userAgent = kUaPresets[active].ua;
|
|
|
|
|
|
saveUserAgent(app->userAgent);
|
|
|
|
|
|
webkit_settings_set_user_agent(app->wkSettings, app->userAgent.c_str());
|
|
|
|
|
|
if (TabEntry* tab = currentTab(app)) webkit_web_view_reload(tab->webView);
|
|
|
|
|
|
app->statusMsg = std::string("User-Agent: ") + kUaPresets[active].name;
|
|
|
|
|
|
refreshChromeUi(app);
|
|
|
|
|
|
} else if (active == numPresets) {
|
|
|
|
|
|
gtk_popover_popdown(GTK_POPOVER(app->toolsPopover));
|
|
|
|
|
|
promptCustomUserAgent(app);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void onSoftwareRendererToggled(GtkToggleButton* btn, gpointer ud) {
|
|
|
|
|
|
auto* app = static_cast<BrowserApp*>(ud);
|
|
|
|
|
|
if (!app || app->syncingUiFlags) return;
|
|
|
|
|
|
bool sw = gtk_toggle_button_get_active(btn);
|
|
|
|
|
|
app->softwareRenderer = sw;
|
|
|
|
|
|
configureWebkitRenderer(sw);
|
|
|
|
|
|
webkit_settings_set_hardware_acceleration_policy(
|
|
|
|
|
|
app->wkSettings,
|
|
|
|
|
|
sw ? WEBKIT_HARDWARE_ACCELERATION_POLICY_NEVER
|
|
|
|
|
|
: WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS);
|
|
|
|
|
|
|
|
|
|
|
|
std::string flagPath = getHomeDirPath() + kSoftwareRendererFlag;
|
|
|
|
|
|
if (sw) {
|
|
|
|
|
|
ensureParentDir(flagPath);
|
|
|
|
|
|
std::ofstream out(flagPath, std::ios::trunc);
|
|
|
|
|
|
if (out.is_open()) out << "1\n";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
::unlink(flagPath.c_str());
|
|
|
|
|
|
}
|
|
|
|
|
|
if (TabEntry* tab = currentTab(app)) webkit_web_view_reload(tab->webView);
|
|
|
|
|
|
app->statusMsg = sw ? "Switched to Software WebKit renderer" : "Switched to GPU WebKit renderer";
|
|
|
|
|
|
refreshChromeUi(app);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean onWindowKeyPress(GtkWidget*, GdkEventKey* ev, gpointer ud) {
|
|
|
|
|
|
auto* app = static_cast<BrowserApp*>(ud);
|
|
|
|
|
|
if (!app) return FALSE;
|
|
|
|
|
|
guint kv = ev->keyval;
|
|
|
|
|
|
guint mods = ev->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK);
|
|
|
|
|
|
bool ctrl = (mods & GDK_CONTROL_MASK) != 0;
|
|
|
|
|
|
bool shift = (mods & GDK_SHIFT_MASK) != 0;
|
|
|
|
|
|
bool alt = (mods & GDK_MOD1_MASK) != 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (ctrl && !shift && !alt && (kv == GDK_KEY_t || kv == GDK_KEY_T)) {
|
|
|
|
|
|
createTab(app, kDefaultHomepage, true);
|
|
|
|
|
|
gtk_widget_grab_focus(GTK_WIDGET(app->urlEntry));
|
|
|
|
|
|
gtk_editable_select_region(GTK_EDITABLE(app->urlEntry), 0, -1);
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (ctrl && shift && !alt && (kv == GDK_KEY_T || kv == GDK_KEY_t)) {
|
|
|
|
|
|
if (!app->closedTabUrls.empty()) {
|
|
|
|
|
|
std::string url = app->closedTabUrls.back();
|
|
|
|
|
|
app->closedTabUrls.pop_back();
|
|
|
|
|
|
createTab(app, url, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (ctrl && !alt && (kv == GDK_KEY_w || kv == GDK_KEY_W)) {
|
|
|
|
|
|
closeTabAt(app, app->activeTabIndex);
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (ctrl && !alt && (kv == GDK_KEY_q || kv == GDK_KEY_Q)) {
|
|
|
|
|
|
gtk_main_quit();
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ((ctrl && kv == GDK_KEY_Tab) || (alt && (kv == GDK_KEY_Down || kv == GDK_KEY_Page_Down))) {
|
|
|
|
|
|
if (!app->tabs.empty()) {
|
|
|
|
|
|
int next = (app->activeTabIndex + (shift ? -1 : 1) + static_cast<int>(app->tabs.size())) %
|
|
|
|
|
|
static_cast<int>(app->tabs.size());
|
|
|
|
|
|
selectTab(app, next);
|
|
|
|
|
|
}
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ((ctrl && (kv == GDK_KEY_ISO_Left_Tab || (shift && kv == GDK_KEY_Tab))) ||
|
|
|
|
|
|
(alt && (kv == GDK_KEY_Up || kv == GDK_KEY_Page_Up))) {
|
|
|
|
|
|
if (!app->tabs.empty()) {
|
|
|
|
|
|
int prev = (app->activeTabIndex - 1 + static_cast<int>(app->tabs.size())) %
|
|
|
|
|
|
static_cast<int>(app->tabs.size());
|
|
|
|
|
|
selectTab(app, prev);
|
|
|
|
|
|
}
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (alt && !ctrl && kv >= GDK_KEY_1 && kv <= GDK_KEY_9) {
|
|
|
|
|
|
int slot = static_cast<int>(kv - GDK_KEY_1);
|
|
|
|
|
|
if (kv == GDK_KEY_9) slot = static_cast<int>(app->tabs.size()) - 1;
|
|
|
|
|
|
if (slot >= 0 && slot < static_cast<int>(app->tabs.size())) {
|
|
|
|
|
|
selectTab(app, slot);
|
|
|
|
|
|
}
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ((ctrl && !shift && !alt && (kv == GDK_KEY_b || kv == GDK_KEY_B)) ||
|
|
|
|
|
|
(alt && !ctrl && (kv == GDK_KEY_t || kv == GDK_KEY_T))) {
|
|
|
|
|
|
toggleTabSidebar(app);
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ((ctrl && !alt && (kv == GDK_KEY_l || kv == GDK_KEY_L)) ||
|
|
|
|
|
|
(alt && !ctrl && (kv == GDK_KEY_d || kv == GDK_KEY_D)) ||
|
|
|
|
|
|
kv == GDK_KEY_F6) {
|
|
|
|
|
|
gtk_widget_grab_focus(GTK_WIDGET(app->urlEntry));
|
|
|
|
|
|
gtk_editable_select_region(GTK_EDITABLE(app->urlEntry), 0, -1);
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ((ctrl && !alt && (kv == GDK_KEY_r || kv == GDK_KEY_R)) || kv == GDK_KEY_F5) {
|
|
|
|
|
|
if (TabEntry* tab = currentTab(app)) {
|
|
|
|
|
|
if (shift) webkit_web_view_reload_bypass_cache(tab->webView);
|
|
|
|
|
|
else webkit_web_view_reload(tab->webView);
|
|
|
|
|
|
}
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (alt && !ctrl && kv == GDK_KEY_Left) {
|
|
|
|
|
|
if (TabEntry* tab = currentTab(app)) webkit_web_view_go_back(tab->webView);
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (alt && !ctrl && kv == GDK_KEY_Right) {
|
|
|
|
|
|
if (TabEntry* tab = currentTab(app)) webkit_web_view_go_forward(tab->webView);
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (ctrl && !shift && !alt && (kv == GDK_KEY_d || kv == GDK_KEY_D)) {
|
|
|
|
|
|
toggleBookmarkCurrent(app);
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (ctrl && shift && !alt && (kv == GDK_KEY_D || kv == GDK_KEY_d)) {
|
|
|
|
|
|
toggleDarkMode(app);
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (ctrl && !alt && (kv == GDK_KEY_f || kv == GDK_KEY_F)) {
|
|
|
|
|
|
openFindBar(app);
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (ctrl && !alt && (kv == GDK_KEY_plus || kv == GDK_KEY_equal || kv == GDK_KEY_KP_Add)) {
|
|
|
|
|
|
adjustZoom(app, 0.1);
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (ctrl && !alt && (kv == GDK_KEY_minus || kv == GDK_KEY_KP_Subtract)) {
|
|
|
|
|
|
adjustZoom(app, -0.1);
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (ctrl && !alt && (kv == GDK_KEY_0 || kv == GDK_KEY_KP_0)) {
|
|
|
|
|
|
adjustZoom(app, 0.0);
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (kv == GDK_KEY_F11) {
|
|
|
|
|
|
app->fullscreen = !app->fullscreen;
|
|
|
|
|
|
if (app->fullscreen) gtk_window_fullscreen(GTK_WINDOW(app->window));
|
|
|
|
|
|
else gtk_window_unfullscreen(GTK_WINDOW(app->window));
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (kv == GDK_KEY_Escape) {
|
|
|
|
|
|
if (gtk_revealer_get_reveal_child(app->findRevealer)) {
|
|
|
|
|
|
closeFindBar(app);
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (TabEntry* tab = currentTab(app); tab && tab->loading) {
|
|
|
|
|
|
webkit_web_view_stop_loading(tab->webView);
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean onSigUsr1ThemeReload(gpointer ud) {
|
|
|
|
|
|
applyGtkThemeCss(static_cast<BrowserApp*>(ud));
|
|
|
|
|
|
return G_SOURCE_CONTINUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean onFifoReadable(gint fd, GIOCondition, gpointer ud) {
|
|
|
|
|
|
auto* app = static_cast<BrowserApp*>(ud);
|
|
|
|
|
|
char buf[4096];
|
|
|
|
|
|
ssize_t n = ::read(fd, buf, sizeof(buf) - 1);
|
|
|
|
|
|
if (n <= 0 || !app) return G_SOURCE_CONTINUE;
|
|
|
|
|
|
buf[n] = '\0';
|
|
|
|
|
|
std::istringstream iss(buf);
|
|
|
|
|
|
std::string line;
|
|
|
|
|
|
while (std::getline(iss, line)) {
|
|
|
|
|
|
std::string cmd = trimStr(line);
|
|
|
|
|
|
if (cmd.rfind("NEW_TAB ", 0) == 0) {
|
|
|
|
|
|
std::string target = normalizeInputUrlOrSearch(cmd.substr(8));
|
|
|
|
|
|
createTab(app, target, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
gtk_window_present(GTK_WINDOW(app->window));
|
|
|
|
|
|
}
|
|
|
|
|
|
return G_SOURCE_CONTINUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool tryForwardToExistingInstance(const std::string& initialUrl) {
|
|
|
|
|
|
std::ifstream pidIn(pidRuntimePath());
|
|
|
|
|
|
pid_t pid = 0;
|
|
|
|
|
|
if (!(pidIn >> pid) || pid <= 0 || ::kill(pid, 0) != 0) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
int fd = ::open(fifoRuntimePath().c_str(), O_WRONLY | O_NONBLOCK);
|
|
|
|
|
|
if (fd < 0) return false;
|
|
|
|
|
|
std::string msg = initialUrl.empty() ? "FOCUS\n" : ("NEW_TAB " + initialUrl + "\n");
|
|
|
|
|
|
ssize_t wrote = ::write(fd, msg.data(), msg.size());
|
|
|
|
|
|
::close(fd);
|
|
|
|
|
|
return wrote > 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void buildUi(BrowserApp* app) {
|
|
|
|
|
|
app->cssProvider = gtk_css_provider_new();
|
|
|
|
|
|
if (GdkScreen* scr = gdk_screen_get_default()) {
|
|
|
|
|
|
gtk_style_context_add_provider_for_screen(
|
|
|
|
|
|
scr, GTK_STYLE_PROVIDER(app->cssProvider), GTK_STYLE_PROVIDER_PRIORITY_USER);
|
|
|
|
|
|
}
|
|
|
|
|
|
applyGtkThemeCss(app);
|
|
|
|
|
|
|
|
|
|
|
|
app->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
|
|
|
|
gtk_window_set_wmclass(GTK_WINDOW(app->window), "webarchy", "Webarchy");
|
|
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
|
|
gtk_window_set_title(GTK_WINDOW(app->window), "Webarchy Browser");
|
|
|
|
|
|
// Gemini PDA is 2160x1080 physical; with GDK_SCALE=2 and DWM 68px bar -> 1080x506 logical px.
|
|
|
|
|
|
gtk_window_set_default_size(GTK_WINDOW(app->window), 1080, 506);
|
|
|
|
|
|
|
|
|
|
|
|
GtkWidget* root = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
|
|
gtk_widget_set_name(root, "wa-root");
|
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(app->window), root);
|
|
|
|
|
|
|
|
|
|
|
|
// Left side: Main web viewport + top navbar + find bar + status bar
|
|
|
|
|
|
GtkWidget* mainPane = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
|
|
gtk_widget_set_name(mainPane, "wa-main-pane");
|
|
|
|
|
|
gtk_widget_set_hexpand(mainPane, TRUE);
|
|
|
|
|
|
gtk_widget_set_vexpand(mainPane, TRUE);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(root), mainPane, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
|
|
|
|
// Top navigation bar
|
|
|
|
|
|
GtkWidget* navbar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
|
|
|
|
|
|
gtk_widget_set_name(navbar, "wa-navbar");
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(mainPane), navbar, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
|
|
|
|
app->backBtn = gtk_button_new_with_label("←");
|
|
|
|
|
|
app->fwdBtn = gtk_button_new_with_label("→");
|
|
|
|
|
|
app->reloadBtn = gtk_button_new_with_label("↻");
|
|
|
|
|
|
app->homeBtn = gtk_button_new_with_label("⌂");
|
|
|
|
|
|
app->urlEntry = GTK_ENTRY(gtk_entry_new());
|
|
|
|
|
|
gtk_widget_set_name(GTK_WIDGET(app->urlEntry), "wa-urlbar");
|
|
|
|
|
|
gtk_entry_set_placeholder_text(app->urlEntry, "Enter URL or DuckDuckGo search...");
|
|
|
|
|
|
gtk_widget_set_hexpand(GTK_WIDGET(app->urlEntry), TRUE);
|
|
|
|
|
|
|
|
|
|
|
|
app->bookmarkBtn = gtk_button_new_with_label("☆");
|
|
|
|
|
|
app->menuBtn = gtk_menu_button_new();
|
|
|
|
|
|
gtk_button_set_label(GTK_BUTTON(app->menuBtn), "☰");
|
|
|
|
|
|
app->toggleTabsBtn = gtk_button_new_with_label("Tabs ◫");
|
|
|
|
|
|
gtk_style_context_add_class(gtk_widget_get_style_context(app->toggleTabsBtn), "active-accent");
|
|
|
|
|
|
|
|
|
|
|
|
for (GtkWidget* w : {app->backBtn, app->fwdBtn, app->reloadBtn, app->homeBtn,
|
|
|
|
|
|
app->bookmarkBtn, app->menuBtn, app->toggleTabsBtn}) {
|
|
|
|
|
|
gtk_widget_set_can_focus(w, FALSE);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(navbar), app->backBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(navbar), app->fwdBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(navbar), app->reloadBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(navbar), app->homeBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(navbar), GTK_WIDGET(app->urlEntry), TRUE, TRUE, 2);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(navbar), app->bookmarkBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(navbar), app->menuBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(navbar), app->toggleTabsBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
|
|
|
|
// Slim load progress bar
|
|
|
|
|
|
app->progressBar = GTK_PROGRESS_BAR(gtk_progress_bar_new());
|
|
|
|
|
|
gtk_widget_set_name(GTK_WIDGET(app->progressBar), "wa-progress");
|
|
|
|
|
|
gtk_widget_set_no_show_all(GTK_WIDGET(app->progressBar), TRUE);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(mainPane), GTK_WIDGET(app->progressBar), FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
|
|
|
|
// Find-in-page revealer
|
|
|
|
|
|
app->findRevealer = GTK_REVEALER(gtk_revealer_new());
|
|
|
|
|
|
gtk_revealer_set_transition_type(app->findRevealer, GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
|
|
|
|
|
|
GtkWidget* findBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
|
|
|
|
|
|
gtk_widget_set_name(findBox, "wa-findbar");
|
|
|
|
|
|
app->findEntry = GTK_ENTRY(gtk_entry_new());
|
|
|
|
|
|
gtk_entry_set_placeholder_text(app->findEntry, "Find in page...");
|
|
|
|
|
|
gtk_widget_set_hexpand(GTK_WIDGET(app->findEntry), TRUE);
|
|
|
|
|
|
GtkWidget* findPrevBtn = gtk_button_new_with_label("↑ Prev");
|
|
|
|
|
|
GtkWidget* findNextBtn = gtk_button_new_with_label("↓ Next");
|
|
|
|
|
|
app->findCountLabel = GTK_LABEL(gtk_label_new(""));
|
|
|
|
|
|
GtkWidget* findCloseBtn = gtk_button_new_with_label("✕");
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(findBox), GTK_WIDGET(app->findEntry), TRUE, TRUE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(findBox), findPrevBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(findBox), findNextBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(findBox), GTK_WIDGET(app->findCountLabel), FALSE, FALSE, 4);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(findBox), findCloseBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(app->findRevealer), findBox);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(mainPane), GTK_WIDGET(app->findRevealer), FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
|
|
|
|
// WebView stack
|
|
|
|
|
|
app->webStack = GTK_STACK(gtk_stack_new());
|
|
|
|
|
|
gtk_stack_set_transition_type(app->webStack, GTK_STACK_TRANSITION_TYPE_NONE);
|
|
|
|
|
|
gtk_widget_set_hexpand(GTK_WIDGET(app->webStack), TRUE);
|
|
|
|
|
|
gtk_widget_set_vexpand(GTK_WIDGET(app->webStack), TRUE);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(mainPane), GTK_WIDGET(app->webStack), TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
|
|
|
|
// Bottom status bar
|
|
|
|
|
|
GtkWidget* statusBar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
|
|
|
|
|
|
gtk_widget_set_name(statusBar, "wa-statusbar");
|
|
|
|
|
|
app->statusLabel = GTK_LABEL(gtk_label_new("Ready"));
|
|
|
|
|
|
gtk_label_set_xalign(app->statusLabel, 0.0f);
|
|
|
|
|
|
gtk_label_set_ellipsize(app->statusLabel, PANGO_ELLIPSIZE_END);
|
|
|
|
|
|
gtk_widget_set_hexpand(GTK_WIDGET(app->statusLabel), TRUE);
|
|
|
|
|
|
app->modeBadgeLabel = GTK_LABEL(gtk_label_new("GPU • 100%"));
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(statusBar), GTK_WIDGET(app->statusLabel), TRUE, TRUE, 0);
|
|
|
|
|
|
gtk_box_pack_end(GTK_BOX(statusBar), GTK_WIDGET(app->modeBadgeLabel), FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_end(GTK_BOX(mainPane), statusBar, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
|
|
|
|
// Right-side vertical tab bar (236 logical px = 472 physical px snapped flush right on 2160x1080)
|
|
|
|
|
|
app->tabSidebar = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
|
|
gtk_widget_set_name(app->tabSidebar, "wa-tabbar");
|
|
|
|
|
|
gtk_widget_set_size_request(app->tabSidebar, 236, -1);
|
|
|
|
|
|
gtk_widget_set_hexpand(app->tabSidebar, FALSE);
|
|
|
|
|
|
gtk_widget_set_hexpand_set(app->tabSidebar, TRUE);
|
|
|
|
|
|
gtk_widget_set_halign(app->tabSidebar, GTK_ALIGN_END);
|
|
|
|
|
|
gtk_box_pack_end(GTK_BOX(root), app->tabSidebar, FALSE, TRUE, 0);
|
|
|
|
|
|
|
|
|
|
|
|
GtkWidget* tabHeader = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
|
|
|
|
|
|
gtk_widget_set_name(tabHeader, "wa-tabbar-header");
|
|
|
|
|
|
app->tabHeaderLabel = GTK_LABEL(gtk_label_new("TABS (1)"));
|
|
|
|
|
|
gtk_label_set_xalign(app->tabHeaderLabel, 0.0f);
|
|
|
|
|
|
GtkWidget* newTabBtn = gtk_button_new_with_label("+ New Tab");
|
|
|
|
|
|
gtk_widget_set_name(newTabBtn, "wa-newtab-btn");
|
|
|
|
|
|
gtk_widget_set_can_focus(newTabBtn, FALSE);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(tabHeader), GTK_WIDGET(app->tabHeaderLabel), TRUE, TRUE, 0);
|
|
|
|
|
|
gtk_box_pack_end(GTK_BOX(tabHeader), newTabBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(app->tabSidebar), tabHeader, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
|
|
|
|
GtkWidget* tabScroll = gtk_scrolled_window_new(nullptr, nullptr);
|
|
|
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(tabScroll),
|
|
|
|
|
|
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
|
|
|
|
|
gtk_widget_set_vexpand(tabScroll, TRUE);
|
|
|
|
|
|
app->tabListBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
|
|
gtk_widget_set_name(app->tabListBox, "wa-tablist");
|
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(tabScroll), app->tabListBox);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(app->tabSidebar), tabScroll, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
|
|
|
|
// Thumb-reachable quick controls footer on right vertical tab bar
|
|
|
|
|
|
GtkWidget* tabFooter = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
|
|
|
|
|
|
gtk_widget_set_name(tabFooter, "wa-tabbar-footer");
|
|
|
|
|
|
GtkWidget* bmMenuBtn = gtk_menu_button_new();
|
|
|
|
|
|
gtk_button_set_label(GTK_BUTTON(bmMenuBtn), "★");
|
|
|
|
|
|
gtk_widget_set_tooltip_text(bmMenuBtn, "Bookmarks");
|
|
|
|
|
|
app->tabDarkBtn = gtk_button_new_with_label("◐");
|
|
|
|
|
|
gtk_widget_set_tooltip_text(app->tabDarkBtn, "Toggle Dark Mode");
|
|
|
|
|
|
GtkWidget* zoomOutBtn = gtk_button_new_with_label("−");
|
|
|
|
|
|
app->zoomLabel = GTK_LABEL(gtk_label_new("100%"));
|
|
|
|
|
|
GtkWidget* zoomInBtn = gtk_button_new_with_label("+");
|
|
|
|
|
|
for (GtkWidget* w : {bmMenuBtn, app->tabDarkBtn, zoomOutBtn, zoomInBtn}) {
|
|
|
|
|
|
gtk_widget_set_can_focus(w, FALSE);
|
|
|
|
|
|
}
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(tabFooter), bmMenuBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(tabFooter), app->tabDarkBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_end(GTK_BOX(tabFooter), zoomInBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_end(GTK_BOX(tabFooter), GTK_WIDGET(app->zoomLabel), FALSE, FALSE, 2);
|
|
|
|
|
|
gtk_box_pack_end(GTK_BOX(tabFooter), zoomOutBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_end(GTK_BOX(app->tabSidebar), tabFooter, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
|
|
|
|
// Bookmarks popover (attached to sidebar footer button)
|
|
|
|
|
|
app->bookmarksPopover = gtk_popover_new(bmMenuBtn);
|
|
|
|
|
|
GtkWidget* bmScroll = gtk_scrolled_window_new(nullptr, nullptr);
|
|
|
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(bmScroll),
|
|
|
|
|
|
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
|
|
|
|
|
gtk_widget_set_size_request(bmScroll, 320, 260);
|
|
|
|
|
|
app->bookmarksListBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
|
|
|
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(app->bookmarksListBox), 8);
|
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(bmScroll), app->bookmarksListBox);
|
|
|
|
|
|
gtk_widget_show_all(bmScroll);
|
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(app->bookmarksPopover), bmScroll);
|
|
|
|
|
|
gtk_menu_button_set_popover(GTK_MENU_BUTTON(bmMenuBtn), app->bookmarksPopover);
|
|
|
|
|
|
refreshBookmarksPopover(app);
|
|
|
|
|
|
|
|
|
|
|
|
// Tools menu popover (attached to top-bar ☰ button)
|
|
|
|
|
|
app->toolsPopover = gtk_popover_new(app->menuBtn);
|
|
|
|
|
|
GtkWidget* toolsBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6);
|
|
|
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(toolsBox), 10);
|
|
|
|
|
|
|
|
|
|
|
|
GtkWidget* uaTitle = gtk_label_new("User-Agent Profile:");
|
|
|
|
|
|
gtk_label_set_xalign(GTK_LABEL(uaTitle), 0.0f);
|
|
|
|
|
|
app->uaCombo = gtk_combo_box_text_new();
|
|
|
|
|
|
int activeUa = -1;
|
|
|
|
|
|
constexpr int numPresets = static_cast<int>(sizeof(kUaPresets) / sizeof(kUaPresets[0]));
|
|
|
|
|
|
for (int i = 0; i < numPresets; ++i) {
|
|
|
|
|
|
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(app->uaCombo), kUaPresets[i].name);
|
|
|
|
|
|
if (app->userAgent == kUaPresets[i].ua) activeUa = i;
|
|
|
|
|
|
}
|
|
|
|
|
|
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(app->uaCombo), "Custom User-Agent...");
|
|
|
|
|
|
gtk_combo_box_set_active(GTK_COMBO_BOX(app->uaCombo), activeUa >= 0 ? activeUa : numPresets);
|
|
|
|
|
|
|
|
|
|
|
|
app->darkCheckBtn = gtk_check_button_new_with_label("Dark Page Inverter (Ctrl+Shift+D)");
|
|
|
|
|
|
app->fitCheckBtn = gtk_check_button_new_with_label("Reader Width Fit");
|
|
|
|
|
|
app->swCheckBtn = gtk_check_button_new_with_label("Software WebKit Renderer");
|
|
|
|
|
|
|
|
|
|
|
|
GtkWidget* findTriggerBtn = gtk_button_new_with_label("Find in Page (Ctrl+F)");
|
|
|
|
|
|
GtkWidget* resetZoomBtn = gtk_button_new_with_label("Reset Zoom 100% (Ctrl+0)");
|
|
|
|
|
|
GtkWidget* reopenTabBtn = gtk_button_new_with_label("Reopen Closed Tab (Ctrl+Shift+T)");
|
|
|
|
|
|
GtkWidget* helpLbl = gtk_label_new(
|
|
|
|
|
|
"Shortcuts: Ctrl+T New Tab | Ctrl+W Close | Ctrl+Tab Next\n"
|
|
|
|
|
|
"Ctrl+L URL | Ctrl+B Tabs | Alt+1..9 Tab | F11 Fullscreen");
|
|
|
|
|
|
gtk_label_set_xalign(GTK_LABEL(helpLbl), 0.0f);
|
|
|
|
|
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(toolsBox), uaTitle, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(toolsBox), app->uaCombo, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(toolsBox), gtk_separator_new(GTK_ORIENTATION_HORIZONTAL), FALSE, FALSE, 2);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(toolsBox), app->darkCheckBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(toolsBox), app->fitCheckBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(toolsBox), app->swCheckBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(toolsBox), gtk_separator_new(GTK_ORIENTATION_HORIZONTAL), FALSE, FALSE, 2);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(toolsBox), findTriggerBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(toolsBox), resetZoomBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(toolsBox), reopenTabBtn, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(toolsBox), gtk_separator_new(GTK_ORIENTATION_HORIZONTAL), FALSE, FALSE, 2);
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(toolsBox), helpLbl, FALSE, FALSE, 0);
|
|
|
|
|
|
gtk_widget_show_all(toolsBox);
|
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(app->toolsPopover), toolsBox);
|
|
|
|
|
|
gtk_menu_button_set_popover(GTK_MENU_BUTTON(app->menuBtn), app->toolsPopover);
|
|
|
|
|
|
|
|
|
|
|
|
// Wire UI signals
|
|
|
|
|
|
g_signal_connect(app->window, "destroy", G_CALLBACK(gtk_main_quit), nullptr);
|
|
|
|
|
|
g_signal_connect(app->window, "key-press-event", G_CALLBACK(onWindowKeyPress), app);
|
|
|
|
|
|
|
|
|
|
|
|
g_signal_connect(app->backBtn, "clicked", G_CALLBACK(+[](GtkButton*, gpointer ud) {
|
|
|
|
|
|
if (TabEntry* tab = currentTab(static_cast<BrowserApp*>(ud))) {
|
|
|
|
|
|
webkit_web_view_go_back(tab->webView);
|
|
|
|
|
|
}
|
|
|
|
|
|
}), app);
|
|
|
|
|
|
g_signal_connect(app->fwdBtn, "clicked", G_CALLBACK(+[](GtkButton*, gpointer ud) {
|
|
|
|
|
|
if (TabEntry* tab = currentTab(static_cast<BrowserApp*>(ud))) {
|
|
|
|
|
|
webkit_web_view_go_forward(tab->webView);
|
|
|
|
|
|
}
|
|
|
|
|
|
}), app);
|
|
|
|
|
|
g_signal_connect(app->reloadBtn, "clicked", G_CALLBACK(+[](GtkButton*, gpointer ud) {
|
|
|
|
|
|
if (TabEntry* tab = currentTab(static_cast<BrowserApp*>(ud))) {
|
|
|
|
|
|
if (tab->loading) webkit_web_view_stop_loading(tab->webView);
|
|
|
|
|
|
else webkit_web_view_reload(tab->webView);
|
|
|
|
|
|
}
|
|
|
|
|
|
}), app);
|
|
|
|
|
|
g_signal_connect(app->homeBtn, "clicked", G_CALLBACK(+[](GtkButton*, gpointer ud) {
|
|
|
|
|
|
auto* a = static_cast<BrowserApp*>(ud);
|
|
|
|
|
|
std::string homeUrl = a->bookmarks.empty() ? kDefaultHomepage : a->bookmarks[0].url;
|
|
|
|
|
|
navigateCurrentTab(a, homeUrl);
|
|
|
|
|
|
}), app);
|
|
|
|
|
|
g_signal_connect(app->urlEntry, "activate", G_CALLBACK(+[](GtkEntry* entry, gpointer ud) {
|
|
|
|
|
|
navigateCurrentTab(static_cast<BrowserApp*>(ud), gtk_entry_get_text(entry));
|
|
|
|
|
|
}), app);
|
|
|
|
|
|
g_signal_connect(app->bookmarkBtn, "clicked", G_CALLBACK(+[](GtkButton*, gpointer ud) {
|
|
|
|
|
|
toggleBookmarkCurrent(static_cast<BrowserApp*>(ud));
|
|
|
|
|
|
}), app);
|
|
|
|
|
|
g_signal_connect(app->toggleTabsBtn, "clicked", G_CALLBACK(+[](GtkButton*, gpointer ud) {
|
|
|
|
|
|
toggleTabSidebar(static_cast<BrowserApp*>(ud));
|
|
|
|
|
|
}), app);
|
|
|
|
|
|
g_signal_connect(newTabBtn, "clicked", G_CALLBACK(+[](GtkButton*, gpointer ud) {
|
|
|
|
|
|
auto* a = static_cast<BrowserApp*>(ud);
|
|
|
|
|
|
createTab(a, kDefaultHomepage, true);
|
|
|
|
|
|
gtk_widget_grab_focus(GTK_WIDGET(a->urlEntry));
|
|
|
|
|
|
gtk_editable_select_region(GTK_EDITABLE(a->urlEntry), 0, -1);
|
|
|
|
|
|
}), app);
|
|
|
|
|
|
g_signal_connect(app->tabDarkBtn, "clicked", G_CALLBACK(+[](GtkButton*, gpointer ud) {
|
|
|
|
|
|
toggleDarkMode(static_cast<BrowserApp*>(ud));
|
|
|
|
|
|
}), app);
|
|
|
|
|
|
g_signal_connect(zoomOutBtn, "clicked", G_CALLBACK(+[](GtkButton*, gpointer ud) {
|
|
|
|
|
|
adjustZoom(static_cast<BrowserApp*>(ud), -0.1);
|
|
|
|
|
|
}), app);
|
|
|
|
|
|
g_signal_connect(zoomInBtn, "clicked", G_CALLBACK(+[](GtkButton*, gpointer ud) {
|
|
|
|
|
|
adjustZoom(static_cast<BrowserApp*>(ud), 0.1);
|
|
|
|
|
|
}), app);
|
|
|
|
|
|
|
|
|
|
|
|
g_signal_connect(app->findEntry, "changed", G_CALLBACK(+[](GtkEditable* ed, gpointer ud) {
|
|
|
|
|
|
runFindSearch(static_cast<BrowserApp*>(ud), gtk_entry_get_text(GTK_ENTRY(ed)));
|
|
|
|
|
|
}), app);
|
|
|
|
|
|
g_signal_connect(app->findEntry, "activate", G_CALLBACK(+[](GtkEntry*, gpointer ud) {
|
|
|
|
|
|
if (TabEntry* tab = currentTab(static_cast<BrowserApp*>(ud))) {
|
|
|
|
|
|
webkit_find_controller_search_next(webkit_web_view_get_find_controller(tab->webView));
|
|
|
|
|
|
}
|
|
|
|
|
|
}), app);
|
|
|
|
|
|
g_signal_connect(findPrevBtn, "clicked", G_CALLBACK(+[](GtkButton*, gpointer ud) {
|
|
|
|
|
|
if (TabEntry* tab = currentTab(static_cast<BrowserApp*>(ud))) {
|
|
|
|
|
|
webkit_find_controller_search_previous(webkit_web_view_get_find_controller(tab->webView));
|
|
|
|
|
|
}
|
|
|
|
|
|
}), app);
|
|
|
|
|
|
g_signal_connect(findNextBtn, "clicked", G_CALLBACK(+[](GtkButton*, gpointer ud) {
|
|
|
|
|
|
if (TabEntry* tab = currentTab(static_cast<BrowserApp*>(ud))) {
|
|
|
|
|
|
webkit_find_controller_search_next(webkit_web_view_get_find_controller(tab->webView));
|
|
|
|
|
|
}
|
|
|
|
|
|
}), app);
|
|
|
|
|
|
g_signal_connect(findCloseBtn, "clicked", G_CALLBACK(+[](GtkButton*, gpointer ud) {
|
|
|
|
|
|
closeFindBar(static_cast<BrowserApp*>(ud));
|
|
|
|
|
|
}), app);
|
|
|
|
|
|
|
|
|
|
|
|
g_signal_connect(app->uaCombo, "changed", G_CALLBACK(onUaComboChanged), app);
|
|
|
|
|
|
g_signal_connect(app->darkCheckBtn, "toggled", G_CALLBACK(+[](GtkToggleButton*, gpointer ud) {
|
|
|
|
|
|
auto* a = static_cast<BrowserApp*>(ud);
|
|
|
|
|
|
if (!a->syncingUiFlags) toggleDarkMode(a);
|
|
|
|
|
|
}), app);
|
|
|
|
|
|
g_signal_connect(app->fitCheckBtn, "toggled", G_CALLBACK(+[](GtkToggleButton*, gpointer ud) {
|
|
|
|
|
|
auto* a = static_cast<BrowserApp*>(ud);
|
|
|
|
|
|
if (!a->syncingUiFlags) toggleMobileFit(a);
|
|
|
|
|
|
}), app);
|
|
|
|
|
|
g_signal_connect(app->swCheckBtn, "toggled", G_CALLBACK(onSoftwareRendererToggled), app);
|
|
|
|
|
|
g_signal_connect(findTriggerBtn, "clicked", G_CALLBACK(+[](GtkButton*, gpointer ud) {
|
|
|
|
|
|
auto* a = static_cast<BrowserApp*>(ud);
|
|
|
|
|
|
gtk_popover_popdown(GTK_POPOVER(a->toolsPopover));
|
|
|
|
|
|
openFindBar(a);
|
|
|
|
|
|
}), app);
|
|
|
|
|
|
g_signal_connect(resetZoomBtn, "clicked", G_CALLBACK(+[](GtkButton*, gpointer ud) {
|
|
|
|
|
|
auto* a = static_cast<BrowserApp*>(ud);
|
|
|
|
|
|
gtk_popover_popdown(GTK_POPOVER(a->toolsPopover));
|
|
|
|
|
|
adjustZoom(a, 0.0);
|
|
|
|
|
|
}), app);
|
|
|
|
|
|
g_signal_connect(reopenTabBtn, "clicked", G_CALLBACK(+[](GtkButton*, gpointer ud) {
|
|
|
|
|
|
auto* a = static_cast<BrowserApp*>(ud);
|
|
|
|
|
|
gtk_popover_popdown(GTK_POPOVER(a->toolsPopover));
|
|
|
|
|
|
if (!a->closedTabUrls.empty()) {
|
|
|
|
|
|
std::string url = a->closedTabUrls.back();
|
|
|
|
|
|
a->closedTabUrls.pop_back();
|
|
|
|
|
|
createTab(a, url, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
}), app);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void initWebKitEngine(BrowserApp* app) {
|
|
|
|
|
|
// 1.2 GB limit suited for 4 GB Gemini PDA MT6797X with multi-tab browsing
|
|
|
|
|
|
WebKitMemoryPressureSettings* mp = webkit_memory_pressure_settings_new();
|
|
|
|
|
|
webkit_memory_pressure_settings_set_memory_limit(mp, 1200);
|
|
|
|
|
|
webkit_memory_pressure_settings_set_kill_threshold(mp, 0.95);
|
|
|
|
|
|
webkit_memory_pressure_settings_set_strict_threshold(mp, 0.78);
|
|
|
|
|
|
webkit_memory_pressure_settings_set_conservative_threshold(mp, 0.55);
|
|
|
|
|
|
webkit_website_data_manager_set_memory_pressure_settings(mp);
|
|
|
|
|
|
webkit_memory_pressure_settings_free(mp);
|
|
|
|
|
|
|
|
|
|
|
|
std::string dataDir = getHomeDirPath() + "/.local/share/geminux/webarchy/data";
|
|
|
|
|
|
std::string cacheDir = getHomeDirPath() + "/.cache/geminux/webarchy";
|
|
|
|
|
|
std::string cookieFile = getHomeDirPath() + "/.local/share/geminux/webarchy/cookies.sqlite";
|
|
|
|
|
|
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);
|
|
|
|
|
|
app->webCtx = webkit_web_context_new_with_website_data_manager(dataMgr);
|
|
|
|
|
|
g_object_unref(dataMgr);
|
|
|
|
|
|
|
|
|
|
|
|
webkit_web_context_set_sandbox_enabled(app->webCtx, FALSE);
|
|
|
|
|
|
webkit_web_context_set_cache_model(app->webCtx, WEBKIT_CACHE_MODEL_WEB_BROWSER);
|
|
|
|
|
|
|
|
|
|
|
|
WebKitCookieManager* cookieMgr = webkit_web_context_get_cookie_manager(app->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);
|
|
|
|
|
|
|
|
|
|
|
|
app->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(app->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(app->ucm, script);
|
|
|
|
|
|
webkit_user_script_unref(script);
|
|
|
|
|
|
|
|
|
|
|
|
WebKitSettings* s = webkit_settings_new();
|
|
|
|
|
|
webkit_settings_set_user_agent(s, app->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, 15);
|
|
|
|
|
|
webkit_settings_set_default_monospace_font_size(s, 13);
|
|
|
|
|
|
webkit_settings_set_minimum_font_size(s, 10);
|
|
|
|
|
|
|
|
|
|
|
|
webkit_settings_set_hardware_acceleration_policy(
|
|
|
|
|
|
s, app->softwareRenderer ? WEBKIT_HARDWARE_ACCELERATION_POLICY_NEVER
|
|
|
|
|
|
: WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS);
|
|
|
|
|
|
webkit_settings_set_enable_webgl(s, TRUE);
|
|
|
|
|
|
webkit_settings_set_enable_smooth_scrolling(s, TRUE);
|
|
|
|
|
|
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);
|
|
|
|
|
|
app->wkSettings = s;
|
|
|
|
|
|
|
|
|
|
|
|
app->wkPolicies = webkit_website_policies_new_with_policies(
|
|
|
|
|
|
"autoplay", WEBKIT_AUTOPLAY_ALLOW, nullptr);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setupSingleInstanceServer(BrowserApp* app) {
|
|
|
|
|
|
std::string pidPath = pidRuntimePath();
|
|
|
|
|
|
std::ofstream pidOut(pidPath, std::ios::trunc);
|
|
|
|
|
|
if (pidOut.is_open()) pidOut << static_cast<long>(::getpid()) << "\n";
|
|
|
|
|
|
|
|
|
|
|
|
std::string fifoPath = fifoRuntimePath();
|
|
|
|
|
|
::unlink(fifoPath.c_str());
|
|
|
|
|
|
if (::mkfifo(fifoPath.c_str(), 0600) == 0) {
|
|
|
|
|
|
app->fifoFd = ::open(fifoPath.c_str(), O_RDWR | O_NONBLOCK);
|
|
|
|
|
|
if (app->fifoFd >= 0) {
|
|
|
|
|
|
app->fifoWatchId = g_unix_fd_add(app->fifoFd, G_IO_IN, onFifoReadable, app);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cleanupSingleInstanceServer(BrowserApp* app) {
|
|
|
|
|
|
if (app->fifoWatchId > 0) {
|
|
|
|
|
|
g_source_remove(app->fifoWatchId);
|
|
|
|
|
|
app->fifoWatchId = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (app->fifoFd >= 0) {
|
|
|
|
|
|
::close(app->fifoFd);
|
|
|
|
|
|
app->fifoFd = -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
::unlink(fifoRuntimePath().c_str());
|
|
|
|
|
|
::unlink(pidRuntimePath().c_str());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
|
|
bool newWindow = false;
|
|
|
|
|
|
bool forceSoftware = false;
|
|
|
|
|
|
std::vector<std::string> urls;
|
|
|
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
|
|
|
|
if (!argv[i] || !argv[i][0]) continue;
|
|
|
|
|
|
if (std::strcmp(argv[i], "--new-window") == 0) newWindow = true;
|
|
|
|
|
|
else if (std::strcmp(argv[i], "--software") == 0) forceSoftware = true;
|
|
|
|
|
|
else urls.push_back(argv[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!newWindow) {
|
|
|
|
|
|
std::string first = urls.empty() ? "" : normalizeInputUrlOrSearch(urls[0]);
|
|
|
|
|
|
if (tryForwardToExistingInstance(first)) {
|
|
|
|
|
|
for (size_t i = 1; i < urls.size(); ++i) {
|
|
|
|
|
|
tryForwardToExistingInstance(normalizeInputUrlOrSearch(urls[i]));
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BrowserApp app;
|
|
|
|
|
|
app.softwareRenderer = forceSoftware || webarchySoftwareRendererPreferred();
|
|
|
|
|
|
configureWebkitRenderer(app.softwareRenderer);
|
|
|
|
|
|
|
|
|
|
|
|
gtk_init(&argc, &argv);
|
|
|
|
|
|
|
|
|
|
|
|
app.bookmarks = loadBookmarks();
|
|
|
|
|
|
app.userAgent = loadUserAgent();
|
|
|
|
|
|
|
|
|
|
|
|
initWebKitEngine(&app);
|
|
|
|
|
|
buildUi(&app);
|
|
|
|
|
|
if (!newWindow) {
|
|
|
|
|
|
setupSingleInstanceServer(&app);
|
|
|
|
|
|
}
|
|
|
|
|
|
g_unix_signal_add(SIGUSR1, onSigUsr1ThemeReload, &app);
|
|
|
|
|
|
|
|
|
|
|
|
if (urls.empty()) {
|
|
|
|
|
|
std::string homeUrl = app.bookmarks.empty() ? kDefaultHomepage : app.bookmarks[0].url;
|
|
|
|
|
|
createTab(&app, homeUrl, true);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
for (size_t i = 0; i < urls.size(); ++i) {
|
|
|
|
|
|
createTab(&app, normalizeInputUrlOrSearch(urls[i]), i == 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gtk_widget_show_all(app.window);
|
|
|
|
|
|
gtk_widget_hide(GTK_WIDGET(app.progressBar));
|
|
|
|
|
|
refreshChromeUi(&app);
|
|
|
|
|
|
|
|
|
|
|
|
gtk_main();
|
|
|
|
|
|
|
|
|
|
|
|
app.tabs.clear();
|
|
|
|
|
|
if (!newWindow) cleanupSingleInstanceServer(&app);
|
|
|
|
|
|
if (app.wkPolicies) g_object_unref(app.wkPolicies);
|
|
|
|
|
|
if (app.wkSettings) g_object_unref(app.wkSettings);
|
|
|
|
|
|
if (app.ucm) g_object_unref(app.ucm);
|
|
|
|
|
|
if (app.webCtx) g_object_unref(app.webCtx);
|
|
|
|
|
|
if (app.cssProvider) g_object_unref(app.cssProvider);
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|