Files
Jungfraujoch/viewer/windows/JFJochMouseShortcutsWindow.cpp
T
leonarski_fandClaude Fable 5 7b868fb9f5 viewer: raster window composition and remote-display repaint throttling
Over "ssh -X" the viewer was near unusable, and the July finding that every
repaint uploads the whole window (5.3 MiB at the default size) regardless of
how small the damage is turns out to have a single cause: the reciprocal-space
window constructed a QOpenGLWidget at startup, and one dormant QOpenGLWidget -
unmapped, in a window nobody ever opened - switches Qt's window composition
onto the OpenGL swapchain path. That path re-presents the entire window on
every flush (and is also the llvmpipe CPU burn seen on headless boxes). The
reciprocal-space window was a placeholder feature and is removed; with it gone
Qt flushes through the raster backing store, which sends only the damaged
region.

On top of that, interactions that repainted once per input event are held to
the hover cadence (15 Hz) on remote sessions only: panning accumulates its
pixel delta, wheel zoom its steps, a recolour burst its final value, live
playback keeps only the newest frame (the worker ack stays per-frame), and the
toolbar counter/slider readbacks coalesce the same way. Each throttle applies
inline with a single-shot tail, the same shape as the existing hover limiter,
so the view always lands exactly where the gesture put it. Local sessions are
unchanged - every event still applies inline.

Remote sessions are detected once at startup (xcb platform and a DISPLAY with
a host part, i.e. "localhost:10.0" from SSH forwarding or "host:0"); the
JFJOCH_VIEWER_REMOTE environment variable and a View-menu toggle override the
detection in either direction.

Measured through a byte-counting X relay against Xvfb with MIT-SHM disabled
(client-to-server bytes are what the SSH link carries), same scripted
interaction sequence, 1200x1100 window, KiB:

                     rc169    removal only   removal+throttles
  hover, 50 motions  82088    2040           2040
  pan, 50 motions    290046   12087          4778
  wheel zoom x10     71143    12603          7649
  ctrl-wheel x6      65672    7194           4797
  frame step x10     284572   21454          21454

Removing the reciprocal-space window from the source measured byte-identical
to only deferring its GL view to first show, confirming the cost is the live
QOpenGLWidget, not the code being compiled in. The image panel renders
pixel-identically (AE=0) to rc169 after identical zoom+pan gestures, with the
throttles on and off.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WbjnQhutnboy4qbxwmgDAX
2026-09-12 22:38:45 +02:00

70 lines
3.5 KiB
C++

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#include "JFJochMouseShortcutsWindow.h"
#include <QTextBrowser>
#include <QVBoxLayout>
namespace {
struct Shortcut { QString action; QString effect; };
struct Section { QString title; QVector<Shortcut> rows; };
QString BuildHtml() {
const QVector<Section> sections = {
// JFJochImage / JFJochDiffractionImage mouse handling
{"Diffraction image", {
{"Wheel", "Zoom in / out, centred on the cursor"},
{"Shift + wheel", "Move the foreground (upper contrast limit) in linear steps"},
{"Ctrl + wheel", "Move the foreground in multiplicative steps (&times;1.15 per notch)"},
{"F held + wheel", "Same as Shift + wheel, for as long as F is held"},
{"A", "Apply auto-contrast once; press again to switch on continuous Auto"},
{"Home / End", "Jump to the first / last image in the dataset"},
{"Page Up / Page Down", "Step one image forward / back"},
{"Hover", "Status bar shows the pixel position, its value and the resolution"},
{"Drag", "Pan the image"},
{"Shift + drag", "Draw a rectangular ROI"},
{"Shift + Ctrl + drag", "Draw a circular ROI"},
{"Drag an ROI or its handle", "Move or resize the selected ROI"},
{"Right click", "Copy / save the image, fit to view, clear the ROI"},
}},
// JFJochGridScanImage
{"Grid scan", {
{"Hover", "Status bar shows the image number, the grid position and its value"},
{"Shift + hover", "Load the image under the cursor while moving over the grid"},
{"Double click", "Load the image under the cursor"},
}},
{"Other views", {
{"2D azimuthal image: double click", "Zoom the diffraction image on the corresponding detector position"},
{"Dataset-info plot: hover", "Status bar shows the image number and the plotted value"},
{"Dataset-info plot: Shift + hover", "Load the hovered image"},
{"Spot / reflection list: double click", "Zoom the diffraction image on that spot or prediction"},
{"Image list: double click", "Load that image"},
{"Magnifier: wheel", "Zoom the magnifier; it follows the cursor on the main image"},
}},
};
QString html = "<html><body>";
for (const auto &section : sections) {
html += "<h3>" + section.title + "</h3>";
html += "<table cellspacing='0' cellpadding='4' width='100%'>";
for (const auto &row : section.rows)
html += "<tr><td width='38%'><b>" + row.action + "</b></td><td>" + row.effect + "</td></tr>";
html += "</table>";
}
html += "</body></html>";
return html;
}
}
JFJochMouseShortcutsWindow::JFJochMouseShortcutsWindow(QWidget *parent) : QDialog(parent) {
setWindowTitle("Mouse Shortcuts");
resize(620, 620);
auto *browser = new QTextBrowser(this);
browser->setHtml(BuildHtml());
auto *layout = new QVBoxLayout(this);
layout->addWidget(browser);
}