don't scale hints with webpage

This commit is contained in:
2026-10-17 13:56:10 +02:00
parent e202725e07
commit 9eab4b89f0
4 changed files with 15 additions and 7 deletions
+1 -1
View File
@@ -65,7 +65,7 @@ The only tests are the Rust crate's (`nix develop -c sh -c 'cd adblock && cargo
- **Hardening** (`src/hardening.cpp`): `applyToProfile` sets the restrictive `QWebEngineSettings` and the third-party cookie filter. The filter runs on the network thread and must stay a pure function. `main.cpp` applies it right after creating the profile, and warns in the first window if `sandboxDisabledReason` finds the sandbox off. `StatusBar::setUrl` takes a `QUrl` so it can mark plain-HTTP pages (`insecure` property).
- **User agent** (`src/useragent.cpp`): `useragent::apply` sets the profile's UA string *and* its `QWebEngineClientHints`, so the two don't contradict each other. Chromium sends the low-entropy hints (brands, platform, mobile) even with `setAllClientHintsEnabled(false)`, so every preset sets a platform; the brand ("Google Chrome", "Microsoft Edge") goes in through `setFullVersionList`. Chrome-based presets use the engine's own major version. `:useragent` completion reuses `CompletionView` with name / string columns.
- **Settings** live as constants in `src/config.h` (`config::kZoomDefault`, `config::kZoomLevels`, `kBlockThirdPartyCookies`, `kPdfViewer`, `kUserAgent`, `kScrollStepPx`), named after qutebrowser's settings, until there's a config file. Zoom is per window: `setZoom` / `zoomStep` in `BrowserWindow`, applied before the first load. QtWebEngine keeps a view's zoom across navigations, so it doesn't need re-applying.
- The UI stylesheet is the `kStyleSheet` string in `src/main.cpp`, with qutebrowser's default colours; `@FONT@` is replaced with `config::kFont` (the hint script does the same in its CSS). Stylesheet fonts and colours don't propagate to child widgets, so rules name the labels (`QWidget#statusBar QLabel`). Widgets are styled by `objectName` and by dynamic properties, re-polished on change: the status bar's `mode` (insert turns it green), the URL label's `state` (`https`/`error`/`hover`) and a message's `level`.
- The UI stylesheet is the `kStyleSheet` string in `src/main.cpp`, with qutebrowser's default colours; `@FONT@` is replaced with `config::kFont` (the hint script does the same in its CSS, and scales its labels by `1 / zoom` so page zoom doesn't enlarge them). Stylesheet fonts and colours don't propagate to child widgets, so rules name the labels (`QWidget#statusBar QLabel`). Widgets are styled by `objectName` and by dynamic properties, re-polished on change: the status bar's `mode` (insert turns it green), the URL label's `state` (`https`/`error`/`hover`) and a message's `level`.
- **Status bar** (`StatusBar`) is laid out like qutebrowser's: mode, key string (`m_pendingKeys`), URL (an eliding label, so a long URL can't widen the window), scroll position, progress bar. All messages go through `BrowserWindow::showMessage` to the `MessageView`, never to the bar. The scroll position comes from `QWebEnginePage::scrollPosition`/`contentsSize`, which are in *zoomed* pixels like the view's height, not CSS pixels.
**Windows, not tabs.** att_browser deliberately has no tab bar, because the user's window manager does the tabbing. Map qutebrowser's tab features onto top-level windows: `d` closes the window, `O` / `:open -w` (or `-t`) opens a new one. Each `BrowserWindow` is one page, with `WA_DeleteOnClose`. All windows share a `Session` (profile, `AdBlocker`, `History`) that `main()` owns. After `app.exec()`, `main()` deletes any window still alive before the history and profile go away. `:quit` closes all windows; `:close` closes one.
+1 -1
View File
@@ -420,7 +420,7 @@ void BrowserWindow::handleHintModeKey(QKeyEvent *event)
void BrowserWindow::startHints()
{
setMode(Mode::Hint);
runHintScript(hints::showScript());
runHintScript(hints::showScript(m_view->zoomFactor()));
}
void BrowserWindow::focusInput()
+11 -4
View File
@@ -6,8 +6,9 @@ namespace {
constexpr auto kChars = "1qaz2wsx3edc4rfv5tgb6yhn7ujm8ik9ol0p";
// Installs window.__attHints and shows the labels. "@CHARS@" and "@FONT@" are
// substituted with kChars and config::kFont before running.
// Installs window.__attHints and shows the labels. "@CHARS@", "@FONT@" and
// "@UNZOOM@" are substituted with kChars, config::kFont and 1 / zoom before
// running.
constexpr auto kShowScript = R"JS(
(function () {
'use strict';
@@ -97,6 +98,11 @@ constexpr auto kShowScript = R"JS(
text-transform: uppercase;
white-space: nowrap;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
/* Undo the page zoom, which scales the labels like the rest of
the page, so they show at the configured font size. Anchored
top-left, so a label stays on its element. */
transform: scale(@UNZOOM@);
transform-origin: top left;
}
span.typed { color: #8a6d00; }
`;
@@ -264,11 +270,12 @@ QString chars()
return QString::fromLatin1(kChars);
}
QString showScript()
QString showScript(double zoomFactor)
{
return QString::fromUtf8(kShowScript)
.replace(QLatin1String("@CHARS@"), chars())
.replace(QLatin1String("@FONT@"), QString::fromLatin1(config::kFont));
.replace(QLatin1String("@FONT@"), QString::fromLatin1(config::kFont))
.replace(QLatin1String("@UNZOOM@"), QString::number(1.0 / zoomFactor));
}
QString keyScript(QChar key)
+2 -1
View File
@@ -21,7 +21,8 @@ namespace hints {
// The characters labels are built from - qutebrowser's home-row default.
QString chars();
QString showScript();
// zoomFactor is the page zoom, which the labels compensate for.
QString showScript(double zoomFactor);
QString keyScript(QChar key);
QString backspaceScript();
QString clearScript();